Author: fireball
Date: Sat Aug 15 20:10:34 2009
New Revision: 42711
URL:
http://svn.reactos.org/svn/reactos?rev=42711&view=rev
Log:
- Implement system palette based on palette.c from r41760 (pre-Timo rewrite, to be
compatible with other existing stuff).
Modified:
branches/arwinss/reactos/subsystems/win32/win32k/gdi/dc.c
branches/arwinss/reactos/subsystems/win32/win32k/gre/palobj.c
branches/arwinss/reactos/subsystems/win32/win32k/include/dc.h
branches/arwinss/reactos/subsystems/win32/win32k/include/palobj.h
branches/arwinss/reactos/subsystems/win32/win32k/main/init.c
Modified: branches/arwinss/reactos/subsystems/win32/win32k/gdi/dc.c
URL:
http://svn.reactos.org/svn/reactos/branches/arwinss/reactos/subsystems/win3…
==============================================================================
--- branches/arwinss/reactos/subsystems/win32/win32k/gdi/dc.c [iso-8859-1] (original)
+++ branches/arwinss/reactos/subsystems/win32/win32k/gdi/dc.c [iso-8859-1] Sat Aug 15
20:10:34 2009
@@ -143,6 +143,9 @@
/* Create an empty combined clipping region */
pNewDC->CombinedClip = EngCreateClip();
+
+ /* Set default palette */
+ pNewDC->hPalette = hSystemPal;
/* Give handle to the caller */
*pdev = hNewDC;
Modified: branches/arwinss/reactos/subsystems/win32/win32k/gre/palobj.c
URL:
http://svn.reactos.org/svn/reactos/branches/arwinss/reactos/subsystems/win3…
==============================================================================
--- branches/arwinss/reactos/subsystems/win32/win32k/gre/palobj.c [iso-8859-1] (original)
+++ branches/arwinss/reactos/subsystems/win32/win32k/gre/palobj.c [iso-8859-1] Sat Aug 15
20:10:34 2009
@@ -14,6 +14,84 @@
#define NDEBUG
#include <debug.h>
+/* GLOBALS *******************************************************************/
+HGDIOBJ hSystemPal;
+
+#define NB_RESERVED_COLORS 20 /* number of fixed colors in system palette
*/
+#define PC_SYS_USED 0x80 /* palentry is used (both system and logical) */
+
+const PALETTEENTRY COLOR_sysPalTemplate[NB_RESERVED_COLORS] =
+{
+ // first 10 entries in the system palette
+ // red green blue flags
+ { 0x00, 0x00, 0x00, PC_SYS_USED },
+ { 0x80, 0x00, 0x00, PC_SYS_USED },
+ { 0x00, 0x80, 0x00, PC_SYS_USED },
+ { 0x80, 0x80, 0x00, PC_SYS_USED },
+ { 0x00, 0x00, 0x80, PC_SYS_USED },
+ { 0x80, 0x00, 0x80, PC_SYS_USED },
+ { 0x00, 0x80, 0x80, PC_SYS_USED },
+ { 0xc0, 0xc0, 0xc0, PC_SYS_USED },
+ { 0xc0, 0xdc, 0xc0, PC_SYS_USED },
+ { 0xa6, 0xca, 0xf0, PC_SYS_USED },
+
+ // ... c_min/2 dynamic colorcells
+ // ... gap (for sparse palettes)
+ // ... c_min/2 dynamic colorcells
+
+ { 0xff, 0xfb, 0xf0, PC_SYS_USED },
+ { 0xa0, 0xa0, 0xa4, PC_SYS_USED },
+ { 0x80, 0x80, 0x80, PC_SYS_USED },
+ { 0xff, 0x00, 0x00, PC_SYS_USED },
+ { 0x00, 0xff, 0x00, PC_SYS_USED },
+ { 0xff, 0xff, 0x00, PC_SYS_USED },
+ { 0x00, 0x00, 0xff, PC_SYS_USED },
+ { 0xff, 0x00, 0xff, PC_SYS_USED },
+ { 0x00, 0xff, 0xff, PC_SYS_USED },
+ { 0xff, 0xff, 0xff, PC_SYS_USED } // last 10
+};
+
+const PALETTEENTRY* FASTCALL COLOR_GetSystemPaletteTemplate(void)
+{
+ return (const PALETTEENTRY*)&COLOR_sysPalTemplate;
+}
+
+/* PRIVATE FUNCTIONS *********************************************************/
+/*
+ * @implemented
+ */
+HPALETTE APIENTRY
+GrepCreatePalette( IN LPLOGPALETTE pLogPal, IN UINT cEntries )
+{
+ PPALETTE PalGDI;
+ HPALETTE NewPalette;
+
+ pLogPal->palNumEntries = cEntries;
+ NewPalette = PALETTE_AllocPalette( PAL_INDEXED,
+ cEntries,
+ (PULONG)pLogPal->palPalEntry,
+ 0, 0, 0);
+
+ if (NewPalette == NULL)
+ {
+ return NULL;
+ }
+
+ PalGDI = (PPALETTE) PALETTE_LockPalette(NewPalette);
+ if (PalGDI != NULL)
+ {
+ PALETTE_ValidateFlags(PalGDI->IndexedColors, PalGDI->NumColors);
+ //PalGDI->logicalToSystem = NULL;
+ PALETTE_UnlockPalette(PalGDI);
+ }
+ else
+ {
+ /* FIXME - Handle PalGDI == NULL!!!! */
+ DPRINT1("Warning: PalGDI is NULL!\n");
+ }
+ return NewPalette;
+}
+
/* PUBLIC FUNCTIONS **********************************************************/
HPALETTE
@@ -105,6 +183,108 @@
return NewPalette;
}
+// Create the system palette
+VOID APIENTRY
+PALETTE_Init(VOID)
+{
+ int i;
+ PLOGPALETTE palPtr;
+
+ const PALETTEENTRY* __sysPalTemplate = (const
PALETTEENTRY*)COLOR_GetSystemPaletteTemplate();
+
+ // create default palette (20 system colors)
+ palPtr = ExAllocatePoolWithTag(PagedPool,
+ sizeof(LOGPALETTE) +
+ (NB_RESERVED_COLORS * sizeof(PALETTEENTRY)),
+ TAG_PALETTE);
+ if (!palPtr)
+ {
+ hSystemPal = 0;
+ return;
+ }
+
+ palPtr->palVersion = 0x300;
+ palPtr->palNumEntries = NB_RESERVED_COLORS;
+ for (i=0; i<NB_RESERVED_COLORS; i++)
+ {
+ palPtr->palPalEntry[i].peRed = __sysPalTemplate[i].peRed;
+ palPtr->palPalEntry[i].peGreen = __sysPalTemplate[i].peGreen;
+ palPtr->palPalEntry[i].peBlue = __sysPalTemplate[i].peBlue;
+ palPtr->palPalEntry[i].peFlags = 0;
+ }
+
+ hSystemPal = GrepCreatePalette(palPtr,NB_RESERVED_COLORS);
+ ExFreePoolWithTag(palPtr, TAG_PALETTE);
+
+ /* Convert it to a stock object */
+ GDIOBJ_ConvertToStockObj(&hSystemPal);
+}
+
+UINT APIENTRY
+GreGetSystemPaletteEntries(HDC hDC,
+ UINT StartIndex,
+ UINT Entries,
+ LPPALETTEENTRY pe)
+{
+ PPALETTE palGDI = NULL;
+ PDC dc = NULL;
+ UINT EntriesSize = 0;
+ UINT Ret = 0;
+
+ if (Entries == 0)
+ {
+ SetLastWin32Error(ERROR_INVALID_PARAMETER);
+ return 0;
+ }
+
+ if (pe != NULL)
+ {
+ EntriesSize = Entries * sizeof(pe[0]);
+ if (Entries != EntriesSize / sizeof(pe[0]))
+ {
+ /* Integer overflow! */
+ SetLastWin32Error(ERROR_INVALID_PARAMETER);
+ return 0;
+ }
+ }
+
+ if (!(dc = DC_Lock(hDC)))
+ {
+ SetLastWin32Error(ERROR_INVALID_HANDLE);
+ return 0;
+ }
+
+ palGDI = PALETTE_LockPalette(dc->hPalette);
+ if (palGDI != NULL)
+ {
+ if (pe != NULL)
+ {
+ if (StartIndex >= palGDI->NumColors)
+ Entries = 0;
+ else if (Entries > palGDI->NumColors - StartIndex)
+ Entries = palGDI->NumColors - StartIndex;
+
+ memcpy(pe,
+ palGDI->IndexedColors + StartIndex,
+ Entries * sizeof(pe[0]));
+
+ Ret = Entries;
+ }
+ else
+ {
+ Ret = dc->pPDevice->GDIInfo.ulNumPalReg;
+ }
+ }
+
+ if (palGDI != NULL)
+ PALETTE_UnlockPalette(palGDI);
+
+ if (dc != NULL)
+ DC_Unlock(dc);
+
+ return Ret;
+}
+
RGBQUAD *
NTAPI
DIB_MapPaletteColors(PDC dc, CONST BITMAPINFO* lpbmi)
@@ -114,7 +294,7 @@
USHORT *lpIndex;
PPALETTE palGDI;
- palGDI = NULL;//PALETTE_LockPalette(dc->hPalette);
+ palGDI = PALETTE_LockPalette(dc->hPalette);
UNIMPLEMENTED;
if (NULL == palGDI)
{
@@ -219,5 +399,11 @@
return hPal;
}
+VOID FASTCALL PALETTE_ValidateFlags(PALETTEENTRY* lpPalE, INT size)
+{
+ int i = 0;
+ for (; i<size ; i++)
+ lpPalE[i].peFlags = PC_SYS_USED | (lpPalE[i].peFlags & 0x07);
+}
/* EOF */
Modified: branches/arwinss/reactos/subsystems/win32/win32k/include/dc.h
URL:
http://svn.reactos.org/svn/reactos/branches/arwinss/reactos/subsystems/win3…
==============================================================================
--- branches/arwinss/reactos/subsystems/win32/win32k/include/dc.h [iso-8859-1] (original)
+++ branches/arwinss/reactos/subsystems/win32/win32k/include/dc.h [iso-8859-1] Sat Aug 15
20:10:34 2009
@@ -12,6 +12,7 @@
PBRUSHGDI pLineBrush;
COLORREF crForegroundClr;
COLORREF crBackgroundClr;
+ HPALETTE hPalette;
/* Origins and extents */
RECT rcDcRect; /* Relative to Vport */
Modified: branches/arwinss/reactos/subsystems/win32/win32k/include/palobj.h
URL:
http://svn.reactos.org/svn/reactos/branches/arwinss/reactos/subsystems/win3…
==============================================================================
--- branches/arwinss/reactos/subsystems/win32/win32k/include/palobj.h [iso-8859-1]
(original)
+++ branches/arwinss/reactos/subsystems/win32/win32k/include/palobj.h [iso-8859-1] Sat Aug
15 20:10:34 2009
@@ -17,6 +17,8 @@
//HDEV hPDev;
} PALETTE, *PPALETTE;
+HGDIOBJ hSystemPal;
+
HPALETTE FASTCALL PALETTE_AllocPalette(ULONG Mode,
ULONG NumColors,
ULONG *Colors,
@@ -27,6 +29,12 @@
HPALETTE FASTCALL
PALETTE_AllocPaletteIndexedRGB(ULONG NumColors,
CONST RGBQUAD *Colors);
+
+UINT APIENTRY
+GreGetSystemPaletteEntries(HDC hDC,
+ UINT StartIndex,
+ UINT Entries,
+ LPPALETTEENTRY pe);
RGBQUAD * NTAPI
DIB_MapPaletteColors(PDC dc, CONST BITMAPINFO* lpbmi);
@@ -41,6 +49,9 @@
GDIOBJ_FreeObjByHandle(hPalette, GDI_OBJECT_TYPE_PALETTE);
}
+VOID FASTCALL PALETTE_ValidateFlags(PALETTEENTRY* lpPalE, INT size);
+VOID APIENTRY PALETTE_Init(VOID);
+
#define PALETTE_LockPalette(hPalette) ((PPALETTE)GDIOBJ_LockObj((HGDIOBJ)hPalette,
GDI_OBJECT_TYPE_PALETTE))
#define PALETTE_UnlockPalette(pPalette) GDIOBJ_UnlockObjByPtr((PBASEOBJECT)pPalette)
Modified: branches/arwinss/reactos/subsystems/win32/win32k/main/init.c
URL:
http://svn.reactos.org/svn/reactos/branches/arwinss/reactos/subsystems/win3…
==============================================================================
--- branches/arwinss/reactos/subsystems/win32/win32k/main/init.c [iso-8859-1] (original)
+++ branches/arwinss/reactos/subsystems/win32/win32k/main/init.c [iso-8859-1] Sat Aug 15
20:10:34 2009
@@ -355,6 +355,7 @@
/* Create stock objects */
CreateStockBitmap();
+ PALETTE_Init();
/* Init video driver implementation */
InitDcImpl();