ReactOS  0.4.15-dev-1384-g878186b
d3dkmt.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS kernel
4  * PURPOSE: Native DirectDraw implementation
5  * FILE: win32ss/reactx/ntddraw/d3dkmt.c
6  * PROGRAMER: Sebastian Gasiorek (sebastian.gasiorek@reactos.com)
7  */
8 
9 #include <win32k.h>
10 #include <debug.h>
11 
12 DWORD
15 {
16  PSURFACE psurf;
17  HDC hDC;
18 
19  const struct d3dddi_format_info
20  {
22  unsigned int bit_count;
24  unsigned int palette_size;
25  DWORD mask_r, mask_g, mask_b;
26  } *format = NULL;
27  unsigned int i;
28 
29  static const struct d3dddi_format_info format_info[] =
30  {
31  { D3DDDIFMT_R8G8B8, 24, BI_RGB, 0, 0x00000000, 0x00000000, 0x00000000 },
32  { D3DDDIFMT_A8R8G8B8, 32, BI_RGB, 0, 0x00000000, 0x00000000, 0x00000000 },
33  { D3DDDIFMT_X8R8G8B8, 32, BI_RGB, 0, 0x00000000, 0x00000000, 0x00000000 },
34  { D3DDDIFMT_R5G6B5, 16, BI_BITFIELDS, 0, 0x0000f800, 0x000007e0, 0x0000001f },
35  { D3DDDIFMT_X1R5G5B5, 16, BI_BITFIELDS, 0, 0x00007c00, 0x000003e0, 0x0000001f },
36  { D3DDDIFMT_A1R5G5B5, 16, BI_BITFIELDS, 0, 0x00007c00, 0x000003e0, 0x0000001f },
37  { D3DDDIFMT_A4R4G4B4, 16, BI_BITFIELDS, 0, 0x00000f00, 0x000000f0, 0x0000000f },
38  { D3DDDIFMT_X4R4G4B4, 16, BI_BITFIELDS, 0, 0x00000f00, 0x000000f0, 0x0000000f },
39  { D3DDDIFMT_P8, 8, BI_RGB, 256, 0x00000000, 0x00000000, 0x00000000 },
40  };
41 
42  if (!desc)
44 
45  if (!desc->pMemory)
47 
48  for (i = 0; i < sizeof(format_info) / sizeof(*format_info); ++i)
49  {
50  if (format_info[i].format == desc->Format)
51  {
52  format = &format_info[i];
53  break;
54  }
55  }
56 
57  if (!format)
59 
60  if (desc->Width > (UINT_MAX & ~3) / (format->bit_count / 8) ||
61  !desc->Pitch || desc->Pitch < (((desc->Width * format->bit_count + 31) >> 3) & ~3) ||
62  !desc->Height || desc->Height > UINT_MAX / desc->Pitch)
63  {
65  }
66 
67  if (!desc->hDeviceDc || !(hDC = NtGdiCreateCompatibleDC(desc->hDeviceDc)))
68  {
70  }
71 
72  /* Allocate a surface */
74  desc->Width,
75  desc->Height,
76  BitmapFormat(format->bit_count, format->compression),
78  desc->Pitch,
79  0,
80  desc->pMemory);
81 
82  /* Mark as API bitmap */
83  psurf->flags |= (DDB_SURFACE | API_BITMAP);
84 
85  desc->hDc = hDC;
86  /* Get the handle for the bitmap */
87  desc->hBitmap = (HBITMAP)psurf->SurfObj.hsurf;
88 
89  /* Allocate a palette for this surface */
90  if (format->bit_count <= 8)
91  {
92  PPALETTE palette = PALETTE_AllocPalette(PAL_INDEXED, 1 << format->bit_count, NULL, 0, 0, 0);
93  if (palette)
94  {
97  }
98  }
99 
100  /* Unlock the surface and return */
101  SURFACE_UnlockSurface(psurf);
102 
103  NtGdiSelectBitmap(desc->hDc, desc->hBitmap);
104 
105  return STATUS_SUCCESS;
106 }
107 
108 DWORD
109 APIENTRY
111 {
112  if (!desc)
114 
118 
119  NtGdiDeleteObjectApp(desc->hBitmap);
121 
122  return STATUS_SUCCESS;
123 }
DWORD APIENTRY NtGdiDdDDIDestroyDCFromMemory(const D3DKMT_DESTROYDCFROMMEMORY *desc)
Definition: d3dkmt.c:110
#define STYPE_BITMAP
Definition: winddi.h:1175
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
DWORD APIENTRY NtGdiDdDDICreateDCFromMemory(D3DKMT_CREATEDCFROMMEMORY *desc)
Definition: d3dkmt.c:14
static HDC
Definition: imagelist.c:92
#define BMF_TOPDOWN
Definition: winddi.h:1180
__kernel_entry W32KAPI HBITMAP APIENTRY NtGdiSelectBitmap(_In_ HDC hdc, _In_ HBITMAP hbm)
#define BI_BITFIELDS
Definition: mmreg.h:507
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
format_info
PPALETTE NTAPI PALETTE_AllocPalette(_In_ ULONG iMode, _In_ ULONG cColors, _In_opt_ const PALETTEENTRY *pEntries, _In_ FLONG flRed, _In_ FLONG flGreen, _In_ FLONG flBlue)
Definition: palette.c:135
static const WCHAR desc[]
Definition: protectdata.c:36
SURFOBJ SurfObj
Definition: surface.h:8
HSURF hsurf
Definition: winddi.h:1206
enum _D3DDDIFORMAT D3DDDIFORMAT
ULONG FASTCALL BitmapFormat(ULONG cBits, ULONG iCompression)
Definition: surface.c:39
#define GDI_HANDLE_GET_TYPE(h)
Definition: gdi.h:31
if(!(yy_init))
Definition: macro.lex.yy.c:714
unsigned long DWORD
Definition: ntddk_ex.h:95
#define BMF_NOZEROINIT
Definition: winddi.h:1181
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
FORCEINLINE VOID SURFACE_vSetPalette(_Inout_ PSURFACE psurf, _In_ PPALETTE ppal)
Definition: surface.h:136
#define GDI_OBJECT_TYPE_DC
Definition: gdi.h:46
static unsigned int palette_size(DWORD flags)
Definition: palette.c:241
_In_ fcb _In_ chunk _In_ uint64_t _In_ uint64_t _In_ bool _In_opt_ void _In_opt_ PIRP _In_ LIST_ENTRY _In_ uint8_t compression
Definition: btrfs_drv.h:1357
#define GDI_OBJECT_TYPE_BITMAP
Definition: gdi.h:48
static HPALETTE palette
Definition: clipboard.c:1345
__kernel_entry W32KAPI HDC APIENTRY NtGdiCreateCompatibleDC(_In_opt_ HDC hdc)
#define SURFACE_UnlockSurface(pBMObj)
Definition: surface.h:100
static HDC hDC
Definition: 3dtext.c:33
#define UINT_MAX
Definition: limits.h:41
__kernel_entry W32KAPI BOOL APIENTRY NtGdiDeleteObjectApp(_In_ HANDLE hobj)
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
FLONG flags
Definition: surface.h:10
#define PALETTE_ShareUnlockPalette(ppal)
Definition: palette.h:59
#define NULL
Definition: types.h:112
static HBITMAP
Definition: button.c:44
#define STATUS_SUCCESS
Definition: shellext.h:65
#define BI_RGB
Definition: precomp.h:47
#define APIENTRY
Definition: api.h:79