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
31 #include "wine/list.h"
32 #include "wine/library.h"
33 #include "wine/debug.h"
36 #include "wine/winbase16.h" /* GlobalLock16 */
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")); */
55 static BOOL done = FALSE; \
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
74 /* extra stock object: default 1x1 bitmap for memory DCs
75 grabbed from gdi_private.h */
76 #define DEFAULT_BITMAP (STOCK_LAST+1)
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
130 DIBFMT_DIB16_RGB
= 6,
131 DIBFMT_DIB16_BITFIELDS
= 7,
133 DIBFMT_DIB32_RGB
= 9,
134 DIBFMT_DIB32_BITFIELDS
= 10
137 /* DIB driver's generic bitmap structure */
138 typedef struct _DIBDRVBITMAP
140 /* bitmap format of dib */
143 /* pointer to top left corner of bitmap */
146 /* flags indicating if bits array is owned
150 /* bitmap dimensions */
154 /* bitmap stride (== width in bytes) of a bitmap line */
155 /* negative for a bottom-up bitmap */
158 /* number of bits/pixel in bitmap */
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 */
172 DWORD colorTableSize
;
174 /* flag indicating that color table has been grabbed */
175 BOOL colorTableGrabbed
;
177 /* primitive function pointers */
178 DIBDRV_PRIMITIVE_FUNCS
*funcs
;
183 typedef struct _DASHPATTERN
190 /* DIB driver physical device */
191 typedef struct _DIBDRVPHYSDEV
193 /* X11 driver physical device */
196 /* HDC associated with physDev */
199 /* is a DIB selected into DC ? */
202 /* currently selected HBITMAP */
205 /* physical bitmap */
206 DIBDRVBITMAP physBitmap
;
211 /* clipping region and its rectangles */
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
;
226 DWORD penAnd
, penXor
;
227 const DASHPATTERN
*penPattern
;
228 DWORD curDash
, leftInDash
;
229 enum MARKSPACE
{ mark
, space
} markSpace
;
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
;
244 DWORD brushAnd
, brushXor
;
245 DWORD
*brushAnds
, *brushXors
;
250 /* brush bitmap, if needed, and its converted/resized cache copy */
252 DIBDRVBITMAP brushBitmap
;
253 DIBDRVBITMAP brushBmpCache
;
257 COLORREF textBackground
;
259 #ifdef DIBDRV_ANTIALIASED_FONTS
260 /* text color table for antialiased fonts */
261 COLORREF textColorTable
[256];
264 /* freetype face associated to current DC HFONT */
270 /* *********************************************************************
271 * DISPLAY DRIVER ACCESS FUNCTIONS
272 * ********************************************************************/
275 * Loads display driver - partially grabbed from gdi32 */
276 DC_FUNCTIONS
*_DIBDRV_LoadDisplayDriver(void);
279 Frees resources allocated by Display driver */
280 void _DIBDRV_FreeDisplayDriver(void);
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 /* *********************************************************************
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 /* sets/gets bits of a DIBDRVBITMAP taking in account if it's a top down
316 or a bottom-up DIB */
317 void _DIBDRVBITMAP_Set_Bits(DIBDRVBITMAP
*dib
, void *bits
, BOOL owns
);
318 void *_DIBDRVBITMAP_Get_Bits(DIBDRVBITMAP
*dib
);
320 /* initializes dib from a bitmap :
321 dib dib being initialized
322 bi source BITMAPINFOHEADER with required DIB format info
323 bit_fields color masks
324 color_table color table, if any
325 bits pointer to image data array
326 NOTE : DIBDRVBITMAP doesn't owns bits, but do own color table */
327 BOOL
_DIBDRVBITMAP_InitFromBMIH(DIBDRVBITMAP
*dib
, const BITMAPINFOHEADER
*bi
, const DWORD
*bit_fields
,
328 const RGBQUAD
*color_table
, void *bits
);
330 BOOL
_DIBDRVBITMAP_InitFromBitmapinfo(DIBDRVBITMAP
*dib
, const BITMAPINFO
*bmi
);
332 /* initializes a DIBRDVBITMAP copying it from a source one
334 dib destination DIBDRVBITMAP
335 src source DIBDRVBITMAP
336 copy TRUE->copy source pixel array FALSE->link to source pixel array */
337 BOOL
_DIBDRVBITMAP_InitFromDibdrvbitmap(DIBDRVBITMAP
*dib
, const DIBDRVBITMAP
*src
, BOOL copy
);
339 /* initializes a DIBRDVBITMAP from a DIB HBITMAP
341 bmp destination DIBDRVBITMAP
343 copyPixels TRUE->copy source pixel array FALSE->link to source pixel array */
344 BOOL
_DIBDRVBITMAP_InitFromHBITMAP(DIBDRVBITMAP
*bmp
, const HBITMAP hbmp
, BOOL copyPixels
);
346 /* creates a DIBRDVBITMAP copying format info from a source one
348 dib destination DIBDRVBITMAP
349 src source DIBDRVBITMAP
350 widht, height sizes of newly created bitmap */
351 BOOL
_DIBDRVBITMAP_CreateFromDibdrvbitmap(DIBDRVBITMAP
*dib
, const DIBDRVBITMAP
*src
, int width
, int height
);
353 /* Clears a DIBDRVBITMAP structure data
354 WARNING : doesn't free anything */
355 void _DIBDRVBITMAP_Clear(DIBDRVBITMAP
*bmp
);
357 /* Frees a DIBDRVBITMAP structure data */
358 void _DIBDRVBITMAP_Free(DIBDRVBITMAP
*bmp
);
360 /* checks whether the format of 2 DIBs are identical
361 it checks the pixel bit count and the color table size
362 and content, if needed */
363 BOOL
_DIBDRVBITMAP_FormatMatch(const DIBDRVBITMAP
*d1
, const DIBDRVBITMAP
*d2
);
365 /* convert a given dib into another format given by 'format' parameter */
366 BOOL
_DIBDRVBITMAP_Convert(DIBDRVBITMAP
*dst
, const DIBDRVBITMAP
*src
, const DIBDRVBITMAP
*format
);
368 /* creates a solid-filled DIB of given color and format
369 DIB format is given by 'format' parameter */
370 BOOL
_DIBDRVBITMAP_CreateSolid(DIBDRVBITMAP
*bmp
, DIBDRVBITMAP
*format
, int width
, int height
, DWORD Color
);
372 /* expands horizontally a bitmap to reach a minimum size,
373 keeping its width as a multiple of a base width
374 Used to widen brushes in order to optimize blitting */
375 BOOL
_DIBDRVBITMAP_ExpandHoriz(DIBDRVBITMAP
*dib
, int baseWidth
, int minWidth
);
377 /* *********************************************************************
378 * DIB <--> DDB CONVERSION ROUTINES
379 * ********************************************************************/
381 /***********************************************************************
382 * Creates DDB that is compatible with source hdc.
383 * hdc is the HDC on where the DIB MUST be selected in
384 * srcBmp is the source DIB
385 * startScan and scanLines specify the portion of DIB to convert
386 * in order to avoid unneeded conversion of large DIBs on blitting
388 * NOTE : the srcBmp DIB MUST NOT be selected in any DC */
389 HBITMAP
_DIBDRV_ConvertDIBtoDDB( HDC hdc
, HBITMAP srcBmp
, int startScan
, int scanLines
);
391 /***********************************************************************
392 * Creates DIB that is compatible with the target hdc.
393 * startScan and scanLines specify the portion of DDB to convert
394 * in order to avoid unneeded conversion of large DDBs on blitting
396 * NOTE : the srcBmp DDB MUST NOT be selected in any DC */
397 HBITMAP
_DIBDRV_ConvertDDBtoDIB( HDC hdc
, HBITMAP srcBmp
, int startScan
, int scanLines
);
399 /***********************************************************************
400 * Creates DIB that is compatible with the target hdc for a device (non memory) source DC */
401 HBITMAP
_DIBDRV_ConvertDevDDBtoDIB( HDC hdcSrc
, HDC hdcDst
, int xSrc
, int ySrc
, int width
, int height
);
403 /* *********************************************************************
405 * ********************************************************************/
407 /***********************************************************************
408 * DIBDRV_GetDeviceCaps */
409 INT
DIBDRV_GetDeviceCaps( DIBDRVPHYSDEV
*physDev
, INT cap
);
411 /* *********************************************************************
412 * GEOMETRIC UTILITIES
413 * ********************************************************************/
415 /* intersect 2 rectangles (just to not use USER32 one...) */
416 BOOL
_DIBDRV_IntersectRect(RECT
*d
, const RECT
*s1
, const RECT
*s2
);
418 /* converts positions from Word space to Device space */
419 void _DIBDRV_Position_ws2ds(DIBDRVPHYSDEV
*physDev
, int *x
, int *y
);
420 void _DIBDRV_Positions_ws2ds(DIBDRVPHYSDEV
*physDev
, int *x1
, int *y1
, int *x2
, int *y2
);
422 /* converts sizes from Word space to Device space */
423 void _DIBDRV_Sizes_ws2ds(DIBDRVPHYSDEV
*physDev
, int *w
, int *h
);
425 /* converts a rectangle form Word space to Device space */
426 void _DIBDRV_Rect_ws2ds(DIBDRVPHYSDEV
*physDev
, const RECT
*src
, RECT
*dst
);
428 /* *********************************************************************
430 * ********************************************************************/
432 /* maps a colorref to actual color */
433 COLORREF
_DIBDRV_MapColor(DIBDRVPHYSDEV
*physDev
, COLORREF color
);
435 /* gets nearest color index in DIB palette of a given colorref */
436 DWORD
_DIBDRV_GetNearestColorIndex(const DIBDRVBITMAP
*dib
, COLORREF color
);
438 /* gets nearest color to DIB palette color */
439 DWORD
_DIBDRV_GetNearestColor(const DIBDRVBITMAP
*dib
, COLORREF color
);