DIB Engine: Add clipping on xxxBlt and AlphaBlend
[wine/hacks.git] / dlls / winedib.drv / dibdrv.h
blobb0f128ecbcd3c168d812d9a8046d2c61c0f7f6fe
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 /* provide a way to make debugging output appear
48 only once. Usage example:
49 ONCE(FIXME("Some message\n")); */
50 #define ONCE(x) \
51 { \
52 static BOOL done = FALSE; \
53 if(!done) \
54 { \
55 done = TRUE; \
56 x; \
57 } \
60 /* provide a way to make debugging output appear
61 only if enabled here. Can speed up stuffs
62 avoiding long traces.Usage example:
63 MAYBE(TRACE("Some message\n")); */
64 #ifdef DIBDRV_ENABLE_MAYBE
65 #define MAYBE(x) x
66 #else
67 #define MAYBE(x)
68 #endif
71 /* extra stock object: default 1x1 bitmap for memory DCs
72 grabbed from gdi_private.h */
73 #define DEFAULT_BITMAP (STOCK_LAST+1)
75 struct _DIBDRVBITMAP;
76 struct _DIBDRVPHYSDEV;
77 typedef struct _DIBDRV_PRIMITIVE_FUNCS
79 /* color to pixel data conversion */
80 DWORD (* ColorToPixel) (const struct _DIBDRVBITMAP *bmp, COLORREF color);
82 /* pixel primitives */
83 void* (* GetPixelPointer) (const struct _DIBDRVBITMAP *bmp, int x, int y);
84 void (* SetPixel) ( struct _DIBDRVBITMAP *bmp, int x, int y, DWORD and, DWORD xor);
85 DWORD (* GetPixel) (const struct _DIBDRVBITMAP *bmp, int x, int y);
87 /* line drawing primitives */
88 void (* SolidHLine) ( struct _DIBDRVBITMAP *bmp, int x1, int x2, int y, DWORD and, DWORD xor);
89 void (* PatternHLine) ( struct _DIBDRVBITMAP *bmp, int x1, int x2, int y, const void *and, const void *xor, DWORD offset, DWORD count);
90 void (* SolidVLine) ( struct _DIBDRVBITMAP *bmp, int x, int y1, int y2, DWORD and, DWORD xor);
92 /* bitmap conversion helpers */
93 BOOL (* GetLine) (const struct _DIBDRVBITMAP *bmp, int line, int startx, int width, void *buf);
94 BOOL (* PutLine) ( struct _DIBDRVBITMAP *bmp, int line, int startx, int width, void *buf);
96 /* BitBlt primitives */
97 BOOL (* AlphaBlend) ( struct _DIBDRVPHYSDEV *physDevDst, int xDst, int yDst, int widthDst, int heightDst,
98 const struct _DIBDRVPHYSDEV *physDevSrc, int xSrc, int ySrc, int widthSrc, int heightSrc, BLENDFUNCTION blendFn );
99 BOOL (* BitBlt) ( struct _DIBDRVPHYSDEV *physDevDst, int xDst, int yDst, int width, int height,
100 const struct _DIBDRVPHYSDEV *physDevSrc, int xSrc, int ySrc, DWORD rop );
101 BOOL (* StretchBlt) ( struct _DIBDRVPHYSDEV *physDevDst, int xDst, int yDst, int widthDst, int heightDst,
102 const struct _DIBDRVPHYSDEV *physDevSrc, int xSrc, int ySrc, int widthSrc, int heightSrc, DWORD rop );
104 /* font drawing helper */
105 void (* FreetypeBlit) ( struct _DIBDRVPHYSDEV *physDev, int x, int y, FT_Bitmap *bmp);
107 } DIBDRV_PRIMITIVE_FUNCS;
109 extern DIBDRV_PRIMITIVE_FUNCS DIBDRV_funcs_DIB32_RGB;
110 extern DIBDRV_PRIMITIVE_FUNCS DIBDRV_funcs_DIB32_BITFIELDS;
111 extern DIBDRV_PRIMITIVE_FUNCS DIBDRV_funcs_DIB24;
112 extern DIBDRV_PRIMITIVE_FUNCS DIBDRV_funcs_DIB16_RGB;
113 extern DIBDRV_PRIMITIVE_FUNCS DIBDRV_funcs_DIB16_BITFIELDS;
114 extern DIBDRV_PRIMITIVE_FUNCS DIBDRV_funcs_DIB8;
115 extern DIBDRV_PRIMITIVE_FUNCS DIBDRV_funcs_DIB4;
116 extern DIBDRV_PRIMITIVE_FUNCS DIBDRV_funcs_DIB1;
118 /* DIB bitmaps formats */
119 typedef enum _DIBFORMAT
121 DIBFMT_UNKNOWN = 0,
122 DIBFMT_DIB1 = 1,
123 DIBFMT_DIB4 = 2,
124 DIBFMT_DIB4_RLE = 3,
125 DIBFMT_DIB8 = 4,
126 DIBFMT_DIB8_RLE = 5,
127 DIBFMT_DIB16_RGB = 6,
128 DIBFMT_DIB16_BITFIELDS = 7,
129 DIBFMT_DIB24 = 8,
130 DIBFMT_DIB32_RGB = 9,
131 DIBFMT_DIB32_BITFIELDS = 10
132 } DIBFORMAT;
134 /* DIB driver's generic bitmap structure */
135 typedef struct _DIBDRVBITMAP
137 /* bitmap format of dib */
138 DIBFORMAT format;
140 /* pointer to top left corner of bitmap */
141 void *bits;
143 /* flags indicating if bits array is owned
144 by the bitmap */
145 BOOL ownsBits;
147 /* bitmap dimensions */
148 int width;
149 int height;
151 /* bitmap stride (== width in bytes) of a bitmap line */
152 /* negative for a bottom-up bitmap */
153 int stride;
155 /* number of bits/pixel in bitmap */
156 int bitCount;
158 /* calculated numbers for bitfields */
160 /* bitfields masks */
161 DWORD redMask, greenMask, blueMask;
162 /* shifting required within a COLORREF's BYTE */
163 int redShift, greenShift, blueShift;
164 /* size of the fields */
165 int redLen, greenLen, blueLen;
167 /* color table and its size */
168 RGBQUAD *colorTable;
169 DWORD colorTableSize;
171 /* flag indicating that color table has been grabbed */
172 BOOL colorTableGrabbed;
174 /* primitive function pointers */
175 DIBDRV_PRIMITIVE_FUNCS *funcs;
177 } DIBDRVBITMAP;
179 /* dash patterns */
180 typedef struct _DASHPATTERN
182 DWORD count;
183 DWORD dashes[6];
185 } DASHPATTERN;
187 /* DIB driver physical device */
188 typedef struct _DIBDRVPHYSDEV
190 /* X11 driver physical device */
191 PHYSDEV X11PhysDev;
193 /* HDC associated with physDev */
194 HDC hdc;
196 /* is a DIB selected into DC ? */
197 BOOL hasDIB;
199 /* currently selected HBITMAP */
200 HBITMAP hbitmap;
202 /* physical bitmap */
203 DIBDRVBITMAP physBitmap;
205 /* active ROP2 */
206 INT rop2;
208 /* clipping region and its rectangles */
209 HRGN region;
210 RGNDATA *regionData;
211 RECT *regionRects;
212 int regionRectCount;
214 /* background color and active ROP2 precalculated
215 AND and XOR values for it */
216 COLORREF backgroundColor;
217 DWORD backgroundAnd, backgroundXor;
219 /* pen color and active ROP2 precalculated
220 AND and XOR values for it */
221 COLORREF penColorref;
222 DWORD penColor;
223 DWORD penAnd, penXor;
224 const DASHPATTERN *penPattern;
225 DWORD curDash, leftInDash;
226 enum MARKSPACE { mark, space } markSpace;
228 /* pen drawing functions */
229 void (* penHLine) (struct _DIBDRVPHYSDEV *physDev, int x1, int x2, int y);
230 void (* penVLine) (struct _DIBDRVPHYSDEV *physDev, int x, int y1, int y2);
231 void (* penLine) (struct _DIBDRVPHYSDEV *physDev, int x1, int y1, int x2, int y2);
232 void (* brushHLine)(struct _DIBDRVPHYSDEV *physDev, int x1, int x2, int y);
234 /* brush color and active ROP2 precalculated
235 AND and XOR values for it */
236 COLORREF brushColorref;
237 DWORD brushColor;
238 DWORD brushAnd, brushXor;
239 DWORD *brushAnds, *brushXors;
241 /* brush style */
242 UINT brushStyle;
244 /* brush bitmap, if needed, and its converted/resized cache copy */
245 BOOL isBrushBitmap;
246 DIBDRVBITMAP brushBitmap;
247 DIBDRVBITMAP brushBmpCache;
249 /* text color */
250 COLORREF textColor;
251 COLORREF textBackground;
253 /* text color table for antialiased fonts */
254 COLORREF textColorTable[256];
256 /* freetype face associated to current DC HFONT */
257 FT_Face face;
259 } DIBDRVPHYSDEV;
262 /* *********************************************************************
263 * DISPLAY DRIVER ACCESS FUNCTIONS
264 * ********************************************************************/
266 /* LoadDisplayDriver
267 * Loads display driver - partially grabbed from gdi32 */
268 DC_FUNCTIONS *_DIBDRV_LoadDisplayDriver(void);
270 /* FreeDisplayDriver
271 Frees resources allocated by Display driver */
272 void _DIBDRV_FreeDisplayDriver(void);
274 /* GetDisplayDriver
275 Gets a pointer to display drives'function table */
276 inline DC_FUNCTIONS *_DIBDRV_GetDisplayDriver(void);
278 /* *********************************************************************
279 * ROP2 AND OTHER DRAWING RELATED FUNCTIONS
280 * ********************************************************************/
282 void _DIBDRV_CalcAndXorMasks(INT rop, DWORD color, DWORD *and, DWORD *xor);
284 inline void _DIBDRV_rop32(DWORD *ptr, DWORD and, DWORD xor);
285 inline void _DIBDRV_rop16(WORD *ptr, WORD and, WORD xor);
286 inline void _DIBDRV_rop8(BYTE *ptr, BYTE and, BYTE xor);
288 void _DIBDRV_ResetDashOrigin(DIBDRVPHYSDEV *physDev);
290 /* *********************************************************************
291 * ROP2 FUNCTIONS
292 * ********************************************************************/
294 /* the ROP3 operations
295 this is a BIG case block; beware that some
296 commons ROP3 operations will be optimized
297 from inside blt routines */
298 DWORD _DIBDRV_ROP3(DWORD p, DWORD s, DWORD d, BYTE rop);
300 /* *********************************************************************
301 * PHYSICAL BITMAP FUNCTIONS
302 * ********************************************************************/
304 /* gets human-readable dib format name */
305 const char *_DIBDRVBITMAP_GetFormatName(DIBDRVBITMAP const *bmp);
307 /* initializes dib from a bitmap :
308 dib dib being initialized
309 bi source BITMAPINFOHEADER with required DIB format info
310 bit_fields color masks
311 color_table color table, if any
312 bits pointer to image data array
313 NOTE : DIBDRVBITMAP doesn't owns bits, but do own color table */
314 BOOL _DIBDRVBITMAP_InitFromBMIH(DIBDRVBITMAP *dib, const BITMAPINFOHEADER *bi, const DWORD *bit_fields,
315 const RGBQUAD *color_table, void *bits);
317 BOOL _DIBDRVBITMAP_InitFromBitmapinfo(DIBDRVBITMAP *dib, BITMAPINFO *bmi);
319 /* initializes a DIBRDVBITMAP copying it from a source one
320 Parameters :
321 dib destination DIBDRVBITMAP
322 src source DIBDRVBITMAP
323 copy TRUE->copy source pixel array FALSE->link to source pixel array */
324 BOOL _DIBDRVBITMAP_InitFromDibdrvbitmap(DIBDRVBITMAP *dib, const DIBDRVBITMAP *src, BOOL copy);
326 /* creates a DIBRDVBITMAP copying format info from a source one
327 Parameters :
328 dib destination DIBDRVBITMAP
329 src source DIBDRVBITMAP
330 widht, height sizes of newly created bitmap */
331 BOOL _DIBDRVBITMAP_CreateFromDibdrvbitmap(DIBDRVBITMAP *dib, const DIBDRVBITMAP *src, int width, int height);
333 /* Clears a DIBDRVBITMAP structure data
334 WARNING : doesn't free anything */
335 void _DIBDRVBITMAP_Clear(DIBDRVBITMAP *bmp);
337 /* Frees a DIBDRVBITMAP structure data */
338 void _DIBDRVBITMAP_Free(DIBDRVBITMAP *bmp);
340 /* checks whether the format of 2 DIBs are identical
341 it checks the pixel bit count and the color table size
342 and content, if needed */
343 BOOL _DIBDRVBITMAP_FormatMatch(const DIBDRVBITMAP *d1, const DIBDRVBITMAP *d2);
345 /* convert a given dib into another format given by 'format' parameter */
346 BOOL _DIBDRVBITMAP_Convert(DIBDRVBITMAP *dst, const DIBDRVBITMAP *src, const DIBDRVBITMAP *format);
348 /* creates a solid-filled DIB of given color and format
349 DIB format is given by 'format' parameter */
350 BOOL _DIBDRVBITMAP_CreateSolid(DIBDRVBITMAP *bmp, DIBDRVBITMAP *format, int width, int height, DWORD Color);
352 /* expands horizontally a bitmap to reach a minimum size,
353 keeping its width as a multiple of a base width
354 Used to widen brushes in order to optimize blitting */
355 BOOL _DIBDRVBITMAP_ExpandHoriz(DIBDRVBITMAP *dib, int baseWidth, int minWidth);
357 /* *********************************************************************
358 * DIB <--> DDB CONVERSION ROUTINES
359 * ********************************************************************/
361 /***********************************************************************
362 * Creates DDB that is compatible with source hdc.
363 * hdc is the HDC on where the DIB MUST be selected in
364 * srcBmp is the source DIB
365 * startScan and scanLines specify the portion of DIB to convert
366 * in order to avoid unneeded conversion of large DIBs on blitting
368 * NOTE : the srcBmp DIB MUST NOT be selected in any DC */
369 HBITMAP _DIBDRV_ConvertDIBtoDDB( HDC hdc, HBITMAP srcBmp, int startScan, int scanLines );
371 /***********************************************************************
372 * Creates DIB that is compatible with the target hdc.
373 * startScan and scanLines specify the portion of DDB to convert
374 * in order to avoid unneeded conversion of large DDBs on blitting
376 * NOTE : the srcBmp DDB MUST NOT be selected in any DC */
377 HBITMAP _DIBDRV_ConvertDDBtoDIB( HDC hdc, HBITMAP srcBmp, int startScan, int scanLines );
379 /***********************************************************************
380 * Creates DIB that is compatible with the target hdc for a device (non memory) source DC */
381 HBITMAP _DIBDRV_ConvertDevDDBtoDIB( HDC hdcSrc, HDC hdcDst, int xSrc, int ySrc, int width, int height );
383 /* *********************************************************************
384 * QUERY FUNCTIONS
385 * ********************************************************************/
387 /***********************************************************************
388 * DIBDRV_GetDeviceCaps */
389 INT DIBDRV_GetDeviceCaps( DIBDRVPHYSDEV *physDev, INT cap );
391 #endif