| 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/avda_codec_image.h" | 5 #include "content/common/gpu/media/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 "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
| 12 #include "content/common/gpu/media/avda_shared_state.h" | 12 #include "content/common/gpu/media/avda_shared_state.h" |
| 13 #include "gpu/command_buffer/service/context_group.h" | 13 #include "gpu/command_buffer/service/context_group.h" |
| 14 #include "gpu/command_buffer/service/context_state.h" | 14 #include "gpu/command_buffer/service/context_state.h" |
| 15 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 15 #include "gpu/command_buffer/service/gles2_cmd_decoder.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_context.h" | 18 #include "ui/gl/gl_context.h" |
| 19 #include "ui/gl/scoped_make_current.h" | 19 #include "ui/gl/scoped_make_current.h" |
| 20 | 20 |
| 21 namespace content { | 21 namespace content { |
| 22 | 22 |
| 23 AVDACodecImage::AVDACodecImage( | 23 AVDACodecImage::AVDACodecImage( |
| 24 int picture_buffer_id, |
| 24 const scoped_refptr<AVDASharedState>& shared_state, | 25 const scoped_refptr<AVDASharedState>& shared_state, |
| 25 media::VideoCodecBridge* codec, | 26 media::VideoCodecBridge* codec, |
| 26 const base::WeakPtr<gpu::gles2::GLES2Decoder>& decoder, | 27 const base::WeakPtr<gpu::gles2::GLES2Decoder>& decoder, |
| 27 const scoped_refptr<gfx::SurfaceTexture>& surface_texture) | 28 const scoped_refptr<gfx::SurfaceTexture>& surface_texture) |
| 28 : shared_state_(shared_state), | 29 : shared_state_(shared_state), |
| 29 codec_buffer_index_(kInvalidCodecBufferIndex), | 30 codec_buffer_index_(kInvalidCodecBufferIndex), |
| 30 media_codec_(codec), | 31 media_codec_(codec), |
| 31 decoder_(decoder), | 32 decoder_(decoder), |
| 32 surface_texture_(surface_texture), | 33 surface_texture_(surface_texture), |
| 33 detach_surface_texture_on_destruction_(false), | 34 detach_surface_texture_on_destruction_(false), |
| 34 texture_(0) { | 35 texture_(0), |
| 36 picture_buffer_id_(picture_buffer_id) { |
| 35 // Default to a sane guess of "flip Y", just in case we can't get | 37 // Default to a sane guess of "flip Y", just in case we can't get |
| 36 // the matrix on the first call. | 38 // the matrix on the first call. |
| 37 memset(gl_matrix_, 0, sizeof(gl_matrix_)); | 39 memset(gl_matrix_, 0, sizeof(gl_matrix_)); |
| 38 gl_matrix_[0] = gl_matrix_[10] = gl_matrix_[15] = 1.0f; | 40 gl_matrix_[0] = gl_matrix_[10] = gl_matrix_[15] = 1.0f; |
| 39 gl_matrix_[5] = -1.0f; | 41 gl_matrix_[5] = -1.0f; |
| 42 shared_state_->SetImageForPicture(picture_buffer_id_, this); |
| 40 } | 43 } |
| 41 | 44 |
| 42 AVDACodecImage::~AVDACodecImage() {} | 45 AVDACodecImage::~AVDACodecImage() { |
| 46 shared_state_->SetImageForPicture(picture_buffer_id_, nullptr); |
| 47 } |
| 43 | 48 |
| 44 void AVDACodecImage::Destroy(bool have_context) {} | 49 void AVDACodecImage::Destroy(bool have_context) {} |
| 45 | 50 |
| 46 gfx::Size AVDACodecImage::GetSize() { | 51 gfx::Size AVDACodecImage::GetSize() { |
| 47 return size_; | 52 return size_; |
| 48 } | 53 } |
| 49 | 54 |
| 50 unsigned AVDACodecImage::GetInternalFormat() { | 55 unsigned AVDACodecImage::GetInternalFormat() { |
| 51 return GL_RGBA; | 56 return GL_RGBA; |
| 52 } | 57 } |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 } | 170 } |
| 166 | 171 |
| 167 int AVDACodecImage::GetMediaCodecBufferIndex() const { | 172 int AVDACodecImage::GetMediaCodecBufferIndex() const { |
| 168 return codec_buffer_index_; | 173 return codec_buffer_index_; |
| 169 } | 174 } |
| 170 | 175 |
| 171 void AVDACodecImage::SetSize(const gfx::Size& size) { | 176 void AVDACodecImage::SetSize(const gfx::Size& size) { |
| 172 size_ = size; | 177 size_ = size; |
| 173 } | 178 } |
| 174 | 179 |
| 175 void AVDACodecImage::SetMediaCodec(media::MediaCodecBridge* codec) { | 180 void AVDACodecImage::CodecChanged(media::MediaCodecBridge* codec) { |
| 176 media_codec_ = codec; | 181 media_codec_ = codec; |
| 182 codec_buffer_index_ = kInvalidCodecBufferIndex; |
| 177 } | 183 } |
| 178 | 184 |
| 179 void AVDACodecImage::SetTexture(gpu::gles2::Texture* texture) { | 185 void AVDACodecImage::SetTexture(gpu::gles2::Texture* texture) { |
| 180 texture_ = texture; | 186 texture_ = texture; |
| 181 } | 187 } |
| 182 | 188 |
| 183 void AVDACodecImage::AttachSurfaceTextureToContext() { | 189 void AVDACodecImage::AttachSurfaceTextureToContext() { |
| 184 DCHECK(surface_texture_); | 190 DCHECK(surface_texture_); |
| 185 | 191 |
| 186 // We assume that the currently bound texture is the intended one. | 192 // We assume that the currently bound texture is the intended one. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 } | 240 } |
| 235 | 241 |
| 236 memcpy(matrix, gl_matrix_, sizeof(gl_matrix_)); | 242 memcpy(matrix, gl_matrix_, sizeof(gl_matrix_)); |
| 237 } | 243 } |
| 238 | 244 |
| 239 bool AVDACodecImage::IsCodecBufferOutstanding() const { | 245 bool AVDACodecImage::IsCodecBufferOutstanding() const { |
| 240 return codec_buffer_index_ != kInvalidCodecBufferIndex && media_codec_; | 246 return codec_buffer_index_ != kInvalidCodecBufferIndex && media_codec_; |
| 241 } | 247 } |
| 242 | 248 |
| 243 } // namespace content | 249 } // namespace content |
| OLD | NEW |