OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_COMMON_X11_UTIL_H_ | 5 #ifndef CHROME_COMMON_X11_UTIL_H_ |
6 #define CHROME_COMMON_X11_UTIL_H_ | 6 #define CHROME_COMMON_X11_UTIL_H_ |
7 | 7 |
8 // This file declares utility functions for X11 (Linux only). | 8 // This file declares utility functions for X11 (Linux only). |
9 // | 9 // |
10 // These functions do not require the Xlib headers to be included (which is why | 10 // These functions do not require the Xlib headers to be included (which is why |
11 // we use a void* for Visual*). The Xlib headers are highly polluting so we try | 11 // we use a void* for Visual*). The Xlib headers are highly polluting so we try |
12 // hard to limit their spread into the rest of the code. | 12 // hard to limit their spread into the rest of the code. |
13 | 13 |
| 14 typedef struct _GdkDrawable GdkWindow; |
14 typedef struct _GtkWidget GtkWidget; | 15 typedef struct _GtkWidget GtkWidget; |
15 typedef unsigned long XID; | 16 typedef unsigned long XID; |
16 typedef struct _XDisplay Display; | 17 typedef struct _XDisplay Display; |
17 | 18 |
| 19 namespace base { |
| 20 class Thread; |
| 21 } |
| 22 |
18 namespace gfx { | 23 namespace gfx { |
19 class Size; | 24 class Size; |
20 } | 25 } |
21 | 26 |
22 namespace x11_util { | 27 namespace x11_util { |
23 // These functions cache their results and must be called from the UI thread. | |
24 // Currently they don't support multiple screens/displays. | |
25 | 28 |
26 // Return an X11 connection for the current, primary display. | 29 // These functions use the GDK default display and this /must/ be called from |
27 Display* GetXDisplay(); | 30 // the UI thread. Thus, they don't support multiple displays. |
28 // Return true iff the connection supports X shared memory | |
29 bool QuerySharedMemorySupport(Display* dpy); | |
30 // Return true iff the display supports Xrender | |
31 bool QueryRenderSupport(Display* dpy); | |
32 | 31 |
33 // These functions do not cache their results | 32 // These functions cache their results. |
34 | 33 |
35 // Get the X window id for the default root window | 34 // Return an X11 connection for the current, primary display. |
36 XID GetX11RootWindow(); | 35 Display* GetXDisplay(); |
37 // Get the X window id for the given GTK widget. | 36 // Return true iff the connection supports X shared memory |
38 XID GetX11WindowFromGtkWidget(GtkWidget*); | 37 bool QuerySharedMemorySupport(Display* dpy); |
39 // Get a Visual from the given widget. Since we don't include the Xlib | 38 // Return true iff the display supports Xrender |
40 // headers, this is returned as a void*. | 39 bool QueryRenderSupport(Display* dpy); |
41 void* GetVisualFromGtkWidget(GtkWidget*); | 40 // Return the default screen number for the display |
42 // Return the number of bits-per-pixel for a pixmap of the given depth | 41 int GetDefaultScreen(Display* display); |
43 int BitsPerPixelForPixmapDepth(Display*, int depth); | |
44 | 42 |
45 // Return a handle to a server side pixmap. |shared_memory_key| is a SysV | 43 // These functions do not cache their results |
46 // IPC key. The shared memory region must contain 32-bit pixels. | |
47 XID AttachSharedMemory(Display* display, int shared_memory_support); | |
48 void DetachSharedMemory(Display* display, XID shmseg); | |
49 | 44 |
50 // Return a handle to an XRender picture where |pixmap| is a handle to a | 45 // Get the X window id for the default root window |
51 // pixmap containing Skia ARGB data. | 46 XID GetX11RootWindow(); |
52 XID CreatePictureFromSkiaPixmap(Display* display, XID pixmap); | 47 // Get the X window id for the given GTK widget. |
| 48 XID GetX11WindowFromGtkWidget(GtkWidget*); |
| 49 XID GetX11WindowFromGdkWindow(GdkWindow*); |
| 50 // Get a Visual from the given widget. Since we don't include the Xlib |
| 51 // headers, this is returned as a void*. |
| 52 void* GetVisualFromGtkWidget(GtkWidget*); |
| 53 // Return the number of bits-per-pixel for a pixmap of the given depth |
| 54 int BitsPerPixelForPixmapDepth(Display*, int depth); |
53 | 55 |
54 void FreePicture(Display* display, XID picture); | 56 // Return a handle to a server side pixmap. |shared_memory_key| is a SysV |
55 void FreePixmap(Display* display, XID pixmap); | 57 // IPC key. The shared memory region must contain 32-bit pixels. |
56 }; | 58 XID AttachSharedMemory(Display* display, int shared_memory_support); |
| 59 void DetachSharedMemory(Display* display, XID shmseg); |
| 60 |
| 61 // Return a handle to an XRender picture where |pixmap| is a handle to a |
| 62 // pixmap containing Skia ARGB data. |
| 63 XID CreatePictureFromSkiaPixmap(Display* display, XID pixmap); |
| 64 |
| 65 void FreePicture(Display* display, XID picture); |
| 66 void FreePixmap(Display* display, XID pixmap); |
| 67 |
| 68 // These functions are for performing X opertions outside of the UI thread. |
| 69 |
| 70 // Return the Display for the secondary X connection. We keep a second |
| 71 // connection around for making X requests outside of the UI thread. |
| 72 // This function may only be called from the BACKGROUND_X11 thread. |
| 73 Display* GetSecondaryDisplay(); |
| 74 |
| 75 // Since one cannot include both WebKit header and Xlib headers in the same |
| 76 // file (due to collisions), we wrap all the Xlib functions that we need here. |
| 77 // These functions must be called on the BACKGROUND_X11 thread since they |
| 78 // reference GetSecondaryDisplay(). |
| 79 |
| 80 void GetWindowGeometry(int* x, int* y, unsigned* width, unsigned* height, |
| 81 XID window); |
| 82 |
| 83 } // namespace x11_util |
57 | 84 |
58 #endif // CHROME_COMMON_X11_UTIL_H_ | 85 #endif // CHROME_COMMON_X11_UTIL_H_ |
OLD | NEW |