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

Side by Side Diff: ui/gl/gl_image_memory.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: build issues addressed. Created 6 years, 5 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "ui/gl/gl_image_memory.h" 5 #include "ui/gl/gl_image_memory.h"
6 6
7 #include "base/debug/trace_event.h" 7 #include "base/debug/trace_event.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "ui/gl/gl_bindings.h" 9 #include "ui/gl/gl_bindings.h"
10 #include "ui/gl/scoped_binders.h" 10 #include "ui/gl/scoped_binders.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 #if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \ 74 #if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \
75 defined(USE_OZONE) 75 defined(USE_OZONE)
76 , 76 ,
77 egl_texture_id_(0u), 77 egl_texture_id_(0u),
78 egl_image_(EGL_NO_IMAGE_KHR) 78 egl_image_(EGL_NO_IMAGE_KHR)
79 #endif 79 #endif
80 { 80 {
81 } 81 }
82 82
83 GLImageMemory::~GLImageMemory() { 83 GLImageMemory::~GLImageMemory() {
84 #if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \
85 defined(USE_OZONE)
86 DCHECK_EQ(EGL_NO_IMAGE_KHR, egl_image_);
87 DCHECK_EQ(0u, egl_texture_id_);
88 #endif
84 } 89 }
85 90
86 bool GLImageMemory::Initialize(const unsigned char* memory) { 91 bool GLImageMemory::Initialize(const unsigned char* memory) {
87 if (!ValidFormat(internalformat_)) { 92 if (!ValidFormat(internalformat_)) {
88 DVLOG(0) << "Invalid format: " << internalformat_; 93 DVLOG(0) << "Invalid format: " << internalformat_;
89 return false; 94 return false;
90 } 95 }
91 96
92 DCHECK(memory); 97 DCHECK(memory);
93 DCHECK(!memory_); 98 DCHECK(!memory_);
94 memory_ = memory; 99 memory_ = memory;
95 return true; 100 return true;
96 } 101 }
97 102
98 void GLImageMemory::Destroy() { 103 void GLImageMemory::Destroy(bool have_context) {
99 #if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \ 104 #if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \
100 defined(USE_OZONE) 105 defined(USE_OZONE)
101 if (egl_image_ != EGL_NO_IMAGE_KHR) { 106 if (egl_image_ != EGL_NO_IMAGE_KHR) {
102 eglDestroyImageKHR(GLSurfaceEGL::GetHardwareDisplay(), egl_image_); 107 eglDestroyImageKHR(GLSurfaceEGL::GetHardwareDisplay(), egl_image_);
103 egl_image_ = EGL_NO_IMAGE_KHR; 108 egl_image_ = EGL_NO_IMAGE_KHR;
104 } 109 }
105 110
106 if (egl_texture_id_) { 111 if (egl_texture_id_) {
107 glDeleteTextures(1, &egl_texture_id_); 112 if (have_context)
113 glDeleteTextures(1, &egl_texture_id_);
108 egl_texture_id_ = 0u; 114 egl_texture_id_ = 0u;
109 } 115 }
110 #endif 116 #endif
111 memory_ = NULL; 117 memory_ = NULL;
112 } 118 }
113 119
114 gfx::Size GLImageMemory::GetSize() { 120 gfx::Size GLImageMemory::GetSize() {
115 return size_; 121 return size_;
116 } 122 }
117 123
118 bool GLImageMemory::BindTexImage(unsigned target) { 124 bool GLImageMemory::BindTexImage(unsigned target) {
119 TRACE_EVENT0("gpu", "GLImageMemory::BindTexImage"); 125 TRACE_EVENT0("gpu", "GLImageMemory::BindTexImage");
120 126
121 DCHECK(memory_); 127 if (!memory_) {
128 LOG(ERROR) << "Uninitialized image cannot be bound to texture";
129 return false;
130 }
reveman 2014/07/25 19:00:23 Let's keep this as before. Sorry.
sohanjg 2014/07/26 10:42:23 Done.
122 #if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \ 131 #if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \
123 defined(USE_OZONE) 132 defined(USE_OZONE)
124 if (target == GL_TEXTURE_EXTERNAL_OES) { 133 if (target == GL_TEXTURE_EXTERNAL_OES) {
125 if (egl_image_ == EGL_NO_IMAGE_KHR) { 134 if (egl_image_ == EGL_NO_IMAGE_KHR) {
126 DCHECK_EQ(0u, egl_texture_id_); 135 DCHECK_EQ(0u, egl_texture_id_);
127 glGenTextures(1, &egl_texture_id_); 136 glGenTextures(1, &egl_texture_id_);
128 137
129 { 138 {
130 ScopedTextureBinder texture_binder(GL_TEXTURE_2D, egl_texture_id_); 139 ScopedTextureBinder texture_binder(GL_TEXTURE_2D, egl_texture_id_);
131 140
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 200
192 bool GLImageMemory::HasValidFormat() const { 201 bool GLImageMemory::HasValidFormat() const {
193 return ValidFormat(internalformat_); 202 return ValidFormat(internalformat_);
194 } 203 }
195 204
196 size_t GLImageMemory::Bytes() const { 205 size_t GLImageMemory::Bytes() const {
197 return size_.GetArea() * BytesPerPixel(internalformat_); 206 return size_.GetArea() * BytesPerPixel(internalformat_);
198 } 207 }
199 208
200 } // namespace gfx 209 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698