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