gdi32: Add a dib primitive function table.
[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 init_bit_fields(dib_info *dib, const DWORD *bit_fields)
40 {
41     dib->red_mask    = bit_fields[0];
42     dib->green_mask  = bit_fields[1];
43     dib->blue_mask   = bit_fields[2];
44 }
45
46 static BOOL init_dib(dib_info *dib, const BITMAPINFOHEADER *bi, const DWORD *bit_fields, void *bits)
47 {
48     dib->bit_count = bi->biBitCount;
49     dib->width     = bi->biWidth;
50     dib->height    = bi->biHeight;
51     dib->stride    = ((dib->width * dib->bit_count + 31) >> 3) & ~3;
52     dib->bits      = bits;
53
54     if(dib->height < 0) /* top-down */
55     {
56         dib->height = -dib->height;
57     }
58     else /* bottom-up */
59     {
60         /* bits always points to the top-left corner and the stride is -ve */
61         dib->bits    = (BYTE*)dib->bits + (dib->height - 1) * dib->stride;
62         dib->stride  = -dib->stride;
63     }
64
65     dib->funcs = &funcs_null;
66
67     switch(dib->bit_count)
68     {
69     case 32:
70          init_bit_fields(dib, bit_fields);
71          if(dib->red_mask == 0xff0000 && dib->green_mask == 0x00ff00 && dib->blue_mask == 0x0000ff)
72              dib->funcs = &funcs_8888;
73          else
74          {
75              TRACE("32 bpp bitmasks not supported, will forward to graphics driver.\n");
76              return FALSE;
77          }
78          break;
79
80     default:
81         TRACE("bpp %d not supported, will forward to graphics driver.\n", dib->bit_count);
82         return FALSE;
83     }
84
85     return TRUE;
86 }
87
88 /***********************************************************************
89  *           dibdrv_SelectBitmap
90  */
91 static HBITMAP CDECL dibdrv_SelectBitmap( PHYSDEV dev, HBITMAP bitmap )
92 {
93     PHYSDEV next = GET_NEXT_PHYSDEV( dev, pSelectBitmap );
94     dibdrv_physdev *pdev = get_dibdrv_pdev(dev);
95     BITMAPOBJ *bmp = GDI_GetObjPtr( bitmap, OBJ_BITMAP );
96     TRACE("(%p, %p)\n", dev, bitmap);
97
98     if (!bmp) return 0;
99     assert(bmp->dib);
100
101     init_dib(&pdev->dib, &bmp->dib->dsBmih, bmp->dib->dsBitfields, bmp->dib->dsBm.bmBits);
102
103     GDI_ReleaseObj( bitmap );
104
105     return next->funcs->pSelectBitmap( next, bitmap );
106 }
107
108 const DC_FUNCTIONS dib_driver =
109 {
110     NULL,                               /* pAbortDoc */
111     NULL,                               /* pAbortPath */
112     NULL,                               /* pAlphaBlend */
113     NULL,                               /* pAngleArc */
114     NULL,                               /* pArc */
115     NULL,                               /* pArcTo */
116     NULL,                               /* pBeginPath */
117     NULL,                               /* pChoosePixelFormat */
118     NULL,                               /* pChord */
119     NULL,                               /* pCloseFigure */
120     NULL,                               /* pCreateBitmap */
121     NULL,                               /* pCreateDC */
122     NULL,                               /* pCreateDIBSection */
123     NULL,                               /* pDeleteBitmap */
124     dibdrv_DeleteDC,                    /* pDeleteDC */
125     NULL,                               /* pDeleteObject */
126     NULL,                               /* pDescribePixelFormat */
127     NULL,                               /* pDeviceCapabilities */
128     NULL,                               /* pEllipse */
129     NULL,                               /* pEndDoc */
130     NULL,                               /* pEndPage */
131     NULL,                               /* pEndPath */
132     NULL,                               /* pEnumDeviceFonts */
133     NULL,                               /* pEnumICMProfiles */
134     NULL,                               /* pExcludeClipRect */
135     NULL,                               /* pExtDeviceMode */
136     NULL,                               /* pExtEscape */
137     NULL,                               /* pExtFloodFill */
138     NULL,                               /* pExtSelectClipRgn */
139     NULL,                               /* pExtTextOut */
140     NULL,                               /* pFillPath */
141     NULL,                               /* pFillRgn */
142     NULL,                               /* pFlattenPath */
143     NULL,                               /* pFrameRgn */
144     NULL,                               /* pGdiComment */
145     NULL,                               /* pGetBitmapBits */
146     NULL,                               /* pGetCharWidth */
147     NULL,                               /* pGetDIBits */
148     NULL,                               /* pGetDeviceCaps */
149     NULL,                               /* pGetDeviceGammaRamp */
150     NULL,                               /* pGetICMProfile */
151     NULL,                               /* pGetNearestColor */
152     NULL,                               /* pGetPixel */
153     NULL,                               /* pGetPixelFormat */
154     NULL,                               /* pGetSystemPaletteEntries */
155     NULL,                               /* pGetTextExtentExPoint */
156     NULL,                               /* pGetTextMetrics */
157     NULL,                               /* pIntersectClipRect */
158     NULL,                               /* pInvertRgn */
159     NULL,                               /* pLineTo */
160     NULL,                               /* pModifyWorldTransform */
161     NULL,                               /* pMoveTo */
162     NULL,                               /* pOffsetClipRgn */
163     NULL,                               /* pOffsetViewportOrg */
164     NULL,                               /* pOffsetWindowOrg */
165     NULL,                               /* pPaintRgn */
166     NULL,                               /* pPatBlt */
167     NULL,                               /* pPie */
168     NULL,                               /* pPolyBezier */
169     NULL,                               /* pPolyBezierTo */
170     NULL,                               /* pPolyDraw */
171     NULL,                               /* pPolyPolygon */
172     NULL,                               /* pPolyPolyline */
173     NULL,                               /* pPolygon */
174     NULL,                               /* pPolyline */
175     NULL,                               /* pPolylineTo */
176     NULL,                               /* pRealizeDefaultPalette */
177     NULL,                               /* pRealizePalette */
178     NULL,                               /* pRectangle */
179     NULL,                               /* pResetDC */
180     NULL,                               /* pRestoreDC */
181     NULL,                               /* pRoundRect */
182     NULL,                               /* pSaveDC */
183     NULL,                               /* pScaleViewportExt */
184     NULL,                               /* pScaleWindowExt */
185     dibdrv_SelectBitmap,                /* pSelectBitmap */
186     NULL,                               /* pSelectBrush */
187     NULL,                               /* pSelectClipPath */
188     NULL,                               /* pSelectFont */
189     NULL,                               /* pSelectPalette */
190     NULL,                               /* pSelectPen */
191     NULL,                               /* pSetArcDirection */
192     NULL,                               /* pSetBitmapBits */
193     NULL,                               /* pSetBkColor */
194     NULL,                               /* pSetBkMode */
195     NULL,                               /* pSetDCBrushColor */
196     NULL,                               /* pSetDCPenColor */
197     NULL,                               /* pSetDIBColorTable */
198     NULL,                               /* pSetDIBits */
199     NULL,                               /* pSetDIBitsToDevice */
200     NULL,                               /* pSetDeviceClipping */
201     NULL,                               /* pSetDeviceGammaRamp */
202     NULL,                               /* pSetLayout */
203     NULL,                               /* pSetMapMode */
204     NULL,                               /* pSetMapperFlags */
205     NULL,                               /* pSetPixel */
206     NULL,                               /* pSetPixelFormat */
207     NULL,                               /* pSetPolyFillMode */
208     NULL,                               /* pSetROP2 */
209     NULL,                               /* pSetRelAbs */
210     NULL,                               /* pSetStretchBltMode */
211     NULL,                               /* pSetTextAlign */
212     NULL,                               /* pSetTextCharacterExtra */
213     NULL,                               /* pSetTextColor */
214     NULL,                               /* pSetTextJustification */
215     NULL,                               /* pSetViewportExt */
216     NULL,                               /* pSetViewportOrg */
217     NULL,                               /* pSetWindowExt */
218     NULL,                               /* pSetWindowOrg */
219     NULL,                               /* pSetWorldTransform */
220     NULL,                               /* pStartDoc */
221     NULL,                               /* pStartPage */
222     NULL,                               /* pStretchBlt */
223     NULL,                               /* pStretchDIBits */
224     NULL,                               /* pStrokeAndFillPath */
225     NULL,                               /* pStrokePath */
226     NULL,                               /* pSwapBuffers */
227     NULL,                               /* pUnrealizePalette */
228     NULL,                               /* pWidenPath */
229     NULL,                               /* pwglCopyContext */
230     NULL,                               /* pwglCreateContext */
231     NULL,                               /* pwglCreateContextAttribsARB */
232     NULL,                               /* pwglDeleteContext */
233     NULL,                               /* pwglGetProcAddress */
234     NULL,                               /* pwglGetPbufferDCARB */
235     NULL,                               /* pwglMakeCurrent */
236     NULL,                               /* pwglMakeContextCurrentARB */
237     NULL,                               /* pwglSetPixelFormatWINE */
238     NULL,                               /* pwglShareLists */
239     NULL,                               /* pwglUseFontBitmapsA */
240     NULL                                /* pwglUseFontBitmapsW */
241 };