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

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: build issues addressed. 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
« 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
42 if (!surface_texture_) {
43 LOG(ERROR) << "Uninitialized image cannot be bound to texture";
44 return false;
45 }
reveman 2014/07/25 19:00:23 Let's keep this as before. Sorry.
sohanjg 2014/07/26 10:42:23 Done.
46
39 if (target != GL_TEXTURE_EXTERNAL_OES) { 47 if (target != GL_TEXTURE_EXTERNAL_OES) {
40 LOG(ERROR) 48 LOG(ERROR)
41 << "Surface texture can only be bound to TEXTURE_EXTERNAL_OES target"; 49 << "Surface texture can only be bound to TEXTURE_EXTERNAL_OES target";
42 return false; 50 return false;
43 } 51 }
44 52
45 GLint texture_id; 53 GLint texture_id;
46 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &texture_id); 54 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &texture_id);
47 DCHECK(texture_id); 55 DCHECK(texture_id);
48 56
49 if (texture_id_ && texture_id_ != texture_id) { 57 if (texture_id_ && texture_id_ != texture_id) {
50 LOG(ERROR) << "Surface texture can only be bound to one texture ID"; 58 LOG(ERROR) << "Surface texture can only be bound to one texture ID";
51 return false; 59 return false;
52 } 60 }
53 61
54 DCHECK(surface_texture_);
55 if (texture_id != texture_id_) { 62 if (texture_id != texture_id_) {
56 // Note: Surface textures used as gpu memory buffers are created with an 63 // 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 64 // 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 65 // to detach from the dummy texture before we can attach to a real texture
59 // id. DetachFromGLContext() will delete the texture for the current 66 // id. DetachFromGLContext() will delete the texture for the current
60 // attachment point so it's important that this is never called when 67 // 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 68 // 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 69 // not cause any problems as the GL should silently ignore 0 when passed to
63 // glDeleteTextures. 70 // glDeleteTextures.
64 DCHECK_EQ(0, texture_id_); 71 DCHECK_EQ(0, texture_id_);
65 surface_texture_->DetachFromGLContext(); 72 surface_texture_->DetachFromGLContext();
66 73
67 // This will attach the surface texture to the texture currently bound to 74 // This will attach the surface texture to the texture currently bound to
68 // GL_TEXTURE_EXTERNAL_OES target. 75 // GL_TEXTURE_EXTERNAL_OES target.
69 surface_texture_->AttachToGLContext(); 76 surface_texture_->AttachToGLContext();
70 texture_id_ = texture_id; 77 texture_id_ = texture_id;
71 } 78 }
72 79
73 surface_texture_->UpdateTexImage(); 80 surface_texture_->UpdateTexImage();
74 return true; 81 return true;
75 } 82 }
76 83
77 } // namespace gfx 84 } // 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