winex11: Remove some remainders of the ddraw HAL support.
[wine.git] / dlls / winex11.drv / init.c
blobf03dd4dd50bfd179a95be584ee242494fb979655
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 "ddrawi.h"
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 /******************************************************************************
54 * get_dpi
56 * get the dpi from the registry
58 static DWORD get_dpi( void )
60 DWORD dpi = 96;
61 HKEY hkey;
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)
71 dpi = new_dpi;
73 RegCloseKey(hkey);
75 return dpi;
78 /**********************************************************************
79 * device_init
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();
90 /* Init Xcursor */
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 );
117 return physDev;
120 /**********************************************************************
121 * X11DRV_CreateDC
123 static BOOL X11DRV_CreateDC( PHYSDEV *pdev, LPCWSTR driver, LPCWSTR device,
124 LPCWSTR output, const DEVMODEW* initData )
126 X11DRV_PDEVICE *physDev = create_x11_physdev( root_window );
128 if (!physDev) return FALSE;
130 physDev->depth = default_visual.depth;
131 physDev->color_shifts = &X11DRV_PALETTE_default_shifts;
132 SetRect( &physDev->dc_rect, 0, 0, virtual_screen_rect.right - virtual_screen_rect.left,
133 virtual_screen_rect.bottom - virtual_screen_rect.top );
134 push_dc_driver( pdev, &physDev->dev, &x11drv_funcs );
135 if (xrender_funcs && !xrender_funcs->pCreateDC( pdev, driver, device, output, initData )) return FALSE;
136 return TRUE;
140 /**********************************************************************
141 * X11DRV_CreateCompatibleDC
143 static BOOL X11DRV_CreateCompatibleDC( PHYSDEV orig, PHYSDEV *pdev )
145 X11DRV_PDEVICE *physDev = create_x11_physdev( stock_bitmap_pixmap );
147 if (!physDev) return FALSE;
149 physDev->depth = 1;
150 SetRect( &physDev->dc_rect, 0, 0, 1, 1 );
151 push_dc_driver( pdev, &physDev->dev, &x11drv_funcs );
152 if (orig) return TRUE; /* we already went through Xrender if we have an orig device */
153 if (xrender_funcs && !xrender_funcs->pCreateCompatibleDC( NULL, pdev )) return FALSE;
154 return TRUE;
158 /**********************************************************************
159 * X11DRV_DeleteDC
161 static BOOL X11DRV_DeleteDC( PHYSDEV dev )
163 X11DRV_PDEVICE *physDev = get_x11drv_dev( dev );
165 XFreeGC( gdi_display, physDev->gc );
166 HeapFree( GetProcessHeap(), 0, physDev );
167 return TRUE;
171 void add_device_bounds( X11DRV_PDEVICE *dev, const RECT *rect )
173 RECT rc;
175 if (!dev->bounds) return;
176 if (dev->region && GetRgnBox( dev->region, &rc ))
178 if (IntersectRect( &rc, &rc, rect )) add_bounds_rect( dev->bounds, &rc );
180 else add_bounds_rect( dev->bounds, rect );
183 /***********************************************************************
184 * X11DRV_SetBoundsRect
186 static UINT X11DRV_SetBoundsRect( PHYSDEV dev, RECT *rect, UINT flags )
188 X11DRV_PDEVICE *pdev = get_x11drv_dev( dev );
190 if (flags & DCB_DISABLE) pdev->bounds = NULL;
191 else if (flags & DCB_ENABLE) pdev->bounds = rect;
192 return DCB_RESET; /* we don't have device-specific bounds */
196 /***********************************************************************
197 * GetDeviceCaps (X11DRV.@)
199 static INT X11DRV_GetDeviceCaps( PHYSDEV dev, INT cap )
201 switch(cap)
203 case DRIVERVERSION:
204 return 0x300;
205 case TECHNOLOGY:
206 return DT_RASDISPLAY;
207 case HORZSIZE:
208 return horz_size;
209 case VERTSIZE:
210 return vert_size;
211 case HORZRES:
212 return screen_width;
213 case VERTRES:
214 return screen_height;
215 case DESKTOPHORZRES:
216 return virtual_screen_rect.right - virtual_screen_rect.left;
217 case DESKTOPVERTRES:
218 return virtual_screen_rect.bottom - virtual_screen_rect.top;
219 case BITSPIXEL:
220 return screen_bpp;
221 case PLANES:
222 return 1;
223 case NUMBRUSHES:
224 return -1;
225 case NUMPENS:
226 return -1;
227 case NUMMARKERS:
228 return 0;
229 case NUMFONTS:
230 return 0;
231 case NUMCOLORS:
232 /* MSDN: Number of entries in the device's color table, if the device has
233 * a color depth of no more than 8 bits per pixel.For devices with greater
234 * color depths, -1 is returned. */
235 return (default_visual.depth > 8) ? -1 : (1 << default_visual.depth);
236 case PDEVICESIZE:
237 return sizeof(X11DRV_PDEVICE);
238 case CURVECAPS:
239 return (CC_CIRCLES | CC_PIE | CC_CHORD | CC_ELLIPSES | CC_WIDE |
240 CC_STYLED | CC_WIDESTYLED | CC_INTERIORS | CC_ROUNDRECT);
241 case LINECAPS:
242 return (LC_POLYLINE | LC_MARKER | LC_POLYMARKER | LC_WIDE |
243 LC_STYLED | LC_WIDESTYLED | LC_INTERIORS);
244 case POLYGONALCAPS:
245 return (PC_POLYGON | PC_RECTANGLE | PC_WINDPOLYGON | PC_SCANLINE |
246 PC_WIDE | PC_STYLED | PC_WIDESTYLED | PC_INTERIORS);
247 case TEXTCAPS:
248 return (TC_OP_CHARACTER | TC_OP_STROKE | TC_CP_STROKE |
249 TC_CR_ANY | TC_SF_X_YINDEP | TC_SA_DOUBLE | TC_SA_INTEGER |
250 TC_SA_CONTIN | TC_UA_ABLE | TC_SO_ABLE | TC_RA_ABLE | TC_VA_ABLE);
251 case CLIPCAPS:
252 return CP_REGION;
253 case COLORRES:
254 /* The observed correspondence between BITSPIXEL and COLORRES is:
255 * BITSPIXEL: 8 -> COLORRES: 18
256 * BITSPIXEL: 16 -> COLORRES: 16
257 * BITSPIXEL: 24 -> COLORRES: 24
258 * BITSPIXEL: 32 -> COLORRES: 24 */
259 return (screen_bpp <= 8) ? 18 : min( 24, screen_bpp );
260 case RASTERCAPS:
261 return (RC_BITBLT | RC_BANDING | RC_SCALING | RC_BITMAP64 | RC_DI_BITMAP |
262 RC_DIBTODEV | RC_BIGFONT | RC_STRETCHBLT | RC_STRETCHDIB | RC_DEVBITS |
263 (palette_size ? RC_PALETTE : 0));
264 case SHADEBLENDCAPS:
265 return (SB_GRAD_RECT | SB_GRAD_TRI | SB_CONST_ALPHA | SB_PIXEL_ALPHA);
266 case ASPECTX:
267 case ASPECTY:
268 return 36;
269 case ASPECTXY:
270 return 51;
271 case LOGPIXELSX:
272 return log_pixels_x;
273 case LOGPIXELSY:
274 return log_pixels_y;
275 case CAPS1:
276 FIXME("(%p): CAPS1 is unimplemented, will return 0\n", dev->hdc );
277 /* please see wingdi.h for the possible bit-flag values that need
278 to be returned. */
279 return 0;
280 case SIZEPALETTE:
281 return palette_size;
282 case NUMRESERVED:
283 case PHYSICALWIDTH:
284 case PHYSICALHEIGHT:
285 case PHYSICALOFFSETX:
286 case PHYSICALOFFSETY:
287 case SCALINGFACTORX:
288 case SCALINGFACTORY:
289 case VREFRESH:
290 case BLTALIGNMENT:
291 return 0;
292 default:
293 FIXME("(%p): unsupported capability %d, will return 0\n", dev->hdc, cap );
294 return 0;
299 /**********************************************************************
300 * ExtEscape (X11DRV.@)
302 static INT X11DRV_ExtEscape( PHYSDEV dev, INT escape, INT in_count, LPCVOID in_data,
303 INT out_count, LPVOID out_data )
305 X11DRV_PDEVICE *physDev = get_x11drv_dev( dev );
307 switch(escape)
309 case QUERYESCSUPPORT:
310 if (in_data)
312 switch (*(const INT *)in_data)
314 case X11DRV_ESCAPE:
315 return TRUE;
318 break;
320 case X11DRV_ESCAPE:
321 if (in_data && in_count >= sizeof(enum x11drv_escape_codes))
323 switch(*(const enum x11drv_escape_codes *)in_data)
325 case X11DRV_SET_DRAWABLE:
326 if (in_count >= sizeof(struct x11drv_escape_set_drawable))
328 const struct x11drv_escape_set_drawable *data = in_data;
329 physDev->dc_rect = data->dc_rect;
330 physDev->drawable = data->drawable;
331 XFreeGC( gdi_display, physDev->gc );
332 physDev->gc = XCreateGC( gdi_display, physDev->drawable, 0, NULL );
333 XSetGraphicsExposures( gdi_display, physDev->gc, False );
334 XSetSubwindowMode( gdi_display, physDev->gc, data->mode );
335 TRACE( "SET_DRAWABLE hdc %p drawable %lx dc_rect %s\n",
336 dev->hdc, physDev->drawable, wine_dbgstr_rect(&physDev->dc_rect) );
337 return TRUE;
339 break;
340 case X11DRV_GET_DRAWABLE:
341 if (out_count >= sizeof(struct x11drv_escape_get_drawable))
343 struct x11drv_escape_get_drawable *data = out_data;
344 data->drawable = physDev->drawable;
345 return TRUE;
347 break;
348 case X11DRV_FLUSH_GL_DRAWABLE:
349 if (in_count >= sizeof(struct x11drv_escape_flush_gl_drawable))
351 const struct x11drv_escape_flush_gl_drawable *data = in_data;
352 RECT rect = physDev->dc_rect;
354 OffsetRect( &rect, -physDev->dc_rect.left, -physDev->dc_rect.top );
355 /* The GL drawable may be lagged behind if we don't flush first, so
356 * flush the display make sure we copy up-to-date data */
357 XFlush( gdi_display );
358 XSetFunction( gdi_display, physDev->gc, GXcopy );
359 XCopyArea( gdi_display, data->gl_drawable, physDev->drawable, physDev->gc,
360 0, 0, rect.right, rect.bottom,
361 physDev->dc_rect.left, physDev->dc_rect.top );
362 add_device_bounds( physDev, &rect );
363 return TRUE;
365 break;
366 case X11DRV_START_EXPOSURES:
367 XSetGraphicsExposures( gdi_display, physDev->gc, True );
368 physDev->exposures = 0;
369 return TRUE;
370 case X11DRV_END_EXPOSURES:
371 if (out_count >= sizeof(HRGN))
373 HRGN hrgn = 0, tmp = 0;
375 XSetGraphicsExposures( gdi_display, physDev->gc, False );
376 if (physDev->exposures)
378 for (;;)
380 XEvent event;
382 XWindowEvent( gdi_display, physDev->drawable, ~0, &event );
383 if (event.type == NoExpose) break;
384 if (event.type == GraphicsExpose)
386 RECT rect;
388 rect.left = event.xgraphicsexpose.x - physDev->dc_rect.left;
389 rect.top = event.xgraphicsexpose.y - physDev->dc_rect.top;
390 rect.right = rect.left + event.xgraphicsexpose.width;
391 rect.bottom = rect.top + event.xgraphicsexpose.height;
392 if (GetLayout( dev->hdc ) & LAYOUT_RTL)
393 mirror_rect( &physDev->dc_rect, &rect );
395 TRACE( "got %s count %d\n", wine_dbgstr_rect(&rect),
396 event.xgraphicsexpose.count );
398 if (!tmp) tmp = CreateRectRgnIndirect( &rect );
399 else SetRectRgn( tmp, rect.left, rect.top, rect.right, rect.bottom );
400 if (hrgn) CombineRgn( hrgn, hrgn, tmp, RGN_OR );
401 else
403 hrgn = tmp;
404 tmp = 0;
406 if (!event.xgraphicsexpose.count) break;
408 else
410 ERR( "got unexpected event %d\n", event.type );
411 break;
414 if (tmp) DeleteObject( tmp );
416 *(HRGN *)out_data = hrgn;
417 return TRUE;
419 break;
420 default:
421 break;
424 break;
426 return 0;
429 /**********************************************************************
430 * X11DRV_wine_get_wgl_driver
432 static struct opengl_funcs * X11DRV_wine_get_wgl_driver( PHYSDEV dev, UINT version )
434 struct opengl_funcs *ret;
436 if (!(ret = get_glx_driver( version )))
438 dev = GET_NEXT_PHYSDEV( dev, wine_get_wgl_driver );
439 ret = dev->funcs->wine_get_wgl_driver( dev, version );
441 return ret;
445 static const struct gdi_dc_funcs x11drv_funcs =
447 NULL, /* pAbortDoc */
448 NULL, /* pAbortPath */
449 NULL, /* pAlphaBlend */
450 NULL, /* pAngleArc */
451 X11DRV_Arc, /* pArc */
452 NULL, /* pArcTo */
453 NULL, /* pBeginPath */
454 NULL, /* pBlendImage */
455 X11DRV_Chord, /* pChord */
456 NULL, /* pCloseFigure */
457 X11DRV_CreateCompatibleDC, /* pCreateCompatibleDC */
458 X11DRV_CreateDC, /* pCreateDC */
459 X11DRV_DeleteDC, /* pDeleteDC */
460 NULL, /* pDeleteObject */
461 NULL, /* pDeviceCapabilities */
462 X11DRV_Ellipse, /* pEllipse */
463 NULL, /* pEndDoc */
464 NULL, /* pEndPage */
465 NULL, /* pEndPath */
466 NULL, /* pEnumFonts */
467 X11DRV_EnumICMProfiles, /* pEnumICMProfiles */
468 NULL, /* pExcludeClipRect */
469 NULL, /* pExtDeviceMode */
470 X11DRV_ExtEscape, /* pExtEscape */
471 X11DRV_ExtFloodFill, /* pExtFloodFill */
472 NULL, /* pExtSelectClipRgn */
473 NULL, /* pExtTextOut */
474 NULL, /* pFillPath */
475 NULL, /* pFillRgn */
476 NULL, /* pFlattenPath */
477 NULL, /* pFontIsLinked */
478 NULL, /* pFrameRgn */
479 NULL, /* pGdiComment */
480 NULL, /* pGdiRealizationInfo */
481 NULL, /* pGetBoundsRect */
482 NULL, /* pGetCharABCWidths */
483 NULL, /* pGetCharABCWidthsI */
484 NULL, /* pGetCharWidth */
485 X11DRV_GetDeviceCaps, /* pGetDeviceCaps */
486 X11DRV_GetDeviceGammaRamp, /* pGetDeviceGammaRamp */
487 NULL, /* pGetFontData */
488 NULL, /* pGetFontUnicodeRanges */
489 NULL, /* pGetGlyphIndices */
490 NULL, /* pGetGlyphOutline */
491 X11DRV_GetICMProfile, /* pGetICMProfile */
492 X11DRV_GetImage, /* pGetImage */
493 NULL, /* pGetKerningPairs */
494 X11DRV_GetNearestColor, /* pGetNearestColor */
495 NULL, /* pGetOutlineTextMetrics */
496 NULL, /* pGetPixel */
497 X11DRV_GetSystemPaletteEntries, /* pGetSystemPaletteEntries */
498 NULL, /* pGetTextCharsetInfo */
499 NULL, /* pGetTextExtentExPoint */
500 NULL, /* pGetTextExtentExPointI */
501 NULL, /* pGetTextFace */
502 NULL, /* pGetTextMetrics */
503 X11DRV_GradientFill, /* pGradientFill */
504 NULL, /* pIntersectClipRect */
505 NULL, /* pInvertRgn */
506 X11DRV_LineTo, /* pLineTo */
507 NULL, /* pModifyWorldTransform */
508 NULL, /* pMoveTo */
509 NULL, /* pOffsetClipRgn */
510 NULL, /* pOffsetViewportOrg */
511 NULL, /* pOffsetWindowOrg */
512 X11DRV_PaintRgn, /* pPaintRgn */
513 X11DRV_PatBlt, /* pPatBlt */
514 X11DRV_Pie, /* pPie */
515 NULL, /* pPolyBezier */
516 NULL, /* pPolyBezierTo */
517 NULL, /* pPolyDraw */
518 X11DRV_PolyPolygon, /* pPolyPolygon */
519 X11DRV_PolyPolyline, /* pPolyPolyline */
520 X11DRV_Polygon, /* pPolygon */
521 NULL, /* pPolyline */
522 NULL, /* pPolylineTo */
523 X11DRV_PutImage, /* pPutImage */
524 X11DRV_RealizeDefaultPalette, /* pRealizeDefaultPalette */
525 X11DRV_RealizePalette, /* pRealizePalette */
526 X11DRV_Rectangle, /* pRectangle */
527 NULL, /* pResetDC */
528 NULL, /* pRestoreDC */
529 X11DRV_RoundRect, /* pRoundRect */
530 NULL, /* pSaveDC */
531 NULL, /* pScaleViewportExt */
532 NULL, /* pScaleWindowExt */
533 NULL, /* pSelectBitmap */
534 X11DRV_SelectBrush, /* pSelectBrush */
535 NULL, /* pSelectClipPath */
536 NULL, /* pSelectFont */
537 NULL, /* pSelectPalette */
538 X11DRV_SelectPen, /* pSelectPen */
539 NULL, /* pSetArcDirection */
540 NULL, /* pSetBkColor */
541 NULL, /* pSetBkMode */
542 X11DRV_SetBoundsRect, /* pSetBoundsRect */
543 X11DRV_SetDCBrushColor, /* pSetDCBrushColor */
544 X11DRV_SetDCPenColor, /* pSetDCPenColor */
545 NULL, /* pSetDIBitsToDevice */
546 X11DRV_SetDeviceClipping, /* pSetDeviceClipping */
547 X11DRV_SetDeviceGammaRamp, /* pSetDeviceGammaRamp */
548 NULL, /* pSetLayout */
549 NULL, /* pSetMapMode */
550 NULL, /* pSetMapperFlags */
551 X11DRV_SetPixel, /* pSetPixel */
552 NULL, /* pSetPolyFillMode */
553 NULL, /* pSetROP2 */
554 NULL, /* pSetRelAbs */
555 NULL, /* pSetStretchBltMode */
556 NULL, /* pSetTextAlign */
557 NULL, /* pSetTextCharacterExtra */
558 NULL, /* pSetTextColor */
559 NULL, /* pSetTextJustification */
560 NULL, /* pSetViewportExt */
561 NULL, /* pSetViewportOrg */
562 NULL, /* pSetWindowExt */
563 NULL, /* pSetWindowOrg */
564 NULL, /* pSetWorldTransform */
565 NULL, /* pStartDoc */
566 NULL, /* pStartPage */
567 X11DRV_StretchBlt, /* pStretchBlt */
568 NULL, /* pStretchDIBits */
569 NULL, /* pStrokeAndFillPath */
570 NULL, /* pStrokePath */
571 X11DRV_UnrealizePalette, /* pUnrealizePalette */
572 NULL, /* pWidenPath */
573 X11DRV_wine_get_wgl_driver, /* wine_get_wgl_driver */
574 GDI_PRIORITY_GRAPHICS_DRV /* priority */
578 /******************************************************************************
579 * X11DRV_get_gdi_driver
581 const struct gdi_dc_funcs * CDECL X11DRV_get_gdi_driver( unsigned int version )
583 if (version != WINE_GDI_DRIVER_VERSION)
585 ERR( "version mismatch, gdi32 wants %u but winex11 has %u\n", version, WINE_GDI_DRIVER_VERSION );
586 return NULL;
588 return &x11drv_funcs;