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_copying_backing_strategy.h" | 5 #include "content/common/gpu/media/android_copying_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/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
| 10 #include "content/common/gpu/media/avda_return_on_failure.h" | 10 #include "content/common/gpu/media/avda_return_on_failure.h" |
| 11 #include "gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.h" | 11 #include "gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.h" |
| 12 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 12 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
| 13 #include "media/base/limits.h" | 13 #include "media/base/limits.h" |
| 14 #include "media/video/picture.h" | 14 #include "media/video/picture.h" |
| 15 #include "ui/gl/android/surface_texture.h" | 15 #include "ui/gl/android/surface_texture.h" |
| 16 #include "ui/gl/gl_bindings.h" | 16 #include "ui/gl/gl_bindings.h" |
| 17 | 17 |
| 18 namespace content { | 18 namespace content { |
| 19 | 19 |
| 20 const static GLfloat kIdentityMatrix[16] = {1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, | 20 const static GLfloat kIdentityMatrix[16] = {1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, |
| 21 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, | 21 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, |
| 22 0.0f, 0.0f, 0.0f, 1.0f}; | 22 0.0f, 0.0f, 0.0f, 1.0f}; |
| 23 | 23 |
| 24 AndroidCopyingBackingStrategy::AndroidCopyingBackingStrategy() | 24 AndroidCopyingBackingStrategy::AndroidCopyingBackingStrategy() |
| 25 : state_provider_(nullptr), surface_texture_id_(0), media_codec_(nullptr) {} | 25 : state_provider_(nullptr), surface_texture_id_(0), media_codec_(nullptr) {} |
| 26 | 26 |
| 27 AndroidCopyingBackingStrategy::~AndroidCopyingBackingStrategy() {} | 27 AndroidCopyingBackingStrategy::~AndroidCopyingBackingStrategy() {} |
| 28 | 28 |
| 29 void AndroidCopyingBackingStrategy::Initialize( | 29 gfx::ScopedJavaSurface AndroidCopyingBackingStrategy::Initialize( |
|
liberato (no reviews please)
2016/01/27 16:15:33
that's a good idea.
| |
| 30 AVDAStateProvider* state_provider) { | 30 AVDAStateProvider* state_provider, |
| 31 int surface_view_id) { | |
| 32 DCHECK(surface_view_id == | |
|
DaleCurtis
2016/01/27 21:48:13
DCHECK_EQ
| |
| 33 media::VideoDecodeAccelerator::Config::kNoSurfaceID); | |
| 31 state_provider_ = state_provider; | 34 state_provider_ = state_provider; |
| 32 } | |
| 33 | 35 |
| 34 void AndroidCopyingBackingStrategy::Cleanup( | 36 // Create a texture and attach the SurfaceTexture to it. |
| 35 bool have_context, | |
| 36 const AndroidVideoDecodeAccelerator::OutputBufferMap&) { | |
| 37 DCHECK(state_provider_->ThreadChecker().CalledOnValidThread()); | |
| 38 if (copier_) | |
| 39 copier_->Destroy(); | |
| 40 | |
| 41 if (surface_texture_id_ && have_context) | |
| 42 glDeleteTextures(1, &surface_texture_id_); | |
| 43 } | |
| 44 | |
| 45 uint32_t AndroidCopyingBackingStrategy::GetTextureTarget() const { | |
| 46 return GL_TEXTURE_2D; | |
| 47 } | |
| 48 | |
| 49 scoped_refptr<gfx::SurfaceTexture> | |
| 50 AndroidCopyingBackingStrategy::CreateSurfaceTexture() { | |
| 51 glGenTextures(1, &surface_texture_id_); | 37 glGenTextures(1, &surface_texture_id_); |
| 52 glActiveTexture(GL_TEXTURE0); | 38 glActiveTexture(GL_TEXTURE0); |
| 53 glBindTexture(GL_TEXTURE_EXTERNAL_OES, surface_texture_id_); | 39 glBindTexture(GL_TEXTURE_EXTERNAL_OES, surface_texture_id_); |
| 54 | 40 |
| 55 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 41 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 56 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 42 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 57 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 43 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 58 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 44 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 45 | |
| 59 state_provider_->GetGlDecoder()->RestoreTextureUnitBindings(0); | 46 state_provider_->GetGlDecoder()->RestoreTextureUnitBindings(0); |
| 60 state_provider_->GetGlDecoder()->RestoreActiveTexture(); | 47 state_provider_->GetGlDecoder()->RestoreActiveTexture(); |
| 61 | 48 |
| 62 surface_texture_ = gfx::SurfaceTexture::Create(surface_texture_id_); | 49 surface_texture_ = gfx::SurfaceTexture::Create(surface_texture_id_); |
| 63 | 50 |
| 51 return gfx::ScopedJavaSurface(surface_texture_.get()); | |
| 52 } | |
| 53 | |
| 54 void AndroidCopyingBackingStrategy::Cleanup( | |
| 55 bool have_context, | |
| 56 const AndroidVideoDecodeAccelerator::OutputBufferMap&) { | |
| 57 DCHECK(state_provider_->ThreadChecker().CalledOnValidThread()); | |
| 58 if (copier_) | |
| 59 copier_->Destroy(); | |
| 60 | |
| 61 if (surface_texture_id_ && have_context) | |
| 62 glDeleteTextures(1, &surface_texture_id_); | |
| 63 } | |
| 64 | |
| 65 scoped_refptr<gfx::SurfaceTexture> | |
| 66 AndroidCopyingBackingStrategy::GetSurfaceTexture() const { | |
| 64 return surface_texture_; | 67 return surface_texture_; |
| 65 } | 68 } |
| 66 | 69 |
| 70 uint32_t AndroidCopyingBackingStrategy::GetTextureTarget() const { | |
| 71 return GL_TEXTURE_2D; | |
| 72 } | |
| 73 | |
| 67 void AndroidCopyingBackingStrategy::UseCodecBufferForPictureBuffer( | 74 void AndroidCopyingBackingStrategy::UseCodecBufferForPictureBuffer( |
| 68 int32_t codec_buf_index, | 75 int32_t codec_buf_index, |
| 69 const media::PictureBuffer& picture_buffer) { | 76 const media::PictureBuffer& picture_buffer) { |
| 70 // Make sure that the decoder is available. | 77 // Make sure that the decoder is available. |
| 71 RETURN_ON_FAILURE(state_provider_, state_provider_->GetGlDecoder().get(), | 78 RETURN_ON_FAILURE(state_provider_, state_provider_->GetGlDecoder().get(), |
| 72 "Failed to get gles2 decoder instance.", ILLEGAL_STATE); | 79 "Failed to get gles2 decoder instance.", ILLEGAL_STATE); |
| 73 | 80 |
| 74 // Render the codec buffer into |surface_texture_|, and switch it to be | 81 // Render the codec buffer into |surface_texture_|, and switch it to be |
| 75 // the front buffer. | 82 // the front buffer. |
| 76 // This ignores the emitted ByteBuffer and instead relies on rendering to | 83 // This ignores the emitted ByteBuffer and instead relies on rendering to |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 } | 141 } |
| 135 | 142 |
| 136 void AndroidCopyingBackingStrategy::OnFrameAvailable() { | 143 void AndroidCopyingBackingStrategy::OnFrameAvailable() { |
| 137 // TODO(liberato): crbug.com/574948 . The OnFrameAvailable logic can be | 144 // TODO(liberato): crbug.com/574948 . The OnFrameAvailable logic can be |
| 138 // moved into AVDA, and we should wait for it before doing the copy. | 145 // moved into AVDA, and we should wait for it before doing the copy. |
| 139 // Because there were some test failures, we don't do this now but | 146 // Because there were some test failures, we don't do this now but |
| 140 // instead preserve the old behavior. | 147 // instead preserve the old behavior. |
| 141 } | 148 } |
| 142 | 149 |
| 143 } // namespace content | 150 } // namespace content |
| OLD | NEW |