Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 extern "C" { | 5 extern "C" { |
| 6 #include <X11/extensions/Xcomposite.h> | 6 #include <X11/extensions/Xcomposite.h> |
| 7 } | 7 } |
| 8 | 8 |
| 9 #include "ui/gl/gl_image_glx.h" | 9 #include "ui/gl/gl_image_glx.h" |
| 10 | 10 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 } | 42 } |
| 43 | 43 |
| 44 } // namespace anonymous | 44 } // namespace anonymous |
| 45 | 45 |
| 46 GLImageGLX::GLImageGLX(gfx::PluginWindowHandle window) | 46 GLImageGLX::GLImageGLX(gfx::PluginWindowHandle window) |
| 47 : display_(gfx::GetXDisplay()), | 47 : display_(gfx::GetXDisplay()), |
| 48 window_(window), | 48 window_(window), |
| 49 pixmap_(0), | 49 pixmap_(0), |
| 50 glx_pixmap_(0) {} | 50 glx_pixmap_(0) {} |
| 51 | 51 |
| 52 GLImageGLX::~GLImageGLX() { Destroy(); } | 52 GLImageGLX::~GLImageGLX() { |
| 53 DCHECK_EQ(0u, glx_pixmap_); | |
| 54 DCHECK_EQ(0u, pixmap_); | |
|
reveman
2014/05/31 05:05:06
this can fail. see why below.
sohanjg
2014/06/02 13:59:42
Done.
| |
| 55 } | |
| 53 | 56 |
| 54 bool GLImageGLX::Initialize() { | 57 bool GLImageGLX::Initialize() { |
| 55 if (!GLSurfaceGLX::IsTextureFromPixmapSupported()) { | 58 if (!GLSurfaceGLX::IsTextureFromPixmapSupported()) { |
| 56 LOG(ERROR) << "GLX_EXT_texture_from_pixmap not supported."; | 59 LOG(ERROR) << "GLX_EXT_texture_from_pixmap not supported."; |
| 57 return false; | 60 return false; |
| 58 } | 61 } |
| 59 | 62 |
| 60 XWindowAttributes attributes; | 63 XWindowAttributes attributes; |
| 61 if (!XGetWindowAttributes(display_, window_, &attributes)) { | 64 if (!XGetWindowAttributes(display_, window_, &attributes)) { |
| 62 LOG(ERROR) << "XGetWindowAttributes failed for window " << window_ << "."; | 65 LOG(ERROR) << "XGetWindowAttributes failed for window " << window_ << "."; |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 90 if (!config.get()) { | 93 if (!config.get()) { |
| 91 LOG(ERROR) << "glXChooseFBConfig failed."; | 94 LOG(ERROR) << "glXChooseFBConfig failed."; |
| 92 return false; | 95 return false; |
| 93 } | 96 } |
| 94 if (!num_elements) { | 97 if (!num_elements) { |
| 95 LOG(ERROR) << "glXChooseFBConfig returned 0 elements."; | 98 LOG(ERROR) << "glXChooseFBConfig returned 0 elements."; |
| 96 return false; | 99 return false; |
| 97 } | 100 } |
| 98 | 101 |
| 99 // Create backing pixmap reference. | 102 // Create backing pixmap reference. |
| 100 pixmap_ = XCompositeNameWindowPixmap(display_, window_); | 103 pixmap_ = XCompositeNameWindowPixmap(display_, window_); |
|
reveman
2014/05/31 05:05:06
For this new Destroy logic to work correctly, pixm
sohanjg
2014/06/02 13:59:42
Done.
| |
| 101 | 104 |
| 102 XID root = 0; | 105 XID root = 0; |
| 103 int x = 0; | 106 int x = 0; |
| 104 int y = 0; | 107 int y = 0; |
| 105 unsigned int width = 0; | 108 unsigned int width = 0; |
| 106 unsigned int height = 0; | 109 unsigned int height = 0; |
| 107 unsigned int bw = 0; | 110 unsigned int bw = 0; |
| 108 unsigned int depth = 0; | 111 unsigned int depth = 0; |
| 109 if (!XGetGeometry( | 112 if (!XGetGeometry( |
| 110 display_, pixmap_, &root, &x, &y, &width, &height, &bw, &depth)) { | 113 display_, pixmap_, &root, &x, &y, &width, &height, &bw, &depth)) { |
| 111 LOG(ERROR) << "XGetGeometry failed for pixmap " << pixmap_ << "."; | 114 LOG(ERROR) << "XGetGeometry failed for pixmap " << pixmap_ << "."; |
| 112 return false; | 115 return false; |
| 113 } | 116 } |
| 114 | 117 |
| 115 int pixmap_attribs[] = {GLX_TEXTURE_TARGET_EXT, GLX_TEXTURE_2D_EXT, | 118 int pixmap_attribs[] = {GLX_TEXTURE_TARGET_EXT, GLX_TEXTURE_2D_EXT, |
| 116 GLX_TEXTURE_FORMAT_EXT, TextureFormat(visinfo->depth), | 119 GLX_TEXTURE_FORMAT_EXT, TextureFormat(visinfo->depth), |
| 117 0}; | 120 0}; |
| 118 glx_pixmap_ = | 121 glx_pixmap_ = |
| 119 glXCreatePixmap(display_, *config.get(), pixmap_, pixmap_attribs); | 122 glXCreatePixmap(display_, *config.get(), pixmap_, pixmap_attribs); |
| 120 if (!glx_pixmap_) { | 123 if (!glx_pixmap_) { |
| 121 LOG(ERROR) << "glXCreatePixmap failed."; | 124 LOG(ERROR) << "glXCreatePixmap failed."; |
| 122 return false; | 125 return false; |
| 123 } | 126 } |
| 124 | 127 |
| 125 size_ = gfx::Size(width, height); | 128 size_ = gfx::Size(width, height); |
| 126 return true; | 129 return true; |
| 127 } | 130 } |
| 128 | 131 |
| 129 void GLImageGLX::Destroy() { | 132 void GLImageGLX::Destroy(bool have_context) { |
| 130 if (glx_pixmap_) { | 133 if (glx_pixmap_) { |
| 131 glXDestroyGLXPixmap(display_, glx_pixmap_); | 134 glXDestroyGLXPixmap(display_, glx_pixmap_); |
| 132 glx_pixmap_ = 0; | 135 glx_pixmap_ = 0; |
| 133 } | 136 } |
| 134 if (pixmap_) { | 137 if (pixmap_) { |
| 135 XFreePixmap(display_, pixmap_); | 138 XFreePixmap(display_, pixmap_); |
| 136 pixmap_ = 0; | 139 pixmap_ = 0; |
| 137 } | 140 } |
| 138 } | 141 } |
| 139 | 142 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 152 } | 155 } |
| 153 | 156 |
| 154 void GLImageGLX::ReleaseTexImage(unsigned target) { | 157 void GLImageGLX::ReleaseTexImage(unsigned target) { |
| 155 DCHECK(glx_pixmap_); | 158 DCHECK(glx_pixmap_); |
| 156 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), target); | 159 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), target); |
| 157 | 160 |
| 158 glXReleaseTexImageEXT(display_, glx_pixmap_, GLX_FRONT_LEFT_EXT); | 161 glXReleaseTexImageEXT(display_, glx_pixmap_, GLX_FRONT_LEFT_EXT); |
| 159 } | 162 } |
| 160 | 163 |
| 161 } // namespace gfx | 164 } // namespace gfx |
| OLD | NEW |