DIB Engine: fixes clipping, text and more
[wine/hacks.git] / dlls / winedib.drv / dibdrv.h
blob66cc1140676581b89fd23acf2e3fcce135753daf
1 /*
2 * DIB driver private definitions
4 * Copyright 2009 Massimo Del Fedele
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #ifndef __WINE_DIBDRV_H
21 #define __WINE_DIBDRV_H
23 #include <stdarg.h>
24 #include <stdlib.h>
25 #include <X11/Xlib.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winerror.h"
30 #include "wingdi.h"
31 #include "wine/list.h"
32 #include "wine/library.h"
33 #include "wine/debug.h"
34 #include "wingdi.h"
35 #include "winreg.h"
36 #include "wine/winbase16.h" /* GlobalLock16 */
38 #include "freetype.h"
40 /* data structures needed to access opaque pointers
41 * defined in gdi32.h */
42 #include "dibdrv_gdi32.h"
44 /* enable this if you want debugging (i.e. TRACEs) output */
45 #define DIBDRV_ENABLE_MAYBE
47 /* enable this if you want antialiased fonts */
48 #define DIBDRV_ANTIALIASED_FONTS
50 /* provide a way to make debugging output appear
51 only once. Usage example:
52 ONCE(FIXME("Some message\n")); */
53 #define ONCE(x) \
54 { \
55 static BOOL done = FALSE; \
56 if(!done) \
57 { \
58 done = TRUE; \
59 x; \
60 } \
63 /* provide a way to make debugging output appear
64 only if enabled here. Can speed up stuffs
65 avoiding long traces.Usage example:
66 MAYBE(TRACE("Some message\n")); */
67 #ifdef DIBDRV_ENABLE_MAYBE
68 #define MAYBE(x) x
69 #else
70 #define MAYBE(x)
71 #endif
74 /* extra stock object: default 1x1 bitmap for memory DCs
75 grabbed from gdi_private.h */
76 #define DEFAULT_BITMAP (STOCK_LAST+1)
78 struct _DIBDRVBITMAP;
79 struct _DIBDRVPHYSDEV;
80 typedef struct _DIBDRV_PRIMITIVE_FUNCS
82 /* color to pixel data conversion */
83 DWORD (* ColorToPixel) (const struct _DIBDRVBITMAP *bmp, COLORREF color);
85 /* pixel primitives */
86 void* (* GetPixelPointer) (const struct _DIBDRVBITMAP *bmp, int x, int y);
87 void (* SetPixel) ( struct _DIBDRVBITMAP *bmp, int x, int y, DWORD and, DWORD xor);
88 DWORD (* GetPixel) (const struct _DIBDRVBITMAP *bmp, int x, int y);
90 /* line drawing primitives */
91 void (* SolidHLine) ( struct _DIBDRVBITMAP *bmp, int x1, int x2, int y, DWORD and, DWORD xor);
92 void (* PatternHLine) ( struct _DIBDRVBITMAP *bmp, int x1, int x2, int y, const void *and, const void *xor, DWORD offset, DWORD count);
93 void (* SolidVLine) ( struct _DIBDRVBITMAP *bmp, int x, int y1, int y2, DWORD and, DWORD xor);
95 /* bitmap conversion helpers */
96 BOOL (* GetLine) (const struct _DIBDRVBITMAP *bmp, int line, int startx, int width, void *buf);
97 BOOL (* PutLine) ( struct _DIBDRVBITMAP *bmp, int line, int startx, int width, void *buf);
99 /* BitBlt primitives */
100 BOOL (* AlphaBlend) ( struct _DIBDRVPHYSDEV *physDevDst, int xDst, int yDst, int widthDst, int heightDst,
101 const struct _DIBDRVPHYSDEV *physDevSrc, int xSrc, int ySrc, int widthSrc, int heightSrc, BLENDFUNCTION blendFn );
102 BOOL (* BitBlt) ( struct _DIBDRVPHYSDEV *physDevDst, int xDst, int yDst, int width, int height,
103 const struct _DIBDRVPHYSDEV *physDevSrc, int xSrc, int ySrc, DWORD rop );
104 BOOL (* StretchBlt) ( struct _DIBDRVPHYSDEV *physDevDst, int xDst, int yDst, int widthDst, int heightDst,
105 const struct _DIBDRVPHYSDEV *physDevSrc, int xSrc, int ySrc, int widthSrc, int heightSrc, DWORD rop );
107 /* font drawing helper */
108 void (* FreetypeBlit) ( struct _DIBDRVPHYSDEV *physDev, int x, int y, RECT *clipRec, FT_Bitmap *bmp);
110 } DIBDRV_PRIMITIVE_FUNCS;
112 extern DIBDRV_PRIMITIVE_FUNCS DIBDRV_funcs_DIB32_RGB;
113 extern DIBDRV_PRIMITIVE_FUNCS DIBDRV_funcs_DIB32_BITFIELDS;
114 extern DIBDRV_PRIMITIVE_FUNCS DIBDRV_funcs_DIB24;
115 extern DIBDRV_PRIMITIVE_FUNCS DIBDRV_funcs_DIB16_RGB;
116 extern DIBDRV_PRIMITIVE_FUNCS DIBDRV_funcs_DIB16_BITFIELDS;
117 extern DIBDRV_PRIMITIVE_FUNCS DIBDRV_funcs_DIB8;
118 extern DIBDRV_PRIMITIVE_FUNCS DIBDRV_funcs_DIB4;
119 extern DIBDRV_PRIMITIVE_FUNCS DIBDRV_funcs_DIB1;
121 /* DIB bitmaps formats */
122 typedef enum _DIBFORMAT
124 DIBFMT_UNKNOWN = 0,
125 DIBFMT_DIB1 = 1,
126 DIBFMT_DIB4 = 2,
127 DIBFMT_DIB4_RLE = 3,
128 DIBFMT_DIB8 = 4,
129 DIBFMT_DIB8_RLE = 5,
130 DIBFMT_DIB16_RGB = 6,
131 DIBFMT_DIB16_BITFIELDS = 7,
132 DIBFMT_DIB24 = 8,
133 DIBFMT_DIB32_RGB = 9,
134 DIBFMT_DIB32_BITFIELDS = 10
135 } DIBFORMAT;
137 /* DIB driver's generic bitmap structure */
138 typedef struct _DIBDRVBITMAP
140 /* bitmap format of dib */
141 DIBFORMAT format;
143 /* pointer to top left corner of bitmap */
144 void *bits;
146 /* flags indicating if bits array is owned
147 by the bitmap */
148 BOOL ownsBits;
150 /* bitmap dimensions */
151 int width;
152 int height;
154 /* bitmap stride (== width in bytes) of a bitmap line */
155 /* negative for a bottom-up bitmap */
156 int stride;
158 /* number of bits/pixel in bitmap */
159 int bitCount;
161 /* calculated numbers for bitfields */
163 /* bitfields masks */
164 DWORD redMask, greenMask, blueMask;
165 /* shifting required within a COLORREF's BYTE */
166 int redShift, greenShift, blueShift;
167 /* size of the fields */
168 int redLen, greenLen, blueLen;
170 /* color table and its size */
171 RGBQUAD *colorTable;
172 DWORD colorTableSize;
174 /* flag indicating that color table has been grabbed */
175 BOOL colorTableGrabbed;
177 /* primitive function pointers */
178 DIBDRV_PRIMITIVE_FUNCS *funcs;
180 } DIBDRVBITMAP;
182 /* dash patterns */
183 typedef struct _DASHPATTERN
185 DWORD count;
186 DWORD dashes[6];
188 } DASHPATTERN;
190 /* DIB driver physical device */
191 typedef struct _DIBDRVPHYSDEV
193 /* X11 driver physical device */
194 PHYSDEV X11PhysDev;
196 /* HDC associated with physDev */
197 HDC hdc;
199 /* is a DIB selected into DC ? */
200 BOOL hasDIB;
202 /* currently selected HBITMAP */
203 HBITMAP hbitmap;
205 /* physical bitmap */
206 DIBDRVBITMAP physBitmap;
208 /* active ROP2 */
209 INT rop2;
211 /* clipping region and its rectangles */
212 HRGN region;
213 RGNDATA *regionData;
214 RECT *regionRects;
215 int regionRectCount;
217 /* background color and active ROP2 precalculated
218 AND and XOR values for it */
219 COLORREF backgroundColor;
220 DWORD backgroundAnd, backgroundXor;
222 /* pen color and active ROP2 precalculated
223 AND and XOR values for it */
224 COLORREF penColorref;
225 DWORD penColor;
226 DWORD penAnd, penXor;
227 const DASHPATTERN *penPattern;
228 DWORD curDash, leftInDash;
229 enum MARKSPACE { mark, space } markSpace;
231 /* pen style */
232 UINT penStyle;
234 /* pen drawing functions */
235 void (* penHLine) (struct _DIBDRVPHYSDEV *physDev, int x1, int x2, int y);
236 void (* penVLine) (struct _DIBDRVPHYSDEV *physDev, int x, int y1, int y2);
237 void (* penLine) (struct _DIBDRVPHYSDEV *physDev, int x1, int y1, int x2, int y2);
238 void (* brushHLine)(struct _DIBDRVPHYSDEV *physDev, int x1, int x2, int y);
240 /* brush color and active ROP2 precalculated
241 AND and XOR values for it */
242 COLORREF brushColorref;
243 DWORD brushColor;
244 DWORD brushAnd, brushXor;
245 DWORD *brushAnds, *brushXors;
247 /* brush style */
248 UINT brushStyle;
250 /* brush bitmap, if needed, and its converted/resized cache copy */
251 BOOL isBrushBitmap;
252 DIBDRVBITMAP brushBitmap;
253 DIBDRVBITMAP brushBmpCache;
255 /* text color */
256 COLORREF textColor;
257 COLORREF textBackground;
259 #ifdef DIBDRV_ANTIALIASED_FONTS
260 /* text color table for antialiased fonts */
261 COLORREF textColorTable[256];
262 #endif
264 /* freetype face associated to current DC HFONT */
265 FT_Face face;
267 } DIBDRVPHYSDEV;
270 /* *********************************************************************
271 * DISPLAY DRIVER ACCESS FUNCTIONS
272 * ********************************************************************/
274 /* LoadDisplayDriver
275 * Loads display driver - partially grabbed from gdi32 */
276 DC_FUNCTIONS *_DIBDRV_LoadDisplayDriver(void);
278 /* FreeDisplayDriver
279 Frees resources allocated by Display driver */
280 void _DIBDRV_FreeDisplayDriver(void);
282 /* GetDisplayDriver
283 Gets a pointer to display drives'function table */
284 inline DC_FUNCTIONS *_DIBDRV_GetDisplayDriver(void);
286 /* *********************************************************************
287 * ROP2 AND OTHER DRAWING RELATED FUNCTIONS
288 * ********************************************************************/
290 void _DIBDRV_CalcAndXorMasks(INT rop, DWORD color, DWORD *and, DWORD *xor);
292 inline void _DIBDRV_rop32(DWORD *ptr, DWORD and, DWORD xor);
293 inline void _DIBDRV_rop16(WORD *ptr, WORD and, WORD xor);
294 inline void _DIBDRV_rop8(BYTE *ptr, BYTE and, BYTE xor);
296 void _DIBDRV_ResetDashOrigin(DIBDRVPHYSDEV *physDev);
298 /* *********************************************************************
299 * ROP2 FUNCTIONS
300 * ********************************************************************/
302 /* the ROP3 operations
303 this is a BIG case block; beware that some
304 commons ROP3 operations will be optimized
305 from inside blt routines */
306 DWORD _DIBDRV_ROP3(DWORD p, DWORD s, DWORD d, BYTE rop);
308 /* *********************************************************************
309 * PHYSICAL BITMAP FUNCTIONS
310 * ********************************************************************/
312 /* gets human-readable dib format name */
313 const char *_DIBDRVBITMAP_GetFormatName(DIBDRVBITMAP const *bmp);
315 /* initializes dib from a bitmap :
316 dib dib being initialized
317 bi source BITMAPINFOHEADER with required DIB format info
318 bit_fields color masks
319 color_table color table, if any
320 bits pointer to image data array
321 NOTE : DIBDRVBITMAP doesn't owns bits, but do own color table */
322 BOOL _DIBDRVBITMAP_InitFromBMIH(DIBDRVBITMAP *dib, const BITMAPINFOHEADER *bi, const DWORD *bit_fields,
323 const RGBQUAD *color_table, void *bits);
325 BOOL _DIBDRVBITMAP_InitFromBitmapinfo(DIBDRVBITMAP *dib, BITMAPINFO *bmi);
327 /* initializes a DIBRDVBITMAP copying it from a source one
328 Parameters :
329 dib destination DIBDRVBITMAP
330 src source DIBDRVBITMAP
331 copy TRUE->copy source pixel array FALSE->link to source pixel array */
332 BOOL _DIBDRVBITMAP_InitFromDibdrvbitmap(DIBDRVBITMAP *dib, const DIBDRVBITMAP *src, BOOL copy);
334 /* creates a DIBRDVBITMAP copying format info from a source one
335 Parameters :
336 dib destination DIBDRVBITMAP
337 src source DIBDRVBITMAP
338 widht, height sizes of newly created bitmap */
339 BOOL _DIBDRVBITMAP_CreateFromDibdrvbitmap(DIBDRVBITMAP *dib, const DIBDRVBITMAP *src, int width, int height);
341 /* Clears a DIBDRVBITMAP structure data
342 WARNING : doesn't free anything */
343 void _DIBDRVBITMAP_Clear(DIBDRVBITMAP *bmp);
345 /* Frees a DIBDRVBITMAP structure data */
346 void _DIBDRVBITMAP_Free(DIBDRVBITMAP *bmp);
348 /* checks whether the format of 2 DIBs are identical
349 it checks the pixel bit count and the color table size
350 and content, if needed */
351 BOOL _DIBDRVBITMAP_FormatMatch(const DIBDRVBITMAP *d1, const DIBDRVBITMAP *d2);
353 /* convert a given dib into another format given by 'format' parameter */
354 BOOL _DIBDRVBITMAP_Convert(DIBDRVBITMAP *dst, const DIBDRVBITMAP *src, const DIBDRVBITMAP *format);
356 /* creates a solid-filled DIB of given color and format
357 DIB format is given by 'format' parameter */
358 BOOL _DIBDRVBITMAP_CreateSolid(DIBDRVBITMAP *bmp, DIBDRVBITMAP *format, int width, int height, DWORD Color);
360 /* expands horizontally a bitmap to reach a minimum size,
361 keeping its width as a multiple of a base width
362 Used to widen brushes in order to optimize blitting */
363 BOOL _DIBDRVBITMAP_ExpandHoriz(DIBDRVBITMAP *dib, int baseWidth, int minWidth);
365 /* *********************************************************************
366 * DIB <--> DDB CONVERSION ROUTINES
367 * ********************************************************************/
369 /***********************************************************************
370 * Creates DDB that is compatible with source hdc.
371 * hdc is the HDC on where the DIB MUST be selected in
372 * srcBmp is the source DIB
373 * startScan and scanLines specify the portion of DIB to convert
374 * in order to avoid unneeded conversion of large DIBs on blitting
376 * NOTE : the srcBmp DIB MUST NOT be selected in any DC */
377 HBITMAP _DIBDRV_ConvertDIBtoDDB( HDC hdc, HBITMAP srcBmp, int startScan, int scanLines );
379 /***********************************************************************
380 * Creates DIB that is compatible with the target hdc.
381 * startScan and scanLines specify the portion of DDB to convert
382 * in order to avoid unneeded conversion of large DDBs on blitting
384 * NOTE : the srcBmp DDB MUST NOT be selected in any DC */
385 HBITMAP _DIBDRV_ConvertDDBtoDIB( HDC hdc, HBITMAP srcBmp, int startScan, int scanLines );
387 /***********************************************************************
388 * Creates DIB that is compatible with the target hdc for a device (non memory) source DC */
389 HBITMAP _DIBDRV_ConvertDevDDBtoDIB( HDC hdcSrc, HDC hdcDst, int xSrc, int ySrc, int width, int height );
391 /* *********************************************************************
392 * QUERY FUNCTIONS
393 * ********************************************************************/
395 /***********************************************************************
396 * DIBDRV_GetDeviceCaps */
397 INT DIBDRV_GetDeviceCaps( DIBDRVPHYSDEV *physDev, INT cap );
399 /* *********************************************************************
400 * GEOMETRIC UTILITIES
401 * ********************************************************************/
403 /* intersect 2 rectangles (just to not use USER32 one...) */
404 BOOL _DIBDRV_IntersectRect(RECT *d, const RECT *s1, const RECT *s2);
406 /* converts positions from Word space to Device space */
407 void _DIBDRV_Position_ws2ds(DIBDRVPHYSDEV *physDev, int *x, int *y);
408 void _DIBDRV_Positions_ws2ds(DIBDRVPHYSDEV *physDev, int *x1, int *y1, int *x2, int *y2);
410 /* converts sizes from Word space to Device space */
411 void _DIBDRV_Sizes_ws2ds(DIBDRVPHYSDEV *physDev, int *w, int *h);
413 /* converts a rectangle form Word space to Device space */
414 void _DIBDRV_Rect_ws2ds(DIBDRVPHYSDEV *physDev, const RECT *src, RECT *dst);
416 #endif