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

Side by Side Diff: ui/gl/gl_image_surface_texture.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
« ui/gl/gl_image_memory.cc ('K') | « ui/gl/gl_image_surface_texture.h ('k') | no next file » | 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_surface_texture.h" 5 #include "ui/gl/gl_image_surface_texture.h"
6 6
7 #include "base/debug/trace_event.h" 7 #include "base/debug/trace_event.h"
8 #include "ui/gl/android/surface_texture.h" 8 #include "ui/gl/android/surface_texture.h"
9 #include "ui/gl/android/surface_texture_tracker.h" 9 #include "ui/gl/android/surface_texture_tracker.h"
10 10
11 namespace gfx { 11 namespace gfx {
12 12
13 GLImageSurfaceTexture::GLImageSurfaceTexture(const gfx::Size& size) 13 GLImageSurfaceTexture::GLImageSurfaceTexture(const gfx::Size& size)
14 : size_(size), texture_id_(0) { 14 : size_(size), texture_id_(0) {
15 } 15 }
16 16
17 GLImageSurfaceTexture::~GLImageSurfaceTexture() { Destroy(); } 17 GLImageSurfaceTexture::~GLImageSurfaceTexture() {
18 DCHECK(!surface_texture_);
19 DCHECK_EQ(0u, texture_id_);
20 }
18 21
19 bool GLImageSurfaceTexture::Initialize( 22 bool GLImageSurfaceTexture::Initialize(
20 const gfx::GpuMemoryBufferHandle& handle) { 23 const gfx::GpuMemoryBufferHandle& handle) {
21 DCHECK(!surface_texture_); 24 DCHECK(!surface_texture_);
22 surface_texture_ = 25 surface_texture_ =
23 SurfaceTextureTracker::GetInstance()->AcquireSurfaceTexture( 26 SurfaceTextureTracker::GetInstance()->AcquireSurfaceTexture(
24 handle.surface_texture_id.primary_id, 27 handle.surface_texture_id.primary_id,
25 handle.surface_texture_id.secondary_id); 28 handle.surface_texture_id.secondary_id);
26 return !!surface_texture_; 29 return !!surface_texture_;
27 } 30 }
28 31
29 void GLImageSurfaceTexture::Destroy() { 32 void GLImageSurfaceTexture::Destroy(bool have_context) {
30 surface_texture_ = NULL; 33 surface_texture_ = NULL;
31 texture_id_ = 0; 34 texture_id_ = 0;
32 } 35 }
33 36
34 gfx::Size GLImageSurfaceTexture::GetSize() { return size_; } 37 gfx::Size GLImageSurfaceTexture::GetSize() { return size_; }
35 38
36 bool GLImageSurfaceTexture::BindTexImage(unsigned target) { 39 bool GLImageSurfaceTexture::BindTexImage(unsigned target) {
37 TRACE_EVENT0("gpu", "GLImageSurfaceTexture::BindTexImage"); 40 TRACE_EVENT0("gpu", "GLImageSurfaceTexture::BindTexImage");
38 41
39 if (target != GL_TEXTURE_EXTERNAL_OES) { 42 if (target != GL_TEXTURE_EXTERNAL_OES) {
40 LOG(ERROR) 43 LOG(ERROR)
41 << "Surface texture can only be bound to TEXTURE_EXTERNAL_OES target"; 44 << "Surface texture can only be bound to TEXTURE_EXTERNAL_OES target";
42 return false; 45 return false;
43 } 46 }
44 47
45 GLint texture_id; 48 GLint texture_id;
46 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &texture_id); 49 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &texture_id);
47 DCHECK(texture_id); 50 DCHECK(texture_id);
48 51
49 if (texture_id_ && texture_id_ != texture_id) { 52 if (texture_id_ && texture_id_ != texture_id) {
50 LOG(ERROR) << "Surface texture can only be bound to one texture ID"; 53 LOG(ERROR) << "Surface texture can only be bound to one texture ID";
51 return false; 54 return false;
52 } 55 }
53 56
54 DCHECK(surface_texture_); 57 if (!surface_texture_) {
58 LOG(ERROR) << "No SurfaceTexture Image memory to bind";
reveman 2014/07/24 16:22:03 "Uninitialized image cannot be bound to texture" a
sohanjg 2014/07/25 10:54:22 Done.
59 return false;
60 }
55 if (texture_id != texture_id_) { 61 if (texture_id != texture_id_) {
56 // Note: Surface textures used as gpu memory buffers are created with an 62 // Note: Surface textures used as gpu memory buffers are created with an
57 // initial dummy texture id of 0. We need to call DetachFromGLContext() here 63 // initial dummy texture id of 0. We need to call DetachFromGLContext() here
58 // to detach from the dummy texture before we can attach to a real texture 64 // to detach from the dummy texture before we can attach to a real texture
59 // id. DetachFromGLContext() will delete the texture for the current 65 // id. DetachFromGLContext() will delete the texture for the current
60 // attachment point so it's important that this is never called when 66 // attachment point so it's important that this is never called when
61 // attached to a real texture id. Detaching from the dummy texture id should 67 // attached to a real texture id. Detaching from the dummy texture id should
62 // not cause any problems as the GL should silently ignore 0 when passed to 68 // not cause any problems as the GL should silently ignore 0 when passed to
63 // glDeleteTextures. 69 // glDeleteTextures.
64 DCHECK_EQ(0, texture_id_); 70 DCHECK_EQ(0, texture_id_);
65 surface_texture_->DetachFromGLContext(); 71 surface_texture_->DetachFromGLContext();
66 72
67 // This will attach the surface texture to the texture currently bound to 73 // This will attach the surface texture to the texture currently bound to
68 // GL_TEXTURE_EXTERNAL_OES target. 74 // GL_TEXTURE_EXTERNAL_OES target.
69 surface_texture_->AttachToGLContext(); 75 surface_texture_->AttachToGLContext();
70 texture_id_ = texture_id; 76 texture_id_ = texture_id;
71 } 77 }
72 78
73 surface_texture_->UpdateTexImage(); 79 surface_texture_->UpdateTexImage();
74 return true; 80 return true;
75 } 81 }
76 82
77 } // namespace gfx 83 } // namespace gfx
OLDNEW
« ui/gl/gl_image_memory.cc ('K') | « ui/gl/gl_image_surface_texture.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698