ReactOS  r76032
surface.c File Reference
#include <win32k.h>
#include <debug.h>
Include dependency graph for surface.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

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 cjBufSize, _In_opt_ PVOID pvBits)
 
HBITMAP APIENTRY EngCreateBitmap (_In_ SIZEL sizl, _In_ LONG lWidth, _In_ ULONG iFormat, _In_ ULONG fl, _In_opt_ PVOID pvBits)
 
HBITMAP APIENTRY EngCreateDeviceBitmap (_In_ DHSURF dhsurf, _In_ SIZEL sizl, _In_ ULONG iFormat)
 
HSURF APIENTRY EngCreateDeviceSurface (_In_ DHSURF dhsurf, _In_ SIZEL sizl, _In_ ULONG iFormat)
 
BOOL APIENTRY EngAssociateSurface (_In_ HSURF hsurf, _In_ HDEV hdev, _In_ FLONG flHooks)
 
BOOL APIENTRY EngModifySurface (_In_ HSURF hsurf, _In_ HDEV hdev, _In_ FLONG flHooks, _In_ FLONG flSurface, _In_ DHSURF dhsurf, _In_ PVOID pvScan0, _In_ LONG lDelta, _Reserved_ PVOID pvReserved)
 
BOOL APIENTRY EngDeleteSurface (_In_ _Post_ptr_invalid_ HSURF hsurf)
 
BOOL APIENTRY EngEraseSurface (_In_ SURFOBJ *pso, _In_ RECTL *prcl, _In_ ULONG iColor)
 
SURFOBJ *APIENTRY NtGdiEngLockSurface (IN HSURF hsurf)
 
SURFOBJ *APIENTRY EngLockSurface (_In_ HSURF hsurf)
 
__kernel_entry NTSTATUS APIENTRY NtGdiEngUnlockSurface (_In_ SURFOBJ *pso)
 
VOID APIENTRY EngUnlockSurface (_In_ _Post_ptr_invalid_ SURFOBJ *pso)
 

Variables

LONG giUniqueSurface = 0
 
UCHAR gajBitsPerFormat [11]
 

Macro Definition Documentation

#define NDEBUG

Definition at line 15 of file surface.c.

Function Documentation

ULONG FASTCALL BitmapFormat ( ULONG  cBits,
ULONG  iCompression 
)

Definition at line 39 of file surface.c.

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

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 BMF_24BPP
Definition: winddi.h:359
#define BMF_32BPP
Definition: winddi.h:360
#define BMF_8RLE
Definition: winddi.h:362
#define BI_BITFIELDS
Definition: mmreg.h:505
Definition: xlate.c:8
#define BMF_4RLE
Definition: winddi.h:361
#define BMF_16BPP
Definition: winddi.h:358
Definition: xlate.c:9
Definition: xlate.c:10
#define BI_RLE4
Definition: precomp.h:36
#define BI_RLE8
Definition: wingdi.h:35
#define BI_RGB
Definition: precomp.h:35
BOOL APIENTRY EngAssociateSurface ( _In_ HSURF  hsurf,
_In_ HDEV  hdev,
_In_ FLONG  flHooks 
)

Definition at line 428 of file surface.c.

Referenced by DrvEnableSurface().

432 {
433  SURFOBJ *pso;
434  PSURFACE psurf;
435  PDEVOBJ* ppdev;
436  PPALETTE ppal;
437 
438  ppdev = (PDEVOBJ*)hdev;
439 
440  /* Lock the surface */
441  psurf = SURFACE_ShareLockSurface(hsurf);
442  if (!psurf)
443  {
444  return FALSE;
445  }
446  pso = &psurf->SurfObj;
447 
448  /* Associate the hdev */
449  pso->hdev = hdev;
450  pso->dhpdev = ppdev->dhpdev;
451 
452  /* Hook up specified functions */
453  psurf->flags &= ~HOOK_FLAGS;
454  psurf->flags |= (flHooks & HOOK_FLAGS);
455 
456  /* Assign the PDEV's palette */
458  SURFACE_vSetPalette(psurf, ppal);
460 
462 
463  return TRUE;
464 }
DHPDEV dhpdev
Definition: pdevobj.h:121
DHPDEV dhpdev
Definition: winddi.h:1207
#define TRUE
Definition: types.h:120
#define SURFACE_ShareUnlockSurface(pBMObj)
Definition: surface.h:95
#define SURFACE_ShareLockSurface(hBMObj)
Definition: surface.h:91
#define FALSE
Definition: types.h:117
#define HOOK_FLAGS
Definition: winddi.h:1438
SURFOBJ SurfObj
Definition: surface.h:8
HPALETTE hpalDefault
Definition: winddi.h:398
#define PALETTE_ShareLockPalette(hpal)
Definition: palette.h:57
_In_ HANDLE _In_ SURFOBJ * pso
Definition: winddi.h:3664
DEVINFO devinfo
Definition: pdevobj.h:123
FORCEINLINE VOID SURFACE_vSetPalette(_Inout_ PSURFACE psurf, _In_ PPALETTE ppal)
Definition: surface.h:129
HDEV hdev
Definition: winddi.h:1208
FLONG flags
Definition: surface.h:10
#define PALETTE_ShareUnlockPalette(ppal)
Definition: palette.h:59
_In_ HDEV hdev
Definition: winddi.h:3449
HBITMAP APIENTRY EngCreateBitmap ( _In_ SIZEL  sizl,
_In_ LONG  lWidth,
_In_ ULONG  iFormat,
_In_ ULONG  fl,
_In_opt_ PVOID  pvBits 
)

Definition at line 306 of file surface.c.

Referenced by DrvEnableSurface().

312 {
313  PSURFACE psurf;
314  HBITMAP hbmp;
315 
316  /* Allocate a surface */
318  sizl.cx,
319  sizl.cy,
320  iFormat,
321  fl,
322  lWidth,
323  0,
324  pvBits);
325  if (!psurf)
326  {
327  DPRINT1("SURFACE_AllocSurface failed. (STYPE_BITMAP, sizl.cx=%ld, sizl.cy=%ld, iFormat=%lu, fl=%lu, lWidth=%ld, pvBits=0x%p)\n",
328  sizl.cx, sizl.cy, iFormat, fl, lWidth, pvBits);
329  return NULL;
330  }
331 
332  /* Get the handle for the bitmap */
333  hbmp = (HBITMAP)psurf->SurfObj.hsurf;
334 
335  /* Set public ownership */
337 
338  /* Unlock the surface and return */
339  SURFACE_UnlockSurface(psurf);
340  return hbmp;
341 }
#define HBITMAP
Definition: msvc.h:28
#define STYPE_BITMAP
Definition: winddi.h:1175
_In_ SIZEL sizl
Definition: winddi.h:3467
_In_ FLONG fl
Definition: winddi.h:1279
SURFOBJ SurfObj
Definition: surface.h:8
HSURF hsurf
Definition: winddi.h:1206
smooth NULL
Definition: ftsmooth.c:557
BASEOBJECT BaseObject
Definition: surface.h:6
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 cjBufSize, _In_opt_ PVOID pvBits)
Definition: surface.c:116
_In_ SIZEL _In_ ULONG iFormat
Definition: winddi.h:3467
#define SURFACE_UnlockSurface(pBMObj)
Definition: surface.h:93
#define GDI_OBJ_HMGR_PUBLIC
Definition: ntgdihdl.h:116
#define DPRINT1
Definition: precomp.h:8
VOID NTAPI GDIOBJ_vSetObjectOwner(POBJ pobj, ULONG ulNewOwner)
Definition: gdiobj.c:960
HBITMAP hbmp
Definition: msvc.h:60
HBITMAP APIENTRY EngCreateDeviceBitmap ( _In_ DHSURF  dhsurf,
_In_ SIZEL  sizl,
_In_ ULONG  iFormat 
)

Definition at line 348 of file surface.c.

352 {
353  PSURFACE psurf;
354  HBITMAP hbmp;
355 
356  /* Allocate a surface */
358  sizl.cx,
359  sizl.cy,
360  iFormat,
361  0,
362  0,
363  0,
364  NULL);
365  if (!psurf)
366  {
367  DPRINT1("SURFACE_AllocSurface failed. (STYPE_DEVBITMAP, sizl.cx=%ld, sizl.cy=%ld, iFormat=%lu)\n",
368  sizl.cx, sizl.cy, iFormat);
369  return NULL;
370  }
371 
372  /* Set the device handle */
373  psurf->SurfObj.dhsurf = dhsurf;
374 
375  /* Set public ownership */
377 
378  /* Get the handle for the bitmap */
379  hbmp = (HBITMAP)psurf->SurfObj.hsurf;
380 
381  /* Unlock the surface and return */
382  SURFACE_UnlockSurface(psurf);
383  return hbmp;
384 }
#define STYPE_DEVBITMAP
Definition: winddi.h:1177
#define HBITMAP
Definition: msvc.h:28
_In_ SIZEL sizl
Definition: winddi.h:3467
DHSURF dhsurf
Definition: winddi.h:1205
SURFOBJ SurfObj
Definition: surface.h:8
HSURF hsurf
Definition: winddi.h:1206
smooth NULL
Definition: ftsmooth.c:557
BASEOBJECT BaseObject
Definition: surface.h:6
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 cjBufSize, _In_opt_ PVOID pvBits)
Definition: surface.c:116
_In_ SIZEL _In_ ULONG iFormat
Definition: winddi.h:3467
#define SURFACE_UnlockSurface(pBMObj)
Definition: surface.h:93
#define GDI_OBJ_HMGR_PUBLIC
Definition: ntgdihdl.h:116
#define DPRINT1
Definition: precomp.h:8
VOID NTAPI GDIOBJ_vSetObjectOwner(POBJ pobj, ULONG ulNewOwner)
Definition: gdiobj.c:960
HBITMAP hbmp
Definition: msvc.h:60
HSURF APIENTRY EngCreateDeviceSurface ( _In_ DHSURF  dhsurf,
_In_ SIZEL  sizl,
_In_ ULONG  iFormat 
)

Definition at line 388 of file surface.c.

Referenced by DrvEnableSurface().

392 {
393  PSURFACE psurf;
394  HSURF hsurf;
395 
396  /* Allocate a surface */
398  sizl.cx,
399  sizl.cy,
400  iFormat,
401  0,
402  0,
403  0,
404  NULL);
405  if (!psurf)
406  {
407  DPRINT1("SURFACE_AllocSurface failed. (STYPE_DEVICE, sizl.cx=%ld, sizl.cy=%ld, iFormat=%lu)\n",
408  sizl.cx, sizl.cy, iFormat);
409  return NULL;
410  }
411 
412  /* Set the device handle */
413  psurf->SurfObj.dhsurf = dhsurf;
414 
415  /* Set public ownership */
417 
418  /* Get the handle for the surface */
419  hsurf = psurf->SurfObj.hsurf;
420 
421  /* Unlock the surface and return */
422  SURFACE_UnlockSurface(psurf);
423  return hsurf;
424 }
#define STYPE_DEVICE
Definition: lmshare.h:24
_In_ SIZEL sizl
Definition: winddi.h:3467
DHSURF dhsurf
Definition: winddi.h:1205
SURFOBJ SurfObj
Definition: surface.h:8
HSURF hsurf
Definition: winddi.h:1206
smooth NULL
Definition: ftsmooth.c:557
typedef HSURF(APIENTRY FN_DrvEnableSurface)(_In_ DHPDEV dhpdev)
BASEOBJECT BaseObject
Definition: surface.h:6
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 cjBufSize, _In_opt_ PVOID pvBits)
Definition: surface.c:116
_In_ SIZEL _In_ ULONG iFormat
Definition: winddi.h:3467
#define SURFACE_UnlockSurface(pBMObj)
Definition: surface.h:93
#define GDI_OBJ_HMGR_PUBLIC
Definition: ntgdihdl.h:116
#define DPRINT1
Definition: precomp.h:8
VOID NTAPI GDIOBJ_vSetObjectOwner(POBJ pobj, ULONG ulNewOwner)
Definition: gdiobj.c:960
BOOL APIENTRY EngDeleteSurface ( _In_ _Post_ptr_invalid_ HSURF  hsurf)

Definition at line 564 of file surface.c.

Referenced by DrvDisableSurface(), DrvEnableSurface(), EBRUSHOBJ_pvGetEngBrush(), EngRealizeBrush(), EngSetPointerShape(), GreExtTextOutW(), IntEngEnter(), IntEngLeave(), and NtGdiSetDIBitsToDeviceInternal().

566 {
567  PSURFACE psurf;
568 
569  psurf = SURFACE_ShareLockSurface(hsurf);
570  if (!psurf)
571  {
572  DPRINT1("Could not reference surface %p to delete\n", hsurf);
573  return FALSE;
574  }
575 
577  return TRUE;
578 }
#define TRUE
Definition: types.h:120
#define SURFACE_ShareLockSurface(hBMObj)
Definition: surface.h:91
#define FALSE
Definition: types.h:117
BASEOBJECT BaseObject
Definition: surface.h:6
VOID NTAPI GDIOBJ_vDeleteObject(POBJ pobj)
Definition: gdiobj.c:1106
#define DPRINT1
Definition: precomp.h:8
BOOL APIENTRY EngEraseSurface ( _In_ SURFOBJ pso,
_In_ RECTL prcl,
_In_ ULONG  iColor 
)

Definition at line 582 of file surface.c.

586 {
587  ASSERT(pso);
588  ASSERT(prcl);
589  return FillSolid(pso, prcl, iColor);
590 }
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
BOOL APIENTRY FillSolid(SURFOBJ *pso, PRECTL pRect, ULONG iColor)
Definition: paint.c:35
_In_ HANDLE _In_ SURFOBJ * pso
Definition: winddi.h:3664
_In_ ULONG _In_ CLIPOBJ _In_ RECTL * prcl
Definition: winddi.h:3529
_In_ ULONG iColor
Definition: xlateobj.h:17
SURFOBJ* APIENTRY EngLockSurface ( _In_ HSURF  hsurf)

Definition at line 604 of file surface.c.

Referenced by DrvEnableSurface(), GreExtTextOutW(), IntEngEnter(), IntGdiCreateMaskFromRLE(), NtGdiEngLockSurface(), and NtGdiSetDIBitsToDeviceInternal().

606 {
607  SURFACE *psurf = SURFACE_ShareLockSurface(hsurf);
608 
609  return psurf ? &psurf->SurfObj : NULL;
610 }
#define SURFACE_ShareLockSurface(hBMObj)
Definition: surface.h:91
SURFOBJ SurfObj
Definition: surface.h:8
smooth NULL
Definition: ftsmooth.c:557
BOOL APIENTRY EngModifySurface ( _In_ HSURF  hsurf,
_In_ HDEV  hdev,
_In_ FLONG  flHooks,
_In_ FLONG  flSurface,
_In_ DHSURF  dhsurf,
_In_ PVOID  pvScan0,
_In_ LONG  lDelta,
_Reserved_ PVOID  pvReserved 
)

Definition at line 468 of file surface.c.

Referenced by DrvAssertMode(), and DrvEnableSurface().

477 {
478  SURFOBJ *pso;
479  PSURFACE psurf;
480  PDEVOBJ* ppdev;
481  PPALETTE ppal;
482 
483  /* Lock the surface */
484  psurf = SURFACE_ShareLockSurface(hsurf);
485  if (psurf == NULL)
486  {
487  DPRINT1("Failed to reference surface %p\n", hsurf);
488  return FALSE;
489  }
490 
491  ppdev = (PDEVOBJ*)hdev;
492  pso = &psurf->SurfObj;
493  pso->dhsurf = dhsurf;
494 
495  /* Associate the hdev */
496  pso->hdev = hdev;
497  pso->dhpdev = ppdev->dhpdev;
498 
499  /* Hook up specified functions */
500  psurf->flags &= ~HOOK_FLAGS;
501  psurf->flags |= (flHooks & HOOK_FLAGS);
502 
503  /* Assign the PDEV's palette */
505  SURFACE_vSetPalette(psurf, ppal);
507 
508  /* Update surface flags */
509  if (flSurface & MS_NOTSYSTEMMEMORY)
510  pso->fjBitmap |= BMF_NOTSYSMEM;
511  else
512  pso->fjBitmap &= ~BMF_NOTSYSMEM;
513  if (flSurface & MS_SHAREDACCESS)
514  psurf->flags |= SHAREACCESS_SURFACE;
515  else
516  psurf->flags &= ~SHAREACCESS_SURFACE;
517 
518  /* Check if the caller passed bitmap bits */
519  if ((pvScan0 != NULL) && (lDelta != 0))
520  {
521  /* Update the fields */
522  pso->pvScan0 = pvScan0;
523  pso->lDelta = lDelta;
524 
525  /* This is a bitmap now! */
526  pso->iType = STYPE_BITMAP;
527 
528  /* Check memory layout */
529  if (lDelta > 0)
530  {
531  /* Topdown is the normal way */
532  pso->cjBits = lDelta * pso->sizlBitmap.cy;
533  pso->pvBits = pso->pvScan0;
534  pso->fjBitmap |= BMF_TOPDOWN;
535  }
536  else
537  {
538  /* Inversed bitmap (bottom up) */
539  pso->cjBits = (-lDelta) * pso->sizlBitmap.cy;
540  pso->pvBits = (PCHAR)pso->pvScan0 - pso->cjBits - lDelta;
541  pso->fjBitmap &= ~BMF_TOPDOWN;
542  }
543  }
544  else
545  {
546  /* Set bits to NULL */
547  pso->pvBits = NULL;
548  pso->pvScan0 = NULL;
549  pso->lDelta = 0;
550 
551  /* Set appropriate surface type */
552  if (pso->iType != STYPE_DEVICE)
553  pso->iType = STYPE_DEVBITMAP;
554  }
555 
557 
558  return TRUE;
559 }
DHPDEV dhpdev
Definition: pdevobj.h:121
#define STYPE_DEVICE
Definition: lmshare.h:24
#define STYPE_DEVBITMAP
Definition: winddi.h:1177
signed char * PCHAR
Definition: retypes.h:7
DHPDEV dhpdev
Definition: winddi.h:1207
#define TRUE
Definition: types.h:120
SIZEL sizlBitmap
Definition: winddi.h:1209
LONG lDelta
Definition: winddi.h:1213
#define STYPE_BITMAP
Definition: winddi.h:1175
#define SURFACE_ShareUnlockSurface(pBMObj)
Definition: surface.h:95
USHORT iType
Definition: winddi.h:1216
#define BMF_TOPDOWN
Definition: winddi.h:1180
#define SURFACE_ShareLockSurface(hBMObj)
Definition: surface.h:91
DHSURF dhsurf
Definition: winddi.h:1205
ULONG cjBits
Definition: winddi.h:1210
#define FALSE
Definition: types.h:117
#define HOOK_FLAGS
Definition: winddi.h:1438
SURFOBJ SurfObj
Definition: surface.h:8
HPALETTE hpalDefault
Definition: winddi.h:398
smooth NULL
Definition: ftsmooth.c:557
#define BMF_NOTSYSMEM
Definition: winddi.h:1185
#define PALETTE_ShareLockPalette(hpal)
Definition: palette.h:57
_In_ HANDLE _In_ SURFOBJ * pso
Definition: winddi.h:3664
DEVINFO devinfo
Definition: pdevobj.h:123
#define MS_SHAREDACCESS
Definition: winddi.h:2130
FORCEINLINE VOID SURFACE_vSetPalette(_Inout_ PSURFACE psurf, _In_ PPALETTE ppal)
Definition: surface.h:129
#define MS_NOTSYSTEMMEMORY
Definition: winddi.h:2129
HDEV hdev
Definition: winddi.h:1208
USHORT fjBitmap
Definition: winddi.h:1217
FLONG flags
Definition: surface.h:10
#define PALETTE_ShareUnlockPalette(ppal)
Definition: palette.h:59
#define DPRINT1
Definition: precomp.h:8
PVOID pvBits
Definition: winddi.h:1211
LONG cy
Definition: windef.h:348
_In_ HDEV hdev
Definition: winddi.h:3449
PVOID pvScan0
Definition: winddi.h:1212
VOID APIENTRY EngUnlockSurface ( _In_ _Post_ptr_invalid_ SURFOBJ pso)

Definition at line 625 of file surface.c.

Referenced by GreExtTextOutW(), IntEngEnter(), IntEngLeave(), IntGdiCreateMaskFromRLE(), NtGdiSetDIBitsToDeviceInternal(), and SynchonizeDriver().

627 {
628  if (pso != NULL)
629  {
630  SURFACE *psurf = CONTAINING_RECORD(pso, SURFACE, SurfObj);
632  }
633 }
#define SURFACE_ShareUnlockSurface(pBMObj)
Definition: surface.h:95
smooth NULL
Definition: ftsmooth.c:557
_In_ HANDLE _In_ SURFOBJ * pso
Definition: winddi.h:3664
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:259
SURFOBJ* APIENTRY NtGdiEngLockSurface ( IN HSURF  hsurf)

Definition at line 596 of file surface.c.

597 {
598  return EngLockSurface(hsurf);
599 }
SURFOBJ *APIENTRY EngLockSurface(_In_ HSURF hsurf)
Definition: surface.c:604
__kernel_entry NTSTATUS APIENTRY NtGdiEngUnlockSurface ( _In_ SURFOBJ pso)

Definition at line 615 of file surface.c.

617 {
619  ASSERT(FALSE);
620  return STATUS_NOT_IMPLEMENTED;
621 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
#define FALSE
Definition: types.h:117
#define UNIMPLEMENTED
Definition: debug.h:114
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  cjBufSize,
_In_opt_ PVOID  pvBits 
)

Definition at line 116 of file surface.c.

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

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 }
DWORD *typedef PVOID
Definition: winlogon.h:52
SIZEL sizlBitmap
Definition: winddi.h:1209
LONG lDelta
Definition: winddi.h:1213
#define BMF_32BPP
Definition: winddi.h:360
#define WIDTH_BYTES_ALIGN32(cx, bpp)
Definition: swimpl.c:26
#define STYPE_BITMAP
Definition: winddi.h:1175
_In_ ULONG iType
Definition: winddi.h:3748
USHORT iType
Definition: winddi.h:1216
#define BMF_TOPDOWN
Definition: winddi.h:1180
ULONG iBitmapFormat
Definition: winddi.h:1215
ULONG iUniq
Definition: winddi.h:1214
Definition: xlate.c:8
ULONG cjBits
Definition: winddi.h:1210
#define BMF_PNG
Definition: winddi.h:364
long LONG
Definition: pedump.c:60
SURFOBJ SurfObj
Definition: surface.h:8
_Out_opt_ int _Out_opt_ int * cy
Definition: commctrl.h:570
HGDIOBJ hHmgr(VOID)
Definition: baseobj.hpp:95
HSURF hsurf
Definition: winddi.h:1206
smooth NULL
Definition: ftsmooth.c:557
LONG cx
Definition: windef.h:347
#define PCHAR
Definition: match.c:90
#define BMF_USERMEM
Definition: winddi.h:1183
_In_ HANDLE _In_ SURFOBJ * pso
Definition: winddi.h:3664
BASEOBJECT BaseObject
Definition: surface.h:6
VOID NTAPI GDIOBJ_vDeleteObject(POBJ pobj)
Definition: gdiobj.c:1106
BOOL APIENTRY EngFreeSectionMem(_In_opt_ PVOID pvSection, _In_opt_ PVOID pvMappedBase)
Definition: mapping.c:246
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
#define BMF_NOZEROINIT
Definition: winddi.h:1181
#define LONG
Definition: msvc.h:36
FORCEINLINE VOID SURFACE_vSetPalette(_Inout_ PSURFACE psurf, _In_ PPALETTE ppal)
Definition: surface.h:129
#define FL_ZERO_MEMORY
Definition: polytest.cpp:58
#define GDI_OBJECT_TYPE_BITMAP
Definition: gdi.h:48
_In_ SIZEL _In_ ULONG iFormat
Definition: winddi.h:3467
USHORT fjBitmap
Definition: winddi.h:1217
#define InterlockedIncrement
Definition: armddk.h:53
unsigned short USHORT
Definition: pedump.c:61
POBJ NTAPI GDIOBJ_AllocObjWithHandle(ULONG ObjectType, ULONG cjSize)
Definition: gdiobj.c:1483
struct _SURFACE SURFACE
PPALETTE appalSurfaceDefault[11]
Definition: palette.c:18
#define DPRINT1
Definition: precomp.h:8
_Out_opt_ int * cx
Definition: commctrl.h:570
PVOID pvBits
Definition: winddi.h:1211
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
LONG giUniqueSurface
Definition: surface.c:18
LONG cy
Definition: windef.h:348
struct _SURFACE * PSURFACE
UCHAR gajBitsPerFormat[11]
Definition: surface.c:21
#define BMF_KMSECTION
Definition: winddi.h:1184
PVOID pvScan0
Definition: winddi.h:1212
#define TAG_DIB
Definition: tags.h:17
#define NT_ASSERT
Definition: rtlfuncs.h:3312
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 */
76  ASSERT(psurf->SurfObj.iType == STYPE_BITMAP);
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?
96  ASSERT(FALSE);
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 }
DWORD *typedef PVOID
Definition: winlogon.h:52
#define STYPE_BITMAP
Definition: winddi.h:1175
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
#define EngFreeMem
Definition: polytest.cpp:56
USHORT iType
Definition: winddi.h:1216
struct _PALETTE *const ppal
Definition: surface.h:11
#define FALSE
Definition: types.h:117
SURFOBJ SurfObj
Definition: surface.h:8
smooth NULL
Definition: ftsmooth.c:557
ENGAPI VOID APIENTRY EngFreeUserMem(_Pre_notnull_ __drv_freesMem(UserMem) PVOID pv)
#define BMF_USERMEM
Definition: winddi.h:1183
BOOL APIENTRY EngFreeSectionMem(_In_opt_ PVOID pvSection, _In_opt_ PVOID pvMappedBase)
Definition: mapping.c:246
HANDLE hSecure
Definition: surface.h:32
#define BMF_POOLALLOC
Definition: surface.h:84
VOID NTAPI EngUnmapSectionView(_In_ PVOID pvBits, _In_ ULONG cjOffset, _In_ HANDLE hSecure)
Definition: mapping.c:71
USHORT fjBitmap
Definition: winddi.h:1217
DWORD dwOffset
Definition: surface.h:33
#define PALETTE_ShareUnlockPalette(ppal)
Definition: palette.h:59
HANDLE hDIBSection
Definition: surface.h:31
#define DPRINT1
Definition: precomp.h:8
PVOID pvBits
Definition: winddi.h:1211
struct _SURFACE * PSURFACE
#define BMF_KMSECTION
Definition: winddi.h:1184

Variable Documentation

UCHAR gajBitsPerFormat[11]
Initial value:
=
{
0,
1,
4,
8,
16,
24,
32,
4,
8,
0,
0,
}

Definition at line 21 of file surface.c.

Referenced by DC_bIsBitmapCompatible(), EngBitBlt(), GreCreateBitmapEx(), NtGdiCreateBitmap(), NtGdiMaskBlt(), and SURFACE_AllocSurface().

LONG giUniqueSurface = 0

Definition at line 18 of file surface.c.

Referenced by SURFACE_AllocSurface().