msi: Don't defer custom actions in the UI sequence if they match the currently runnin...
[wine/multimedia.git] / dlls / winex11.drv / init.c
blob8f8ff09510accc024250086e0d7c2cc701b8fd7c
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 /* a few dynamic device caps */
37 static int log_pixels_x; /* pixels per logical inch in x direction */
38 static int log_pixels_y; /* pixels per logical inch in y direction */
39 static int horz_size; /* horz. size of screen in millimeters */
40 static int vert_size; /* vert. size of screen in millimeters */
41 static int palette_size;
42 static int device_init_done;
44 static Pixmap stock_bitmap_pixmap; /* phys bitmap for the default stock bitmap */
46 static const WCHAR dpi_key_name[] = {'S','o','f','t','w','a','r','e','\\','F','o','n','t','s','\0'};
47 static const WCHAR dpi_value_name[] = {'L','o','g','P','i','x','e','l','s','\0'};
49 static const struct gdi_dc_funcs x11drv_funcs;
50 static const struct gdi_dc_funcs *xrender_funcs;
52 /******************************************************************************
53 * get_dpi
55 * get the dpi from the registry
57 static DWORD get_dpi( void )
59 DWORD dpi = 96;
60 HKEY hkey;
62 if (RegOpenKeyW(HKEY_CURRENT_CONFIG, dpi_key_name, &hkey) == ERROR_SUCCESS)
64 DWORD type, size, new_dpi;
66 size = sizeof(new_dpi);
67 if(RegQueryValueExW(hkey, dpi_value_name, NULL, &type, (void *)&new_dpi, &size) == ERROR_SUCCESS)
69 if(type == REG_DWORD && new_dpi != 0)
70 dpi = new_dpi;
72 RegCloseKey(hkey);
74 return dpi;
77 /**********************************************************************
78 * device_init
80 * Perform initializations needed upon creation of the first device.
82 static void device_init(void)
84 device_init_done = TRUE;
86 /* Initialize XRender */
87 xrender_funcs = X11DRV_XRender_Init();
89 /* Init Xcursor */
90 X11DRV_Xcursor_Init();
92 palette_size = X11DRV_PALETTE_Init();
94 stock_bitmap_pixmap = XCreatePixmap( gdi_display, root_window, 1, 1, 1 );
96 /* Initialize device caps */
97 log_pixels_x = log_pixels_y = get_dpi();
98 horz_size = MulDiv( screen_width, 254, log_pixels_x * 10 );
99 vert_size = MulDiv( screen_height, 254, log_pixels_y * 10 );
103 static X11DRV_PDEVICE *create_x11_physdev( Drawable drawable )
105 X11DRV_PDEVICE *physDev;
107 if (!device_init_done) device_init();
109 if (!(physDev = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*physDev) ))) return NULL;
111 physDev->drawable = drawable;
112 physDev->gc = XCreateGC( gdi_display, drawable, 0, NULL );
113 XSetGraphicsExposures( gdi_display, physDev->gc, False );
114 XSetSubwindowMode( gdi_display, physDev->gc, IncludeInferiors );
115 XFlush( gdi_display );
116 return physDev;
119 /**********************************************************************
120 * X11DRV_CreateDC
122 static BOOL X11DRV_CreateDC( PHYSDEV *pdev, LPCWSTR driver, LPCWSTR device,
123 LPCWSTR output, const DEVMODEW* initData )
125 X11DRV_PDEVICE *physDev = create_x11_physdev( root_window );
127 if (!physDev) return FALSE;
129 physDev->depth = default_visual.depth;
130 physDev->color_shifts = &X11DRV_PALETTE_default_shifts;
131 SetRect( &physDev->dc_rect, 0, 0, virtual_screen_rect.right - virtual_screen_rect.left,
132 virtual_screen_rect.bottom - virtual_screen_rect.top );
133 push_dc_driver( pdev, &physDev->dev, &x11drv_funcs );
134 if (xrender_funcs && !xrender_funcs->pCreateDC( pdev, driver, device, output, initData )) return FALSE;
135 return TRUE;
139 /**********************************************************************
140 * X11DRV_CreateCompatibleDC
142 static BOOL X11DRV_CreateCompatibleDC( PHYSDEV orig, PHYSDEV *pdev )
144 X11DRV_PDEVICE *physDev = create_x11_physdev( stock_bitmap_pixmap );
146 if (!physDev) return FALSE;
148 physDev->depth = 1;
149 SetRect( &physDev->dc_rect, 0, 0, 1, 1 );
150 push_dc_driver( pdev, &physDev->dev, &x11drv_funcs );
151 if (orig) return TRUE; /* we already went through Xrender if we have an orig device */
152 if (xrender_funcs && !xrender_funcs->pCreateCompatibleDC( NULL, pdev )) return FALSE;
153 return TRUE;
157 /**********************************************************************
158 * X11DRV_DeleteDC
160 static BOOL X11DRV_DeleteDC( PHYSDEV dev )
162 X11DRV_PDEVICE *physDev = get_x11drv_dev( dev );
164 XFreeGC( gdi_display, physDev->gc );
165 HeapFree( GetProcessHeap(), 0, physDev );
166 return TRUE;
170 void add_device_bounds( X11DRV_PDEVICE *dev, const RECT *rect )
172 RECT rc;
174 if (!dev->bounds) return;
175 if (dev->region && GetRgnBox( dev->region, &rc ))
177 if (IntersectRect( &rc, &rc, rect )) add_bounds_rect( dev->bounds, &rc );
179 else add_bounds_rect( dev->bounds, rect );
182 /***********************************************************************
183 * X11DRV_SetBoundsRect
185 static UINT X11DRV_SetBoundsRect( PHYSDEV dev, RECT *rect, UINT flags )
187 X11DRV_PDEVICE *pdev = get_x11drv_dev( dev );
189 if (flags & DCB_DISABLE) pdev->bounds = NULL;
190 else if (flags & DCB_ENABLE) pdev->bounds = rect;
191 return DCB_RESET; /* we don't have device-specific bounds */
195 /***********************************************************************
196 * GetDeviceCaps (X11DRV.@)
198 static INT X11DRV_GetDeviceCaps( PHYSDEV dev, INT cap )
200 switch(cap)
202 case DRIVERVERSION:
203 return 0x300;
204 case TECHNOLOGY:
205 return DT_RASDISPLAY;
206 case HORZSIZE:
207 return horz_size;
208 case VERTSIZE:
209 return vert_size;
210 case HORZRES:
211 return screen_width;
212 case VERTRES:
213 return screen_height;
214 case DESKTOPHORZRES:
215 return virtual_screen_rect.right - virtual_screen_rect.left;
216 case DESKTOPVERTRES:
217 return virtual_screen_rect.bottom - virtual_screen_rect.top;
218 case BITSPIXEL:
219 return screen_bpp;
220 case PLANES:
221 return 1;
222 case NUMBRUSHES:
223 return -1;
224 case NUMPENS:
225 return -1;
226 case NUMMARKERS:
227 return 0;
228 case NUMFONTS:
229 return 0;
230 case NUMCOLORS:
231 /* MSDN: Number of entries in the device's color table, if the device has
232 * a color depth of no more than 8 bits per pixel.For devices with greater
233 * color depths, -1 is returned. */
234 return (default_visual.depth > 8) ? -1 : (1 << default_visual.depth);
235 case PDEVICESIZE:
236 return sizeof(X11DRV_PDEVICE);
237 case CURVECAPS:
238 return (CC_CIRCLES | CC_PIE | CC_CHORD | CC_ELLIPSES | CC_WIDE |
239 CC_STYLED | CC_WIDESTYLED | CC_INTERIORS | CC_ROUNDRECT);
240 case LINECAPS:
241 return (LC_POLYLINE | LC_MARKER | LC_POLYMARKER | LC_WIDE |
242 LC_STYLED | LC_WIDESTYLED | LC_INTERIORS);
243 case POLYGONALCAPS:
244 return (PC_POLYGON | PC_RECTANGLE | PC_WINDPOLYGON | PC_SCANLINE |
245 PC_WIDE | PC_STYLED | PC_WIDESTYLED | PC_INTERIORS);
246 case TEXTCAPS:
247 return (TC_OP_CHARACTER | TC_OP_STROKE | TC_CP_STROKE |
248 TC_CR_ANY | TC_SF_X_YINDEP | TC_SA_DOUBLE | TC_SA_INTEGER |
249 TC_SA_CONTIN | TC_UA_ABLE | TC_SO_ABLE | TC_RA_ABLE | TC_VA_ABLE);
250 case CLIPCAPS:
251 return CP_REGION;
252 case COLORRES:
253 /* The observed correspondence between BITSPIXEL and COLORRES is:
254 * BITSPIXEL: 8 -> COLORRES: 18
255 * BITSPIXEL: 16 -> COLORRES: 16
256 * BITSPIXEL: 24 -> COLORRES: 24
257 * BITSPIXEL: 32 -> COLORRES: 24 */
258 return (screen_bpp <= 8) ? 18 : min( 24, screen_bpp );
259 case RASTERCAPS:
260 return (RC_BITBLT | RC_BANDING | RC_SCALING | RC_BITMAP64 | RC_DI_BITMAP |
261 RC_DIBTODEV | RC_BIGFONT | RC_STRETCHBLT | RC_STRETCHDIB | RC_DEVBITS |
262 (palette_size ? RC_PALETTE : 0));
263 case SHADEBLENDCAPS:
264 return (SB_GRAD_RECT | SB_GRAD_TRI | SB_CONST_ALPHA | SB_PIXEL_ALPHA);
265 case ASPECTX:
266 case ASPECTY:
267 return 36;
268 case ASPECTXY:
269 return 51;
270 case LOGPIXELSX:
271 return log_pixels_x;
272 case LOGPIXELSY:
273 return log_pixels_y;
274 case CAPS1:
275 FIXME("(%p): CAPS1 is unimplemented, will return 0\n", dev->hdc );
276 /* please see wingdi.h for the possible bit-flag values that need
277 to be returned. */
278 return 0;
279 case SIZEPALETTE:
280 return palette_size;
281 case NUMRESERVED:
282 case PHYSICALWIDTH:
283 case PHYSICALHEIGHT:
284 case PHYSICALOFFSETX:
285 case PHYSICALOFFSETY:
286 case SCALINGFACTORX:
287 case SCALINGFACTORY:
288 case VREFRESH:
289 case BLTALIGNMENT:
290 return 0;
291 default:
292 FIXME("(%p): unsupported capability %d, will return 0\n", dev->hdc, cap );
293 return 0;
298 /***********************************************************************
299 * SelectFont
301 static HFONT X11DRV_SelectFont( PHYSDEV dev, HFONT hfont, UINT *aa_flags )
303 if (default_visual.depth <= 8) *aa_flags = GGO_BITMAP; /* no anti-aliasing on <= 8bpp */
304 dev = GET_NEXT_PHYSDEV( dev, pSelectFont );
305 return dev->funcs->pSelectFont( dev, hfont, aa_flags );
308 /**********************************************************************
309 * ExtEscape (X11DRV.@)
311 static INT X11DRV_ExtEscape( PHYSDEV dev, INT escape, INT in_count, LPCVOID in_data,
312 INT out_count, LPVOID out_data )
314 X11DRV_PDEVICE *physDev = get_x11drv_dev( dev );
316 switch(escape)
318 case QUERYESCSUPPORT:
319 if (in_data && in_count >= sizeof(DWORD))
321 switch (*(const INT *)in_data)
323 case X11DRV_ESCAPE:
324 return TRUE;
327 break;
329 case X11DRV_ESCAPE:
330 if (in_data && in_count >= sizeof(enum x11drv_escape_codes))
332 switch(*(const enum x11drv_escape_codes *)in_data)
334 case X11DRV_SET_DRAWABLE:
335 if (in_count >= sizeof(struct x11drv_escape_set_drawable))
337 const struct x11drv_escape_set_drawable *data = in_data;
338 physDev->dc_rect = data->dc_rect;
339 physDev->drawable = data->drawable;
340 XFreeGC( gdi_display, physDev->gc );
341 physDev->gc = XCreateGC( gdi_display, physDev->drawable, 0, NULL );
342 XSetGraphicsExposures( gdi_display, physDev->gc, False );
343 XSetSubwindowMode( gdi_display, physDev->gc, data->mode );
344 TRACE( "SET_DRAWABLE hdc %p drawable %lx dc_rect %s\n",
345 dev->hdc, physDev->drawable, wine_dbgstr_rect(&physDev->dc_rect) );
346 return TRUE;
348 break;
349 case X11DRV_GET_DRAWABLE:
350 if (out_count >= sizeof(struct x11drv_escape_get_drawable))
352 struct x11drv_escape_get_drawable *data = out_data;
353 data->drawable = physDev->drawable;
354 return TRUE;
356 break;
357 case X11DRV_FLUSH_GL_DRAWABLE:
358 if (in_count >= sizeof(struct x11drv_escape_flush_gl_drawable))
360 const struct x11drv_escape_flush_gl_drawable *data = in_data;
361 RECT rect = physDev->dc_rect;
363 OffsetRect( &rect, -physDev->dc_rect.left, -physDev->dc_rect.top );
364 /* The GL drawable may be lagged behind if we don't flush first, so
365 * flush the display make sure we copy up-to-date data */
366 XFlush( gdi_display );
367 XSetFunction( gdi_display, physDev->gc, GXcopy );
368 XCopyArea( gdi_display, data->gl_drawable, physDev->drawable, physDev->gc,
369 0, 0, rect.right, rect.bottom,
370 physDev->dc_rect.left, physDev->dc_rect.top );
371 add_device_bounds( physDev, &rect );
372 return TRUE;
374 break;
375 case X11DRV_START_EXPOSURES:
376 XSetGraphicsExposures( gdi_display, physDev->gc, True );
377 physDev->exposures = 0;
378 return TRUE;
379 case X11DRV_END_EXPOSURES:
380 if (out_count >= sizeof(HRGN))
382 HRGN hrgn = 0, tmp = 0;
384 XSetGraphicsExposures( gdi_display, physDev->gc, False );
385 if (physDev->exposures)
387 for (;;)
389 XEvent event;
391 XWindowEvent( gdi_display, physDev->drawable, ~0, &event );
392 if (event.type == NoExpose) break;
393 if (event.type == GraphicsExpose)
395 RECT rect;
397 rect.left = event.xgraphicsexpose.x - physDev->dc_rect.left;
398 rect.top = event.xgraphicsexpose.y - physDev->dc_rect.top;
399 rect.right = rect.left + event.xgraphicsexpose.width;
400 rect.bottom = rect.top + event.xgraphicsexpose.height;
401 if (GetLayout( dev->hdc ) & LAYOUT_RTL)
402 mirror_rect( &physDev->dc_rect, &rect );
404 TRACE( "got %s count %d\n", wine_dbgstr_rect(&rect),
405 event.xgraphicsexpose.count );
407 if (!tmp) tmp = CreateRectRgnIndirect( &rect );
408 else SetRectRgn( tmp, rect.left, rect.top, rect.right, rect.bottom );
409 if (hrgn) CombineRgn( hrgn, hrgn, tmp, RGN_OR );
410 else
412 hrgn = tmp;
413 tmp = 0;
415 if (!event.xgraphicsexpose.count) break;
417 else
419 ERR( "got unexpected event %d\n", event.type );
420 break;
423 if (tmp) DeleteObject( tmp );
425 *(HRGN *)out_data = hrgn;
426 return TRUE;
428 break;
429 default:
430 break;
433 break;
435 return 0;
438 /**********************************************************************
439 * X11DRV_wine_get_wgl_driver
441 static struct opengl_funcs * X11DRV_wine_get_wgl_driver( PHYSDEV dev, UINT version )
443 struct opengl_funcs *ret;
445 if (!(ret = get_glx_driver( version )))
447 dev = GET_NEXT_PHYSDEV( dev, wine_get_wgl_driver );
448 ret = dev->funcs->wine_get_wgl_driver( dev, version );
450 return ret;
454 static const struct gdi_dc_funcs x11drv_funcs =
456 NULL, /* pAbortDoc */
457 NULL, /* pAbortPath */
458 NULL, /* pAlphaBlend */
459 NULL, /* pAngleArc */
460 X11DRV_Arc, /* pArc */
461 NULL, /* pArcTo */
462 NULL, /* pBeginPath */
463 NULL, /* pBlendImage */
464 X11DRV_Chord, /* pChord */
465 NULL, /* pCloseFigure */
466 X11DRV_CreateCompatibleDC, /* pCreateCompatibleDC */
467 X11DRV_CreateDC, /* pCreateDC */
468 X11DRV_DeleteDC, /* pDeleteDC */
469 NULL, /* pDeleteObject */
470 NULL, /* pDeviceCapabilities */
471 X11DRV_Ellipse, /* pEllipse */
472 NULL, /* pEndDoc */
473 NULL, /* pEndPage */
474 NULL, /* pEndPath */
475 NULL, /* pEnumFonts */
476 X11DRV_EnumICMProfiles, /* pEnumICMProfiles */
477 NULL, /* pExcludeClipRect */
478 NULL, /* pExtDeviceMode */
479 X11DRV_ExtEscape, /* pExtEscape */
480 X11DRV_ExtFloodFill, /* pExtFloodFill */
481 NULL, /* pExtSelectClipRgn */
482 NULL, /* pExtTextOut */
483 NULL, /* pFillPath */
484 NULL, /* pFillRgn */
485 NULL, /* pFlattenPath */
486 NULL, /* pFontIsLinked */
487 NULL, /* pFrameRgn */
488 NULL, /* pGdiComment */
489 NULL, /* pGdiRealizationInfo */
490 NULL, /* pGetBoundsRect */
491 NULL, /* pGetCharABCWidths */
492 NULL, /* pGetCharABCWidthsI */
493 NULL, /* pGetCharWidth */
494 X11DRV_GetDeviceCaps, /* pGetDeviceCaps */
495 X11DRV_GetDeviceGammaRamp, /* pGetDeviceGammaRamp */
496 NULL, /* pGetFontData */
497 NULL, /* pGetFontUnicodeRanges */
498 NULL, /* pGetGlyphIndices */
499 NULL, /* pGetGlyphOutline */
500 X11DRV_GetICMProfile, /* pGetICMProfile */
501 X11DRV_GetImage, /* pGetImage */
502 NULL, /* pGetKerningPairs */
503 X11DRV_GetNearestColor, /* pGetNearestColor */
504 NULL, /* pGetOutlineTextMetrics */
505 NULL, /* pGetPixel */
506 X11DRV_GetSystemPaletteEntries, /* pGetSystemPaletteEntries */
507 NULL, /* pGetTextCharsetInfo */
508 NULL, /* pGetTextExtentExPoint */
509 NULL, /* pGetTextExtentExPointI */
510 NULL, /* pGetTextFace */
511 NULL, /* pGetTextMetrics */
512 X11DRV_GradientFill, /* pGradientFill */
513 NULL, /* pIntersectClipRect */
514 NULL, /* pInvertRgn */
515 X11DRV_LineTo, /* pLineTo */
516 NULL, /* pModifyWorldTransform */
517 NULL, /* pMoveTo */
518 NULL, /* pOffsetClipRgn */
519 NULL, /* pOffsetViewportOrg */
520 NULL, /* pOffsetWindowOrg */
521 X11DRV_PaintRgn, /* pPaintRgn */
522 X11DRV_PatBlt, /* pPatBlt */
523 X11DRV_Pie, /* pPie */
524 NULL, /* pPolyBezier */
525 NULL, /* pPolyBezierTo */
526 NULL, /* pPolyDraw */
527 X11DRV_PolyPolygon, /* pPolyPolygon */
528 X11DRV_PolyPolyline, /* pPolyPolyline */
529 X11DRV_Polygon, /* pPolygon */
530 NULL, /* pPolyline */
531 NULL, /* pPolylineTo */
532 X11DRV_PutImage, /* pPutImage */
533 X11DRV_RealizeDefaultPalette, /* pRealizeDefaultPalette */
534 X11DRV_RealizePalette, /* pRealizePalette */
535 X11DRV_Rectangle, /* pRectangle */
536 NULL, /* pResetDC */
537 NULL, /* pRestoreDC */
538 X11DRV_RoundRect, /* pRoundRect */
539 NULL, /* pSaveDC */
540 NULL, /* pScaleViewportExt */
541 NULL, /* pScaleWindowExt */
542 NULL, /* pSelectBitmap */
543 X11DRV_SelectBrush, /* pSelectBrush */
544 NULL, /* pSelectClipPath */
545 X11DRV_SelectFont, /* pSelectFont */
546 NULL, /* pSelectPalette */
547 X11DRV_SelectPen, /* pSelectPen */
548 NULL, /* pSetArcDirection */
549 NULL, /* pSetBkColor */
550 NULL, /* pSetBkMode */
551 X11DRV_SetBoundsRect, /* pSetBoundsRect */
552 X11DRV_SetDCBrushColor, /* pSetDCBrushColor */
553 X11DRV_SetDCPenColor, /* pSetDCPenColor */
554 NULL, /* pSetDIBitsToDevice */
555 X11DRV_SetDeviceClipping, /* pSetDeviceClipping */
556 X11DRV_SetDeviceGammaRamp, /* pSetDeviceGammaRamp */
557 NULL, /* pSetLayout */
558 NULL, /* pSetMapMode */
559 NULL, /* pSetMapperFlags */
560 X11DRV_SetPixel, /* pSetPixel */
561 NULL, /* pSetPolyFillMode */
562 NULL, /* pSetROP2 */
563 NULL, /* pSetRelAbs */
564 NULL, /* pSetStretchBltMode */
565 NULL, /* pSetTextAlign */
566 NULL, /* pSetTextCharacterExtra */
567 NULL, /* pSetTextColor */
568 NULL, /* pSetTextJustification */
569 NULL, /* pSetViewportExt */
570 NULL, /* pSetViewportOrg */
571 NULL, /* pSetWindowExt */
572 NULL, /* pSetWindowOrg */
573 NULL, /* pSetWorldTransform */
574 NULL, /* pStartDoc */
575 NULL, /* pStartPage */
576 X11DRV_StretchBlt, /* pStretchBlt */
577 NULL, /* pStretchDIBits */
578 NULL, /* pStrokeAndFillPath */
579 NULL, /* pStrokePath */
580 X11DRV_UnrealizePalette, /* pUnrealizePalette */
581 NULL, /* pWidenPath */
582 X11DRV_wine_get_wgl_driver, /* wine_get_wgl_driver */
583 GDI_PRIORITY_GRAPHICS_DRV /* priority */
587 /******************************************************************************
588 * X11DRV_get_gdi_driver
590 const struct gdi_dc_funcs * CDECL X11DRV_get_gdi_driver( unsigned int version )
592 if (version != WINE_GDI_DRIVER_VERSION)
594 ERR( "version mismatch, gdi32 wants %u but winex11 has %u\n", version, WINE_GDI_DRIVER_VERSION );
595 return NULL;
597 return &x11drv_funcs;