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

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: review comments 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_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 if (egl_image_ == EGL_NO_IMAGE_KHR) {
50 LOG(ERROR) << "No EGLImage to bind";
reveman 2014/07/24 16:22:03 nit: "Uninitialized image cannot be bound to textu
sohanjg 2014/07/25 10:54:21 Done.
51 return false;
52 }
45 53
46 if (target == GL_TEXTURE_RECTANGLE_ARB) { 54 if (target == GL_TEXTURE_RECTANGLE_ARB) {
47 LOG(ERROR) << "EGLImage cannot be bound to TEXTURE_RECTANGLE_ARB target"; 55 LOG(ERROR) << "EGLImage cannot be bound to TEXTURE_RECTANGLE_ARB target";
48 return false; 56 return false;
49 } 57 }
50 58
51 if (target_ && target_ != target) { 59 if (target_ && target_ != target) {
52 LOG(ERROR) << "EGLImage can only be bound to one target"; 60 LOG(ERROR) << "EGLImage can only be bound to one target";
53 return false; 61 return false;
54 } 62 }
55 target_ = target; 63 target_ = target;
56 64
57 // Defer ImageTargetTexture2D if not currently in use. 65 // Defer ImageTargetTexture2D if not currently in use.
58 if (!in_use_) 66 if (!in_use_)
59 return true; 67 return true;
60 68
61 glEGLImageTargetTexture2DOES(target_, egl_image_); 69 glEGLImageTargetTexture2DOES(target_, egl_image_);
62 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); 70 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
63 return true; 71 return true;
64 } 72 }
65 73
66 void GLImageAndroidNativeBuffer::WillUseTexImage() { 74 void GLImageAndroidNativeBuffer::WillUseTexImage() {
reveman 2014/07/24 16:22:03 this can also be called after the buffer has been
sohanjg 2014/07/25 10:54:21 Done.
67 DCHECK(egl_image_); 75 DCHECK(egl_image_);
68 DCHECK(!in_use_); 76 DCHECK(!in_use_);
69 in_use_ = true; 77 in_use_ = true;
70 glEGLImageTargetTexture2DOES(target_, egl_image_); 78 glEGLImageTargetTexture2DOES(target_, egl_image_);
71 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); 79 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
72 } 80 }
73 81
74 void GLImageAndroidNativeBuffer::DidUseTexImage() { 82 void GLImageAndroidNativeBuffer::DidUseTexImage() {
reveman 2014/07/24 16:22:03 and this
sohanjg 2014/07/25 10:54:21 we use a new eglimage for unbinding, not controlle
75 DCHECK(in_use_); 83 DCHECK(in_use_);
76 in_use_ = false; 84 in_use_ = false;
77 85
78 if (!release_after_use_) 86 if (!release_after_use_)
79 return; 87 return;
80 88
81 if (egl_image_for_unbind_ == EGL_NO_IMAGE_KHR) { 89 if (egl_image_for_unbind_ == EGL_NO_IMAGE_KHR) {
82 DCHECK_EQ(0u, texture_id_for_unbind_); 90 DCHECK_EQ(0u, texture_id_for_unbind_);
83 glGenTextures(1, &texture_id_for_unbind_); 91 glGenTextures(1, &texture_id_for_unbind_);
84 92
(...skipping 23 matching lines...) Expand all
108 116
109 glEGLImageTargetTexture2DOES(target_, egl_image_for_unbind_); 117 glEGLImageTargetTexture2DOES(target_, egl_image_for_unbind_);
110 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); 118 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
111 } 119 }
112 120
113 void GLImageAndroidNativeBuffer::SetReleaseAfterUse() { 121 void GLImageAndroidNativeBuffer::SetReleaseAfterUse() {
114 release_after_use_ = true; 122 release_after_use_ = true;
115 } 123 }
116 124
117 } // namespace gfx 125 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698