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/Xlib.h> | 6 #include <X11/Xlib.h> |
7 } | 7 } |
8 | 8 |
9 #include "ui/gl/gl_image_glx.h" | 9 #include "ui/gl/gl_image_glx.h" |
10 | 10 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
104 | 104 |
105 return size; | 105 return size; |
106 } | 106 } |
107 | 107 |
108 } // namespace anonymous | 108 } // namespace anonymous |
109 | 109 |
110 GLImageGLX::GLImageGLX(const gfx::Size& size, unsigned internalformat) | 110 GLImageGLX::GLImageGLX(const gfx::Size& size, unsigned internalformat) |
111 : glx_pixmap_(0), size_(size), internalformat_(internalformat) { | 111 : glx_pixmap_(0), size_(size), internalformat_(internalformat) { |
112 } | 112 } |
113 | 113 |
114 GLImageGLX::~GLImageGLX() { Destroy(); } | 114 GLImageGLX::~GLImageGLX() { |
115 DCHECK_EQ(0u, glx_pixmap_); | |
116 } | |
115 | 117 |
116 bool GLImageGLX::Initialize(XID pixmap) { | 118 bool GLImageGLX::Initialize(XID pixmap) { |
117 if (!GLSurfaceGLX::IsTextureFromPixmapSupported()) { | 119 if (!GLSurfaceGLX::IsTextureFromPixmapSupported()) { |
118 DVLOG(0) << "GLX_EXT_texture_from_pixmap not supported."; | 120 DVLOG(0) << "GLX_EXT_texture_from_pixmap not supported."; |
119 return false; | 121 return false; |
120 } | 122 } |
121 | 123 |
122 if (!ValidFormat(internalformat_)) { | 124 if (!ValidFormat(internalformat_)) { |
123 DVLOG(0) << "Invalid format: " << internalformat_; | 125 DVLOG(0) << "Invalid format: " << internalformat_; |
124 return false; | 126 return false; |
(...skipping 28 matching lines...) Expand all Loading... | |
153 glx_pixmap_ = glXCreatePixmap( | 155 glx_pixmap_ = glXCreatePixmap( |
154 gfx::GetXDisplay(), *config.get(), pixmap, pixmap_attribs); | 156 gfx::GetXDisplay(), *config.get(), pixmap, pixmap_attribs); |
155 if (!glx_pixmap_) { | 157 if (!glx_pixmap_) { |
156 DVLOG(0) << "glXCreatePixmap failed."; | 158 DVLOG(0) << "glXCreatePixmap failed."; |
157 return false; | 159 return false; |
158 } | 160 } |
159 | 161 |
160 return true; | 162 return true; |
161 } | 163 } |
162 | 164 |
163 void GLImageGLX::Destroy() { | 165 void GLImageGLX::Destroy(bool have_context) { |
164 if (glx_pixmap_) { | 166 if (glx_pixmap_) { |
165 glXDestroyGLXPixmap(gfx::GetXDisplay(), glx_pixmap_); | 167 glXDestroyGLXPixmap(gfx::GetXDisplay(), glx_pixmap_); |
166 glx_pixmap_ = 0; | 168 glx_pixmap_ = 0; |
167 } | 169 } |
168 } | 170 } |
169 | 171 |
170 gfx::Size GLImageGLX::GetSize() { return size_; } | 172 gfx::Size GLImageGLX::GetSize() { return size_; } |
171 | 173 |
172 bool GLImageGLX::BindTexImage(unsigned target) { | 174 bool GLImageGLX::BindTexImage(unsigned target) { |
173 if (!glx_pixmap_) | 175 if (!glx_pixmap_) |
174 return false; | 176 return false; |
175 | 177 |
176 // Requires TEXTURE_2D target. | 178 // Requires TEXTURE_2D target. |
177 if (target != GL_TEXTURE_2D) | 179 if (target != GL_TEXTURE_2D) |
178 return false; | 180 return false; |
179 | 181 |
180 glXBindTexImageEXT(gfx::GetXDisplay(), glx_pixmap_, GLX_FRONT_LEFT_EXT, 0); | 182 glXBindTexImageEXT(gfx::GetXDisplay(), glx_pixmap_, GLX_FRONT_LEFT_EXT, 0); |
181 return true; | 183 return true; |
182 } | 184 } |
183 | 185 |
184 void GLImageGLX::ReleaseTexImage(unsigned target) { | 186 void GLImageGLX::ReleaseTexImage(unsigned target) { |
185 DCHECK(glx_pixmap_); | 187 if (!glx_pixmap_) |
188 return; | |
reveman
2014/07/27 23:58:32
nit: you don't have to change this. please keep it
sohanjg
2014/07/28 10:15:58
Done.
| |
186 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), target); | 189 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), target); |
187 | 190 |
188 glXReleaseTexImageEXT(gfx::GetXDisplay(), glx_pixmap_, GLX_FRONT_LEFT_EXT); | 191 glXReleaseTexImageEXT(gfx::GetXDisplay(), glx_pixmap_, GLX_FRONT_LEFT_EXT); |
189 } | 192 } |
190 | 193 |
191 } // namespace gfx | 194 } // namespace gfx |
OLD | NEW |