wined3d: Pass a wined3d_device_context to wined3d_cs_emit_blt_sub_resource().
[wine/zf.git] / dlls / winex11.drv / init.c
blobd070c0f1171fce03e13236f993d8866726e2907b
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 CDECL 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 CDECL 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 CDECL 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 CDECL 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 CDECL 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 CDECL 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 CDECL 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 * CDECL 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 * CDECL 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 NULL, /* pGetCharWidthInfo */
385 X11DRV_GetDeviceCaps, /* pGetDeviceCaps */
386 X11DRV_GetDeviceGammaRamp, /* pGetDeviceGammaRamp */
387 NULL, /* pGetFontData */
388 NULL, /* pGetFontRealizationInfo */
389 NULL, /* pGetFontUnicodeRanges */
390 NULL, /* pGetGlyphIndices */
391 NULL, /* pGetGlyphOutline */
392 X11DRV_GetICMProfile, /* pGetICMProfile */
393 X11DRV_GetImage, /* pGetImage */
394 NULL, /* pGetKerningPairs */
395 X11DRV_GetNearestColor, /* pGetNearestColor */
396 NULL, /* pGetOutlineTextMetrics */
397 NULL, /* pGetPixel */
398 X11DRV_GetSystemPaletteEntries, /* pGetSystemPaletteEntries */
399 NULL, /* pGetTextCharsetInfo */
400 NULL, /* pGetTextExtentExPoint */
401 NULL, /* pGetTextExtentExPointI */
402 NULL, /* pGetTextFace */
403 NULL, /* pGetTextMetrics */
404 X11DRV_GradientFill, /* pGradientFill */
405 NULL, /* pIntersectClipRect */
406 NULL, /* pInvertRgn */
407 X11DRV_LineTo, /* pLineTo */
408 NULL, /* pModifyWorldTransform */
409 NULL, /* pMoveTo */
410 NULL, /* pOffsetClipRgn */
411 NULL, /* pOffsetViewportOrg */
412 NULL, /* pOffsetWindowOrg */
413 X11DRV_PaintRgn, /* pPaintRgn */
414 X11DRV_PatBlt, /* pPatBlt */
415 X11DRV_Pie, /* pPie */
416 NULL, /* pPolyBezier */
417 NULL, /* pPolyBezierTo */
418 NULL, /* pPolyDraw */
419 X11DRV_PolyPolygon, /* pPolyPolygon */
420 X11DRV_PolyPolyline, /* pPolyPolyline */
421 X11DRV_Polygon, /* pPolygon */
422 NULL, /* pPolyline */
423 NULL, /* pPolylineTo */
424 X11DRV_PutImage, /* pPutImage */
425 X11DRV_RealizeDefaultPalette, /* pRealizeDefaultPalette */
426 X11DRV_RealizePalette, /* pRealizePalette */
427 X11DRV_Rectangle, /* pRectangle */
428 NULL, /* pResetDC */
429 NULL, /* pRestoreDC */
430 X11DRV_RoundRect, /* pRoundRect */
431 NULL, /* pSaveDC */
432 NULL, /* pScaleViewportExt */
433 NULL, /* pScaleWindowExt */
434 NULL, /* pSelectBitmap */
435 X11DRV_SelectBrush, /* pSelectBrush */
436 NULL, /* pSelectClipPath */
437 X11DRV_SelectFont, /* pSelectFont */
438 NULL, /* pSelectPalette */
439 X11DRV_SelectPen, /* pSelectPen */
440 NULL, /* pSetArcDirection */
441 NULL, /* pSetBkColor */
442 NULL, /* pSetBkMode */
443 X11DRV_SetBoundsRect, /* pSetBoundsRect */
444 X11DRV_SetDCBrushColor, /* pSetDCBrushColor */
445 X11DRV_SetDCPenColor, /* pSetDCPenColor */
446 NULL, /* pSetDIBitsToDevice */
447 X11DRV_SetDeviceClipping, /* pSetDeviceClipping */
448 X11DRV_SetDeviceGammaRamp, /* pSetDeviceGammaRamp */
449 NULL, /* pSetLayout */
450 NULL, /* pSetMapMode */
451 NULL, /* pSetMapperFlags */
452 X11DRV_SetPixel, /* pSetPixel */
453 NULL, /* pSetPolyFillMode */
454 NULL, /* pSetROP2 */
455 NULL, /* pSetRelAbs */
456 NULL, /* pSetStretchBltMode */
457 NULL, /* pSetTextAlign */
458 NULL, /* pSetTextCharacterExtra */
459 NULL, /* pSetTextColor */
460 NULL, /* pSetTextJustification */
461 NULL, /* pSetViewportExt */
462 NULL, /* pSetViewportOrg */
463 NULL, /* pSetWindowExt */
464 NULL, /* pSetWindowOrg */
465 NULL, /* pSetWorldTransform */
466 NULL, /* pStartDoc */
467 NULL, /* pStartPage */
468 X11DRV_StretchBlt, /* pStretchBlt */
469 NULL, /* pStretchDIBits */
470 X11DRV_StrokeAndFillPath, /* pStrokeAndFillPath */
471 X11DRV_StrokePath, /* pStrokePath */
472 X11DRV_UnrealizePalette, /* pUnrealizePalette */
473 NULL, /* pWidenPath */
474 X11DRV_D3DKMTCheckVidPnExclusiveOwnership, /* pD3DKMTCheckVidPnExclusiveOwnership */
475 X11DRV_D3DKMTSetVidPnSourceOwner, /* pD3DKMTSetVidPnSourceOwner */
476 X11DRV_wine_get_wgl_driver, /* wine_get_wgl_driver */
477 X11DRV_wine_get_vulkan_driver, /* wine_get_vulkan_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;