Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(264)

Side by Side Diff: ui/gl/gl_image_glx.cc

Issue 301793003: During image destroy, delete textures only if we have a GL context. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: WIP - Avoid optional image manager creation/destroy in context group Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 XFreePixmap(display_, pixmap_);
120 pixmap_ = 0u;
112 return false; 121 return false;
113 } 122 }
114 123
115 int pixmap_attribs[] = {GLX_TEXTURE_TARGET_EXT, GLX_TEXTURE_2D_EXT, 124 int pixmap_attribs[] = {GLX_TEXTURE_TARGET_EXT, GLX_TEXTURE_2D_EXT,
116 GLX_TEXTURE_FORMAT_EXT, TextureFormat(visinfo->depth), 125 GLX_TEXTURE_FORMAT_EXT, TextureFormat(visinfo->depth),
117 0}; 126 0};
118 glx_pixmap_ = 127 glx_pixmap_ =
119 glXCreatePixmap(display_, *config.get(), pixmap_, pixmap_attribs); 128 glXCreatePixmap(display_, *config.get(), pixmap_, pixmap_attribs);
120 if (!glx_pixmap_) { 129 if (!glx_pixmap_) {
121 LOG(ERROR) << "glXCreatePixmap failed."; 130 LOG(ERROR) << "glXCreatePixmap failed.";
131 XFreePixmap(display_, pixmap_);
132 pixmap_ = 0u;
122 return false; 133 return false;
123 } 134 }
124 135
125 size_ = gfx::Size(width, height); 136 size_ = gfx::Size(width, height);
126 return true; 137 return true;
127 } 138 }
128 139
129 void GLImageGLX::Destroy() { 140 void GLImageGLX::Destroy(bool have_context) {
130 if (glx_pixmap_) { 141 if (glx_pixmap_) {
131 glXDestroyGLXPixmap(display_, glx_pixmap_); 142 glXDestroyGLXPixmap(display_, glx_pixmap_);
132 glx_pixmap_ = 0; 143 glx_pixmap_ = 0;
133 } 144 }
134 if (pixmap_) { 145 if (pixmap_) {
135 XFreePixmap(display_, pixmap_); 146 XFreePixmap(display_, pixmap_);
136 pixmap_ = 0; 147 pixmap_ = 0;
137 } 148 }
138 } 149 }
139 150
(...skipping 12 matching lines...) Expand all
152 } 163 }
153 164
154 void GLImageGLX::ReleaseTexImage(unsigned target) { 165 void GLImageGLX::ReleaseTexImage(unsigned target) {
155 DCHECK(glx_pixmap_); 166 DCHECK(glx_pixmap_);
156 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), target); 167 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), target);
157 168
158 glXReleaseTexImageEXT(display_, glx_pixmap_, GLX_FRONT_LEFT_EXT); 169 glXReleaseTexImageEXT(display_, glx_pixmap_, GLX_FRONT_LEFT_EXT);
159 } 170 }
160 171
161 } // namespace gfx 172 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698