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

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: resolve android clang dbg build issue. Created 6 years, 4 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
« no previous file with comments | « ui/gl/gl_image_android_native_buffer.h ('k') | ui/gl/gl_image_egl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
51 if (target_ && target_ != target) { 56 if (target_ && target_ != target) {
52 LOG(ERROR) << "EGLImage can only be bound to one target"; 57 LOG(ERROR) << "EGLImage can only be bound to one target";
53 return false; 58 return false;
54 } 59 }
55 target_ = target; 60 target_ = target;
56 61
57 // Defer ImageTargetTexture2D if not currently in use. 62 // Defer ImageTargetTexture2D if not currently in use.
58 if (!in_use_) 63 if (!in_use_)
59 return true; 64 return true;
60 65
61 glEGLImageTargetTexture2DOES(target_, egl_image_); 66 glEGLImageTargetTexture2DOES(target_, egl_image_);
62 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); 67 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
63 return true; 68 return true;
64 } 69 }
65 70
66 void GLImageAndroidNativeBuffer::WillUseTexImage() { 71 void GLImageAndroidNativeBuffer::WillUseTexImage() {
67 DCHECK(egl_image_); 72 DCHECK_NE(EGL_NO_IMAGE_KHR, egl_image_);
68 DCHECK(!in_use_); 73 DCHECK(!in_use_);
69 in_use_ = true; 74 in_use_ = true;
70 glEGLImageTargetTexture2DOES(target_, egl_image_); 75 glEGLImageTargetTexture2DOES(target_, egl_image_);
71 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); 76 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
72 } 77 }
73 78
74 void GLImageAndroidNativeBuffer::DidUseTexImage() { 79 void GLImageAndroidNativeBuffer::DidUseTexImage() {
80 DCHECK_NE(EGL_NO_IMAGE_KHR, egl_image_);
75 DCHECK(in_use_); 81 DCHECK(in_use_);
76 in_use_ = false; 82 in_use_ = false;
77 83
78 if (!release_after_use_) 84 if (!release_after_use_)
79 return; 85 return;
80 86
81 if (egl_image_for_unbind_ == EGL_NO_IMAGE_KHR) { 87 if (egl_image_for_unbind_ == EGL_NO_IMAGE_KHR) {
82 DCHECK_EQ(0u, texture_id_for_unbind_); 88 DCHECK_EQ(0u, texture_id_for_unbind_);
83 glGenTextures(1, &texture_id_for_unbind_); 89 glGenTextures(1, &texture_id_for_unbind_);
84 90
(...skipping 23 matching lines...) Expand all
108 114
109 glEGLImageTargetTexture2DOES(target_, egl_image_for_unbind_); 115 glEGLImageTargetTexture2DOES(target_, egl_image_for_unbind_);
110 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); 116 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
111 } 117 }
112 118
113 void GLImageAndroidNativeBuffer::SetReleaseAfterUse() { 119 void GLImageAndroidNativeBuffer::SetReleaseAfterUse() {
114 release_after_use_ = true; 120 release_after_use_ = true;
115 } 121 }
116 122
117 } // namespace gfx 123 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gl/gl_image_android_native_buffer.h ('k') | ui/gl/gl_image_egl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698