gdi32: Add the ability to track whether we should defer to the graphics driver.
[wine] / dlls / gdi32 / dibdrv / dc.c
1 /*
2  * DIB driver initialization and DC functions.
3  *
4  * Copyright 2011 Huw Davies
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include <assert.h>
22
23 #include "gdi_private.h"
24 #include "dibdrv.h"
25
26 #include "wine/debug.h"
27
28 WINE_DEFAULT_DEBUG_CHANNEL(dib);
29
30 /***********************************************************************
31  *           dibdrv_DeleteDC
32  */
33 static BOOL CDECL dibdrv_DeleteDC( PHYSDEV dev )
34 {
35     TRACE("(%p)\n", dev);
36     return 0;
37 }
38
39 static void calc_shift_and_len(DWORD mask, int *shift, int *len)
40 {
41     int s, l;
42
43     s = 0;
44     while ((mask & 1) == 0)
45     {
46         mask >>= 1;
47         s++;
48     }
49     l = 0;
50     while ((mask & 1) == 1)
51     {
52         mask >>= 1;
53         l++;
54     }
55     *shift = s;
56     *len = l;
57 }
58
59 static void init_bit_fields(dib_info *dib, const DWORD *bit_fields)
60 {
61     dib->red_mask    = bit_fields[0];
62     dib->green_mask  = bit_fields[1];
63     dib->blue_mask   = bit_fields[2];
64     calc_shift_and_len(dib->red_mask,   &dib->red_shift,   &dib->red_len);
65     calc_shift_and_len(dib->green_mask, &dib->green_shift, &dib->green_len);
66     calc_shift_and_len(dib->blue_mask,  &dib->blue_shift,  &dib->blue_len);
67 }
68
69 static BOOL init_dib(dib_info *dib, const BITMAPINFOHEADER *bi, const DWORD *bit_fields, void *bits)
70 {
71     dib->bit_count = bi->biBitCount;
72     dib->width     = bi->biWidth;
73     dib->height    = bi->biHeight;
74     dib->stride    = ((dib->width * dib->bit_count + 31) >> 3) & ~3;
75     dib->bits      = bits;
76
77     if(dib->height < 0) /* top-down */
78     {
79         dib->height = -dib->height;
80     }
81     else /* bottom-up */
82     {
83         /* bits always points to the top-left corner and the stride is -ve */
84         dib->bits    = (BYTE*)dib->bits + (dib->height - 1) * dib->stride;
85         dib->stride  = -dib->stride;
86     }
87
88     dib->funcs = &funcs_null;
89
90     switch(dib->bit_count)
91     {
92     case 32:
93         init_bit_fields(dib, bit_fields);
94         if(dib->red_mask == 0xff0000 && dib->green_mask == 0x00ff00 && dib->blue_mask == 0x0000ff)
95             dib->funcs = &funcs_8888;
96         else
97             dib->funcs = &funcs_32;
98         break;
99
100     default:
101         TRACE("bpp %d not supported, will forward to graphics driver.\n", dib->bit_count);
102         return FALSE;
103     }
104
105     return TRUE;
106 }
107
108 /***********************************************************************
109  *           dibdrv_SelectBitmap
110  */
111 static HBITMAP CDECL dibdrv_SelectBitmap( PHYSDEV dev, HBITMAP bitmap )
112 {
113     PHYSDEV next = GET_NEXT_PHYSDEV( dev, pSelectBitmap );
114     dibdrv_physdev *pdev = get_dibdrv_pdev(dev);
115     BITMAPOBJ *bmp = GDI_GetObjPtr( bitmap, OBJ_BITMAP );
116     TRACE("(%p, %p)\n", dev, bitmap);
117
118     if (!bmp) return 0;
119     assert(bmp->dib);
120
121     pdev->defer = 0;
122
123     if(!init_dib(&pdev->dib, &bmp->dib->dsBmih, bmp->dib->dsBitfields, bmp->dib->dsBm.bmBits))
124         pdev->defer |= DEFER_FORMAT;
125
126     GDI_ReleaseObj( bitmap );
127
128     return next->funcs->pSelectBitmap( next, bitmap );
129 }
130
131 const DC_FUNCTIONS dib_driver =
132 {
133     NULL,                               /* pAbortDoc */
134     NULL,                               /* pAbortPath */
135     NULL,                               /* pAlphaBlend */
136     NULL,                               /* pAngleArc */
137     NULL,                               /* pArc */
138     NULL,                               /* pArcTo */
139     NULL,                               /* pBeginPath */
140     NULL,                               /* pChoosePixelFormat */
141     NULL,                               /* pChord */
142     NULL,                               /* pCloseFigure */
143     NULL,                               /* pCreateBitmap */
144     NULL,                               /* pCreateDC */
145     NULL,                               /* pCreateDIBSection */
146     NULL,                               /* pDeleteBitmap */
147     dibdrv_DeleteDC,                    /* pDeleteDC */
148     NULL,                               /* pDeleteObject */
149     NULL,                               /* pDescribePixelFormat */
150     NULL,                               /* pDeviceCapabilities */
151     NULL,                               /* pEllipse */
152     NULL,                               /* pEndDoc */
153     NULL,                               /* pEndPage */
154     NULL,                               /* pEndPath */
155     NULL,                               /* pEnumDeviceFonts */
156     NULL,                               /* pEnumICMProfiles */
157     NULL,                               /* pExcludeClipRect */
158     NULL,                               /* pExtDeviceMode */
159     NULL,                               /* pExtEscape */
160     NULL,                               /* pExtFloodFill */
161     NULL,                               /* pExtSelectClipRgn */
162     NULL,                               /* pExtTextOut */
163     NULL,                               /* pFillPath */
164     NULL,                               /* pFillRgn */
165     NULL,                               /* pFlattenPath */
166     NULL,                               /* pFrameRgn */
167     NULL,                               /* pGdiComment */
168     NULL,                               /* pGetBitmapBits */
169     NULL,                               /* pGetCharWidth */
170     NULL,                               /* pGetDIBits */
171     NULL,                               /* pGetDeviceCaps */
172     NULL,                               /* pGetDeviceGammaRamp */
173     NULL,                               /* pGetICMProfile */
174     NULL,                               /* pGetNearestColor */
175     NULL,                               /* pGetPixel */
176     NULL,                               /* pGetPixelFormat */
177     NULL,                               /* pGetSystemPaletteEntries */
178     NULL,                               /* pGetTextExtentExPoint */
179     NULL,                               /* pGetTextMetrics */
180     NULL,                               /* pIntersectClipRect */
181     NULL,                               /* pInvertRgn */
182     NULL,                               /* pLineTo */
183     NULL,                               /* pModifyWorldTransform */
184     NULL,                               /* pMoveTo */
185     NULL,                               /* pOffsetClipRgn */
186     NULL,                               /* pOffsetViewportOrg */
187     NULL,                               /* pOffsetWindowOrg */
188     NULL,                               /* pPaintRgn */
189     NULL,                               /* pPatBlt */
190     NULL,                               /* pPie */
191     NULL,                               /* pPolyBezier */
192     NULL,                               /* pPolyBezierTo */
193     NULL,                               /* pPolyDraw */
194     NULL,                               /* pPolyPolygon */
195     NULL,                               /* pPolyPolyline */
196     NULL,                               /* pPolygon */
197     NULL,                               /* pPolyline */
198     NULL,                               /* pPolylineTo */
199     NULL,                               /* pRealizeDefaultPalette */
200     NULL,                               /* pRealizePalette */
201     NULL,                               /* pRectangle */
202     NULL,                               /* pResetDC */
203     NULL,                               /* pRestoreDC */
204     NULL,                               /* pRoundRect */
205     NULL,                               /* pSaveDC */
206     NULL,                               /* pScaleViewportExt */
207     NULL,                               /* pScaleWindowExt */
208     dibdrv_SelectBitmap,                /* pSelectBitmap */
209     NULL,                               /* pSelectBrush */
210     NULL,                               /* pSelectClipPath */
211     NULL,                               /* pSelectFont */
212     NULL,                               /* pSelectPalette */
213     dibdrv_SelectPen,                   /* pSelectPen */
214     NULL,                               /* pSetArcDirection */
215     NULL,                               /* pSetBitmapBits */
216     NULL,                               /* pSetBkColor */
217     NULL,                               /* pSetBkMode */
218     NULL,                               /* pSetDCBrushColor */
219     NULL,                               /* pSetDCPenColor */
220     NULL,                               /* pSetDIBColorTable */
221     NULL,                               /* pSetDIBits */
222     NULL,                               /* pSetDIBitsToDevice */
223     NULL,                               /* pSetDeviceClipping */
224     NULL,                               /* pSetDeviceGammaRamp */
225     NULL,                               /* pSetLayout */
226     NULL,                               /* pSetMapMode */
227     NULL,                               /* pSetMapperFlags */
228     NULL,                               /* pSetPixel */
229     NULL,                               /* pSetPixelFormat */
230     NULL,                               /* pSetPolyFillMode */
231     NULL,                               /* pSetROP2 */
232     NULL,                               /* pSetRelAbs */
233     NULL,                               /* pSetStretchBltMode */
234     NULL,                               /* pSetTextAlign */
235     NULL,                               /* pSetTextCharacterExtra */
236     NULL,                               /* pSetTextColor */
237     NULL,                               /* pSetTextJustification */
238     NULL,                               /* pSetViewportExt */
239     NULL,                               /* pSetViewportOrg */
240     NULL,                               /* pSetWindowExt */
241     NULL,                               /* pSetWindowOrg */
242     NULL,                               /* pSetWorldTransform */
243     NULL,                               /* pStartDoc */
244     NULL,                               /* pStartPage */
245     NULL,                               /* pStretchBlt */
246     NULL,                               /* pStretchDIBits */
247     NULL,                               /* pStrokeAndFillPath */
248     NULL,                               /* pStrokePath */
249     NULL,                               /* pSwapBuffers */
250     NULL,                               /* pUnrealizePalette */
251     NULL,                               /* pWidenPath */
252     NULL,                               /* pwglCopyContext */
253     NULL,                               /* pwglCreateContext */
254     NULL,                               /* pwglCreateContextAttribsARB */
255     NULL,                               /* pwglDeleteContext */
256     NULL,                               /* pwglGetProcAddress */
257     NULL,                               /* pwglGetPbufferDCARB */
258     NULL,                               /* pwglMakeCurrent */
259     NULL,                               /* pwglMakeContextCurrentARB */
260     NULL,                               /* pwglSetPixelFormatWINE */
261     NULL,                               /* pwglShareLists */
262     NULL,                               /* pwglUseFontBitmapsA */
263     NULL                                /* pwglUseFontBitmapsW */
264 };