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 // This file defines utility functions for X11 (Linux only). This code has been | 5 // This file defines utility functions for X11 (Linux only). This code has been |
6 // ported from XCB since we can't use XCB on Ubuntu while its 32-bit support | 6 // ported from XCB since we can't use XCB on Ubuntu while its 32-bit support |
7 // remains woefully incomplete. | 7 // remains woefully incomplete. |
8 | 8 |
| 9 #include "base/thread.h" |
9 #include "chrome/common/x11_util.h" | 10 #include "chrome/common/x11_util.h" |
10 #include "chrome/common/x11_util_internal.h" | 11 #include "chrome/common/x11_util_internal.h" |
11 | 12 |
12 #include <string.h> | 13 #include <string.h> |
13 | 14 |
14 #include <gdk/gdk.h> | 15 #include <gdk/gdk.h> |
15 #include <gdk/gdkx.h> | 16 #include <gdk/gdkx.h> |
16 #include <gtk/gtk.h> | 17 #include <gtk/gtk.h> |
17 | 18 |
18 #include <sys/ipc.h> | 19 #include <sys/ipc.h> |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 | 92 |
92 // We don't care about the version of Xrender since all the features which | 93 // We don't care about the version of Xrender since all the features which |
93 // we use are included in every version. | 94 // we use are included in every version. |
94 int dummy; | 95 int dummy; |
95 render_supported = XRenderQueryExtension(dpy, &dummy, &dummy); | 96 render_supported = XRenderQueryExtension(dpy, &dummy, &dummy); |
96 render_supported_cached = true; | 97 render_supported_cached = true; |
97 | 98 |
98 return render_supported; | 99 return render_supported; |
99 } | 100 } |
100 | 101 |
| 102 int GetDefaultScreen(Display* display) { |
| 103 return XDefaultScreen(display); |
| 104 } |
| 105 |
101 XID GetX11RootWindow() { | 106 XID GetX11RootWindow() { |
102 return GDK_WINDOW_XID(gdk_get_default_root_window()); | 107 return GDK_WINDOW_XID(gdk_get_default_root_window()); |
103 } | 108 } |
104 | 109 |
105 XID GetX11WindowFromGtkWidget(GtkWidget* widget) { | 110 XID GetX11WindowFromGtkWidget(GtkWidget* widget) { |
106 return GDK_WINDOW_XID(widget->window); | 111 return GDK_WINDOW_XID(widget->window); |
107 } | 112 } |
108 | 113 |
| 114 XID GetX11WindowFromGdkWindow(GdkWindow* window) { |
| 115 return GDK_WINDOW_XID(window); |
| 116 } |
| 117 |
109 void* GetVisualFromGtkWidget(GtkWidget* widget) { | 118 void* GetVisualFromGtkWidget(GtkWidget* widget) { |
110 return GDK_VISUAL_XVISUAL(gtk_widget_get_visual(widget)); | 119 return GDK_VISUAL_XVISUAL(gtk_widget_get_visual(widget)); |
111 } | 120 } |
112 | 121 |
113 int BitsPerPixelForPixmapDepth(Display* dpy, int depth) { | 122 int BitsPerPixelForPixmapDepth(Display* dpy, int depth) { |
114 int count; | 123 int count; |
115 XPixmapFormatValues* formats = XListPixmapFormats(dpy, &count); | 124 XPixmapFormatValues* formats = XListPixmapFormats(dpy, &count); |
116 if (!formats) | 125 if (!formats) |
117 return -1; | 126 return -1; |
118 | 127 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 } | 221 } |
213 | 222 |
214 void FreePicture(Display* display, XID picture) { | 223 void FreePicture(Display* display, XID picture) { |
215 XRenderFreePicture(display, picture); | 224 XRenderFreePicture(display, picture); |
216 } | 225 } |
217 | 226 |
218 void FreePixmap(Display* display, XID pixmap) { | 227 void FreePixmap(Display* display, XID pixmap) { |
219 XFreePixmap(display, pixmap); | 228 XFreePixmap(display, pixmap); |
220 } | 229 } |
221 | 230 |
| 231 // Called on BACKGROUND_X11 thread. |
| 232 Display* GetSecondaryDisplay() { |
| 233 static Display* display = NULL; |
| 234 if (!display) { |
| 235 display = XOpenDisplay(NULL); |
| 236 CHECK(display); |
| 237 } |
| 238 |
| 239 return display; |
| 240 } |
| 241 |
| 242 // Called on BACKGROUND_X11 thread. |
| 243 void GetWindowGeometry(int* x, int* y, unsigned* width, unsigned* height, |
| 244 XID window) { |
| 245 Window root_window; |
| 246 unsigned border_width, depth; |
| 247 |
| 248 CHECK(XGetGeometry(GetSecondaryDisplay(), window, |
| 249 &root_window, x, y, width, height, &border_width, &depth)); |
| 250 } |
| 251 |
222 } // namespace x11_util | 252 } // namespace x11_util |
OLD | NEW |