| 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 "chrome/common/x11_util.h" | 9 #include "chrome/common/x11_util.h" |
| 10 #include "chrome/common/x11_util_internal.h" | 10 #include "chrome/common/x11_util_internal.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 | 75 |
| 76 if (shared_memory_support_cached) | 76 if (shared_memory_support_cached) |
| 77 return shared_memory_support; | 77 return shared_memory_support; |
| 78 | 78 |
| 79 shared_memory_support = DoQuerySharedMemorySupport(dpy); | 79 shared_memory_support = DoQuerySharedMemorySupport(dpy); |
| 80 shared_memory_support_cached = true; | 80 shared_memory_support_cached = true; |
| 81 | 81 |
| 82 return shared_memory_support; | 82 return shared_memory_support; |
| 83 } | 83 } |
| 84 | 84 |
| 85 bool QueryRenderSupport(Display* dpy) { |
| 86 static bool render_supported = false; |
| 87 static bool render_supported_cached = false; |
| 88 |
| 89 if (render_supported_cached) |
| 90 return render_supported; |
| 91 |
| 92 // We don't care about the version of Xrender since all the features which |
| 93 // we use are included in every version. |
| 94 int dummy; |
| 95 render_supported = XRenderQueryExtension(dpy, &dummy, &dummy); |
| 96 render_supported_cached = true; |
| 97 |
| 98 return render_supported; |
| 99 } |
| 100 |
| 85 XID GetX11RootWindow() { | 101 XID GetX11RootWindow() { |
| 86 return GDK_WINDOW_XID(gdk_get_default_root_window()); | 102 return GDK_WINDOW_XID(gdk_get_default_root_window()); |
| 87 } | 103 } |
| 88 | 104 |
| 89 XID GetX11WindowFromGtkWidget(GtkWidget* widget) { | 105 XID GetX11WindowFromGtkWidget(GtkWidget* widget) { |
| 90 return GDK_WINDOW_XID(widget->window); | 106 return GDK_WINDOW_XID(widget->window); |
| 91 } | 107 } |
| 92 | 108 |
| 93 void* GetVisualFromGtkWidget(GtkWidget* widget) { | 109 void* GetVisualFromGtkWidget(GtkWidget* widget) { |
| 94 return GDK_VISUAL_XVISUAL(gtk_widget_get_visual(widget)); | 110 return GDK_VISUAL_XVISUAL(gtk_widget_get_visual(widget)); |
| 95 } | 111 } |
| 96 | 112 |
| 113 int BitsPerPixelForPixmapDepth(Display* dpy, int depth) { |
| 114 int count; |
| 115 XPixmapFormatValues* formats = XListPixmapFormats(dpy, &count); |
| 116 if (!formats) |
| 117 return -1; |
| 118 |
| 119 int bits_per_pixel = -1; |
| 120 for (int i = 0; i < count; ++i) { |
| 121 if (formats[i].depth == depth) { |
| 122 bits_per_pixel = formats[i].bits_per_pixel; |
| 123 break; |
| 124 } |
| 125 } |
| 126 |
| 127 XFree(formats); |
| 128 return bits_per_pixel; |
| 129 } |
| 130 |
| 97 XRenderPictFormat* GetRenderVisualFormat(Display* dpy, Visual* visual) { | 131 XRenderPictFormat* GetRenderVisualFormat(Display* dpy, Visual* visual) { |
| 98 static XRenderPictFormat* pictformat = NULL; | 132 static XRenderPictFormat* pictformat = NULL; |
| 99 if (pictformat) | 133 if (pictformat) |
| 100 return pictformat; | 134 return pictformat; |
| 101 | 135 |
| 102 int dummy; | 136 DCHECK(QueryRenderSupport(dpy)); |
| 103 if (!XRenderQueryExtension(dpy, &dummy, &dummy)) | |
| 104 CHECK(false) << "XRENDER not supported on display"; | |
| 105 | 137 |
| 106 pictformat = XRenderFindVisualFormat(dpy, visual); | 138 pictformat = XRenderFindVisualFormat(dpy, visual); |
| 107 CHECK(pictformat) << "XRENDER does not support default visual"; | 139 CHECK(pictformat) << "XRENDER does not support default visual"; |
| 108 | 140 |
| 109 return pictformat; | 141 return pictformat; |
| 110 } | 142 } |
| 111 | 143 |
| 112 XRenderPictFormat* GetRenderARGB32Format(Display* dpy) { | 144 XRenderPictFormat* GetRenderARGB32Format(Display* dpy) { |
| 113 static XRenderPictFormat* pictformat = NULL; | 145 static XRenderPictFormat* pictformat = NULL; |
| 114 if (pictformat) | 146 if (pictformat) |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 | 213 |
| 182 void FreePicture(Display* display, XID picture) { | 214 void FreePicture(Display* display, XID picture) { |
| 183 XRenderFreePicture(display, picture); | 215 XRenderFreePicture(display, picture); |
| 184 } | 216 } |
| 185 | 217 |
| 186 void FreePixmap(Display* display, XID pixmap) { | 218 void FreePixmap(Display* display, XID pixmap) { |
| 187 XFreePixmap(display, pixmap); | 219 XFreePixmap(display, pixmap); |
| 188 } | 220 } |
| 189 | 221 |
| 190 } // namespace x11_util | 222 } // namespace x11_util |
| OLD | NEW |