Moved a bunch of definitions from gdi.h into a new gdi_private.h to
[wine/multimedia.git] / dlls / x11drv / init.c
blobbd10202f404ac84d49d1df06650c54629b796841
1 /*
2 * X11 graphics driver initialisation functions
4 * Copyright 1996 Alexandre Julliard
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "config.h"
23 #include <stdarg.h>
24 #include <string.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "x11drv.h"
29 #include "x11font.h"
30 #include "ddrawi.h"
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(x11drv);
35 const struct tagDC_FUNCS *X11DRV_DC_Funcs = NULL; /* hack */
37 Display *gdi_display; /* display to use for all GDI functions */
39 /* a few dynamic device caps */
40 static int log_pixels_x; /* pixels per logical inch in x direction */
41 static int log_pixels_y; /* pixels per logical inch in y direction */
42 static int horz_size; /* horz. size of screen in millimeters */
43 static int vert_size; /* vert. size of screen in millimeters */
44 static int palette_size;
45 unsigned int text_caps = (TC_OP_CHARACTER | TC_OP_STROKE | TC_CP_STROKE |
46 TC_CR_ANY | TC_SA_DOUBLE | TC_SA_INTEGER |
47 TC_SA_CONTIN | TC_UA_ABLE | TC_SO_ABLE | TC_RA_ABLE);
48 /* X11R6 adds TC_SF_X_YINDEP, Xrender adds TC_VA_ABLE */
50 /**********************************************************************
51 * X11DRV_GDI_Initialize
53 BOOL X11DRV_GDI_Initialize( Display *display )
55 Screen *screen = DefaultScreenOfDisplay(display);
57 gdi_display = display;
59 palette_size = X11DRV_PALETTE_Init();
61 if (!X11DRV_BITMAP_Init()) return FALSE;
63 /* Initialize XRender */
64 X11DRV_XRender_Init();
66 /* Initialize fonts and text caps */
68 log_pixels_x = MulDiv( WidthOfScreen(screen), 254, WidthMMOfScreen(screen) * 10 );
69 log_pixels_y = MulDiv( HeightOfScreen(screen), 254, HeightMMOfScreen(screen) * 10 );
70 X11DRV_FONT_Init( &log_pixels_x, &log_pixels_y );
71 horz_size = MulDiv( screen_width, 254, log_pixels_x * 10 );
72 vert_size = MulDiv( screen_height, 254, log_pixels_y * 10 );
73 return TRUE;
76 /**********************************************************************
77 * X11DRV_GDI_Finalize
79 void X11DRV_GDI_Finalize(void)
81 X11DRV_PALETTE_Cleanup();
82 XCloseDisplay( gdi_display );
83 gdi_display = NULL;
86 /**********************************************************************
87 * X11DRV_CreateDC
89 BOOL X11DRV_CreateDC( DC *dc, X11DRV_PDEVICE **pdev, LPCWSTR driver, LPCWSTR device,
90 LPCWSTR output, const DEVMODEW* initData )
92 X11DRV_PDEVICE *physDev;
94 if (!X11DRV_DC_Funcs) X11DRV_DC_Funcs = dc->funcs; /* hack */
96 physDev = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*physDev) );
97 if(!physDev) {
98 ERR("Can't allocate physDev\n");
99 return FALSE;
101 *pdev = physDev;
102 physDev->hdc = dc->hSelf;
103 physDev->dc = dc; /* FIXME */
105 if (GetObjectType( dc->hSelf ) == OBJ_MEMDC)
107 physDev->drawable = BITMAP_stock_pixmap;
109 else
111 physDev->drawable = root_window;
112 dc->bitsPerPixel = screen_depth;
114 physDev->org.x = physDev->org.y = 0;
115 physDev->drawable_org.x = physDev->drawable_org.y = 0;
117 physDev->current_pf = 0;
118 physDev->used_visuals = 0;
120 wine_tsx11_lock();
121 physDev->gc = XCreateGC( gdi_display, physDev->drawable, 0, NULL );
122 XSetGraphicsExposures( gdi_display, physDev->gc, False );
123 XSetSubwindowMode( gdi_display, physDev->gc, IncludeInferiors );
124 XFlush( gdi_display );
125 wine_tsx11_unlock();
126 return TRUE;
130 /**********************************************************************
131 * X11DRV_DeleteDC
133 BOOL X11DRV_DeleteDC( X11DRV_PDEVICE *physDev )
135 if(physDev->xrender)
136 X11DRV_XRender_DeleteDC( physDev );
137 wine_tsx11_lock();
138 XFreeGC( gdi_display, physDev->gc );
139 while (physDev->used_visuals-- > 0)
140 XFree(physDev->visuals[physDev->used_visuals]);
141 wine_tsx11_unlock();
142 HeapFree( GetProcessHeap(), 0, physDev );
143 return TRUE;
147 /***********************************************************************
148 * GetDeviceCaps (X11DRV.@)
150 INT X11DRV_GetDeviceCaps( X11DRV_PDEVICE *physDev, INT cap )
152 switch(cap)
154 case DRIVERVERSION:
155 return 0x300;
156 case TECHNOLOGY:
157 return DT_RASDISPLAY;
158 case HORZSIZE:
159 return horz_size;
160 case VERTSIZE:
161 return vert_size;
162 case HORZRES:
163 return screen_width;
164 case VERTRES:
165 return screen_height;
166 case BITSPIXEL:
167 return screen_depth;
168 case PLANES:
169 return 1;
170 case NUMBRUSHES:
171 return -1;
172 case NUMPENS:
173 return -1;
174 case NUMMARKERS:
175 return 0;
176 case NUMFONTS:
177 return 0;
178 case NUMCOLORS:
179 /* MSDN: Number of entries in the device's color table, if the device has
180 * a color depth of no more than 8 bits per pixel.For devices with greater
181 * color depths, -1 is returned. */
182 return (screen_depth > 8) ? -1 : (1 << screen_depth);
183 case PDEVICESIZE:
184 return sizeof(X11DRV_PDEVICE);
185 case CURVECAPS:
186 return (CC_CIRCLES | CC_PIE | CC_CHORD | CC_ELLIPSES | CC_WIDE |
187 CC_STYLED | CC_WIDESTYLED | CC_INTERIORS | CC_ROUNDRECT);
188 case LINECAPS:
189 return (LC_POLYLINE | LC_MARKER | LC_POLYMARKER | LC_WIDE |
190 LC_STYLED | LC_WIDESTYLED | LC_INTERIORS);
191 case POLYGONALCAPS:
192 return (PC_POLYGON | PC_RECTANGLE | PC_WINDPOLYGON | PC_SCANLINE |
193 PC_WIDE | PC_STYLED | PC_WIDESTYLED | PC_INTERIORS);
194 case TEXTCAPS:
195 return text_caps;
196 case CLIPCAPS:
197 return CP_REGION;
198 case RASTERCAPS:
199 return (RC_BITBLT | RC_BANDING | RC_SCALING | RC_BITMAP64 | RC_DI_BITMAP |
200 RC_DIBTODEV | RC_BIGFONT | RC_STRETCHBLT | RC_STRETCHDIB | RC_DEVBITS |
201 (palette_size ? RC_PALETTE : 0));
202 case ASPECTX:
203 case ASPECTY:
204 return 36;
205 case ASPECTXY:
206 return 51;
207 case LOGPIXELSX:
208 return log_pixels_x;
209 case LOGPIXELSY:
210 return log_pixels_y;
211 case CAPS1:
212 FIXME("(%p): CAPS1 is unimplemented, will return 0\n", physDev->hdc );
213 /* please see wingdi.h for the possible bit-flag values that need
214 to be returned. also, see
215 http://msdn.microsoft.com/library/ddkdoc/win95ddk/graphcnt_1m0p.htm */
216 return 0;
217 case SIZEPALETTE:
218 return palette_size;
219 case NUMRESERVED:
220 case COLORRES:
221 case PHYSICALWIDTH:
222 case PHYSICALHEIGHT:
223 case PHYSICALOFFSETX:
224 case PHYSICALOFFSETY:
225 case SCALINGFACTORX:
226 case SCALINGFACTORY:
227 case VREFRESH:
228 case DESKTOPVERTRES:
229 case DESKTOPHORZRES:
230 case BTLALIGNMENT:
231 return 0;
232 default:
233 FIXME("(%p): unsupported capability %d, will return 0\n", physDev->hdc, cap );
234 return 0;
239 /**********************************************************************
240 * ExtEscape (X11DRV.@)
242 INT X11DRV_ExtEscape( X11DRV_PDEVICE *physDev, INT escape, INT in_count, LPCVOID in_data,
243 INT out_count, LPVOID out_data )
245 switch(escape)
247 case QUERYESCSUPPORT:
248 if (in_data)
250 switch (*(INT *)in_data)
252 case DCICOMMAND:
253 return DD_HAL_VERSION;
254 case X11DRV_ESCAPE:
255 return TRUE;
258 break;
260 case DCICOMMAND:
261 if (in_data)
263 const DCICMD *lpCmd = in_data;
264 if (lpCmd->dwVersion != DD_VERSION) break;
265 return X11DRV_DCICommand(in_count, lpCmd, out_data);
267 break;
269 case X11DRV_ESCAPE:
270 if (in_data && in_count >= sizeof(enum x11drv_escape_codes))
272 switch(*(enum x11drv_escape_codes *)in_data)
274 case X11DRV_GET_DISPLAY:
275 if (out_count >= sizeof(Display *))
277 *(Display **)out_data = gdi_display;
278 return TRUE;
280 break;
281 case X11DRV_GET_DRAWABLE:
282 if (out_count >= sizeof(Drawable))
284 *(Drawable *)out_data = physDev->drawable;
285 return TRUE;
287 break;
288 case X11DRV_GET_FONT:
289 if (out_count >= sizeof(Font))
291 fontObject* pfo = XFONT_GetFontObject( physDev->font );
292 if (pfo == NULL) return FALSE;
293 *(Font *)out_data = pfo->fs->fid;
294 return TRUE;
296 break;
297 case X11DRV_SET_DRAWABLE:
298 if (in_count >= sizeof(struct x11drv_escape_set_drawable))
300 struct x11drv_escape_set_drawable *data = (struct x11drv_escape_set_drawable *)in_data;
301 if(physDev->xrender) X11DRV_XRender_UpdateDrawable( physDev );
302 physDev->org = data->org;
303 physDev->drawable = data->drawable;
304 physDev->drawable_org = data->drawable_org;
305 wine_tsx11_lock();
306 XSetSubwindowMode( gdi_display, physDev->gc, data->mode );
307 wine_tsx11_unlock();
308 return TRUE;
310 break;
311 case X11DRV_START_EXPOSURES:
312 wine_tsx11_lock();
313 XSetGraphicsExposures( gdi_display, physDev->gc, True );
314 wine_tsx11_unlock();
315 physDev->exposures = 0;
316 return TRUE;
317 case X11DRV_END_EXPOSURES:
318 if (out_count >= sizeof(HRGN))
320 HRGN hrgn = 0, tmp = 0;
322 wine_tsx11_lock();
323 XSetGraphicsExposures( gdi_display, physDev->gc, False );
324 if (physDev->exposures)
326 for (;;)
328 XEvent event;
330 XWindowEvent( gdi_display, physDev->drawable, ~0, &event );
331 if (event.type == NoExpose) break;
332 if (event.type == GraphicsExpose)
334 int x = event.xgraphicsexpose.x - physDev->org.x;
335 int y = event.xgraphicsexpose.y - physDev->org.y;
337 TRACE( "got %d,%d %dx%d count %d\n", x, y,
338 event.xgraphicsexpose.width,
339 event.xgraphicsexpose.height,
340 event.xgraphicsexpose.count );
342 if (!tmp) tmp = CreateRectRgn( 0, 0, 0, 0 );
343 SetRectRgn( tmp, x, y,
344 x + event.xgraphicsexpose.width,
345 y + event.xgraphicsexpose.height );
346 if (hrgn) CombineRgn( hrgn, hrgn, tmp, RGN_OR );
347 else
349 hrgn = tmp;
350 tmp = 0;
352 if (!event.xgraphicsexpose.count) break;
354 else
356 ERR( "got unexpected event %d\n", event.type );
357 break;
360 if (tmp) DeleteObject( tmp );
362 wine_tsx11_unlock();
363 *(HRGN *)out_data = hrgn;
364 return TRUE;
366 break;
369 break;
371 return 0;