ReactOS 0.4.15-dev-8093-g3285f69
surface.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _SURFACE
 

Macros

#define BMF_POOLALLOC   0x100
 
#define SURFACE_AllocSurfaceWithHandle()   ((PSURFACE) GDIOBJ_AllocObjWithHandle(GDI_OBJECT_TYPE_BITMAP, sizeof(SURFACE)))
 
#define SURFACE_ShareLockSurface(hBMObj)    ((PSURFACE) GDIOBJ_ShareLockObj ((HGDIOBJ) hBMObj, GDI_OBJECT_TYPE_BITMAP))
 
#define SURFACE_UnlockSurface(pBMObj)    GDIOBJ_vUnlockObject ((POBJ)pBMObj)
 
#define SURFACE_ShareUnlockSurface(pBMObj)    GDIOBJ_vDereferenceObject ((POBJ)pBMObj)
 
#define GDIDEV(SurfObj)   ((PDEVOBJ *)((SurfObj)->hdev))
 
#define GDIDEVFUNCS(SurfObj)   ((PDEVOBJ *)((SurfObj)->hdev))->DriverFunctions
 
#define BitsPerFormat(Format)   gajBitsPerFormat[Format]
 
#define WIDTH_BYTES_ALIGN32(cx, bpp)   ((((cx) * (bpp) + 31) & ~31) >> 3)
 
#define WIDTH_BYTES_ALIGN16(cx, bpp)   ((((cx) * (bpp) + 15) & ~15) >> 3)
 

Typedefs

typedef struct _SURFACE SURFACE
 
typedef struct _SURFACEPSURFACE
 

Enumerations

enum  _SURFACEFLAGS {
  SHAREACCESS_SURFACE = 0x00000200 , UMPD_SURFACE = 0x00040000 , MIRROR_SURFACE = 0x00080000 , DIRECTDRAW_SURFACE = 0x00100000 ,
  DRIVER_CREATED_SURFACE = 0x00200000 , ENG_CREATE_DEVICE_SURFACE = 0x00400000 , DDB_SURFACE = 0x00800000 , LAZY_DELETE_SURFACE = 0x01000000 ,
  BANDING_SURFACE = 0x02000000 , API_BITMAP = 0x04000000 , PALETTE_SELECT_SET = 0x08000000 , UNREADABLE_SURFACE = 0x10000000 ,
  DYNAMIC_MODE_PALETTE = 0x20000000 , ABORT_SURFACE = 0x40000000 , PDEV_SURFACE = 0x80000000
}
 

Functions

FORCEINLINE VOID SURFACE_ShareLockByPointer (PSURFACE psurf)
 
ULONG FASTCALL BitmapFormat (ULONG cBits, ULONG iCompression)
 
VOID NTAPI SURFACE_vCleanup (PVOID ObjectBody)
 
PSURFACE NTAPI SURFACE_AllocSurface (_In_ USHORT iType, _In_ ULONG cx, _In_ ULONG cy, _In_ ULONG iFormat, _In_ ULONG fjBitmap, _In_opt_ ULONG cjWidth, _In_opt_ ULONG cjBits, _In_opt_ PVOID pvBits)
 
FORCEINLINE VOID SURFACE_vSetPalette (_Inout_ PSURFACE psurf, _In_ PPALETTE ppal)
 

Variables

UCHAR gajBitsPerFormat []
 

Macro Definition Documentation

◆ BitsPerFormat

#define BitsPerFormat (   Format)    gajBitsPerFormat[Format]

Definition at line 109 of file surface.h.

◆ BMF_POOLALLOC

#define BMF_POOLALLOC   0x100

Definition at line 84 of file surface.h.

◆ GDIDEV

#define GDIDEV (   SurfObj)    ((PDEVOBJ *)((SurfObj)->hdev))

Definition at line 105 of file surface.h.

◆ GDIDEVFUNCS

#define GDIDEVFUNCS (   SurfObj)    ((PDEVOBJ *)((SurfObj)->hdev))->DriverFunctions

Definition at line 106 of file surface.h.

◆ SURFACE_AllocSurfaceWithHandle

#define SURFACE_AllocSurfaceWithHandle ( )    ((PSURFACE) GDIOBJ_AllocObjWithHandle(GDI_OBJECT_TYPE_BITMAP, sizeof(SURFACE)))

Definition at line 88 of file surface.h.

◆ SURFACE_ShareLockSurface

#define SURFACE_ShareLockSurface (   hBMObj)     ((PSURFACE) GDIOBJ_ShareLockObj ((HGDIOBJ) hBMObj, GDI_OBJECT_TYPE_BITMAP))

Definition at line 91 of file surface.h.

◆ SURFACE_ShareUnlockSurface

#define SURFACE_ShareUnlockSurface (   pBMObj)     GDIOBJ_vDereferenceObject ((POBJ)pBMObj)

Definition at line 102 of file surface.h.

◆ SURFACE_UnlockSurface

#define SURFACE_UnlockSurface (   pBMObj)     GDIOBJ_vUnlockObject ((POBJ)pBMObj)

Definition at line 100 of file surface.h.

◆ WIDTH_BYTES_ALIGN16

#define WIDTH_BYTES_ALIGN16 (   cx,
  bpp 
)    ((((cx) * (bpp) + 15) & ~15) >> 3)

Definition at line 112 of file surface.h.

◆ WIDTH_BYTES_ALIGN32

#define WIDTH_BYTES_ALIGN32 (   cx,
  bpp 
)    ((((cx) * (bpp) + 31) & ~31) >> 3)

Definition at line 111 of file surface.h.

Typedef Documentation

◆ PSURFACE

◆ SURFACE

Enumeration Type Documentation

◆ _SURFACEFLAGS

Enumerator
SHAREACCESS_SURFACE 
UMPD_SURFACE 
MIRROR_SURFACE 
DIRECTDRAW_SURFACE 
DRIVER_CREATED_SURFACE 
ENG_CREATE_DEVICE_SURFACE 
DDB_SURFACE 
LAZY_DELETE_SURFACE 
BANDING_SURFACE 
API_BITMAP 
PALETTE_SELECT_SET 
UNREADABLE_SURFACE 
DYNAMIC_MODE_PALETTE 
ABORT_SURFACE 
PDEV_SURFACE 

Definition at line 41 of file surface.h.

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};
@ MIRROR_SURFACE
Definition: surface.h:69
@ UNREADABLE_SURFACE
Definition: surface.h:78
@ BANDING_SURFACE
Definition: surface.h:75
@ LAZY_DELETE_SURFACE
Definition: surface.h:74
@ API_BITMAP
Definition: surface.h:76
@ DRIVER_CREATED_SURFACE
Definition: surface.h:71
@ ABORT_SURFACE
Definition: surface.h:80
@ PDEV_SURFACE
Definition: surface.h:81
@ UMPD_SURFACE
Definition: surface.h:68
@ ENG_CREATE_DEVICE_SURFACE
Definition: surface.h:72
@ DDB_SURFACE
Definition: surface.h:73
@ PALETTE_SELECT_SET
Definition: surface.h:77
@ SHAREACCESS_SURFACE
Definition: surface.h:52
@ DIRECTDRAW_SURFACE
Definition: surface.h:70
@ DYNAMIC_MODE_PALETTE
Definition: surface.h:79

Function Documentation

◆ BitmapFormat()

ULONG FASTCALL BitmapFormat ( ULONG  cBits,
ULONG  iCompression 
)

Definition at line 39 of file surface.c.

40{
41 switch (iCompression)
42 {
43 case BI_RGB:
44 /* Fall through */
45 case BI_BITFIELDS:
46 if (cBits <= 1) return BMF_1BPP;
47 if (cBits <= 4) return BMF_4BPP;
48 if (cBits <= 8) return BMF_8BPP;
49 if (cBits <= 16) return BMF_16BPP;
50 if (cBits <= 24) return BMF_24BPP;
51 if (cBits <= 32) return BMF_32BPP;
52 return 0;
53
54 case BI_RLE4:
55 return BMF_4RLE;
56
57 case BI_RLE8:
58 return BMF_8RLE;
59
60 default:
61 return 0;
62 }
63}
#define BI_RLE4
Definition: precomp.h:57
#define BI_RGB
Definition: precomp.h:56
#define BI_BITFIELDS
Definition: mmreg.h:507
#define BMF_16BPP
Definition: winddi.h:358
#define BMF_8BPP
Definition: winddi.h:357
#define BMF_1BPP
Definition: winddi.h:355
#define BMF_24BPP
Definition: winddi.h:359
#define BMF_32BPP
Definition: winddi.h:360
#define BMF_8RLE
Definition: winddi.h:362
#define BMF_4RLE
Definition: winddi.h:361
#define BMF_4BPP
Definition: winddi.h:356
#define BI_RLE8
Definition: wingdi.h:35

Referenced by DIB_CreateDIBSection(), GreCreateBitmap(), IntCreateDIBitmap(), IntSetDIBits(), NtGdiCreateBitmap(), NtGdiDdDDICreateDCFromMemory(), NtGdiSetDIBitsToDeviceInternal(), NtGdiStretchDIBitsInternal(), and SetDIBitsToDevice().

◆ SURFACE_AllocSurface()

PSURFACE NTAPI SURFACE_AllocSurface ( _In_ USHORT  iType,
_In_ ULONG  cx,
_In_ ULONG  cy,
_In_ ULONG  iFormat,
_In_ ULONG  fjBitmap,
_In_opt_ ULONG  cjWidth,
_In_opt_ ULONG  cjBits,
_In_opt_ PVOID  pvBits 
)

Definition at line 116 of file surface.c.

125{
126 ULONG cBitsPixel, cjBits, cjObject;
127 PSURFACE psurf;
128 SURFOBJ *pso;
129 PVOID pvSection;
130
131 NT_ASSERT(!pvBits || (iType == STYPE_BITMAP));
132 NT_ASSERT((iFormat <= BMF_32BPP) || (cjBufSize != 0));
133 NT_ASSERT((LONG)cy > 0);
134
135 /* Verify format */
136 if ((iFormat < BMF_1BPP) || (iFormat > BMF_PNG))
137 {
138 DPRINT1("Invalid bitmap format: %lu\n", iFormat);
139 return NULL;
140 }
141
142 /* Get bits per pixel from the format */
143 cBitsPixel = gajBitsPerFormat[iFormat];
144
145 /* Are bits and a width in bytes given? */
146 if (pvBits && cjWidth)
147 {
148 /* Align the width (Windows compatibility, drivers expect that) */
149 cjWidth = WIDTH_BYTES_ALIGN32((cjWidth << 3) / cBitsPixel, cBitsPixel);
150 }
151 else
152 {
153 /* Calculate width from the bitmap width in pixels */
154 cjWidth = WIDTH_BYTES_ALIGN32(cx, cBitsPixel);
155 }
156
157 /* Is this an uncompressed format? */
158 if (iFormat <= BMF_32BPP)
159 {
160 /* Calculate the correct bitmap size in bytes */
161 if (!NT_SUCCESS(RtlULongMult(cjWidth, cy, &cjBits)))
162 {
163 DPRINT1("Overflow calculating size: cjWidth %lu, cy %lu\n",
164 cjWidth, cy);
165 return NULL;
166 }
167
168 /* Did we get a buffer and size? */
169 if ((pvBits != NULL) && (cjBufSize != 0))
170 {
171 /* Make sure the buffer is large enough */
172 if (cjBufSize < cjBits)
173 {
174 DPRINT1("Buffer is too small, required: %lu, got %lu\n",
175 cjBits, cjBufSize);
176 return NULL;
177 }
178 }
179 }
180 else
181 {
182 /* Compressed format, use the provided size */
183 NT_ASSERT(cjBufSize != 0);
184 cjBits = cjBufSize;
185 }
186
187 /* Check if we need an extra large object */
188 if ((iType == STYPE_BITMAP) && (pvBits == NULL) &&
189 !(fjBitmap & BMF_USERMEM) && !(fjBitmap & BMF_KMSECTION))
190 {
191 /* Allocate an object large enough to hold the bits */
192 cjObject = sizeof(SURFACE) + cjBits;
193 }
194 else
195 {
196 /* Otherwise just allocate the SURFACE structure */
197 cjObject = sizeof(SURFACE);
198 }
199
200 /* Check for arithmetic overflow */
201 if (cjObject < sizeof(SURFACE))
202 {
203 /* Fail! */
204 DPRINT1("Overflow calculating cjObject: cjBits %lu\n", cjBits);
205 return NULL;
206 }
207
208 /* Allocate a SURFACE object */
210 if (!psurf)
211 {
212 return NULL;
213 }
214
215 /* Initialize the basic fields */
216 pso = &psurf->SurfObj;
217 pso->hsurf = psurf->BaseObject.hHmgr;
218 pso->sizlBitmap.cx = cx;
219 pso->sizlBitmap.cy = cy;
220 pso->iBitmapFormat = iFormat;
221 pso->iType = iType;
222 pso->fjBitmap = (USHORT)fjBitmap;
224 pso->cjBits = cjBits;
225
226 /* Check if we need a bitmap buffer */
227 if (iType == STYPE_BITMAP)
228 {
229 /* Check if we got one or if we need to allocate one */
230 if (pvBits != NULL)
231 {
232 /* Use the caller provided buffer */
233 pso->pvBits = pvBits;
234 }
235 else if (fjBitmap & BMF_USERMEM)
236 {
237 /* User mode memory was requested */
238 pso->pvBits = EngAllocUserMem(cjBits, 0);
239
240 /* Check for failure */
241 if (!pso->pvBits)
242 {
244 return NULL;
245 }
246 }
247 else if (fjBitmap & BMF_KMSECTION)
248 {
249 /* Use a kernel mode section */
250 pso->pvBits = EngAllocSectionMem(&pvSection,
251 (fjBitmap & BMF_NOZEROINIT) ?
252 0 : FL_ZERO_MEMORY,
253 cjBits, TAG_DIB);
254
255 /* Check for failure */
256 if (!pso->pvBits)
257 {
259 return NULL;
260 }
261
262 /* Free the section already, but keep the mapping */
263 EngFreeSectionMem(pvSection, NULL);
264 }
265 else
266 {
267 /* Buffer is after the object */
268 pso->pvBits = psurf + 1;
269
270 /* Zero the buffer, except requested otherwise */
271 if (!(fjBitmap & BMF_NOZEROINIT))
272 {
273 RtlZeroMemory(pso->pvBits, cjBits);
274 }
275 }
276
277 /* Set pvScan0 and lDelta */
278 if (fjBitmap & BMF_TOPDOWN)
279 {
280 /* Topdown is the normal way */
281 pso->pvScan0 = pso->pvBits;
282 pso->lDelta = cjWidth;
283 }
284 else
285 {
286 /* Inversed bitmap (bottom up) */
287 pso->pvScan0 = ((PCHAR)pso->pvBits + pso->cjBits - cjWidth);
288 pso->lDelta = -(LONG)cjWidth;
289 }
290 }
291 else
292 {
293 /* There are no bitmap bits */
294 pso->pvScan0 = pso->pvBits = NULL;
295 pso->lDelta = 0;
296 }
297
298 /* Assign a default palette and increment its reference count */
300
301 return psurf;
302}
#define InterlockedIncrement
Definition: armddk.h:53
#define DPRINT1
Definition: precomp.h:8
HGDIOBJ hHmgr(VOID)
Definition: baseobj.hpp:95
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define GDI_OBJECT_TYPE_BITMAP
Definition: gdi.h:48
#define PCHAR
Definition: match.c:90
long LONG
Definition: pedump.c:60
unsigned short USHORT
Definition: pedump.c:61
#define FL_ZERO_MEMORY
Definition: polytest.cpp:58
_Out_opt_ int _Out_opt_ int * cy
Definition: commctrl.h:586
_Out_opt_ int * cx
Definition: commctrl.h:585
SURFOBJ SurfObj
Definition: surface.h:8
BASEOBJECT BaseObject
Definition: surface.h:6
HSURF hsurf
Definition: winddi.h:1206
#define WIDTH_BYTES_ALIGN32(cx, bpp)
Definition: swimpl.c:16
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG
Definition: typedefs.h:59
BOOL APIENTRY EngFreeSectionMem(_In_opt_ PVOID pvSection, _In_opt_ PVOID pvMappedBase)
Definition: mapping.c:246
UCHAR gajBitsPerFormat[11]
Definition: surface.c:21
LONG giUniqueSurface
Definition: surface.c:18
struct _SURFACE SURFACE
FORCEINLINE VOID SURFACE_vSetPalette(_Inout_ PSURFACE psurf, _In_ PPALETTE ppal)
Definition: surface.h:136
struct _SURFACE * PSURFACE
POBJ NTAPI GDIOBJ_AllocObjWithHandle(ULONG ObjectType, ULONG cjSize)
Definition: gdiobj.c:1522
VOID NTAPI GDIOBJ_vDeleteObject(POBJ pobj)
Definition: gdiobj.c:1111
PPALETTE appalSurfaceDefault[11]
Definition: palette.c:21
#define TAG_DIB
Definition: tags.h:17
#define STYPE_BITMAP
Definition: winddi.h:1175
_In_ HANDLE _In_ SURFOBJ * pso
Definition: winddi.h:3665
#define BMF_PNG
Definition: winddi.h:364
#define BMF_TOPDOWN
Definition: winddi.h:1180
#define BMF_USERMEM
Definition: winddi.h:1183
_In_ ULONG iType
Definition: winddi.h:3748
#define BMF_NOZEROINIT
Definition: winddi.h:1181
#define BMF_KMSECTION
Definition: winddi.h:1184
_In_ SIZEL _In_ ULONG iFormat
Definition: winddi.h:3468
#define NT_ASSERT
Definition: rtlfuncs.h:3310

Referenced by EngCreateBitmap(), EngCreateDeviceBitmap(), EngCreateDeviceSurface(), GreCreateBitmapEx(), IntEngMaskBlt(), NtGdiCreateBitmap(), NtGdiDdDDICreateDCFromMemory(), NtGdiGetPixel(), and UserDrawIconEx().

◆ SURFACE_ShareLockByPointer()

FORCEINLINE VOID SURFACE_ShareLockByPointer ( PSURFACE  psurf)

Definition at line 95 of file surface.h.

96{
98}
VOID NTAPI GDIOBJ_vReferenceObjectByPointer(POBJ pobj)
Definition: gdiobj.c:734

Referenced by NtGdiExtEscape().

◆ SURFACE_vCleanup()

VOID NTAPI SURFACE_vCleanup ( PVOID  ObjectBody)

Definition at line 67 of file surface.c.

68{
69 PSURFACE psurf = (PSURFACE)ObjectBody;
70 PVOID pvBits = psurf->SurfObj.pvBits;
71
72 /* Check if the surface has bits */
73 if (pvBits)
74 {
75 /* Only bitmaps can have bits */
77
78 /* Check if it is a DIB section */
79 if (psurf->hDIBSection)
80 {
81 /* Unmap the section view */
82 EngUnmapSectionView(pvBits, psurf->dwOffset, psurf->hSecure);
83 }
84 else if (psurf->SurfObj.fjBitmap & BMF_USERMEM)
85 {
86 /* Bitmap was allocated from usermode memory */
87 EngFreeUserMem(pvBits);
88 }
89 else if (psurf->SurfObj.fjBitmap & BMF_KMSECTION)
90 {
91 /* Bitmap was allocated from a kernel section */
92 if (!EngFreeSectionMem(NULL, pvBits))
93 {
94 DPRINT1("EngFreeSectionMem failed for %p!\n", pvBits);
95 // Should we BugCheck here?
97 }
98 }
99 else if (psurf->SurfObj.fjBitmap & BMF_POOLALLOC)
100 {
101 /* Free a pool allocation */
102 EngFreeMem(pvBits);
103 }
104 }
105
106 /* Free palette */
107 if(psurf->ppal)
108 {
110 }
111}
#define FALSE
Definition: types.h:117
#define ASSERT(a)
Definition: mode.c:44
#define EngFreeMem
Definition: polytest.cpp:56
HANDLE hDIBSection
Definition: surface.h:31
HANDLE hSecure
Definition: surface.h:32
DWORD dwOffset
Definition: surface.h:33
struct _PALETTE *const ppal
Definition: surface.h:11
USHORT iType
Definition: winddi.h:1216
USHORT fjBitmap
Definition: winddi.h:1217
PVOID pvBits
Definition: winddi.h:1211
VOID NTAPI EngUnmapSectionView(_In_ PVOID pvBits, _In_ ULONG cjOffset, _In_ HANDLE hSecure)
Definition: mapping.c:71
#define BMF_POOLALLOC
Definition: surface.h:84
#define PALETTE_ShareUnlockPalette(ppal)
Definition: palette.h:59
ENGAPI VOID APIENTRY EngFreeUserMem(_Pre_notnull_ __drv_freesMem(UserMem) PVOID pv)

◆ SURFACE_vSetPalette()

FORCEINLINE VOID SURFACE_vSetPalette ( _Inout_ PSURFACE  psurf,
_In_ PPALETTE  ppal 
)

Definition at line 136 of file surface.h.

139{
140 if (psurf->ppal)
141 GDIOBJ_vDereferenceObject((POBJ)psurf->ppal);
142 if (ppal)
144 *(PVOID*)&psurf->ppal = ppal;
145}
VOID NTAPI GDIOBJ_vDereferenceObject(POBJ pobj)
Definition: gdiobj.c:631

Referenced by BITMAP_CopyBitmap(), DIB_CreateDIBSection(), EngAssociateSurface(), EngModifySurface(), IntCreateCompatibleBitmap(), IntCreateDIBitmap(), NtGdiDdDDICreateDCFromMemory(), and SURFACE_AllocSurface().

Variable Documentation

◆ gajBitsPerFormat