| 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 #ifndef MEDIA_GPU_AVDA_CODEC_IMAGE_H_ | 5 #ifndef MEDIA_GPU_AVDA_CODEC_IMAGE_H_ |
| 6 #define MEDIA_GPU_AVDA_CODEC_IMAGE_H_ | 6 #define MEDIA_GPU_AVDA_CODEC_IMAGE_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 | 11 |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "gpu/command_buffer/service/gl_stream_texture_image.h" | 13 #include "gpu/command_buffer/service/gl_stream_texture_image.h" |
| 14 #include "media/gpu/avda_shared_state.h" | 14 #include "media/gpu/avda_shared_state.h" |
| 15 | 15 |
| 16 namespace ui { | 16 namespace ui { |
| 17 class ScopedMakeCurrent; | 17 class ScopedMakeCurrent; |
| 18 } | 18 } |
| 19 | 19 |
| 20 namespace media { | 20 namespace media { |
| 21 | 21 |
| 22 class VideoCodecBridge; | 22 class VideoCodecBridge; |
| 23 | 23 |
| 24 // GLImage that renders MediaCodec buffers to a SurfaceTexture or SurfaceView as | 24 // GLImage that renders MediaCodec buffers to a SurfaceTexture or SurfaceView as |
| 25 // needed in order to draw them. | 25 // needed in order to draw them. |
| 26 class AVDACodecImage : public gpu::gles2::GLStreamTextureImage { | 26 class AVDACodecImage : public gpu::gles2::GLStreamTextureImage { |
| 27 public: | 27 public: |
| 28 AVDACodecImage(int picture_buffer_id, | 28 AVDACodecImage(const scoped_refptr<AVDASharedState>& shared_state, |
| 29 const scoped_refptr<AVDASharedState>& shared_state, | |
| 30 VideoCodecBridge* codec, | 29 VideoCodecBridge* codec, |
| 31 const base::WeakPtr<gpu::gles2::GLES2Decoder>& decoder); | 30 const base::WeakPtr<gpu::gles2::GLES2Decoder>& decoder); |
| 32 | 31 |
| 33 // gl::GLImage implementation | 32 // gl::GLImage implementation |
| 34 gfx::Size GetSize() override; | 33 gfx::Size GetSize() override; |
| 35 unsigned GetInternalFormat() override; | 34 unsigned GetInternalFormat() override; |
| 36 bool BindTexImage(unsigned target) override; | 35 bool BindTexImage(unsigned target) override; |
| 37 void ReleaseTexImage(unsigned target) override; | 36 void ReleaseTexImage(unsigned target) override; |
| 38 bool CopyTexImage(unsigned target) override; | 37 bool CopyTexImage(unsigned target) override; |
| 39 bool CopyTexSubImage(unsigned target, | 38 bool CopyTexSubImage(unsigned target, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 69 // |codec_buffer_index_| and updates the surface if specified by the given | 68 // |codec_buffer_index_| and updates the surface if specified by the given |
| 70 // |update_mode|. See UpdateMode documentation for details. | 69 // |update_mode|. See UpdateMode documentation for details. |
| 71 void UpdateSurface(UpdateMode update_mode); | 70 void UpdateSurface(UpdateMode update_mode); |
| 72 | 71 |
| 73 // Updates the MediaCodec for this image; clears |codec_buffer_index_|. | 72 // Updates the MediaCodec for this image; clears |codec_buffer_index_|. |
| 74 void CodecChanged(MediaCodecBridge* codec); | 73 void CodecChanged(MediaCodecBridge* codec); |
| 75 | 74 |
| 76 void set_texture(gpu::gles2::Texture* texture) { texture_ = texture; } | 75 void set_texture(gpu::gles2::Texture* texture) { texture_ = texture; } |
| 77 | 76 |
| 78 // Decoded buffer index that has the image for us to display. | 77 // Decoded buffer index that has the image for us to display. |
| 79 void set_media_codec_buffer_index(int buffer_index) { | 78 void SetBufferMetadata(int buffer_index, |
| 80 codec_buffer_index_ = buffer_index; | 79 bool has_surface_texture, |
| 81 } | 80 const gfx::Size size); |
| 82 | 81 |
| 83 // Set the size of the current image. | 82 bool SetSharedState(const scoped_refptr<AVDASharedState>& shared_state); |
| 84 void set_size(const gfx::Size& size) { size_ = size; } | |
| 85 | 83 |
| 86 // Indicates if the codec buffer has been released to the back buffer. | 84 // Indicates if the codec buffer has been released to the back buffer. |
| 87 bool was_rendered_to_back_buffer() const { | 85 bool was_rendered_to_back_buffer() const { |
| 88 return codec_buffer_index_ == kUpdateOnly; | 86 return codec_buffer_index_ == kUpdateOnly; |
| 89 } | 87 } |
| 90 | 88 |
| 91 // Indicates if the codec buffer has been released to the front buffer. | 89 // Indicates if the codec buffer has been released to the front buffer. |
| 92 bool was_rendered_to_front_buffer() const { | 90 bool was_rendered_to_front_buffer() const { |
| 93 return codec_buffer_index_ == kRendered; | 91 return codec_buffer_index_ == kRendered; |
| 94 } | 92 } |
| 95 | 93 |
| 94 bool has_unrendered_frame() const { |
| 95 return codec_buffer_index_ >= kUpdateOnly; |
| 96 } |
| 97 |
| 96 protected: | 98 protected: |
| 97 ~AVDACodecImage() override; | 99 ~AVDACodecImage() override; |
| 98 | 100 |
| 99 private: | 101 private: |
| 100 // Make sure that the surface texture's front buffer is current. This will | 102 // Make sure that the surface texture's front buffer is current. This will |
| 101 // save / restore the current context. It will optionally restore the texture | 103 // save / restore the current context. It will optionally restore the texture |
| 102 // bindings in the surface texture's context, based on |mode|. This is | 104 // bindings in the surface texture's context, based on |mode|. This is |
| 103 // intended as a hint if we don't need to change contexts. If we do need to | 105 // intended as a hint if we don't need to change contexts. If we do need to |
| 104 // change contexts, then we'll always preserve the texture bindings in the | 106 // change contexts, then we'll always preserve the texture bindings in the |
| 105 // both contexts. In other words, the caller is telling us whether it's | 107 // both contexts. In other words, the caller is telling us whether it's |
| (...skipping 29 matching lines...) Expand all Loading... |
| 135 int codec_buffer_index_; | 137 int codec_buffer_index_; |
| 136 | 138 |
| 137 // Our image size. | 139 // Our image size. |
| 138 gfx::Size size_; | 140 gfx::Size size_; |
| 139 | 141 |
| 140 // May be null. | 142 // May be null. |
| 141 MediaCodecBridge* media_codec_; | 143 MediaCodecBridge* media_codec_; |
| 142 | 144 |
| 143 const base::WeakPtr<gpu::gles2::GLES2Decoder> decoder_; | 145 const base::WeakPtr<gpu::gles2::GLES2Decoder> decoder_; |
| 144 | 146 |
| 145 // Indicates if we're rendering to a SurfaceTexture or not. | 147 // Indicates if we're rendering to a SurfaceTexture or not. Set during the |
| 146 const bool has_surface_texture_; | 148 // call to SetBufferMetadata(). |
| 149 bool has_surface_texture_; |
| 147 | 150 |
| 148 // The texture that we're attached to. | 151 // The texture that we're attached to. |
| 149 gpu::gles2::Texture* texture_; | 152 gpu::gles2::Texture* texture_; |
| 150 | 153 |
| 151 // The picture buffer id attached to this image. | |
| 152 int picture_buffer_id_; | |
| 153 | |
| 154 DISALLOW_COPY_AND_ASSIGN(AVDACodecImage); | 154 DISALLOW_COPY_AND_ASSIGN(AVDACodecImage); |
| 155 }; | 155 }; |
| 156 | 156 |
| 157 } // namespace media | 157 } // namespace media |
| 158 | 158 |
| 159 #endif // MEDIA_GPU_AVDA_CODEC_IMAGE_H_ | 159 #endif // MEDIA_GPU_AVDA_CODEC_IMAGE_H_ |
| OLD | NEW |