xref: /reactos/win32ss/gdi/eng/surface.h (revision 9592728f)
1 #pragma once
2 
3 /* GDI surface object */
4 typedef struct _SURFACE
5 {
6     BASEOBJECT  BaseObject;
7 
8     SURFOBJ     SurfObj;
9     //XDCOBJ *   pdcoAA;
10     FLONG       flags;
11     struct _PALETTE  * const ppal; // Use SURFACE_vSetPalette to assign a palette
12     struct _EWNDOBJ  *pWinObj;
13 
14     union
15     {
16         HANDLE  hSecureUMPD;  // if UMPD_SURFACE set
17         HANDLE  hMirrorParent;// if MIRROR_SURFACE set
18         HANDLE  hDDSurface;   // if DIRECTDRAW_SURFACE set
19     };
20 
21     SIZEL       sizlDim;      /* For SetBitmapDimension(), do NOT use
22                                to get width/height of bitmap, use
23                                bitmap.bmWidth/bitmap.bmHeight for
24                                that */
25 
26     HDC         hdc;          // Doc in "Undocumented Windows", page 546, seems to be supported with XP.
27     ULONG       cRef;
28     HPALETTE    hpalHint;
29 
30     /* For device-independent bitmaps: */
31     HANDLE      hDIBSection;
32     HANDLE      hSecure;
33     DWORD       dwOffset;
34     //UINT       unk_078;
35 
36   /* reactos specific */
37     DWORD biClrImportant;
38 } SURFACE, *PSURFACE;
39 
40 /* flags field */
41 enum _SURFACEFLAGS
42 {
43 //#define HOOK_BITBLT               0x00000001
44 //#define HOOK_STRETCHBLT           0x00000002
45 //#define HOOK_PLGBLT               0x00000004
46 //#define HOOK_TEXTOUT              0x00000008
47 //#define HOOK_PAINT                0x00000010
48 //#define HOOK_STROKEPATH           0x00000020
49 //#define HOOK_FILLPATH             0x00000040
50 //#define HOOK_STROKEANDFILLPATH    0x00000080
51 //#define HOOK_LINETO               0x00000100
52     SHAREACCESS_SURFACE       = 0x00000200,
53 //#define HOOK_COPYBITS             0x00000400
54 //#define REDIRECTION_SURFACE       0x00000800 // ?
55 //#define HOOK_MOVEPANNING          0x00000800
56 //#define HOOK_SYNCHRONIZE          0x00001000
57 //#define HOOK_STRETCHBLTROP        0x00002000
58 //#define HOOK_SYNCHRONIZEACCESS    0x00004000
59 //#define USE_DEVLOCK_SURFACE       0x00004000
60 //#define HOOK_TRANSPARENTBLT       0x00008000
61 //#define HOOK_ALPHABLEND           0x00010000
62 //#define HOOK_GRADIENTFILL         0x00020000
63 //#if (NTDDI_VERSION < 0x06000000)
64 // #define HOOK_FLAGS               0x0003B5FF
65 //#else
66 // #define HOOK_FLAGS               0x0003B5EF
67 //#endif
68     UMPD_SURFACE              = 0x00040000,
69     MIRROR_SURFACE            = 0x00080000,
70     DIRECTDRAW_SURFACE        = 0x00100000,
71     DRIVER_CREATED_SURFACE    = 0x00200000,
72     ENG_CREATE_DEVICE_SURFACE = 0x00400000,
73     DDB_SURFACE               = 0x00800000,
74     LAZY_DELETE_SURFACE       = 0x01000000,
75     BANDING_SURFACE           = 0x02000000,
76     API_BITMAP                = 0x04000000,
77     PALETTE_SELECT_SET        = 0x08000000,
78     UNREADABLE_SURFACE        = 0x10000000,
79     DYNAMIC_MODE_PALETTE      = 0x20000000,
80     ABORT_SURFACE             = 0x40000000,
81     PDEV_SURFACE              = 0x80000000
82 };
83 
84 #define BMF_POOLALLOC 0x100
85 
86 /*  Internal interface  */
87 
88 #define SURFACE_AllocSurfaceWithHandle()    ((PSURFACE) GDIOBJ_AllocObjWithHandle(GDI_OBJECT_TYPE_BITMAP, sizeof(SURFACE)))
89 
90 /* NOTE: Use shared locks! */
91 #define  SURFACE_ShareLockSurface(hBMObj) \
92   ((PSURFACE) GDIOBJ_ShareLockObj ((HGDIOBJ) hBMObj, GDI_OBJECT_TYPE_BITMAP))
93 FORCEINLINE
94 VOID
95 SURFACE_ShareLockByPointer(PSURFACE psurf)
96 {
97     GDIOBJ_vReferenceObjectByPointer(&psurf->BaseObject);
98 }
99 
100 #define  SURFACE_UnlockSurface(pBMObj)  \
101   GDIOBJ_vUnlockObject ((POBJ)pBMObj)
102 #define  SURFACE_ShareUnlockSurface(pBMObj)  \
103   GDIOBJ_vDereferenceObject ((POBJ)pBMObj)
104 
105 #define GDIDEV(SurfObj) ((PDEVOBJ *)((SurfObj)->hdev))
106 #define GDIDEVFUNCS(SurfObj) ((PDEVOBJ *)((SurfObj)->hdev))->DriverFunctions
107 
108 extern UCHAR gajBitsPerFormat[];
109 #define BitsPerFormat(Format) gajBitsPerFormat[Format]
110 
111 #define WIDTH_BYTES_ALIGN32(cx, bpp) ((((cx) * (bpp) + 31) & ~31) >> 3)
112 #define WIDTH_BYTES_ALIGN16(cx, bpp) ((((cx) * (bpp) + 15) & ~15) >> 3)
113 
114 ULONG
115 FASTCALL
116 BitmapFormat(ULONG cBits, ULONG iCompression);
117 
118 VOID
119 NTAPI
120 SURFACE_vCleanup(PVOID ObjectBody);
121 
122 PSURFACE
123 NTAPI
124 SURFACE_AllocSurface(
125     _In_ USHORT iType,
126     _In_ ULONG cx,
127     _In_ ULONG cy,
128     _In_ ULONG iFormat,
129     _In_ ULONG fjBitmap,
130     _In_opt_ ULONG cjWidth,
131     _In_opt_ ULONG cjBits,
132     _In_opt_ PVOID pvBits);
133 
134 FORCEINLINE
135 VOID
136 SURFACE_vSetPalette(
137     _Inout_ PSURFACE psurf,
138     _In_ PPALETTE ppal)
139 {
140     if (psurf->ppal)
141         GDIOBJ_vDereferenceObject((POBJ)psurf->ppal);
142     if (ppal)
143         GDIOBJ_vReferenceObjectByPointer((POBJ)ppal);
144     *(PVOID*)&psurf->ppal = ppal;
145 }
146 
147