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

Side by Side Diff: content/common/gpu/media/android_deferred_rendering_backing_strategy.cc

Issue 1682343002: AVDACodecImages keep a reference to the SurfaceTexture backing them (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix comment Created 4 years, 10 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "content/common/gpu/media/android_deferred_rendering_backing_strategy.h " 5 #include "content/common/gpu/media/android_deferred_rendering_backing_strategy.h "
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
11 #include "content/common/gpu/gpu_channel.h" 11 #include "content/common/gpu/gpu_channel.h"
12 #include "content/common/gpu/gpu_surface_lookup.h" 12 #include "content/common/gpu/gpu_surface_lookup.h"
13 #include "content/common/gpu/media/avda_codec_image.h" 13 #include "content/common/gpu/media/avda_codec_image.h"
14 #include "content/common/gpu/media/avda_return_on_failure.h" 14 #include "content/common/gpu/media/avda_return_on_failure.h"
15 #include "content/common/gpu/media/avda_shared_state.h" 15 #include "content/common/gpu/media/avda_shared_state.h"
16 #include "gpu/command_buffer/service/texture_manager.h" 16 #include "gpu/command_buffer/service/texture_manager.h"
17 #include "ui/gl/android/surface_texture.h" 17 #include "ui/gl/android/surface_texture.h"
18 #include "ui/gl/gl_bindings.h" 18 #include "ui/gl/gl_bindings.h"
19 #include "ui/gl/scoped_make_current.h"
20
21 namespace {
22 void DeleteTexture(const scoped_refptr<gfx::GLContext>& context,
23 const scoped_refptr<gfx::GLSurface>& surface,
24 GLuint service_id) {
25 auto scoped_make_current =
26 make_scoped_ptr(new ui::ScopedMakeCurrent(context.get(), surface.get()));
27 glDeleteTextures(1, &service_id);
liberato (no reviews please) 2016/02/11 15:55:41 the more i think about it after our conversation o
watk 2016/02/11 21:21:58 :( Thanks for catching this. I'll have to look int
28 }
29 }
19 30
20 namespace content { 31 namespace content {
21 32
22 AndroidDeferredRenderingBackingStrategy:: 33 AndroidDeferredRenderingBackingStrategy::
23 AndroidDeferredRenderingBackingStrategy(AVDAStateProvider* state_provider) 34 AndroidDeferredRenderingBackingStrategy(AVDAStateProvider* state_provider)
24 : state_provider_(state_provider), media_codec_(nullptr) {} 35 : shared_state_(new AVDASharedState),
36 state_provider_(state_provider),
37 media_codec_(nullptr) {}
25 38
26 AndroidDeferredRenderingBackingStrategy:: 39 AndroidDeferredRenderingBackingStrategy::
27 ~AndroidDeferredRenderingBackingStrategy() {} 40 ~AndroidDeferredRenderingBackingStrategy() {}
28 41
29 gfx::ScopedJavaSurface AndroidDeferredRenderingBackingStrategy::Initialize( 42 gfx::ScopedJavaSurface AndroidDeferredRenderingBackingStrategy::Initialize(
30 int surface_view_id) { 43 int surface_view_id) {
31 shared_state_ = new AVDASharedState();
32
33 gfx::ScopedJavaSurface surface; 44 gfx::ScopedJavaSurface surface;
34 if (surface_view_id != media::VideoDecodeAccelerator::Config::kNoSurfaceID) { 45 if (surface_view_id != media::VideoDecodeAccelerator::Config::kNoSurfaceID) {
35 surface = 46 surface =
36 GpuSurfaceLookup::GetInstance()->AcquireJavaSurface(surface_view_id); 47 GpuSurfaceLookup::GetInstance()->AcquireJavaSurface(surface_view_id);
37 } else { 48 } else {
38 // Create a detached SurfaceTexture. Detaching it will silently fail to 49 // Create a detached SurfaceTexture. Detaching it will silently fail to
39 // delete texture 0. 50 // delete texture 0.
40 surface_texture_ = gfx::SurfaceTexture::Create(0); 51 surface_texture_ = gfx::SurfaceTexture::Create(0);
41 surface_texture_->DetachFromGLContext(); 52 surface_texture_->DetachFromGLContext();
42 surface = gfx::ScopedJavaSurface(surface_texture_.get()); 53 surface = gfx::ScopedJavaSurface(surface_texture_.get());
54 shared_state_->set_surface_texture(surface_texture_);
43 } 55 }
44 56
45 // Create a texture for the SurfaceTexture to use. We don't attach it here 57 // Create a texture for the SurfaceTexture to use. We don't attach it here
46 // so that it gets attached in the compositor gl context in the common case. 58 // so that it gets attached in the compositor gl context in the common case.
47 GLuint service_id = 0; 59 GLuint service_id = 0;
48 glGenTextures(1, &service_id); 60 glGenTextures(1, &service_id);
49 DCHECK(service_id); 61 DCHECK(service_id);
50 shared_state_->set_surface_texture_service_id(service_id); 62 scoped_refptr<gfx::GLContext> glcontext = gfx::GLContext::GetCurrent();
63 scoped_refptr<gfx::GLSurface> glsurface = gfx::GLSurface::GetCurrent();
64 shared_state_->SetSurfaceTextureServiceID(
liberato (no reviews please) 2016/02/11 15:55:41 good idea.
65 service_id, base::Bind(&DeleteTexture, glcontext, glsurface));
51 66
52 return surface; 67 return surface;
53 } 68 }
54 69
55 void AndroidDeferredRenderingBackingStrategy::Cleanup( 70 void AndroidDeferredRenderingBackingStrategy::Cleanup(
56 bool have_context, 71 bool have_context,
57 const AndroidVideoDecodeAccelerator::OutputBufferMap& buffers) { 72 const AndroidVideoDecodeAccelerator::OutputBufferMap& buffers) {
58 // If we failed before Initialize, then do nothing. 73 CodecChanged(nullptr, buffers);
59 if (!shared_state_)
60 return;
61
62 // Make sure that no PictureBuffer textures refer to the SurfaceTexture or to
63 // the service_id that we created for it.
64 for (const std::pair<int, media::PictureBuffer>& entry : buffers)
65 SetImageForPicture(entry.second, nullptr);
66
67 // Now that no AVDACodecImages refer to the SurfaceTexture's texture, delete
68 // the texture name.
69 GLuint service_id = shared_state_->surface_texture_service_id();
70 if (service_id > 0 && have_context)
71 glDeleteTextures(1, &service_id);
72 } 74 }
73 75
74 scoped_refptr<gfx::SurfaceTexture> 76 scoped_refptr<gfx::SurfaceTexture>
75 AndroidDeferredRenderingBackingStrategy::GetSurfaceTexture() const { 77 AndroidDeferredRenderingBackingStrategy::GetSurfaceTexture() const {
76 return surface_texture_; 78 return surface_texture_;
77 } 79 }
78 80
79 uint32_t AndroidDeferredRenderingBackingStrategy::GetTextureTarget() const { 81 uint32_t AndroidDeferredRenderingBackingStrategy::GetTextureTarget() const {
80 return GL_TEXTURE_EXTERNAL_OES; 82 return GL_TEXTURE_EXTERNAL_OES;
81 } 83 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 if (image) { 118 if (image) {
117 // Also set the parameters for the level if we're not clearing 119 // Also set the parameters for the level if we're not clearing
118 // the image. 120 // the image.
119 const gfx::Size size = state_provider_->GetSize(); 121 const gfx::Size size = state_provider_->GetSize();
120 texture_manager->SetLevelInfo(texture_ref, GetTextureTarget(), 0, GL_RGBA, 122 texture_manager->SetLevelInfo(texture_ref, GetTextureTarget(), 0, GL_RGBA,
121 size.width(), size.height(), 1, 0, GL_RGBA, 123 size.width(), size.height(), 1, 0, GL_RGBA,
122 GL_UNSIGNED_BYTE, gfx::Rect()); 124 GL_UNSIGNED_BYTE, gfx::Rect());
123 125
124 // Override the texture's service_id, so that it will use the one that 126 // Override the texture's service_id, so that it will use the one that
125 // will be / is attached to the SurfaceTexture. 127 // will be / is attached to the SurfaceTexture.
128 // It's okay to never reset the unowned service id as long as the Textures
129 // that refer to it have an AVDACodecImage attached. The AVDACodecImage will
130 // ensure that the surface texture service id is valid as long as the
131 // Texture is.
126 DCHECK(shared_state_->surface_texture_service_id()); 132 DCHECK(shared_state_->surface_texture_service_id());
127 texture_ref->texture()->SetUnownedServiceId( 133 texture_ref->texture()->SetUnownedServiceId(
128 shared_state_->surface_texture_service_id()); 134 shared_state_->surface_texture_service_id());
129 135
130 static_cast<AVDACodecImage*>(image.get()) 136 static_cast<AVDACodecImage*>(image.get())
131 ->SetTexture(texture_ref->texture()); 137 ->SetTexture(texture_ref->texture());
132 } else { 138 } else {
133 // Clear the unowned service_id, so that this texture is no longer going 139 // Clear the unowned service_id, so that this texture is no longer going
134 // to depend on the surface texture at all. 140 // to depend on the surface texture at all.
135 texture_ref->texture()->SetUnownedServiceId(0); 141 texture_ref->texture()->SetUnownedServiceId(0);
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 shared_state_->SignalFrameAvailable(); 234 shared_state_->SignalFrameAvailable();
229 } 235 }
230 236
231 bool AndroidDeferredRenderingBackingStrategy::ArePicturesOverlayable() { 237 bool AndroidDeferredRenderingBackingStrategy::ArePicturesOverlayable() {
232 // SurfaceView frames are always overlayable because that's the only way to 238 // SurfaceView frames are always overlayable because that's the only way to
233 // display them. 239 // display them.
234 return !surface_texture_; 240 return !surface_texture_;
235 } 241 }
236 242
237 } // namespace content 243 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698