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 "media/gpu/avda_codec_image.h" | 5 #include "media/gpu/avda_codec_image.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| 11 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 11 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
| 12 #include "gpu/command_buffer/service/texture_manager.h" | 12 #include "gpu/command_buffer/service/texture_manager.h" |
| 13 #include "media/base/android/sdk_media_codec_bridge.h" | 13 #include "media/base/android/sdk_media_codec_bridge.h" |
| 14 #include "media/gpu/avda_shared_state.h" | 14 #include "media/gpu/avda_shared_state.h" |
| 15 #include "ui/gl/android/surface_texture.h" | 15 #include "ui/gl/android/surface_texture.h" |
| 16 #include "ui/gl/gl_context.h" | 16 #include "ui/gl/gl_context.h" |
| 17 #include "ui/gl/scoped_make_current.h" | 17 #include "ui/gl/scoped_make_current.h" |
| 18 | 18 |
| 19 namespace media { | 19 namespace media { |
| 20 | 20 |
| 21 AVDACodecImage::AVDACodecImage( | 21 AVDACodecImage::AVDACodecImage( |
| 22 int picture_buffer_id, | |
| 23 const scoped_refptr<AVDASharedState>& shared_state, | 22 const scoped_refptr<AVDASharedState>& shared_state, |
| 24 VideoCodecBridge* codec, | 23 VideoCodecBridge* codec, |
| 25 const base::WeakPtr<gpu::gles2::GLES2Decoder>& decoder) | 24 const base::WeakPtr<gpu::gles2::GLES2Decoder>& decoder) |
| 26 : shared_state_(shared_state), | 25 : shared_state_(shared_state), |
| 27 codec_buffer_index_(kInvalidCodecBufferIndex), | 26 codec_buffer_index_(kInvalidCodecBufferIndex), |
| 28 media_codec_(codec), | 27 media_codec_(codec), |
| 29 decoder_(decoder), | 28 decoder_(decoder), |
| 30 has_surface_texture_(!!shared_state_->surface_texture_service_id()), | 29 has_surface_texture_(false), |
| 31 texture_(0), | 30 texture_(0) {} |
| 32 picture_buffer_id_(picture_buffer_id) { | |
| 33 shared_state_->SetImageForPicture(picture_buffer_id_, this); | |
| 34 } | |
| 35 | 31 |
| 36 AVDACodecImage::~AVDACodecImage() { | 32 AVDACodecImage::~AVDACodecImage() {} |
| 37 shared_state_->SetImageForPicture(picture_buffer_id_, nullptr); | |
| 38 } | |
| 39 | 33 |
| 40 gfx::Size AVDACodecImage::GetSize() { | 34 gfx::Size AVDACodecImage::GetSize() { |
| 41 return size_; | 35 return size_; |
| 42 } | 36 } |
| 43 | 37 |
| 44 unsigned AVDACodecImage::GetInternalFormat() { | 38 unsigned AVDACodecImage::GetInternalFormat() { |
| 45 return GL_RGBA; | 39 return GL_RGBA; |
| 46 } | 40 } |
| 47 | 41 |
| 48 bool AVDACodecImage::BindTexImage(unsigned target) { | 42 bool AVDACodecImage::BindTexImage(unsigned target) { |
| 49 return false; | 43 return false; |
| 50 } | 44 } |
| 51 | 45 |
| 52 void AVDACodecImage::ReleaseTexImage(unsigned target) {} | 46 void AVDACodecImage::ReleaseTexImage(unsigned target) {} |
| 53 | 47 |
| 54 bool AVDACodecImage::CopyTexImage(unsigned target) { | 48 bool AVDACodecImage::CopyTexImage(unsigned target) { |
| 55 if (!has_surface_texture_) | 49 if (!has_surface_texture_) |
| 56 return false; | 50 return false; |
| 57 | 51 |
| 58 if (target != GL_TEXTURE_EXTERNAL_OES) | 52 if (target != GL_TEXTURE_EXTERNAL_OES) |
| 59 return false; | 53 return false; |
| 60 | 54 |
| 61 GLint bound_service_id = 0; | 55 // GLint bound_service_id = 0; |
|
liberato (no reviews please)
2016/11/03 20:51:04
now that we're swapping out |shared_state_| when s
DaleCurtis
2016/11/04 01:07:22
Just left over testing. Removed.
| |
| 62 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &bound_service_id); | 56 // glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &bound_service_id); |
| 63 // We insist that the currently bound texture is the right one. | 57 // // We insist that the currently bound texture is the right one. |
| 64 if (bound_service_id != | 58 // if (bound_service_id != |
| 65 static_cast<GLint>(shared_state_->surface_texture_service_id())) { | 59 // static_cast<GLint>(shared_state_->surface_texture_service_id())) { |
| 66 return false; | 60 // return false; |
| 67 } | 61 // } |
| 68 | 62 |
| 69 // Make sure that we have the right image in the front buffer. Note that the | 63 // Make sure that we have the right image in the front buffer. Note that the |
| 70 // bound_service_id is guaranteed to be equal to the surface texture's client | 64 // bound_service_id is guaranteed to be equal to the surface texture's client |
| 71 // texture id, so we can skip preserving it if the right context is current. | 65 // texture id, so we can skip preserving it if the right context is current. |
| 72 UpdateSurfaceInternal(UpdateMode::RENDER_TO_FRONT_BUFFER, | 66 UpdateSurfaceInternal(UpdateMode::RENDER_TO_FRONT_BUFFER, |
| 73 kDontRestoreBindings); | 67 kDontRestoreBindings); |
| 74 | 68 |
| 75 // By setting image state to UNBOUND instead of COPIED we ensure that | 69 // By setting image state to UNBOUND instead of COPIED we ensure that |
| 76 // CopyTexImage() is called each time the surface texture is used for drawing. | 70 // CopyTexImage() is called each time the surface texture is used for drawing. |
| 77 // It would be nice if we could do this via asking for the currently bound | 71 // It would be nice if we could do this via asking for the currently bound |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 | 128 |
| 135 void AVDACodecImage::UpdateSurface(UpdateMode update_mode) { | 129 void AVDACodecImage::UpdateSurface(UpdateMode update_mode) { |
| 136 UpdateSurfaceInternal(update_mode, kDoRestoreBindings); | 130 UpdateSurfaceInternal(update_mode, kDoRestoreBindings); |
| 137 } | 131 } |
| 138 | 132 |
| 139 void AVDACodecImage::CodecChanged(MediaCodecBridge* codec) { | 133 void AVDACodecImage::CodecChanged(MediaCodecBridge* codec) { |
| 140 media_codec_ = codec; | 134 media_codec_ = codec; |
| 141 codec_buffer_index_ = kInvalidCodecBufferIndex; | 135 codec_buffer_index_ = kInvalidCodecBufferIndex; |
| 142 } | 136 } |
| 143 | 137 |
| 138 void AVDACodecImage::SetBufferMetadata(int buffer_index, | |
| 139 bool has_surface_texture, | |
| 140 const gfx::Size size) { | |
| 141 has_surface_texture_ = has_surface_texture; | |
| 142 codec_buffer_index_ = buffer_index; | |
| 143 size_ = size; | |
| 144 } | |
| 145 | |
| 146 bool AVDACodecImage::SetSharedState( | |
| 147 const scoped_refptr<AVDASharedState>& shared_state) { | |
| 148 if (shared_state == shared_state_) | |
| 149 return false; | |
| 150 shared_state_ = shared_state; | |
| 151 return true; | |
| 152 } | |
| 153 | |
| 144 void AVDACodecImage::UpdateSurfaceInternal( | 154 void AVDACodecImage::UpdateSurfaceInternal( |
| 145 UpdateMode update_mode, | 155 UpdateMode update_mode, |
| 146 RestoreBindingsMode attached_bindings_mode) { | 156 RestoreBindingsMode attached_bindings_mode) { |
| 147 if (!IsCodecBufferOutstanding()) | 157 if (!IsCodecBufferOutstanding()) |
| 148 return; | 158 return; |
| 149 | 159 |
| 150 ReleaseOutputBuffer(update_mode); | 160 ReleaseOutputBuffer(update_mode); |
| 151 | 161 |
| 152 // SurfaceViews are updated implicitly, so no further steps are necessary. | 162 // SurfaceViews are updated implicitly, so no further steps are necessary. |
| 153 if (!has_surface_texture_) { | 163 if (!has_surface_texture_) { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 224 } | 234 } |
| 225 | 235 |
| 226 bool AVDACodecImage::IsCodecBufferOutstanding() const { | 236 bool AVDACodecImage::IsCodecBufferOutstanding() const { |
| 227 static_assert(kUpdateOnly < 0 && kUpdateOnly > kRendered && | 237 static_assert(kUpdateOnly < 0 && kUpdateOnly > kRendered && |
| 228 kRendered > kInvalidCodecBufferIndex, | 238 kRendered > kInvalidCodecBufferIndex, |
| 229 "Codec buffer index enum values are not ordered correctly."); | 239 "Codec buffer index enum values are not ordered correctly."); |
| 230 return codec_buffer_index_ > kRendered && media_codec_; | 240 return codec_buffer_index_ > kRendered && media_codec_; |
| 231 } | 241 } |
| 232 | 242 |
| 233 } // namespace media | 243 } // namespace media |
| OLD | NEW |