r=pedemont, sr=blizzard (OS/2 only)
OS/2 only - Add 256 color support


git-svn-id: svn://10.0.0.236/trunk@136392 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
mkaply%us.ibm.com 2003-01-16 00:23:32 +00:00
parent 6266e3e3a0
commit bd7ac1d4e8
7 changed files with 47 additions and 249 deletions

View File

@ -24,9 +24,6 @@
#include "nsDeviceContextOS2.h"
#include "nsRenderingContextOS2.h"
#include "nsDeviceContextSpecOS2.h"
#ifdef COLOR_256
#include "il_util.h"
#endif
#include "nsIServiceManager.h"
#include "nsCOMPtr.h"
#include "nsIScreenManager.h"
@ -38,9 +35,7 @@
#include "nsIPref.h"
#include "nsOS2Uni.h"
// Size of the color cube
#define COLOR_CUBE_SIZE 216
#include "nsPaletteOS2.h"
#define NOT_SETUP 0x33
static PRBool gIsWarp4 = NOT_SETUP;
@ -52,12 +47,7 @@ nsDeviceContextOS2 :: nsDeviceContextOS2()
: DeviceContextImpl()
{
mSurface = NULL;
#ifdef COLOR_256
mPaletteInfo.isPaletteDevice = PR_FALSE;
mPaletteInfo.sizePalette = 0;
mPaletteInfo.numReserved = 0;
mPaletteInfo.palette = NULL;
#endif
mIsPaletteDevice = PR_FALSE;
mPrintDC = NULL;
mWidth = -1;
mHeight = -1;
@ -209,20 +199,7 @@ void nsDeviceContextOS2 :: CommonInit(HDC aDC)
GFX (::DevQueryCaps(aDC, CAPS_FAMILY, CAPS_DEVICE_POLYSET_POINTS, alArray), FALSE);
mDepth = alArray[CAPS_COLOR_BITCOUNT];
#ifdef COLOR_256
mPaletteInfo.isPaletteDevice = !!(alArray[CAPS_ADDITIONAL_GRAPHICS] & CAPS_PALETTE_MANAGER);
/* OS2TODO - pref to turn off palette management should set isPaletteDevice to false */
if (mPaletteInfo.isPaletteDevice)
mPaletteInfo.sizePalette = 256;
if (alArray[CAPS_COLORS] >= 20) {
mPaletteInfo.numReserved = 20;
} else {
mPaletteInfo.numReserved = alArray[CAPS_COLORS];
} /* endif */
#endif
mIsPaletteDevice = ((alArray[CAPS_ADDITIONAL_GRAPHICS] & CAPS_PALETTE_MANAGER) == CAPS_PALETTE_MANAGER);
mWidth = alArray[CAPS_WIDTH];
mHeight = alArray[CAPS_HEIGHT];
@ -652,169 +629,6 @@ int prefChanged(const char *aPref, void *aClosure)
return 0;
}
#ifdef COLOR_256
NS_IMETHODIMP nsDeviceContextOS2::GetILColorSpace(IL_ColorSpace*& aColorSpace)
{
if (nsnull == mColorSpace) {
// See if we're dealing with an 8-bit palette device
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
//
// Note: the image library doesn't use the reserved colors, so it doesn't
// matter what they're set to...
#ifdef XP_OS2
IL_ColorMap* colorMap = IL_NewCubeColorMap(0, 0, COLOR_CUBE_SIZE);
#else /* This code causes traps on 256 color */
IL_RGB reserved[10];
memset(reserved, 0, sizeof(reserved));
IL_ColorMap* colorMap = IL_NewCubeColorMap(reserved, 10, COLOR_CUBE_SIZE + 10);
#endif
if (nsnull == colorMap) {
return NS_ERROR_OUT_OF_MEMORY;
}
// Create a pseudo color space
mColorSpace = IL_CreatePseudoColorSpace(colorMap, 8, 8);
} else {
IL_RGBBits colorRGBBits;
// 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;
mColorSpace = IL_CreateTrueColorSpace(&colorRGBBits, 24);
}
if (nsnull == mColorSpace) {
aColorSpace = nsnull;
return NS_ERROR_OUT_OF_MEMORY;
}
}
// Return the color space
aColorSpace = mColorSpace;
IL_AddRefToColorSpace(aColorSpace);
return NS_OK;
}
#define NUM_SYS_COLORS 22
typedef struct _MYRGB
{
BYTE red;
BYTE green;
BYTE blue;
} MYRGB;
MYRGB sysColors[NUM_SYS_COLORS] =
{
0x00, 0x00, 0x00, // CLR_BLACK
0x00, 0x00, 0x80, // CLR_DARKBLUE
0x00, 0x80, 0x00, // CLR_DARKGREEN
0x00, 0x80, 0x80, // CLR_DARKCYAN
0x80, 0x00, 0x00, // CLR_DARKRED
0x80, 0x00, 0x80, // CLR_DARKPINK
0x80, 0x80, 0x00, // CLR_BROWN
0x80, 0x80, 0x80, // CLR_DARKGRAY
0xCC, 0xCC, 0xCC, // CLR_PALEGRAY
0x00, 0x00, 0xFF, // CLR_BLUE
0x00, 0xFF, 0x00, // CLR_GREEN
0x00, 0xFF, 0xFF, // CLR_CYAN
0xFF, 0x00, 0x00, // CLR_RED
0xFF, 0x00, 0xFF, // CLR_PINK
0xFF, 0xFF, 0x00, // CLR_YELLOW
0xFE, 0xFE, 0xFE, // CLR_OFFWHITE - can only use white at index 255
0xC0, 0xC0, 0xC0, // Gray (Windows)
0xFF, 0xFB, 0xF0, // Pale Yellow (Windows)
0xC0, 0xDC, 0xC0, // Pale Green (Windows)
0xA4, 0xC8, 0xF0, // Light Blue (Windows)
0xA4, 0xA0, 0xA4, // Medium Gray (Windows)
0xFF, 0xFF, 0xE4 // Tooltip color - see nsLookAndFeel.cpp
};
NS_IMETHODIMP nsDeviceContextOS2::GetPaletteInfo(nsPaletteInfo& aPaletteInfo)
{
static PRBool fPaletteInitialized = PR_FALSE;
static ULONG aulTable[256];
aPaletteInfo.isPaletteDevice = mPaletteInfo.isPaletteDevice;
aPaletteInfo.sizePalette = mPaletteInfo.sizePalette;
aPaletteInfo.numReserved = mPaletteInfo.numReserved;
if ((mPaletteInfo.isPaletteDevice) && (NULL == mPaletteInfo.palette)) {
if (!fPaletteInitialized) {
IL_ColorSpace* colorSpace;
GetILColorSpace(colorSpace);
// Create a logical palette
ULONG ulCount;
PRInt32 i,j;
// system colors
for (i = 0; i < NUM_SYS_COLORS; i++) {
aulTable[i] = MK_RGB(sysColors[i].red, sysColors[i].green, sysColors[i].blue);
}
// Now set the color cube entries.
#ifdef XP_OS2
NI_RGB* map = colorSpace->cmap.map;
#else /* Combined with changes in GetILColor Space, this traps */
NI_RGB* map = colorSpace->cmap.map + 10;
#endif
PRInt32 k = NUM_SYS_COLORS;
for (i = 0; i < COLOR_CUBE_SIZE; i++, map++) {
aulTable[k] = MK_RGB(map->red, map->green, map->blue);
for (j = 0;j < NUM_SYS_COLORS; j++) {
if (aulTable[k] == aulTable[j]) {
aulTable[k] = 0;
break;
} /* endif */
} /* endfor */
if (j == NUM_SYS_COLORS) {
k++;
} /* endif */
} /* endfor */
ulCount = (k-1);
// This overwrites the last entry in the cube (white)
for (i=ulCount;i<256 ;i++ ) {
aulTable[i] = MK_RGB(254,254,254);
} /* endfor */
aulTable[255] = MK_RGB(255, 255, 255); // Entry 255 must be white
fPaletteInitialized = PR_TRUE;
IL_ReleaseColorSpace(colorSpace);
#ifdef DEBUG
for (i=0;i<256 ;i++ )
printf("Entry[%d] in table is %x\n", i, aulTable[i]);
#endif
} /* endif */
// Create a GPI palette
mPaletteInfo.palette =
(void*)GFX (::GpiCreatePalette ((HAB)0, NULL,
LCOLF_CONSECRGB, 256, aulTable),
GPI_ERROR);
} /* endif */
aPaletteInfo.palette = mPaletteInfo.palette;
return NS_OK;
}
#endif
NS_IMETHODIMP nsDeviceContextOS2 :: ConvertPixel(nscolor aColor, PRUint32 & aPixel)
{
aPixel = aColor;

View File

@ -65,13 +65,6 @@ public:
NS_IMETHOD GetDepth(PRUint32& aDepth);
#ifdef COLOR_256
NS_IMETHOD GetILColorSpace(IL_ColorSpace*& aColorSpace);
NS_IMETHOD GetPaletteInfo(nsPaletteInfo&);
#endif
NS_IMETHOD ConvertPixel(nscolor aColor, PRUint32 & aPixel);
NS_IMETHOD GetDeviceSurfaceDimensions(PRInt32 &aWidth, PRInt32 &aHeight);
@ -109,9 +102,7 @@ protected:
nsDrawingSurface mSurface;
PRUint32 mDepth; // bit depth of device
#ifdef COLOR_256
nsPaletteInfo mPaletteInfo;
#endif
PRBool mIsPaletteDevice;
PRInt32 mWidth;
PRInt32 mHeight;
nsRect mClientRect;
@ -136,6 +127,7 @@ public:
BOOL isPrintDC();
PRBool SupportsRasterFonts();
PRBool IsPaletteDevice() {return mIsPaletteDevice;};
nsresult nsDeviceContextOS2::CreateFontAliasTable();
};

View File

@ -25,6 +25,7 @@
#include "nsIWidget.h"
#include "nsDrawingSurfaceOS2.h"
#include "nsFontMetricsOS2.h"
#include "nsPaletteOS2.h"
// Base class -- fonts, palette and xpcom -----------------------------------
@ -188,6 +189,8 @@ nsresult nsOffscreenSurface::Init( HPS aCompatiblePS,
if( GPI_ERROR != mPS)
{
nsPaletteOS2::SelectGlobalPalette(mPS);
// now create a bitmap of the right size
BITMAPINFOHEADER2 hdr = { 0 };

View File

@ -58,6 +58,7 @@
#include "gfxImageFrame.h"
#include "nsOS2Uni.h"
#include "nsPaletteOS2.h"
// objects that just require generic constructors
@ -205,6 +206,7 @@ PR_STATIC_CALLBACK(void)
nsGfxOS2ModuleDtor(nsIModule *self)
{
OS2Uni::FreeUconvObjects();
nsPaletteOS2::FreeGlobalPalette();
// nsRenderingContextOS2::Shutdown();
}

View File

@ -52,6 +52,7 @@
#include "nsFont.h"
#include "prprf.h"
#include "nsIRenderingContextOS2.h"
#include "nsPaletteOS2.h"
// helper clip region functions - defined at the bottom of this file.
@ -265,28 +266,15 @@ nsresult nsRenderingContextOS2::SetupPS (void)
{
LONG BlackColor, WhiteColor;
#ifdef COLOR_256
// If this is a palette device, then select and realize the palette
nsPaletteInfo palInfo;
mContext->GetPaletteInfo(palInfo);
if (palInfo.isPaletteDevice && palInfo.palette)
// If this is a palette device, then set transparent colors
if (((nsDeviceContextOS2*)mContext)->IsPaletteDevice())
{
ULONG cclr;
// Select the palette in the background
GFX (::GpiSelectPalette (mPS, (HPAL)palInfo.palette), PAL_ERROR);
if (mDCOwner)
GFX (::WinRealizePalette((HWND)mDCOwner->GetNativeData(NS_NATIVE_WINDOW), mPS, &cclr), PAL_ERROR);
BlackColor = GFX (::GpiQueryColorIndex (mPS, 0, MK_RGB (0x00, 0x00, 0x00)), GPI_ALTERROR); // CLR_BLACK;
WhiteColor = GFX (::GpiQueryColorIndex (mPS, 0, MK_RGB (0xFF, 0xFF, 0xFF)), GPI_ALTERROR); // CLR_WHITE;
mPaletteMode = PR_TRUE;
}
else
#endif
{
GFX (::GpiCreateLogColorTable (mPS, 0, LCOLF_RGB, 0, 0, 0), FALSE);

View File

@ -61,6 +61,7 @@
#include "nsIFile.h"
#include "nsOS2Uni.h"
#include "nsPaletteOS2.h"
#include <stdlib.h>
#include <ctype.h>
@ -1844,8 +1845,12 @@ void* nsWindow::GetNativeData(PRUint32 aDataType)
case NS_NATIVE_GRAPHIC:
if( !mPS)
{
if( mDragInside) mPS = DrgGetPS( mWnd);
else mPS = WinGetPS( mWnd);
if( mDragInside) {
mPS = DrgGetPS(mWnd);
} else {
mPS = WinGetPS(mWnd);
}
nsPaletteOS2::SelectGlobalPalette(mPS, mWnd);
}
mPSRefs++;
rc = (void*) mPS;
@ -2592,32 +2597,24 @@ PRBool nsWindow::OnReposition( PSWP pSwp)
return result;
}
// Realize-palette. I reckon only top-level windows get the message, so
// there's code in frame to broadcast it to children.
PRBool nsWindow::OnRealizePalette()
{
PRBool rc = PR_FALSE;
if (WinQueryWindowUShort(mWnd, QWS_ID) == FID_CLIENT) {
HWND hwndFocus = WinQueryFocus(HWND_DESKTOP);
if (WinIsChild(hwndFocus, mWnd)) {
/* We are getting the focus */
HPS hps = WinGetPS(hwndFocus);
nsPaletteOS2::SelectGlobalPalette(hps, hwndFocus);
WinReleasePS(hps);
WinInvalidateRect( mWnd, 0, TRUE);
} else {
/* We are losing the focus */
WinInvalidateRect( mWnd, 0, TRUE);
}
}
#ifdef COLOR_256
// Get palette info from device
nsPaletteInfo palInfo;
mContext->GetPaletteInfo( palInfo);
if( mPS && palInfo.isPaletteDevice && palInfo.palette)
{
// An onscreen nsDrawingSurface has been created for the window,
// and we have a palette. So realize it.
ULONG cclr;
long palrc = WinRealizePalette( mWnd, mPS, &cclr);
if( palrc && palrc != PAL_ERROR)
// Colours have changed, redraw.
WinInvalidateRect( mWnd, 0, FALSE);
rc = PR_TRUE;
}
#endif
return rc;
// Always call the default window procedure
return PR_TRUE;
}
PRBool nsWindow::OnPresParamChanged( MPARAM mp1, MPARAM mp2)
@ -2715,6 +2712,7 @@ PRBool nsWindow::OnPaint()
RECTL rcl = { 0 };
HPS hPS = WinBeginPaint(mWnd, NULLHANDLE, &rcl);
nsPaletteOS2::SelectGlobalPalette(hPS, mWnd);
// XXX What is this check doing? If it's trying to check for an empty
// paint rect then use the IsRectEmpty() function...
@ -2764,15 +2762,6 @@ PRBool nsWindow::OnPaint()
if (NS_OK == winrc->CreateDrawingSurface(hPS, surf, event.widget))
{
event.renderingContext->Init(mContext, surf);
#ifdef COLOR_256
nsPaletteInfo palInfo;
mContext->GetPaletteInfo(palInfo);
if (palInfo.isPaletteDevice && palInfo.palette)
{
ULONG cclr;
::WinRealizePalette(mWnd, hPS, &cclr);
}
#endif
rc = DispatchWindowEvent(&event);
event.renderingContext->DestroyDrawingSurface(surf);
}

View File

@ -56,6 +56,7 @@
#include "nsIPromptService.h"
#include "nsNetCID.h"
#include "nsIObserverService.h"
#include "nsPaletteOS2.h"
// These are needed to load a URL in a browser window.
#include "nsIDOMLocation.h"
@ -338,7 +339,8 @@ private:
* whether Mozilla is already running.
*/
class nsNativeAppSupportOS2 : public nsNativeAppSupportBase {
class nsNativeAppSupportOS2 : public nsNativeAppSupportBase
{
public:
// Overrides of base implementation.
NS_IMETHOD Start( PRBool *aResult );
@ -589,6 +591,7 @@ MRESULT EXPENTRY DialogProc( HWND dlg, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
else if ( msg == WM_PAINT ) {
nsSplashScreenOS2 *splashScreen = (nsSplashScreenOS2*)WinQueryWindowPtr( dlg, QWL_USER );
HPS hps = WinBeginPaint (dlg, NULLHANDLE, NULL);
nsPaletteOS2::SelectGlobalPalette(hps, dlg);
GpiErase (hps);
POINTL aptl[8] = {0, 0, splashScreen->mBitmapCX, splashScreen->mBitmapCY,
0, 0, 0, 0,
@ -599,6 +602,13 @@ MRESULT EXPENTRY DialogProc( HWND dlg, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
WinEndPaint( hps );
return (MRESULT)TRUE;
}
else if ( msg == WM_REALIZEPALETTE ) {
HPS hps = WinGetPS(dlg);
nsPaletteOS2::SelectGlobalPalette(hps, dlg);
WinReleasePS(hps);
WinInvalidateRect( dlg, 0, TRUE);
return (MRESULT)TRUE;
}
return WinDefDlgProc (dlg, msg, mp1, mp2);
}