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 /* lightest color index, for monochrome bitmaps */
177 /* flag indicating that color table has been grabbed */
178 BOOL colorTableGrabbed
;
180 /* primitive function pointers */
181 DIBDRV_PRIMITIVE_FUNCS
*funcs
;
186 typedef struct _DASHPATTERN
193 /* DIB driver physical device */
194 typedef struct _DIBDRVPHYSDEV
196 /* X11 driver physical device */
199 /* HDC associated with physDev */
202 /* is a DIB selected into DC ? */
205 /* currently selected HBITMAP */
208 /* physical bitmap */
209 DIBDRVBITMAP
*physBitmap
;
214 /* clipping region and its rectangles */
220 /* background color and active ROP2 precalculated
221 AND and XOR values for it */
222 COLORREF backgroundColor
;
223 DWORD backgroundAnd
, backgroundXor
;
225 /* pen color and active ROP2 precalculated
226 AND and XOR values for it */
227 COLORREF penColorref
;
229 DWORD penAnd
, penXor
;
230 const DASHPATTERN
*penPattern
;
231 DWORD curDash
, leftInDash
;
232 enum MARKSPACE
{ mark
, space
} markSpace
;
237 /* pen drawing functions */
238 void (* penHLine
) (struct _DIBDRVPHYSDEV
*physDev
, int x1
, int x2
, int y
);
239 void (* penVLine
) (struct _DIBDRVPHYSDEV
*physDev
, int x
, int y1
, int y2
);
240 void (* penLine
) (struct _DIBDRVPHYSDEV
*physDev
, int x1
, int y1
, int x2
, int y2
);
241 void (* brushHLine
)(struct _DIBDRVPHYSDEV
*physDev
, int x1
, int x2
, int y
);
243 /* brush color and active ROP2 precalculated
244 AND and XOR values for it */
245 COLORREF brushColorref
;
247 DWORD brushAnd
, brushXor
;
248 DWORD
*brushAnds
, *brushXors
;
253 /* brush bitmap, if needed, and its converted/resized cache copy */
255 DIBDRVBITMAP
*brushBitmap
;
256 DIBDRVBITMAP
*brushBmpCache
;
260 COLORREF textBackground
;
262 #ifdef DIBDRV_ANTIALIASED_FONTS
263 /* text color table for antialiased fonts */
264 COLORREF textColorTable
[256];
267 /* freetype face associated to current DC HFONT */
273 /* *********************************************************************
274 * DISPLAY DRIVER ACCESS FUNCTIONS
275 * ********************************************************************/
278 * Loads display driver - partially grabbed from gdi32 */
279 DC_FUNCTIONS
*_DIBDRV_LoadDisplayDriver(void);
282 Frees resources allocated by Display driver */
283 void _DIBDRV_FreeDisplayDriver(void);
286 Gets a pointer to display drives'function table */
287 inline DC_FUNCTIONS
*_DIBDRV_GetDisplayDriver(void);
289 /* *********************************************************************
290 * ROP2 AND OTHER DRAWING RELATED FUNCTIONS
291 * ********************************************************************/
293 void _DIBDRV_CalcAndXorMasks(INT rop
, DWORD color
, DWORD
*and, DWORD
*xor);
295 inline void _DIBDRV_rop32(DWORD
*ptr
, DWORD
and, DWORD
xor);
296 inline void _DIBDRV_rop16(WORD
*ptr
, WORD
and, WORD
xor);
297 inline void _DIBDRV_rop8(BYTE
*ptr
, BYTE
and, BYTE
xor);
299 void _DIBDRV_ResetDashOrigin(DIBDRVPHYSDEV
*physDev
);
301 /* *********************************************************************
303 * ********************************************************************/
305 /* the ROP3 operations
306 this is a BIG case block; beware that some
307 commons ROP3 operations will be optimized
308 from inside blt routines */
309 DWORD
_DIBDRV_ROP3(DWORD p
, DWORD s
, DWORD d
, BYTE rop
);
311 /* *********************************************************************
312 * PHYSICAL BITMAP FUNCTIONS
313 * ********************************************************************/
315 /* gets human-readable dib format name */
316 const char *_DIBDRVBITMAP_GetFormatName(DIBDRVBITMAP
const *bmp
);
318 /* sets/gets bits of a DIBDRVBITMAP taking in account if it's a top down
319 or a bottom-up DIB */
320 void _DIBDRVBITMAP_Set_Bits(DIBDRVBITMAP
*dib
, void *bits
, BOOL owns
);
321 void *_DIBDRVBITMAP_Get_Bits(DIBDRVBITMAP
*dib
);
323 /* calculates and sets the lightest color for monochrome bitmaps */
324 int _DIBDRVBITMAP_GetLightestColorIndex(DIBDRVBITMAP
*dib
);
326 /* initialize or create dib from a bitmap :
327 dib dib being initialized
328 bi source BITMAPINFOHEADER with required DIB format info
329 bit_fields color masks
330 color_table color table, if any
331 bits pointer to image data array
332 NOTE : DIBDRVBITMAP doesn't owns bits, but do own color table */
333 BOOL
_DIBDRVBITMAP_InitFromBMIH(DIBDRVBITMAP
*dib
, const BITMAPINFOHEADER
*bi
, const DWORD
*bit_fields
,
334 const RGBQUAD
*color_table
, void *bits
);
335 DIBDRVBITMAP
*_DIBDRVBITMAP_CreateFromBMIH(const BITMAPINFOHEADER
*bi
, const DWORD
*bit_fields
,
336 const RGBQUAD
*colorTable
, void *bits
);
338 BOOL
_DIBDRVBITMAP_InitFromBitmapinfo(DIBDRVBITMAP
*dib
, const BITMAPINFO
*bmi
, void *bits
);
339 DIBDRVBITMAP
*_DIBDRVBITMAP_CreateFromBitmapinfo(const BITMAPINFO
*bmi
, void *bits
);
341 /* initializes a DIBRDVBITMAP copying it from a source one
343 dib destination DIBDRVBITMAP
344 src source DIBDRVBITMAP
345 copy TRUE->copy source pixel array FALSE->link to source pixel array */
346 BOOL
_DIBDRVBITMAP_InitFromDibdrvbitmap(DIBDRVBITMAP
*dib
, const DIBDRVBITMAP
*src
, BOOL copy
);
348 /* creates a DIBRDVBITMAP copying format info from a source one
350 dib destination DIBDRVBITMAP
351 src source DIBDRVBITMAP
352 widht, height sizes of newly created bitmap */
353 BOOL
_DIBDRVBITMAP_CreateFromDibdrvbitmap(DIBDRVBITMAP
*dib
, const DIBDRVBITMAP
*src
, int width
, int height
);
355 /* allocates a new DIBDTVBITMAP */
356 DIBDRVBITMAP
*_DIBDRVBITMAP_New(void);
358 /* Frees and de-allocates a DIBDRVBITMAP structure data */
359 void _DIBDRVBITMAP_Free(DIBDRVBITMAP
*bmp
);
361 /* Clears a DIBDRVBITMAP structure data
362 WARNING : doesn't free anything */
363 void _DIBDRVBITMAP_Clear(DIBDRVBITMAP
*bmp
);
365 /* checks whether the format of 2 DIBs are identical
366 it checks the pixel bit count and the color table size
367 and content, if needed */
368 BOOL
_DIBDRVBITMAP_FormatMatch(const DIBDRVBITMAP
*d1
, const DIBDRVBITMAP
*d2
);
370 /* convert a given dib into another format given by 'format' parameter */
371 BOOL
_DIBDRVBITMAP_Convert(DIBDRVBITMAP
*dst
, const DIBDRVBITMAP
*src
, const DIBDRVBITMAP
*format
);
373 /* creates a solid-filled DIB of given color and format
374 DIB format is given by 'format' parameter */
375 BOOL
_DIBDRVBITMAP_CreateSolid(DIBDRVBITMAP
*bmp
, DIBDRVBITMAP
*format
, int width
, int height
, DWORD Color
);
377 /* expands horizontally a bitmap to reach a minimum size,
378 keeping its width as a multiple of a base width
379 Used to widen brushes in order to optimize blitting */
380 BOOL
_DIBDRVBITMAP_ExpandHoriz(DIBDRVBITMAP
*dib
, int baseWidth
, int minWidth
);
382 /* *********************************************************************
383 * BITMAP LIST MANAGEMENT FUNCTIONS
384 * ********************************************************************/
386 /* initializes bitmap list -- to be called at process attach */
387 void _BITMAPLIST_Init(void);
389 /* terminates bitmap list -- to be called at process detach */
390 void _BITMAPLIST_Terminate(void);
392 /* adds a DIB to the list - it adds it on top, as
393 usually most recently created DIBs are used first */
394 BOOL
_BITMAPLIST_Add(HBITMAP hbmp
, DIBDRVBITMAP
*bmp
);
396 /* removes a DIB from the list */
397 DIBDRVBITMAP
*_BITMAPLIST_Remove(HBITMAP hbmp
);
399 /* scans list for a DIB */
400 DIBDRVBITMAP
*_BITMAPLIST_Get(HBITMAP hbmp
);
402 /* *********************************************************************
403 * DIB <--> DDB CONVERSION ROUTINES
404 * ********************************************************************/
406 /***********************************************************************
407 * Creates DDB that is compatible with source hdc.
408 * hdc is the HDC on where the DIB MUST be selected in
409 * srcBmp is the source DIB
410 * startScan and scanLines specify the portion of DIB to convert
411 * in order to avoid unneeded conversion of large DIBs on blitting
413 * NOTE : the srcBmp DIB MUST NOT be selected in any DC */
414 HBITMAP
_DIBDRV_ConvertDIBtoDDB( HDC hdc
, HBITMAP srcBmp
, int startScan
, int scanLines
);
416 /***********************************************************************
417 * Creates DIB that is compatible with the target hdc.
418 * startScan and scanLines specify the portion of DDB to convert
419 * in order to avoid unneeded conversion of large DDBs on blitting
421 * NOTE : the srcBmp DDB MUST NOT be selected in any DC */
422 HBITMAP
_DIBDRV_ConvertDDBtoDIB( HDC hdc
, HBITMAP srcBmp
, int startScan
, int scanLines
);
424 /***********************************************************************
425 * Creates DIB that is compatible with the target hdc for a device (non memory) source DC */
426 HBITMAP
_DIBDRV_ConvertDevDDBtoDIB( HDC hdcSrc
, HDC hdcDst
, int xSrc
, int ySrc
, int width
, int height
);
428 /* *********************************************************************
430 * ********************************************************************/
432 /***********************************************************************
433 * DIBDRV_GetDeviceCaps */
434 INT
DIBDRV_GetDeviceCaps( DIBDRVPHYSDEV
*physDev
, INT cap
);
436 /* *********************************************************************
437 * GEOMETRIC UTILITIES
438 * ********************************************************************/
440 /* intersect 2 rectangles (just to not use USER32 one...) */
441 BOOL
_DIBDRV_IntersectRect(RECT
*d
, const RECT
*s1
, const RECT
*s2
);
443 /* converts positions from Word space to Device space */
444 void _DIBDRV_Position_ws2ds(DIBDRVPHYSDEV
*physDev
, int *x
, int *y
);
445 void _DIBDRV_Positions_ws2ds(DIBDRVPHYSDEV
*physDev
, int *x1
, int *y1
, int *x2
, int *y2
);
447 /* converts sizes from Word space to Device space */
448 void _DIBDRV_Sizes_ws2ds(DIBDRVPHYSDEV
*physDev
, int *w
, int *h
);
450 /* converts a rectangle form Word space to Device space */
451 void _DIBDRV_Rect_ws2ds(DIBDRVPHYSDEV
*physDev
, const RECT
*src
, RECT
*dst
);
453 /* converts positions from Device space to World space */
454 void _DIBDRV_Position_ds2ws(DIBDRVPHYSDEV
*physDev
, int *x
, int *y
);
455 void _DIBDRV_Positions_ds2ws(DIBDRVPHYSDEV
*physDev
, int *x1
, int *y1
, int *x2
, int *y2
);
457 /* converts sizes from Device space to World space */
458 void _DIBDRV_Sizes_ds2ws(DIBDRVPHYSDEV
*physDev
, int *w
, int *h
);
460 /* *********************************************************************
462 * ********************************************************************/
464 /* maps a colorref to actual color */
465 COLORREF
_DIBDRV_MapColor(DIBDRVPHYSDEV
*physDev
, COLORREF color
);
467 /* gets nearest color index in DIB palette of a given colorref */
468 DWORD
_DIBDRV_GetNearestColorIndex(const DIBDRVBITMAP
*dib
, COLORREF color
);
470 /* gets nearest color to DIB palette color */
471 DWORD
_DIBDRV_GetNearestColor(const DIBDRVBITMAP
*dib
, COLORREF color
);