ReactOS 0.4.15-dev-7924-g5949c20
rosglue.c
Go to the documentation of this file.
1
2#include <precomp.h>
3#include "gdi_private.h"
4#undef SetWorldTransform
5
6#define NDEBUG
7#include <debug.h>
8
9static
12 WORD wType)
13{
14 /* Get the GDI object type */
15 switch (wType)
16 {
31 default: return 0;
32 }
33}
34
37 PVOID pvObject,
38 WORD wType,
39 const struct gdi_obj_funcs *funcs)
40{
41 GDILOOBJTYPE eObjType;
42
43 /* Get the GDI object type */
44 eObjType = ConvertObjectType(wType);
45 if ((eObjType != GDILoObjType_LO_METAFILE_TYPE) &&
46 (eObjType != GDILoObjType_LO_METAFILE16_TYPE) &&
48 {
49 /* This is not supported! */
51 return NULL;
52 }
53
54 /* Insert the client object */
55 return GdiCreateClientObj(pvObject, eObjType);
56}
57
60{
61 /* Should be a client object */
62 return GdiDeleteClientObj(hobj);
63}
64
67 HGDIOBJ hobj,
68 WORD wType)
69{
70 GDILOOBJTYPE eObjType;
71
72 /* Check if the object type matches */
73 eObjType = ConvertObjectType(wType);
74 if ((eObjType == 0) || (GDI_HANDLE_GET_TYPE(hobj) != eObjType))
75 {
76 return NULL;
77 }
78
79 /* Check if we have an ALTDC */
80 if (eObjType == GDILoObjType_LO_ALTDC_TYPE)
81 {
82 /* Object is stored as LDC */
83 return GdiGetLDC(hobj);
84 }
85
86 /* Check for client objects */
87 if ((eObjType == GDILoObjType_LO_METAFILE_TYPE) ||
88 (eObjType == GDILoObjType_LO_METAFILE16_TYPE) ||
90 {
91 return GdiGetClientObjLink(hobj);
92 }
93
94 /* This should never happen! */
96 return NULL;
97}
98
99VOID
101{
102 /* We don't do any reference-counting */
103}
104
105WINEDC*
107{
108 WINEDC* pWineDc;
109
110 /* Allocate the Wine DC */
111 pWineDc = HeapAlloc(GetProcessHeap(), 0, sizeof(*pWineDc));
112 if (pWineDc == NULL)
113 {
114 return NULL;
115 }
116
117 ZeroMemory(pWineDc, sizeof(*pWineDc));
119 pWineDc->hPen = GetStockObject(BLACK_PEN);
120
121 if (magic == OBJ_ENHMETADC)
122 {
123 /* We create a metafile DC, but we ignore the reference DC, this is
124 handled by the wine code */
125 pWineDc->hdc = NtGdiCreateMetafileDC(NULL);
126 if (pWineDc->hdc == NULL)
127 {
128 HeapFree(GetProcessHeap(), 0, pWineDc);
129 return NULL;
130 }
131
132 pWineDc->iType = LDC_EMFLDC;
133
134 /* Set the Wine DC as LDC */
135 GdiSetLDC(pWineDc->hdc, pWineDc);
136 }
137 else
138 {
139 // nothing else supported!
140 ASSERT(FALSE);
141 }
142
143 return pWineDc;
144}
145
146WINEDC*
148{
149 /* Check for EMF DC */
151 {
152 /* The Wine DC is stored as the LDC */
153 return (WINEDC*)GdiGetLDC(hdc);
154 }
155
156 /* Check for METADC16 */
158 {
159 return GdiGetClientObjLink(hdc);
160 }
161
162 return NULL;
163}
164
165VOID
167 HGDIOBJ hobj,
168 HDC hdc)
169{
170 /* Record that we have an object in use by a METADC. We simply link the
171 object to the HDC that we use. Wine API does not give us a way to
172 respond to failure, so we silently ignore it */
173 if (!GdiCreateClientObjLink(hobj, hdc))
174 {
175 /* Ignore failure, and return */
176 DPRINT1("Failed to create link for selected METADC object.\n");
177 return;
178 }
179}
180
181VOID
183 HGDIOBJ hobj,
184 HDC hdc)
185{
186 HDC hdcLink;
187
188 /* Remove the HDC link for the object */
189 hdcLink = GdiRemoveClientObjLink(hobj);
190 ASSERT(hdcLink == hdc);
191}
192
193/***********************************************************************
194 * bitmap_info_size
195 *
196 * Return the size of the bitmap info structure including color table.
197 */
198int
200 const BITMAPINFO * info,
201 WORD coloruse)
202{
203 unsigned int colors, size, masks = 0;
204
205 if (info->bmiHeader.biSize == sizeof(BITMAPCOREHEADER))
206 {
207 const BITMAPCOREHEADER *core = (const BITMAPCOREHEADER *)info;
208 colors = (core->bcBitCount <= 8) ? 1 << core->bcBitCount : 0;
209 return sizeof(BITMAPCOREHEADER) + colors *
210 ((coloruse == DIB_RGB_COLORS) ? sizeof(RGBTRIPLE) : sizeof(WORD));
211 }
212 else /* assume BITMAPINFOHEADER */
213 {
214 if (info->bmiHeader.biClrUsed) colors = min( info->bmiHeader.biClrUsed, 256 );
215 else colors = info->bmiHeader.biBitCount > 8 ? 0 : 1 << info->bmiHeader.biBitCount;
216 if (info->bmiHeader.biCompression == BI_BITFIELDS) masks = 3;
217 size = max( info->bmiHeader.biSize, sizeof(BITMAPINFOHEADER) + masks * sizeof(DWORD) );
218 return size + colors * ((coloruse == DIB_RGB_COLORS) ? sizeof(RGBQUAD) : sizeof(WORD));
219 }
220}
221
222BOOL
224 HBRUSH hbr,
226 PVOID pvBits,
227 PUINT puUsage)
228{
230 HDC hdc;
231 PVOID Bits;
232
233 /* Call win32k to get the bitmap handle and color usage */
234 hbmp = NtGdiGetObjectBitmapHandle(hbr, puUsage);
235 if (hbmp == NULL)
236 return FALSE;
237
238 hdc = GetDC(NULL);
239 if (hdc == NULL)
240 return FALSE;
241
242 /* Initialize the BITMAPINFO */
243 ZeroMemory(pbmi, sizeof(*pbmi));
245
246 /* Retrieve information about the bitmap */
247 if (!GetDIBits(hdc, hbmp, 0, 0, NULL, pbmi, *puUsage))
248 return FALSE;
249
250 if (pvBits)
251 {
252 /* Now allocate a buffer for the bits */
254 if (Bits == NULL)
255 return FALSE;
256
257 /* Retrieve the bitmap bits */
258 if (!GetDIBits(hdc, hbmp, 0, pbmi->bmiHeader.biHeight, Bits, pbmi, *puUsage))
259 {
260 HeapFree(GetProcessHeap(), 0, Bits);
261 return FALSE;
262 }
263
264 CopyMemory( pvBits, Bits, pbmi->bmiHeader.biSizeImage );
265
266 }
267
268 /* GetDIBits doesn't set biClrUsed, but wine code needs it, so we set it */
269 if (pbmi->bmiHeader.biBitCount <= 8)
270 {
272 }
273 return TRUE;
274}
275
276BOOL
277WINAPI
279 HDC hdc,
280 DWORD cxVirtualDevicePixel,
281 DWORD cyVirtualDevicePixel,
282 DWORD cxVirtualDeviceMm,
283 DWORD cyVirtualDeviceMm)
284{
286 cxVirtualDevicePixel,
287 cyVirtualDevicePixel,
288 cxVirtualDeviceMm,
289 cyVirtualDeviceMm);
290}
291
292BOOL
293WINAPI
295 HCOLORSPACE hcs)
296{
297 return NtGdiDeleteColorSpace(hcs);
298}
299void
302 const char *exp,
303 const char *file,
304 unsigned line)
305{
307}
308
309/******************************************************************************/
310BOOL
311WINAPI
313 _In_ HDC hdc,
315 _In_ USHORT usMF16Id
316)
317{
318 switch(usMF16Id)
319 {
320 case META_SETMAPMODE:
321 return METADC_SetMapMode(hdc, dwIn);
322 case META_SETRELABS:
323 return METADC_SetRelAbs(hdc, dwIn);
324 default:
325 return FALSE;
326 }
327}
328
329BOOL
330WINAPI
332 _In_ PLDC pldc,
334 _In_ ULONG ulMFId)
335{
336 switch(ulMFId)
337 {
338 case EMR_SETMAPMODE:
339 return EMFDC_SetMapMode( pldc, dwIn);
341 return EMFDC_SetArcDirection( pldc, dwIn);
342 default:
343 return FALSE;
344 }
345}
346
347extern void METADC_DeleteObject( HDC hdc, HGDIOBJ obj );
348extern void emfdc_delete_object( HDC hdc, HGDIOBJ obj );
349
350VOID
351WINAPI
353{
354 GDILOOBJTYPE eObjectType;
355 HDC hdc;
356
357 /* Check for one of the types we actually handle here */
358 eObjectType = GDI_HANDLE_GET_TYPE(hobj);
359 if ((eObjectType != GDILoObjType_LO_BRUSH_TYPE) &&
360 (eObjectType != GDILoObjType_LO_PEN_TYPE) &&
361 (eObjectType != GDILoObjType_LO_EXTPEN_TYPE) &&
362 (eObjectType != GDILoObjType_LO_PALETTE_TYPE) &&
363 (eObjectType != GDILoObjType_LO_FONT_TYPE))
364 {
365 return;
366 }
367
368 /* Check if we have a client object link and remove it if it was found.
369 The link is the HDC that the object was selected into. */
371 if (hdc == NULL)
372 {
373 DPRINT1("the link was not found\n");
374 /* The link was not found, so we are not handling this object here */
375 return;
376 }
377
379
381 {
382 LDC* pWineDc = GdiGetLDC(hdc);
383 if ( pWineDc )
384 {
385 emfdc_delete_object( hdc, hobj );
386 }
387 }
388}
389
390BOOL
391WINAPI
393 _In_ HDC hdc)
394{
395 LDC* pWineDc = NULL;
396
398 {
399 return METADC_DeleteDC(hdc);
400 }
401
403 {
404 pWineDc = GdiGetLDC(hdc);
405
406 if ( pWineDc )
407 {
408 // Handle Printer LDC
409 if (pWineDc->iType != LDC_EMFLDC)
410 {
411 //return IntDeleteDC(hdc);
412 }
413
414 EMFDC_DeleteDC( pWineDc );
415
416 /* Get rid of the LDC */
417 ASSERT(GdiGetLDC(pWineDc->hDC) == pWineDc);
418 GdiSetLDC(pWineDc->hDC, NULL);
419
420 /* Free the Wine DC */
421 HeapFree(GetProcessHeap(), 0, pWineDc);
422 }
423 }
424
426}
427
#define __cdecl
Definition: accygwin.h:79
#define DPRINT1
Definition: precomp.h:8
HBITMAP hbmp
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
ULONG RGBQUAD
Definition: precomp.h:59
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned short WORD
Definition: ntddk_ex.h:93
BOOL EMFDC_DeleteDC(LDC *dc_attr) DECLSPEC_HIDDEN
HGDIOBJ WINAPI GdiCreateClientObj(_In_ PVOID pvObject, _In_ GDILOOBJTYPE eObjType)
Definition: clientobj.c:148
BOOL METADC_SetMapMode(HDC hdc, INT mode) DECLSPEC_HIDDEN
Definition: metadc.c:271
BOOL FASTCALL GdiSetLDC(HDC hdc, PVOID pvLDC)
Definition: misc.c:802
BOOL WINAPI GdiCreateClientObjLink(_In_ HGDIOBJ hobj, _In_ PVOID pvObject)
Definition: clientobj.c:24
PVOID WINAPI GdiGetClientObjLink(_In_ HGDIOBJ hobj)
Definition: clientobj.c:61
BOOL EMFDC_SetMapMode(LDC *dc_attr, INT mode) DECLSPEC_HIDDEN
BOOL EMFDC_SetArcDirection(LDC *dc_attr, INT dir) DECLSPEC_HIDDEN
BOOL METADC_DeleteDC(HDC hdc)
Definition: metadc.c:1318
PVOID WINAPI GdiDeleteClientObj(_In_ HGDIOBJ hobj)
Definition: clientobj.c:173
BOOL METADC_SetRelAbs(HDC hdc, INT mode) DECLSPEC_HIDDEN
Definition: metadc.c:236
PLDC FASTCALL GdiGetLDC(HDC hDC)
Definition: misc.c:785
PVOID WINAPI GdiRemoveClientObjLink(_In_ HGDIOBJ hobj)
Definition: clientobj.c:98
VOID GDI_hdc_not_using_object(HGDIOBJ hobj, HDC hdc)
Definition: rosglue.c:182
int bitmap_info_size(const BITMAPINFO *info, WORD coloruse)
Definition: rosglue.c:199
BOOL WINAPI EMFDC_SetD(_In_ PLDC pldc, _In_ DWORD dwIn, _In_ ULONG ulMFId)
Definition: rosglue.c:331
WINEDC * alloc_dc_ptr(WORD magic)
Definition: rosglue.c:106
BOOL get_brush_bitmap_info(HBRUSH hbr, PBITMAPINFO pbmi, PVOID pvBits, PUINT puUsage)
Definition: rosglue.c:223
BOOL WINAPI METADC_RosGlueDeleteDC(_In_ HDC hdc)
Definition: rosglue.c:392
BOOL WINAPI SetVirtualResolution(HDC hdc, DWORD cxVirtualDevicePixel, DWORD cyVirtualDevicePixel, DWORD cxVirtualDeviceMm, DWORD cyVirtualDeviceMm)
Definition: rosglue.c:278
VOID GDI_hdc_using_object(HGDIOBJ hobj, HDC hdc)
Definition: rosglue.c:166
static GDILOOBJTYPE ConvertObjectType(WORD wType)
Definition: rosglue.c:11
PVOID free_gdi_handle(HGDIOBJ hobj)
Definition: rosglue.c:59
BOOL WINAPI METADC_SetD(_In_ HDC hdc, _In_ DWORD dwIn, _In_ USHORT usMF16Id)
Definition: rosglue.c:312
VOID GDI_ReleaseObj(HGDIOBJ hobj)
Definition: rosglue.c:100
VOID WINAPI METADC_RosGlueDeleteObject(HGDIOBJ hobj)
Definition: rosglue.c:352
void METADC_DeleteObject(HDC hdc, HGDIOBJ obj)
Definition: metadc.c:1015
BOOL WINAPI DeleteColorSpace(HCOLORSPACE hcs)
Definition: rosglue.c:294
void emfdc_delete_object(HDC hdc, HGDIOBJ obj)
Definition: emfdc.c:232
WINEDC * get_dc_ptr(HDC hdc)
Definition: rosglue.c:147
void __cdecl _assert(const char *exp, const char *file, unsigned line)
Definition: rosglue.c:301
PVOID GDI_GetObjPtr(HGDIOBJ hobj, WORD wType)
Definition: rosglue.c:66
HGDIOBJ alloc_gdi_handle(PVOID pvObject, WORD wType, const struct gdi_obj_funcs *funcs)
Definition: rosglue.c:36
#define GDI_HANDLE_GET_TYPE(h)
Definition: gdi.h:31
#define LDC_EMFLDC
Definition: gdi_private.h:105
@ GDILoObjType_LO_FONT_TYPE
Definition: gdi_private.h:37
@ GDILoObjType_LO_PALETTE_TYPE
Definition: gdi_private.h:36
@ GDILoObjType_LO_BRUSH_TYPE
Definition: gdi_private.h:33
@ GDILoObjType_LO_BITMAP_TYPE
Definition: gdi_private.h:35
@ GDILoObjType_LO_METAFILE_TYPE
Definition: gdi_private.h:48
@ GDILoObjType_LO_METADC16_TYPE
Definition: gdi_private.h:49
@ GDILoObjType_LO_REGION_TYPE
Definition: gdi_private.h:38
@ GDILoObjType_LO_EXTPEN_TYPE
Definition: gdi_private.h:45
@ GDILoObjType_LO_METAFILE16_TYPE
Definition: gdi_private.h:47
@ GDILoObjType_LO_ICMLCS_TYPE
Definition: gdi_private.h:39
@ GDILoObjType_LO_DC_TYPE
Definition: gdi_private.h:34
@ GDILoObjType_LO_PEN_TYPE
Definition: gdi_private.h:44
@ GDILoObjType_LO_ALTDC_TYPE
Definition: gdi_private.h:43
enum GDILoObjType GDILOOBJTYPE
GLsizeiptr size
Definition: glext.h:5919
#define BI_BITFIELDS
Definition: mmreg.h:507
#define ASSERT(a)
Definition: mode.c:44
HDC hdc
Definition: main.c:9
static HBITMAP
Definition: button.c:44
static HDC
Definition: imagelist.c:92
static const BYTE masks[8]
Definition: dib.c:2760
DWORD exp
Definition: msg.c:16058
#define min(a, b)
Definition: monoChain.cc:55
#define _In_
Definition: ms_sal.h:308
unsigned int * PUINT
Definition: ndis.h:50
u32_t magic(void)
__kernel_entry W32KAPI HBITMAP APIENTRY NtGdiGetObjectBitmapHandle(_In_ HBRUSH hbr, _Out_ UINT *piUsage)
Definition: brush.cpp:513
_In_ UINT _In_ DWORD dwIn
Definition: ntgdi.h:249
__kernel_entry W32KAPI HDC APIENTRY NtGdiCreateMetafileDC(_In_ HDC hdc)
_In_ HBITMAP _In_ UINT _In_ UINT _Inout_ LPBITMAPINFO pbmi
Definition: ntgdi.h:2780
__kernel_entry W32KAPI BOOL APIENTRY NtGdiDeleteObjectApp(_In_ HANDLE hobj)
__kernel_entry W32KAPI BOOL APIENTRY NtGdiDeleteColorSpace(_In_ HANDLE hColorSpace)
__kernel_entry W32KAPI BOOL APIENTRY NtGdiSetVirtualResolution(_In_ HDC hdc, _In_ INT cxVirtualDevicePixel, _In_ INT cyVirtualDevicePixel, _In_ INT cxVirtualDeviceMm, _In_ INT cyVirtualDeviceMm)
#define OBJ_METAFILE
Definition: objidl.idl:1417
#define OBJ_EXTPEN
Definition: objidl.idl:1419
#define OBJ_REGION
Definition: objidl.idl:1416
#define OBJ_DC
Definition: objidl.idl:1411
#define OBJ_PEN
Definition: objidl.idl:1409
#define OBJ_METADC
Definition: objidl.idl:1412
#define OBJ_BRUSH
Definition: objidl.idl:1410
#define OBJ_FONT
Definition: objidl.idl:1414
#define OBJ_BITMAP
Definition: objidl.idl:1415
#define OBJ_ENHMETADC
Definition: objidl.idl:1420
#define OBJ_PAL
Definition: objidl.idl:1413
#define OBJ_MEMDC
Definition: objidl.idl:1418
#define OBJ_ENHMETAFILE
Definition: objidl.idl:1421
unsigned short USHORT
Definition: pedump.c:61
#define DbgRaiseAssertionFailure
Definition: ke.h:177
static struct __wine_debug_functions funcs
Definition: debug.c:59
Definition: ntgdihdl.h:263
INT iType
Definition: ntgdihdl.h:266
HDC hDC
Definition: ntgdihdl.h:264
Definition: fci.c:127
Definition: parser.c:49
USHORT biBitCount
Definition: precomp.h:46
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1476
HBRUSH hBrush
Definition: gdi_private.h:128
#define max(a, b)
Definition: svc.c:63
uint32_t ULONG
Definition: typedefs.h:59
#define ZeroMemory
Definition: winbase.h:1712
#define CopyMemory
Definition: winbase.h:1710
#define WINAPI
Definition: msvc.h:6
#define DIB_RGB_COLORS
Definition: wingdi.h:367
HGDIOBJ WINAPI GetStockObject(_In_ int)
int WINAPI GetDIBits(_In_ HDC hdc, _In_ HBITMAP hbm, _In_ UINT start, _In_ UINT cLines, _Out_opt_ LPVOID lpvBits, _At_((LPBITMAPINFOHEADER) lpbmi, _Inout_) LPBITMAPINFO lpbmi, _In_ UINT usage)
#define OBJ_COLORSPACE
Definition: wingdi.h:704
#define META_SETMAPMODE
Definition: wingdi.h:212
#define META_SETRELABS
Definition: wingdi.h:214
#define EMR_SETARCDIRECTION
Definition: wingdi.h:131
#define WHITE_BRUSH
Definition: wingdi.h:902
#define BLACK_PEN
Definition: wingdi.h:903
#define EMR_SETMAPMODE
Definition: wingdi.h:91
HDC WINAPI GetDC(_In_opt_ HWND)