Added definitions of MERITs.
[wine] / include / x11drv.h
1 /*
2  * X11 driver definitions
3  */
4
5 #ifndef __WINE_X11DRV_H
6 #define __WINE_X11DRV_H
7
8 #include "config.h"
9
10 #include <X11/Xlib.h>
11 #include <X11/Xresource.h>
12 #include <X11/Xutil.h>
13 #include <X11/Xatom.h>
14 #ifdef HAVE_LIBXXSHM
15 # include <X11/extensions/XShm.h>
16 #endif /* defined(HAVE_LIBXXSHM) */
17
18 #include "windef.h"
19 #include "winbase.h"
20 #include "gdi.h"
21 #include "user.h"
22 #include "win.h"
23 #include "thread.h"
24
25 #define MAX_PIXELFORMATS 8
26
27 struct tagBITMAPOBJ;
28 struct tagCURSORICONINFO;
29 struct tagDC;
30 struct tagDeviceCaps;
31 struct tagPALETTEOBJ;
32 struct tagWINDOWPOS;
33
34   /* X physical pen */
35 typedef struct
36 {
37     int          style;
38     int          endcap;
39     int          linejoin;
40     int          pixel;
41     int          width;
42     char *       dashes;
43     int          dash_len;
44     int          type;          /* GEOMETRIC || COSMETIC */
45 } X_PHYSPEN;
46
47   /* X physical brush */
48 typedef struct
49 {
50     int          style;
51     int          fillStyle;
52     int          pixel;
53     Pixmap       pixmap;
54 } X_PHYSBRUSH;
55
56   /* X physical font */
57 typedef UINT     X_PHYSFONT;
58
59   /* X physical device */
60 typedef struct
61 {
62     GC            gc;          /* X Window GC */
63     Drawable      drawable;
64     X_PHYSFONT    font;
65     X_PHYSPEN     pen;
66     X_PHYSBRUSH   brush;
67     int           backgroundPixel;
68     int           textPixel;
69     int           exposures;   /* count of graphics exposures operations */
70     XVisualInfo  *visuals[MAX_PIXELFORMATS];
71     int           used_visuals;
72     int           current_pf;
73 } X11DRV_PDEVICE;
74
75
76   /* GCs used for B&W and color bitmap operations */
77 extern GC BITMAP_monoGC, BITMAP_colorGC;
78
79 #define BITMAP_GC(bmp) \
80   (((bmp)->bitmap.bmBitsPixel == 1) ? BITMAP_monoGC : BITMAP_colorGC)
81
82 extern unsigned int X11DRV_server_startticks;
83
84 /* Wine driver X11 functions */
85
86 extern BOOL X11DRV_BitBlt( struct tagDC *dcDst, INT xDst, INT yDst,
87                              INT width, INT height, struct tagDC *dcSrc,
88                              INT xSrc, INT ySrc, DWORD rop );
89 extern BOOL X11DRV_EnumDeviceFonts( HDC hdc, LPLOGFONTW plf,
90                                     DEVICEFONTENUMPROC dfeproc, LPARAM lp );
91 extern BOOL X11DRV_GetCharWidth( struct tagDC *dc, UINT firstChar,
92                                    UINT lastChar, LPINT buffer );
93 extern BOOL X11DRV_GetDCOrgEx( struct tagDC *dc, LPPOINT lpp );
94 extern BOOL X11DRV_GetTextExtentPoint( struct tagDC *dc, LPCWSTR str,
95                                          INT count, LPSIZE size );
96 extern BOOL X11DRV_GetTextMetrics(struct tagDC *dc, TEXTMETRICW *metrics);
97 extern BOOL X11DRV_PatBlt( struct tagDC *dc, INT left, INT top,
98                              INT width, INT height, DWORD rop );
99 extern VOID   X11DRV_SetDeviceClipping(struct tagDC *dc);
100 extern BOOL X11DRV_StretchBlt( struct tagDC *dcDst, INT xDst, INT yDst,
101                                  INT widthDst, INT heightDst,
102                                  struct tagDC *dcSrc, INT xSrc, INT ySrc,
103                                  INT widthSrc, INT heightSrc, DWORD rop );
104 extern BOOL X11DRV_LineTo( struct tagDC *dc, INT x, INT y);
105 extern BOOL X11DRV_Arc( struct tagDC *dc, INT left, INT top, INT right,
106                           INT bottom, INT xstart, INT ystart, INT xend,
107                           INT yend );
108 extern BOOL X11DRV_Pie( struct tagDC *dc, INT left, INT top, INT right,
109                           INT bottom, INT xstart, INT ystart, INT xend,
110                           INT yend );
111 extern BOOL X11DRV_Chord( struct tagDC *dc, INT left, INT top,
112                             INT right, INT bottom, INT xstart,
113                             INT ystart, INT xend, INT yend );
114 extern BOOL X11DRV_Ellipse( struct tagDC *dc, INT left, INT top,
115                               INT right, INT bottom );
116 extern BOOL X11DRV_Rectangle(struct tagDC *dc, INT left, INT top,
117                               INT right, INT bottom);
118 extern BOOL X11DRV_RoundRect( struct tagDC *dc, INT left, INT top,
119                                 INT right, INT bottom, INT ell_width,
120                                 INT ell_height );
121 extern COLORREF X11DRV_SetPixel( struct tagDC *dc, INT x, INT y,
122                                  COLORREF color );
123 extern COLORREF X11DRV_GetPixel( struct tagDC *dc, INT x, INT y);
124 extern BOOL X11DRV_PaintRgn( struct tagDC *dc, HRGN hrgn );
125 extern BOOL X11DRV_Polyline( struct tagDC *dc,const POINT* pt,INT count);
126 extern BOOL X11DRV_Polygon( struct tagDC *dc, const POINT* pt, INT count );
127 extern BOOL X11DRV_PolyPolygon( struct tagDC *dc, const POINT* pt, 
128                                   const INT* counts, UINT polygons);
129 extern BOOL X11DRV_PolyPolyline( struct tagDC *dc, const POINT* pt, 
130                                   const DWORD* counts, DWORD polylines);
131
132 extern HGDIOBJ X11DRV_SelectObject( struct tagDC *dc, HGDIOBJ handle );
133
134 extern COLORREF X11DRV_SetBkColor( struct tagDC *dc, COLORREF color );
135 extern COLORREF X11DRV_SetTextColor( struct tagDC *dc, COLORREF color );
136 extern BOOL X11DRV_ExtFloodFill( struct tagDC *dc, INT x, INT y,
137                                    COLORREF color, UINT fillType );
138 extern BOOL X11DRV_ExtTextOut( struct tagDC *dc, INT x, INT y,
139                                  UINT flags, const RECT *lprect,
140                                  LPCWSTR str, UINT count, const INT *lpDx );
141 extern BOOL X11DRV_CreateBitmap( HBITMAP hbitmap );
142 extern BOOL X11DRV_DeleteObject( HGDIOBJ handle );
143 extern LONG X11DRV_BitmapBits( HBITMAP hbitmap, void *bits, LONG count,
144                                WORD flags );
145 extern INT X11DRV_SetDIBitsToDevice( struct tagDC *dc, INT xDest,
146                                        INT yDest, DWORD cx, DWORD cy,
147                                        INT xSrc, INT ySrc,
148                                        UINT startscan, UINT lines,
149                                        LPCVOID bits, const BITMAPINFO *info,
150                                        UINT coloruse );
151 extern INT X11DRV_DeviceBitmapBits( struct tagDC *dc, HBITMAP hbitmap,
152                                       WORD fGet, UINT startscan,
153                                       UINT lines, LPSTR bits,
154                                       LPBITMAPINFO info, UINT coloruse );
155 extern BOOL X11DRV_GetDeviceGammaRamp( struct tagDC *dc, LPVOID ramp );
156 extern BOOL X11DRV_SetDeviceGammaRamp( struct tagDC *dc, LPVOID ramp );
157
158 /* OpenGL / X11 driver functions */
159 extern int X11DRV_ChoosePixelFormat(DC *dc, const PIXELFORMATDESCRIPTOR *pppfd) ;
160 extern int X11DRV_DescribePixelFormat(DC *dc, int iPixelFormat, UINT nBytes, PIXELFORMATDESCRIPTOR *ppfd) ;
161 extern int X11DRV_GetPixelFormat(DC *dc) ;
162 extern BOOL X11DRV_SetPixelFormat(DC *dc, int iPixelFormat, const PIXELFORMATDESCRIPTOR *ppfd) ;
163 extern BOOL X11DRV_SwapBuffers(DC *dc) ;
164
165 /* X11 driver internal functions */
166
167 extern BOOL X11DRV_BITMAP_Init(void);
168 extern int X11DRV_FONT_Init( int *log_pixels_x, int *log_pixels_y );
169 extern BOOL X11DRV_OBM_Init(void);
170 extern HBRUSH X11DRV_BRUSH_SelectObject( DC * dc, HBRUSH hbrush );
171 extern HFONT X11DRV_FONT_SelectObject( DC * dc, HFONT hfont );
172 extern HPEN X11DRV_PEN_SelectObject( DC * dc, HPEN hpen );
173 extern HBITMAP X11DRV_BITMAP_SelectObject( DC * dc, HBITMAP hbitmap );
174 extern BOOL X11DRV_BITMAP_DeleteObject( HBITMAP hbitmap );
175
176 struct tagBITMAPOBJ;
177 extern XImage *X11DRV_BITMAP_GetXImage( const struct tagBITMAPOBJ *bmp );
178 extern XImage *X11DRV_DIB_CreateXImage( int width, int height, int depth );
179 extern HBITMAP X11DRV_BITMAP_CreateBitmapHeaderFromPixmap(Pixmap pixmap);
180 extern HGLOBAL X11DRV_DIB_CreateDIBFromPixmap(Pixmap pixmap, HDC hdc, BOOL bDeletePixmap);
181 extern HBITMAP X11DRV_BITMAP_CreateBitmapFromPixmap(Pixmap pixmap, BOOL bDeletePixmap);
182 extern Pixmap X11DRV_DIB_CreatePixmapFromDIB( HGLOBAL hPackedDIB, HDC hdc );
183 extern Pixmap X11DRV_BITMAP_CreatePixmapFromBitmap( HBITMAP hBmp, HDC hdc );
184
185 extern void X11DRV_SetDrawable( HDC hdc, Drawable drawable, int mode, int org_x, int org_y );
186 extern void X11DRV_StartGraphicsExposures( HDC hdc );
187 extern void X11DRV_EndGraphicsExposures( HDC hdc, HRGN hrgn );
188
189 extern BOOL X11DRV_SetupGCForPatBlt( struct tagDC *dc, GC gc, BOOL fMapColors );
190 extern BOOL X11DRV_SetupGCForBrush( struct tagDC *dc );
191 extern BOOL X11DRV_SetupGCForPen( struct tagDC *dc );
192 extern BOOL X11DRV_SetupGCForText( struct tagDC *dc );
193
194 extern const int X11DRV_XROPfunction[];
195
196 extern void _XInitImageFuncPtrs(XImage *);
197
198 /* exported dib functions for now */
199
200 /* Additional info for DIB section objects */
201 typedef struct
202 {
203     /* Windows DIB section */
204     DIBSECTION  dibSection;
205
206     /* Mapping status */
207     int         status, p_status;
208
209     /* Color map info */
210     int         nColorMap;
211     int        *colorMap;
212
213     /* Cached XImage */
214     XImage     *image;
215
216 #ifdef HAVE_LIBXXSHM
217     /* Shared memory segment info */
218     XShmSegmentInfo shminfo;
219 #endif
220
221     /* Aux buffer access function */
222     void (*copy_aux)(void*ctx, int req);
223     void *aux_ctx;
224
225     /* GDI access lock */
226     CRITICAL_SECTION lock;
227
228 } X11DRV_DIBSECTION;
229
230 extern int *X11DRV_DIB_BuildColorMap( struct tagDC *dc, WORD coloruse,
231                                       WORD depth, const BITMAPINFO *info,
232                                       int *nColors );
233 extern INT X11DRV_CoerceDIBSection(struct tagDC *dc,INT,BOOL);
234 extern INT X11DRV_LockDIBSection(struct tagDC *dc,INT,BOOL);
235 extern void X11DRV_UnlockDIBSection(struct tagDC *dc,BOOL);
236 extern INT X11DRV_CoerceDIBSection2(HBITMAP bmp,INT,BOOL);
237 extern INT X11DRV_LockDIBSection2(HBITMAP bmp,INT,BOOL);
238 extern void X11DRV_UnlockDIBSection2(HBITMAP bmp,BOOL);
239
240 extern HBITMAP X11DRV_DIB_CreateDIBSection(struct tagDC *dc, BITMAPINFO *bmi, UINT usage,
241                                            LPVOID *bits, HANDLE section, DWORD offset, DWORD ovr_pitch);
242
243 extern struct tagBITMAP_DRIVER X11DRV_BITMAP_Driver;
244
245 extern INT X11DRV_DIB_SetDIBits(struct tagBITMAPOBJ *bmp, struct tagDC *dc, UINT startscan,
246                                 UINT lines, LPCVOID bits, const BITMAPINFO *info,
247                                 UINT coloruse, HBITMAP hbitmap);
248 extern INT X11DRV_DIB_GetDIBits(struct tagBITMAPOBJ *bmp, struct tagDC *dc, UINT startscan,
249                                 UINT lines, LPVOID bits, BITMAPINFO *info,
250                                 UINT coloruse, HBITMAP hbitmap);
251 extern void X11DRV_DIB_DeleteDIBSection(struct tagBITMAPOBJ *bmp);
252 extern UINT X11DRV_DIB_SetDIBColorTable(struct tagBITMAPOBJ *,struct tagDC*,UINT,UINT,const RGBQUAD *);
253 extern UINT X11DRV_DIB_GetDIBColorTable(struct tagBITMAPOBJ *,struct tagDC*,UINT,UINT,RGBQUAD *);
254 extern INT X11DRV_DIB_Coerce(struct tagBITMAPOBJ *,INT,BOOL);
255 extern INT X11DRV_DIB_Lock(struct tagBITMAPOBJ *,INT,BOOL);
256 extern void X11DRV_DIB_Unlock(struct tagBITMAPOBJ *,BOOL);
257 void X11DRV_DIB_CopyDIBSection(DC *dcSrc, DC *dcDst,     
258                                DWORD xSrc, DWORD ySrc,   
259                                DWORD xDest, DWORD yDest, 
260                                DWORD width, DWORD height);
261 struct _DCICMD;
262 extern INT X11DRV_DCICommand(INT cbInput, const struct _DCICMD *lpCmd, LPVOID lpOutData);
263
264 /**************************************************************************
265  * X11 GDI driver
266  */
267
268 BOOL X11DRV_GDI_Initialize( Display *display );
269 void X11DRV_GDI_Finalize(void);
270
271 extern Display *gdi_display;  /* display to use for all GDI functions */
272
273 /* X11 GDI palette driver */
274
275 #define X11DRV_PALETTE_FIXED    0x0001 /* read-only colormap - have to use XAllocColor (if not virtual) */
276 #define X11DRV_PALETTE_VIRTUAL  0x0002 /* no mapping needed - pixel == pixel color */
277
278 #define X11DRV_PALETTE_PRIVATE  0x1000 /* private colormap, identity mapping */
279 #define X11DRV_PALETTE_WHITESET 0x2000
280
281 extern Colormap X11DRV_PALETTE_PaletteXColormap;
282 extern UINT16 X11DRV_PALETTE_PaletteFlags;
283
284 extern int *X11DRV_PALETTE_PaletteToXPixel;
285 extern int *X11DRV_PALETTE_XPixelToPalette;
286
287 extern int X11DRV_PALETTE_mapEGAPixel[16];
288
289 extern int X11DRV_PALETTE_Init(void);
290 extern void X11DRV_PALETTE_Cleanup(void);
291
292 extern COLORREF X11DRV_PALETTE_ToLogical(int pixel);
293 extern int X11DRV_PALETTE_ToPhysical(struct tagDC *dc, COLORREF color);
294
295 extern struct tagPALETTE_DRIVER X11DRV_PALETTE_Driver;
296
297 extern int X11DRV_PALETTE_SetMapping(struct tagPALETTEOBJ *palPtr, UINT uStart, UINT uNum, BOOL mapOnly);
298 extern int X11DRV_PALETTE_UpdateMapping(struct tagPALETTEOBJ *palPtr);
299 extern BOOL X11DRV_PALETTE_IsDark(int pixel);
300
301 /**************************************************************************
302  * X11 USER driver
303  */
304
305 struct x11drv_thread_data
306 {
307     Display *display;
308     HANDLE   display_fd;
309     int      process_event_count;  /* recursion count for event processing */
310 };
311
312 extern struct x11drv_thread_data *x11drv_init_thread_data(void);
313
314 inline static struct x11drv_thread_data *x11drv_thread_data(void)
315 {
316     struct x11drv_thread_data *data = NtCurrentTeb()->driver_data;
317     if (!data) data = x11drv_init_thread_data();
318     return data;
319 }
320
321 inline static Display *thread_display(void) { return x11drv_thread_data()->display; }
322
323 extern Visual *visual;
324 extern Window root_window;
325 extern unsigned int screen_width;
326 extern unsigned int screen_height;
327 extern unsigned int screen_depth;
328
329 extern Atom wmProtocols;
330 extern Atom wmDeleteWindow;
331 extern Atom wmTakeFocus;
332 extern Atom dndProtocol;
333 extern Atom dndSelection;
334 extern Atom wmChangeState;
335 extern Atom kwmDockWindow;
336 extern Atom _kde_net_wm_system_tray_window_for;
337
338 /* X11 clipboard driver */
339
340 extern void X11DRV_CLIPBOARD_FreeResources( Atom property );
341 extern BOOL X11DRV_CLIPBOARD_RegisterPixmapResource( Atom property, Pixmap pixmap );
342 extern BOOL X11DRV_CLIPBOARD_IsNativeProperty(Atom prop);
343 extern UINT X11DRV_CLIPBOARD_MapPropertyToFormat(char *itemFmtName);
344 extern Atom X11DRV_CLIPBOARD_MapFormatToProperty(UINT id);
345 extern void X11DRV_CLIPBOARD_ReleaseSelection(Atom selType, Window w, HWND hwnd);
346 extern BOOL X11DRV_IsSelectionOwner(void);
347 extern BOOL X11DRV_GetClipboardData(UINT wFormat);
348
349 /* X11 event driver */
350
351 typedef enum {
352   X11DRV_INPUT_RELATIVE,
353   X11DRV_INPUT_ABSOLUTE
354 } INPUT_TYPE;
355 extern INPUT_TYPE X11DRV_EVENT_SetInputMethod(INPUT_TYPE type);
356
357 #ifdef HAVE_LIBXXF86DGA2
358 void X11DRV_EVENT_SetDGAStatus(HWND hwnd, int event_base) ;
359 #endif
360
361 /* x11drv private window data */
362 struct x11drv_win_data
363 {
364     Window  whole_window;   /* X window for the complete window */
365     Window  client_window;  /* X window for the client area */
366     Window  icon_window;    /* X window for the icon */
367     RECT    whole_rect;     /* X window rectangle for the whole window relative to parent */
368     RECT    client_rect;    /* client area relative to whole window */
369     HBITMAP hWMIconBitmap;
370     HBITMAP hWMIconMask;
371 };
372
373 typedef struct x11drv_win_data X11DRV_WND_DATA;
374
375 extern Window X11DRV_get_client_window( HWND hwnd );
376 extern Window X11DRV_get_whole_window( HWND hwnd );
377
378 inline static Window get_client_window( WND *wnd )
379 {
380     struct x11drv_win_data *data = wnd->pDriverData;
381     return data->client_window;
382 }
383
384 inline static Window get_whole_window( WND *wnd )
385 {
386     struct x11drv_win_data *data = wnd->pDriverData;
387     return data->whole_window;
388 }
389
390 extern void X11DRV_SetFocus( HWND hwnd );
391 extern Cursor X11DRV_GetCursor( Display *display, struct tagCURSORICONINFO *ptr );
392
393 extern void X11DRV_expect_error( unsigned char request, unsigned char error, XID id );
394 extern int X11DRV_check_error(void);
395 extern void X11DRV_register_window( Display *display, HWND hwnd, struct x11drv_win_data *data );
396 extern void X11DRV_set_iconic_state( WND *win );
397 extern void X11DRV_window_to_X_rect( WND *win, RECT *rect );
398 extern void X11DRV_X_to_window_rect( WND *win, RECT *rect );
399 extern void X11DRV_create_desktop_thread(void);
400 extern Window X11DRV_create_desktop( XVisualInfo *desktop_vi, const char *geometry );
401 extern int X11DRV_sync_whole_window_position( Display *display, WND *win, int zorder );
402 extern int X11DRV_sync_client_window_position( Display *display, WND *win );
403
404 #endif  /* __WINE_X11DRV_H */