DIB Engine: implement most engine functions
[wine/hacks.git] / dlls / winedib.drv / driver.c
blob46fa7a149b236b32f8e80136e9c91bd22c6fc2fa
1 /*
2 * Access to display driver
4 * Copyright 2009 Massimo Del Fedele
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.
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.
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
21 #include "config.h"
22 #include "wine/port.h"
24 #include "dibdrv.h"
25 #include <stdio.h>
27 WINE_DEFAULT_DEBUG_CHANNEL(dibdrv);
29 /* CreateDriver
30 * Allocate and fill the function pointer structure for a given module. */
31 static DC_FUNCTIONS *CreateDriver( HMODULE module )
33 DC_FUNCTIONS *funcs;
35 if (!(funcs = HeapAlloc( GetProcessHeap(), 0, sizeof(*funcs))))
36 return NULL;
38 /* fill the function table */
39 if (module)
41 #define GET_FUNC(name) funcs->p##name = (void*)GetProcAddress( module, #name )
42 GET_FUNC(AbortDoc);
43 GET_FUNC(AbortPath);
44 GET_FUNC(AlphaBlend);
45 GET_FUNC(AngleArc);
46 GET_FUNC(Arc);
47 GET_FUNC(ArcTo);
48 GET_FUNC(BeginPath);
49 GET_FUNC(BitBlt);
50 GET_FUNC(ChoosePixelFormat);
51 GET_FUNC(Chord);
52 GET_FUNC(CloseFigure);
53 GET_FUNC(CreateBitmap);
54 GET_FUNC(CreateDC);
55 GET_FUNC(CreateDIBSection);
56 GET_FUNC(DeleteBitmap);
57 GET_FUNC(DeleteDC);
58 GET_FUNC(DescribePixelFormat);
59 GET_FUNC(DeviceCapabilities);
60 GET_FUNC(Ellipse);
61 GET_FUNC(EndDoc);
62 GET_FUNC(EndPage);
63 GET_FUNC(EndPath);
64 GET_FUNC(EnumDeviceFonts);
65 GET_FUNC(ExcludeClipRect);
66 GET_FUNC(ExtDeviceMode);
67 GET_FUNC(ExtEscape);
68 GET_FUNC(ExtFloodFill);
69 GET_FUNC(ExtSelectClipRgn);
70 GET_FUNC(ExtTextOut);
71 GET_FUNC(FillPath);
72 GET_FUNC(FillRgn);
73 GET_FUNC(FlattenPath);
74 GET_FUNC(FrameRgn);
75 GET_FUNC(GdiComment);
76 GET_FUNC(GetBitmapBits);
77 GET_FUNC(GetCharWidth);
78 GET_FUNC(GetDCOrgEx);
79 GET_FUNC(GetDIBColorTable);
80 GET_FUNC(GetDIBits);
81 GET_FUNC(GetDeviceCaps);
82 GET_FUNC(GetDeviceGammaRamp);
83 GET_FUNC(GetICMProfile);
84 GET_FUNC(GetNearestColor);
85 GET_FUNC(GetPixel);
86 GET_FUNC(GetPixelFormat);
87 GET_FUNC(GetSystemPaletteEntries);
88 GET_FUNC(GetTextExtentExPoint);
89 GET_FUNC(GetTextMetrics);
90 GET_FUNC(IntersectClipRect);
91 GET_FUNC(InvertRgn);
92 GET_FUNC(LineTo);
93 GET_FUNC(MoveTo);
94 GET_FUNC(ModifyWorldTransform);
95 GET_FUNC(OffsetClipRgn);
96 GET_FUNC(OffsetViewportOrg);
97 GET_FUNC(OffsetWindowOrg);
98 GET_FUNC(PaintRgn);
99 GET_FUNC(PatBlt);
100 GET_FUNC(Pie);
101 GET_FUNC(PolyBezier);
102 GET_FUNC(PolyBezierTo);
103 GET_FUNC(PolyDraw);
104 GET_FUNC(PolyPolygon);
105 GET_FUNC(PolyPolyline);
106 GET_FUNC(Polygon);
107 GET_FUNC(Polyline);
108 GET_FUNC(PolylineTo);
109 GET_FUNC(RealizeDefaultPalette);
110 GET_FUNC(RealizePalette);
111 GET_FUNC(Rectangle);
112 GET_FUNC(ResetDC);
113 GET_FUNC(RestoreDC);
114 GET_FUNC(RoundRect);
115 GET_FUNC(SaveDC);
116 GET_FUNC(ScaleViewportExt);
117 GET_FUNC(ScaleWindowExt);
118 GET_FUNC(SelectBitmap);
119 GET_FUNC(SelectBrush);
120 GET_FUNC(SelectClipPath);
121 GET_FUNC(SelectFont);
122 GET_FUNC(SelectPalette);
123 GET_FUNC(SelectPen);
124 GET_FUNC(SetArcDirection);
125 GET_FUNC(SetBitmapBits);
126 GET_FUNC(SetBkColor);
127 GET_FUNC(SetBkMode);
128 GET_FUNC(SetDCBrushColor);
129 GET_FUNC(SetDCOrg);
130 GET_FUNC(SetDCPenColor);
131 GET_FUNC(SetDIBColorTable);
132 GET_FUNC(SetDIBits);
133 GET_FUNC(SetDIBitsToDevice);
134 GET_FUNC(SetDeviceClipping);
135 GET_FUNC(SetDeviceGammaRamp);
136 GET_FUNC(SetMapMode);
137 GET_FUNC(SetMapperFlags);
138 GET_FUNC(SetPixel);
139 GET_FUNC(SetPixelFormat);
140 GET_FUNC(SetPolyFillMode);
141 GET_FUNC(SetROP2);
142 GET_FUNC(SetRelAbs);
143 GET_FUNC(SetStretchBltMode);
144 GET_FUNC(SetTextAlign);
145 GET_FUNC(SetTextCharacterExtra);
146 GET_FUNC(SetTextColor);
147 GET_FUNC(SetTextJustification);
148 GET_FUNC(SetViewportExt);
149 GET_FUNC(SetViewportOrg);
150 GET_FUNC(SetWindowExt);
151 GET_FUNC(SetWindowOrg);
152 GET_FUNC(SetWorldTransform);
153 GET_FUNC(StartDoc);
154 GET_FUNC(StartPage);
155 GET_FUNC(StretchBlt);
156 GET_FUNC(StretchDIBits);
157 GET_FUNC(StrokeAndFillPath);
158 GET_FUNC(StrokePath);
159 GET_FUNC(SwapBuffers);
160 GET_FUNC(UnrealizePalette);
161 GET_FUNC(WidenPath);
163 /* OpenGL32 */
164 GET_FUNC(wglCreateContext);
165 GET_FUNC(wglDeleteContext);
166 GET_FUNC(wglGetProcAddress);
167 GET_FUNC(wglGetPbufferDCARB);
168 GET_FUNC(wglMakeContextCurrentARB);
169 GET_FUNC(wglMakeCurrent);
170 GET_FUNC(wglSetPixelFormatWINE);
171 GET_FUNC(wglShareLists);
172 GET_FUNC(wglUseFontBitmapsA);
173 GET_FUNC(wglUseFontBitmapsW);
174 #undef GET_FUNC
176 else
177 memset( funcs, 0, sizeof(*funcs) );
179 /* add it to the list */
180 return funcs;
184 /* LoadDisplayDriver
185 * Loads display driver - partially grabbed from gdi32 */
186 static DC_FUNCTIONS *X11DrvFuncs = NULL;
187 static HMODULE X11DrvModule = 0;
188 DC_FUNCTIONS *_DIBDRV_LoadDisplayDriver(void)
190 char buffer[MAX_PATH], libname[32], *name, *next;
191 HMODULE module = 0;
192 HKEY hkey;
194 if (X11DrvFuncs) /* already loaded */
195 return X11DrvFuncs;
197 strcpy( buffer, "x11" ); /* default value */
198 /* @@ Wine registry key: HKCU\Software\Wine\Drivers */
199 if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Drivers", &hkey ))
201 DWORD type, count = sizeof(buffer);
202 RegQueryValueExA( hkey, "Graphics", 0, &type, (LPBYTE) buffer, &count );
203 RegCloseKey( hkey );
206 name = buffer;
207 while (name)
209 next = strchr( name, ',' );
210 if (next)
211 *next++ = 0;
213 snprintf( libname, sizeof(libname), "wine%s.drv", name );
214 if ((module = LoadLibraryA( libname )) != 0)
215 break;
216 name = next;
219 if (!(X11DrvFuncs = CreateDriver(module)))
221 ERR( "Could not create graphics driver '%s'\n", buffer );
222 FreeLibrary( module );
223 ExitProcess(1);
226 X11DrvModule = module;
227 return X11DrvFuncs;
230 /* FreeDisplayDriver
231 Frees resources allocated by Display driver */
232 void _DIBDRV_FreeDisplayDriver(void)
234 /* frees function table */
235 if(X11DrvFuncs)
237 HeapFree(GetProcessHeap(), 0, X11DrvFuncs);
238 X11DrvFuncs = 0;
240 /* and unload the module */
241 if(X11DrvModule)
243 FreeLibrary(X11DrvModule);
244 X11DrvModule = 0;
248 /* GetDisplayDriver
249 Gets a pointer to display drives'function table */
250 inline DC_FUNCTIONS *_DIBDRV_GetDisplayDriver(void)
252 return X11DrvFuncs;