winex11: Use fallback implementation for screen dimensions in GetDeviceCaps().
[wine.git] / dlls / winex11.drv / init.c
blob326873314c06e010504392685121541e31f93b98
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 BITSPIXEL:
166 return screen_bpp;
167 case SIZEPALETTE:
168 return palette_size;
169 default:
170 dev = GET_NEXT_PHYSDEV( dev, pGetDeviceCaps );
171 return dev->funcs->pGetDeviceCaps( dev, cap );
176 /***********************************************************************
177 * SelectFont
179 static HFONT X11DRV_SelectFont( PHYSDEV dev, HFONT hfont, UINT *aa_flags )
181 if (default_visual.depth <= 8) *aa_flags = GGO_BITMAP; /* no anti-aliasing on <= 8bpp */
182 dev = GET_NEXT_PHYSDEV( dev, pSelectFont );
183 return dev->funcs->pSelectFont( dev, hfont, aa_flags );
186 /**********************************************************************
187 * ExtEscape (X11DRV.@)
189 static INT X11DRV_ExtEscape( PHYSDEV dev, INT escape, INT in_count, LPCVOID in_data,
190 INT out_count, LPVOID out_data )
192 X11DRV_PDEVICE *physDev = get_x11drv_dev( dev );
194 switch(escape)
196 case QUERYESCSUPPORT:
197 if (in_data && in_count >= sizeof(DWORD))
199 switch (*(const INT *)in_data)
201 case X11DRV_ESCAPE:
202 return TRUE;
205 break;
207 case X11DRV_ESCAPE:
208 if (in_data && in_count >= sizeof(enum x11drv_escape_codes))
210 switch(*(const enum x11drv_escape_codes *)in_data)
212 case X11DRV_SET_DRAWABLE:
213 if (in_count >= sizeof(struct x11drv_escape_set_drawable))
215 const struct x11drv_escape_set_drawable *data = in_data;
216 physDev->dc_rect = data->dc_rect;
217 physDev->drawable = data->drawable;
218 XFreeGC( gdi_display, physDev->gc );
219 physDev->gc = XCreateGC( gdi_display, physDev->drawable, 0, NULL );
220 XSetGraphicsExposures( gdi_display, physDev->gc, False );
221 XSetSubwindowMode( gdi_display, physDev->gc, data->mode );
222 TRACE( "SET_DRAWABLE hdc %p drawable %lx dc_rect %s\n",
223 dev->hdc, physDev->drawable, wine_dbgstr_rect(&physDev->dc_rect) );
224 return TRUE;
226 break;
227 case X11DRV_GET_DRAWABLE:
228 if (out_count >= sizeof(struct x11drv_escape_get_drawable))
230 struct x11drv_escape_get_drawable *data = out_data;
231 data->drawable = physDev->drawable;
232 return TRUE;
234 break;
235 case X11DRV_FLUSH_GL_DRAWABLE:
236 if (in_count >= sizeof(struct x11drv_escape_flush_gl_drawable))
238 const struct x11drv_escape_flush_gl_drawable *data = in_data;
239 RECT rect = physDev->dc_rect;
241 OffsetRect( &rect, -physDev->dc_rect.left, -physDev->dc_rect.top );
242 if (data->flush) XFlush( gdi_display );
243 XSetFunction( gdi_display, physDev->gc, GXcopy );
244 XCopyArea( gdi_display, data->gl_drawable, physDev->drawable, physDev->gc,
245 0, 0, rect.right, rect.bottom,
246 physDev->dc_rect.left, physDev->dc_rect.top );
247 add_device_bounds( physDev, &rect );
248 return TRUE;
250 break;
251 case X11DRV_START_EXPOSURES:
252 XSetGraphicsExposures( gdi_display, physDev->gc, True );
253 physDev->exposures = 0;
254 return TRUE;
255 case X11DRV_END_EXPOSURES:
256 if (out_count >= sizeof(HRGN))
258 HRGN hrgn = 0, tmp = 0;
260 XSetGraphicsExposures( gdi_display, physDev->gc, False );
261 if (physDev->exposures)
263 for (;;)
265 XEvent event;
267 XWindowEvent( gdi_display, physDev->drawable, ~0, &event );
268 if (event.type == NoExpose) break;
269 if (event.type == GraphicsExpose)
271 RECT rect;
273 rect.left = event.xgraphicsexpose.x - physDev->dc_rect.left;
274 rect.top = event.xgraphicsexpose.y - physDev->dc_rect.top;
275 rect.right = rect.left + event.xgraphicsexpose.width;
276 rect.bottom = rect.top + event.xgraphicsexpose.height;
277 if (GetLayout( dev->hdc ) & LAYOUT_RTL)
278 mirror_rect( &physDev->dc_rect, &rect );
280 TRACE( "got %s count %d\n", wine_dbgstr_rect(&rect),
281 event.xgraphicsexpose.count );
283 if (!tmp) tmp = CreateRectRgnIndirect( &rect );
284 else SetRectRgn( tmp, rect.left, rect.top, rect.right, rect.bottom );
285 if (hrgn) CombineRgn( hrgn, hrgn, tmp, RGN_OR );
286 else
288 hrgn = tmp;
289 tmp = 0;
291 if (!event.xgraphicsexpose.count) break;
293 else
295 ERR( "got unexpected event %d\n", event.type );
296 break;
299 if (tmp) DeleteObject( tmp );
301 *(HRGN *)out_data = hrgn;
302 return TRUE;
304 break;
305 default:
306 break;
309 break;
311 return 0;
314 /**********************************************************************
315 * X11DRV_wine_get_wgl_driver
317 static struct opengl_funcs * X11DRV_wine_get_wgl_driver( PHYSDEV dev, UINT version )
319 struct opengl_funcs *ret;
321 if (!(ret = get_glx_driver( version )))
323 dev = GET_NEXT_PHYSDEV( dev, wine_get_wgl_driver );
324 ret = dev->funcs->wine_get_wgl_driver( dev, version );
326 return ret;
329 /**********************************************************************
330 * X11DRV_wine_get_vulkan_driver
332 static const struct vulkan_funcs * X11DRV_wine_get_vulkan_driver( PHYSDEV dev, UINT version )
334 const struct vulkan_funcs *ret;
336 if (!(ret = get_vulkan_driver( version )))
338 dev = GET_NEXT_PHYSDEV( dev, wine_get_vulkan_driver );
339 ret = dev->funcs->wine_get_vulkan_driver( dev, version );
341 return ret;
345 static const struct gdi_dc_funcs x11drv_funcs =
347 NULL, /* pAbortDoc */
348 NULL, /* pAbortPath */
349 NULL, /* pAlphaBlend */
350 NULL, /* pAngleArc */
351 X11DRV_Arc, /* pArc */
352 NULL, /* pArcTo */
353 NULL, /* pBeginPath */
354 NULL, /* pBlendImage */
355 X11DRV_Chord, /* pChord */
356 NULL, /* pCloseFigure */
357 X11DRV_CreateCompatibleDC, /* pCreateCompatibleDC */
358 X11DRV_CreateDC, /* pCreateDC */
359 X11DRV_DeleteDC, /* pDeleteDC */
360 NULL, /* pDeleteObject */
361 NULL, /* pDeviceCapabilities */
362 X11DRV_Ellipse, /* pEllipse */
363 NULL, /* pEndDoc */
364 NULL, /* pEndPage */
365 NULL, /* pEndPath */
366 NULL, /* pEnumFonts */
367 X11DRV_EnumICMProfiles, /* pEnumICMProfiles */
368 NULL, /* pExcludeClipRect */
369 NULL, /* pExtDeviceMode */
370 X11DRV_ExtEscape, /* pExtEscape */
371 X11DRV_ExtFloodFill, /* pExtFloodFill */
372 NULL, /* pExtSelectClipRgn */
373 NULL, /* pExtTextOut */
374 X11DRV_FillPath, /* pFillPath */
375 NULL, /* pFillRgn */
376 NULL, /* pFlattenPath */
377 NULL, /* pFontIsLinked */
378 NULL, /* pFrameRgn */
379 NULL, /* pGdiComment */
380 NULL, /* pGetBoundsRect */
381 NULL, /* pGetCharABCWidths */
382 NULL, /* pGetCharABCWidthsI */
383 NULL, /* pGetCharWidth */
384 X11DRV_GetDeviceCaps, /* pGetDeviceCaps */
385 X11DRV_GetDeviceGammaRamp, /* pGetDeviceGammaRamp */
386 NULL, /* pGetFontData */
387 NULL, /* pGetFontRealizationInfo */
388 NULL, /* pGetFontUnicodeRanges */
389 NULL, /* pGetGlyphIndices */
390 NULL, /* pGetGlyphOutline */
391 X11DRV_GetICMProfile, /* pGetICMProfile */
392 X11DRV_GetImage, /* pGetImage */
393 NULL, /* pGetKerningPairs */
394 X11DRV_GetNearestColor, /* pGetNearestColor */
395 NULL, /* pGetOutlineTextMetrics */
396 NULL, /* pGetPixel */
397 X11DRV_GetSystemPaletteEntries, /* pGetSystemPaletteEntries */
398 NULL, /* pGetTextCharsetInfo */
399 NULL, /* pGetTextExtentExPoint */
400 NULL, /* pGetTextExtentExPointI */
401 NULL, /* pGetTextFace */
402 NULL, /* pGetTextMetrics */
403 X11DRV_GradientFill, /* pGradientFill */
404 NULL, /* pIntersectClipRect */
405 NULL, /* pInvertRgn */
406 X11DRV_LineTo, /* pLineTo */
407 NULL, /* pModifyWorldTransform */
408 NULL, /* pMoveTo */
409 NULL, /* pOffsetClipRgn */
410 NULL, /* pOffsetViewportOrg */
411 NULL, /* pOffsetWindowOrg */
412 X11DRV_PaintRgn, /* pPaintRgn */
413 X11DRV_PatBlt, /* pPatBlt */
414 X11DRV_Pie, /* pPie */
415 NULL, /* pPolyBezier */
416 NULL, /* pPolyBezierTo */
417 NULL, /* pPolyDraw */
418 X11DRV_PolyPolygon, /* pPolyPolygon */
419 X11DRV_PolyPolyline, /* pPolyPolyline */
420 X11DRV_Polygon, /* pPolygon */
421 NULL, /* pPolyline */
422 NULL, /* pPolylineTo */
423 X11DRV_PutImage, /* pPutImage */
424 X11DRV_RealizeDefaultPalette, /* pRealizeDefaultPalette */
425 X11DRV_RealizePalette, /* pRealizePalette */
426 X11DRV_Rectangle, /* pRectangle */
427 NULL, /* pResetDC */
428 NULL, /* pRestoreDC */
429 X11DRV_RoundRect, /* pRoundRect */
430 NULL, /* pSaveDC */
431 NULL, /* pScaleViewportExt */
432 NULL, /* pScaleWindowExt */
433 NULL, /* pSelectBitmap */
434 X11DRV_SelectBrush, /* pSelectBrush */
435 NULL, /* pSelectClipPath */
436 X11DRV_SelectFont, /* pSelectFont */
437 NULL, /* pSelectPalette */
438 X11DRV_SelectPen, /* pSelectPen */
439 NULL, /* pSetArcDirection */
440 NULL, /* pSetBkColor */
441 NULL, /* pSetBkMode */
442 X11DRV_SetBoundsRect, /* pSetBoundsRect */
443 X11DRV_SetDCBrushColor, /* pSetDCBrushColor */
444 X11DRV_SetDCPenColor, /* pSetDCPenColor */
445 NULL, /* pSetDIBitsToDevice */
446 X11DRV_SetDeviceClipping, /* pSetDeviceClipping */
447 X11DRV_SetDeviceGammaRamp, /* pSetDeviceGammaRamp */
448 NULL, /* pSetLayout */
449 NULL, /* pSetMapMode */
450 NULL, /* pSetMapperFlags */
451 X11DRV_SetPixel, /* pSetPixel */
452 NULL, /* pSetPolyFillMode */
453 NULL, /* pSetROP2 */
454 NULL, /* pSetRelAbs */
455 NULL, /* pSetStretchBltMode */
456 NULL, /* pSetTextAlign */
457 NULL, /* pSetTextCharacterExtra */
458 NULL, /* pSetTextColor */
459 NULL, /* pSetTextJustification */
460 NULL, /* pSetViewportExt */
461 NULL, /* pSetViewportOrg */
462 NULL, /* pSetWindowExt */
463 NULL, /* pSetWindowOrg */
464 NULL, /* pSetWorldTransform */
465 NULL, /* pStartDoc */
466 NULL, /* pStartPage */
467 X11DRV_StretchBlt, /* pStretchBlt */
468 NULL, /* pStretchDIBits */
469 X11DRV_StrokeAndFillPath, /* pStrokeAndFillPath */
470 X11DRV_StrokePath, /* pStrokePath */
471 X11DRV_UnrealizePalette, /* pUnrealizePalette */
472 NULL, /* pWidenPath */
473 X11DRV_wine_get_wgl_driver, /* wine_get_wgl_driver */
474 X11DRV_wine_get_vulkan_driver, /* wine_get_vulkan_driver */
475 GDI_PRIORITY_GRAPHICS_DRV /* priority */
479 /******************************************************************************
480 * X11DRV_get_gdi_driver
482 const struct gdi_dc_funcs * CDECL X11DRV_get_gdi_driver( unsigned int version )
484 if (version != WINE_GDI_DRIVER_VERSION)
486 ERR( "version mismatch, gdi32 wants %u but winex11 has %u\n", version, WINE_GDI_DRIVER_VERSION );
487 return NULL;
489 return &x11drv_funcs;