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

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: Destroy GLImage during ContextGroup destroy 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 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(gfx::Size size) 12 GLImageAndroidNativeBuffer::GLImageAndroidNativeBuffer(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 GLImageAndroidNativeBuffer::~GLImageAndroidNativeBuffer() { Destroy(); } 20 GLImageAndroidNativeBuffer::~GLImageAndroidNativeBuffer() {
21 Destroy(false);
reveman 2014/05/29 16:30:34 I don't think any GLImage dtor should be calling D
22 }
21 23
22 bool GLImageAndroidNativeBuffer::Initialize(gfx::GpuMemoryBufferHandle buffer) { 24 bool GLImageAndroidNativeBuffer::Initialize(gfx::GpuMemoryBufferHandle buffer) {
23 DCHECK(buffer.native_buffer); 25 DCHECK(buffer.native_buffer);
24 26
25 EGLint attrs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE}; 27 EGLint attrs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE};
26 return GLImageEGL::Initialize( 28 return GLImageEGL::Initialize(
27 EGL_NATIVE_BUFFER_ANDROID, buffer.native_buffer, attrs); 29 EGL_NATIVE_BUFFER_ANDROID, buffer.native_buffer, attrs);
28 } 30 }
29 31
30 void GLImageAndroidNativeBuffer::Destroy() { 32 void GLImageAndroidNativeBuffer::Destroy(bool have_context) {
31 if (egl_image_for_unbind_ != EGL_NO_IMAGE_KHR) { 33 if (egl_image_for_unbind_ != EGL_NO_IMAGE_KHR) {
32 eglDestroyImageKHR(GLSurfaceEGL::GetHardwareDisplay(), 34 eglDestroyImageKHR(GLSurfaceEGL::GetHardwareDisplay(),
33 egl_image_for_unbind_); 35 egl_image_for_unbind_);
34 egl_image_for_unbind_ = EGL_NO_IMAGE_KHR; 36 egl_image_for_unbind_ = EGL_NO_IMAGE_KHR;
35 } 37 }
36 if (texture_id_for_unbind_) { 38 if (texture_id_for_unbind_) {
37 glDeleteTextures(1, &texture_id_for_unbind_); 39 glDeleteTextures(1, &texture_id_for_unbind_);
reveman 2014/05/29 16:30:34 This should only be called if have_context is true
38 texture_id_for_unbind_ = 0; 40 texture_id_for_unbind_ = 0;
39 } 41 }
40 42
41 GLImageEGL::Destroy(); 43 GLImageEGL::Destroy(have_context);
42 } 44 }
43 45
44 bool GLImageAndroidNativeBuffer::BindTexImage(unsigned target) { 46 bool GLImageAndroidNativeBuffer::BindTexImage(unsigned target) {
45 DCHECK_NE(EGL_NO_IMAGE_KHR, egl_image_); 47 DCHECK_NE(EGL_NO_IMAGE_KHR, egl_image_);
46 48
47 if (target == GL_TEXTURE_RECTANGLE_ARB) { 49 if (target == GL_TEXTURE_RECTANGLE_ARB) {
48 LOG(ERROR) << "EGLImage cannot be bound to TEXTURE_RECTANGLE_ARB target"; 50 LOG(ERROR) << "EGLImage cannot be bound to TEXTURE_RECTANGLE_ARB target";
49 return false; 51 return false;
50 } 52 }
51 53
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 111
110 glEGLImageTargetTexture2DOES(target_, egl_image_for_unbind_); 112 glEGLImageTargetTexture2DOES(target_, egl_image_for_unbind_);
111 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); 113 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
112 } 114 }
113 115
114 void GLImageAndroidNativeBuffer::SetReleaseAfterUse() { 116 void GLImageAndroidNativeBuffer::SetReleaseAfterUse() {
115 release_after_use_ = true; 117 release_after_use_ = true;
116 } 118 }
117 119
118 } // namespace gfx 120 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698