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
;
120 WORD textAlign
; /* Text alignment from SetTextAlign() */
121 short charExtra
; /* Spacing from SetTextCharacterExtra() */
122 short breakTotalExtra
; /* Total extra space for justification */
123 short breakCount
; /* Break char. count */
124 short breakExtra
; /* breakTotalExtra / breakCount */
125 short breakRem
; /* breakTotalExtra % breakCount */
130 INT32 GraphicsMode
; /* Graphics mode */
131 INT32 DCOrgX
; /* DC origin */
133 FARPROC16 lpfnPrint
; /* AbortProc for Printing */
134 INT32 CursPosX
; /* Current position */
137 XFORM xformWorld2Wnd
; /* World-to-window transformation */
138 XFORM xformWorld2Vport
; /* World-to-viewport transformation */
139 XFORM xformVport2World
; /* Inverse of the above transformation */
140 BOOL32 vport2WorldValid
; /* Is xformVport2World valid? */
143 typedef X11DRV_PDEVICE X_DC_INFO
; /* Temporary */
148 HDC32 hSelf
; /* Handle to this DC */
149 const struct tagDC_FUNCS
*funcs
; /* DC function table */
150 void *physDev
; /* Physical device (driver-specific) */
155 INT32 wndOrgX
; /* Window origin */
157 INT32 wndExtX
; /* Window extent */
159 INT32 vportOrgX
; /* Viewport origin */
161 INT32 vportExtX
; /* Viewport extent */
168 /* other devices (e.g. printer) */
172 /* Device functions for the Wine driver interface */
173 typedef struct tagDC_FUNCS
175 BOOL32 (*pArc
)(DC
*,INT32
,INT32
,INT32
,INT32
,INT32
,INT32
,INT32
,INT32
);
176 BOOL32 (*pBitBlt
)(DC
*,INT32
,INT32
,INT32
,INT32
,DC
*,INT32
,INT32
,DWORD
);
177 BOOL32 (*pChord
)(DC
*,INT32
,INT32
,INT32
,INT32
,INT32
,INT32
,INT32
,INT32
);
178 BOOL32 (*pCreateDC
)(DC
*,LPCSTR
,LPCSTR
,LPCSTR
,const DEVMODE16
*);
179 BOOL32 (*pDeleteDC
)(DC
*);
180 BOOL32 (*pDeleteObject
)(HGDIOBJ16
);
181 BOOL32 (*pEllipse
)(DC
*,INT32
,INT32
,INT32
,INT32
);
182 BOOL32 (*pEnumDeviceFonts
)(DC
*,LPLOGFONT16
,DEVICEFONTENUMPROC
,LPARAM
);
183 INT32 (*pEscape
)(DC
*,INT32
,INT32
,SEGPTR
,SEGPTR
);
184 INT32 (*pExcludeClipRect
)(DC
*,INT32
,INT32
,INT32
,INT32
);
185 INT32 (*pExcludeVisRect
)(DC
*,INT32
,INT32
,INT32
,INT32
);
186 BOOL32 (*pExtFloodFill
)(DC
*,INT32
,INT32
,COLORREF
,UINT32
);
187 BOOL32 (*pExtTextOut
)(DC
*,INT32
,INT32
,UINT32
,const RECT32
*,LPCSTR
,UINT32
,const INT32
*);
188 BOOL32 (*pGetCharWidth
)(DC
*,UINT32
,UINT32
,LPINT32
);
189 COLORREF (*pGetPixel
)(DC
*,INT32
,INT32
);
190 BOOL32 (*pGetTextExtentPoint
)(DC
*,LPCSTR
,INT32
,LPSIZE32
);
191 BOOL32 (*pGetTextMetrics
)(DC
*,TEXTMETRIC32A
*);
192 INT32 (*pIntersectClipRect
)(DC
*,INT32
,INT32
,INT32
,INT32
);
193 INT32 (*pIntersectVisRect
)(DC
*,INT32
,INT32
,INT32
,INT32
);
194 BOOL32 (*pLineTo
)(DC
*,INT32
,INT32
);
195 BOOL32 (*pMoveToEx
)(DC
*,INT32
,INT32
,LPPOINT32
);
196 INT32 (*pOffsetClipRgn
)(DC
*,INT32
,INT32
);
197 BOOL32 (*pOffsetViewportOrg
)(DC
*,INT32
,INT32
);
198 BOOL32 (*pOffsetWindowOrg
)(DC
*,INT32
,INT32
);
199 BOOL32 (*pPaintRgn
)(DC
*,HRGN32
);
200 BOOL32 (*pPatBlt
)(DC
*,INT32
,INT32
,INT32
,INT32
,DWORD
);
201 BOOL32 (*pPie
)(DC
*,INT32
,INT32
,INT32
,INT32
,INT32
,INT32
,INT32
,INT32
);
202 BOOL32 (*pPolyPolygon
)(DC
*,LPPOINT32
,LPINT32
,UINT32
);
203 BOOL32 (*pPolyPolyline
)(DC
*,LPPOINT32
,LPDWORD
,DWORD
);
204 BOOL32 (*pPolygon
)(DC
*,LPPOINT32
,INT32
);
205 BOOL32 (*pPolyline
)(DC
*,LPPOINT32
,INT32
);
206 BOOL32 (*pPolyBezier
)(DC
*,POINT32
, LPPOINT32
,DWORD
);
207 UINT32 (*pRealizePalette
)(DC
*);
208 BOOL32 (*pRectangle
)(DC
*,INT32
,INT32
,INT32
,INT32
);
209 BOOL32 (*pRestoreDC
)(DC
*,INT32
);
210 BOOL32 (*pRoundRect
)(DC
*,INT32
,INT32
,INT32
,INT32
,INT32
,INT32
);
211 INT32 (*pSaveDC
)(DC
*);
212 BOOL32 (*pScaleViewportExt
)(DC
*,INT32
,INT32
,INT32
,INT32
);
213 BOOL32 (*pScaleWindowExt
)(DC
*,INT32
,INT32
,INT32
,INT32
);
214 INT32 (*pSelectClipRgn
)(DC
*,HRGN32
);
215 HANDLE32 (*pSelectObject
)(DC
*,HANDLE32
);
216 HPALETTE32 (*pSelectPalette
)(DC
*,HPALETTE32
,BOOL32
);
217 COLORREF (*pSetBkColor
)(DC
*,COLORREF
);
218 WORD (*pSetBkMode
)(DC
*,WORD
);
219 VOID (*pSetDeviceClipping
)(DC
*);
220 INT32 (*pSetDIBitsToDevice
)(DC
*,INT32
,INT32
,DWORD
,DWORD
,INT32
,INT32
,UINT32
,UINT32
,LPCVOID
,const BITMAPINFO
*,UINT32
);
221 INT32 (*pSetMapMode
)(DC
*,INT32
);
222 DWORD (*pSetMapperFlags
)(DC
*,DWORD
);
223 COLORREF (*pSetPixel
)(DC
*,INT32
,INT32
,COLORREF
);
224 WORD (*pSetPolyFillMode
)(DC
*,WORD
);
225 WORD (*pSetROP2
)(DC
*,WORD
);
226 WORD (*pSetRelAbs
)(DC
*,WORD
);
227 WORD (*pSetStretchBltMode
)(DC
*,WORD
);
228 WORD (*pSetTextAlign
)(DC
*,WORD
);
229 INT32 (*pSetTextCharacterExtra
)(DC
*,INT32
);
230 DWORD (*pSetTextColor
)(DC
*,DWORD
);
231 INT32 (*pSetTextJustification
)(DC
*,INT32
,INT32
);
232 BOOL32 (*pSetViewportExt
)(DC
*,INT32
,INT32
);
233 BOOL32 (*pSetViewportOrg
)(DC
*,INT32
,INT32
);
234 BOOL32 (*pSetWindowExt
)(DC
*,INT32
,INT32
);
235 BOOL32 (*pSetWindowOrg
)(DC
*,INT32
,INT32
);
236 BOOL32 (*pStretchBlt
)(DC
*,INT32
,INT32
,INT32
,INT32
,DC
*,INT32
,INT32
,INT32
,INT32
,DWORD
);
237 INT32 (*pStretchDIBits
)(DC
*,INT32
,INT32
,INT32
,INT32
,INT32
,INT32
,INT32
,INT32
,LPSTR
,LPBITMAPINFO
,WORD
,DWORD
);
241 #define DCHC_INVALIDVISRGN 0x0001
242 #define DCHC_DELETEDC 0x0002
244 #define DCHF_INVALIDATEVISRGN 0x0001
245 #define DCHF_VALIDATEVISRGN 0x0002
248 #define DC_MEMORY 0x0001 /* It is a memory DC */
249 #define DC_SAVED 0x0002 /* It is a saved DC */
250 #define DC_DIRTY 0x0004 /* hVisRgn has to be updated */
251 #define DC_THUNKHOOK 0x0008 /* DC hook is in the 16-bit code */
253 /* Last 32 bytes are reserved for stock object handles */
254 #define GDI_HEAP_SIZE 0xffe0
256 /* First handle possible for stock objects (must be >= GDI_HEAP_SIZE) */
257 #define FIRST_STOCK_HANDLE GDI_HEAP_SIZE
259 /* Stock objects handles */
261 #define NB_STOCK_OBJECTS (DEFAULT_GUI_FONT + 1)
263 #define STOCK_WHITE_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+WHITE_BRUSH))
264 #define STOCK_LTGRAY_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+LTGRAY_BRUSH))
265 #define STOCK_GRAY_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+GRAY_BRUSH))
266 #define STOCK_DKGRAY_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+DKGRAY_BRUSH))
267 #define STOCK_BLACK_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+BLACK_BRUSH))
268 #define STOCK_NULL_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+NULL_BRUSH))
269 #define STOCK_HOLLOW_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+HOLLOW_BRUSH))
270 #define STOCK_WHITE_PEN ((HPEN16)(FIRST_STOCK_HANDLE+WHITE_PEN))
271 #define STOCK_BLACK_PEN ((HPEN16)(FIRST_STOCK_HANDLE+BLACK_PEN))
272 #define STOCK_NULL_PEN ((HPEN16)(FIRST_STOCK_HANDLE+NULL_PEN))
273 #define STOCK_OEM_FIXED_FONT ((HFONT16)(FIRST_STOCK_HANDLE+OEM_FIXED_FONT))
274 #define STOCK_ANSI_FIXED_FONT ((HFONT16)(FIRST_STOCK_HANDLE+ANSI_FIXED_FONT))
275 #define STOCK_ANSI_VAR_FONT ((HFONT16)(FIRST_STOCK_HANDLE+ANSI_VAR_FONT))
276 #define STOCK_SYSTEM_FONT ((HFONT16)(FIRST_STOCK_HANDLE+SYSTEM_FONT))
277 #define STOCK_DEVICE_DEFAULT_FONT ((HFONT16)(FIRST_STOCK_HANDLE+DEVICE_DEFAULT_FONT))
278 #define STOCK_DEFAULT_PALETTE ((HPALETTE16)(FIRST_STOCK_HANDLE+DEFAULT_PALETTE))
279 #define STOCK_SYSTEM_FIXED_FONT ((HFONT16)(FIRST_STOCK_HANDLE+SYSTEM_FIXED_FONT))
280 #define STOCK_DEFAULT_GUI_FONT ((HFONT16)(FIRST_STOCK_HANDLE+DEFAULT_GUI_FONT))
282 #define FIRST_STOCK_FONT STOCK_OEM_FIXED_FONT
283 #define LAST_STOCK_FONT STOCK_DEFAULT_GUI_FONT
285 #define LAST_STOCK_HANDLE ((DWORD)STOCK_DEFAULT_GUI_FONT)
287 /* Device <-> logical coords conversion */
289 /* A floating point version of the POINT structure */
290 typedef struct tagFLOAT_POINT
295 /* Rounds a floating point number to integer. The world-to-viewport
296 * transformation process is done in floating point internally. This function
297 * is then used to round these coordinates to integer values.
299 static __inline__ INT32
GDI_ROUND(FLOAT val
)
301 return (int)floor(val
+ 0.5);
304 /* Performs a viewport-to-world transformation on the specified point (which
305 * is in floating point format). Returns TRUE if successful, else FALSE.
307 static __inline__ BOOL32
INTERNAL_DPTOLP_FLOAT(DC
*dc
, FLOAT_POINT
*point
)
311 /* Check that the viewport-to-world transformation is valid */
312 if (!dc
->w
.vport2WorldValid
)
315 /* Perform the transformation */
318 point
->x
= x
* dc
->w
.xformVport2World
.eM11
+
319 y
* dc
->w
.xformVport2World
.eM21
+
320 dc
->w
.xformVport2World
.eDx
;
321 point
->y
= x
* dc
->w
.xformVport2World
.eM12
+
322 y
* dc
->w
.xformVport2World
.eM22
+
323 dc
->w
.xformVport2World
.eDy
;
328 /* Performs a viewport-to-world transformation on the specified point (which
329 * is in integer format). Returns TRUE if successful, else FALSE.
331 static __inline__ BOOL32
INTERNAL_DPTOLP(DC
*dc
, LPPOINT32 point
)
333 FLOAT_POINT floatPoint
;
335 /* Perform operation with floating point */
336 floatPoint
.x
=(FLOAT
)point
->x
;
337 floatPoint
.y
=(FLOAT
)point
->y
;
338 if (!INTERNAL_DPTOLP_FLOAT(dc
, &floatPoint
))
341 /* Round to integers */
342 point
->x
= GDI_ROUND(floatPoint
.x
);
343 point
->y
= GDI_ROUND(floatPoint
.y
);
348 /* Performs a world-to-viewport transformation on the specified point (which
349 * is in floating point format).
351 static __inline__
void INTERNAL_LPTODP_FLOAT(DC
*dc
, FLOAT_POINT
*point
)
355 /* Perform the transformation */
358 point
->x
= x
* dc
->w
.xformWorld2Vport
.eM11
+
359 y
* dc
->w
.xformWorld2Vport
.eM21
+
360 dc
->w
.xformWorld2Vport
.eDx
;
361 point
->y
= x
* dc
->w
.xformWorld2Vport
.eM12
+
362 y
* dc
->w
.xformWorld2Vport
.eM22
+
363 dc
->w
.xformWorld2Vport
.eDy
;
366 /* Performs a world-to-viewport transformation on the specified point (which
367 * is in integer format).
369 static __inline__
void INTERNAL_LPTODP(DC
*dc
, LPPOINT32 point
)
371 FLOAT_POINT floatPoint
;
373 /* Perform operation with floating point */
374 floatPoint
.x
=(FLOAT
)point
->x
;
375 floatPoint
.y
=(FLOAT
)point
->y
;
376 INTERNAL_LPTODP_FLOAT(dc
, &floatPoint
);
378 /* Round to integers */
379 point
->x
= GDI_ROUND(floatPoint
.x
);
380 point
->y
= GDI_ROUND(floatPoint
.y
);
383 #define XDPTOLP(dc,x) \
384 (((x)-(dc)->vportOrgX) * (dc)->wndExtX / (dc)->vportExtX+(dc)->wndOrgX)
385 #define YDPTOLP(dc,y) \
386 (((y)-(dc)->vportOrgY) * (dc)->wndExtY / (dc)->vportExtY+(dc)->wndOrgY)
387 #define XLPTODP(dc,x) \
388 (((x)-(dc)->wndOrgX) * (dc)->vportExtX / (dc)->wndExtX+(dc)->vportOrgX)
389 #define YLPTODP(dc,y) \
390 (((y)-(dc)->wndOrgY) * (dc)->vportExtY / (dc)->wndExtY+(dc)->vportOrgY)
392 /* Device <-> logical size conversion */
394 #define XDSTOLS(dc,x) \
395 ((x) * (dc)->wndExtX / (dc)->vportExtX)
396 #define YDSTOLS(dc,y) \
397 ((y) * (dc)->wndExtY / (dc)->vportExtY)
398 #define XLSTODS(dc,x) \
399 ((x) * (dc)->vportExtX / (dc)->wndExtX)
400 #define YLSTODS(dc,y) \
401 ((y) * (dc)->vportExtY / (dc)->wndExtY)
405 extern WORD GDI_HeapSel
;
407 #define GDI_HEAP_ALLOC(size) \
408 LOCAL_Alloc( GDI_HeapSel, LMEM_FIXED, (size) )
409 #define GDI_HEAP_ALLOC_MOVEABLE(size) \
410 LOCAL_Alloc( GDI_HeapSel, LMEM_MOVEABLE, (size) )
411 #define GDI_HEAP_REALLOC(handle,size) \
412 LOCAL_ReAlloc( GDI_HeapSel, (handle), (size), LMEM_FIXED )
413 #define GDI_HEAP_FREE(handle) \
414 LOCAL_Free( GDI_HeapSel, (handle) )
416 #define GDI_HEAP_LOCK(handle) \
417 LOCAL_Lock( GDI_HeapSel, (handle) )
418 #define GDI_HEAP_LOCK_SEGPTR(handle) \
419 LOCAL_LockSegptr( GDI_HeapSel, (handle) )
420 #define GDI_HEAP_UNLOCK(handle) \
421 ((((HGDIOBJ16)(handle) >= FIRST_STOCK_HANDLE) && \
422 ((HGDIOBJ16)(handle)<=LAST_STOCK_HANDLE)) ? \
423 0 : LOCAL_Unlock( GDI_HeapSel, (handle) ))
425 extern BOOL32
GDI_Init(void);
426 extern HGDIOBJ16
GDI_AllocObject( WORD
, WORD
);
427 extern BOOL32
GDI_FreeObject( HGDIOBJ16
);
428 extern GDIOBJHDR
* GDI_GetObjPtr( HGDIOBJ16
, WORD
);
430 extern BOOL32
DRIVER_RegisterDriver( LPCSTR name
, const DC_FUNCTIONS
*funcs
);
431 extern const DC_FUNCTIONS
*DRIVER_FindDriver( LPCSTR name
);
432 extern BOOL32
DRIVER_UnregisterDriver( LPCSTR name
);
434 extern BOOL32
DIB_Init(void);
436 extern Display
* display
;
437 extern Screen
* screen
;
438 extern Window rootWindow
;
439 extern int screenWidth
, screenHeight
, screenDepth
;
441 #endif /* __WINE_GDI_H */