| 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/context_group.h" | |
| 12 #include "gpu/command_buffer/service/context_state.h" | |
| 13 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 11 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
| 14 #include "gpu/command_buffer/service/texture_manager.h" | 12 #include "gpu/command_buffer/service/texture_manager.h" |
| 15 #include "media/gpu/avda_shared_state.h" | 13 #include "media/gpu/avda_shared_state.h" |
| 16 #include "ui/gl/android/surface_texture.h" | 14 #include "ui/gl/android/surface_texture.h" |
| 17 #include "ui/gl/gl_context.h" | 15 #include "ui/gl/gl_context.h" |
| 18 #include "ui/gl/scoped_make_current.h" | 16 #include "ui/gl/scoped_make_current.h" |
| 19 | 17 |
| 20 namespace media { | 18 namespace media { |
| 21 | 19 |
| 22 AVDACodecImage::AVDACodecImage( | 20 AVDACodecImage::AVDACodecImage( |
| 23 int picture_buffer_id, | 21 int picture_buffer_id, |
| 24 const scoped_refptr<AVDASharedState>& shared_state, | 22 const scoped_refptr<AVDASharedState>& shared_state, |
| 25 media::VideoCodecBridge* codec, | 23 media::MediaCodecBridge* codec, |
| 26 const base::WeakPtr<gpu::gles2::GLES2Decoder>& decoder, | 24 const base::WeakPtr<gpu::gles2::GLES2Decoder>& decoder, |
| 27 const scoped_refptr<gfx::SurfaceTexture>& surface_texture) | 25 const scoped_refptr<gfx::SurfaceTexture>& surface_texture) |
| 28 : shared_state_(shared_state), | 26 : shared_state_(shared_state), |
| 29 codec_buffer_index_(kInvalidCodecBufferIndex), | 27 codec_buffer_index_(kInvalidCodecBufferIndex), |
| 30 media_codec_(codec), | 28 media_codec_(codec), |
| 31 decoder_(decoder), | 29 decoder_(decoder), |
| 32 surface_texture_(surface_texture), | 30 surface_texture_(surface_texture), |
| 33 texture_(0), | 31 texture_(0), |
| 34 picture_buffer_id_(picture_buffer_id) { | 32 picture_buffer_id_(picture_buffer_id) { |
| 35 // Default to a sane guess of "flip Y", just in case we can't get | 33 // Default to a sane guess of "flip Y", just in case we can't get |
| (...skipping 26 matching lines...) Expand all Loading... |
| 62 | 60 |
| 63 bool AVDACodecImage::CopyTexImage(unsigned target) { | 61 bool AVDACodecImage::CopyTexImage(unsigned target) { |
| 64 if (!surface_texture_) | 62 if (!surface_texture_) |
| 65 return false; | 63 return false; |
| 66 | 64 |
| 67 if (target != GL_TEXTURE_EXTERNAL_OES) | 65 if (target != GL_TEXTURE_EXTERNAL_OES) |
| 68 return false; | 66 return false; |
| 69 | 67 |
| 70 GLint bound_service_id = 0; | 68 GLint bound_service_id = 0; |
| 71 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &bound_service_id); | 69 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &bound_service_id); |
| 72 // We insist that the currently bound texture is the right one. We could | 70 // We insist that the currently bound texture is the right one. |
| 73 // make a new glimage from a 2D image. | 71 if (bound_service_id != |
| 74 if (bound_service_id != shared_state_->surface_texture_service_id()) | 72 static_cast<GLint>(shared_state_->surface_texture_service_id())) { |
| 75 return false; | 73 return false; |
| 74 } |
| 76 | 75 |
| 77 // Make sure that we have the right image in the front buffer. Note that the | 76 // Make sure that we have the right image in the front buffer. Note that the |
| 78 // bound_service_id is guaranteed to be equal to the surface texture's client | 77 // bound_service_id is guaranteed to be equal to the surface texture's client |
| 79 // texture id, so we can skip preserving it if the right context is current. | 78 // texture id, so we can skip preserving it if the right context is current. |
| 80 UpdateSurfaceInternal(UpdateMode::RENDER_TO_FRONT_BUFFER, | 79 UpdateSurfaceInternal(UpdateMode::RENDER_TO_FRONT_BUFFER, |
| 81 kDontRestoreBindings); | 80 kDontRestoreBindings); |
| 82 | 81 |
| 83 // By setting image state to UNBOUND instead of COPIED we ensure that | 82 // By setting image state to UNBOUND instead of COPIED we ensure that |
| 84 // CopyTexImage() is called each time the surface texture is used for drawing. | 83 // CopyTexImage() is called each time the surface texture is used for drawing. |
| 85 // It would be nice if we could do this via asking for the currently bound | 84 // It would be nice if we could do this via asking for the currently bound |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 // SurfaceViews are updated implicitly, so no further steps are necessary. | 162 // SurfaceViews are updated implicitly, so no further steps are necessary. |
| 164 if (!surface_texture_) { | 163 if (!surface_texture_) { |
| 165 DCHECK(update_mode != UpdateMode::RENDER_TO_BACK_BUFFER); | 164 DCHECK(update_mode != UpdateMode::RENDER_TO_BACK_BUFFER); |
| 166 return; | 165 return; |
| 167 } | 166 } |
| 168 | 167 |
| 169 // If front buffer rendering hasn't been requested, exit early. | 168 // If front buffer rendering hasn't been requested, exit early. |
| 170 if (update_mode != UpdateMode::RENDER_TO_FRONT_BUFFER) | 169 if (update_mode != UpdateMode::RENDER_TO_FRONT_BUFFER) |
| 171 return; | 170 return; |
| 172 | 171 |
| 173 DCHECK(shared_state_->surface_texture_is_attached()); | |
| 174 UpdateSurfaceTexture(attached_bindings_mode); | 172 UpdateSurfaceTexture(attached_bindings_mode); |
| 175 } | 173 } |
| 176 | 174 |
| 177 void AVDACodecImage::ReleaseOutputBuffer(UpdateMode update_mode) { | 175 void AVDACodecImage::ReleaseOutputBuffer(UpdateMode update_mode) { |
| 178 DCHECK(IsCodecBufferOutstanding()); | 176 DCHECK(IsCodecBufferOutstanding()); |
| 179 | 177 |
| 180 // In case of discard, simply discard and clear our codec buffer index. | 178 // In case of discard, simply discard and clear our codec buffer index. |
| 181 if (update_mode == UpdateMode::DISCARD_CODEC_BUFFER) { | 179 if (update_mode == UpdateMode::DISCARD_CODEC_BUFFER) { |
| 182 if (codec_buffer_index_ != kUpdateOnly) | 180 if (codec_buffer_index_ != kUpdateOnly) |
| 183 media_codec_->ReleaseOutputBuffer(codec_buffer_index_, false); | 181 media_codec_->ReleaseOutputBuffer(codec_buffer_index_, false); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 } | 233 } |
| 236 | 234 |
| 237 bool AVDACodecImage::IsCodecBufferOutstanding() const { | 235 bool AVDACodecImage::IsCodecBufferOutstanding() const { |
| 238 static_assert(kUpdateOnly < 0 && kUpdateOnly > kRendered && | 236 static_assert(kUpdateOnly < 0 && kUpdateOnly > kRendered && |
| 239 kRendered > kInvalidCodecBufferIndex, | 237 kRendered > kInvalidCodecBufferIndex, |
| 240 "Codec buffer index enum values are not ordered correctly."); | 238 "Codec buffer index enum values are not ordered correctly."); |
| 241 return codec_buffer_index_ > kRendered && media_codec_; | 239 return codec_buffer_index_ > kRendered && media_codec_; |
| 242 } | 240 } |
| 243 | 241 |
| 244 } // namespace media | 242 } // namespace media |
| OLD | NEW |