2010-02-26 11:43:19 +00:00
|
|
|
#pragma once
|
2002-09-24 20:25:49 +00:00
|
|
|
|
2015-03-25 22:32:22 +00:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma warning(disable:4200) // zero-sized array in struct/union
|
|
|
|
#endif // _MSC_VER
|
|
|
|
|
2007-12-02 03:08:00 +00:00
|
|
|
// Palette mode flags
|
2012-07-29 11:20:05 +00:00
|
|
|
enum _PALFLAGS
|
|
|
|
{
|
|
|
|
#ifndef _WINDDI_ // Defined in ddk/winddi.h
|
|
|
|
PAL_INDEXED = 0x00000001, // Indexed palette
|
|
|
|
PAL_BITFIELDS = 0x00000002, // Bit fields used for DIB, DIB section
|
|
|
|
PAL_RGB = 0x00000004, // Red, green, blue
|
|
|
|
PAL_BGR = 0x00000008, // Blue, green, red
|
|
|
|
PAL_CMYK = 0x00000010, // Cyan, magenta, yellow, black
|
2007-12-02 03:08:00 +00:00
|
|
|
#endif
|
2012-07-29 11:20:05 +00:00
|
|
|
PAL_DC = 0x00000100,
|
|
|
|
PAL_FIXED = 0x00000200, // Can't be changed
|
|
|
|
PAL_FREE = 0x00000400,
|
|
|
|
PAL_MANAGED = 0x00000800,
|
|
|
|
PAL_NOSTATIC = 0x00001000,
|
|
|
|
PAL_MONOCHROME = 0x00002000, // Two colors only
|
|
|
|
PAL_BRUSHHACK = 0x00004000,
|
|
|
|
PAL_DIBSECTION = 0x00008000, // Used for a DIB section
|
|
|
|
PAL_NOSTATIC256 = 0x00010000,
|
|
|
|
PAL_HT = 0x00100000, // Halftone palette
|
|
|
|
PAL_RGB16_555 = 0x00200000, // 16-bit RGB in 555 format
|
|
|
|
PAL_RGB16_565 = 0x00400000, // 16-bit RGB in 565 format
|
|
|
|
PAL_GAMMACORRECTION = 0x00800000, // Correct colors
|
|
|
|
};
|
2007-12-02 03:08:00 +00:00
|
|
|
|
2009-04-09 22:28:54 +00:00
|
|
|
typedef struct _PALETTE
|
2008-02-26 01:00:34 +00:00
|
|
|
{
|
2012-05-02 09:46:07 +00:00
|
|
|
/* Header for all gdi objects in the handle table.
|
|
|
|
Do not (re)move this. */
|
|
|
|
BASEOBJECT BaseObject;
|
|
|
|
|
|
|
|
PALOBJ PalObj;
|
|
|
|
XLATEOBJ *logicalToSystem;
|
|
|
|
FLONG flFlags; // PAL_INDEXED, PAL_BITFIELDS, PAL_RGB, PAL_BGR
|
|
|
|
ULONG NumColors;
|
|
|
|
PALETTEENTRY *IndexedColors;
|
|
|
|
ULONG RedMask;
|
|
|
|
ULONG GreenMask;
|
|
|
|
ULONG BlueMask;
|
|
|
|
ULONG ulRedShift;
|
|
|
|
ULONG ulGreenShift;
|
|
|
|
ULONG ulBlueShift;
|
|
|
|
HDEV hPDev;
|
|
|
|
PALETTEENTRY apalColors[0];
|
2014-12-28 20:50:35 +00:00
|
|
|
} PALETTE, *PPALETTE;
|
2003-08-28 12:35:59 +00:00
|
|
|
|
2012-05-08 23:21:09 +00:00
|
|
|
extern PALETTE gpalRGB, gpalBGR, gpalRGB555, gpalRGB565, *gppalMono, *gppalDefault;
|
2010-06-09 02:57:52 +00:00
|
|
|
extern PPALETTE appalSurfaceDefault[];
|
2009-07-10 13:40:36 +00:00
|
|
|
|
[WIN32K]
Rewrite of the GDI handle manager
- The old handle manager used a completely retarded spinlock in combination with KeDelayExecutionThread() for both exclusive
and shared locks. This is probably the most uneffective algorithm possible. It was also duplicating code everywhere and it was a overall mess It
is now replaced with a lock-free reference counter for shared locks and a pushlock for exclusive locks. -> Better performance and scalability.
- Allocate user mode object attributes from the new gdi pool. This way, we don't need any caching, since the pool serves as a cache. Its also
much faster and uses much less memory.
- Allow object allocations of different size, instead of fixed size from a table. This way a single allocation can take care of actual needs.
- Allow allcoating objects without a handle and insert them into the handle table later
- Properly synchronize the process GDIHandleCount. Now gdiview and taskmanager show the correct number of gdi handles.
- Implement a new event tracking system, that is capable of tracking all reverences and locks of objects and pool allocations to help track
possible leaks
- Make sure that all objects of a process are deleted in cleanup
- Make sure all usermode memory allocations are freed, when cleaning up the process pool.
- Make sure that each object type is using the correct type of lock (either shared or exclusive, not a mixture)
- Fix some object / reference leaks
- Lots of inferface improvements
- Use global variables for certain things instead of members in the mapped gdi handle table
- Make IntSysCreateRectpRgn create a region without a handle
- Fix detection od source and mask use in GreStretchBltMask
- Use GDIOBJ_bLockMultipleObjects in NtGdiCombineRegion to avoid possible deadlocks
- Fix NtGdiAbortPath to reset DCPATH_ACTIVE flag in the dc and only bail out on error, instead of always
- Replace DC_AllocateDcAttr and DC_AllocDcAttr with DC_bAllocDcAttr using the new user mode pool
- Remove DCU_SyncDcAttrtoUser and DCU_SynchDcAttrtoUser. Those functions were unused and didn't do anything useful anyway,
- Replace IntGdiSetDCOwnerEx and DC_SetOwnership with GreSetDCOwner, remove unused NoSetBrush parameter
- Replace GDIOBJ_bValidateHandle and IsObjectDead with GreIsHandleValid
- Chage GDIOBJ_bLockMultipleObjects: pass object type, return a BOOL, whether all objects could be locked, cleanup on failure
svn path=/trunk/; revision=51470
2011-04-28 08:26:46 +00:00
|
|
|
#define PALETTE_UnlockPalette(pPalette) GDIOBJ_vUnlockObject((POBJ)pPalette)
|
2009-07-15 21:06:40 +00:00
|
|
|
#define PALETTE_ShareLockPalette(hpal) \
|
|
|
|
((PPALETTE)GDIOBJ_ShareLockObj((HGDIOBJ)hpal, GDI_OBJECT_TYPE_PALETTE))
|
|
|
|
#define PALETTE_ShareUnlockPalette(ppal) \
|
[WIN32K]
Rewrite of the GDI handle manager
- The old handle manager used a completely retarded spinlock in combination with KeDelayExecutionThread() for both exclusive
and shared locks. This is probably the most uneffective algorithm possible. It was also duplicating code everywhere and it was a overall mess It
is now replaced with a lock-free reference counter for shared locks and a pushlock for exclusive locks. -> Better performance and scalability.
- Allocate user mode object attributes from the new gdi pool. This way, we don't need any caching, since the pool serves as a cache. Its also
much faster and uses much less memory.
- Allow object allocations of different size, instead of fixed size from a table. This way a single allocation can take care of actual needs.
- Allow allcoating objects without a handle and insert them into the handle table later
- Properly synchronize the process GDIHandleCount. Now gdiview and taskmanager show the correct number of gdi handles.
- Implement a new event tracking system, that is capable of tracking all reverences and locks of objects and pool allocations to help track
possible leaks
- Make sure that all objects of a process are deleted in cleanup
- Make sure all usermode memory allocations are freed, when cleaning up the process pool.
- Make sure that each object type is using the correct type of lock (either shared or exclusive, not a mixture)
- Fix some object / reference leaks
- Lots of inferface improvements
- Use global variables for certain things instead of members in the mapped gdi handle table
- Make IntSysCreateRectpRgn create a region without a handle
- Fix detection od source and mask use in GreStretchBltMask
- Use GDIOBJ_bLockMultipleObjects in NtGdiCombineRegion to avoid possible deadlocks
- Fix NtGdiAbortPath to reset DCPATH_ACTIVE flag in the dc and only bail out on error, instead of always
- Replace DC_AllocateDcAttr and DC_AllocDcAttr with DC_bAllocDcAttr using the new user mode pool
- Remove DCU_SyncDcAttrtoUser and DCU_SynchDcAttrtoUser. Those functions were unused and didn't do anything useful anyway,
- Replace IntGdiSetDCOwnerEx and DC_SetOwnership with GreSetDCOwner, remove unused NoSetBrush parameter
- Replace GDIOBJ_bValidateHandle and IsObjectDead with GreIsHandleValid
- Chage GDIOBJ_bLockMultipleObjects: pass object type, return a BOOL, whether all objects could be locked, cleanup on failure
svn path=/trunk/; revision=51470
2011-04-28 08:26:46 +00:00
|
|
|
GDIOBJ_vDereferenceObject(&ppal->BaseObject)
|
2009-07-15 21:06:40 +00:00
|
|
|
|
2012-05-02 09:46:07 +00:00
|
|
|
INIT_FUNCTION
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
InitPaletteImpl(VOID);
|
2003-05-18 17:16:18 +00:00
|
|
|
|
2012-05-02 09:46:07 +00:00
|
|
|
PPALETTE
|
|
|
|
NTAPI
|
2012-05-05 17:29:34 +00:00
|
|
|
PALETTE_AllocPalette(
|
2012-05-02 09:46:07 +00:00
|
|
|
_In_ ULONG iMode,
|
|
|
|
_In_ ULONG cColors,
|
2014-06-30 18:27:44 +00:00
|
|
|
_In_opt_ const PALETTEENTRY* pEntries,
|
2012-05-02 09:46:07 +00:00
|
|
|
_In_ FLONG flRed,
|
|
|
|
_In_ FLONG flGreen,
|
|
|
|
_In_ FLONG flBlue);
|
2007-04-23 15:32:04 +00:00
|
|
|
|
2012-05-02 09:46:07 +00:00
|
|
|
PPALETTE
|
|
|
|
NTAPI
|
|
|
|
PALETTE_AllocPalWithHandle(
|
|
|
|
_In_ ULONG iMode,
|
|
|
|
_In_ ULONG cColors,
|
2014-06-30 18:27:44 +00:00
|
|
|
_In_opt_ const PALETTEENTRY* pEntries,
|
2012-05-02 09:46:07 +00:00
|
|
|
_In_ FLONG flRed,
|
|
|
|
_In_ FLONG flGreen,
|
|
|
|
_In_ FLONG flBlue);
|
|
|
|
|
|
|
|
VOID
|
|
|
|
FASTCALL
|
|
|
|
PALETTE_ValidateFlags(
|
|
|
|
PALETTEENTRY* lpPalE,
|
|
|
|
INT size);
|
|
|
|
|
|
|
|
INT
|
|
|
|
FASTCALL
|
|
|
|
PALETTE_GetObject(
|
|
|
|
PPALETTE pGdiObject,
|
|
|
|
INT cbCount,
|
|
|
|
LPLOGBRUSH lpBuffer);
|
|
|
|
|
|
|
|
ULONG
|
|
|
|
NTAPI
|
|
|
|
PALETTE_ulGetNearestPaletteIndex(
|
|
|
|
PPALETTE ppal,
|
|
|
|
ULONG iColor);
|
|
|
|
|
|
|
|
ULONG
|
|
|
|
NTAPI
|
|
|
|
PALETTE_ulGetNearestIndex(
|
|
|
|
PPALETTE ppal,
|
|
|
|
ULONG iColor);
|
|
|
|
|
|
|
|
ULONG
|
|
|
|
NTAPI
|
|
|
|
PALETTE_ulGetNearestBitFieldsIndex(
|
|
|
|
PPALETTE ppal,
|
|
|
|
ULONG ulColor);
|
|
|
|
|
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
PALETTE_vGetBitMasks(
|
|
|
|
PPALETTE ppal,
|
|
|
|
PULONG pulColors);
|
|
|
|
|
2014-05-22 11:45:53 +00:00
|
|
|
VOID
|
2012-05-02 09:46:07 +00:00
|
|
|
NTAPI
|
2014-05-22 11:45:53 +00:00
|
|
|
PALETTE_vCleanup(PVOID ObjectBody);
|
2008-06-03 03:41:54 +00:00
|
|
|
|
2009-08-04 20:37:10 +00:00
|
|
|
FORCEINLINE
|
2014-05-04 09:45:42 +00:00
|
|
|
ULONG
|
2009-08-04 20:37:10 +00:00
|
|
|
CalculateShift(ULONG ulMask1, ULONG ulMask2)
|
|
|
|
{
|
|
|
|
ULONG ulShift1, ulShift2;
|
|
|
|
BitScanReverse(&ulShift1, ulMask1);
|
|
|
|
BitScanReverse(&ulShift2, ulMask2);
|
|
|
|
ulShift2 -= ulShift1;
|
|
|
|
if ((INT)ulShift2 < 0) ulShift2 += 32;
|
|
|
|
return ulShift2;
|
|
|
|
}
|
|
|
|
|
2009-07-04 13:56:33 +00:00
|
|
|
FORCEINLINE
|
|
|
|
ULONG
|
|
|
|
PALETTE_ulGetRGBColorFromIndex(PPALETTE ppal, ULONG ulIndex)
|
|
|
|
{
|
2012-04-27 16:46:12 +00:00
|
|
|
if (ulIndex >= ppal->NumColors) return 0;
|
2009-07-04 13:56:33 +00:00
|
|
|
return RGB(ppal->IndexedColors[ulIndex].peRed,
|
|
|
|
ppal->IndexedColors[ulIndex].peGreen,
|
|
|
|
ppal->IndexedColors[ulIndex].peBlue);
|
|
|
|
}
|
2012-04-01 20:42:43 +00:00
|
|
|
|
2012-05-05 21:39:35 +00:00
|
|
|
FORCEINLINE
|
|
|
|
VOID
|
|
|
|
PALETTE_vSetRGBColorForIndex(PPALETTE ppal, ULONG ulIndex, COLORREF crColor)
|
|
|
|
{
|
|
|
|
if (ulIndex >= ppal->NumColors) return;
|
|
|
|
ppal->IndexedColors[ulIndex].peRed = GetRValue(crColor);
|
|
|
|
ppal->IndexedColors[ulIndex].peGreen = GetGValue(crColor);
|
|
|
|
ppal->IndexedColors[ulIndex].peBlue = GetBValue(crColor);
|
|
|
|
}
|
|
|
|
|
2012-05-02 09:46:07 +00:00
|
|
|
HPALETTE
|
|
|
|
NTAPI
|
|
|
|
GreCreatePaletteInternal(
|
|
|
|
IN LPLOGPALETTE pLogPal,
|
|
|
|
IN UINT cEntries);
|
|
|
|
|