Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 | 19 |
| 20 namespace content { | 20 namespace content { |
| 21 | 21 |
| 22 AndroidDeferredRenderingBackingStrategy:: | 22 AndroidDeferredRenderingBackingStrategy:: |
| 23 AndroidDeferredRenderingBackingStrategy(AVDAStateProvider* state_provider) | 23 AndroidDeferredRenderingBackingStrategy(AVDAStateProvider* state_provider) |
| 24 : state_provider_(state_provider), media_codec_(nullptr) {} | 24 : shared_state_(new AVDASharedState), |
| 25 state_provider_(state_provider), | |
| 26 media_codec_(nullptr) {} | |
| 25 | 27 |
| 26 AndroidDeferredRenderingBackingStrategy:: | 28 AndroidDeferredRenderingBackingStrategy:: |
| 27 ~AndroidDeferredRenderingBackingStrategy() {} | 29 ~AndroidDeferredRenderingBackingStrategy() {} |
| 28 | 30 |
| 29 gfx::ScopedJavaSurface AndroidDeferredRenderingBackingStrategy::Initialize( | 31 gfx::ScopedJavaSurface AndroidDeferredRenderingBackingStrategy::Initialize( |
| 30 int surface_view_id) { | 32 int surface_view_id) { |
| 31 shared_state_ = new AVDASharedState(); | |
| 32 | |
| 33 gfx::ScopedJavaSurface surface; | 33 gfx::ScopedJavaSurface surface; |
| 34 if (surface_view_id != media::VideoDecodeAccelerator::Config::kNoSurfaceID) { | 34 if (surface_view_id != media::VideoDecodeAccelerator::Config::kNoSurfaceID) { |
| 35 surface = | 35 surface = |
| 36 GpuSurfaceLookup::GetInstance()->AcquireJavaSurface(surface_view_id); | 36 GpuSurfaceLookup::GetInstance()->AcquireJavaSurface(surface_view_id); |
| 37 } else { | 37 } else { |
| 38 // Create a detached SurfaceTexture. Detaching it will silently fail to | 38 // Create a detached SurfaceTexture. Detaching it will silently fail to |
| 39 // delete texture 0. | 39 // delete texture 0. |
| 40 surface_texture_ = gfx::SurfaceTexture::Create(0); | 40 surface_texture_ = gfx::SurfaceTexture::Create(0); |
| 41 surface_texture_->DetachFromGLContext(); | 41 surface_texture_->DetachFromGLContext(); |
| 42 surface = gfx::ScopedJavaSurface(surface_texture_.get()); | 42 surface = gfx::ScopedJavaSurface(surface_texture_.get()); |
| 43 shared_state_->set_surface_texture(surface_texture_); | |
| 43 } | 44 } |
| 44 | 45 |
| 45 // Create a texture for the SurfaceTexture to use. We don't attach it here | 46 // 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. | 47 // so that it gets attached in the compositor gl context in the common case. |
| 47 GLuint service_id = 0; | 48 GLuint service_id = 0; |
| 48 glGenTextures(1, &service_id); | 49 glGenTextures(1, &service_id); |
| 49 DCHECK(service_id); | 50 DCHECK(service_id); |
| 50 shared_state_->set_surface_texture_service_id(service_id); | 51 shared_state_->set_surface_texture_service_id(service_id); |
| 51 | 52 |
| 52 return surface; | 53 return surface; |
| 53 } | 54 } |
| 54 | 55 |
| 55 void AndroidDeferredRenderingBackingStrategy::Cleanup( | 56 void AndroidDeferredRenderingBackingStrategy::Cleanup( |
| 56 bool have_context, | 57 bool have_context, |
| 57 const AndroidVideoDecodeAccelerator::OutputBufferMap& buffers) { | 58 const AndroidVideoDecodeAccelerator::OutputBufferMap& buffers) { |
| 58 // If we failed before Initialize, then do nothing. | 59 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); | |
|
liberato (no reviews please)
2016/02/10 06:39:12
it's late, and i might very well be missing it, bu
| |
| 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 } | 60 } |
| 73 | 61 |
| 74 scoped_refptr<gfx::SurfaceTexture> | 62 scoped_refptr<gfx::SurfaceTexture> |
| 75 AndroidDeferredRenderingBackingStrategy::GetSurfaceTexture() const { | 63 AndroidDeferredRenderingBackingStrategy::GetSurfaceTexture() const { |
| 76 return surface_texture_; | 64 return surface_texture_; |
| 77 } | 65 } |
| 78 | 66 |
| 79 uint32_t AndroidDeferredRenderingBackingStrategy::GetTextureTarget() const { | 67 uint32_t AndroidDeferredRenderingBackingStrategy::GetTextureTarget() const { |
| 80 return GL_TEXTURE_EXTERNAL_OES; | 68 return GL_TEXTURE_EXTERNAL_OES; |
| 81 } | 69 } |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 228 shared_state_->SignalFrameAvailable(); | 216 shared_state_->SignalFrameAvailable(); |
| 229 } | 217 } |
| 230 | 218 |
| 231 bool AndroidDeferredRenderingBackingStrategy::ArePicturesOverlayable() { | 219 bool AndroidDeferredRenderingBackingStrategy::ArePicturesOverlayable() { |
| 232 // SurfaceView frames are always overlayable because that's the only way to | 220 // SurfaceView frames are always overlayable because that's the only way to |
| 233 // display them. | 221 // display them. |
| 234 return !surface_texture_; | 222 return !surface_texture_; |
| 235 } | 223 } |
| 236 | 224 |
| 237 } // namespace content | 225 } // namespace content |
| OLD | NEW |