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"
39 /* data structures needed to access opaque pointers
40 * defined in gdi32.h */
41 #include "dibdrv_gdi32.h"
43 /* enable this if you want debugging (i.e. TRACEs) output */
44 #define DIBDRV_ENABLE_MAYBE
46 /* enable this if you want antialiased fonts */
47 #define DIBDRV_ANTIALIASED_FONTS
49 /* provide a way to make debugging output appear
50 only once. Usage example:
51 ONCE(FIXME("Some message\n")); */
54 static BOOL done = FALSE; \
62 /* provide a way to make debugging output appear
63 only if enabled here. Can speed up stuffs
64 avoiding long traces.Usage example:
65 MAYBE(TRACE("Some message\n")); */
66 #ifdef DIBDRV_ENABLE_MAYBE
73 /* extra stock object: default 1x1 bitmap for memory DCs
74 grabbed from gdi_private.h */
75 #define DEFAULT_BITMAP (STOCK_LAST+1)
78 struct _DIBDRVPHYSDEV
;
79 typedef struct _DIBDRV_PRIMITIVE_FUNCS
81 /* color to pixel data conversion */
82 DWORD (* ColorToPixel
) (const struct _DIBDRVBITMAP
*bmp
, COLORREF color
);
84 /* pixel primitives */
85 void* (* GetPixelPointer
) (const struct _DIBDRVBITMAP
*bmp
, int x
, int y
);
86 void (* SetPixel
) ( struct _DIBDRVBITMAP
*bmp
, int x
, int y
, DWORD
and, DWORD
xor);
87 DWORD (* GetPixel
) (const struct _DIBDRVBITMAP
*bmp
, int x
, int y
);
89 /* line drawing primitives */
90 void (* SolidHLine
) ( struct _DIBDRVBITMAP
*bmp
, int x1
, int x2
, int y
, DWORD
and, DWORD
xor);
91 void (* PatternHLine
) ( struct _DIBDRVBITMAP
*bmp
, int x1
, int x2
, int y
, const void *and, const void *xor, DWORD offset
, DWORD count
);
92 void (* SolidVLine
) ( struct _DIBDRVBITMAP
*bmp
, int x
, int y1
, int y2
, DWORD
and, DWORD
xor);
94 /* bitmap conversion helpers */
95 BOOL (* GetLine
) (const struct _DIBDRVBITMAP
*bmp
, int line
, int startx
, int width
, void *buf
);
96 BOOL (* PutLine
) ( struct _DIBDRVBITMAP
*bmp
, int line
, int startx
, int width
, void *buf
);
98 /* BitBlt primitives */
99 BOOL (* AlphaBlend
) ( struct _DIBDRVPHYSDEV
*physDevDst
, int xDst
, int yDst
, int widthDst
, int heightDst
,
100 const struct _DIBDRVPHYSDEV
*physDevSrc
, int xSrc
, int ySrc
, int widthSrc
, int heightSrc
, BLENDFUNCTION blendFn
);
101 BOOL (* BitBlt
) ( struct _DIBDRVPHYSDEV
*physDevDst
, int xDst
, int yDst
, int width
, int height
,
102 const struct _DIBDRVPHYSDEV
*physDevSrc
, int xSrc
, int ySrc
, DWORD rop
);
103 BOOL (* StretchBlt
) ( struct _DIBDRVPHYSDEV
*physDevDst
, int xDst
, int yDst
, int widthDst
, int heightDst
,
104 const struct _DIBDRVPHYSDEV
*physDevSrc
, int xSrc
, int ySrc
, int widthSrc
, int heightSrc
, DWORD rop
);
106 /* font drawing helper */
107 void (* FreetypeBlit
) ( struct _DIBDRVPHYSDEV
*physDev
, int x
, int y
, RECT
*clipRec
, FT_Bitmap
*bmp
);
109 } DIBDRV_PRIMITIVE_FUNCS
;
111 extern DIBDRV_PRIMITIVE_FUNCS DIBDRV_funcs_DIB32_RGB
;
112 extern DIBDRV_PRIMITIVE_FUNCS DIBDRV_funcs_DIB32_BITFIELDS
;
113 extern DIBDRV_PRIMITIVE_FUNCS DIBDRV_funcs_DIB24
;
114 extern DIBDRV_PRIMITIVE_FUNCS DIBDRV_funcs_DIB16_RGB
;
115 extern DIBDRV_PRIMITIVE_FUNCS DIBDRV_funcs_DIB16_BITFIELDS
;
116 extern DIBDRV_PRIMITIVE_FUNCS DIBDRV_funcs_DIB8
;
117 extern DIBDRV_PRIMITIVE_FUNCS DIBDRV_funcs_DIB4
;
118 extern DIBDRV_PRIMITIVE_FUNCS DIBDRV_funcs_DIB1
;
120 /* DIB bitmaps formats */
121 typedef enum _DIBFORMAT
129 DIBFMT_DIB16_RGB
= 6,
130 DIBFMT_DIB16_BITFIELDS
= 7,
132 DIBFMT_DIB32_RGB
= 9,
133 DIBFMT_DIB32_BITFIELDS
= 10
136 /* DIB driver's generic bitmap structure */
137 typedef struct _DIBDRVBITMAP
139 /* bitmap format of dib */
145 /* pointer to top left corner of bitmap */
148 /* flags indicating if bits array is owned
152 /* bitmap dimensions */
156 /* bitmap stride (== width in bytes) of a bitmap line */
157 /* negative for a bottom-up bitmap */
160 /* number of bits/pixel in bitmap */
163 /* calculated numbers for bitfields */
165 /* bitfields masks */
166 DWORD redMask
, greenMask
, blueMask
;
167 /* shifting required within a COLORREF's BYTE */
168 int redShift
, greenShift
, blueShift
;
169 /* size of the fields */
170 int redLen
, greenLen
, blueLen
;
172 /* color table and its size */
174 DWORD colorTableSize
;
176 /* lightest color index, for monochrome bitmaps */
179 /* flag indicating that color table has been grabbed */
180 BOOL colorTableGrabbed
;
182 /* primitive function pointers */
183 DIBDRV_PRIMITIVE_FUNCS
*funcs
;
188 typedef struct _DASHPATTERN
195 /* DIB driver physical device */
196 typedef struct _DIBDRVPHYSDEV
198 /* X11 driver physical device */
201 /* HDC associated with physDev */
204 /* is a DIB selected into DC ? */
207 /* currently selected HBITMAP */
210 /* physical bitmap */
211 DIBDRVBITMAP
*physBitmap
;
216 /* clipping region and its rectangles */
222 /* background color and active ROP2 precalculated
223 AND and XOR values for it */
224 COLORREF backgroundColor
;
225 DWORD backgroundAnd
, backgroundXor
;
227 /* pen color and active ROP2 precalculated
228 AND and XOR values for it */
229 COLORREF penColorref
;
231 DWORD penAnd
, penXor
;
232 const DASHPATTERN
*penPattern
;
233 DWORD curDash
, leftInDash
;
234 enum MARKSPACE
{ mark
, space
} markSpace
;
239 /* pen drawing functions */
240 void (* penHLine
) (struct _DIBDRVPHYSDEV
*physDev
, int x1
, int x2
, int y
);
241 void (* penVLine
) (struct _DIBDRVPHYSDEV
*physDev
, int x
, int y1
, int y2
);
242 void (* penLine
) (struct _DIBDRVPHYSDEV
*physDev
, int x1
, int y1
, int x2
, int y2
);
243 void (* brushHLine
)(struct _DIBDRVPHYSDEV
*physDev
, int x1
, int x2
, int y
);
245 /* brush color and active ROP2 precalculated
246 AND and XOR values for it */
247 COLORREF brushColorref
;
249 DWORD brushAnd
, brushXor
;
250 DWORD
*brushAnds
, *brushXors
;
255 /* brush bitmap, if needed, and its converted/resized cache copy */
257 DIBDRVBITMAP
*brushBitmap
;
258 DIBDRVBITMAP
*brushBmpCache
;
262 COLORREF textBackground
;
264 #ifdef DIBDRV_ANTIALIASED_FONTS
265 /* text color table for antialiased fonts */
266 COLORREF textColorTable
[256];
269 /* freetype face associated to current DC HFONT */
275 /* *********************************************************************
276 * DISPLAY DRIVER ACCESS FUNCTIONS
277 * ********************************************************************/
280 * Loads display driver - partially grabbed from gdi32 */
281 DC_FUNCTIONS
*_DIBDRV_LoadDisplayDriver(void);
284 Frees resources allocated by Display driver */
285 void _DIBDRV_FreeDisplayDriver(void);
288 Gets a pointer to display drives'function table */
289 inline DC_FUNCTIONS
*_DIBDRV_GetDisplayDriver(void);
291 /* *********************************************************************
292 * ROP2 AND OTHER DRAWING RELATED FUNCTIONS
293 * ********************************************************************/
295 void _DIBDRV_CalcAndXorMasks(INT rop
, DWORD color
, DWORD
*and, DWORD
*xor);
297 inline void _DIBDRV_rop32(DWORD
*ptr
, DWORD
and, DWORD
xor);
298 inline void _DIBDRV_rop16(WORD
*ptr
, WORD
and, WORD
xor);
299 inline void _DIBDRV_rop8(BYTE
*ptr
, BYTE
and, BYTE
xor);
301 void _DIBDRV_ResetDashOrigin(DIBDRVPHYSDEV
*physDev
);
303 /* *********************************************************************
305 * ********************************************************************/
307 /* the ROP3 operations
308 this is a BIG case block; beware that some
309 commons ROP3 operations will be optimized
310 from inside blt routines */
311 DWORD
_DIBDRV_ROP3(DWORD p
, DWORD s
, DWORD d
, BYTE rop
);
313 /* *********************************************************************
314 * PHYSICAL BITMAP FUNCTIONS
315 * ********************************************************************/
317 /* gets human-readable dib format name */
318 const char *_DIBDRVBITMAP_GetFormatName(DIBDRVBITMAP
const *bmp
);
320 /* sets/gets bits of a DIBDRVBITMAP taking in account if it's a top down
321 or a bottom-up DIB */
322 void _DIBDRVBITMAP_Set_Bits(DIBDRVBITMAP
*dib
, void *bits
, BOOL owns
);
323 void *_DIBDRVBITMAP_Get_Bits(DIBDRVBITMAP
*dib
);
325 /* calculates and sets the lightest color for monochrome bitmaps */
326 int _DIBDRVBITMAP_GetLightestColorIndex(DIBDRVBITMAP
*dib
);
328 /* initialize or create dib from a bitmap :
329 dib dib being initialized
330 bi source BITMAPINFOHEADER with required DIB format info
331 bit_fields color masks
332 color_table color table, if any
333 bits pointer to image data array
334 NOTE : DIBDRVBITMAP doesn't owns bits, but do own color table */
335 BOOL
_DIBDRVBITMAP_InitFromBMIH(DIBDRVBITMAP
*dib
, const BITMAPINFOHEADER
*bi
, const DWORD
*bit_fields
,
336 const RGBQUAD
*color_table
, void *bits
);
337 DIBDRVBITMAP
*_DIBDRVBITMAP_CreateFromBMIH(const BITMAPINFOHEADER
*bi
, const DWORD
*bit_fields
,
338 const RGBQUAD
*colorTable
, void *bits
);
340 BOOL
_DIBDRVBITMAP_InitFromBitmapinfo(DIBDRVBITMAP
*dib
, const BITMAPINFO
*bmi
, void *bits
);
341 DIBDRVBITMAP
*_DIBDRVBITMAP_CreateFromBitmapinfo(const BITMAPINFO
*bmi
, void *bits
);
343 /* initializes a DIBRDVBITMAP copying it from a source one
345 dib destination DIBDRVBITMAP
346 src source DIBDRVBITMAP
347 copy TRUE->copy source pixel array FALSE->link to source pixel array */
348 BOOL
_DIBDRVBITMAP_InitFromDibdrvbitmap(DIBDRVBITMAP
*dib
, const DIBDRVBITMAP
*src
, BOOL copy
);
350 /* creates a DIBRDVBITMAP copying format info from a source one
352 dib destination DIBDRVBITMAP
353 src source DIBDRVBITMAP
354 widht, height sizes of newly created bitmap */
355 BOOL
_DIBDRVBITMAP_CreateFromDibdrvbitmap(DIBDRVBITMAP
*dib
, const DIBDRVBITMAP
*src
, int width
, int height
);
357 /* allocates a new DIBDTVBITMAP */
358 DIBDRVBITMAP
*_DIBDRVBITMAP_New(void);
360 /* Frees and de-allocates a DIBDRVBITMAP structure data */
361 void _DIBDRVBITMAP_Free(DIBDRVBITMAP
*bmp
);
363 /* Clears a DIBDRVBITMAP structure data
364 WARNING : doesn't free anything */
365 void _DIBDRVBITMAP_Clear(DIBDRVBITMAP
*bmp
);
367 /* checks whether the format of 2 DIBs are identical
368 it checks the pixel bit count and the color table size
369 and content, if needed */
370 BOOL
_DIBDRVBITMAP_FormatMatch(const DIBDRVBITMAP
*d1
, const DIBDRVBITMAP
*d2
);
372 /* convert a given dib into another format given by 'format' parameter */
373 BOOL
_DIBDRVBITMAP_Convert(DIBDRVBITMAP
*dst
, const DIBDRVBITMAP
*src
, const DIBDRVBITMAP
*format
);
375 /* creates a solid-filled DIB of given color and format
376 DIB format is given by 'format' parameter */
377 BOOL
_DIBDRVBITMAP_CreateSolid(DIBDRVBITMAP
*bmp
, DIBDRVBITMAP
*format
, int width
, int height
, DWORD Color
);
379 /* expands horizontally a bitmap to reach a minimum size,
380 keeping its width as a multiple of a base width
381 Used to widen brushes in order to optimize blitting */
382 BOOL
_DIBDRVBITMAP_ExpandHoriz(DIBDRVBITMAP
*dib
, int baseWidth
, int minWidth
);
384 /* *********************************************************************
385 * BITMAP LIST MANAGEMENT FUNCTIONS
386 * ********************************************************************/
388 /* initializes bitmap list -- to be called at process attach */
389 void _BITMAPLIST_Init(void);
391 /* terminates bitmap list -- to be called at process detach */
392 void _BITMAPLIST_Terminate(void);
394 /* adds a DIB to the list - it adds it on top, as
395 usually most recently created DIBs are used first */
396 BOOL
_BITMAPLIST_Add(HBITMAP hbmp
, DIBDRVBITMAP
*bmp
);
398 /* removes a DIB from the list */
399 DIBDRVBITMAP
*_BITMAPLIST_Remove(HBITMAP hbmp
);
401 /* scans list for a DIB */
402 DIBDRVBITMAP
*_BITMAPLIST_Get(HBITMAP hbmp
);
404 /* *********************************************************************
405 * DIB <--> DDB CONVERSION ROUTINES
406 * ********************************************************************/
408 /***********************************************************************
409 * Creates DDB that is compatible with source hdc.
410 * hdc is the HDC on where the DIB MUST be selected in
411 * srcBmp is the source DIB
412 * startScan and scanLines specify the portion of DIB to convert
413 * in order to avoid unneeded conversion of large DIBs on blitting
415 * NOTE : the srcBmp DIB MUST NOT be selected in any DC */
416 HBITMAP
_DIBDRV_ConvertDIBtoDDB( HDC hdc
, HBITMAP srcBmp
, int startScan
, int scanLines
);
418 /***********************************************************************
419 * Creates DIB that is compatible with the target hdc.
420 * startScan and scanLines specify the portion of DDB to convert
421 * in order to avoid unneeded conversion of large DDBs on blitting
423 * NOTE : the srcBmp DDB MUST NOT be selected in any DC */
424 HBITMAP
_DIBDRV_ConvertDDBtoDIB( HDC hdc
, HBITMAP srcBmp
, int startScan
, int scanLines
);
426 /***********************************************************************
427 * Creates DIB that is compatible with the target hdc for a device (non memory) source DC */
428 HBITMAP
_DIBDRV_ConvertDevDDBtoDIB( HDC hdcSrc
, HDC hdcDst
, int xSrc
, int ySrc
, int width
, int height
);
430 /* *********************************************************************
432 * ********************************************************************/
434 /***********************************************************************
435 * DIBDRV_GetDeviceCaps */
436 INT
DIBDRV_GetDeviceCaps( DIBDRVPHYSDEV
*physDev
, INT cap
);
438 /* *********************************************************************
439 * GEOMETRIC UTILITIES
440 * ********************************************************************/
442 /* intersect 2 rectangles (just to not use USER32 one...) */
443 BOOL
_DIBDRV_IntersectRect(RECT
*d
, const RECT
*s1
, const RECT
*s2
);
445 /* converts positions from Word space to Device space */
446 void _DIBDRV_Position_ws2ds(DIBDRVPHYSDEV
*physDev
, int *x
, int *y
);
447 void _DIBDRV_Positions_ws2ds(DIBDRVPHYSDEV
*physDev
, int *x1
, int *y1
, int *x2
, int *y2
);
449 /* converts sizes from Word space to Device space */
450 void _DIBDRV_Sizes_ws2ds(DIBDRVPHYSDEV
*physDev
, int *w
, int *h
);
452 /* converts a rectangle form Word space to Device space */
453 void _DIBDRV_Rect_ws2ds(DIBDRVPHYSDEV
*physDev
, const RECT
*src
, RECT
*dst
);
455 /* converts positions from Device space to World space */
456 void _DIBDRV_Position_ds2ws(DIBDRVPHYSDEV
*physDev
, int *x
, int *y
);
457 void _DIBDRV_Positions_ds2ws(DIBDRVPHYSDEV
*physDev
, int *x1
, int *y1
, int *x2
, int *y2
);
459 /* converts sizes from Device space to World space */
460 void _DIBDRV_Sizes_ds2ws(DIBDRVPHYSDEV
*physDev
, int *w
, int *h
);
462 /* *********************************************************************
464 * ********************************************************************/
466 /* maps a colorref to actual color */
467 COLORREF
_DIBDRV_MapColor(DIBDRVPHYSDEV
*physDev
, COLORREF color
);
469 /* gets nearest color index in DIB palette of a given colorref */
470 DWORD
_DIBDRV_GetNearestColorIndex(const DIBDRVBITMAP
*dib
, COLORREF color
);
472 /* gets nearest color to DIB palette color */
473 DWORD
_DIBDRV_GetNearestColor(const DIBDRVBITMAP
*dib
, COLORREF color
);