msvcrt: Use WINAPIV calling convention for variadic functions.
[wine.git] / dlls / winex11.drv / init.c
blobe1eb3f84d3f96686b8538b3d813b6f53e46cafaf
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
23 #include <stdarg.h>
24 #include <string.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winreg.h"
29 #include "x11drv.h"
30 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(x11drv);
34 Display *gdi_display; /* display to use for all GDI functions */
36 static int palette_size;
38 static Pixmap stock_bitmap_pixmap; /* phys bitmap for the default stock bitmap */
40 static INIT_ONCE init_once = INIT_ONCE_STATIC_INIT;
42 static const struct gdi_dc_funcs x11drv_funcs;
43 static const struct gdi_dc_funcs *xrender_funcs;
45 /**********************************************************************
46 * device_init
48 * Perform initializations needed upon creation of the first device.
50 static BOOL WINAPI device_init( INIT_ONCE *once, void *param, void **context )
52 /* Initialize XRender */
53 xrender_funcs = X11DRV_XRender_Init();
55 /* Init Xcursor */
56 X11DRV_Xcursor_Init();
58 palette_size = X11DRV_PALETTE_Init();
60 stock_bitmap_pixmap = XCreatePixmap( gdi_display, root_window, 1, 1, 1 );
62 return TRUE;
66 static X11DRV_PDEVICE *create_x11_physdev( Drawable drawable )
68 X11DRV_PDEVICE *physDev;
70 InitOnceExecuteOnce( &init_once, device_init, NULL, NULL );
72 if (!(physDev = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*physDev) ))) return NULL;
74 physDev->drawable = drawable;
75 physDev->gc = XCreateGC( gdi_display, drawable, 0, NULL );
76 XSetGraphicsExposures( gdi_display, physDev->gc, False );
77 XSetSubwindowMode( gdi_display, physDev->gc, IncludeInferiors );
78 XFlush( gdi_display );
79 return physDev;
82 /**********************************************************************
83 * X11DRV_CreateDC
85 static BOOL X11DRV_CreateDC( PHYSDEV *pdev, LPCWSTR driver, LPCWSTR device,
86 LPCWSTR output, const DEVMODEW* initData )
88 X11DRV_PDEVICE *physDev = create_x11_physdev( root_window );
90 if (!physDev) return FALSE;
92 physDev->depth = default_visual.depth;
93 physDev->color_shifts = &X11DRV_PALETTE_default_shifts;
94 physDev->dc_rect = get_virtual_screen_rect();
95 OffsetRect( &physDev->dc_rect, -physDev->dc_rect.left, -physDev->dc_rect.top );
96 push_dc_driver( pdev, &physDev->dev, &x11drv_funcs );
97 if (xrender_funcs && !xrender_funcs->pCreateDC( pdev, driver, device, output, initData )) return FALSE;
98 return TRUE;
102 /**********************************************************************
103 * X11DRV_CreateCompatibleDC
105 static BOOL X11DRV_CreateCompatibleDC( PHYSDEV orig, PHYSDEV *pdev )
107 X11DRV_PDEVICE *physDev = create_x11_physdev( stock_bitmap_pixmap );
109 if (!physDev) return FALSE;
111 physDev->depth = 1;
112 SetRect( &physDev->dc_rect, 0, 0, 1, 1 );
113 push_dc_driver( pdev, &physDev->dev, &x11drv_funcs );
114 if (orig) return TRUE; /* we already went through Xrender if we have an orig device */
115 if (xrender_funcs && !xrender_funcs->pCreateCompatibleDC( NULL, pdev )) return FALSE;
116 return TRUE;
120 /**********************************************************************
121 * X11DRV_DeleteDC
123 static BOOL X11DRV_DeleteDC( PHYSDEV dev )
125 X11DRV_PDEVICE *physDev = get_x11drv_dev( dev );
127 XFreeGC( gdi_display, physDev->gc );
128 HeapFree( GetProcessHeap(), 0, physDev );
129 return TRUE;
133 void add_device_bounds( X11DRV_PDEVICE *dev, const RECT *rect )
135 RECT rc;
137 if (!dev->bounds) return;
138 if (dev->region && GetRgnBox( dev->region, &rc ))
140 if (IntersectRect( &rc, &rc, rect )) add_bounds_rect( dev->bounds, &rc );
142 else add_bounds_rect( dev->bounds, rect );
145 /***********************************************************************
146 * X11DRV_SetBoundsRect
148 static UINT X11DRV_SetBoundsRect( PHYSDEV dev, RECT *rect, UINT flags )
150 X11DRV_PDEVICE *pdev = get_x11drv_dev( dev );
152 if (flags & DCB_DISABLE) pdev->bounds = NULL;
153 else if (flags & DCB_ENABLE) pdev->bounds = rect;
154 return DCB_RESET; /* we don't have device-specific bounds */
158 /***********************************************************************
159 * GetDeviceCaps (X11DRV.@)
161 static INT X11DRV_GetDeviceCaps( PHYSDEV dev, INT cap )
163 switch(cap)
165 case HORZRES:
167 RECT primary_rect = get_primary_monitor_rect();
168 return primary_rect.right - primary_rect.left;
170 case VERTRES:
172 RECT primary_rect = get_primary_monitor_rect();
173 return primary_rect.bottom - primary_rect.top;
175 case DESKTOPHORZRES:
177 RECT virtual_rect = get_virtual_screen_rect();
178 return virtual_rect.right - virtual_rect.left;
180 case DESKTOPVERTRES:
182 RECT virtual_rect = get_virtual_screen_rect();
183 return virtual_rect.bottom - virtual_rect.top;
185 case BITSPIXEL:
186 return screen_bpp;
187 case SIZEPALETTE:
188 return palette_size;
189 default:
190 dev = GET_NEXT_PHYSDEV( dev, pGetDeviceCaps );
191 return dev->funcs->pGetDeviceCaps( dev, cap );
196 /***********************************************************************
197 * SelectFont
199 static HFONT X11DRV_SelectFont( PHYSDEV dev, HFONT hfont, UINT *aa_flags )
201 if (default_visual.depth <= 8) *aa_flags = GGO_BITMAP; /* no anti-aliasing on <= 8bpp */
202 dev = GET_NEXT_PHYSDEV( dev, pSelectFont );
203 return dev->funcs->pSelectFont( dev, hfont, aa_flags );
206 /**********************************************************************
207 * ExtEscape (X11DRV.@)
209 static INT X11DRV_ExtEscape( PHYSDEV dev, INT escape, INT in_count, LPCVOID in_data,
210 INT out_count, LPVOID out_data )
212 X11DRV_PDEVICE *physDev = get_x11drv_dev( dev );
214 switch(escape)
216 case QUERYESCSUPPORT:
217 if (in_data && in_count >= sizeof(DWORD))
219 switch (*(const INT *)in_data)
221 case X11DRV_ESCAPE:
222 return TRUE;
225 break;
227 case X11DRV_ESCAPE:
228 if (in_data && in_count >= sizeof(enum x11drv_escape_codes))
230 switch(*(const enum x11drv_escape_codes *)in_data)
232 case X11DRV_SET_DRAWABLE:
233 if (in_count >= sizeof(struct x11drv_escape_set_drawable))
235 const struct x11drv_escape_set_drawable *data = in_data;
236 physDev->dc_rect = data->dc_rect;
237 physDev->drawable = data->drawable;
238 XFreeGC( gdi_display, physDev->gc );
239 physDev->gc = XCreateGC( gdi_display, physDev->drawable, 0, NULL );
240 XSetGraphicsExposures( gdi_display, physDev->gc, False );
241 XSetSubwindowMode( gdi_display, physDev->gc, data->mode );
242 TRACE( "SET_DRAWABLE hdc %p drawable %lx dc_rect %s\n",
243 dev->hdc, physDev->drawable, wine_dbgstr_rect(&physDev->dc_rect) );
244 return TRUE;
246 break;
247 case X11DRV_GET_DRAWABLE:
248 if (out_count >= sizeof(struct x11drv_escape_get_drawable))
250 struct x11drv_escape_get_drawable *data = out_data;
251 data->drawable = physDev->drawable;
252 return TRUE;
254 break;
255 case X11DRV_FLUSH_GL_DRAWABLE:
256 if (in_count >= sizeof(struct x11drv_escape_flush_gl_drawable))
258 const struct x11drv_escape_flush_gl_drawable *data = in_data;
259 RECT rect = physDev->dc_rect;
261 OffsetRect( &rect, -physDev->dc_rect.left, -physDev->dc_rect.top );
262 XSetFunction( gdi_display, physDev->gc, GXcopy );
263 XCopyArea( gdi_display, data->gl_drawable, physDev->drawable, physDev->gc,
264 0, 0, rect.right, rect.bottom,
265 physDev->dc_rect.left, physDev->dc_rect.top );
266 add_device_bounds( physDev, &rect );
267 return TRUE;
269 break;
270 case X11DRV_START_EXPOSURES:
271 XSetGraphicsExposures( gdi_display, physDev->gc, True );
272 physDev->exposures = 0;
273 return TRUE;
274 case X11DRV_END_EXPOSURES:
275 if (out_count >= sizeof(HRGN))
277 HRGN hrgn = 0, tmp = 0;
279 XSetGraphicsExposures( gdi_display, physDev->gc, False );
280 if (physDev->exposures)
282 for (;;)
284 XEvent event;
286 XWindowEvent( gdi_display, physDev->drawable, ~0, &event );
287 if (event.type == NoExpose) break;
288 if (event.type == GraphicsExpose)
290 RECT rect;
292 rect.left = event.xgraphicsexpose.x - physDev->dc_rect.left;
293 rect.top = event.xgraphicsexpose.y - physDev->dc_rect.top;
294 rect.right = rect.left + event.xgraphicsexpose.width;
295 rect.bottom = rect.top + event.xgraphicsexpose.height;
296 if (GetLayout( dev->hdc ) & LAYOUT_RTL)
297 mirror_rect( &physDev->dc_rect, &rect );
299 TRACE( "got %s count %d\n", wine_dbgstr_rect(&rect),
300 event.xgraphicsexpose.count );
302 if (!tmp) tmp = CreateRectRgnIndirect( &rect );
303 else SetRectRgn( tmp, rect.left, rect.top, rect.right, rect.bottom );
304 if (hrgn) CombineRgn( hrgn, hrgn, tmp, RGN_OR );
305 else
307 hrgn = tmp;
308 tmp = 0;
310 if (!event.xgraphicsexpose.count) break;
312 else
314 ERR( "got unexpected event %d\n", event.type );
315 break;
318 if (tmp) DeleteObject( tmp );
320 *(HRGN *)out_data = hrgn;
321 return TRUE;
323 break;
324 default:
325 break;
328 break;
330 return 0;
333 /**********************************************************************
334 * X11DRV_wine_get_wgl_driver
336 static struct opengl_funcs * X11DRV_wine_get_wgl_driver( PHYSDEV dev, UINT version )
338 struct opengl_funcs *ret;
340 if (!(ret = get_glx_driver( version )))
342 dev = GET_NEXT_PHYSDEV( dev, wine_get_wgl_driver );
343 ret = dev->funcs->wine_get_wgl_driver( dev, version );
345 return ret;
349 static const struct gdi_dc_funcs x11drv_funcs =
351 NULL, /* pAbortDoc */
352 NULL, /* pAbortPath */
353 NULL, /* pAlphaBlend */
354 NULL, /* pAngleArc */
355 X11DRV_Arc, /* pArc */
356 NULL, /* pArcTo */
357 NULL, /* pBeginPath */
358 NULL, /* pBlendImage */
359 X11DRV_Chord, /* pChord */
360 NULL, /* pCloseFigure */
361 X11DRV_CreateCompatibleDC, /* pCreateCompatibleDC */
362 X11DRV_CreateDC, /* pCreateDC */
363 X11DRV_DeleteDC, /* pDeleteDC */
364 NULL, /* pDeleteObject */
365 NULL, /* pDeviceCapabilities */
366 X11DRV_Ellipse, /* pEllipse */
367 NULL, /* pEndDoc */
368 NULL, /* pEndPage */
369 NULL, /* pEndPath */
370 NULL, /* pEnumFonts */
371 X11DRV_EnumICMProfiles, /* pEnumICMProfiles */
372 NULL, /* pExcludeClipRect */
373 NULL, /* pExtDeviceMode */
374 X11DRV_ExtEscape, /* pExtEscape */
375 X11DRV_ExtFloodFill, /* pExtFloodFill */
376 NULL, /* pExtSelectClipRgn */
377 NULL, /* pExtTextOut */
378 X11DRV_FillPath, /* pFillPath */
379 NULL, /* pFillRgn */
380 NULL, /* pFlattenPath */
381 NULL, /* pFontIsLinked */
382 NULL, /* pFrameRgn */
383 NULL, /* pGdiComment */
384 NULL, /* pGetBoundsRect */
385 NULL, /* pGetCharABCWidths */
386 NULL, /* pGetCharABCWidthsI */
387 NULL, /* pGetCharWidth */
388 X11DRV_GetDeviceCaps, /* pGetDeviceCaps */
389 X11DRV_GetDeviceGammaRamp, /* pGetDeviceGammaRamp */
390 NULL, /* pGetFontData */
391 NULL, /* pGetFontRealizationInfo */
392 NULL, /* pGetFontUnicodeRanges */
393 NULL, /* pGetGlyphIndices */
394 NULL, /* pGetGlyphOutline */
395 X11DRV_GetICMProfile, /* pGetICMProfile */
396 X11DRV_GetImage, /* pGetImage */
397 NULL, /* pGetKerningPairs */
398 X11DRV_GetNearestColor, /* pGetNearestColor */
399 NULL, /* pGetOutlineTextMetrics */
400 NULL, /* pGetPixel */
401 X11DRV_GetSystemPaletteEntries, /* pGetSystemPaletteEntries */
402 NULL, /* pGetTextCharsetInfo */
403 NULL, /* pGetTextExtentExPoint */
404 NULL, /* pGetTextExtentExPointI */
405 NULL, /* pGetTextFace */
406 NULL, /* pGetTextMetrics */
407 X11DRV_GradientFill, /* pGradientFill */
408 NULL, /* pIntersectClipRect */
409 NULL, /* pInvertRgn */
410 X11DRV_LineTo, /* pLineTo */
411 NULL, /* pModifyWorldTransform */
412 NULL, /* pMoveTo */
413 NULL, /* pOffsetClipRgn */
414 NULL, /* pOffsetViewportOrg */
415 NULL, /* pOffsetWindowOrg */
416 X11DRV_PaintRgn, /* pPaintRgn */
417 X11DRV_PatBlt, /* pPatBlt */
418 X11DRV_Pie, /* pPie */
419 NULL, /* pPolyBezier */
420 NULL, /* pPolyBezierTo */
421 NULL, /* pPolyDraw */
422 X11DRV_PolyPolygon, /* pPolyPolygon */
423 X11DRV_PolyPolyline, /* pPolyPolyline */
424 X11DRV_Polygon, /* pPolygon */
425 NULL, /* pPolyline */
426 NULL, /* pPolylineTo */
427 X11DRV_PutImage, /* pPutImage */
428 X11DRV_RealizeDefaultPalette, /* pRealizeDefaultPalette */
429 X11DRV_RealizePalette, /* pRealizePalette */
430 X11DRV_Rectangle, /* pRectangle */
431 NULL, /* pResetDC */
432 NULL, /* pRestoreDC */
433 X11DRV_RoundRect, /* pRoundRect */
434 NULL, /* pSaveDC */
435 NULL, /* pScaleViewportExt */
436 NULL, /* pScaleWindowExt */
437 NULL, /* pSelectBitmap */
438 X11DRV_SelectBrush, /* pSelectBrush */
439 NULL, /* pSelectClipPath */
440 X11DRV_SelectFont, /* pSelectFont */
441 NULL, /* pSelectPalette */
442 X11DRV_SelectPen, /* pSelectPen */
443 NULL, /* pSetArcDirection */
444 NULL, /* pSetBkColor */
445 NULL, /* pSetBkMode */
446 X11DRV_SetBoundsRect, /* pSetBoundsRect */
447 X11DRV_SetDCBrushColor, /* pSetDCBrushColor */
448 X11DRV_SetDCPenColor, /* pSetDCPenColor */
449 NULL, /* pSetDIBitsToDevice */
450 X11DRV_SetDeviceClipping, /* pSetDeviceClipping */
451 X11DRV_SetDeviceGammaRamp, /* pSetDeviceGammaRamp */
452 NULL, /* pSetLayout */
453 NULL, /* pSetMapMode */
454 NULL, /* pSetMapperFlags */
455 X11DRV_SetPixel, /* pSetPixel */
456 NULL, /* pSetPolyFillMode */
457 NULL, /* pSetROP2 */
458 NULL, /* pSetRelAbs */
459 NULL, /* pSetStretchBltMode */
460 NULL, /* pSetTextAlign */
461 NULL, /* pSetTextCharacterExtra */
462 NULL, /* pSetTextColor */
463 NULL, /* pSetTextJustification */
464 NULL, /* pSetViewportExt */
465 NULL, /* pSetViewportOrg */
466 NULL, /* pSetWindowExt */
467 NULL, /* pSetWindowOrg */
468 NULL, /* pSetWorldTransform */
469 NULL, /* pStartDoc */
470 NULL, /* pStartPage */
471 X11DRV_StretchBlt, /* pStretchBlt */
472 NULL, /* pStretchDIBits */
473 X11DRV_StrokeAndFillPath, /* pStrokeAndFillPath */
474 X11DRV_StrokePath, /* pStrokePath */
475 X11DRV_UnrealizePalette, /* pUnrealizePalette */
476 NULL, /* pWidenPath */
477 X11DRV_wine_get_wgl_driver, /* wine_get_wgl_driver */
478 GDI_PRIORITY_GRAPHICS_DRV /* priority */
482 /******************************************************************************
483 * X11DRV_get_gdi_driver
485 const struct gdi_dc_funcs * CDECL X11DRV_get_gdi_driver( unsigned int version )
487 if (version != WINE_GDI_DRIVER_VERSION)
489 ERR( "version mismatch, gdi32 wants %u but winex11 has %u\n", version, WINE_GDI_DRIVER_VERSION );
490 return NULL;
492 return &x11drv_funcs;