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
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(x11drv
);
35 Display
*gdi_display
; /* display to use for all GDI functions */
37 /* a few dynamic device caps */
38 static int log_pixels_x
; /* pixels per logical inch in x direction */
39 static int log_pixels_y
; /* pixels per logical inch in y direction */
40 static int horz_size
; /* horz. size of screen in millimeters */
41 static int vert_size
; /* vert. size of screen in millimeters */
42 static int palette_size
;
43 static int device_init_done
;
45 static Pixmap stock_bitmap_pixmap
; /* phys bitmap for the default stock bitmap */
47 static const WCHAR dpi_key_name
[] = {'S','o','f','t','w','a','r','e','\\','F','o','n','t','s','\0'};
48 static const WCHAR dpi_value_name
[] = {'L','o','g','P','i','x','e','l','s','\0'};
50 static const struct gdi_dc_funcs x11drv_funcs
;
51 static const struct gdi_dc_funcs
*xrender_funcs
;
53 /******************************************************************************
56 * get the dpi from the registry
58 static DWORD
get_dpi( void )
63 if (RegOpenKeyW(HKEY_CURRENT_CONFIG
, dpi_key_name
, &hkey
) == ERROR_SUCCESS
)
65 DWORD type
, size
, new_dpi
;
67 size
= sizeof(new_dpi
);
68 if(RegQueryValueExW(hkey
, dpi_value_name
, NULL
, &type
, (void *)&new_dpi
, &size
) == ERROR_SUCCESS
)
70 if(type
== REG_DWORD
&& new_dpi
!= 0)
78 /**********************************************************************
81 * Perform initializations needed upon creation of the first device.
83 static void device_init(void)
85 device_init_done
= TRUE
;
87 /* Initialize XRender */
88 xrender_funcs
= X11DRV_XRender_Init();
91 X11DRV_Xcursor_Init();
93 palette_size
= X11DRV_PALETTE_Init();
96 stock_bitmap_pixmap
= XCreatePixmap( gdi_display
, root_window
, 1, 1, 1 );
99 /* Initialize device caps */
100 log_pixels_x
= log_pixels_y
= get_dpi();
101 horz_size
= MulDiv( screen_width
, 254, log_pixels_x
* 10 );
102 vert_size
= MulDiv( screen_height
, 254, log_pixels_y
* 10 );
105 /**********************************************************************
106 * X11DRV_GDI_Finalize
108 void X11DRV_GDI_Finalize(void)
110 X11DRV_PALETTE_Cleanup();
111 /* don't bother to close the display, it often triggers X bugs */
112 /* XCloseDisplay( gdi_display ); */
116 static X11DRV_PDEVICE
*create_x11_physdev( Drawable drawable
)
118 X11DRV_PDEVICE
*physDev
;
120 if (!device_init_done
) device_init();
122 if (!(physDev
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*physDev
) ))) return NULL
;
125 physDev
->drawable
= drawable
;
126 physDev
->gc
= XCreateGC( gdi_display
, drawable
, 0, NULL
);
127 XSetGraphicsExposures( gdi_display
, physDev
->gc
, False
);
128 XSetSubwindowMode( gdi_display
, physDev
->gc
, IncludeInferiors
);
129 XFlush( gdi_display
);
134 /**********************************************************************
137 static BOOL
X11DRV_CreateDC( PHYSDEV
*pdev
, LPCWSTR driver
, LPCWSTR device
,
138 LPCWSTR output
, const DEVMODEW
* initData
)
140 const struct gdi_dc_funcs
*glx_funcs
= get_glx_driver();
141 X11DRV_PDEVICE
*physDev
= create_x11_physdev( root_window
);
143 if (!physDev
) return FALSE
;
145 physDev
->depth
= screen_depth
;
146 physDev
->color_shifts
= &X11DRV_PALETTE_default_shifts
;
147 physDev
->drawable_rect
= virtual_screen_rect
;
148 SetRect( &physDev
->dc_rect
, 0, 0, virtual_screen_rect
.right
- virtual_screen_rect
.left
,
149 virtual_screen_rect
.bottom
- virtual_screen_rect
.top
);
150 push_dc_driver( pdev
, &physDev
->dev
, &x11drv_funcs
);
151 if (xrender_funcs
&& !xrender_funcs
->pCreateDC( pdev
, driver
, device
, output
, initData
)) return FALSE
;
152 if (glx_funcs
&& !glx_funcs
->pCreateDC( pdev
, driver
, device
, output
, initData
)) return FALSE
;
157 /**********************************************************************
158 * X11DRV_CreateCompatibleDC
160 static BOOL
X11DRV_CreateCompatibleDC( PHYSDEV orig
, PHYSDEV
*pdev
)
162 const struct gdi_dc_funcs
*glx_funcs
= get_glx_driver();
163 X11DRV_PDEVICE
*physDev
= create_x11_physdev( stock_bitmap_pixmap
);
165 if (!physDev
) return FALSE
;
168 SetRect( &physDev
->drawable_rect
, 0, 0, 1, 1 );
169 physDev
->dc_rect
= physDev
->drawable_rect
;
170 push_dc_driver( pdev
, &physDev
->dev
, &x11drv_funcs
);
171 if (orig
) return TRUE
; /* we already went through Xrender if we have an orig device */
172 if (xrender_funcs
&& !xrender_funcs
->pCreateCompatibleDC( NULL
, pdev
)) return FALSE
;
173 if (glx_funcs
&& !glx_funcs
->pCreateCompatibleDC( NULL
, pdev
)) return FALSE
;
178 /**********************************************************************
181 static BOOL
X11DRV_DeleteDC( PHYSDEV dev
)
183 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
186 XFreeGC( gdi_display
, physDev
->gc
);
188 HeapFree( GetProcessHeap(), 0, physDev
);
193 void add_device_bounds( X11DRV_PDEVICE
*dev
, const RECT
*rect
)
197 if (!dev
->bounds
) return;
198 if (dev
->region
&& GetRgnBox( dev
->region
, &rc
))
200 if (IntersectRect( &rc
, &rc
, rect
)) add_bounds_rect( dev
->bounds
, &rc
);
202 else add_bounds_rect( dev
->bounds
, rect
);
205 /***********************************************************************
206 * X11DRV_SetBoundsRect
208 static UINT
X11DRV_SetBoundsRect( PHYSDEV dev
, RECT
*rect
, UINT flags
)
210 X11DRV_PDEVICE
*pdev
= get_x11drv_dev( dev
);
212 if (flags
& DCB_DISABLE
) pdev
->bounds
= NULL
;
213 else if (flags
& DCB_ENABLE
) pdev
->bounds
= rect
;
214 return DCB_RESET
; /* we don't have device-specific bounds */
218 /***********************************************************************
219 * GetDeviceCaps (X11DRV.@)
221 static INT
X11DRV_GetDeviceCaps( PHYSDEV dev
, INT cap
)
228 return DT_RASDISPLAY
;
236 return screen_height
;
238 return virtual_screen_rect
.right
- virtual_screen_rect
.left
;
240 return virtual_screen_rect
.bottom
- virtual_screen_rect
.top
;
254 /* MSDN: Number of entries in the device's color table, if the device has
255 * a color depth of no more than 8 bits per pixel.For devices with greater
256 * color depths, -1 is returned. */
257 return (screen_depth
> 8) ? -1 : (1 << screen_depth
);
259 return sizeof(X11DRV_PDEVICE
);
261 return (CC_CIRCLES
| CC_PIE
| CC_CHORD
| CC_ELLIPSES
| CC_WIDE
|
262 CC_STYLED
| CC_WIDESTYLED
| CC_INTERIORS
| CC_ROUNDRECT
);
264 return (LC_POLYLINE
| LC_MARKER
| LC_POLYMARKER
| LC_WIDE
|
265 LC_STYLED
| LC_WIDESTYLED
| LC_INTERIORS
);
267 return (PC_POLYGON
| PC_RECTANGLE
| PC_WINDPOLYGON
| PC_SCANLINE
|
268 PC_WIDE
| PC_STYLED
| PC_WIDESTYLED
| PC_INTERIORS
);
270 return (TC_OP_CHARACTER
| TC_OP_STROKE
| TC_CP_STROKE
|
271 TC_CR_ANY
| TC_SF_X_YINDEP
| TC_SA_DOUBLE
| TC_SA_INTEGER
|
272 TC_SA_CONTIN
| TC_UA_ABLE
| TC_SO_ABLE
| TC_RA_ABLE
| TC_VA_ABLE
);
276 /* The observed correspondence between BITSPIXEL and COLORRES is:
277 * BITSPIXEL: 8 -> COLORRES: 18
278 * BITSPIXEL: 16 -> COLORRES: 16
279 * BITSPIXEL: 24 -> COLORRES: 24
280 * BITSPIXEL: 32 -> COLORRES: 24 */
281 return (screen_bpp
<= 8) ? 18 : min( 24, screen_bpp
);
283 return (RC_BITBLT
| RC_BANDING
| RC_SCALING
| RC_BITMAP64
| RC_DI_BITMAP
|
284 RC_DIBTODEV
| RC_BIGFONT
| RC_STRETCHBLT
| RC_STRETCHDIB
| RC_DEVBITS
|
285 (palette_size
? RC_PALETTE
: 0));
287 return (SB_GRAD_RECT
| SB_GRAD_TRI
| SB_CONST_ALPHA
| SB_PIXEL_ALPHA
);
298 FIXME("(%p): CAPS1 is unimplemented, will return 0\n", dev
->hdc
);
299 /* please see wingdi.h for the possible bit-flag values that need
307 case PHYSICALOFFSETX
:
308 case PHYSICALOFFSETY
:
315 FIXME("(%p): unsupported capability %d, will return 0\n", dev
->hdc
, cap
);
321 /**********************************************************************
322 * ExtEscape (X11DRV.@)
324 static INT
X11DRV_ExtEscape( PHYSDEV dev
, INT escape
, INT in_count
, LPCVOID in_data
,
325 INT out_count
, LPVOID out_data
)
327 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
331 case QUERYESCSUPPORT
:
334 switch (*(const INT
*)in_data
)
337 return DD_HAL_VERSION
;
345 if (in_data
&& in_count
>= sizeof(enum x11drv_escape_codes
))
347 switch(*(const enum x11drv_escape_codes
*)in_data
)
349 case X11DRV_SET_DRAWABLE
:
350 if (in_count
>= sizeof(struct x11drv_escape_set_drawable
))
352 const struct x11drv_escape_set_drawable
*data
= in_data
;
353 physDev
->dc_rect
= data
->dc_rect
;
354 physDev
->drawable
= data
->drawable
;
355 physDev
->drawable_rect
= data
->drawable_rect
;
357 XSetSubwindowMode( gdi_display
, physDev
->gc
, data
->mode
);
359 TRACE( "SET_DRAWABLE hdc %p drawable %lx dc_rect %s drawable_rect %s\n",
360 dev
->hdc
, physDev
->drawable
, wine_dbgstr_rect(&physDev
->dc_rect
),
361 wine_dbgstr_rect(&physDev
->drawable_rect
) );
365 case X11DRV_GET_DRAWABLE
:
366 if (out_count
>= sizeof(struct x11drv_escape_get_drawable
))
368 struct x11drv_escape_get_drawable
*data
= out_data
;
369 data
->drawable
= physDev
->drawable
;
373 case X11DRV_START_EXPOSURES
:
375 XSetGraphicsExposures( gdi_display
, physDev
->gc
, True
);
377 physDev
->exposures
= 0;
379 case X11DRV_END_EXPOSURES
:
380 if (out_count
>= sizeof(HRGN
))
382 HRGN hrgn
= 0, tmp
= 0;
385 XSetGraphicsExposures( gdi_display
, physDev
->gc
, False
);
387 if (physDev
->exposures
)
394 XWindowEvent( gdi_display
, physDev
->drawable
, ~0, &event
);
396 if (event
.type
== NoExpose
) break;
397 if (event
.type
== GraphicsExpose
)
401 rect
.left
= event
.xgraphicsexpose
.x
- physDev
->dc_rect
.left
;
402 rect
.top
= event
.xgraphicsexpose
.y
- physDev
->dc_rect
.top
;
403 rect
.right
= rect
.left
+ event
.xgraphicsexpose
.width
;
404 rect
.bottom
= rect
.top
+ event
.xgraphicsexpose
.height
;
405 if (GetLayout( dev
->hdc
) & LAYOUT_RTL
)
406 mirror_rect( &physDev
->dc_rect
, &rect
);
408 TRACE( "got %s count %d\n", wine_dbgstr_rect(&rect
),
409 event
.xgraphicsexpose
.count
);
411 if (!tmp
) tmp
= CreateRectRgnIndirect( &rect
);
412 else SetRectRgn( tmp
, rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
413 if (hrgn
) CombineRgn( hrgn
, hrgn
, tmp
, RGN_OR
);
419 if (!event
.xgraphicsexpose
.count
) break;
423 ERR( "got unexpected event %d\n", event
.type
);
427 if (tmp
) DeleteObject( tmp
);
429 *(HRGN
*)out_data
= hrgn
;
443 static inline void opengl_error(void)
446 if (!warned
++) ERR("No OpenGL support compiled in.\n");
449 /***********************************************************************
450 * X11DRV_DescribePixelFormat
452 static int X11DRV_DescribePixelFormat( PHYSDEV dev
, int fmt
, UINT size
, PIXELFORMATDESCRIPTOR
*ppfd
)
458 /***********************************************************************
459 * X11DRV_SetPixelFormat
461 static BOOL
X11DRV_SetPixelFormat( PHYSDEV dev
, int fmt
, const PIXELFORMATDESCRIPTOR
*ppfd
)
468 static const struct gdi_dc_funcs x11drv_funcs
=
470 NULL
, /* pAbortDoc */
471 NULL
, /* pAbortPath */
472 NULL
, /* pAlphaBlend */
473 NULL
, /* pAngleArc */
474 X11DRV_Arc
, /* pArc */
476 NULL
, /* pBeginPath */
477 NULL
, /* pBlendImage */
478 X11DRV_Chord
, /* pChord */
479 NULL
, /* pCloseFigure */
480 X11DRV_CreateCompatibleDC
, /* pCreateCompatibleDC */
481 X11DRV_CreateDC
, /* pCreateDC */
482 X11DRV_DeleteDC
, /* pDeleteDC */
483 NULL
, /* pDeleteObject */
484 X11DRV_DescribePixelFormat
, /* pDescribePixelFormat */
485 NULL
, /* pDeviceCapabilities */
486 X11DRV_Ellipse
, /* pEllipse */
490 NULL
, /* pEnumFonts */
491 X11DRV_EnumICMProfiles
, /* pEnumICMProfiles */
492 NULL
, /* pExcludeClipRect */
493 NULL
, /* pExtDeviceMode */
494 X11DRV_ExtEscape
, /* pExtEscape */
495 X11DRV_ExtFloodFill
, /* pExtFloodFill */
496 NULL
, /* pExtSelectClipRgn */
497 NULL
, /* pExtTextOut */
498 NULL
, /* pFillPath */
500 NULL
, /* pFlattenPath */
501 NULL
, /* pFontIsLinked */
502 NULL
, /* pFrameRgn */
503 NULL
, /* pGdiComment */
504 NULL
, /* pGdiRealizationInfo */
505 NULL
, /* pGetBoundsRect */
506 NULL
, /* pGetCharABCWidths */
507 NULL
, /* pGetCharABCWidthsI */
508 NULL
, /* pGetCharWidth */
509 X11DRV_GetDeviceCaps
, /* pGetDeviceCaps */
510 X11DRV_GetDeviceGammaRamp
, /* pGetDeviceGammaRamp */
511 NULL
, /* pGetFontData */
512 NULL
, /* pGetFontUnicodeRanges */
513 NULL
, /* pGetGlyphIndices */
514 NULL
, /* pGetGlyphOutline */
515 X11DRV_GetICMProfile
, /* pGetICMProfile */
516 X11DRV_GetImage
, /* pGetImage */
517 NULL
, /* pGetKerningPairs */
518 X11DRV_GetNearestColor
, /* pGetNearestColor */
519 NULL
, /* pGetOutlineTextMetrics */
520 NULL
, /* pGetPixel */
521 X11DRV_GetSystemPaletteEntries
, /* pGetSystemPaletteEntries */
522 NULL
, /* pGetTextCharsetInfo */
523 NULL
, /* pGetTextExtentExPoint */
524 NULL
, /* pGetTextExtentExPointI */
525 NULL
, /* pGetTextFace */
526 NULL
, /* pGetTextMetrics */
527 X11DRV_GradientFill
, /* pGradientFill */
528 NULL
, /* pIntersectClipRect */
529 NULL
, /* pInvertRgn */
530 X11DRV_LineTo
, /* pLineTo */
531 NULL
, /* pModifyWorldTransform */
533 NULL
, /* pOffsetClipRgn */
534 NULL
, /* pOffsetViewportOrg */
535 NULL
, /* pOffsetWindowOrg */
536 X11DRV_PaintRgn
, /* pPaintRgn */
537 X11DRV_PatBlt
, /* pPatBlt */
538 X11DRV_Pie
, /* pPie */
539 NULL
, /* pPolyBezier */
540 NULL
, /* pPolyBezierTo */
541 NULL
, /* pPolyDraw */
542 X11DRV_PolyPolygon
, /* pPolyPolygon */
543 X11DRV_PolyPolyline
, /* pPolyPolyline */
544 X11DRV_Polygon
, /* pPolygon */
545 NULL
, /* pPolyline */
546 NULL
, /* pPolylineTo */
547 X11DRV_PutImage
, /* pPutImage */
548 X11DRV_RealizeDefaultPalette
, /* pRealizeDefaultPalette */
549 X11DRV_RealizePalette
, /* pRealizePalette */
550 X11DRV_Rectangle
, /* pRectangle */
552 NULL
, /* pRestoreDC */
553 X11DRV_RoundRect
, /* pRoundRect */
555 NULL
, /* pScaleViewportExt */
556 NULL
, /* pScaleWindowExt */
557 NULL
, /* pSelectBitmap */
558 X11DRV_SelectBrush
, /* pSelectBrush */
559 NULL
, /* pSelectClipPath */
560 NULL
, /* pSelectFont */
561 NULL
, /* pSelectPalette */
562 X11DRV_SelectPen
, /* pSelectPen */
563 NULL
, /* pSetArcDirection */
564 NULL
, /* pSetBkColor */
565 NULL
, /* pSetBkMode */
566 X11DRV_SetBoundsRect
, /* pSetBoundsRect */
567 X11DRV_SetDCBrushColor
, /* pSetDCBrushColor */
568 X11DRV_SetDCPenColor
, /* pSetDCPenColor */
569 NULL
, /* pSetDIBitsToDevice */
570 X11DRV_SetDeviceClipping
, /* pSetDeviceClipping */
571 X11DRV_SetDeviceGammaRamp
, /* pSetDeviceGammaRamp */
572 NULL
, /* pSetLayout */
573 NULL
, /* pSetMapMode */
574 NULL
, /* pSetMapperFlags */
575 X11DRV_SetPixel
, /* pSetPixel */
576 X11DRV_SetPixelFormat
, /* pSetPixelFormat */
577 NULL
, /* pSetPolyFillMode */
579 NULL
, /* pSetRelAbs */
580 NULL
, /* pSetStretchBltMode */
581 NULL
, /* pSetTextAlign */
582 NULL
, /* pSetTextCharacterExtra */
583 NULL
, /* pSetTextColor */
584 NULL
, /* pSetTextJustification */
585 NULL
, /* pSetViewportExt */
586 NULL
, /* pSetViewportOrg */
587 NULL
, /* pSetWindowExt */
588 NULL
, /* pSetWindowOrg */
589 NULL
, /* pSetWorldTransform */
590 NULL
, /* pStartDoc */
591 NULL
, /* pStartPage */
592 X11DRV_StretchBlt
, /* pStretchBlt */
593 NULL
, /* pStretchDIBits */
594 NULL
, /* pStrokeAndFillPath */
595 NULL
, /* pStrokePath */
596 NULL
, /* pSwapBuffers */
597 X11DRV_UnrealizePalette
, /* pUnrealizePalette */
598 NULL
, /* pWidenPath */
599 NULL
, /* wine_get_wgl_driver */
600 GDI_PRIORITY_GRAPHICS_DRV
/* priority */
604 /******************************************************************************
605 * X11DRV_get_gdi_driver
607 const struct gdi_dc_funcs
* CDECL
X11DRV_get_gdi_driver( unsigned int version
)
609 if (version
!= WINE_GDI_DRIVER_VERSION
)
611 ERR( "version mismatch, gdi32 wants %u but winex11 has %u\n", version
, WINE_GDI_DRIVER_VERSION
);
614 return &x11drv_funcs
;