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
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 /******************************************************************************
55 * get the dpi from the registry
57 static DWORD
get_dpi( void )
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)
77 /**********************************************************************
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();
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
);
119 /**********************************************************************
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
;
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
;
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
;
157 /**********************************************************************
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
);
170 void add_device_bounds( X11DRV_PDEVICE
*dev
, const RECT
*rect
)
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
)
205 return DT_RASDISPLAY
;
213 return screen_height
;
215 return virtual_screen_rect
.right
- virtual_screen_rect
.left
;
217 return virtual_screen_rect
.bottom
- virtual_screen_rect
.top
;
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
);
236 return sizeof(X11DRV_PDEVICE
);
238 return (CC_CIRCLES
| CC_PIE
| CC_CHORD
| CC_ELLIPSES
| CC_WIDE
|
239 CC_STYLED
| CC_WIDESTYLED
| CC_INTERIORS
| CC_ROUNDRECT
);
241 return (LC_POLYLINE
| LC_MARKER
| LC_POLYMARKER
| LC_WIDE
|
242 LC_STYLED
| LC_WIDESTYLED
| LC_INTERIORS
);
244 return (PC_POLYGON
| PC_RECTANGLE
| PC_WINDPOLYGON
| PC_SCANLINE
|
245 PC_WIDE
| PC_STYLED
| PC_WIDESTYLED
| PC_INTERIORS
);
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
);
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
);
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));
264 return (SB_GRAD_RECT
| SB_GRAD_TRI
| SB_CONST_ALPHA
| SB_PIXEL_ALPHA
);
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
284 case PHYSICALOFFSETX
:
285 case PHYSICALOFFSETY
:
292 FIXME("(%p): unsupported capability %d, will return 0\n", dev
->hdc
, cap
);
298 /**********************************************************************
299 * ExtEscape (X11DRV.@)
301 static INT
X11DRV_ExtEscape( PHYSDEV dev
, INT escape
, INT in_count
, LPCVOID in_data
,
302 INT out_count
, LPVOID out_data
)
304 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
308 case QUERYESCSUPPORT
:
311 switch (*(const INT
*)in_data
)
320 if (in_data
&& in_count
>= sizeof(enum x11drv_escape_codes
))
322 switch(*(const enum x11drv_escape_codes
*)in_data
)
324 case X11DRV_SET_DRAWABLE
:
325 if (in_count
>= sizeof(struct x11drv_escape_set_drawable
))
327 const struct x11drv_escape_set_drawable
*data
= in_data
;
328 physDev
->dc_rect
= data
->dc_rect
;
329 physDev
->drawable
= data
->drawable
;
330 XFreeGC( gdi_display
, physDev
->gc
);
331 physDev
->gc
= XCreateGC( gdi_display
, physDev
->drawable
, 0, NULL
);
332 XSetGraphicsExposures( gdi_display
, physDev
->gc
, False
);
333 XSetSubwindowMode( gdi_display
, physDev
->gc
, data
->mode
);
334 TRACE( "SET_DRAWABLE hdc %p drawable %lx dc_rect %s\n",
335 dev
->hdc
, physDev
->drawable
, wine_dbgstr_rect(&physDev
->dc_rect
) );
339 case X11DRV_GET_DRAWABLE
:
340 if (out_count
>= sizeof(struct x11drv_escape_get_drawable
))
342 struct x11drv_escape_get_drawable
*data
= out_data
;
343 data
->drawable
= physDev
->drawable
;
347 case X11DRV_FLUSH_GL_DRAWABLE
:
348 if (in_count
>= sizeof(struct x11drv_escape_flush_gl_drawable
))
350 const struct x11drv_escape_flush_gl_drawable
*data
= in_data
;
351 RECT rect
= physDev
->dc_rect
;
353 OffsetRect( &rect
, -physDev
->dc_rect
.left
, -physDev
->dc_rect
.top
);
354 /* The GL drawable may be lagged behind if we don't flush first, so
355 * flush the display make sure we copy up-to-date data */
356 XFlush( gdi_display
);
357 XSetFunction( gdi_display
, physDev
->gc
, GXcopy
);
358 XCopyArea( gdi_display
, data
->gl_drawable
, physDev
->drawable
, physDev
->gc
,
359 0, 0, rect
.right
, rect
.bottom
,
360 physDev
->dc_rect
.left
, physDev
->dc_rect
.top
);
361 add_device_bounds( physDev
, &rect
);
365 case X11DRV_START_EXPOSURES
:
366 XSetGraphicsExposures( gdi_display
, physDev
->gc
, True
);
367 physDev
->exposures
= 0;
369 case X11DRV_END_EXPOSURES
:
370 if (out_count
>= sizeof(HRGN
))
372 HRGN hrgn
= 0, tmp
= 0;
374 XSetGraphicsExposures( gdi_display
, physDev
->gc
, False
);
375 if (physDev
->exposures
)
381 XWindowEvent( gdi_display
, physDev
->drawable
, ~0, &event
);
382 if (event
.type
== NoExpose
) break;
383 if (event
.type
== GraphicsExpose
)
387 rect
.left
= event
.xgraphicsexpose
.x
- physDev
->dc_rect
.left
;
388 rect
.top
= event
.xgraphicsexpose
.y
- physDev
->dc_rect
.top
;
389 rect
.right
= rect
.left
+ event
.xgraphicsexpose
.width
;
390 rect
.bottom
= rect
.top
+ event
.xgraphicsexpose
.height
;
391 if (GetLayout( dev
->hdc
) & LAYOUT_RTL
)
392 mirror_rect( &physDev
->dc_rect
, &rect
);
394 TRACE( "got %s count %d\n", wine_dbgstr_rect(&rect
),
395 event
.xgraphicsexpose
.count
);
397 if (!tmp
) tmp
= CreateRectRgnIndirect( &rect
);
398 else SetRectRgn( tmp
, rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
399 if (hrgn
) CombineRgn( hrgn
, hrgn
, tmp
, RGN_OR
);
405 if (!event
.xgraphicsexpose
.count
) break;
409 ERR( "got unexpected event %d\n", event
.type
);
413 if (tmp
) DeleteObject( tmp
);
415 *(HRGN
*)out_data
= hrgn
;
428 /**********************************************************************
429 * X11DRV_wine_get_wgl_driver
431 static struct opengl_funcs
* X11DRV_wine_get_wgl_driver( PHYSDEV dev
, UINT version
)
433 struct opengl_funcs
*ret
;
435 if (!(ret
= get_glx_driver( version
)))
437 dev
= GET_NEXT_PHYSDEV( dev
, wine_get_wgl_driver
);
438 ret
= dev
->funcs
->wine_get_wgl_driver( dev
, version
);
444 static const struct gdi_dc_funcs x11drv_funcs
=
446 NULL
, /* pAbortDoc */
447 NULL
, /* pAbortPath */
448 NULL
, /* pAlphaBlend */
449 NULL
, /* pAngleArc */
450 X11DRV_Arc
, /* pArc */
452 NULL
, /* pBeginPath */
453 NULL
, /* pBlendImage */
454 X11DRV_Chord
, /* pChord */
455 NULL
, /* pCloseFigure */
456 X11DRV_CreateCompatibleDC
, /* pCreateCompatibleDC */
457 X11DRV_CreateDC
, /* pCreateDC */
458 X11DRV_DeleteDC
, /* pDeleteDC */
459 NULL
, /* pDeleteObject */
460 NULL
, /* pDeviceCapabilities */
461 X11DRV_Ellipse
, /* pEllipse */
465 NULL
, /* pEnumFonts */
466 X11DRV_EnumICMProfiles
, /* pEnumICMProfiles */
467 NULL
, /* pExcludeClipRect */
468 NULL
, /* pExtDeviceMode */
469 X11DRV_ExtEscape
, /* pExtEscape */
470 X11DRV_ExtFloodFill
, /* pExtFloodFill */
471 NULL
, /* pExtSelectClipRgn */
472 NULL
, /* pExtTextOut */
473 NULL
, /* pFillPath */
475 NULL
, /* pFlattenPath */
476 NULL
, /* pFontIsLinked */
477 NULL
, /* pFrameRgn */
478 NULL
, /* pGdiComment */
479 NULL
, /* pGdiRealizationInfo */
480 NULL
, /* pGetBoundsRect */
481 NULL
, /* pGetCharABCWidths */
482 NULL
, /* pGetCharABCWidthsI */
483 NULL
, /* pGetCharWidth */
484 X11DRV_GetDeviceCaps
, /* pGetDeviceCaps */
485 X11DRV_GetDeviceGammaRamp
, /* pGetDeviceGammaRamp */
486 NULL
, /* pGetFontData */
487 NULL
, /* pGetFontUnicodeRanges */
488 NULL
, /* pGetGlyphIndices */
489 NULL
, /* pGetGlyphOutline */
490 X11DRV_GetICMProfile
, /* pGetICMProfile */
491 X11DRV_GetImage
, /* pGetImage */
492 NULL
, /* pGetKerningPairs */
493 X11DRV_GetNearestColor
, /* pGetNearestColor */
494 NULL
, /* pGetOutlineTextMetrics */
495 NULL
, /* pGetPixel */
496 X11DRV_GetSystemPaletteEntries
, /* pGetSystemPaletteEntries */
497 NULL
, /* pGetTextCharsetInfo */
498 NULL
, /* pGetTextExtentExPoint */
499 NULL
, /* pGetTextExtentExPointI */
500 NULL
, /* pGetTextFace */
501 NULL
, /* pGetTextMetrics */
502 X11DRV_GradientFill
, /* pGradientFill */
503 NULL
, /* pIntersectClipRect */
504 NULL
, /* pInvertRgn */
505 X11DRV_LineTo
, /* pLineTo */
506 NULL
, /* pModifyWorldTransform */
508 NULL
, /* pOffsetClipRgn */
509 NULL
, /* pOffsetViewportOrg */
510 NULL
, /* pOffsetWindowOrg */
511 X11DRV_PaintRgn
, /* pPaintRgn */
512 X11DRV_PatBlt
, /* pPatBlt */
513 X11DRV_Pie
, /* pPie */
514 NULL
, /* pPolyBezier */
515 NULL
, /* pPolyBezierTo */
516 NULL
, /* pPolyDraw */
517 X11DRV_PolyPolygon
, /* pPolyPolygon */
518 X11DRV_PolyPolyline
, /* pPolyPolyline */
519 X11DRV_Polygon
, /* pPolygon */
520 NULL
, /* pPolyline */
521 NULL
, /* pPolylineTo */
522 X11DRV_PutImage
, /* pPutImage */
523 X11DRV_RealizeDefaultPalette
, /* pRealizeDefaultPalette */
524 X11DRV_RealizePalette
, /* pRealizePalette */
525 X11DRV_Rectangle
, /* pRectangle */
527 NULL
, /* pRestoreDC */
528 X11DRV_RoundRect
, /* pRoundRect */
530 NULL
, /* pScaleViewportExt */
531 NULL
, /* pScaleWindowExt */
532 NULL
, /* pSelectBitmap */
533 X11DRV_SelectBrush
, /* pSelectBrush */
534 NULL
, /* pSelectClipPath */
535 NULL
, /* pSelectFont */
536 NULL
, /* pSelectPalette */
537 X11DRV_SelectPen
, /* pSelectPen */
538 NULL
, /* pSetArcDirection */
539 NULL
, /* pSetBkColor */
540 NULL
, /* pSetBkMode */
541 X11DRV_SetBoundsRect
, /* pSetBoundsRect */
542 X11DRV_SetDCBrushColor
, /* pSetDCBrushColor */
543 X11DRV_SetDCPenColor
, /* pSetDCPenColor */
544 NULL
, /* pSetDIBitsToDevice */
545 X11DRV_SetDeviceClipping
, /* pSetDeviceClipping */
546 X11DRV_SetDeviceGammaRamp
, /* pSetDeviceGammaRamp */
547 NULL
, /* pSetLayout */
548 NULL
, /* pSetMapMode */
549 NULL
, /* pSetMapperFlags */
550 X11DRV_SetPixel
, /* pSetPixel */
551 NULL
, /* pSetPolyFillMode */
553 NULL
, /* pSetRelAbs */
554 NULL
, /* pSetStretchBltMode */
555 NULL
, /* pSetTextAlign */
556 NULL
, /* pSetTextCharacterExtra */
557 NULL
, /* pSetTextColor */
558 NULL
, /* pSetTextJustification */
559 NULL
, /* pSetViewportExt */
560 NULL
, /* pSetViewportOrg */
561 NULL
, /* pSetWindowExt */
562 NULL
, /* pSetWindowOrg */
563 NULL
, /* pSetWorldTransform */
564 NULL
, /* pStartDoc */
565 NULL
, /* pStartPage */
566 X11DRV_StretchBlt
, /* pStretchBlt */
567 NULL
, /* pStretchDIBits */
568 NULL
, /* pStrokeAndFillPath */
569 NULL
, /* pStrokePath */
570 X11DRV_UnrealizePalette
, /* pUnrealizePalette */
571 NULL
, /* pWidenPath */
572 X11DRV_wine_get_wgl_driver
, /* wine_get_wgl_driver */
573 GDI_PRIORITY_GRAPHICS_DRV
/* priority */
577 /******************************************************************************
578 * X11DRV_get_gdi_driver
580 const struct gdi_dc_funcs
* CDECL
X11DRV_get_gdi_driver( unsigned int version
)
582 if (version
!= WINE_GDI_DRIVER_VERSION
)
584 ERR( "version mismatch, gdi32 wants %u but winex11 has %u\n", version
, WINE_GDI_DRIVER_VERSION
);
587 return &x11drv_funcs
;