Added function table to GDI objects for better encapsulation.
[wine.git] / graphics / x11drv / init.c
blob72b57627280cb207c4fa10993704c8ce8d965e92
1 /*
2 * X11 graphics driver initialisation functions
4 * Copyright 1996 Alexandre Julliard
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.
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.
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
21 #include "config.h"
23 #include "ts_xlib.h"
25 #include <string.h>
27 #include "bitmap.h"
28 #include "palette.h"
29 #include "wine/debug.h"
30 #include "winnt.h"
31 #include "x11drv.h"
32 #include "x11font.h"
33 #include "ddrawi.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(x11drv);
37 const DC_FUNCTIONS *X11DRV_DC_Funcs = NULL; /* hack */
39 PALETTE_DRIVER X11DRV_PALETTE_Driver =
41 X11DRV_PALETTE_SetMapping,
42 X11DRV_PALETTE_UpdateMapping,
43 X11DRV_PALETTE_IsDark
47 Display *gdi_display; /* display to use for all GDI functions */
49 /* a few dynamic device caps */
50 static int log_pixels_x; /* pixels per logical inch in x direction */
51 static int log_pixels_y; /* pixels per logical inch in y direction */
52 static int horz_size; /* horz. size of screen in millimeters */
53 static int vert_size; /* vert. size of screen in millimeters */
54 static int palette_size;
55 unsigned int text_caps = (TC_OP_CHARACTER | TC_OP_STROKE | TC_CP_STROKE |
56 TC_CR_ANY | TC_SA_DOUBLE | TC_SA_INTEGER |
57 TC_SA_CONTIN | TC_UA_ABLE | TC_SO_ABLE | TC_RA_ABLE);
58 /* X11R6 adds TC_SF_X_YINDEP, Xrender adds TC_VA_ABLE */
60 /**********************************************************************
61 * X11DRV_GDI_Initialize
63 BOOL X11DRV_GDI_Initialize( Display *display )
65 Screen *screen = DefaultScreenOfDisplay(display);
67 gdi_display = display;
68 PALETTE_Driver = &X11DRV_PALETTE_Driver;
70 palette_size = X11DRV_PALETTE_Init();
72 if (!X11DRV_BITMAP_Init()) return FALSE;
74 /* Initialize XRender */
75 X11DRV_XRender_Init();
77 /* Initialize fonts and text caps */
79 log_pixels_x = MulDiv( WidthOfScreen(screen), 254, WidthMMOfScreen(screen) * 10 );
80 log_pixels_y = MulDiv( HeightOfScreen(screen), 254, HeightMMOfScreen(screen) * 10 );
81 X11DRV_FONT_Init( &log_pixels_x, &log_pixels_y );
82 horz_size = MulDiv( screen_width, 254, log_pixels_x * 10 );
83 vert_size = MulDiv( screen_height, 254, log_pixels_y * 10 );
84 return TRUE;
87 /**********************************************************************
88 * X11DRV_GDI_Finalize
90 void X11DRV_GDI_Finalize(void)
92 X11DRV_PALETTE_Cleanup();
93 XCloseDisplay( gdi_display );
94 gdi_display = NULL;
97 /**********************************************************************
98 * X11DRV_CreateDC
100 BOOL X11DRV_CreateDC( DC *dc, LPCSTR driver, LPCSTR device,
101 LPCSTR output, const DEVMODEA* initData )
103 X11DRV_PDEVICE *physDev;
105 if (!X11DRV_DC_Funcs) X11DRV_DC_Funcs = dc->funcs; /* hack */
107 physDev = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*physDev) );
108 if(!physDev) {
109 ERR("Can't allocate physDev\n");
110 return FALSE;
112 dc->physDev = (PHYSDEV)physDev;
113 physDev->hdc = dc->hSelf;
114 physDev->dc = dc; /* FIXME */
116 if (dc->flags & DC_MEMORY)
118 physDev->drawable = BITMAP_stock_pixmap;
120 else
122 physDev->drawable = root_window;
123 dc->bitsPerPixel = screen_depth;
126 physDev->current_pf = 0;
127 physDev->used_visuals = 0;
129 wine_tsx11_lock();
130 physDev->gc = XCreateGC( gdi_display, physDev->drawable, 0, NULL );
131 XSetGraphicsExposures( gdi_display, physDev->gc, False );
132 XSetSubwindowMode( gdi_display, physDev->gc, IncludeInferiors );
133 XFlush( gdi_display );
134 wine_tsx11_unlock();
135 return TRUE;
139 /**********************************************************************
140 * X11DRV_DeleteDC
142 BOOL X11DRV_DeleteDC( X11DRV_PDEVICE *physDev )
144 DC *dc = physDev->dc;
146 if(physDev->xrender)
147 X11DRV_XRender_DeleteDC( physDev );
148 wine_tsx11_lock();
149 XFreeGC( gdi_display, physDev->gc );
150 while (physDev->used_visuals-- > 0)
151 XFree(physDev->visuals[physDev->used_visuals]);
152 wine_tsx11_unlock();
153 HeapFree( GetProcessHeap(), 0, physDev );
154 dc->physDev = NULL;
155 return TRUE;
159 /***********************************************************************
160 * GetDeviceCaps (X11DRV.@)
162 INT X11DRV_GetDeviceCaps( X11DRV_PDEVICE *physDev, INT cap )
164 switch(cap)
166 case DRIVERVERSION:
167 return 0x300;
168 case TECHNOLOGY:
169 return DT_RASDISPLAY;
170 case HORZSIZE:
171 return horz_size;
172 case VERTSIZE:
173 return vert_size;
174 case HORZRES:
175 return screen_width;
176 case VERTRES:
177 return screen_height;
178 case BITSPIXEL:
179 return screen_depth;
180 case PLANES:
181 return 1;
182 case NUMBRUSHES:
183 return -1;
184 case NUMPENS:
185 return -1;
186 case NUMMARKERS:
187 return 0;
188 case NUMFONTS:
189 return 0;
190 case NUMCOLORS:
191 /* MSDN: Number of entries in the device's color table, if the device has
192 * a color depth of no more than 8 bits per pixel.For devices with greater
193 * color depths, -1 is returned. */
194 return (screen_depth > 8) ? -1 : (1 << screen_depth);
195 case PDEVICESIZE:
196 return sizeof(X11DRV_PDEVICE);
197 case CURVECAPS:
198 return (CC_CIRCLES | CC_PIE | CC_CHORD | CC_ELLIPSES | CC_WIDE |
199 CC_STYLED | CC_WIDESTYLED | CC_INTERIORS | CC_ROUNDRECT);
200 case LINECAPS:
201 return (LC_POLYLINE | LC_MARKER | LC_POLYMARKER | LC_WIDE |
202 LC_STYLED | LC_WIDESTYLED | LC_INTERIORS);
203 case POLYGONALCAPS:
204 return (PC_POLYGON | PC_RECTANGLE | PC_WINDPOLYGON | PC_SCANLINE |
205 PC_WIDE | PC_STYLED | PC_WIDESTYLED | PC_INTERIORS);
206 case TEXTCAPS:
207 return text_caps;
208 case CLIPCAPS:
209 return CP_REGION;
210 case RASTERCAPS:
211 return (RC_BITBLT | RC_BANDING | RC_SCALING | RC_BITMAP64 | RC_DI_BITMAP |
212 RC_DIBTODEV | RC_BIGFONT | RC_STRETCHBLT | RC_STRETCHDIB | RC_DEVBITS |
213 (palette_size ? RC_PALETTE : 0));
214 case ASPECTX:
215 case ASPECTY:
216 return 36;
217 case ASPECTXY:
218 return 51;
219 case LOGPIXELSX:
220 return log_pixels_x;
221 case LOGPIXELSY:
222 return log_pixels_y;
223 case CAPS1:
224 FIXME("(%04x): CAPS1 is unimplemented, will return 0\n", physDev->hdc );
225 /* please see wingdi.h for the possible bit-flag values that need
226 to be returned. also, see
227 http://msdn.microsoft.com/library/ddkdoc/win95ddk/graphcnt_1m0p.htm */
228 return 0;
229 case SIZEPALETTE:
230 return palette_size;
231 case NUMRESERVED:
232 case COLORRES:
233 case PHYSICALWIDTH:
234 case PHYSICALHEIGHT:
235 case PHYSICALOFFSETX:
236 case PHYSICALOFFSETY:
237 case SCALINGFACTORX:
238 case SCALINGFACTORY:
239 case VREFRESH:
240 case DESKTOPVERTRES:
241 case DESKTOPHORZRES:
242 case BTLALIGNMENT:
243 return 0;
244 default:
245 FIXME("(%04x): unsupported capability %d, will return 0\n", physDev->hdc, cap );
246 return 0;
251 /**********************************************************************
252 * ExtEscape (X11DRV.@)
254 INT X11DRV_ExtEscape( X11DRV_PDEVICE *physDev, INT escape, INT in_count, LPCVOID in_data,
255 INT out_count, LPVOID out_data )
257 switch(escape)
259 case QUERYESCSUPPORT:
260 if (in_data)
262 switch (*(INT *)in_data)
264 case DCICOMMAND:
265 return DD_HAL_VERSION;
266 case X11DRV_ESCAPE:
267 return TRUE;
270 break;
272 case DCICOMMAND:
273 if (in_data)
275 const DCICMD *lpCmd = in_data;
276 if (lpCmd->dwVersion != DD_VERSION) break;
277 return X11DRV_DCICommand(in_count, lpCmd, out_data);
279 break;
281 case X11DRV_ESCAPE:
282 if (in_data && in_count >= sizeof(enum x11drv_escape_codes))
284 switch(*(enum x11drv_escape_codes *)in_data)
286 case X11DRV_GET_DISPLAY:
287 if (out_count >= sizeof(Display *))
289 *(Display **)out_data = gdi_display;
290 return TRUE;
292 break;
293 case X11DRV_GET_DRAWABLE:
294 if (out_count >= sizeof(Drawable))
296 *(Drawable *)out_data = physDev->drawable;
297 return TRUE;
299 break;
300 case X11DRV_GET_FONT:
301 if (out_count >= sizeof(Font))
303 fontObject* pfo = XFONT_GetFontObject( physDev->font );
304 *(Font *)out_data = pfo->fs->fid;
305 return TRUE;
309 break;
311 return 0;