blob: f2c8e4c4938704b55fdb53a7c6026f612ee246ea [file] [log] [blame]
Alexandre Julliard0e270f41996-08-24 18:26:35 +00001/*
2 * X11 graphics driver initialisation functions
3 *
4 * Copyright 1996 Alexandre Julliard
Alexandre Julliard0799c1a2002-03-09 23:29:33 +00005 *
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
Alexandre Julliard0e270f41996-08-24 18:26:35 +000019 */
20
Patrik Stridvallab121e71999-02-04 11:11:01 +000021#include "config.h"
22
Alexandre Julliarde37c6e12003-09-05 23:08:26 +000023#include <stdarg.h>
Alexandre Julliard0e270f41996-08-24 18:26:35 +000024#include <string.h>
Patrik Stridvallb87fe2e1999-04-01 08:16:08 +000025
Alexandre Julliard435e2e62002-12-10 22:56:43 +000026#include "windef.h"
Alexandre Julliarde37c6e12003-09-05 23:08:26 +000027#include "winbase.h"
Patrik Stridvallb87fe2e1999-04-01 08:16:08 +000028#include "x11drv.h"
Alexandre Julliardced71ed2002-03-23 21:43:56 +000029#include "x11font.h"
Alexandre Julliard294c8af2004-01-20 22:48:57 +000030#include "gdi.h"
Ove Kaaven8f7ac8b2001-04-17 17:29:59 +000031#include "ddrawi.h"
Alexandre Julliard376e6502002-06-02 21:40:24 +000032#include "wine/debug.h"
Alexandre Julliard03468f71998-02-15 19:40:49 +000033
Alexandre Julliard0799c1a2002-03-09 23:29:33 +000034WINE_DEFAULT_DEBUG_CHANNEL(x11drv);
Patrik Stridvallb4b9fae1999-04-19 14:56:29 +000035
Alexandre Julliard6ec42c02004-01-15 00:35:38 +000036const struct tagDC_FUNCS *X11DRV_DC_Funcs = NULL; /* hack */
Alexandre Julliard0e270f41996-08-24 18:26:35 +000037
Alexandre Julliardc5597352001-05-11 00:17:47 +000038Display *gdi_display; /* display to use for all GDI functions */
39
Alexandre Julliard99bb9f92001-07-28 00:18:02 +000040/* a few dynamic device caps */
41static int log_pixels_x; /* pixels per logical inch in x direction */
42static int log_pixels_y; /* pixels per logical inch in y direction */
43static int horz_size; /* horz. size of screen in millimeters */
44static int vert_size; /* vert. size of screen in millimeters */
45static int palette_size;
Huw D M Daviese1e51f92002-04-03 21:18:50 +000046unsigned int text_caps = (TC_OP_CHARACTER | TC_OP_STROKE | TC_CP_STROKE |
47 TC_CR_ANY | TC_SA_DOUBLE | TC_SA_INTEGER |
48 TC_SA_CONTIN | TC_UA_ABLE | TC_SO_ABLE | TC_RA_ABLE);
49 /* X11R6 adds TC_SF_X_YINDEP, Xrender adds TC_VA_ABLE */
Alexandre Julliard99bb9f92001-07-28 00:18:02 +000050
Alexandre Julliard0e270f41996-08-24 18:26:35 +000051/**********************************************************************
Patrik Stridvallb87fe2e1999-04-01 08:16:08 +000052 * X11DRV_GDI_Initialize
Alexandre Julliard0e270f41996-08-24 18:26:35 +000053 */
Alexandre Julliardc5597352001-05-11 00:17:47 +000054BOOL X11DRV_GDI_Initialize( Display *display )
Alexandre Julliard0e270f41996-08-24 18:26:35 +000055{
Alexandre Julliardc5597352001-05-11 00:17:47 +000056 Screen *screen = DefaultScreenOfDisplay(display);
57
58 gdi_display = display;
Patrik Stridvallb87fe2e1999-04-01 08:16:08 +000059
Alexandre Julliard99bb9f92001-07-28 00:18:02 +000060 palette_size = X11DRV_PALETTE_Init();
Alexandre Julliard23946ad1997-06-16 17:43:53 +000061
Alexandre Julliard349a9531997-02-02 19:01:52 +000062 if (!X11DRV_BITMAP_Init()) return FALSE;
63
Huw D M Davies6f7fc502002-01-29 03:07:21 +000064 /* Initialize XRender */
65 X11DRV_XRender_Init();
66
Alexandre Julliard23946ad1997-06-16 17:43:53 +000067 /* Initialize fonts and text caps */
Alexandre Julliard349a9531997-02-02 19:01:52 +000068
Alexandre Julliard99bb9f92001-07-28 00:18:02 +000069 log_pixels_x = MulDiv( WidthOfScreen(screen), 254, WidthMMOfScreen(screen) * 10 );
70 log_pixels_y = MulDiv( HeightOfScreen(screen), 254, HeightMMOfScreen(screen) * 10 );
Huw D M Daviese1e51f92002-04-03 21:18:50 +000071 X11DRV_FONT_Init( &log_pixels_x, &log_pixels_y );
Alexandre Julliard99bb9f92001-07-28 00:18:02 +000072 horz_size = MulDiv( screen_width, 254, log_pixels_x * 10 );
73 vert_size = MulDiv( screen_height, 254, log_pixels_y * 10 );
74 return TRUE;
Alexandre Julliard0e270f41996-08-24 18:26:35 +000075}
76
Alexandre Julliard0e270f41996-08-24 18:26:35 +000077/**********************************************************************
Patrik Stridvallb87fe2e1999-04-01 08:16:08 +000078 * X11DRV_GDI_Finalize
79 */
80void X11DRV_GDI_Finalize(void)
81{
Alexandre Julliardc5597352001-05-11 00:17:47 +000082 X11DRV_PALETTE_Cleanup();
83 XCloseDisplay( gdi_display );
84 gdi_display = NULL;
Patrik Stridvallb87fe2e1999-04-01 08:16:08 +000085}
86
87/**********************************************************************
Alexandre Julliard0e270f41996-08-24 18:26:35 +000088 * X11DRV_CreateDC
89 */
Dmitry Timoshkov3a910c72003-08-12 20:42:18 +000090BOOL X11DRV_CreateDC( DC *dc, X11DRV_PDEVICE **pdev, LPCWSTR driver, LPCWSTR device,
91 LPCWSTR output, const DEVMODEW* initData )
Alexandre Julliard0e270f41996-08-24 18:26:35 +000092{
93 X11DRV_PDEVICE *physDev;
94
Alexandre Julliard3dd63eb2001-07-27 19:37:31 +000095 if (!X11DRV_DC_Funcs) X11DRV_DC_Funcs = dc->funcs; /* hack */
96
Alexandre Julliarde21c15e2002-03-28 22:22:05 +000097 physDev = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*physDev) );
Huw D M Davies9c68faa1998-11-25 12:36:03 +000098 if(!physDev) {
Alexandre Julliard61fece01999-06-26 19:09:08 +000099 ERR("Can't allocate physDev\n");
Huw D M Davies9c68faa1998-11-25 12:36:03 +0000100 return FALSE;
101 }
Alexandre Julliardd3cab182002-06-10 22:52:47 +0000102 *pdev = physDev;
Alexandre Julliarde21c15e2002-03-28 22:22:05 +0000103 physDev->hdc = dc->hSelf;
104 physDev->dc = dc; /* FIXME */
Alexandre Julliard0e270f41996-08-24 18:26:35 +0000105
Alexandre Julliarde1147ba2003-05-13 23:56:12 +0000106 if (GetObjectType( dc->hSelf ) == OBJ_MEMDC)
Alexandre Julliard0e270f41996-08-24 18:26:35 +0000107 {
Alexandre Julliardd8a92442002-05-31 18:43:22 +0000108 physDev->drawable = BITMAP_stock_pixmap;
Alexandre Julliardb89525f2004-01-18 22:20:17 +0000109 physDev->depth = 1;
Alexandre Julliard0e270f41996-08-24 18:26:35 +0000110 }
111 else
112 {
Alexandre Julliardc5597352001-05-11 00:17:47 +0000113 physDev->drawable = root_window;
Alexandre Julliardb89525f2004-01-18 22:20:17 +0000114 physDev->depth = screen_depth;
Alexandre Julliard0e270f41996-08-24 18:26:35 +0000115 }
Alexandre Julliardd3cab182002-06-10 22:52:47 +0000116 physDev->org.x = physDev->org.y = 0;
117 physDev->drawable_org.x = physDev->drawable_org.y = 0;
Alexandre Julliard0e270f41996-08-24 18:26:35 +0000118
Lionel Ulmerbedf40b2000-05-12 20:18:14 +0000119 physDev->current_pf = 0;
120 physDev->used_visuals = 0;
Alexandre Julliardc5597352001-05-11 00:17:47 +0000121
Alexandre Julliardc5597352001-05-11 00:17:47 +0000122 wine_tsx11_lock();
Alexandre Julliardd8a92442002-05-31 18:43:22 +0000123 physDev->gc = XCreateGC( gdi_display, physDev->drawable, 0, NULL );
Alexandre Julliardc5597352001-05-11 00:17:47 +0000124 XSetGraphicsExposures( gdi_display, physDev->gc, False );
125 XSetSubwindowMode( gdi_display, physDev->gc, IncludeInferiors );
126 XFlush( gdi_display );
127 wine_tsx11_unlock();
Alexandre Julliard0e270f41996-08-24 18:26:35 +0000128 return TRUE;
129}
130
131
132/**********************************************************************
133 * X11DRV_DeleteDC
134 */
Alexandre Julliarde21c15e2002-03-28 22:22:05 +0000135BOOL X11DRV_DeleteDC( X11DRV_PDEVICE *physDev )
Alexandre Julliard0e270f41996-08-24 18:26:35 +0000136{
Huw D M Davies6f7fc502002-01-29 03:07:21 +0000137 if(physDev->xrender)
Alexandre Julliarde21c15e2002-03-28 22:22:05 +0000138 X11DRV_XRender_DeleteDC( physDev );
Alexandre Julliardc5597352001-05-11 00:17:47 +0000139 wine_tsx11_lock();
140 XFreeGC( gdi_display, physDev->gc );
Lionel Ulmerbedf40b2000-05-12 20:18:14 +0000141 while (physDev->used_visuals-- > 0)
Alexandre Julliardc5597352001-05-11 00:17:47 +0000142 XFree(physDev->visuals[physDev->used_visuals]);
143 wine_tsx11_unlock();
Huw D M Davies9c68faa1998-11-25 12:36:03 +0000144 HeapFree( GetProcessHeap(), 0, physDev );
Alexandre Julliard0e270f41996-08-24 18:26:35 +0000145 return TRUE;
146}
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000147
Alexandre Julliard99bb9f92001-07-28 00:18:02 +0000148
149/***********************************************************************
150 * GetDeviceCaps (X11DRV.@)
151 */
Alexandre Julliarde21c15e2002-03-28 22:22:05 +0000152INT X11DRV_GetDeviceCaps( X11DRV_PDEVICE *physDev, INT cap )
Alexandre Julliard99bb9f92001-07-28 00:18:02 +0000153{
154 switch(cap)
155 {
156 case DRIVERVERSION:
157 return 0x300;
158 case TECHNOLOGY:
159 return DT_RASDISPLAY;
160 case HORZSIZE:
161 return horz_size;
162 case VERTSIZE:
163 return vert_size;
164 case HORZRES:
165 return screen_width;
166 case VERTRES:
167 return screen_height;
168 case BITSPIXEL:
169 return screen_depth;
170 case PLANES:
171 return 1;
172 case NUMBRUSHES:
173 return -1;
174 case NUMPENS:
175 return -1;
176 case NUMMARKERS:
177 return 0;
178 case NUMFONTS:
179 return 0;
180 case NUMCOLORS:
181 /* MSDN: Number of entries in the device's color table, if the device has
182 * a color depth of no more than 8 bits per pixel.For devices with greater
183 * color depths, -1 is returned. */
184 return (screen_depth > 8) ? -1 : (1 << screen_depth);
185 case PDEVICESIZE:
186 return sizeof(X11DRV_PDEVICE);
187 case CURVECAPS:
188 return (CC_CIRCLES | CC_PIE | CC_CHORD | CC_ELLIPSES | CC_WIDE |
189 CC_STYLED | CC_WIDESTYLED | CC_INTERIORS | CC_ROUNDRECT);
190 case LINECAPS:
191 return (LC_POLYLINE | LC_MARKER | LC_POLYMARKER | LC_WIDE |
192 LC_STYLED | LC_WIDESTYLED | LC_INTERIORS);
193 case POLYGONALCAPS:
194 return (PC_POLYGON | PC_RECTANGLE | PC_WINDPOLYGON | PC_SCANLINE |
195 PC_WIDE | PC_STYLED | PC_WIDESTYLED | PC_INTERIORS);
196 case TEXTCAPS:
197 return text_caps;
198 case CLIPCAPS:
199 return CP_REGION;
200 case RASTERCAPS:
201 return (RC_BITBLT | RC_BANDING | RC_SCALING | RC_BITMAP64 | RC_DI_BITMAP |
202 RC_DIBTODEV | RC_BIGFONT | RC_STRETCHBLT | RC_STRETCHDIB | RC_DEVBITS |
203 (palette_size ? RC_PALETTE : 0));
204 case ASPECTX:
205 case ASPECTY:
206 return 36;
207 case ASPECTXY:
208 return 51;
209 case LOGPIXELSX:
210 return log_pixels_x;
211 case LOGPIXELSY:
212 return log_pixels_y;
213 case CAPS1:
Alexandre Julliarde0315e42002-10-31 02:38:20 +0000214 FIXME("(%p): CAPS1 is unimplemented, will return 0\n", physDev->hdc );
Alexandre Julliard99bb9f92001-07-28 00:18:02 +0000215 /* please see wingdi.h for the possible bit-flag values that need
Vincent Béron9a624912002-05-31 23:06:46 +0000216 to be returned. also, see
Alexandre Julliard99bb9f92001-07-28 00:18:02 +0000217 http://msdn.microsoft.com/library/ddkdoc/win95ddk/graphcnt_1m0p.htm */
218 return 0;
219 case SIZEPALETTE:
220 return palette_size;
221 case NUMRESERVED:
222 case COLORRES:
223 case PHYSICALWIDTH:
224 case PHYSICALHEIGHT:
225 case PHYSICALOFFSETX:
226 case PHYSICALOFFSETY:
227 case SCALINGFACTORX:
228 case SCALINGFACTORY:
229 case VREFRESH:
230 case DESKTOPVERTRES:
231 case DESKTOPHORZRES:
232 case BTLALIGNMENT:
233 return 0;
234 default:
Alexandre Julliarde0315e42002-10-31 02:38:20 +0000235 FIXME("(%p): unsupported capability %d, will return 0\n", physDev->hdc, cap );
Alexandre Julliard99bb9f92001-07-28 00:18:02 +0000236 return 0;
237 }
238}
239
240
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000241/**********************************************************************
Alexandre Julliard92083012001-07-29 20:25:14 +0000242 * ExtEscape (X11DRV.@)
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000243 */
Alexandre Julliarde21c15e2002-03-28 22:22:05 +0000244INT X11DRV_ExtEscape( X11DRV_PDEVICE *physDev, INT escape, INT in_count, LPCVOID in_data,
Alexandre Julliard92083012001-07-29 20:25:14 +0000245 INT out_count, LPVOID out_data )
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000246{
Alexandre Julliard92083012001-07-29 20:25:14 +0000247 switch(escape)
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000248 {
Alexandre Julliard92083012001-07-29 20:25:14 +0000249 case QUERYESCSUPPORT:
250 if (in_data)
251 {
252 switch (*(INT *)in_data)
253 {
254 case DCICOMMAND:
255 return DD_HAL_VERSION;
Alexandre Julliardced71ed2002-03-23 21:43:56 +0000256 case X11DRV_ESCAPE:
257 return TRUE;
Alexandre Julliard92083012001-07-29 20:25:14 +0000258 }
259 }
260 break;
Ove Kaaven8f7ac8b2001-04-17 17:29:59 +0000261
Alexandre Julliard92083012001-07-29 20:25:14 +0000262 case DCICOMMAND:
263 if (in_data)
264 {
265 const DCICMD *lpCmd = in_data;
266 if (lpCmd->dwVersion != DD_VERSION) break;
267 return X11DRV_DCICommand(in_count, lpCmd, out_data);
268 }
269 break;
Alexandre Julliardced71ed2002-03-23 21:43:56 +0000270
271 case X11DRV_ESCAPE:
272 if (in_data && in_count >= sizeof(enum x11drv_escape_codes))
273 {
274 switch(*(enum x11drv_escape_codes *)in_data)
275 {
276 case X11DRV_GET_DISPLAY:
277 if (out_count >= sizeof(Display *))
278 {
279 *(Display **)out_data = gdi_display;
280 return TRUE;
281 }
282 break;
283 case X11DRV_GET_DRAWABLE:
284 if (out_count >= sizeof(Drawable))
285 {
286 *(Drawable *)out_data = physDev->drawable;
287 return TRUE;
288 }
289 break;
290 case X11DRV_GET_FONT:
291 if (out_count >= sizeof(Font))
292 {
293 fontObject* pfo = XFONT_GetFontObject( physDev->font );
Lionel Ulmera3f4e7f2002-07-03 01:16:45 +0000294 if (pfo == NULL) return FALSE;
Alexandre Julliardced71ed2002-03-23 21:43:56 +0000295 *(Font *)out_data = pfo->fs->fid;
296 return TRUE;
297 }
Alexandre Julliard85dcf1e2004-01-14 04:53:11 +0000298 break;
299 case X11DRV_SET_DRAWABLE:
300 if (in_count >= sizeof(struct x11drv_escape_set_drawable))
301 {
302 struct x11drv_escape_set_drawable *data = (struct x11drv_escape_set_drawable *)in_data;
303 if(physDev->xrender) X11DRV_XRender_UpdateDrawable( physDev );
304 physDev->org = data->org;
305 physDev->drawable = data->drawable;
306 physDev->drawable_org = data->drawable_org;
307 wine_tsx11_lock();
308 XSetSubwindowMode( gdi_display, physDev->gc, data->mode );
309 wine_tsx11_unlock();
310 return TRUE;
311 }
312 break;
313 case X11DRV_START_EXPOSURES:
314 wine_tsx11_lock();
315 XSetGraphicsExposures( gdi_display, physDev->gc, True );
316 wine_tsx11_unlock();
317 physDev->exposures = 0;
318 return TRUE;
319 case X11DRV_END_EXPOSURES:
320 if (out_count >= sizeof(HRGN))
321 {
322 HRGN hrgn = 0, tmp = 0;
323
324 wine_tsx11_lock();
325 XSetGraphicsExposures( gdi_display, physDev->gc, False );
326 if (physDev->exposures)
327 {
328 for (;;)
329 {
330 XEvent event;
331
332 XWindowEvent( gdi_display, physDev->drawable, ~0, &event );
333 if (event.type == NoExpose) break;
334 if (event.type == GraphicsExpose)
335 {
336 int x = event.xgraphicsexpose.x - physDev->org.x;
337 int y = event.xgraphicsexpose.y - physDev->org.y;
338
339 TRACE( "got %d,%d %dx%d count %d\n", x, y,
340 event.xgraphicsexpose.width,
341 event.xgraphicsexpose.height,
342 event.xgraphicsexpose.count );
343
344 if (!tmp) tmp = CreateRectRgn( 0, 0, 0, 0 );
345 SetRectRgn( tmp, x, y,
346 x + event.xgraphicsexpose.width,
347 y + event.xgraphicsexpose.height );
348 if (hrgn) CombineRgn( hrgn, hrgn, tmp, RGN_OR );
349 else
350 {
351 hrgn = tmp;
352 tmp = 0;
353 }
354 if (!event.xgraphicsexpose.count) break;
355 }
356 else
357 {
358 ERR( "got unexpected event %d\n", event.type );
359 break;
360 }
361 }
362 if (tmp) DeleteObject( tmp );
363 }
364 wine_tsx11_unlock();
365 *(HRGN *)out_data = hrgn;
366 return TRUE;
367 }
368 break;
Alexandre Julliardced71ed2002-03-23 21:43:56 +0000369 }
370 }
371 break;
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000372 }
373 return 0;
374}