mshtml: Store scheme in nsWineURI instead of nsChannel.
[wine.git] / dlls / winex11.drv / init.c
blob7dcf8da81dd1bc126c6de6d5c5e468cec4b89fec
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 wine_tsx11_lock();
96 stock_bitmap_pixmap = XCreatePixmap( gdi_display, root_window, 1, 1, 1 );
97 wine_tsx11_unlock();
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;
124 wine_tsx11_lock();
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 );
130 wine_tsx11_unlock();
131 return physDev;
134 /**********************************************************************
135 * X11DRV_CreateDC
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 SetRect( &physDev->dc_rect, 0, 0, virtual_screen_rect.right - virtual_screen_rect.left,
148 virtual_screen_rect.bottom - virtual_screen_rect.top );
149 push_dc_driver( pdev, &physDev->dev, &x11drv_funcs );
150 if (xrender_funcs && !xrender_funcs->pCreateDC( pdev, driver, device, output, initData )) return FALSE;
151 if (glx_funcs && !glx_funcs->pCreateDC( pdev, driver, device, output, initData )) return FALSE;
152 return TRUE;
156 /**********************************************************************
157 * X11DRV_CreateCompatibleDC
159 static BOOL X11DRV_CreateCompatibleDC( PHYSDEV orig, PHYSDEV *pdev )
161 const struct gdi_dc_funcs *glx_funcs = get_glx_driver();
162 X11DRV_PDEVICE *physDev = create_x11_physdev( stock_bitmap_pixmap );
164 if (!physDev) return FALSE;
166 physDev->depth = 1;
167 SetRect( &physDev->dc_rect, 0, 0, 1, 1 );
168 push_dc_driver( pdev, &physDev->dev, &x11drv_funcs );
169 if (orig) return TRUE; /* we already went through Xrender if we have an orig device */
170 if (xrender_funcs && !xrender_funcs->pCreateCompatibleDC( NULL, pdev )) return FALSE;
171 if (glx_funcs && !glx_funcs->pCreateCompatibleDC( NULL, pdev )) return FALSE;
172 return TRUE;
176 /**********************************************************************
177 * X11DRV_DeleteDC
179 static BOOL X11DRV_DeleteDC( PHYSDEV dev )
181 X11DRV_PDEVICE *physDev = get_x11drv_dev( dev );
183 wine_tsx11_lock();
184 XFreeGC( gdi_display, physDev->gc );
185 wine_tsx11_unlock();
186 HeapFree( GetProcessHeap(), 0, physDev );
187 return TRUE;
191 void add_device_bounds( X11DRV_PDEVICE *dev, const RECT *rect )
193 RECT rc;
195 if (!dev->bounds) return;
196 if (dev->region && GetRgnBox( dev->region, &rc ))
198 if (IntersectRect( &rc, &rc, rect )) add_bounds_rect( dev->bounds, &rc );
200 else add_bounds_rect( dev->bounds, rect );
203 /***********************************************************************
204 * X11DRV_SetBoundsRect
206 static UINT X11DRV_SetBoundsRect( PHYSDEV dev, RECT *rect, UINT flags )
208 X11DRV_PDEVICE *pdev = get_x11drv_dev( dev );
210 if (flags & DCB_DISABLE) pdev->bounds = NULL;
211 else if (flags & DCB_ENABLE) pdev->bounds = rect;
212 return DCB_RESET; /* we don't have device-specific bounds */
216 /***********************************************************************
217 * GetDeviceCaps (X11DRV.@)
219 static INT X11DRV_GetDeviceCaps( PHYSDEV dev, INT cap )
221 switch(cap)
223 case DRIVERVERSION:
224 return 0x300;
225 case TECHNOLOGY:
226 return DT_RASDISPLAY;
227 case HORZSIZE:
228 return horz_size;
229 case VERTSIZE:
230 return vert_size;
231 case HORZRES:
232 return screen_width;
233 case VERTRES:
234 return screen_height;
235 case DESKTOPHORZRES:
236 return virtual_screen_rect.right - virtual_screen_rect.left;
237 case DESKTOPVERTRES:
238 return virtual_screen_rect.bottom - virtual_screen_rect.top;
239 case BITSPIXEL:
240 return screen_bpp;
241 case PLANES:
242 return 1;
243 case NUMBRUSHES:
244 return -1;
245 case NUMPENS:
246 return -1;
247 case NUMMARKERS:
248 return 0;
249 case NUMFONTS:
250 return 0;
251 case NUMCOLORS:
252 /* MSDN: Number of entries in the device's color table, if the device has
253 * a color depth of no more than 8 bits per pixel.For devices with greater
254 * color depths, -1 is returned. */
255 return (screen_depth > 8) ? -1 : (1 << screen_depth);
256 case PDEVICESIZE:
257 return sizeof(X11DRV_PDEVICE);
258 case CURVECAPS:
259 return (CC_CIRCLES | CC_PIE | CC_CHORD | CC_ELLIPSES | CC_WIDE |
260 CC_STYLED | CC_WIDESTYLED | CC_INTERIORS | CC_ROUNDRECT);
261 case LINECAPS:
262 return (LC_POLYLINE | LC_MARKER | LC_POLYMARKER | LC_WIDE |
263 LC_STYLED | LC_WIDESTYLED | LC_INTERIORS);
264 case POLYGONALCAPS:
265 return (PC_POLYGON | PC_RECTANGLE | PC_WINDPOLYGON | PC_SCANLINE |
266 PC_WIDE | PC_STYLED | PC_WIDESTYLED | PC_INTERIORS);
267 case TEXTCAPS:
268 return (TC_OP_CHARACTER | TC_OP_STROKE | TC_CP_STROKE |
269 TC_CR_ANY | TC_SF_X_YINDEP | TC_SA_DOUBLE | TC_SA_INTEGER |
270 TC_SA_CONTIN | TC_UA_ABLE | TC_SO_ABLE | TC_RA_ABLE | TC_VA_ABLE);
271 case CLIPCAPS:
272 return CP_REGION;
273 case COLORRES:
274 /* The observed correspondence between BITSPIXEL and COLORRES is:
275 * BITSPIXEL: 8 -> COLORRES: 18
276 * BITSPIXEL: 16 -> COLORRES: 16
277 * BITSPIXEL: 24 -> COLORRES: 24
278 * BITSPIXEL: 32 -> COLORRES: 24 */
279 return (screen_bpp <= 8) ? 18 : min( 24, screen_bpp );
280 case RASTERCAPS:
281 return (RC_BITBLT | RC_BANDING | RC_SCALING | RC_BITMAP64 | RC_DI_BITMAP |
282 RC_DIBTODEV | RC_BIGFONT | RC_STRETCHBLT | RC_STRETCHDIB | RC_DEVBITS |
283 (palette_size ? RC_PALETTE : 0));
284 case SHADEBLENDCAPS:
285 return (SB_GRAD_RECT | SB_GRAD_TRI | SB_CONST_ALPHA | SB_PIXEL_ALPHA);
286 case ASPECTX:
287 case ASPECTY:
288 return 36;
289 case ASPECTXY:
290 return 51;
291 case LOGPIXELSX:
292 return log_pixels_x;
293 case LOGPIXELSY:
294 return log_pixels_y;
295 case CAPS1:
296 FIXME("(%p): CAPS1 is unimplemented, will return 0\n", dev->hdc );
297 /* please see wingdi.h for the possible bit-flag values that need
298 to be returned. */
299 return 0;
300 case SIZEPALETTE:
301 return palette_size;
302 case NUMRESERVED:
303 case PHYSICALWIDTH:
304 case PHYSICALHEIGHT:
305 case PHYSICALOFFSETX:
306 case PHYSICALOFFSETY:
307 case SCALINGFACTORX:
308 case SCALINGFACTORY:
309 case VREFRESH:
310 case BLTALIGNMENT:
311 return 0;
312 default:
313 FIXME("(%p): unsupported capability %d, will return 0\n", dev->hdc, cap );
314 return 0;
319 /**********************************************************************
320 * ExtEscape (X11DRV.@)
322 static INT X11DRV_ExtEscape( PHYSDEV dev, INT escape, INT in_count, LPCVOID in_data,
323 INT out_count, LPVOID out_data )
325 X11DRV_PDEVICE *physDev = get_x11drv_dev( dev );
327 switch(escape)
329 case QUERYESCSUPPORT:
330 if (in_data)
332 switch (*(const INT *)in_data)
334 case DCICOMMAND:
335 return DD_HAL_VERSION;
336 case X11DRV_ESCAPE:
337 return TRUE;
340 break;
342 case X11DRV_ESCAPE:
343 if (in_data && in_count >= sizeof(enum x11drv_escape_codes))
345 switch(*(const enum x11drv_escape_codes *)in_data)
347 case X11DRV_SET_DRAWABLE:
348 if (in_count >= sizeof(struct x11drv_escape_set_drawable))
350 const struct x11drv_escape_set_drawable *data = in_data;
351 physDev->dc_rect = data->dc_rect;
352 physDev->drawable = data->drawable;
353 wine_tsx11_lock();
354 XSetSubwindowMode( gdi_display, physDev->gc, data->mode );
355 wine_tsx11_unlock();
356 TRACE( "SET_DRAWABLE hdc %p drawable %lx dc_rect %s\n",
357 dev->hdc, physDev->drawable, wine_dbgstr_rect(&physDev->dc_rect) );
358 return TRUE;
360 break;
361 case X11DRV_GET_DRAWABLE:
362 if (out_count >= sizeof(struct x11drv_escape_get_drawable))
364 struct x11drv_escape_get_drawable *data = out_data;
365 data->drawable = physDev->drawable;
366 return TRUE;
368 break;
369 case X11DRV_START_EXPOSURES:
370 wine_tsx11_lock();
371 XSetGraphicsExposures( gdi_display, physDev->gc, True );
372 wine_tsx11_unlock();
373 physDev->exposures = 0;
374 return TRUE;
375 case X11DRV_END_EXPOSURES:
376 if (out_count >= sizeof(HRGN))
378 HRGN hrgn = 0, tmp = 0;
380 wine_tsx11_lock();
381 XSetGraphicsExposures( gdi_display, physDev->gc, False );
382 wine_tsx11_unlock();
383 if (physDev->exposures)
385 for (;;)
387 XEvent event;
389 wine_tsx11_lock();
390 XWindowEvent( gdi_display, physDev->drawable, ~0, &event );
391 wine_tsx11_unlock();
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;
439 static inline void opengl_error(void)
441 static int warned;
442 if (!warned++) ERR("No OpenGL support compiled in.\n");
445 /***********************************************************************
446 * X11DRV_DescribePixelFormat
448 static int X11DRV_DescribePixelFormat( PHYSDEV dev, int fmt, UINT size, PIXELFORMATDESCRIPTOR *ppfd )
450 opengl_error();
451 return 0;
454 /***********************************************************************
455 * X11DRV_SetPixelFormat
457 static BOOL X11DRV_SetPixelFormat( PHYSDEV dev, int fmt, const PIXELFORMATDESCRIPTOR *ppfd )
459 opengl_error();
460 return FALSE;
464 static const struct gdi_dc_funcs x11drv_funcs =
466 NULL, /* pAbortDoc */
467 NULL, /* pAbortPath */
468 NULL, /* pAlphaBlend */
469 NULL, /* pAngleArc */
470 X11DRV_Arc, /* pArc */
471 NULL, /* pArcTo */
472 NULL, /* pBeginPath */
473 NULL, /* pBlendImage */
474 X11DRV_Chord, /* pChord */
475 NULL, /* pCloseFigure */
476 X11DRV_CreateCompatibleDC, /* pCreateCompatibleDC */
477 X11DRV_CreateDC, /* pCreateDC */
478 X11DRV_DeleteDC, /* pDeleteDC */
479 NULL, /* pDeleteObject */
480 X11DRV_DescribePixelFormat, /* pDescribePixelFormat */
481 NULL, /* pDeviceCapabilities */
482 X11DRV_Ellipse, /* pEllipse */
483 NULL, /* pEndDoc */
484 NULL, /* pEndPage */
485 NULL, /* pEndPath */
486 NULL, /* pEnumFonts */
487 X11DRV_EnumICMProfiles, /* pEnumICMProfiles */
488 NULL, /* pExcludeClipRect */
489 NULL, /* pExtDeviceMode */
490 X11DRV_ExtEscape, /* pExtEscape */
491 X11DRV_ExtFloodFill, /* pExtFloodFill */
492 NULL, /* pExtSelectClipRgn */
493 NULL, /* pExtTextOut */
494 NULL, /* pFillPath */
495 NULL, /* pFillRgn */
496 NULL, /* pFlattenPath */
497 NULL, /* pFontIsLinked */
498 NULL, /* pFrameRgn */
499 NULL, /* pGdiComment */
500 NULL, /* pGdiRealizationInfo */
501 NULL, /* pGetBoundsRect */
502 NULL, /* pGetCharABCWidths */
503 NULL, /* pGetCharABCWidthsI */
504 NULL, /* pGetCharWidth */
505 X11DRV_GetDeviceCaps, /* pGetDeviceCaps */
506 X11DRV_GetDeviceGammaRamp, /* pGetDeviceGammaRamp */
507 NULL, /* pGetFontData */
508 NULL, /* pGetFontUnicodeRanges */
509 NULL, /* pGetGlyphIndices */
510 NULL, /* pGetGlyphOutline */
511 X11DRV_GetICMProfile, /* pGetICMProfile */
512 X11DRV_GetImage, /* pGetImage */
513 NULL, /* pGetKerningPairs */
514 X11DRV_GetNearestColor, /* pGetNearestColor */
515 NULL, /* pGetOutlineTextMetrics */
516 NULL, /* pGetPixel */
517 X11DRV_GetSystemPaletteEntries, /* pGetSystemPaletteEntries */
518 NULL, /* pGetTextCharsetInfo */
519 NULL, /* pGetTextExtentExPoint */
520 NULL, /* pGetTextExtentExPointI */
521 NULL, /* pGetTextFace */
522 NULL, /* pGetTextMetrics */
523 X11DRV_GradientFill, /* pGradientFill */
524 NULL, /* pIntersectClipRect */
525 NULL, /* pInvertRgn */
526 X11DRV_LineTo, /* pLineTo */
527 NULL, /* pModifyWorldTransform */
528 NULL, /* pMoveTo */
529 NULL, /* pOffsetClipRgn */
530 NULL, /* pOffsetViewportOrg */
531 NULL, /* pOffsetWindowOrg */
532 X11DRV_PaintRgn, /* pPaintRgn */
533 X11DRV_PatBlt, /* pPatBlt */
534 X11DRV_Pie, /* pPie */
535 NULL, /* pPolyBezier */
536 NULL, /* pPolyBezierTo */
537 NULL, /* pPolyDraw */
538 X11DRV_PolyPolygon, /* pPolyPolygon */
539 X11DRV_PolyPolyline, /* pPolyPolyline */
540 X11DRV_Polygon, /* pPolygon */
541 NULL, /* pPolyline */
542 NULL, /* pPolylineTo */
543 X11DRV_PutImage, /* pPutImage */
544 X11DRV_RealizeDefaultPalette, /* pRealizeDefaultPalette */
545 X11DRV_RealizePalette, /* pRealizePalette */
546 X11DRV_Rectangle, /* pRectangle */
547 NULL, /* pResetDC */
548 NULL, /* pRestoreDC */
549 X11DRV_RoundRect, /* pRoundRect */
550 NULL, /* pSaveDC */
551 NULL, /* pScaleViewportExt */
552 NULL, /* pScaleWindowExt */
553 NULL, /* pSelectBitmap */
554 X11DRV_SelectBrush, /* pSelectBrush */
555 NULL, /* pSelectClipPath */
556 NULL, /* pSelectFont */
557 NULL, /* pSelectPalette */
558 X11DRV_SelectPen, /* pSelectPen */
559 NULL, /* pSetArcDirection */
560 NULL, /* pSetBkColor */
561 NULL, /* pSetBkMode */
562 X11DRV_SetBoundsRect, /* pSetBoundsRect */
563 X11DRV_SetDCBrushColor, /* pSetDCBrushColor */
564 X11DRV_SetDCPenColor, /* pSetDCPenColor */
565 NULL, /* pSetDIBitsToDevice */
566 X11DRV_SetDeviceClipping, /* pSetDeviceClipping */
567 X11DRV_SetDeviceGammaRamp, /* pSetDeviceGammaRamp */
568 NULL, /* pSetLayout */
569 NULL, /* pSetMapMode */
570 NULL, /* pSetMapperFlags */
571 X11DRV_SetPixel, /* pSetPixel */
572 X11DRV_SetPixelFormat, /* pSetPixelFormat */
573 NULL, /* pSetPolyFillMode */
574 NULL, /* pSetROP2 */
575 NULL, /* pSetRelAbs */
576 NULL, /* pSetStretchBltMode */
577 NULL, /* pSetTextAlign */
578 NULL, /* pSetTextCharacterExtra */
579 NULL, /* pSetTextColor */
580 NULL, /* pSetTextJustification */
581 NULL, /* pSetViewportExt */
582 NULL, /* pSetViewportOrg */
583 NULL, /* pSetWindowExt */
584 NULL, /* pSetWindowOrg */
585 NULL, /* pSetWorldTransform */
586 NULL, /* pStartDoc */
587 NULL, /* pStartPage */
588 X11DRV_StretchBlt, /* pStretchBlt */
589 NULL, /* pStretchDIBits */
590 NULL, /* pStrokeAndFillPath */
591 NULL, /* pStrokePath */
592 NULL, /* pSwapBuffers */
593 X11DRV_UnrealizePalette, /* pUnrealizePalette */
594 NULL, /* pWidenPath */
595 NULL, /* wine_get_wgl_driver */
596 GDI_PRIORITY_GRAPHICS_DRV /* priority */
600 /******************************************************************************
601 * X11DRV_get_gdi_driver
603 const struct gdi_dc_funcs * CDECL X11DRV_get_gdi_driver( unsigned int version )
605 if (version != WINE_GDI_DRIVER_VERSION)
607 ERR( "version mismatch, gdi32 wants %u but winex11 has %u\n", version, WINE_GDI_DRIVER_VERSION );
608 return NULL;
610 return &x11drv_funcs;