2 * X11 graphics driver initialisation functions
4 * Copyright 1996 Alexandre Julliard
15 #include "debugtools.h"
19 DEFAULT_DEBUG_CHANNEL(x11drv);
21 static BOOL X11DRV_CreateDC( DC *dc, LPCSTR driver, LPCSTR device,
22 LPCSTR output, const DEVMODEA* initData );
23 static BOOL X11DRV_DeleteDC( DC *dc );
25 static INT X11DRV_Escape( DC *dc, INT nEscape, INT cbInput,
26 SEGPTR lpInData, SEGPTR lpOutData );
28 const DC_FUNCTIONS X11DRV_DC_Funcs =
31 NULL, /* pAbortPath */
33 X11DRV_Arc, /* pArc */
35 NULL, /* pBeginPath */
36 X11DRV_BitBlt, /* pBitBlt */
37 X11DRV_BitmapBits, /* pBitmapBits */
38 X11DRV_ChoosePixelFormat, /* pChoosePixelFormat */
39 X11DRV_Chord, /* pChord */
40 NULL, /* pCloseFigure */
41 X11DRV_CreateBitmap, /* pCreateBitmap */
42 X11DRV_CreateDC, /* pCreateDC */
43 X11DRV_DIB_CreateDIBSection, /* pCreateDIBSection */
44 X11DRV_DIB_CreateDIBSection16, /* pCreateDIBSection16 */
45 X11DRV_DeleteDC, /* pDeleteDC */
46 X11DRV_DeleteObject, /* pDeleteObject */
47 X11DRV_DescribePixelFormat, /* pDescribePixelFormat */
48 NULL, /* pDeviceCapabilities */
49 X11DRV_Ellipse, /* pEllipse */
53 X11DRV_EnumDeviceFonts, /* pEnumDeviceFonts */
54 X11DRV_Escape, /* pEscape */
55 NULL, /* pExcludeClipRect */
56 NULL, /* pExtDeviceMode */
57 X11DRV_ExtFloodFill, /* pExtFloodFill */
58 X11DRV_ExtTextOut, /* pExtTextOut */
61 NULL, /* pFlattenPath */
63 X11DRV_GetCharWidth, /* pGetCharWidth */
64 X11DRV_GetDCOrgEx, /* pGetDCOrgEx */
65 X11DRV_GetPixel, /* pGetPixel */
66 X11DRV_GetPixelFormat, /* pGetPixelFormat */
67 X11DRV_GetTextExtentPoint, /* pGetTextExtentPoint */
68 X11DRV_GetTextMetrics, /* pGetTextMetrics */
69 NULL, /* pIntersectClipRect */
70 NULL, /* pInvertRgn */
71 X11DRV_LineTo, /* pLineTo */
73 NULL, /* pOffsetClipRgn */
74 NULL, /* pOffsetViewportOrg (optional) */
75 NULL, /* pOffsetWindowOrg (optional) */
76 X11DRV_PaintRgn, /* pPaintRgn */
77 X11DRV_PatBlt, /* pPatBlt */
78 X11DRV_Pie, /* pPie */
79 NULL, /* pPolyBezier */
80 NULL, /* pPolyBezierTo */
82 X11DRV_PolyPolygon, /* pPolyPolygon */
83 X11DRV_PolyPolyline, /* pPolyPolyline */
84 X11DRV_Polygon, /* pPolygon */
85 X11DRV_Polyline, /* pPolyline */
86 NULL, /* pPolylineTo */
87 NULL, /* pRealizePalette */
88 X11DRV_Rectangle, /* pRectangle */
89 NULL, /* pRestoreDC */
90 X11DRV_RoundRect, /* pRoundRect */
92 NULL, /* pScaleViewportExt (optional) */
93 NULL, /* pScaleWindowExt (optional) */
94 NULL, /* pSelectClipPath */
95 NULL, /* pSelectClipRgn */
96 X11DRV_SelectObject, /* pSelectObject */
97 NULL, /* pSelectPalette */
98 X11DRV_SetBkColor, /* pSetBkColor */
99 NULL, /* pSetBkMode */
100 X11DRV_SetDeviceClipping, /* pSetDeviceClipping */
101 X11DRV_SetDIBitsToDevice, /* pSetDIBitsToDevice */
102 NULL, /* pSetMapMode (optional) */
103 NULL, /* pSetMapperFlags */
104 X11DRV_SetPixel, /* pSetPixel */
105 X11DRV_SetPixelFormat, /* pSetPixelFormat */
106 NULL, /* pSetPolyFillMode */
108 NULL, /* pSetRelAbs */
109 NULL, /* pSetStretchBltMode */
110 NULL, /* pSetTextAlign */
111 NULL, /* pSetTextCharacterExtra */
112 X11DRV_SetTextColor, /* pSetTextColor */
113 NULL, /* pSetTextJustification */
114 NULL, /* pSetViewportExt (optional) */
115 NULL, /* pSetViewportOrg (optional) */
116 NULL, /* pSetWindowExt (optional) */
117 NULL, /* pSetWindowOrg (optional) */
118 NULL, /* pStartDoc */
119 NULL, /* pStartPage */
120 X11DRV_StretchBlt, /* pStretchBlt */
121 NULL, /* pStretchDIBits */
122 NULL, /* pStrokeAndFillPath */
123 NULL, /* pStrokePath */
124 X11DRV_SwapBuffers, /* pSwapBuffers */
125 NULL /* pWidenPath */
128 BITMAP_DRIVER X11DRV_BITMAP_Driver =
130 X11DRV_DIB_SetDIBits,
131 X11DRV_DIB_GetDIBits,
132 X11DRV_DIB_DeleteDIBSection,
133 X11DRV_DIB_SetDIBColorTable,
134 X11DRV_DIB_GetDIBColorTable,
139 PALETTE_DRIVER X11DRV_PALETTE_Driver =
141 X11DRV_PALETTE_SetMapping,
142 X11DRV_PALETTE_UpdateMapping,
143 X11DRV_PALETTE_IsDark
146 DeviceCaps X11DRV_DevCaps = {
148 /* technology */ DT_RASDISPLAY,
149 /* size, resolution */ 0, 0, 0, 0, 0,
150 /* device objects */ 1, -1, -1, 0, 0, -1, 1152,
151 /* curve caps */ CC_CIRCLES | CC_PIE | CC_CHORD | CC_ELLIPSES |
152 CC_WIDE | CC_STYLED | CC_WIDESTYLED | CC_INTERIORS | CC_ROUNDRECT,
153 /* line caps */ LC_POLYLINE | LC_MARKER | LC_POLYMARKER | LC_WIDE |
154 LC_STYLED | LC_WIDESTYLED | LC_INTERIORS,
155 /* polygon caps */ PC_POLYGON | PC_RECTANGLE | PC_WINDPOLYGON |
156 PC_SCANLINE | PC_WIDE | PC_STYLED | PC_WIDESTYLED | PC_INTERIORS,
158 /* regions */ CP_REGION,
159 /* raster caps */ RC_BITBLT | RC_BANDING | RC_SCALING | RC_BITMAP64 |
160 RC_DI_BITMAP | RC_DIBTODEV | RC_BIGFONT | RC_STRETCHBLT | RC_STRETCHDIB | RC_DEVBITS,
161 /* aspects */ 36, 36, 51,
163 /* log pixels */ 0, 0,
165 /* palette size */ 0,
168 /**********************************************************************
169 * X11DRV_GDI_Initialize
171 BOOL X11DRV_GDI_Initialize(void)
173 BITMAP_Driver = &X11DRV_BITMAP_Driver;
174 PALETTE_Driver = &X11DRV_PALETTE_Driver;
176 /* FIXME: colormap management should be merged with the X11DRV */
178 if( !X11DRV_DIB_Init() ) return FALSE;
180 if( !X11DRV_PALETTE_Init() ) return FALSE;
182 if( !X11DRV_OBM_Init() ) return FALSE;
184 /* Finish up device caps */
187 TRACE("Height = %-4i pxl, %-4i mm, Width = %-4i pxl, %-4i mm\n",
188 HeightOfScreen(X11DRV_GetXScreen()), HeightMMOfScreen(X11DRV_GetXScreen()),
189 WidthOfScreen(X11DRV_GetXScreen()), WidthMMOfScreen(X11DRV_GetXScreen()) );
192 X11DRV_DevCaps.version = 0x300;
193 X11DRV_DevCaps.horzSize = WidthMMOfScreen(screen) * screen_width / WidthOfScreen(screen);
194 X11DRV_DevCaps.vertSize = HeightMMOfScreen(screen) * screen_height / HeightOfScreen(screen);
195 X11DRV_DevCaps.horzRes = screen_width;
196 X11DRV_DevCaps.vertRes = screen_height;
197 X11DRV_DevCaps.bitsPixel = screen_depth;
199 /* MSDN: Number of entries in the device's color table, if the device has
200 * a color depth of no more than 8 bits per pixel.For devices with greater
201 * color depths, -1 is returned.
203 X11DRV_DevCaps.numColors = (screen_depth>8)?-1:(1<<screen_depth);
205 /* Resolution will be adjusted during the font init */
207 X11DRV_DevCaps.logPixelsX = (int)(X11DRV_DevCaps.horzRes * 25.4 / X11DRV_DevCaps.horzSize);
208 X11DRV_DevCaps.logPixelsY = (int)(X11DRV_DevCaps.vertRes * 25.4 / X11DRV_DevCaps.vertSize);
210 /* Create default bitmap */
212 if (!X11DRV_BITMAP_Init()) return FALSE;
214 /* Initialize brush dithering */
216 if (!X11DRV_BRUSH_Init()) return FALSE;
218 /* Initialize fonts and text caps */
220 if (!X11DRV_FONT_Init( &X11DRV_DevCaps )) return FALSE;
222 return DRIVER_RegisterDriver( "DISPLAY", &X11DRV_DC_Funcs );
225 /**********************************************************************
226 * X11DRV_GDI_Finalize
228 void X11DRV_GDI_Finalize(void)
230 X11DRV_PALETTE_Cleanup();
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(display, physDev->drawable, 0, NULL);
260 dc->bitsPerPixel = bmp->bitmap.bmBitsPixel;
262 dc->totalExtent.left = 0;
263 dc->totalExtent.top = 0;
264 dc->totalExtent.right = bmp->bitmap.bmWidth;
265 dc->totalExtent.bottom = bmp->bitmap.bmHeight;
266 dc->hVisRgn = CreateRectRgnIndirect( &dc->totalExtent );
268 GDI_ReleaseObj( dc->hBitmap );
272 physDev->drawable = X11DRV_GetXRootWindow();
273 physDev->gc = TSXCreateGC( display, physDev->drawable, 0, NULL );
274 dc->bitsPerPixel = screen_depth;
276 dc->totalExtent.left = 0;
277 dc->totalExtent.top = 0;
278 dc->totalExtent.right = screen_width;
279 dc->totalExtent.bottom = screen_height;
280 dc->hVisRgn = CreateRectRgnIndirect( &dc->totalExtent );
283 physDev->current_pf = 0;
284 physDev->used_visuals = 0;
288 TSXFreeGC( display, physDev->gc );
289 HeapFree( GetProcessHeap(), 0, physDev );
293 TSXSetGraphicsExposures( display, physDev->gc, False );
294 TSXSetSubwindowMode( display, physDev->gc, IncludeInferiors );
300 /**********************************************************************
303 static BOOL X11DRV_DeleteDC( DC *dc )
305 X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
306 TSXFreeGC( display, physDev->gc );
307 while (physDev->used_visuals-- > 0)
308 TSXFree(physDev->visuals[physDev->used_visuals]);
309 HeapFree( GetProcessHeap(), 0, physDev );
314 /**********************************************************************
317 static INT X11DRV_Escape( DC *dc, INT nEscape, INT cbInput,
318 SEGPTR lpInData, SEGPTR lpOutData )
322 case GETSCALINGFACTOR:
325 LPPOINT16 lppt = MapSL(lpOutData);
326 lppt->x = lppt->y = 0; /* no device scaling */