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