Index: ui/gl/gl_surface_x11.cc |
diff --git a/ui/gl/gl_surface_x11.cc b/ui/gl/gl_surface_x11.cc |
index 3673a1de592c98cf5787823999435358758d1de8..54c7f438829c13d5132500de38dc00b5eca9ee15 100644 |
--- a/ui/gl/gl_surface_x11.cc |
+++ b/ui/gl/gl_surface_x11.cc |
@@ -18,10 +18,6 @@ |
namespace gfx { |
-namespace { |
-Display* g_osmesa_display; |
-} // namespace |
- |
// This OSMesa GL surface can use XLib to swap the contents of the buffer to a |
// view. |
class NativeViewGLSurfaceOSMesa : public GLSurfaceOSMesa { |
@@ -43,6 +39,7 @@ class NativeViewGLSurfaceOSMesa : public GLSurfaceOSMesa { |
virtual ~NativeViewGLSurfaceOSMesa(); |
private: |
+ Display* xdisplay_; |
GC window_graphics_context_; |
gfx::AcceleratedWidget window_; |
GC pixmap_graphics_context_; |
@@ -80,21 +77,23 @@ bool GLSurface::InitializeOneOffInternal() { |
NativeViewGLSurfaceOSMesa::NativeViewGLSurfaceOSMesa( |
gfx::AcceleratedWidget window) |
- : GLSurfaceOSMesa(OSMESA_BGRA, gfx::Size(1, 1)), |
- window_graphics_context_(0), |
- window_(window), |
- pixmap_graphics_context_(0), |
- pixmap_(0) { |
- DCHECK(window); |
+ : GLSurfaceOSMesa(OSMESA_BGRA, gfx::Size(1, 1)), |
+ xdisplay_(base::MessagePumpForUI::GetDefaultXDisplay()), |
+ window_graphics_context_(0), |
+ window_(window), |
+ pixmap_graphics_context_(0), |
+ pixmap_(0) { |
+ DCHECK(xdisplay_); |
+ DCHECK(window_); |
} |
+// static |
bool NativeViewGLSurfaceOSMesa::InitializeOneOff() { |
static bool initialized = false; |
if (initialized) |
return true; |
- g_osmesa_display = base::MessagePumpForUI::GetDefaultXDisplay(); |
- if (!g_osmesa_display) { |
+ if (!base::MessagePumpForUI::GetDefaultXDisplay()) { |
LOG(ERROR) << "XOpenDisplay failed."; |
return false; |
} |
@@ -107,10 +106,7 @@ bool NativeViewGLSurfaceOSMesa::Initialize() { |
if (!GLSurfaceOSMesa::Initialize()) |
return false; |
- window_graphics_context_ = XCreateGC(g_osmesa_display, |
- window_, |
- 0, |
- NULL); |
+ window_graphics_context_ = XCreateGC(xdisplay_, window_, 0, NULL); |
if (!window_graphics_context_) { |
LOG(ERROR) << "XCreateGC failed."; |
Destroy(); |
@@ -122,21 +118,21 @@ bool NativeViewGLSurfaceOSMesa::Initialize() { |
void NativeViewGLSurfaceOSMesa::Destroy() { |
if (pixmap_graphics_context_) { |
- XFreeGC(g_osmesa_display, pixmap_graphics_context_); |
+ XFreeGC(xdisplay_, pixmap_graphics_context_); |
pixmap_graphics_context_ = NULL; |
} |
if (pixmap_) { |
- XFreePixmap(g_osmesa_display, pixmap_); |
+ XFreePixmap(xdisplay_, pixmap_); |
pixmap_ = 0; |
} |
if (window_graphics_context_) { |
- XFreeGC(g_osmesa_display, window_graphics_context_); |
+ XFreeGC(xdisplay_, window_graphics_context_); |
window_graphics_context_ = NULL; |
} |
- XSync(g_osmesa_display, False); |
+ XSync(xdisplay_, False); |
} |
bool NativeViewGLSurfaceOSMesa::Resize(const gfx::Size& new_size) { |
@@ -144,23 +140,23 @@ bool NativeViewGLSurfaceOSMesa::Resize(const gfx::Size& new_size) { |
return false; |
XWindowAttributes attributes; |
- if (!XGetWindowAttributes(g_osmesa_display, window_, &attributes)) { |
+ if (!XGetWindowAttributes(xdisplay_, window_, &attributes)) { |
LOG(ERROR) << "XGetWindowAttributes failed for window " << window_ << "."; |
return false; |
} |
// Destroy the previous pixmap and graphics context. |
if (pixmap_graphics_context_) { |
- XFreeGC(g_osmesa_display, pixmap_graphics_context_); |
+ XFreeGC(xdisplay_, pixmap_graphics_context_); |
pixmap_graphics_context_ = NULL; |
} |
if (pixmap_) { |
- XFreePixmap(g_osmesa_display, pixmap_); |
+ XFreePixmap(xdisplay_, pixmap_); |
pixmap_ = 0; |
} |
// Recreate a pixmap to hold the frame. |
- pixmap_ = XCreatePixmap(g_osmesa_display, |
+ pixmap_ = XCreatePixmap(xdisplay_, |
window_, |
new_size.width(), |
new_size.height(), |
@@ -171,7 +167,7 @@ bool NativeViewGLSurfaceOSMesa::Resize(const gfx::Size& new_size) { |
} |
// Recreate a graphics context for the pixmap. |
- pixmap_graphics_context_ = XCreateGC(g_osmesa_display, pixmap_, 0, NULL); |
+ pixmap_graphics_context_ = XCreateGC(xdisplay_, pixmap_, 0, NULL); |
if (!pixmap_graphics_context_) { |
LOG(ERROR) << "XCreateGC failed"; |
return false; |
@@ -192,13 +188,13 @@ bool NativeViewGLSurfaceOSMesa::SwapBuffers() { |
gfx::Size size = GetSize(); |
XWindowAttributes attributes; |
- if (!XGetWindowAttributes(g_osmesa_display, window_, &attributes)) { |
+ if (!XGetWindowAttributes(xdisplay_, window_, &attributes)) { |
LOG(ERROR) << "XGetWindowAttributes failed for window " << window_ << "."; |
return false; |
} |
// Copy the frame into the pixmap. |
- gfx::PutARGBImage(g_osmesa_display, |
+ gfx::PutARGBImage(xdisplay_, |
attributes.visual, |
attributes.depth, |
pixmap_, |
@@ -208,13 +204,16 @@ bool NativeViewGLSurfaceOSMesa::SwapBuffers() { |
size.height()); |
// Copy the pixmap to the window. |
- XCopyArea(g_osmesa_display, |
+ XCopyArea(xdisplay_, |
pixmap_, |
window_, |
window_graphics_context_, |
- 0, 0, |
- size.width(), size.height(), |
- 0, 0); |
+ 0, |
+ 0, |
+ size.width(), |
+ size.height(), |
+ 0, |
+ 0); |
return true; |
} |
@@ -234,13 +233,13 @@ bool NativeViewGLSurfaceOSMesa::PostSubBuffer( |
y = size.height() - y - height; |
XWindowAttributes attributes; |
- if (!XGetWindowAttributes(g_osmesa_display, window_, &attributes)) { |
+ if (!XGetWindowAttributes(xdisplay_, window_, &attributes)) { |
LOG(ERROR) << "XGetWindowAttributes failed for window " << window_ << "."; |
return false; |
} |
// Copy the frame into the pixmap. |
- gfx::PutARGBImage(g_osmesa_display, |
+ gfx::PutARGBImage(xdisplay_, |
attributes.visual, |
attributes.depth, |
pixmap_, |
@@ -248,19 +247,24 @@ bool NativeViewGLSurfaceOSMesa::PostSubBuffer( |
static_cast<const uint8*>(GetHandle()), |
size.width(), |
size.height(), |
- x, y, |
- x, y, |
+ x, |
+ y, |
+ x, |
+ y, |
width, |
height); |
// Copy the pixmap to the window. |
- XCopyArea(g_osmesa_display, |
+ XCopyArea(xdisplay_, |
pixmap_, |
window_, |
window_graphics_context_, |
- x, y, |
- width, height, |
- x, y); |
+ x, |
+ y, |
+ width, |
+ height, |
+ x, |
+ y); |
return true; |
} |