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_); | |
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 28 matching lines...) Expand all Loading... | |
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_); |
104 if (!pixmap_) { | |
105 LOG(ERROR) << "XCompositeNameWindowPixmap failed."; | |
106 return false; | |
107 } | |
101 | 108 |
102 XID root = 0; | 109 XID root = 0; |
103 int x = 0; | 110 int x = 0; |
104 int y = 0; | 111 int y = 0; |
105 unsigned int width = 0; | 112 unsigned int width = 0; |
106 unsigned int height = 0; | 113 unsigned int height = 0; |
107 unsigned int bw = 0; | 114 unsigned int bw = 0; |
108 unsigned int depth = 0; | 115 unsigned int depth = 0; |
109 if (!XGetGeometry( | 116 if (!XGetGeometry( |
110 display_, pixmap_, &root, &x, &y, &width, &height, &bw, &depth)) { | 117 display_, pixmap_, &root, &x, &y, &width, &height, &bw, &depth)) { |
111 LOG(ERROR) << "XGetGeometry failed for pixmap " << pixmap_ << "."; | 118 LOG(ERROR) << "XGetGeometry failed for pixmap " << pixmap_ << "."; |
119 pixmap_ = 0u; | |
reveman
2014/06/02 16:45:29
You're leaking a pixmap here.
sohanjg
2014/06/03 05:48:33
Done.
| |
112 return false; | 120 return false; |
113 } | 121 } |
114 | 122 |
115 int pixmap_attribs[] = {GLX_TEXTURE_TARGET_EXT, GLX_TEXTURE_2D_EXT, | 123 int pixmap_attribs[] = {GLX_TEXTURE_TARGET_EXT, GLX_TEXTURE_2D_EXT, |
116 GLX_TEXTURE_FORMAT_EXT, TextureFormat(visinfo->depth), | 124 GLX_TEXTURE_FORMAT_EXT, TextureFormat(visinfo->depth), |
117 0}; | 125 0}; |
118 glx_pixmap_ = | 126 glx_pixmap_ = |
119 glXCreatePixmap(display_, *config.get(), pixmap_, pixmap_attribs); | 127 glXCreatePixmap(display_, *config.get(), pixmap_, pixmap_attribs); |
120 if (!glx_pixmap_) { | 128 if (!glx_pixmap_) { |
121 LOG(ERROR) << "glXCreatePixmap failed."; | 129 LOG(ERROR) << "glXCreatePixmap failed."; |
130 pixmap_ = 0u; | |
reveman
2014/06/02 16:45:29
You're leaking a pixmap here.
sohanjg
2014/06/03 05:48:33
Done.
| |
122 return false; | 131 return false; |
123 } | 132 } |
124 | 133 |
125 size_ = gfx::Size(width, height); | 134 size_ = gfx::Size(width, height); |
126 return true; | 135 return true; |
127 } | 136 } |
128 | 137 |
129 void GLImageGLX::Destroy() { | 138 void GLImageGLX::Destroy(bool have_context) { |
130 if (glx_pixmap_) { | 139 if (glx_pixmap_) { |
131 glXDestroyGLXPixmap(display_, glx_pixmap_); | 140 glXDestroyGLXPixmap(display_, glx_pixmap_); |
132 glx_pixmap_ = 0; | 141 glx_pixmap_ = 0; |
133 } | 142 } |
134 if (pixmap_) { | 143 if (pixmap_) { |
135 XFreePixmap(display_, pixmap_); | 144 XFreePixmap(display_, pixmap_); |
136 pixmap_ = 0; | 145 pixmap_ = 0; |
137 } | 146 } |
138 } | 147 } |
139 | 148 |
(...skipping 12 matching lines...) Expand all Loading... | |
152 } | 161 } |
153 | 162 |
154 void GLImageGLX::ReleaseTexImage(unsigned target) { | 163 void GLImageGLX::ReleaseTexImage(unsigned target) { |
155 DCHECK(glx_pixmap_); | 164 DCHECK(glx_pixmap_); |
156 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), target); | 165 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), target); |
157 | 166 |
158 glXReleaseTexImageEXT(display_, glx_pixmap_, GLX_FRONT_LEFT_EXT); | 167 glXReleaseTexImageEXT(display_, glx_pixmap_, GLX_FRONT_LEFT_EXT); |
159 } | 168 } |
160 | 169 |
161 } // namespace gfx | 170 } // namespace gfx |
OLD | NEW |