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();
95 stock_bitmap_pixmap
= XCreatePixmap( gdi_display
, root_window
, 1, 1, 1 );
97 /* Initialize device caps */
98 log_pixels_x
= log_pixels_y
= get_dpi();
99 horz_size
= MulDiv( screen_width
, 254, log_pixels_x
* 10 );
100 vert_size
= MulDiv( screen_height
, 254, log_pixels_y
* 10 );
104 static X11DRV_PDEVICE
*create_x11_physdev( Drawable drawable
)
106 X11DRV_PDEVICE
*physDev
;
108 if (!device_init_done
) device_init();
110 if (!(physDev
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*physDev
) ))) return NULL
;
112 physDev
->drawable
= drawable
;
113 physDev
->gc
= XCreateGC( gdi_display
, drawable
, 0, NULL
);
114 XSetGraphicsExposures( gdi_display
, physDev
->gc
, False
);
115 XSetSubwindowMode( gdi_display
, physDev
->gc
, IncludeInferiors
);
116 XFlush( gdi_display
);
120 /**********************************************************************
123 static BOOL
X11DRV_CreateDC( PHYSDEV
*pdev
, LPCWSTR driver
, LPCWSTR device
,
124 LPCWSTR output
, const DEVMODEW
* initData
)
126 const struct gdi_dc_funcs
*glx_funcs
= get_glx_driver();
127 X11DRV_PDEVICE
*physDev
= create_x11_physdev( root_window
);
129 if (!physDev
) return FALSE
;
131 physDev
->depth
= screen_depth
;
132 physDev
->color_shifts
= &X11DRV_PALETTE_default_shifts
;
133 SetRect( &physDev
->dc_rect
, 0, 0, virtual_screen_rect
.right
- virtual_screen_rect
.left
,
134 virtual_screen_rect
.bottom
- virtual_screen_rect
.top
);
135 push_dc_driver( pdev
, &physDev
->dev
, &x11drv_funcs
);
136 if (xrender_funcs
&& !xrender_funcs
->pCreateDC( pdev
, driver
, device
, output
, initData
)) return FALSE
;
137 if (glx_funcs
&& !glx_funcs
->pCreateDC( pdev
, driver
, device
, output
, initData
)) return FALSE
;
142 /**********************************************************************
143 * X11DRV_CreateCompatibleDC
145 static BOOL
X11DRV_CreateCompatibleDC( PHYSDEV orig
, PHYSDEV
*pdev
)
147 const struct gdi_dc_funcs
*glx_funcs
= get_glx_driver();
148 X11DRV_PDEVICE
*physDev
= create_x11_physdev( stock_bitmap_pixmap
);
150 if (!physDev
) return FALSE
;
153 SetRect( &physDev
->dc_rect
, 0, 0, 1, 1 );
154 push_dc_driver( pdev
, &physDev
->dev
, &x11drv_funcs
);
155 if (orig
) return TRUE
; /* we already went through Xrender if we have an orig device */
156 if (xrender_funcs
&& !xrender_funcs
->pCreateCompatibleDC( NULL
, pdev
)) return FALSE
;
157 if (glx_funcs
&& !glx_funcs
->pCreateCompatibleDC( NULL
, pdev
)) return FALSE
;
162 /**********************************************************************
165 static BOOL
X11DRV_DeleteDC( PHYSDEV dev
)
167 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
169 XFreeGC( gdi_display
, physDev
->gc
);
170 HeapFree( GetProcessHeap(), 0, physDev
);
175 void add_device_bounds( X11DRV_PDEVICE
*dev
, const RECT
*rect
)
179 if (!dev
->bounds
) return;
180 if (dev
->region
&& GetRgnBox( dev
->region
, &rc
))
182 if (IntersectRect( &rc
, &rc
, rect
)) add_bounds_rect( dev
->bounds
, &rc
);
184 else add_bounds_rect( dev
->bounds
, rect
);
187 /***********************************************************************
188 * X11DRV_SetBoundsRect
190 static UINT
X11DRV_SetBoundsRect( PHYSDEV dev
, RECT
*rect
, UINT flags
)
192 X11DRV_PDEVICE
*pdev
= get_x11drv_dev( dev
);
194 if (flags
& DCB_DISABLE
) pdev
->bounds
= NULL
;
195 else if (flags
& DCB_ENABLE
) pdev
->bounds
= rect
;
196 return DCB_RESET
; /* we don't have device-specific bounds */
200 /***********************************************************************
201 * GetDeviceCaps (X11DRV.@)
203 static INT
X11DRV_GetDeviceCaps( PHYSDEV dev
, INT cap
)
210 return DT_RASDISPLAY
;
218 return screen_height
;
220 return virtual_screen_rect
.right
- virtual_screen_rect
.left
;
222 return virtual_screen_rect
.bottom
- virtual_screen_rect
.top
;
236 /* MSDN: Number of entries in the device's color table, if the device has
237 * a color depth of no more than 8 bits per pixel.For devices with greater
238 * color depths, -1 is returned. */
239 return (screen_depth
> 8) ? -1 : (1 << screen_depth
);
241 return sizeof(X11DRV_PDEVICE
);
243 return (CC_CIRCLES
| CC_PIE
| CC_CHORD
| CC_ELLIPSES
| CC_WIDE
|
244 CC_STYLED
| CC_WIDESTYLED
| CC_INTERIORS
| CC_ROUNDRECT
);
246 return (LC_POLYLINE
| LC_MARKER
| LC_POLYMARKER
| LC_WIDE
|
247 LC_STYLED
| LC_WIDESTYLED
| LC_INTERIORS
);
249 return (PC_POLYGON
| PC_RECTANGLE
| PC_WINDPOLYGON
| PC_SCANLINE
|
250 PC_WIDE
| PC_STYLED
| PC_WIDESTYLED
| PC_INTERIORS
);
252 return (TC_OP_CHARACTER
| TC_OP_STROKE
| TC_CP_STROKE
|
253 TC_CR_ANY
| TC_SF_X_YINDEP
| TC_SA_DOUBLE
| TC_SA_INTEGER
|
254 TC_SA_CONTIN
| TC_UA_ABLE
| TC_SO_ABLE
| TC_RA_ABLE
| TC_VA_ABLE
);
258 /* The observed correspondence between BITSPIXEL and COLORRES is:
259 * BITSPIXEL: 8 -> COLORRES: 18
260 * BITSPIXEL: 16 -> COLORRES: 16
261 * BITSPIXEL: 24 -> COLORRES: 24
262 * BITSPIXEL: 32 -> COLORRES: 24 */
263 return (screen_bpp
<= 8) ? 18 : min( 24, screen_bpp
);
265 return (RC_BITBLT
| RC_BANDING
| RC_SCALING
| RC_BITMAP64
| RC_DI_BITMAP
|
266 RC_DIBTODEV
| RC_BIGFONT
| RC_STRETCHBLT
| RC_STRETCHDIB
| RC_DEVBITS
|
267 (palette_size
? RC_PALETTE
: 0));
269 return (SB_GRAD_RECT
| SB_GRAD_TRI
| SB_CONST_ALPHA
| SB_PIXEL_ALPHA
);
280 FIXME("(%p): CAPS1 is unimplemented, will return 0\n", dev
->hdc
);
281 /* please see wingdi.h for the possible bit-flag values that need
289 case PHYSICALOFFSETX
:
290 case PHYSICALOFFSETY
:
297 FIXME("(%p): unsupported capability %d, will return 0\n", dev
->hdc
, cap
);
303 /**********************************************************************
304 * ExtEscape (X11DRV.@)
306 static INT
X11DRV_ExtEscape( PHYSDEV dev
, INT escape
, INT in_count
, LPCVOID in_data
,
307 INT out_count
, LPVOID out_data
)
309 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
313 case QUERYESCSUPPORT
:
316 switch (*(const INT
*)in_data
)
319 return DD_HAL_VERSION
;
327 if (in_data
&& in_count
>= sizeof(enum x11drv_escape_codes
))
329 switch(*(const enum x11drv_escape_codes
*)in_data
)
331 case X11DRV_SET_DRAWABLE
:
332 if (in_count
>= sizeof(struct x11drv_escape_set_drawable
))
334 const struct x11drv_escape_set_drawable
*data
= in_data
;
335 physDev
->dc_rect
= data
->dc_rect
;
336 physDev
->drawable
= data
->drawable
;
337 XSetSubwindowMode( gdi_display
, physDev
->gc
, data
->mode
);
338 TRACE( "SET_DRAWABLE hdc %p drawable %lx dc_rect %s\n",
339 dev
->hdc
, physDev
->drawable
, wine_dbgstr_rect(&physDev
->dc_rect
) );
343 case X11DRV_GET_DRAWABLE
:
344 if (out_count
>= sizeof(struct x11drv_escape_get_drawable
))
346 struct x11drv_escape_get_drawable
*data
= out_data
;
347 data
->drawable
= physDev
->drawable
;
351 case X11DRV_START_EXPOSURES
:
352 XSetGraphicsExposures( gdi_display
, physDev
->gc
, True
);
353 physDev
->exposures
= 0;
355 case X11DRV_END_EXPOSURES
:
356 if (out_count
>= sizeof(HRGN
))
358 HRGN hrgn
= 0, tmp
= 0;
360 XSetGraphicsExposures( gdi_display
, physDev
->gc
, False
);
361 if (physDev
->exposures
)
367 XWindowEvent( gdi_display
, physDev
->drawable
, ~0, &event
);
368 if (event
.type
== NoExpose
) break;
369 if (event
.type
== GraphicsExpose
)
373 rect
.left
= event
.xgraphicsexpose
.x
- physDev
->dc_rect
.left
;
374 rect
.top
= event
.xgraphicsexpose
.y
- physDev
->dc_rect
.top
;
375 rect
.right
= rect
.left
+ event
.xgraphicsexpose
.width
;
376 rect
.bottom
= rect
.top
+ event
.xgraphicsexpose
.height
;
377 if (GetLayout( dev
->hdc
) & LAYOUT_RTL
)
378 mirror_rect( &physDev
->dc_rect
, &rect
);
380 TRACE( "got %s count %d\n", wine_dbgstr_rect(&rect
),
381 event
.xgraphicsexpose
.count
);
383 if (!tmp
) tmp
= CreateRectRgnIndirect( &rect
);
384 else SetRectRgn( tmp
, rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
385 if (hrgn
) CombineRgn( hrgn
, hrgn
, tmp
, RGN_OR
);
391 if (!event
.xgraphicsexpose
.count
) break;
395 ERR( "got unexpected event %d\n", event
.type
);
399 if (tmp
) DeleteObject( tmp
);
401 *(HRGN
*)out_data
= hrgn
;
415 static const struct gdi_dc_funcs x11drv_funcs
=
417 NULL
, /* pAbortDoc */
418 NULL
, /* pAbortPath */
419 NULL
, /* pAlphaBlend */
420 NULL
, /* pAngleArc */
421 X11DRV_Arc
, /* pArc */
423 NULL
, /* pBeginPath */
424 NULL
, /* pBlendImage */
425 X11DRV_Chord
, /* pChord */
426 NULL
, /* pCloseFigure */
427 X11DRV_CreateCompatibleDC
, /* pCreateCompatibleDC */
428 X11DRV_CreateDC
, /* pCreateDC */
429 X11DRV_DeleteDC
, /* pDeleteDC */
430 NULL
, /* pDeleteObject */
431 NULL
, /* pDeviceCapabilities */
432 X11DRV_Ellipse
, /* pEllipse */
436 NULL
, /* pEnumFonts */
437 X11DRV_EnumICMProfiles
, /* pEnumICMProfiles */
438 NULL
, /* pExcludeClipRect */
439 NULL
, /* pExtDeviceMode */
440 X11DRV_ExtEscape
, /* pExtEscape */
441 X11DRV_ExtFloodFill
, /* pExtFloodFill */
442 NULL
, /* pExtSelectClipRgn */
443 NULL
, /* pExtTextOut */
444 NULL
, /* pFillPath */
446 NULL
, /* pFlattenPath */
447 NULL
, /* pFontIsLinked */
448 NULL
, /* pFrameRgn */
449 NULL
, /* pGdiComment */
450 NULL
, /* pGdiRealizationInfo */
451 NULL
, /* pGetBoundsRect */
452 NULL
, /* pGetCharABCWidths */
453 NULL
, /* pGetCharABCWidthsI */
454 NULL
, /* pGetCharWidth */
455 X11DRV_GetDeviceCaps
, /* pGetDeviceCaps */
456 X11DRV_GetDeviceGammaRamp
, /* pGetDeviceGammaRamp */
457 NULL
, /* pGetFontData */
458 NULL
, /* pGetFontUnicodeRanges */
459 NULL
, /* pGetGlyphIndices */
460 NULL
, /* pGetGlyphOutline */
461 X11DRV_GetICMProfile
, /* pGetICMProfile */
462 X11DRV_GetImage
, /* pGetImage */
463 NULL
, /* pGetKerningPairs */
464 X11DRV_GetNearestColor
, /* pGetNearestColor */
465 NULL
, /* pGetOutlineTextMetrics */
466 NULL
, /* pGetPixel */
467 X11DRV_GetSystemPaletteEntries
, /* pGetSystemPaletteEntries */
468 NULL
, /* pGetTextCharsetInfo */
469 NULL
, /* pGetTextExtentExPoint */
470 NULL
, /* pGetTextExtentExPointI */
471 NULL
, /* pGetTextFace */
472 NULL
, /* pGetTextMetrics */
473 X11DRV_GradientFill
, /* pGradientFill */
474 NULL
, /* pIntersectClipRect */
475 NULL
, /* pInvertRgn */
476 X11DRV_LineTo
, /* pLineTo */
477 NULL
, /* pModifyWorldTransform */
479 NULL
, /* pOffsetClipRgn */
480 NULL
, /* pOffsetViewportOrg */
481 NULL
, /* pOffsetWindowOrg */
482 X11DRV_PaintRgn
, /* pPaintRgn */
483 X11DRV_PatBlt
, /* pPatBlt */
484 X11DRV_Pie
, /* pPie */
485 NULL
, /* pPolyBezier */
486 NULL
, /* pPolyBezierTo */
487 NULL
, /* pPolyDraw */
488 X11DRV_PolyPolygon
, /* pPolyPolygon */
489 X11DRV_PolyPolyline
, /* pPolyPolyline */
490 X11DRV_Polygon
, /* pPolygon */
491 NULL
, /* pPolyline */
492 NULL
, /* pPolylineTo */
493 X11DRV_PutImage
, /* pPutImage */
494 X11DRV_RealizeDefaultPalette
, /* pRealizeDefaultPalette */
495 X11DRV_RealizePalette
, /* pRealizePalette */
496 X11DRV_Rectangle
, /* pRectangle */
498 NULL
, /* pRestoreDC */
499 X11DRV_RoundRect
, /* pRoundRect */
501 NULL
, /* pScaleViewportExt */
502 NULL
, /* pScaleWindowExt */
503 NULL
, /* pSelectBitmap */
504 X11DRV_SelectBrush
, /* pSelectBrush */
505 NULL
, /* pSelectClipPath */
506 NULL
, /* pSelectFont */
507 NULL
, /* pSelectPalette */
508 X11DRV_SelectPen
, /* pSelectPen */
509 NULL
, /* pSetArcDirection */
510 NULL
, /* pSetBkColor */
511 NULL
, /* pSetBkMode */
512 X11DRV_SetBoundsRect
, /* pSetBoundsRect */
513 X11DRV_SetDCBrushColor
, /* pSetDCBrushColor */
514 X11DRV_SetDCPenColor
, /* pSetDCPenColor */
515 NULL
, /* pSetDIBitsToDevice */
516 X11DRV_SetDeviceClipping
, /* pSetDeviceClipping */
517 X11DRV_SetDeviceGammaRamp
, /* pSetDeviceGammaRamp */
518 NULL
, /* pSetLayout */
519 NULL
, /* pSetMapMode */
520 NULL
, /* pSetMapperFlags */
521 X11DRV_SetPixel
, /* pSetPixel */
522 NULL
, /* pSetPolyFillMode */
524 NULL
, /* pSetRelAbs */
525 NULL
, /* pSetStretchBltMode */
526 NULL
, /* pSetTextAlign */
527 NULL
, /* pSetTextCharacterExtra */
528 NULL
, /* pSetTextColor */
529 NULL
, /* pSetTextJustification */
530 NULL
, /* pSetViewportExt */
531 NULL
, /* pSetViewportOrg */
532 NULL
, /* pSetWindowExt */
533 NULL
, /* pSetWindowOrg */
534 NULL
, /* pSetWorldTransform */
535 NULL
, /* pStartDoc */
536 NULL
, /* pStartPage */
537 X11DRV_StretchBlt
, /* pStretchBlt */
538 NULL
, /* pStretchDIBits */
539 NULL
, /* pStrokeAndFillPath */
540 NULL
, /* pStrokePath */
541 X11DRV_UnrealizePalette
, /* pUnrealizePalette */
542 NULL
, /* pWidenPath */
543 NULL
, /* wine_get_wgl_driver */
544 GDI_PRIORITY_GRAPHICS_DRV
/* priority */
548 /******************************************************************************
549 * X11DRV_get_gdi_driver
551 const struct gdi_dc_funcs
* CDECL
X11DRV_get_gdi_driver( unsigned int version
)
553 if (version
!= WINE_GDI_DRIVER_VERSION
)
555 ERR( "version mismatch, gdi32 wants %u but winex11 has %u\n", version
, WINE_GDI_DRIVER_VERSION
);
558 return &x11drv_funcs
;