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