| 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_(!!shared_state_->surface_texture_service_id()), |
| 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_ || target != GL_TEXTURE_EXTERNAL_OES) |
| 56 return false; | |
| 57 | |
| 58 if (target != GL_TEXTURE_EXTERNAL_OES) | |
| 59 return false; | 50 return false; |
| 60 | 51 |
| 61 GLint bound_service_id = 0; | 52 GLint bound_service_id = 0; |
| 62 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &bound_service_id); | 53 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &bound_service_id); |
| 63 // We insist that the currently bound texture is the right one. | 54 // We insist that the currently bound texture is the right one. |
| 64 if (bound_service_id != | 55 if (bound_service_id != |
| 65 static_cast<GLint>(shared_state_->surface_texture_service_id())) { | 56 static_cast<GLint>(shared_state_->surface_texture_service_id())) { |
| 66 return false; | 57 return false; |
| 67 } | 58 } |
| 68 | 59 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 codec_buffer_index_ = kUpdateOnly; | 188 codec_buffer_index_ = kUpdateOnly; |
| 198 } | 189 } |
| 199 | 190 |
| 200 // Only wait for the SurfaceTexture update if we're rendering to the front. | 191 // Only wait for the SurfaceTexture update if we're rendering to the front. |
| 201 if (update_mode == UpdateMode::RENDER_TO_FRONT_BUFFER) | 192 if (update_mode == UpdateMode::RENDER_TO_FRONT_BUFFER) |
| 202 shared_state_->WaitForFrameAvailable(); | 193 shared_state_->WaitForFrameAvailable(); |
| 203 } | 194 } |
| 204 | 195 |
| 205 std::unique_ptr<ui::ScopedMakeCurrent> AVDACodecImage::MakeCurrentIfNeeded() { | 196 std::unique_ptr<ui::ScopedMakeCurrent> AVDACodecImage::MakeCurrentIfNeeded() { |
| 206 DCHECK(shared_state_->context()); | 197 DCHECK(shared_state_->context()); |
| 207 std::unique_ptr<ui::ScopedMakeCurrent> scoped_make_current; | |
| 208 // Remember: virtual contexts return true if and only if their shared context | 198 // Remember: virtual contexts return true if and only if their shared context |
| 209 // is current, regardless of which virtual context it is. | 199 // is current, regardless of which virtual context it is. |
| 210 if (!shared_state_->context()->IsCurrent(NULL)) { | 200 return std::unique_ptr<ui::ScopedMakeCurrent>( |
| 211 scoped_make_current.reset(new ui::ScopedMakeCurrent( | 201 shared_state_->context()->IsCurrent(nullptr) |
| 212 shared_state_->context(), shared_state_->surface())); | 202 ? nullptr |
| 213 } | 203 : new ui::ScopedMakeCurrent(shared_state_->context(), |
| 214 | 204 shared_state_->surface())); |
| 215 return scoped_make_current; | |
| 216 } | 205 } |
| 217 | 206 |
| 218 void AVDACodecImage::GetTextureMatrix(float matrix[16]) { | 207 void AVDACodecImage::GetTextureMatrix(float matrix[16]) { |
| 219 // Our current matrix may be stale. Update it if possible. | 208 // Our current matrix may be stale. Update it if possible. |
| 220 if (has_surface_texture_) | 209 if (has_surface_texture_) |
| 221 UpdateSurface(UpdateMode::RENDER_TO_FRONT_BUFFER); | 210 UpdateSurface(UpdateMode::RENDER_TO_FRONT_BUFFER); |
| 222 shared_state_->GetTransformMatrix(matrix); | 211 shared_state_->GetTransformMatrix(matrix); |
| 223 YInvertMatrix(matrix); | 212 YInvertMatrix(matrix); |
| 224 } | 213 } |
| 225 | 214 |
| 226 bool AVDACodecImage::IsCodecBufferOutstanding() const { | 215 bool AVDACodecImage::IsCodecBufferOutstanding() const { |
| 227 static_assert(kUpdateOnly < 0 && kUpdateOnly > kRendered && | 216 static_assert(kUpdateOnly < 0 && kUpdateOnly > kRendered && |
| 228 kRendered > kInvalidCodecBufferIndex, | 217 kRendered > kInvalidCodecBufferIndex, |
| 229 "Codec buffer index enum values are not ordered correctly."); | 218 "Codec buffer index enum values are not ordered correctly."); |
| 230 return codec_buffer_index_ > kRendered && media_codec_; | 219 return codec_buffer_index_ > kRendered && media_codec_; |
| 231 } | 220 } |
| 232 | 221 |
| 233 } // namespace media | 222 } // namespace media |
| OLD | NEW |