Moved more things to the X11 driver.
[wine/multimedia.git] / graphics / x11drv / init.c
blob42e03ecdc20364ef262aca2938d0a2e04548c624
1 /*
2 * X11 graphics driver initialisation functions
4 * Copyright 1996 Alexandre Julliard
5 */
7 #include "ts_xlib.h"
9 #include <string.h>
10 #include "x11drv.h"
11 #include "color.h"
12 #include "bitmap.h"
13 #include "winnt.h"
14 #include "debug.h"
16 static BOOL32 X11DRV_CreateDC( DC *dc, LPCSTR driver, LPCSTR device,
17 LPCSTR output, const DEVMODE16* initData );
18 static BOOL32 X11DRV_DeleteDC( DC *dc );
20 static INT32 X11DRV_Escape( DC *dc, INT32 nEscape, INT32 cbInput,
21 SEGPTR lpInData, SEGPTR lpOutData );
23 static const DC_FUNCTIONS X11DRV_Funcs =
25 X11DRV_Arc, /* pArc */
26 X11DRV_BitBlt, /* pBitBlt */
27 X11DRV_BitmapBits, /* pBitmapBits */
28 X11DRV_Chord, /* pChord */
29 X11DRV_CreateBitmap, /* pCreateBitmap */
30 X11DRV_CreateDC, /* pCreateDC */
31 X11DRV_DeleteDC, /* pDeleteDC */
32 X11DRV_DeleteObject, /* pDeleteObject */
33 X11DRV_Ellipse, /* pEllipse */
34 X11DRV_EnumDeviceFonts, /* pEnumDeviceFonts */
35 X11DRV_Escape, /* pEscape */
36 NULL, /* pExcludeClipRect */
37 NULL, /* pExcludeVisRect */
38 X11DRV_ExtFloodFill, /* pExtFloodFill */
39 X11DRV_ExtTextOut, /* pExtTextOut */
40 X11DRV_GetCharWidth, /* pGetCharWidth */
41 X11DRV_GetPixel, /* pGetPixel */
42 X11DRV_GetTextExtentPoint, /* pGetTextExtentPoint */
43 X11DRV_GetTextMetrics, /* pGetTextMetrics */
44 NULL, /* pIntersectClipRect */
45 NULL, /* pIntersectVisRect */
46 X11DRV_LineTo, /* pLineTo */
47 X11DRV_LoadOEMResource, /* pLoadOEMResource */
48 X11DRV_MoveToEx, /* pMoveToEx */
49 NULL, /* pOffsetClipRgn */
50 NULL, /* pOffsetViewportOrg (optional) */
51 NULL, /* pOffsetWindowOrg (optional) */
52 X11DRV_PaintRgn, /* pPaintRgn */
53 X11DRV_PatBlt, /* pPatBlt */
54 X11DRV_Pie, /* pPie */
55 X11DRV_PolyPolygon, /* pPolyPolygon */
56 X11DRV_PolyPolyline, /* pPolyPolyline */
57 X11DRV_Polygon, /* pPolygon */
58 X11DRV_Polyline, /* pPolyline */
59 X11DRV_PolyBezier, /* pPolyBezier */
60 NULL, /* pRealizePalette */
61 X11DRV_Rectangle, /* pRectangle */
62 NULL, /* pRestoreDC */
63 X11DRV_RoundRect, /* pRoundRect */
64 NULL, /* pSaveDC */
65 NULL, /* pScaleViewportExt (optional) */
66 NULL, /* pScaleWindowExt (optional) */
67 NULL, /* pSelectClipRgn */
68 X11DRV_SelectObject, /* pSelectObject */
69 NULL, /* pSelectPalette */
70 X11DRV_SetBkColor, /* pSetBkColor */
71 NULL, /* pSetBkMode */
72 X11DRV_SetDeviceClipping, /* pSetDeviceClipping */
73 X11DRV_SetDIBitsToDevice, /* pSetDIBitsToDevice */
74 NULL, /* pSetMapMode (optional) */
75 NULL, /* pSetMapperFlags */
76 X11DRV_SetPixel, /* pSetPixel */
77 NULL, /* pSetPolyFillMode */
78 NULL, /* pSetROP2 */
79 NULL, /* pSetRelAbs */
80 NULL, /* pSetStretchBltMode */
81 NULL, /* pSetTextAlign */
82 NULL, /* pSetTextCharacterExtra */
83 X11DRV_SetTextColor, /* pSetTextColor */
84 NULL, /* pSetTextJustification */
85 NULL, /* pSetViewportExt (optional) */
86 NULL, /* pSetViewportOrg (optional) */
87 NULL, /* pSetWindowExt (optional) */
88 NULL, /* pSetWindowOrg (optional) */
89 X11DRV_StretchBlt, /* pStretchBlt */
90 NULL /* pStretchDIBits */
93 static DeviceCaps X11DRV_DevCaps = {
94 /* version */ 0,
95 /* technology */ DT_RASDISPLAY,
96 /* size, resolution */ 0, 0, 0, 0, 0,
97 /* device objects */ 1, 16 + 6, 16, 0, 0, 100, 0,
98 /* curve caps */ CC_CIRCLES | CC_PIE | CC_CHORD | CC_ELLIPSES |
99 CC_WIDE | CC_STYLED | CC_WIDESTYLED | CC_INTERIORS | CC_ROUNDRECT,
100 /* line caps */ LC_POLYLINE | LC_MARKER | LC_POLYMARKER | LC_WIDE |
101 LC_STYLED | LC_WIDESTYLED | LC_INTERIORS,
102 /* polygon caps */ PC_POLYGON | PC_RECTANGLE | PC_WINDPOLYGON |
103 PC_SCANLINE | PC_WIDE | PC_STYLED | PC_WIDESTYLED | PC_INTERIORS,
104 /* text caps */ 0,
105 /* regions */ CP_REGION,
106 /* raster caps */ RC_BITBLT | RC_BANDING | RC_SCALING | RC_BITMAP64 |
107 RC_DI_BITMAP | RC_DIBTODEV | RC_BIGFONT | RC_STRETCHBLT | RC_STRETCHDIB | RC_DEVBITS,
108 /* aspects */ 36, 36, 51,
109 /* pad1 */ { 0 },
110 /* log pixels */ 0, 0,
111 /* pad2 */ { 0 },
112 /* palette size */ 0,
113 /* ..etc */ 0, 0 };
115 /**********************************************************************
116 * X11DRV_Init
118 BOOL32 X11DRV_Init(void)
120 /* FIXME: colormap management should be merged with the X11DRV */
122 if( !X11DRV_DIB_Init() ) return FALSE;
124 if( !COLOR_Init() ) return FALSE;
126 if( !X11DRV_OBM_Init() ) return FALSE;
128 /* Finish up device caps */
130 #if 0
131 TRACE(x11drv, "Height = %-4i pxl, %-4i mm, Width = %-4i pxl, %-4i mm\n",
132 HeightOfScreen(screen), HeightMMOfScreen(screen),
133 WidthOfScreen(screen), WidthMMOfScreen(screen) );
134 #endif
136 X11DRV_DevCaps.version = 0x300;
137 X11DRV_DevCaps.horzSize = WidthMMOfScreen(screen) * screenWidth / WidthOfScreen(screen);
138 X11DRV_DevCaps.vertSize = HeightMMOfScreen(screen) * screenHeight / HeightOfScreen(screen);
139 X11DRV_DevCaps.horzRes = screenWidth;
140 X11DRV_DevCaps.vertRes = screenHeight;
141 X11DRV_DevCaps.bitsPixel = screenDepth;
143 if( COLOR_GetSystemPaletteFlags() & COLOR_VIRTUAL )
144 X11DRV_DevCaps.sizePalette = 0;
145 else
147 X11DRV_DevCaps.rasterCaps |= RC_PALETTE;
148 X11DRV_DevCaps.sizePalette = DefaultVisual(display,DefaultScreen(display))->map_entries;
151 /* Resolution will be adjusted during the font init */
153 X11DRV_DevCaps.logPixelsX = (int)(X11DRV_DevCaps.horzRes * 25.4 / X11DRV_DevCaps.horzSize);
154 X11DRV_DevCaps.logPixelsY = (int)(X11DRV_DevCaps.vertRes * 25.4 / X11DRV_DevCaps.vertSize);
156 /* Create default bitmap */
158 if (!X11DRV_BITMAP_Init()) return FALSE;
160 /* Initialize brush dithering */
162 if (!X11DRV_BRUSH_Init()) return FALSE;
164 /* Initialize fonts and text caps */
166 if (!X11DRV_FONT_Init( &X11DRV_DevCaps )) return FALSE;
168 return DRIVER_RegisterDriver( "DISPLAY", &X11DRV_Funcs );
171 /**********************************************************************
172 * X11DRV_CreateDC
174 static BOOL32 X11DRV_CreateDC( DC *dc, LPCSTR driver, LPCSTR device,
175 LPCSTR output, const DEVMODE16* initData )
177 X11DRV_PDEVICE *physDev;
179 dc->physDev = physDev = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
180 sizeof(*physDev) );
181 if(!physDev) {
182 ERR(x11drv, "Can't allocate physDev\n");
183 return FALSE;
186 dc->w.devCaps = &X11DRV_DevCaps;
187 if (dc->w.flags & DC_MEMORY)
189 X11DRV_PHYSBITMAP *pbitmap;
190 BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( dc->w.hBitmap,
191 BITMAP_MAGIC );
192 X11DRV_CreateBitmap( dc->w.hBitmap );
193 pbitmap = bmp->DDBitmap->physBitmap;
194 physDev->drawable = pbitmap->pixmap;
195 physDev->gc = TSXCreateGC(display, physDev->drawable, 0, NULL);
196 dc->w.bitsPerPixel = bmp->bitmap.bmBitsPixel;
198 dc->w.totalExtent.left = 0;
199 dc->w.totalExtent.top = 0;
200 dc->w.totalExtent.right = bmp->bitmap.bmWidth;
201 dc->w.totalExtent.bottom = bmp->bitmap.bmHeight;
202 dc->w.hVisRgn = CreateRectRgnIndirect32( &dc->w.totalExtent );
204 GDI_HEAP_UNLOCK( dc->w.hBitmap );
206 else
208 physDev->drawable = rootWindow;
209 physDev->gc = TSXCreateGC( display, physDev->drawable, 0, NULL );
210 dc->w.bitsPerPixel = screenDepth;
212 dc->w.totalExtent.left = 0;
213 dc->w.totalExtent.top = 0;
214 dc->w.totalExtent.right = screenWidth;
215 dc->w.totalExtent.bottom = screenHeight;
216 dc->w.hVisRgn = CreateRectRgnIndirect32( &dc->w.totalExtent );
219 if (!dc->w.hVisRgn)
221 TSXFreeGC( display, physDev->gc );
222 return FALSE;
225 TSXSetGraphicsExposures( display, physDev->gc, False );
226 TSXSetSubwindowMode( display, physDev->gc, IncludeInferiors );
228 return TRUE;
232 /**********************************************************************
233 * X11DRV_DeleteDC
235 static BOOL32 X11DRV_DeleteDC( DC *dc )
237 X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
238 TSXFreeGC( display, physDev->gc );
239 HeapFree( GetProcessHeap(), 0, physDev );
240 dc->physDev = NULL;
241 return TRUE;
244 /**********************************************************************
245 * X11DRV_Escape
247 static INT32 X11DRV_Escape( DC *dc, INT32 nEscape, INT32 cbInput,
248 SEGPTR lpInData, SEGPTR lpOutData )
250 switch( nEscape )
252 case GETSCALINGFACTOR:
253 if( lpOutData )
255 LPPOINT16 lppt = (LPPOINT16)PTR_SEG_TO_LIN(lpOutData);
256 lppt->x = lppt->y = 0; /* no device scaling */
257 return 1;
259 break;
261 return 0;