4 * Copyright 1993 Alexandre Julliard
17 /* GDI objects magic numbers */
18 #define PEN_MAGIC 0x4f47
19 #define BRUSH_MAGIC 0x4f48
20 #define FONT_MAGIC 0x4f49
21 #define PALETTE_MAGIC 0x4f4a
22 #define BITMAP_MAGIC 0x4f4b
23 #define REGION_MAGIC 0x4f4c
24 #define DC_MAGIC 0x4f4d
25 #define DISABLED_DC_MAGIC 0x4f4e
26 #define META_DC_MAGIC 0x4f4f
27 #define METAFILE_MAGIC 0x4f50
28 #define METAFILE_DC_MAGIC 0x4f51
29 #define MAGIC_DONTCARE 0xffff
31 typedef struct tagGDIOBJHDR
47 #define OBJ_METAFILE 9
50 #define OBJ_ENHMETADC 12
51 #define OBJ_ENHMETAFILE 13
54 typedef struct tagDeviceCaps
56 WORD version
; /* 0: driver version */
57 WORD technology
; /* 2: device technology */
58 WORD horzSize
; /* 4: width of display in mm */
59 WORD vertSize
; /* 6: height of display in mm */
60 WORD horzRes
; /* 8: width of display in pixels */
61 WORD vertRes
; /* 10: width of display in pixels */
62 WORD bitsPixel
; /* 12: bits per pixel */
63 WORD planes
; /* 14: color planes */
64 WORD numBrushes
; /* 16: device-specific brushes */
65 WORD numPens
; /* 18: device-specific pens */
66 WORD numMarkers
; /* 20: device-specific markers */
67 WORD numFonts
; /* 22: device-specific fonts */
68 WORD numColors
; /* 24: size of color table */
69 WORD pdeviceSize
; /* 26: size of PDEVICE structure */
70 WORD curveCaps
; /* 28: curve capabilities */
71 WORD lineCaps
; /* 30: line capabilities */
72 WORD polygonalCaps
; /* 32: polygon capabilities */
73 WORD textCaps
; /* 34: text capabilities */
74 WORD clipCaps
; /* 36: clipping capabilities */
75 WORD rasterCaps
; /* 38: raster capabilities */
76 WORD aspectX
; /* 40: relative width of device pixel */
77 WORD aspectY
; /* 42: relative height of device pixel */
78 WORD aspectXY
; /* 44: relative diagonal width of device pixel */
79 WORD pad1
[21]; /* 46-86: reserved */
80 WORD logPixelsX
; /* 88: pixels / logical X inch */
81 WORD logPixelsY
; /* 90: pixels / logical Y inch */
82 WORD pad2
[6]; /* 92-102: reserved */
83 WORD sizePalette
; /* 104: entries in system palette */
84 WORD numReserved
; /* 106: reserved entries */
85 WORD colorRes
; /* 108: color resolution */
89 /* Device independent DC information */
93 const DeviceCaps
*devCaps
;
95 HRGN16 hClipRgn
; /* Clip region (may be 0) */
96 HRGN16 hVisRgn
; /* Visible region (must never be 0) */
97 HRGN16 hGCClipRgn
; /* GC clip region (ClipRgn AND VisRgn) */
102 HBITMAP16 hFirstBitmap
; /* Bitmap selected at creation of the DC */
113 COLORREF backgroundColor
;
118 WORD textAlign
; /* Text alignment from SetTextAlign() */
119 short charExtra
; /* Spacing from SetTextCharacterExtra() */
120 short breakTotalExtra
; /* Total extra space for justification */
121 short breakCount
; /* Break char. count */
122 short breakExtra
; /* breakTotalExtra / breakCount */
123 short breakRem
; /* breakTotalExtra % breakCount */
129 INT32 GraphicsMode
; /* Graphics mode */
130 INT32 DCOrgX
; /* DC origin */
132 FARPROC16 lpfnPrint
; /* AbortProc for Printing */
133 INT32 CursPosX
; /* Current position */
136 XFORM xformWorld2Wnd
; /* World-to-window transformation */
137 XFORM xformWorld2Vport
; /* World-to-viewport transformation */
138 XFORM xformVport2World
; /* Inverse of the above transformation */
139 BOOL32 vport2WorldValid
; /* Is xformVport2World valid? */
142 typedef X11DRV_PDEVICE X_DC_INFO
; /* Temporary */
147 HDC32 hSelf
; /* Handle to this DC */
148 const struct tagDC_FUNCS
*funcs
; /* DC function table */
149 void *physDev
; /* Physical device (driver-specific) */
154 INT32 wndOrgX
; /* Window origin */
156 INT32 wndExtX
; /* Window extent */
158 INT32 vportOrgX
; /* Viewport origin */
160 INT32 vportExtX
; /* Viewport extent */
167 /* other devices (e.g. printer) */
171 /* Device functions for the Wine driver interface */
172 typedef struct tagDC_FUNCS
174 BOOL32 (*pArc
)(DC
*,INT32
,INT32
,INT32
,INT32
,INT32
,INT32
,INT32
,INT32
);
175 BOOL32 (*pBitBlt
)(DC
*,INT32
,INT32
,INT32
,INT32
,DC
*,INT32
,INT32
,DWORD
);
176 LONG (*pBitmapBits
)(HBITMAP32
,void*,LONG
,WORD
);
177 BOOL32 (*pChord
)(DC
*,INT32
,INT32
,INT32
,INT32
,INT32
,INT32
,INT32
,INT32
);
178 BOOL32 (*pCreateBitmap
)(HBITMAP32
);
179 BOOL32 (*pCreateDC
)(DC
*,LPCSTR
,LPCSTR
,LPCSTR
,const DEVMODE16
*);
180 BOOL32 (*pDeleteDC
)(DC
*);
181 BOOL32 (*pDeleteObject
)(HGDIOBJ32
);
182 BOOL32 (*pEllipse
)(DC
*,INT32
,INT32
,INT32
,INT32
);
183 BOOL32 (*pEnumDeviceFonts
)(DC
*,LPLOGFONT16
,DEVICEFONTENUMPROC
,LPARAM
);
184 INT32 (*pEscape
)(DC
*,INT32
,INT32
,SEGPTR
,SEGPTR
);
185 INT32 (*pExcludeClipRect
)(DC
*,INT32
,INT32
,INT32
,INT32
);
186 INT32 (*pExcludeVisRect
)(DC
*,INT32
,INT32
,INT32
,INT32
);
187 BOOL32 (*pExtFloodFill
)(DC
*,INT32
,INT32
,COLORREF
,UINT32
);
188 BOOL32 (*pExtTextOut
)(DC
*,INT32
,INT32
,UINT32
,const RECT32
*,LPCSTR
,UINT32
,const INT32
*);
189 BOOL32 (*pGetCharWidth
)(DC
*,UINT32
,UINT32
,LPINT32
);
190 COLORREF (*pGetPixel
)(DC
*,INT32
,INT32
);
191 BOOL32 (*pGetTextExtentPoint
)(DC
*,LPCSTR
,INT32
,LPSIZE32
);
192 BOOL32 (*pGetTextMetrics
)(DC
*,TEXTMETRIC32A
*);
193 INT32 (*pIntersectClipRect
)(DC
*,INT32
,INT32
,INT32
,INT32
);
194 INT32 (*pIntersectVisRect
)(DC
*,INT32
,INT32
,INT32
,INT32
);
195 BOOL32 (*pLineTo
)(DC
*,INT32
,INT32
);
196 BOOL32 (*pMoveToEx
)(DC
*,INT32
,INT32
,LPPOINT32
);
197 INT32 (*pOffsetClipRgn
)(DC
*,INT32
,INT32
);
198 BOOL32 (*pOffsetViewportOrg
)(DC
*,INT32
,INT32
);
199 BOOL32 (*pOffsetWindowOrg
)(DC
*,INT32
,INT32
);
200 BOOL32 (*pPaintRgn
)(DC
*,HRGN32
);
201 BOOL32 (*pPatBlt
)(DC
*,INT32
,INT32
,INT32
,INT32
,DWORD
);
202 BOOL32 (*pPie
)(DC
*,INT32
,INT32
,INT32
,INT32
,INT32
,INT32
,INT32
,INT32
);
203 BOOL32 (*pPolyPolygon
)(DC
*,const POINT32
*,const INT32
*,UINT32
);
204 BOOL32 (*pPolyPolyline
)(DC
*,const POINT32
*,const DWORD
*,DWORD
);
205 BOOL32 (*pPolygon
)(DC
*,const POINT32
*,INT32
);
206 BOOL32 (*pPolyline
)(DC
*,const POINT32
*,INT32
);
207 BOOL32 (*pPolyBezier
)(DC
*,POINT32
, const POINT32
*,DWORD
);
208 UINT32 (*pRealizePalette
)(DC
*);
209 BOOL32 (*pRectangle
)(DC
*,INT32
,INT32
,INT32
,INT32
);
210 BOOL32 (*pRestoreDC
)(DC
*,INT32
);
211 BOOL32 (*pRoundRect
)(DC
*,INT32
,INT32
,INT32
,INT32
,INT32
,INT32
);
212 INT32 (*pSaveDC
)(DC
*);
213 BOOL32 (*pScaleViewportExt
)(DC
*,INT32
,INT32
,INT32
,INT32
);
214 BOOL32 (*pScaleWindowExt
)(DC
*,INT32
,INT32
,INT32
,INT32
);
215 INT32 (*pSelectClipRgn
)(DC
*,HRGN32
);
216 HANDLE32 (*pSelectObject
)(DC
*,HANDLE32
);
217 HPALETTE32 (*pSelectPalette
)(DC
*,HPALETTE32
,BOOL32
);
218 COLORREF (*pSetBkColor
)(DC
*,COLORREF
);
219 WORD (*pSetBkMode
)(DC
*,WORD
);
220 VOID (*pSetDeviceClipping
)(DC
*);
221 INT32 (*pSetDIBitsToDevice
)(DC
*,INT32
,INT32
,DWORD
,DWORD
,INT32
,INT32
,UINT32
,UINT32
,LPCVOID
,const BITMAPINFO
*,UINT32
);
222 INT32 (*pSetMapMode
)(DC
*,INT32
);
223 DWORD (*pSetMapperFlags
)(DC
*,DWORD
);
224 COLORREF (*pSetPixel
)(DC
*,INT32
,INT32
,COLORREF
);
225 WORD (*pSetPolyFillMode
)(DC
*,WORD
);
226 WORD (*pSetROP2
)(DC
*,WORD
);
227 WORD (*pSetRelAbs
)(DC
*,WORD
);
228 WORD (*pSetStretchBltMode
)(DC
*,WORD
);
229 WORD (*pSetTextAlign
)(DC
*,WORD
);
230 INT32 (*pSetTextCharacterExtra
)(DC
*,INT32
);
231 DWORD (*pSetTextColor
)(DC
*,DWORD
);
232 INT32 (*pSetTextJustification
)(DC
*,INT32
,INT32
);
233 BOOL32 (*pSetViewportExt
)(DC
*,INT32
,INT32
);
234 BOOL32 (*pSetViewportOrg
)(DC
*,INT32
,INT32
);
235 BOOL32 (*pSetWindowExt
)(DC
*,INT32
,INT32
);
236 BOOL32 (*pSetWindowOrg
)(DC
*,INT32
,INT32
);
237 BOOL32 (*pStretchBlt
)(DC
*,INT32
,INT32
,INT32
,INT32
,DC
*,INT32
,INT32
,INT32
,INT32
,DWORD
);
238 INT32 (*pStretchDIBits
)(DC
*,INT32
,INT32
,INT32
,INT32
,INT32
,INT32
,INT32
,INT32
,const void *,const BITMAPINFO
*,UINT32
,DWORD
);
242 #define DCHC_INVALIDVISRGN 0x0001
243 #define DCHC_DELETEDC 0x0002
245 #define DCHF_INVALIDATEVISRGN 0x0001
246 #define DCHF_VALIDATEVISRGN 0x0002
249 #define DC_MEMORY 0x0001 /* It is a memory DC */
250 #define DC_SAVED 0x0002 /* It is a saved DC */
251 #define DC_DIRTY 0x0004 /* hVisRgn has to be updated */
252 #define DC_THUNKHOOK 0x0008 /* DC hook is in the 16-bit code */
254 /* Last 32 bytes are reserved for stock object handles */
255 #define GDI_HEAP_SIZE 0xffe0
257 /* First handle possible for stock objects (must be >= GDI_HEAP_SIZE) */
258 #define FIRST_STOCK_HANDLE GDI_HEAP_SIZE
260 /* Stock objects handles */
262 #define NB_STOCK_OBJECTS (DEFAULT_GUI_FONT + 1)
264 #define STOCK_WHITE_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+WHITE_BRUSH))
265 #define STOCK_LTGRAY_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+LTGRAY_BRUSH))
266 #define STOCK_GRAY_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+GRAY_BRUSH))
267 #define STOCK_DKGRAY_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+DKGRAY_BRUSH))
268 #define STOCK_BLACK_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+BLACK_BRUSH))
269 #define STOCK_NULL_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+NULL_BRUSH))
270 #define STOCK_HOLLOW_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+HOLLOW_BRUSH))
271 #define STOCK_WHITE_PEN ((HPEN16)(FIRST_STOCK_HANDLE+WHITE_PEN))
272 #define STOCK_BLACK_PEN ((HPEN16)(FIRST_STOCK_HANDLE+BLACK_PEN))
273 #define STOCK_NULL_PEN ((HPEN16)(FIRST_STOCK_HANDLE+NULL_PEN))
274 #define STOCK_OEM_FIXED_FONT ((HFONT16)(FIRST_STOCK_HANDLE+OEM_FIXED_FONT))
275 #define STOCK_ANSI_FIXED_FONT ((HFONT16)(FIRST_STOCK_HANDLE+ANSI_FIXED_FONT))
276 #define STOCK_ANSI_VAR_FONT ((HFONT16)(FIRST_STOCK_HANDLE+ANSI_VAR_FONT))
277 #define STOCK_SYSTEM_FONT ((HFONT16)(FIRST_STOCK_HANDLE+SYSTEM_FONT))
278 #define STOCK_DEVICE_DEFAULT_FONT ((HFONT16)(FIRST_STOCK_HANDLE+DEVICE_DEFAULT_FONT))
279 #define STOCK_DEFAULT_PALETTE ((HPALETTE16)(FIRST_STOCK_HANDLE+DEFAULT_PALETTE))
280 #define STOCK_SYSTEM_FIXED_FONT ((HFONT16)(FIRST_STOCK_HANDLE+SYSTEM_FIXED_FONT))
281 #define STOCK_DEFAULT_GUI_FONT ((HFONT16)(FIRST_STOCK_HANDLE+DEFAULT_GUI_FONT))
283 #define FIRST_STOCK_FONT STOCK_OEM_FIXED_FONT
284 #define LAST_STOCK_FONT STOCK_DEFAULT_GUI_FONT
286 #define LAST_STOCK_HANDLE ((DWORD)STOCK_DEFAULT_GUI_FONT)
288 /* Device <-> logical coords conversion */
290 /* A floating point version of the POINT structure */
291 typedef struct tagFLOAT_POINT
296 /* Rounds a floating point number to integer. The world-to-viewport
297 * transformation process is done in floating point internally. This function
298 * is then used to round these coordinates to integer values.
300 static __inline__ INT32
GDI_ROUND(FLOAT val
)
302 return (int)floor(val
+ 0.5);
305 /* Performs a viewport-to-world transformation on the specified point (which
306 * is in floating point format). Returns TRUE if successful, else FALSE.
308 static __inline__ BOOL32
INTERNAL_DPTOLP_FLOAT(DC
*dc
, FLOAT_POINT
*point
)
312 /* Check that the viewport-to-world transformation is valid */
313 if (!dc
->w
.vport2WorldValid
)
316 /* Perform the transformation */
319 point
->x
= x
* dc
->w
.xformVport2World
.eM11
+
320 y
* dc
->w
.xformVport2World
.eM21
+
321 dc
->w
.xformVport2World
.eDx
;
322 point
->y
= x
* dc
->w
.xformVport2World
.eM12
+
323 y
* dc
->w
.xformVport2World
.eM22
+
324 dc
->w
.xformVport2World
.eDy
;
329 /* Performs a viewport-to-world transformation on the specified point (which
330 * is in integer format). Returns TRUE if successful, else FALSE.
332 static __inline__ BOOL32
INTERNAL_DPTOLP(DC
*dc
, LPPOINT32 point
)
334 FLOAT_POINT floatPoint
;
336 /* Perform operation with floating point */
337 floatPoint
.x
=(FLOAT
)point
->x
;
338 floatPoint
.y
=(FLOAT
)point
->y
;
339 if (!INTERNAL_DPTOLP_FLOAT(dc
, &floatPoint
))
342 /* Round to integers */
343 point
->x
= GDI_ROUND(floatPoint
.x
);
344 point
->y
= GDI_ROUND(floatPoint
.y
);
349 /* Performs a world-to-viewport transformation on the specified point (which
350 * is in floating point format).
352 static __inline__
void INTERNAL_LPTODP_FLOAT(DC
*dc
, FLOAT_POINT
*point
)
356 /* Perform the transformation */
359 point
->x
= x
* dc
->w
.xformWorld2Vport
.eM11
+
360 y
* dc
->w
.xformWorld2Vport
.eM21
+
361 dc
->w
.xformWorld2Vport
.eDx
;
362 point
->y
= x
* dc
->w
.xformWorld2Vport
.eM12
+
363 y
* dc
->w
.xformWorld2Vport
.eM22
+
364 dc
->w
.xformWorld2Vport
.eDy
;
367 /* Performs a world-to-viewport transformation on the specified point (which
368 * is in integer format).
370 static __inline__
void INTERNAL_LPTODP(DC
*dc
, LPPOINT32 point
)
372 FLOAT_POINT floatPoint
;
374 /* Perform operation with floating point */
375 floatPoint
.x
=(FLOAT
)point
->x
;
376 floatPoint
.y
=(FLOAT
)point
->y
;
377 INTERNAL_LPTODP_FLOAT(dc
, &floatPoint
);
379 /* Round to integers */
380 point
->x
= GDI_ROUND(floatPoint
.x
);
381 point
->y
= GDI_ROUND(floatPoint
.y
);
384 #define XDPTOLP(dc,x) \
385 (((x)-(dc)->vportOrgX) * (dc)->wndExtX / (dc)->vportExtX+(dc)->wndOrgX)
386 #define YDPTOLP(dc,y) \
387 (((y)-(dc)->vportOrgY) * (dc)->wndExtY / (dc)->vportExtY+(dc)->wndOrgY)
388 #define XLPTODP(dc,x) \
389 (((x)-(dc)->wndOrgX) * (dc)->vportExtX / (dc)->wndExtX+(dc)->vportOrgX)
390 #define YLPTODP(dc,y) \
391 (((y)-(dc)->wndOrgY) * (dc)->vportExtY / (dc)->wndExtY+(dc)->vportOrgY)
393 /* Device <-> logical size conversion */
395 #define XDSTOLS(dc,x) \
396 ((x) * (dc)->wndExtX / (dc)->vportExtX)
397 #define YDSTOLS(dc,y) \
398 ((y) * (dc)->wndExtY / (dc)->vportExtY)
399 #define XLSTODS(dc,x) \
400 ((x) * (dc)->vportExtX / (dc)->wndExtX)
401 #define YLSTODS(dc,y) \
402 ((y) * (dc)->vportExtY / (dc)->wndExtY)
406 extern WORD GDI_HeapSel
;
408 #define GDI_HEAP_ALLOC(size) \
409 LOCAL_Alloc( GDI_HeapSel, LMEM_FIXED, (size) )
410 #define GDI_HEAP_ALLOC_MOVEABLE(size) \
411 LOCAL_Alloc( GDI_HeapSel, LMEM_MOVEABLE, (size) )
412 #define GDI_HEAP_REALLOC(handle,size) \
413 LOCAL_ReAlloc( GDI_HeapSel, (handle), (size), LMEM_FIXED )
414 #define GDI_HEAP_FREE(handle) \
415 LOCAL_Free( GDI_HeapSel, (handle) )
417 #define GDI_HEAP_LOCK(handle) \
418 LOCAL_Lock( GDI_HeapSel, (handle) )
419 #define GDI_HEAP_LOCK_SEGPTR(handle) \
420 LOCAL_LockSegptr( GDI_HeapSel, (handle) )
421 #define GDI_HEAP_UNLOCK(handle) \
422 ((((HGDIOBJ16)(handle) >= FIRST_STOCK_HANDLE) && \
423 ((HGDIOBJ16)(handle)<=LAST_STOCK_HANDLE)) ? \
424 0 : LOCAL_Unlock( GDI_HeapSel, (handle) ))
426 extern BOOL32
GDI_Init(void);
427 extern HGDIOBJ16
GDI_AllocObject( WORD
, WORD
);
428 extern BOOL32
GDI_FreeObject( HGDIOBJ16
);
429 extern GDIOBJHDR
* GDI_GetObjPtr( HGDIOBJ16
, WORD
);
431 extern BOOL32
DRIVER_RegisterDriver( LPCSTR name
, const DC_FUNCTIONS
*funcs
);
432 extern const DC_FUNCTIONS
*DRIVER_FindDriver( LPCSTR name
);
433 extern BOOL32
DRIVER_UnregisterDriver( LPCSTR name
);
435 extern BOOL32
DIB_Init(void);
437 extern Display
* display
;
438 extern Screen
* screen
;
439 extern Window rootWindow
;
440 extern int screenWidth
, screenHeight
, screenDepth
;
442 #endif /* __WINE_GDI_H */