This commit is contained in:
troy%netscape.com 1998-08-19 00:37:05 +00:00
Родитель a3dab18b8b
Коммит 590beb1f4b
6 изменённых файлов: 57 добавлений и 19 удалений

Просмотреть файл

@ -523,3 +523,12 @@ NS_IMETHODIMP DeviceContextImpl::GetILColorSpace(IL_ColorSpace*& aColorSpace)
return NS_OK;
}
NS_IMETHODIMP DeviceContextImpl::GetPaletteInfo(nsPaletteInfo& aPaletteInfo)
{
aPaletteInfo.isPaletteDevice = PR_FALSE;
aPaletteInfo.sizePalette = 0;
aPaletteInfo.numReserved = 0;
aPaletteInfo.palette = nsnull;
return NS_OK;
}

Просмотреть файл

@ -72,6 +72,8 @@ public:
NS_IMETHOD GetILColorSpace(IL_ColorSpace*& aColorSpace);
NS_IMETHOD GetPaletteInfo(nsPaletteInfo&);
protected:
virtual ~DeviceContextImpl();

Просмотреть файл

@ -38,6 +38,17 @@ typedef void * nsNativeDeviceContext;
{ 0x5931c580, 0xb917, 0x11d1, \
{ 0xa8, 0x24, 0x00, 0x40, 0x95, 0x9a, 0x28, 0xc9 } }
//a cross platform way of specifying a native palette handle
typedef void * nsPalette;
//structure used to return information about a device's palette capabilities
struct nsPaletteInfo {
PRPackedBool isPaletteDevice;
PRUint8 sizePalette; // number of entries in the palette
PRUint8 numReserved; // number of reserved palette entries
nsPalette palette; // native palette handle
};
/**
* Constants identifying pre-defined icons.
* @see #LoadIcon()
@ -135,6 +146,11 @@ public:
* You must call IL_ReleaseColorSpace() when you're done using the color space.
*/
NS_IMETHOD GetILColorSpace(IL_ColorSpace*& aColorSpace) = 0;
/**
* Returns information about the device's palette capabilities.
*/
NS_IMETHOD GetPaletteInfo(nsPaletteInfo&) = 0;
};
#endif /* nsIDeviceContext_h___ */

Просмотреть файл

@ -23,8 +23,6 @@
// Size of the color cube
#define COLOR_CUBE_SIZE 216
HPALETTE nsDeviceContextWin::gPalette = NULL;
nsDeviceContextWin :: nsDeviceContextWin()
: DeviceContextImpl()
{
@ -36,6 +34,10 @@ nsDeviceContextWin :: nsDeviceContextWin()
::ReleaseDC(NULL, hdc);
mSurface = NULL;
mPaletteInfo.isPaletteDevice = PR_FALSE;
mPaletteInfo.sizePalette = 0;
mPaletteInfo.numReserved = 0;
mPaletteInfo.palette = NULL;
}
nsDeviceContextWin :: ~nsDeviceContextWin()
@ -44,7 +46,10 @@ nsDeviceContextWin :: ~nsDeviceContextWin()
NS_IF_RELEASE(surf); //this clears the surf pointer...
mSurface = nsnull;
mIsPaletteDevice = PR_FALSE;
if (NULL != mPaletteInfo.palette) {
::DeleteObject((HPALETTE)mPaletteInfo.palette);
}
}
nsresult nsDeviceContextWin::Init(nsNativeWidget aWidget)
@ -54,7 +59,9 @@ nsresult nsDeviceContextWin::Init(nsNativeWidget aWidget)
int rasterCaps = ::GetDeviceCaps(hdc, RASTERCAPS);
mDepth = (PRUint32)::GetDeviceCaps(hdc, BITSPIXEL);
mIsPaletteDevice = RC_PALETTE == (rasterCaps & RC_PALETTE);
mPaletteInfo.isPaletteDevice = RC_PALETTE == (rasterCaps & RC_PALETTE);
mPaletteInfo.sizePalette = (PRUint8)::GetDeviceCaps(hdc, SIZEPALETTE);
mPaletteInfo.numReserved = (PRUint8)::GetDeviceCaps(hdc, NUMRESERVED);
::ReleaseDC(hwnd, hdc);
return DeviceContextImpl::Init(aWidget);
@ -115,7 +122,7 @@ NS_IMETHODIMP nsDeviceContextWin::GetILColorSpace(IL_ColorSpace*& aColorSpace)
{
if (nsnull == mColorSpace) {
// See if we're dealing with an 8-bit palette device
if ((8 == mDepth) && mIsPaletteDevice) {
if ((8 == mDepth) && mPaletteInfo.isPaletteDevice) {
// 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
@ -158,9 +165,13 @@ NS_IMETHODIMP nsDeviceContextWin::GetILColorSpace(IL_ColorSpace*& aColorSpace)
return NS_OK;
}
HPALETTE nsDeviceContextWin::GetLogicalPalette()
NS_IMETHODIMP nsDeviceContextWin::GetPaletteInfo(nsPaletteInfo& aPaletteInfo)
{
if (NULL == gPalette) {
aPaletteInfo.isPaletteDevice = mPaletteInfo.isPaletteDevice;
aPaletteInfo.sizePalette = mPaletteInfo.sizePalette;
aPaletteInfo.numReserved = mPaletteInfo.numReserved;
if (NULL == mPaletteInfo.palette) {
IL_ColorSpace* colorSpace;
GetILColorSpace(colorSpace);
@ -181,7 +192,8 @@ HPALETTE nsDeviceContextWin::GetLogicalPalette()
// Last ten system colors
::GetPaletteEntries(hDefaultPalette, 10, 10, &logPal->palPalEntry[COLOR_CUBE_SIZE + 10]);
// Now set the color cube entries
// Now set the color cube entries.
// XXX Need to gamma correct the palette entries...
PALETTEENTRY* entry = &logPal->palPalEntry[10];
NI_RGB* map = colorSpace->cmap.map + 10;
for (PRInt32 i = 0; i < COLOR_CUBE_SIZE; i++) {
@ -195,11 +207,13 @@ HPALETTE nsDeviceContextWin::GetLogicalPalette()
}
// Create a GDI palette
gPalette = ::CreatePalette(logPal);
mPaletteInfo.palette = ::CreatePalette(logPal);
}
IL_ReleaseColorSpace(colorSpace);
}
return gPalette;
aPaletteInfo.palette = mPaletteInfo.palette;
return NS_OK;
}

Просмотреть файл

@ -44,17 +44,14 @@ public:
NS_IMETHOD GetILColorSpace(IL_ColorSpace*& aColorSpace);
//get the logical palette
HPALETTE GetLogicalPalette();
NS_IMETHOD GetPaletteInfo(nsPaletteInfo&);
protected:
virtual ~nsDeviceContextWin();
nsDrawingSurface mSurface;
PRUint32 mDepth; // bit depth of device
PRBool mIsPaletteDevice;
static HPALETTE gPalette;
nsPaletteInfo mPaletteInfo;
};
#endif /* nsDeviceContextWin_h___ */

Просмотреть файл

@ -440,10 +440,10 @@ nsresult nsRenderingContextWin :: SetupDC(HDC aOldDC, HDC aNewDC)
mOrigSolidPen = ::SelectObject(aNewDC, mBlackPen);
// If this is a palette device, then select and realize the palette
HPALETTE pal = ((nsDeviceContextWin*)mContext)->GetLogicalPalette();
if (nsnull != pal) {
mOrigPalette = ::SelectPalette(aNewDC, pal, FALSE);
nsPaletteInfo palInfo;
mContext->GetPaletteInfo(palInfo);
if (palInfo.isPaletteDevice && palInfo.palette) {
mOrigPalette = ::SelectPalette(aNewDC, (HPALETTE)palInfo.palette, FALSE);
// Don't do the realization for an off-screen memory DC
if (nsnull == aOldDC) {
::RealizePalette(aNewDC);