Release 980628
[wine/multimedia.git] / include / gdi.h
blob723aa2f4e6c4e472c4e05cf287ddf0c6f2915c53
1 /*
2 * GDI definitions
4 * Copyright 1993 Alexandre Julliard
5 */
7 #ifndef __WINE_GDI_H
8 #define __WINE_GDI_H
10 #include "windows.h"
11 #include "ldt.h"
12 #include "local.h"
13 #include "x11drv.h"
14 #include "path.h"
15 #include <math.h>
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
33 HANDLE16 hNext;
34 WORD wMagic;
35 DWORD dwCount;
36 } GDIOBJHDR;
39 #define OBJ_PEN 1
40 #define OBJ_BRUSH 2
41 #define OBJ_DC 3
42 #define OBJ_METADC 4
43 #define OBJ_PAL 5
44 #define OBJ_FONT 6
45 #define OBJ_BITMAP 7
46 #define OBJ_REGION 8
47 #define OBJ_METAFILE 9
48 #define OBJ_MEMDC 10
49 #define OBJ_EXTPEN 11
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 */
86 } DeviceCaps;
89 /* Device independent DC information */
90 typedef struct
92 int flags;
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) */
98 HPEN16 hPen;
99 HBRUSH16 hBrush;
100 HFONT16 hFont;
101 HBITMAP16 hBitmap;
102 HBITMAP16 hFirstBitmap; /* Bitmap selected at creation of the DC */
103 HANDLE16 hDevice;
104 HPALETTE16 hPalette;
106 GdiPath path;
108 WORD ROPmode;
109 WORD polyFillMode;
110 WORD stretchBltMode;
111 WORD relAbsMode;
112 WORD backgroundMode;
113 COLORREF backgroundColor;
114 COLORREF textColor;
115 int backgroundPixel;
116 int textPixel;
117 short brushOrgX;
118 short brushOrgY;
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 */
127 BYTE bitsPerPixel;
129 INT32 MapMode;
130 INT32 GraphicsMode; /* Graphics mode */
131 INT32 DCOrgX; /* DC origin */
132 INT32 DCOrgY;
133 FARPROC16 lpfnPrint; /* AbortProc for Printing */
134 INT32 CursPosX; /* Current position */
135 INT32 CursPosY;
136 INT32 ArcDirection;
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? */
141 } WIN_DC_INFO;
143 typedef X11DRV_PDEVICE X_DC_INFO; /* Temporary */
145 typedef struct tagDC
147 GDIOBJHDR header;
148 HDC32 hSelf; /* Handle to this DC */
149 const struct tagDC_FUNCS *funcs; /* DC function table */
150 void *physDev; /* Physical device (driver-specific) */
151 INT32 saveLevel;
152 DWORD dwHookData;
153 FARPROC16 hookProc;
155 INT32 wndOrgX; /* Window origin */
156 INT32 wndOrgY;
157 INT32 wndExtX; /* Window extent */
158 INT32 wndExtY;
159 INT32 vportOrgX; /* Viewport origin */
160 INT32 vportOrgY;
161 INT32 vportExtX; /* Viewport extent */
162 INT32 vportExtY;
164 WIN_DC_INFO w;
165 union
167 X_DC_INFO x;
168 /* other devices (e.g. printer) */
169 } u;
170 } DC;
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,LPINT32,UINT32);
204 BOOL32 (*pPolygon)(DC*,LPPOINT32,INT32);
205 BOOL32 (*pPolyline)(DC*,LPPOINT32,INT32);
206 UINT32 (*pRealizePalette)(DC*);
207 BOOL32 (*pRectangle)(DC*,INT32,INT32,INT32,INT32);
208 BOOL32 (*pRestoreDC)(DC*,INT32);
209 BOOL32 (*pRoundRect)(DC*,INT32,INT32,INT32,INT32,INT32,INT32);
210 INT32 (*pSaveDC)(DC*);
211 BOOL32 (*pScaleViewportExt)(DC*,INT32,INT32,INT32,INT32);
212 BOOL32 (*pScaleWindowExt)(DC*,INT32,INT32,INT32,INT32);
213 INT32 (*pSelectClipRgn)(DC*,HRGN32);
214 HANDLE32 (*pSelectObject)(DC*,HANDLE32);
215 HPALETTE32 (*pSelectPalette)(DC*,HPALETTE32,BOOL32);
216 COLORREF (*pSetBkColor)(DC*,COLORREF);
217 WORD (*pSetBkMode)(DC*,WORD);
218 VOID (*pSetDeviceClipping)(DC*);
219 INT32 (*pSetDIBitsToDevice)(DC*,INT32,INT32,DWORD,DWORD,INT32,INT32,UINT32,UINT32,LPCVOID,const BITMAPINFO*,UINT32);
220 INT32 (*pSetMapMode)(DC*,INT32);
221 DWORD (*pSetMapperFlags)(DC*,DWORD);
222 COLORREF (*pSetPixel)(DC*,INT32,INT32,COLORREF);
223 WORD (*pSetPolyFillMode)(DC*,WORD);
224 WORD (*pSetROP2)(DC*,WORD);
225 WORD (*pSetRelAbs)(DC*,WORD);
226 WORD (*pSetStretchBltMode)(DC*,WORD);
227 WORD (*pSetTextAlign)(DC*,WORD);
228 INT32 (*pSetTextCharacterExtra)(DC*,INT32);
229 DWORD (*pSetTextColor)(DC*,DWORD);
230 INT32 (*pSetTextJustification)(DC*,INT32,INT32);
231 BOOL32 (*pSetViewportExt)(DC*,INT32,INT32);
232 BOOL32 (*pSetViewportOrg)(DC*,INT32,INT32);
233 BOOL32 (*pSetWindowExt)(DC*,INT32,INT32);
234 BOOL32 (*pSetWindowOrg)(DC*,INT32,INT32);
235 BOOL32 (*pStretchBlt)(DC*,INT32,INT32,INT32,INT32,DC*,INT32,INT32,INT32,INT32,DWORD);
236 INT32 (*pStretchDIBits)(DC*,INT32,INT32,INT32,INT32,INT32,INT32,INT32,INT32,LPSTR,LPBITMAPINFO,WORD,DWORD);
237 } DC_FUNCTIONS;
239 /* DC hook codes */
240 #define DCHC_INVALIDVISRGN 0x0001
241 #define DCHC_DELETEDC 0x0002
243 #define DCHF_INVALIDATEVISRGN 0x0001
244 #define DCHF_VALIDATEVISRGN 0x0002
246 /* DC flags */
247 #define DC_MEMORY 0x0001 /* It is a memory DC */
248 #define DC_SAVED 0x0002 /* It is a saved DC */
249 #define DC_DIRTY 0x0004 /* hVisRgn has to be updated */
250 #define DC_THUNKHOOK 0x0008 /* DC hook is in the 16-bit code */
252 /* Last 32 bytes are reserved for stock object handles */
253 #define GDI_HEAP_SIZE 0xffe0
255 /* First handle possible for stock objects (must be >= GDI_HEAP_SIZE) */
256 #define FIRST_STOCK_HANDLE GDI_HEAP_SIZE
258 /* Stock objects handles */
260 #define NB_STOCK_OBJECTS (DEFAULT_GUI_FONT + 1)
262 #define STOCK_WHITE_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+WHITE_BRUSH))
263 #define STOCK_LTGRAY_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+LTGRAY_BRUSH))
264 #define STOCK_GRAY_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+GRAY_BRUSH))
265 #define STOCK_DKGRAY_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+DKGRAY_BRUSH))
266 #define STOCK_BLACK_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+BLACK_BRUSH))
267 #define STOCK_NULL_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+NULL_BRUSH))
268 #define STOCK_HOLLOW_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+HOLLOW_BRUSH))
269 #define STOCK_WHITE_PEN ((HPEN16)(FIRST_STOCK_HANDLE+WHITE_PEN))
270 #define STOCK_BLACK_PEN ((HPEN16)(FIRST_STOCK_HANDLE+BLACK_PEN))
271 #define STOCK_NULL_PEN ((HPEN16)(FIRST_STOCK_HANDLE+NULL_PEN))
272 #define STOCK_OEM_FIXED_FONT ((HFONT16)(FIRST_STOCK_HANDLE+OEM_FIXED_FONT))
273 #define STOCK_ANSI_FIXED_FONT ((HFONT16)(FIRST_STOCK_HANDLE+ANSI_FIXED_FONT))
274 #define STOCK_ANSI_VAR_FONT ((HFONT16)(FIRST_STOCK_HANDLE+ANSI_VAR_FONT))
275 #define STOCK_SYSTEM_FONT ((HFONT16)(FIRST_STOCK_HANDLE+SYSTEM_FONT))
276 #define STOCK_DEVICE_DEFAULT_FONT ((HFONT16)(FIRST_STOCK_HANDLE+DEVICE_DEFAULT_FONT))
277 #define STOCK_DEFAULT_PALETTE ((HPALETTE16)(FIRST_STOCK_HANDLE+DEFAULT_PALETTE))
278 #define STOCK_SYSTEM_FIXED_FONT ((HFONT16)(FIRST_STOCK_HANDLE+SYSTEM_FIXED_FONT))
279 #define STOCK_DEFAULT_GUI_FONT ((HFONT16)(FIRST_STOCK_HANDLE+DEFAULT_GUI_FONT))
281 #define FIRST_STOCK_FONT STOCK_OEM_FIXED_FONT
282 #define LAST_STOCK_FONT STOCK_DEFAULT_GUI_FONT
284 #define LAST_STOCK_HANDLE ((DWORD)STOCK_DEFAULT_GUI_FONT)
286 /* Device <-> logical coords conversion */
288 /* A floating point version of the POINT structure */
289 typedef struct tagFLOAT_POINT
291 FLOAT x, y;
292 } FLOAT_POINT;
294 /* Rounds a floating point number to integer. The world-to-viewport
295 * transformation process is done in floating point internally. This function
296 * is then used to round these coordinates to integer values.
298 static __inline__ INT32 GDI_ROUND(FLOAT val)
300 return (int)floor(val + 0.5);
303 /* Performs a viewport-to-world transformation on the specified point (which
304 * is in floating point format). Returns TRUE if successful, else FALSE.
306 static __inline__ BOOL32 INTERNAL_DPTOLP_FLOAT(DC *dc, FLOAT_POINT *point)
308 FLOAT x, y;
310 /* Check that the viewport-to-world transformation is valid */
311 if (!dc->w.vport2WorldValid)
312 return FALSE;
314 /* Perform the transformation */
315 x = point->x;
316 y = point->y;
317 point->x = x * dc->w.xformVport2World.eM11 +
318 y * dc->w.xformVport2World.eM21 +
319 dc->w.xformVport2World.eDx;
320 point->y = x * dc->w.xformVport2World.eM12 +
321 y * dc->w.xformVport2World.eM22 +
322 dc->w.xformVport2World.eDy;
324 return TRUE;
327 /* Performs a viewport-to-world transformation on the specified point (which
328 * is in integer format). Returns TRUE if successful, else FALSE.
330 static __inline__ BOOL32 INTERNAL_DPTOLP(DC *dc, LPPOINT32 point)
332 FLOAT_POINT floatPoint;
334 /* Perform operation with floating point */
335 floatPoint.x=(FLOAT)point->x;
336 floatPoint.y=(FLOAT)point->y;
337 if (!INTERNAL_DPTOLP_FLOAT(dc, &floatPoint))
338 return FALSE;
340 /* Round to integers */
341 point->x = GDI_ROUND(floatPoint.x);
342 point->y = GDI_ROUND(floatPoint.y);
344 return TRUE;
347 /* Performs a world-to-viewport transformation on the specified point (which
348 * is in floating point format).
350 static __inline__ void INTERNAL_LPTODP_FLOAT(DC *dc, FLOAT_POINT *point)
352 FLOAT x, y;
354 /* Perform the transformation */
355 x = point->x;
356 y = point->y;
357 point->x = x * dc->w.xformWorld2Vport.eM11 +
358 y * dc->w.xformWorld2Vport.eM21 +
359 dc->w.xformWorld2Vport.eDx;
360 point->y = x * dc->w.xformWorld2Vport.eM12 +
361 y * dc->w.xformWorld2Vport.eM22 +
362 dc->w.xformWorld2Vport.eDy;
365 /* Performs a world-to-viewport transformation on the specified point (which
366 * is in integer format).
368 static __inline__ void INTERNAL_LPTODP(DC *dc, LPPOINT32 point)
370 FLOAT_POINT floatPoint;
372 /* Perform operation with floating point */
373 floatPoint.x=(FLOAT)point->x;
374 floatPoint.y=(FLOAT)point->y;
375 INTERNAL_LPTODP_FLOAT(dc, &floatPoint);
377 /* Round to integers */
378 point->x = GDI_ROUND(floatPoint.x);
379 point->y = GDI_ROUND(floatPoint.y);
382 #define XDPTOLP(dc,x) \
383 (((x)-(dc)->vportOrgX) * (dc)->wndExtX / (dc)->vportExtX+(dc)->wndOrgX)
384 #define YDPTOLP(dc,y) \
385 (((y)-(dc)->vportOrgY) * (dc)->wndExtY / (dc)->vportExtY+(dc)->wndOrgY)
386 #define XLPTODP(dc,x) \
387 (((x)-(dc)->wndOrgX) * (dc)->vportExtX / (dc)->wndExtX+(dc)->vportOrgX)
388 #define YLPTODP(dc,y) \
389 (((y)-(dc)->wndOrgY) * (dc)->vportExtY / (dc)->wndExtY+(dc)->vportOrgY)
391 /* Device <-> logical size conversion */
393 #define XDSTOLS(dc,x) \
394 ((x) * (dc)->wndExtX / (dc)->vportExtX)
395 #define YDSTOLS(dc,y) \
396 ((y) * (dc)->wndExtY / (dc)->vportExtY)
397 #define XLSTODS(dc,x) \
398 ((x) * (dc)->vportExtX / (dc)->wndExtX)
399 #define YLSTODS(dc,y) \
400 ((y) * (dc)->vportExtY / (dc)->wndExtY)
402 /* GDI local heap */
404 extern WORD GDI_HeapSel;
406 #define GDI_HEAP_ALLOC(size) \
407 LOCAL_Alloc( GDI_HeapSel, LMEM_FIXED, (size) )
408 #define GDI_HEAP_ALLOC_MOVEABLE(size) \
409 LOCAL_Alloc( GDI_HeapSel, LMEM_MOVEABLE, (size) )
410 #define GDI_HEAP_REALLOC(handle,size) \
411 LOCAL_ReAlloc( GDI_HeapSel, (handle), (size), LMEM_FIXED )
412 #define GDI_HEAP_FREE(handle) \
413 LOCAL_Free( GDI_HeapSel, (handle) )
415 #define GDI_HEAP_LOCK(handle) \
416 LOCAL_Lock( GDI_HeapSel, (handle) )
417 #define GDI_HEAP_LOCK_SEGPTR(handle) \
418 LOCAL_LockSegptr( GDI_HeapSel, (handle) )
419 #define GDI_HEAP_UNLOCK(handle) \
420 ((((HGDIOBJ16)(handle) >= FIRST_STOCK_HANDLE) && \
421 ((HGDIOBJ16)(handle)<=LAST_STOCK_HANDLE)) ? \
422 0 : LOCAL_Unlock( GDI_HeapSel, (handle) ))
424 extern BOOL32 GDI_Init(void);
425 extern HGDIOBJ16 GDI_AllocObject( WORD, WORD );
426 extern BOOL32 GDI_FreeObject( HGDIOBJ16 );
427 extern GDIOBJHDR * GDI_GetObjPtr( HGDIOBJ16, WORD );
429 extern BOOL32 DRIVER_RegisterDriver( LPCSTR name, const DC_FUNCTIONS *funcs );
430 extern const DC_FUNCTIONS *DRIVER_FindDriver( LPCSTR name );
431 extern BOOL32 DRIVER_UnregisterDriver( LPCSTR name );
433 extern BOOL32 DIB_Init(void);
435 extern Display * display;
436 extern Screen * screen;
437 extern Window rootWindow;
438 extern int screenWidth, screenHeight, screenDepth;
440 #endif /* __WINE_GDI_H */