2 * X11 graphics driver initialisation functions
4 * Copyright 1996 Alexandre Julliard
15 #include "debugtools.h"
20 DEFAULT_DEBUG_CHANNEL(x11drv);
22 static BOOL X11DRV_CreateDC( DC *dc, LPCSTR driver, LPCSTR device,
23 LPCSTR output, const DEVMODEA* initData );
24 static BOOL X11DRV_DeleteDC( DC *dc );
26 static INT X11DRV_Escape( DC *dc, INT nEscape, INT cbInput,
27 SEGPTR lpInData, SEGPTR lpOutData );
29 const DC_FUNCTIONS X11DRV_DC_Funcs =
32 NULL, /* pAbortPath */
34 X11DRV_Arc, /* pArc */
36 NULL, /* pBeginPath */
37 X11DRV_BitBlt, /* pBitBlt */
38 X11DRV_BitmapBits, /* pBitmapBits */
39 X11DRV_ChoosePixelFormat, /* pChoosePixelFormat */
40 X11DRV_Chord, /* pChord */
41 NULL, /* pCloseFigure */
42 X11DRV_CreateBitmap, /* pCreateBitmap */
43 X11DRV_CreateDC, /* pCreateDC */
44 X11DRV_DIB_CreateDIBSection, /* pCreateDIBSection */
45 X11DRV_DIB_CreateDIBSection16, /* pCreateDIBSection16 */
46 X11DRV_DeleteDC, /* pDeleteDC */
47 X11DRV_DeleteObject, /* pDeleteObject */
48 X11DRV_DescribePixelFormat, /* pDescribePixelFormat */
49 NULL, /* pDeviceCapabilities */
50 X11DRV_Ellipse, /* pEllipse */
54 X11DRV_EnumDeviceFonts, /* pEnumDeviceFonts */
55 X11DRV_Escape, /* pEscape */
56 NULL, /* pExcludeClipRect */
57 NULL, /* pExtDeviceMode */
58 X11DRV_ExtFloodFill, /* pExtFloodFill */
59 X11DRV_ExtTextOut, /* pExtTextOut */
62 NULL, /* pFlattenPath */
64 X11DRV_GetCharWidth, /* pGetCharWidth */
65 X11DRV_GetDCOrgEx, /* pGetDCOrgEx */
66 X11DRV_GetDeviceGammaRamp, /* pGetDeviceGammaRamp */
67 X11DRV_GetPixel, /* pGetPixel */
68 X11DRV_GetPixelFormat, /* pGetPixelFormat */
69 X11DRV_GetTextExtentPoint, /* pGetTextExtentPoint */
70 X11DRV_GetTextMetrics, /* pGetTextMetrics */
71 NULL, /* pIntersectClipRect */
72 NULL, /* pInvertRgn */
73 X11DRV_LineTo, /* pLineTo */
75 NULL, /* pOffsetClipRgn */
76 NULL, /* pOffsetViewportOrg (optional) */
77 NULL, /* pOffsetWindowOrg (optional) */
78 X11DRV_PaintRgn, /* pPaintRgn */
79 X11DRV_PatBlt, /* pPatBlt */
80 X11DRV_Pie, /* pPie */
81 NULL, /* pPolyBezier */
82 NULL, /* pPolyBezierTo */
84 X11DRV_PolyPolygon, /* pPolyPolygon */
85 X11DRV_PolyPolyline, /* pPolyPolyline */
86 X11DRV_Polygon, /* pPolygon */
87 X11DRV_Polyline, /* pPolyline */
88 NULL, /* pPolylineTo */
89 NULL, /* pRealizePalette */
90 X11DRV_Rectangle, /* pRectangle */
91 NULL, /* pRestoreDC */
92 X11DRV_RoundRect, /* pRoundRect */
94 NULL, /* pScaleViewportExt (optional) */
95 NULL, /* pScaleWindowExt (optional) */
96 NULL, /* pSelectClipPath */
97 NULL, /* pSelectClipRgn */
98 X11DRV_SelectObject, /* pSelectObject */
99 NULL, /* pSelectPalette */
100 X11DRV_SetBkColor, /* pSetBkColor */
101 NULL, /* pSetBkMode */
102 X11DRV_SetDeviceClipping, /* pSetDeviceClipping */
103 X11DRV_SetDeviceGammaRamp, /* pSetDeviceGammaRamp */
104 X11DRV_SetDIBitsToDevice, /* pSetDIBitsToDevice */
105 NULL, /* pSetMapMode (optional) */
106 NULL, /* pSetMapperFlags */
107 X11DRV_SetPixel, /* pSetPixel */
108 X11DRV_SetPixelFormat, /* pSetPixelFormat */
109 NULL, /* pSetPolyFillMode */
111 NULL, /* pSetRelAbs */
112 NULL, /* pSetStretchBltMode */
113 NULL, /* pSetTextAlign */
114 NULL, /* pSetTextCharacterExtra */
115 X11DRV_SetTextColor, /* pSetTextColor */
116 NULL, /* pSetTextJustification */
117 NULL, /* pSetViewportExt (optional) */
118 NULL, /* pSetViewportOrg (optional) */
119 NULL, /* pSetWindowExt (optional) */
120 NULL, /* pSetWindowOrg (optional) */
121 NULL, /* pStartDoc */
122 NULL, /* pStartPage */
123 X11DRV_StretchBlt, /* pStretchBlt */
124 NULL, /* pStretchDIBits */
125 NULL, /* pStrokeAndFillPath */
126 NULL, /* pStrokePath */
127 X11DRV_SwapBuffers, /* pSwapBuffers */
128 NULL /* pWidenPath */
131 BITMAP_DRIVER X11DRV_BITMAP_Driver =
133 X11DRV_DIB_SetDIBits,
134 X11DRV_DIB_GetDIBits,
135 X11DRV_DIB_DeleteDIBSection,
136 X11DRV_DIB_SetDIBColorTable,
137 X11DRV_DIB_GetDIBColorTable,
142 PALETTE_DRIVER X11DRV_PALETTE_Driver =
144 X11DRV_PALETTE_SetMapping,
145 X11DRV_PALETTE_UpdateMapping,
146 X11DRV_PALETTE_IsDark
149 DeviceCaps X11DRV_DevCaps = {
151 /* technology */ DT_RASDISPLAY,
152 /* size, resolution */ 0, 0, 0, 0, 0,
153 /* device objects */ 1, -1, -1, 0, 0, -1, 1152,
154 /* curve caps */ CC_CIRCLES | CC_PIE | CC_CHORD | CC_ELLIPSES |
155 CC_WIDE | CC_STYLED | CC_WIDESTYLED | CC_INTERIORS | CC_ROUNDRECT,
156 /* line caps */ LC_POLYLINE | LC_MARKER | LC_POLYMARKER | LC_WIDE |
157 LC_STYLED | LC_WIDESTYLED | LC_INTERIORS,
158 /* polygon caps */ PC_POLYGON | PC_RECTANGLE | PC_WINDPOLYGON |
159 PC_SCANLINE | PC_WIDE | PC_STYLED | PC_WIDESTYLED | PC_INTERIORS,
161 /* regions */ CP_REGION,
162 /* raster caps */ RC_BITBLT | RC_BANDING | RC_SCALING | RC_BITMAP64 |
163 RC_DI_BITMAP | RC_DIBTODEV | RC_BIGFONT | RC_STRETCHBLT | RC_STRETCHDIB | RC_DEVBITS,
164 /* aspects */ 36, 36, 51,
166 /* log pixels */ 0, 0,
168 /* palette size */ 0,
172 Display *gdi_display; /* display to use for all GDI functions */
175 /**********************************************************************
176 * X11DRV_GDI_Initialize
178 BOOL X11DRV_GDI_Initialize( Display *display )
180 Screen *screen = DefaultScreenOfDisplay(display);
182 gdi_display = display;
183 BITMAP_Driver = &X11DRV_BITMAP_Driver;
184 PALETTE_Driver = &X11DRV_PALETTE_Driver;
186 /* FIXME: colormap management should be merged with the X11DRV */
188 if( !X11DRV_PALETTE_Init() ) return FALSE;
190 if( !X11DRV_OBM_Init() ) return FALSE;
192 /* Finish up device caps */
194 X11DRV_DevCaps.version = 0x300;
195 X11DRV_DevCaps.horzSize = WidthMMOfScreen(screen) * screen_width / WidthOfScreen(screen);
196 X11DRV_DevCaps.vertSize = HeightMMOfScreen(screen) * screen_height / HeightOfScreen(screen);
197 X11DRV_DevCaps.horzRes = screen_width;
198 X11DRV_DevCaps.vertRes = screen_height;
199 X11DRV_DevCaps.bitsPixel = screen_depth;
201 /* MSDN: Number of entries in the device's color table, if the device has
202 * a color depth of no more than 8 bits per pixel.For devices with greater
203 * color depths, -1 is returned.
205 X11DRV_DevCaps.numColors = (screen_depth>8)?-1:(1<<screen_depth);
207 /* Resolution will be adjusted during the font init */
209 X11DRV_DevCaps.logPixelsX = (int)(X11DRV_DevCaps.horzRes * 25.4 / X11DRV_DevCaps.horzSize);
210 X11DRV_DevCaps.logPixelsY = (int)(X11DRV_DevCaps.vertRes * 25.4 / X11DRV_DevCaps.vertSize);
212 /* Create default bitmap */
214 if (!X11DRV_BITMAP_Init()) return FALSE;
216 /* Initialize fonts and text caps */
218 if (!X11DRV_FONT_Init( &X11DRV_DevCaps )) return FALSE;
220 return DRIVER_RegisterDriver( "DISPLAY", &X11DRV_DC_Funcs );
223 /**********************************************************************
224 * X11DRV_GDI_Finalize
226 void X11DRV_GDI_Finalize(void)
228 X11DRV_PALETTE_Cleanup();
229 XCloseDisplay( gdi_display );
233 /**********************************************************************
236 static BOOL X11DRV_CreateDC( DC *dc, LPCSTR driver, LPCSTR device,
237 LPCSTR output, const DEVMODEA* initData )
239 X11DRV_PDEVICE *physDev;
241 dc->physDev = physDev = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
244 ERR("Can't allocate physDev\n");
248 dc->devCaps = &X11DRV_DevCaps;
249 if (dc->flags & DC_MEMORY)
251 BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( dc->hBitmap, BITMAP_MAGIC );
254 HeapFree( GetProcessHeap(), 0, physDev );
257 if (!bmp->physBitmap) X11DRV_CreateBitmap( dc->hBitmap );
258 physDev->drawable = (Pixmap)bmp->physBitmap;
259 physDev->gc = TSXCreateGC( gdi_display, physDev->drawable, 0, NULL );
260 dc->bitsPerPixel = bmp->bitmap.bmBitsPixel;
261 dc->totalExtent.left = 0;
262 dc->totalExtent.top = 0;
263 dc->totalExtent.right = bmp->bitmap.bmWidth;
264 dc->totalExtent.bottom = bmp->bitmap.bmHeight;
265 GDI_ReleaseObj( dc->hBitmap );
269 physDev->drawable = root_window;
270 physDev->gc = TSXCreateGC( gdi_display, physDev->drawable, 0, NULL );
271 dc->bitsPerPixel = screen_depth;
272 dc->totalExtent.left = 0;
273 dc->totalExtent.top = 0;
274 dc->totalExtent.right = screen_width;
275 dc->totalExtent.bottom = screen_height;
278 physDev->current_pf = 0;
279 physDev->used_visuals = 0;
281 if (!(dc->hVisRgn = CreateRectRgnIndirect( &dc->totalExtent )))
283 TSXFreeGC( gdi_display, physDev->gc );
284 HeapFree( GetProcessHeap(), 0, physDev );
289 XSetGraphicsExposures( gdi_display, physDev->gc, False );
290 XSetSubwindowMode( gdi_display, physDev->gc, IncludeInferiors );
291 XFlush( gdi_display );
297 /**********************************************************************
300 static BOOL X11DRV_DeleteDC( DC *dc )
302 X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
304 XFreeGC( gdi_display, physDev->gc );
305 while (physDev->used_visuals-- > 0)
306 XFree(physDev->visuals[physDev->used_visuals]);
308 HeapFree( GetProcessHeap(), 0, physDev );
313 /**********************************************************************
316 static INT X11DRV_Escape( DC *dc, INT nEscape, INT cbInput,
317 SEGPTR lpInData, SEGPTR lpOutData )
321 case QUERYESCSUPPORT:
324 LPINT16 lpEscape = MapSL(lpInData);
328 return DD_HAL_VERSION;
333 case GETSCALINGFACTOR:
336 LPPOINT16 lppt = MapSL(lpOutData);
337 lppt->x = lppt->y = 0; /* no device scaling */
345 LPDCICMD lpCmd = MapSL(lpInData);
346 if (lpCmd->dwVersion != DD_VERSION) break;
347 return X11DRV_DCICommand(cbInput, lpCmd, MapSL(lpOutData));