зеркало из https://github.com/mozilla/gecko-dev.git
Work in progress for Windows palette support
This commit is contained in:
Родитель
c550aa1e0a
Коммит
efb83ad3fe
|
@ -333,87 +333,3 @@ NS_IMETHODIMP DeviceContextImpl::CreateILColorSpace(IL_ColorSpace*& aColorSpace)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
#if 0
|
||||
nsresult result = NS_OK;
|
||||
int bitsPerPixel = ::GetDeviceCaps(mDC, BITSPIXEL);
|
||||
int rasterCaps = ::GetDeviceCaps(mDC, RASTERCAPS);
|
||||
|
||||
// See if we're dealing with an 8-bit palette device
|
||||
if ((8 == bitsPerPixel) && (rasterCaps & RC_PALETTE)) {
|
||||
// Create a color cube. We want to use DIB_PAL_COLORS because it's faster
|
||||
// than DIB_RGB_COLORS, so make sure the indexes match that of the
|
||||
// GDI physical palette
|
||||
//
|
||||
// Note: the image library doesn't use the reserved colors, so it doesn't
|
||||
// matter what they're set to...
|
||||
IL_RGB reserved[10];
|
||||
IL_ColorMap* colorMap = IL_NewCubeColorMap(reserved, 10, COLOR_CUBE_SIZE + 10);
|
||||
if (nsnull == colorMap) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
// Create a physical palette if we haven't already done so. Each HDC can
|
||||
// share the same physical palette
|
||||
if (nsnull == gPalette) {
|
||||
// Create a logical palette
|
||||
BYTE tmp[sizeof(LOGPALETTE) + ((COLOR_CUBE_SIZE + 20) * sizeof(PALETTEENTRY))];
|
||||
LPLOGPALETTE logPal = (LPLOGPALETTE)tmp;
|
||||
|
||||
logPal->palVersion = 0x300;
|
||||
logPal->palNumEntries = COLOR_CUBE_SIZE + 20;
|
||||
|
||||
// Initialize it from the default Windows palette
|
||||
HPALETTE hDefaultPalette = ::GetStockObject(DEFAULT_PALETTE);
|
||||
|
||||
// First ten system colors
|
||||
::GetPaletteEntries(hDefaultPalette, 0, 10, logPal->palPalEntry);
|
||||
|
||||
// Last ten system colors
|
||||
::GetPaletteEntries(hDefaultPalette, 10, 10, &logPal->palPalEntry[COLOR_CUBE_SIZE + 10]);
|
||||
|
||||
// Now set the color cube entries
|
||||
PALETTEENTRY* entry = &logPal->palPalEntry[10];
|
||||
NI_RGB* map = colorMap->map + 10;
|
||||
for (PRInt32 i = 0; i < COLOR_CUBE_SIZE; i++) {
|
||||
entry->peRed = map->red;
|
||||
entry->peGreen = map->green;
|
||||
entry->peBlue = map->blue;
|
||||
entry->peFlags = 0;
|
||||
|
||||
entry++;
|
||||
map++;
|
||||
}
|
||||
|
||||
// Create a GDI palette
|
||||
gPalette = ::CreatePalette(logPal);
|
||||
}
|
||||
|
||||
// Create an IL pseudo color space
|
||||
aColorSpace = IL_CreatePseudoColorSpace(colorMap, 8, 8);
|
||||
if (nsnull == aColorSpace) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
} else {
|
||||
// Create a default color space.
|
||||
// XXX We should also check for 1 16-bit device and create a 555 or 565
|
||||
// color space...
|
||||
IL_RGBBits colorRGBBits;
|
||||
|
||||
// Default is to create a 24-bit color space
|
||||
colorRGBBits.red_shift = 16;
|
||||
colorRGBBits.red_bits = 8;
|
||||
colorRGBBits.green_shift = 8;
|
||||
colorRGBBits.green_bits = 8;
|
||||
colorRGBBits.blue_shift = 0;
|
||||
colorRGBBits.blue_bits = 8;
|
||||
|
||||
aColorSpace = IL_CreateTrueColorSpace(&colorRGBBits, 24);
|
||||
if (nsnull == aColorSpace) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
#endif
|
||||
|
||||
|
|
|
@ -18,6 +18,10 @@
|
|||
|
||||
#include "nsDeviceContextWin.h"
|
||||
#include "nsRenderingContextWin.h"
|
||||
#include "il_util.h"
|
||||
|
||||
// Size of the color cube
|
||||
#define COLOR_CUBE_SIZE 216
|
||||
|
||||
nsDeviceContextWin :: nsDeviceContextWin()
|
||||
: DeviceContextImpl()
|
||||
|
@ -84,3 +88,78 @@ NS_IMETHODIMP nsDeviceContextWin :: CheckFontExistence(const char * aFontName)
|
|||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextWin::CreateILColorSpace(IL_ColorSpace*& aColorSpace)
|
||||
{
|
||||
HWND hwnd = (HWND)GetNativeWidget();
|
||||
HDC hdc = ::GetDC(hwnd);
|
||||
nsresult result = NS_OK;
|
||||
int bitsPerPixel = ::GetDeviceCaps(hdc, BITSPIXEL);
|
||||
int rasterCaps = ::GetDeviceCaps(hdc, RASTERCAPS);
|
||||
::ReleaseDC(hwnd, hdc);
|
||||
|
||||
// See if we're dealing with an 8-bit palette device
|
||||
if ((8 == bitsPerPixel) && (rasterCaps & RC_PALETTE)) {
|
||||
// Create a color cube. We want to use DIB_PAL_COLORS because it's faster
|
||||
// than DIB_RGB_COLORS, so make sure the indexes match that of the
|
||||
// GDI physical palette
|
||||
//
|
||||
// Note: the image library doesn't use the reserved colors, so it doesn't
|
||||
// matter what they're set to...
|
||||
IL_RGB reserved[10];
|
||||
IL_ColorMap* colorMap = IL_NewCubeColorMap(reserved, 10, COLOR_CUBE_SIZE + 10);
|
||||
if (nsnull == colorMap) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
// Create a physical palette if we haven't already done so. Each HDC can
|
||||
// share the same physical palette
|
||||
//
|
||||
// XXX Device context should own the palette...
|
||||
if (nsnull == nsRenderingContextWin::gPalette) {
|
||||
// Create a logical palette
|
||||
BYTE tmp[sizeof(LOGPALETTE) + ((COLOR_CUBE_SIZE + 20) * sizeof(PALETTEENTRY))];
|
||||
LPLOGPALETTE logPal = (LPLOGPALETTE)tmp;
|
||||
|
||||
logPal->palVersion = 0x300;
|
||||
logPal->palNumEntries = COLOR_CUBE_SIZE + 20;
|
||||
|
||||
// Initialize it from the default Windows palette
|
||||
HPALETTE hDefaultPalette = ::GetStockObject(DEFAULT_PALETTE);
|
||||
|
||||
// First ten system colors
|
||||
::GetPaletteEntries(hDefaultPalette, 0, 10, logPal->palPalEntry);
|
||||
|
||||
// Last ten system colors
|
||||
::GetPaletteEntries(hDefaultPalette, 10, 10, &logPal->palPalEntry[COLOR_CUBE_SIZE + 10]);
|
||||
|
||||
// Now set the color cube entries
|
||||
PALETTEENTRY* entry = &logPal->palPalEntry[10];
|
||||
NI_RGB* map = colorMap->map + 10;
|
||||
for (PRInt32 i = 0; i < COLOR_CUBE_SIZE; i++) {
|
||||
entry->peRed = map->red;
|
||||
entry->peGreen = map->green;
|
||||
entry->peBlue = map->blue;
|
||||
entry->peFlags = 0;
|
||||
|
||||
entry++;
|
||||
map++;
|
||||
}
|
||||
|
||||
// Create a GDI palette
|
||||
nsRenderingContextWin::gPalette = ::CreatePalette(logPal);
|
||||
}
|
||||
|
||||
// Create an IL pseudo color space
|
||||
aColorSpace = IL_CreatePseudoColorSpace(colorMap, 8, 8);
|
||||
if (nsnull == aColorSpace) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
} else {
|
||||
// Create a default color space.
|
||||
result = DeviceContextImpl::CreateILColorSpace(aColorSpace);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -38,6 +38,8 @@ public:
|
|||
|
||||
NS_IMETHOD CheckFontExistence(const char * aFontName);
|
||||
|
||||
NS_IMETHOD CreateILColorSpace(IL_ColorSpace*& aColorSpace);
|
||||
|
||||
protected:
|
||||
virtual ~nsDeviceContextWin();
|
||||
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
#include "nsRegionWin.h"
|
||||
#include <math.h>
|
||||
#include "libimg.h"
|
||||
#include "il_util.h"
|
||||
|
||||
#define FLAG_CLIP_VALID 0x0001
|
||||
#define FLAG_CLIP_CHANGED 0x0002
|
||||
|
|
|
@ -168,11 +168,12 @@ protected:
|
|||
PRUint8 *mGammaTable;
|
||||
COLORREF mCurrTextColor;
|
||||
|
||||
static HPALETTE gPalette;
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
PRBool mInitialized;
|
||||
#endif
|
||||
|
||||
public:
|
||||
static HPALETTE gPalette;
|
||||
};
|
||||
|
||||
#endif /* nsRenderingContextWin_h___ */
|
||||
|
|
Загрузка…
Ссылка в новой задаче