Support viewports the D3D7 way.
[wine/wine64.git] / graphics / x11drv / init.c
blob7577582205307d1f1963ecd32175ee2c5b6a6621
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 "windef.h"
28 #include "bitmap.h"
29 #include "x11drv.h"
30 #include "x11font.h"
31 #include "ddrawi.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(x11drv);
36 const DC_FUNCTIONS *X11DRV_DC_Funcs = NULL; /* hack */
38 Display *gdi_display; /* display to use for all GDI functions */
40 /* a few dynamic device caps */
41 static int log_pixels_x; /* pixels per logical inch in x direction */
42 static int log_pixels_y; /* pixels per logical inch in y direction */
43 static int horz_size; /* horz. size of screen in millimeters */
44 static int vert_size; /* vert. size of screen in millimeters */
45 static int palette_size;
46 unsigned 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 */
51 /**********************************************************************
52 * X11DRV_GDI_Initialize
54 BOOL X11DRV_GDI_Initialize( Display *display )
56 Screen *screen = DefaultScreenOfDisplay(display);
58 gdi_display = display;
60 palette_size = X11DRV_PALETTE_Init();
62 if (!X11DRV_BITMAP_Init()) return FALSE;
64 /* Initialize XRender */
65 X11DRV_XRender_Init();
67 /* Initialize fonts and text caps */
69 log_pixels_x = MulDiv( WidthOfScreen(screen), 254, WidthMMOfScreen(screen) * 10 );
70 log_pixels_y = MulDiv( HeightOfScreen(screen), 254, HeightMMOfScreen(screen) * 10 );
71 X11DRV_FONT_Init( &log_pixels_x, &log_pixels_y );
72 horz_size = MulDiv( screen_width, 254, log_pixels_x * 10 );
73 vert_size = MulDiv( screen_height, 254, log_pixels_y * 10 );
74 return TRUE;
77 /**********************************************************************
78 * X11DRV_GDI_Finalize
80 void X11DRV_GDI_Finalize(void)
82 X11DRV_PALETTE_Cleanup();
83 XCloseDisplay( gdi_display );
84 gdi_display = NULL;
87 /**********************************************************************
88 * X11DRV_CreateDC
90 BOOL X11DRV_CreateDC( DC *dc, X11DRV_PDEVICE **pdev, LPCSTR driver, LPCSTR device,
91 LPCSTR output, const DEVMODEA* initData )
93 X11DRV_PDEVICE *physDev;
95 if (!X11DRV_DC_Funcs) X11DRV_DC_Funcs = dc->funcs; /* hack */
97 physDev = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*physDev) );
98 if(!physDev) {
99 ERR("Can't allocate physDev\n");
100 return FALSE;
102 *pdev = physDev;
103 physDev->hdc = dc->hSelf;
104 physDev->dc = dc; /* FIXME */
106 if (dc->flags & DC_MEMORY)
108 physDev->drawable = BITMAP_stock_pixmap;
110 else
112 physDev->drawable = root_window;
113 dc->bitsPerPixel = screen_depth;
115 physDev->org.x = physDev->org.y = 0;
116 physDev->drawable_org.x = physDev->drawable_org.y = 0;
118 physDev->current_pf = 0;
119 physDev->used_visuals = 0;
121 wine_tsx11_lock();
122 physDev->gc = XCreateGC( gdi_display, physDev->drawable, 0, NULL );
123 XSetGraphicsExposures( gdi_display, physDev->gc, False );
124 XSetSubwindowMode( gdi_display, physDev->gc, IncludeInferiors );
125 XFlush( gdi_display );
126 wine_tsx11_unlock();
127 return TRUE;
131 /**********************************************************************
132 * X11DRV_DeleteDC
134 BOOL X11DRV_DeleteDC( X11DRV_PDEVICE *physDev )
136 if(physDev->xrender)
137 X11DRV_XRender_DeleteDC( physDev );
138 wine_tsx11_lock();
139 XFreeGC( gdi_display, physDev->gc );
140 while (physDev->used_visuals-- > 0)
141 XFree(physDev->visuals[physDev->used_visuals]);
142 wine_tsx11_unlock();
143 HeapFree( GetProcessHeap(), 0, physDev );
144 return TRUE;
148 /***********************************************************************
149 * GetDeviceCaps (X11DRV.@)
151 INT X11DRV_GetDeviceCaps( X11DRV_PDEVICE *physDev, INT cap )
153 switch(cap)
155 case DRIVERVERSION:
156 return 0x300;
157 case TECHNOLOGY:
158 return DT_RASDISPLAY;
159 case HORZSIZE:
160 return horz_size;
161 case VERTSIZE:
162 return vert_size;
163 case HORZRES:
164 return screen_width;
165 case VERTRES:
166 return screen_height;
167 case BITSPIXEL:
168 return screen_depth;
169 case PLANES:
170 return 1;
171 case NUMBRUSHES:
172 return -1;
173 case NUMPENS:
174 return -1;
175 case NUMMARKERS:
176 return 0;
177 case NUMFONTS:
178 return 0;
179 case NUMCOLORS:
180 /* MSDN: Number of entries in the device's color table, if the device has
181 * a color depth of no more than 8 bits per pixel.For devices with greater
182 * color depths, -1 is returned. */
183 return (screen_depth > 8) ? -1 : (1 << screen_depth);
184 case PDEVICESIZE:
185 return sizeof(X11DRV_PDEVICE);
186 case CURVECAPS:
187 return (CC_CIRCLES | CC_PIE | CC_CHORD | CC_ELLIPSES | CC_WIDE |
188 CC_STYLED | CC_WIDESTYLED | CC_INTERIORS | CC_ROUNDRECT);
189 case LINECAPS:
190 return (LC_POLYLINE | LC_MARKER | LC_POLYMARKER | LC_WIDE |
191 LC_STYLED | LC_WIDESTYLED | LC_INTERIORS);
192 case POLYGONALCAPS:
193 return (PC_POLYGON | PC_RECTANGLE | PC_WINDPOLYGON | PC_SCANLINE |
194 PC_WIDE | PC_STYLED | PC_WIDESTYLED | PC_INTERIORS);
195 case TEXTCAPS:
196 return text_caps;
197 case CLIPCAPS:
198 return CP_REGION;
199 case RASTERCAPS:
200 return (RC_BITBLT | RC_BANDING | RC_SCALING | RC_BITMAP64 | RC_DI_BITMAP |
201 RC_DIBTODEV | RC_BIGFONT | RC_STRETCHBLT | RC_STRETCHDIB | RC_DEVBITS |
202 (palette_size ? RC_PALETTE : 0));
203 case ASPECTX:
204 case ASPECTY:
205 return 36;
206 case ASPECTXY:
207 return 51;
208 case LOGPIXELSX:
209 return log_pixels_x;
210 case LOGPIXELSY:
211 return log_pixels_y;
212 case CAPS1:
213 FIXME("(%p): CAPS1 is unimplemented, will return 0\n", physDev->hdc );
214 /* please see wingdi.h for the possible bit-flag values that need
215 to be returned. also, see
216 http://msdn.microsoft.com/library/ddkdoc/win95ddk/graphcnt_1m0p.htm */
217 return 0;
218 case SIZEPALETTE:
219 return palette_size;
220 case NUMRESERVED:
221 case COLORRES:
222 case PHYSICALWIDTH:
223 case PHYSICALHEIGHT:
224 case PHYSICALOFFSETX:
225 case PHYSICALOFFSETY:
226 case SCALINGFACTORX:
227 case SCALINGFACTORY:
228 case VREFRESH:
229 case DESKTOPVERTRES:
230 case DESKTOPHORZRES:
231 case BTLALIGNMENT:
232 return 0;
233 default:
234 FIXME("(%p): unsupported capability %d, will return 0\n", physDev->hdc, cap );
235 return 0;
240 /**********************************************************************
241 * ExtEscape (X11DRV.@)
243 INT X11DRV_ExtEscape( X11DRV_PDEVICE *physDev, INT escape, INT in_count, LPCVOID in_data,
244 INT out_count, LPVOID out_data )
246 switch(escape)
248 case QUERYESCSUPPORT:
249 if (in_data)
251 switch (*(INT *)in_data)
253 case DCICOMMAND:
254 return DD_HAL_VERSION;
255 case X11DRV_ESCAPE:
256 return TRUE;
259 break;
261 case DCICOMMAND:
262 if (in_data)
264 const DCICMD *lpCmd = in_data;
265 if (lpCmd->dwVersion != DD_VERSION) break;
266 return X11DRV_DCICommand(in_count, lpCmd, out_data);
268 break;
270 case X11DRV_ESCAPE:
271 if (in_data && in_count >= sizeof(enum x11drv_escape_codes))
273 switch(*(enum x11drv_escape_codes *)in_data)
275 case X11DRV_GET_DISPLAY:
276 if (out_count >= sizeof(Display *))
278 *(Display **)out_data = gdi_display;
279 return TRUE;
281 break;
282 case X11DRV_GET_DRAWABLE:
283 if (out_count >= sizeof(Drawable))
285 *(Drawable *)out_data = physDev->drawable;
286 return TRUE;
288 break;
289 case X11DRV_GET_FONT:
290 if (out_count >= sizeof(Font))
292 fontObject* pfo = XFONT_GetFontObject( physDev->font );
293 if (pfo == NULL) return FALSE;
294 *(Font *)out_data = pfo->fs->fid;
295 return TRUE;
299 break;
301 return 0;