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

Side by Side Diff: ui/gl/gl_image_android_native_buffer.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: rebased to ToT 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_android_native_buffer.h" 5 #include "ui/gl/gl_image_android_native_buffer.h"
6 6
7 #include "ui/gl/gl_surface_egl.h" 7 #include "ui/gl/gl_surface_egl.h"
8 #include "ui/gl/scoped_binders.h" 8 #include "ui/gl/scoped_binders.h"
9 9
10 namespace gfx { 10 namespace gfx {
11 11
12 GLImageAndroidNativeBuffer::GLImageAndroidNativeBuffer(const gfx::Size& size) 12 GLImageAndroidNativeBuffer::GLImageAndroidNativeBuffer(const gfx::Size& size)
13 : GLImageEGL(size), 13 : GLImageEGL(size),
14 release_after_use_(false), 14 release_after_use_(false),
15 in_use_(false), 15 in_use_(false),
16 target_(0), 16 target_(0),
17 egl_image_for_unbind_(EGL_NO_IMAGE_KHR), 17 egl_image_for_unbind_(EGL_NO_IMAGE_KHR),
18 texture_id_for_unbind_(0) { 18 texture_id_for_unbind_(0) {
19 } 19 }
20 20
21 GLImageAndroidNativeBuffer::~GLImageAndroidNativeBuffer() { Destroy(); } 21 GLImageAndroidNativeBuffer::~GLImageAndroidNativeBuffer() {
22 DCHECK_EQ(EGL_NO_IMAGE_KHR, egl_image_);
23 DCHECK_EQ(0u, texture_id_for_unbind_);
24 }
22 25
23 bool GLImageAndroidNativeBuffer::Initialize(EGLClientBuffer native_buffer) { 26 bool GLImageAndroidNativeBuffer::Initialize(EGLClientBuffer native_buffer) {
24 EGLint attrs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE}; 27 EGLint attrs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE};
25 return GLImageEGL::Initialize( 28 return GLImageEGL::Initialize(
26 EGL_NATIVE_BUFFER_ANDROID, native_buffer, attrs); 29 EGL_NATIVE_BUFFER_ANDROID, native_buffer, attrs);
27 } 30 }
28 31
29 void GLImageAndroidNativeBuffer::Destroy() { 32 void GLImageAndroidNativeBuffer::Destroy(bool have_context) {
30 if (egl_image_for_unbind_ != EGL_NO_IMAGE_KHR) { 33 if (egl_image_for_unbind_ != EGL_NO_IMAGE_KHR) {
31 eglDestroyImageKHR(GLSurfaceEGL::GetHardwareDisplay(), 34 eglDestroyImageKHR(GLSurfaceEGL::GetHardwareDisplay(),
32 egl_image_for_unbind_); 35 egl_image_for_unbind_);
33 egl_image_for_unbind_ = EGL_NO_IMAGE_KHR; 36 egl_image_for_unbind_ = EGL_NO_IMAGE_KHR;
34 } 37 }
38
35 if (texture_id_for_unbind_) { 39 if (texture_id_for_unbind_) {
36 glDeleteTextures(1, &texture_id_for_unbind_); 40 if (have_context)
37 texture_id_for_unbind_ = 0; 41 glDeleteTextures(1, &texture_id_for_unbind_);
42 texture_id_for_unbind_ = 0u;
38 } 43 }
39 44
40 GLImageEGL::Destroy(); 45 GLImageEGL::Destroy(have_context);
41 } 46 }
42 47
43 bool GLImageAndroidNativeBuffer::BindTexImage(unsigned target) { 48 bool GLImageAndroidNativeBuffer::BindTexImage(unsigned target) {
44 DCHECK_NE(EGL_NO_IMAGE_KHR, egl_image_); 49 DCHECK_NE(EGL_NO_IMAGE_KHR, egl_image_);
45 50
46 if (target == GL_TEXTURE_RECTANGLE_ARB) { 51 if (target == GL_TEXTURE_RECTANGLE_ARB) {
47 LOG(ERROR) << "EGLImage cannot be bound to TEXTURE_RECTANGLE_ARB target"; 52 LOG(ERROR) << "EGLImage cannot be bound to TEXTURE_RECTANGLE_ARB target";
48 return false; 53 return false;
49 } 54 }
50 55
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 113
109 glEGLImageTargetTexture2DOES(target_, egl_image_for_unbind_); 114 glEGLImageTargetTexture2DOES(target_, egl_image_for_unbind_);
110 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); 115 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
111 } 116 }
112 117
113 void GLImageAndroidNativeBuffer::SetReleaseAfterUse() { 118 void GLImageAndroidNativeBuffer::SetReleaseAfterUse() {
114 release_after_use_ = true; 119 release_after_use_ = true;
115 } 120 }
116 121
117 } // namespace gfx 122 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698