Corrected operand sizes for the "enter" instruction.
[wine.git] / graphics / x11drv / init.c
blob2ea67e73570a3510df69673a3e1e221f6fa80f05
1 /*
2 * X11 graphics driver initialisation functions
4 * Copyright 1996 Alexandre Julliard
5 */
7 #include "config.h"
9 #ifndef X_DISPLAY_MISSING
11 #include "ts_xlib.h"
13 #include <string.h>
15 #include "bitmap.h"
16 #include "color.h"
17 #include "debugtools.h"
18 #include "ldt.h"
19 #include "local.h"
20 #include "monitor.h"
21 #include "winnt.h"
22 #include "x11drv.h"
24 DEFAULT_DEBUG_CHANNEL(x11drv)
26 static BOOL X11DRV_CreateDC( DC *dc, LPCSTR driver, LPCSTR device,
27 LPCSTR output, const DEVMODEA* initData );
28 static BOOL X11DRV_DeleteDC( DC *dc );
30 static INT X11DRV_Escape( DC *dc, INT nEscape, INT cbInput,
31 SEGPTR lpInData, SEGPTR lpOutData );
33 static const DC_FUNCTIONS X11DRV_Funcs =
35 NULL, /* pAbortDoc */
36 X11DRV_Arc, /* pArc */
37 X11DRV_BitBlt, /* pBitBlt */
38 X11DRV_BitmapBits, /* pBitmapBits */
39 X11DRV_Chord, /* pChord */
40 X11DRV_CreateBitmap, /* pCreateBitmap */
41 X11DRV_CreateDC, /* pCreateDC */
42 X11DRV_DIB_CreateDIBSection, /* pCreateDIBSection */
43 X11DRV_DIB_CreateDIBSection16, /* pCreateDIBSection16 */
44 X11DRV_DeleteDC, /* pDeleteDC */
45 X11DRV_DeleteObject, /* pDeleteObject */
46 NULL, /* pDeviceCapabilities */
47 X11DRV_Ellipse, /* pEllipse */
48 NULL, /* pEndDoc */
49 NULL, /* pEndPage */
50 X11DRV_EnumDeviceFonts, /* pEnumDeviceFonts */
51 X11DRV_Escape, /* pEscape */
52 NULL, /* pExcludeClipRect */
53 NULL, /* pExtDeviceMode */
54 X11DRV_ExtFloodFill, /* pExtFloodFill */
55 X11DRV_ExtTextOut, /* pExtTextOut */
56 NULL, /* pFillRgn */
57 NULL, /* pFrameRgn */
58 X11DRV_GetCharWidth, /* pGetCharWidth */
59 X11DRV_GetPixel, /* pGetPixel */
60 X11DRV_GetTextExtentPoint, /* pGetTextExtentPoint */
61 X11DRV_GetTextMetrics, /* pGetTextMetrics */
62 NULL, /* pIntersectClipRect */
63 NULL, /* pInvertRgn */
64 X11DRV_LineTo, /* pLineTo */
65 X11DRV_LoadOEMResource, /* pLoadOEMResource */
66 X11DRV_MoveToEx, /* pMoveToEx */
67 NULL, /* pOffsetClipRgn */
68 NULL, /* pOffsetViewportOrg (optional) */
69 NULL, /* pOffsetWindowOrg (optional) */
70 X11DRV_PaintRgn, /* pPaintRgn */
71 X11DRV_PatBlt, /* pPatBlt */
72 X11DRV_Pie, /* pPie */
73 X11DRV_PolyPolygon, /* pPolyPolygon */
74 X11DRV_PolyPolyline, /* pPolyPolyline */
75 X11DRV_Polygon, /* pPolygon */
76 X11DRV_Polyline, /* pPolyline */
77 X11DRV_PolyBezier, /* pPolyBezier */
78 NULL, /* pRealizePalette */
79 X11DRV_Rectangle, /* pRectangle */
80 NULL, /* pRestoreDC */
81 X11DRV_RoundRect, /* pRoundRect */
82 NULL, /* pSaveDC */
83 NULL, /* pScaleViewportExt (optional) */
84 NULL, /* pScaleWindowExt (optional) */
85 NULL, /* pSelectClipRgn */
86 X11DRV_SelectObject, /* pSelectObject */
87 NULL, /* pSelectPalette */
88 X11DRV_SetBkColor, /* pSetBkColor */
89 NULL, /* pSetBkMode */
90 X11DRV_SetDeviceClipping, /* pSetDeviceClipping */
91 X11DRV_SetDIBitsToDevice, /* pSetDIBitsToDevice */
92 NULL, /* pSetMapMode (optional) */
93 NULL, /* pSetMapperFlags */
94 X11DRV_SetPixel, /* pSetPixel */
95 NULL, /* pSetPolyFillMode */
96 NULL, /* pSetROP2 */
97 NULL, /* pSetRelAbs */
98 NULL, /* pSetStretchBltMode */
99 NULL, /* pSetTextAlign */
100 NULL, /* pSetTextCharacterExtra */
101 X11DRV_SetTextColor, /* pSetTextColor */
102 NULL, /* pSetTextJustification */
103 NULL, /* pSetViewportExt (optional) */
104 NULL, /* pSetViewportOrg (optional) */
105 NULL, /* pSetWindowExt (optional) */
106 NULL, /* pSetWindowOrg (optional) */
107 NULL, /* pStartDoc */
108 NULL, /* pStartPage */
109 X11DRV_StretchBlt, /* pStretchBlt */
110 NULL /* pStretchDIBits */
113 GDI_DRIVER X11DRV_GDI_Driver =
115 X11DRV_GDI_Initialize,
116 X11DRV_GDI_Finalize
119 BITMAP_DRIVER X11DRV_BITMAP_Driver =
121 X11DRV_DIB_SetDIBits,
122 X11DRV_DIB_GetDIBits,
123 X11DRV_DIB_DeleteDIBSection
126 PALETTE_DRIVER X11DRV_PALETTE_Driver =
128 X11DRV_PALETTE_SetMapping,
129 X11DRV_PALETTE_UpdateMapping,
130 X11DRV_PALETTE_IsDark
133 DeviceCaps X11DRV_DevCaps = {
134 /* version */ 0,
135 /* technology */ DT_RASDISPLAY,
136 /* size, resolution */ 0, 0, 0, 0, 0,
137 /* device objects */ 1, 16 + 6, 16, 0, 0, 100, 0,
138 /* curve caps */ CC_CIRCLES | CC_PIE | CC_CHORD | CC_ELLIPSES |
139 CC_WIDE | CC_STYLED | CC_WIDESTYLED | CC_INTERIORS | CC_ROUNDRECT,
140 /* line caps */ LC_POLYLINE | LC_MARKER | LC_POLYMARKER | LC_WIDE |
141 LC_STYLED | LC_WIDESTYLED | LC_INTERIORS,
142 /* polygon caps */ PC_POLYGON | PC_RECTANGLE | PC_WINDPOLYGON |
143 PC_SCANLINE | PC_WIDE | PC_STYLED | PC_WIDESTYLED | PC_INTERIORS,
144 /* text caps */ 0,
145 /* regions */ CP_REGION,
146 /* raster caps */ RC_BITBLT | RC_BANDING | RC_SCALING | RC_BITMAP64 |
147 RC_DI_BITMAP | RC_DIBTODEV | RC_BIGFONT | RC_STRETCHBLT | RC_STRETCHDIB | RC_DEVBITS,
148 /* aspects */ 36, 36, 51,
149 /* pad1 */ { 0 },
150 /* log pixels */ 0, 0,
151 /* pad2 */ { 0 },
152 /* palette size */ 0,
153 /* ..etc */ 0, 0 };
155 /**********************************************************************
156 * X11DRV_GDI_Initialize
158 BOOL X11DRV_GDI_Initialize(void)
160 BITMAP_Driver = &X11DRV_BITMAP_Driver;
161 PALETTE_Driver = &X11DRV_PALETTE_Driver;
163 /* FIXME: colormap management should be merged with the X11DRV */
165 if( !X11DRV_DIB_Init() ) return FALSE;
167 if( !X11DRV_PALETTE_Init() ) return FALSE;
169 if( !X11DRV_OBM_Init() ) return FALSE;
171 /* Finish up device caps */
173 #if 0
174 TRACE("Height = %-4i pxl, %-4i mm, Width = %-4i pxl, %-4i mm\n",
175 HeightOfScreen(X11DRV_GetXScreen()), HeightMMOfScreen(X11DRV_GetXScreen()),
176 WidthOfScreen(X11DRV_GetXScreen()), WidthMMOfScreen(X11DRV_GetXScreen()) );
177 #endif
179 X11DRV_DevCaps.version = 0x300;
180 X11DRV_DevCaps.horzSize = WidthMMOfScreen(X11DRV_GetXScreen()) * MONITOR_GetWidth(&MONITOR_PrimaryMonitor) / WidthOfScreen(X11DRV_GetXScreen());
181 X11DRV_DevCaps.vertSize = HeightMMOfScreen(X11DRV_GetXScreen()) * MONITOR_GetHeight(&MONITOR_PrimaryMonitor) / HeightOfScreen(X11DRV_GetXScreen());
182 X11DRV_DevCaps.horzRes = MONITOR_GetWidth(&MONITOR_PrimaryMonitor);
183 X11DRV_DevCaps.vertRes = MONITOR_GetHeight(&MONITOR_PrimaryMonitor);
184 X11DRV_DevCaps.bitsPixel = MONITOR_GetDepth(&MONITOR_PrimaryMonitor);
186 /* Resolution will be adjusted during the font init */
188 X11DRV_DevCaps.logPixelsX = (int)(X11DRV_DevCaps.horzRes * 25.4 / X11DRV_DevCaps.horzSize);
189 X11DRV_DevCaps.logPixelsY = (int)(X11DRV_DevCaps.vertRes * 25.4 / X11DRV_DevCaps.vertSize);
191 /* Create default bitmap */
193 if (!X11DRV_BITMAP_Init()) return FALSE;
195 /* Initialize brush dithering */
197 if (!X11DRV_BRUSH_Init()) return FALSE;
199 /* Initialize fonts and text caps */
201 if (!X11DRV_FONT_Init( &X11DRV_DevCaps )) return FALSE;
203 return DRIVER_RegisterDriver( "DISPLAY", &X11DRV_Funcs );
206 /**********************************************************************
207 * X11DRV_GDI_Finalize
209 void X11DRV_GDI_Finalize(void)
211 X11DRV_PALETTE_Cleanup();
214 /**********************************************************************
215 * X11DRV_CreateDC
217 static BOOL X11DRV_CreateDC( DC *dc, LPCSTR driver, LPCSTR device,
218 LPCSTR output, const DEVMODEA* initData )
220 X11DRV_PDEVICE *physDev;
222 dc->physDev = physDev = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
223 sizeof(*physDev) );
224 if(!physDev) {
225 ERR("Can't allocate physDev\n");
226 return FALSE;
229 dc->w.devCaps = &X11DRV_DevCaps;
230 if (dc->w.flags & DC_MEMORY)
232 X11DRV_PHYSBITMAP *pbitmap;
233 BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( dc->w.hBitmap,
234 BITMAP_MAGIC );
235 X11DRV_CreateBitmap( dc->w.hBitmap );
236 pbitmap = bmp->DDBitmap->physBitmap;
237 physDev->drawable = pbitmap->pixmap;
238 physDev->gc = TSXCreateGC(display, physDev->drawable, 0, NULL);
239 dc->w.bitsPerPixel = bmp->bitmap.bmBitsPixel;
241 dc->w.totalExtent.left = 0;
242 dc->w.totalExtent.top = 0;
243 dc->w.totalExtent.right = bmp->bitmap.bmWidth;
244 dc->w.totalExtent.bottom = bmp->bitmap.bmHeight;
245 dc->w.hVisRgn = CreateRectRgnIndirect( &dc->w.totalExtent );
247 GDI_HEAP_UNLOCK( dc->w.hBitmap );
249 else
251 physDev->drawable = X11DRV_GetXRootWindow();
252 physDev->gc = TSXCreateGC( display, physDev->drawable, 0, NULL );
253 dc->w.bitsPerPixel = MONITOR_GetDepth(&MONITOR_PrimaryMonitor);
255 dc->w.totalExtent.left = 0;
256 dc->w.totalExtent.top = 0;
257 dc->w.totalExtent.right = MONITOR_GetWidth(&MONITOR_PrimaryMonitor);
258 dc->w.totalExtent.bottom = MONITOR_GetHeight(&MONITOR_PrimaryMonitor);
259 dc->w.hVisRgn = CreateRectRgnIndirect( &dc->w.totalExtent );
262 if (!dc->w.hVisRgn)
264 TSXFreeGC( display, physDev->gc );
265 return FALSE;
268 TSXSetGraphicsExposures( display, physDev->gc, False );
269 TSXSetSubwindowMode( display, physDev->gc, IncludeInferiors );
271 return TRUE;
275 /**********************************************************************
276 * X11DRV_DeleteDC
278 static BOOL X11DRV_DeleteDC( DC *dc )
280 X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
281 TSXFreeGC( display, physDev->gc );
282 HeapFree( GetProcessHeap(), 0, physDev );
283 dc->physDev = NULL;
284 return TRUE;
287 /**********************************************************************
288 * X11DRV_Escape
290 static INT X11DRV_Escape( DC *dc, INT nEscape, INT cbInput,
291 SEGPTR lpInData, SEGPTR lpOutData )
293 switch( nEscape )
295 case GETSCALINGFACTOR:
296 if( lpOutData )
298 LPPOINT16 lppt = (LPPOINT16)PTR_SEG_TO_LIN(lpOutData);
299 lppt->x = lppt->y = 0; /* no device scaling */
300 return 1;
302 break;
304 return 0;
307 #endif /* !defined(X_DISPLAY_MISSING) */