Fix the case of product and company names.
[wine] / graphics / x11drv / init.c
1 /*
2  * X11 graphics driver initialisation functions
3  *
4  * Copyright 1996 Alexandre Julliard
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include "config.h"
22
23 #include "ts_xlib.h"
24
25 #include <stdarg.h>
26 #include <string.h>
27
28 #include "windef.h"
29 #include "winbase.h"
30 #include "bitmap.h"
31 #include "x11drv.h"
32 #include "x11font.h"
33 #include "ddrawi.h"
34 #include "wine/debug.h"
35
36 WINE_DEFAULT_DEBUG_CHANNEL(x11drv);
37
38 const DC_FUNCTIONS *X11DRV_DC_Funcs = NULL;  /* hack */
39
40 Display *gdi_display;  /* display to use for all GDI functions */
41
42 /* a few dynamic device caps */
43 static int log_pixels_x;  /* pixels per logical inch in x direction */
44 static int log_pixels_y;  /* pixels per logical inch in y direction */
45 static int horz_size;     /* horz. size of screen in millimeters */
46 static int vert_size;     /* vert. size of screen in millimeters */
47 static int palette_size;
48 unsigned int text_caps = (TC_OP_CHARACTER | TC_OP_STROKE | TC_CP_STROKE |
49                           TC_CR_ANY | TC_SA_DOUBLE | TC_SA_INTEGER |
50                           TC_SA_CONTIN | TC_UA_ABLE | TC_SO_ABLE | TC_RA_ABLE);
51                           /* X11R6 adds TC_SF_X_YINDEP, Xrender adds TC_VA_ABLE */
52
53 /**********************************************************************
54  *           X11DRV_GDI_Initialize
55  */
56 BOOL X11DRV_GDI_Initialize( Display *display )
57 {
58     Screen *screen = DefaultScreenOfDisplay(display);
59
60     gdi_display = display;
61
62     palette_size = X11DRV_PALETTE_Init();
63
64     if (!X11DRV_BITMAP_Init()) return FALSE;
65
66     /* Initialize XRender */
67     X11DRV_XRender_Init();
68
69     /* Initialize fonts and text caps */
70
71     log_pixels_x = MulDiv( WidthOfScreen(screen), 254, WidthMMOfScreen(screen) * 10 );
72     log_pixels_y = MulDiv( HeightOfScreen(screen), 254, HeightMMOfScreen(screen) * 10 );
73     X11DRV_FONT_Init( &log_pixels_x, &log_pixels_y );
74     horz_size = MulDiv( screen_width, 254, log_pixels_x * 10 );
75     vert_size = MulDiv( screen_height, 254, log_pixels_y * 10 );
76     return TRUE;
77 }
78
79 /**********************************************************************
80  *           X11DRV_GDI_Finalize
81  */
82 void X11DRV_GDI_Finalize(void)
83 {
84     X11DRV_PALETTE_Cleanup();
85     XCloseDisplay( gdi_display );
86     gdi_display = NULL;
87 }
88
89 /**********************************************************************
90  *           X11DRV_CreateDC
91  */
92 BOOL X11DRV_CreateDC( DC *dc, X11DRV_PDEVICE **pdev, LPCWSTR driver, LPCWSTR device,
93                       LPCWSTR output, const DEVMODEW* initData )
94 {
95     X11DRV_PDEVICE *physDev;
96
97     if (!X11DRV_DC_Funcs) X11DRV_DC_Funcs = dc->funcs;  /* hack */
98
99     physDev = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*physDev) );
100     if(!physDev) {
101         ERR("Can't allocate physDev\n");
102         return FALSE;
103     }
104     *pdev = physDev;
105     physDev->hdc = dc->hSelf;
106     physDev->dc  = dc;  /* FIXME */
107
108     if (GetObjectType( dc->hSelf ) == OBJ_MEMDC)
109     {
110         physDev->drawable  = BITMAP_stock_pixmap;
111     }
112     else
113     {
114         physDev->drawable  = root_window;
115         dc->bitsPerPixel   = screen_depth;
116     }
117     physDev->org.x = physDev->org.y = 0;
118     physDev->drawable_org.x = physDev->drawable_org.y = 0;
119
120     physDev->current_pf   = 0;
121     physDev->used_visuals = 0;
122
123     wine_tsx11_lock();
124     physDev->gc = XCreateGC( gdi_display, physDev->drawable, 0, NULL );
125     XSetGraphicsExposures( gdi_display, physDev->gc, False );
126     XSetSubwindowMode( gdi_display, physDev->gc, IncludeInferiors );
127     XFlush( gdi_display );
128     wine_tsx11_unlock();
129     return TRUE;
130 }
131
132
133 /**********************************************************************
134  *           X11DRV_DeleteDC
135  */
136 BOOL X11DRV_DeleteDC( X11DRV_PDEVICE *physDev )
137 {
138     if(physDev->xrender)
139       X11DRV_XRender_DeleteDC( physDev );
140     wine_tsx11_lock();
141     XFreeGC( gdi_display, physDev->gc );
142     while (physDev->used_visuals-- > 0)
143         XFree(physDev->visuals[physDev->used_visuals]);
144     wine_tsx11_unlock();
145     HeapFree( GetProcessHeap(), 0, physDev );
146     return TRUE;
147 }
148
149
150 /***********************************************************************
151  *           GetDeviceCaps    (X11DRV.@)
152  */
153 INT X11DRV_GetDeviceCaps( X11DRV_PDEVICE *physDev, INT cap )
154 {
155     switch(cap)
156     {
157     case DRIVERVERSION:
158         return 0x300;
159     case TECHNOLOGY:
160         return DT_RASDISPLAY;
161     case HORZSIZE:
162         return horz_size;
163     case VERTSIZE:
164         return vert_size;
165     case HORZRES:
166         return screen_width;
167     case VERTRES:
168         return screen_height;
169     case BITSPIXEL:
170         return screen_depth;
171     case PLANES:
172         return 1;
173     case NUMBRUSHES:
174         return -1;
175     case NUMPENS:
176         return -1;
177     case NUMMARKERS:
178         return 0;
179     case NUMFONTS:
180         return 0;
181     case NUMCOLORS:
182         /* MSDN: Number of entries in the device's color table, if the device has
183          * a color depth of no more than 8 bits per pixel.For devices with greater
184          * color depths, -1 is returned. */
185         return (screen_depth > 8) ? -1 : (1 << screen_depth);
186     case PDEVICESIZE:
187         return sizeof(X11DRV_PDEVICE);
188     case CURVECAPS:
189         return (CC_CIRCLES | CC_PIE | CC_CHORD | CC_ELLIPSES | CC_WIDE |
190                 CC_STYLED | CC_WIDESTYLED | CC_INTERIORS | CC_ROUNDRECT);
191     case LINECAPS:
192         return (LC_POLYLINE | LC_MARKER | LC_POLYMARKER | LC_WIDE |
193                 LC_STYLED | LC_WIDESTYLED | LC_INTERIORS);
194     case POLYGONALCAPS:
195         return (PC_POLYGON | PC_RECTANGLE | PC_WINDPOLYGON | PC_SCANLINE |
196                 PC_WIDE | PC_STYLED | PC_WIDESTYLED | PC_INTERIORS);
197     case TEXTCAPS:
198         return text_caps;
199     case CLIPCAPS:
200         return CP_REGION;
201     case RASTERCAPS:
202         return (RC_BITBLT | RC_BANDING | RC_SCALING | RC_BITMAP64 | RC_DI_BITMAP |
203                 RC_DIBTODEV | RC_BIGFONT | RC_STRETCHBLT | RC_STRETCHDIB | RC_DEVBITS |
204                 (palette_size ? RC_PALETTE : 0));
205     case ASPECTX:
206     case ASPECTY:
207         return 36;
208     case ASPECTXY:
209         return 51;
210     case LOGPIXELSX:
211         return log_pixels_x;
212     case LOGPIXELSY:
213         return log_pixels_y;
214     case CAPS1:
215         FIXME("(%p): CAPS1 is unimplemented, will return 0\n", physDev->hdc );
216         /* please see wingdi.h for the possible bit-flag values that need
217            to be returned. also, see
218            http://msdn.microsoft.com/library/ddkdoc/win95ddk/graphcnt_1m0p.htm */
219         return 0;
220     case SIZEPALETTE:
221         return palette_size;
222     case NUMRESERVED:
223     case COLORRES:
224     case PHYSICALWIDTH:
225     case PHYSICALHEIGHT:
226     case PHYSICALOFFSETX:
227     case PHYSICALOFFSETY:
228     case SCALINGFACTORX:
229     case SCALINGFACTORY:
230     case VREFRESH:
231     case DESKTOPVERTRES:
232     case DESKTOPHORZRES:
233     case BTLALIGNMENT:
234         return 0;
235     default:
236         FIXME("(%p): unsupported capability %d, will return 0\n", physDev->hdc, cap );
237         return 0;
238     }
239 }
240
241
242 /**********************************************************************
243  *           ExtEscape  (X11DRV.@)
244  */
245 INT X11DRV_ExtEscape( X11DRV_PDEVICE *physDev, INT escape, INT in_count, LPCVOID in_data,
246                       INT out_count, LPVOID out_data )
247 {
248     switch(escape)
249     {
250     case QUERYESCSUPPORT:
251         if (in_data)
252         {
253             switch (*(INT *)in_data)
254             {
255             case DCICOMMAND:
256                 return DD_HAL_VERSION;
257             case X11DRV_ESCAPE:
258                 return TRUE;
259             }
260         }
261         break;
262
263     case DCICOMMAND:
264         if (in_data)
265         {
266             const DCICMD *lpCmd = in_data;
267             if (lpCmd->dwVersion != DD_VERSION) break;
268             return X11DRV_DCICommand(in_count, lpCmd, out_data);
269         }
270         break;
271
272     case X11DRV_ESCAPE:
273         if (in_data && in_count >= sizeof(enum x11drv_escape_codes))
274         {
275             switch(*(enum x11drv_escape_codes *)in_data)
276             {
277             case X11DRV_GET_DISPLAY:
278                 if (out_count >= sizeof(Display *))
279                 {
280                     *(Display **)out_data = gdi_display;
281                     return TRUE;
282                 }
283                 break;
284             case X11DRV_GET_DRAWABLE:
285                 if (out_count >= sizeof(Drawable))
286                 {
287                     *(Drawable *)out_data = physDev->drawable;
288                     return TRUE;
289                 }
290                 break;
291             case X11DRV_GET_FONT:
292                 if (out_count >= sizeof(Font))
293                 {
294                     fontObject* pfo = XFONT_GetFontObject( physDev->font );
295                     if (pfo == NULL) return FALSE;
296                     *(Font *)out_data = pfo->fs->fid;
297                     return TRUE;
298                 }
299             }
300         }
301         break;
302     }
303     return 0;
304 }