| 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 CONTENT_COMMON_GPU_MEDIA_AVDA_CODEC_IMAGE_H_ | 5 #ifndef CONTENT_COMMON_GPU_MEDIA_AVDA_CODEC_IMAGE_H_ |
| 6 #define CONTENT_COMMON_GPU_MEDIA_AVDA_CODEC_IMAGE_H_ | 6 #define CONTENT_COMMON_GPU_MEDIA_AVDA_CODEC_IMAGE_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "content/common/gpu/media/avda_shared_state.h" | 11 #include "content/common/gpu/media/avda_shared_state.h" |
| 12 #include "ui/gl/gl_image.h" | 12 #include "ui/gl/gl_stream_texture_image.h" |
| 13 |
| 14 namespace ui { |
| 15 class ScopedMakeCurrent; |
| 16 } |
| 13 | 17 |
| 14 namespace content { | 18 namespace content { |
| 15 | 19 |
| 16 // GLImage that renders MediaCodec buffers to a SurfaceTexture or SurfaceView as | 20 // GLImage that renders MediaCodec buffers to a SurfaceTexture or SurfaceView as |
| 17 // needed in order to draw them. | 21 // needed in order to draw them. |
| 18 class AVDACodecImage : public gl::GLImage { | 22 class AVDACodecImage : public gl::GLStreamTextureImage { |
| 19 public: | 23 public: |
| 20 AVDACodecImage(const scoped_refptr<AVDASharedState>&, | 24 AVDACodecImage(const scoped_refptr<AVDASharedState>&, |
| 21 media::VideoCodecBridge* codec, | 25 media::VideoCodecBridge* codec, |
| 22 const base::WeakPtr<gpu::gles2::GLES2Decoder>& decoder, | 26 const base::WeakPtr<gpu::gles2::GLES2Decoder>& decoder, |
| 23 const scoped_refptr<gfx::SurfaceTexture>& surface_texture); | 27 const scoped_refptr<gfx::SurfaceTexture>& surface_texture); |
| 24 | 28 |
| 25 protected: | 29 protected: |
| 26 ~AVDACodecImage() override; | 30 ~AVDACodecImage() override; |
| 27 | 31 |
| 28 public: | 32 public: |
| 29 // gl::GLImage implementation | 33 // gl::GLImage implementation |
| 30 void Destroy(bool have_context) override; | 34 void Destroy(bool have_context) override; |
| 31 gfx::Size GetSize() override; | 35 gfx::Size GetSize() override; |
| 32 unsigned GetInternalFormat() override; | 36 unsigned GetInternalFormat() override; |
| 33 bool BindTexImage(unsigned target) override; | 37 bool BindTexImage(unsigned target) override; |
| 34 void ReleaseTexImage(unsigned target) override; | 38 void ReleaseTexImage(unsigned target) override; |
| 35 bool CopyTexImage(unsigned target) override; | 39 bool CopyTexImage(unsigned target) override; |
| 36 bool CopyTexSubImage(unsigned target, | 40 bool CopyTexSubImage(unsigned target, |
| 37 const gfx::Point& offset, | 41 const gfx::Point& offset, |
| 38 const gfx::Rect& rect) override; | 42 const gfx::Rect& rect) override; |
| 39 bool ScheduleOverlayPlane(gfx::AcceleratedWidget widget, | 43 bool ScheduleOverlayPlane(gfx::AcceleratedWidget widget, |
| 40 int z_order, | 44 int z_order, |
| 41 gfx::OverlayTransform transform, | 45 gfx::OverlayTransform transform, |
| 42 const gfx::Rect& bounds_rect, | 46 const gfx::Rect& bounds_rect, |
| 43 const gfx::RectF& crop_rect) override; | 47 const gfx::RectF& crop_rect) override; |
| 44 void OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd, | 48 void OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd, |
| 45 uint64_t process_tracing_id, | 49 uint64_t process_tracing_id, |
| 46 const std::string& dump_name) override; | 50 const std::string& dump_name) override; |
| 51 // gl::GLStreamTextureMatrix implementation |
| 52 void GetTextureMatrix(float xform[16]) override; |
| 47 | 53 |
| 48 public: | 54 public: |
| 49 // Decoded buffer index that has the image for us to display. | 55 // Decoded buffer index that has the image for us to display. |
| 50 void SetMediaCodecBufferIndex(int buffer_index); | 56 void SetMediaCodecBufferIndex(int buffer_index); |
| 51 | 57 |
| 52 // Return the codec buffer that we will return to the codec, or | 58 // Return the codec buffer that we will return to the codec, or |
| 53 // <0 if there is no such buffer. | 59 // <0 if there is no such buffer. |
| 54 int GetMediaCodecBufferIndex() const; | 60 int GetMediaCodecBufferIndex() const; |
| 55 | 61 |
| 56 // Set the size of the current image. | 62 // Set the size of the current image. |
| 57 void SetSize(const gfx::Size& size); | 63 void SetSize(const gfx::Size& size); |
| 58 | 64 |
| 59 void SetMediaCodec(media::MediaCodecBridge* codec); | 65 void SetMediaCodec(media::MediaCodecBridge* codec); |
| 60 | 66 |
| 61 void SetTexture(gpu::gles2::Texture* texture); | 67 void SetTexture(gpu::gles2::Texture* texture); |
| 62 | 68 |
| 63 private: | 69 private: |
| 64 enum { kInvalidCodecBufferIndex = -1 }; | 70 enum { kInvalidCodecBufferIndex = -1 }; |
| 65 | 71 |
| 66 // Make sure that the surface texture's front buffer is current. | 72 // Make sure that the surface texture's front buffer is current. This will |
| 67 void UpdateSurfaceTexture(); | 73 // save / restore the current context. It will optionally restore the texture |
| 74 // bindings in the surface texture's context, based on |mode|. This is |
| 75 // intended as a hint if we don't need to change contexts. If we do need to |
| 76 // change contexts, then we'll always preserve the texture bindings in the |
| 77 // both contexts. In other words, the caller is telling us whether it's |
| 78 // okay to change the binding in the current context. |
| 79 enum RestoreBindingsMode { kDontRestoreBindings, kDoRestoreBindings }; |
| 80 void UpdateSurfaceTexture(RestoreBindingsMode mode); |
| 68 | 81 |
| 69 // Attach the surface texture to our GL context, with a texture that we | 82 // Attach the surface texture to our GL context to whatever texture is bound |
| 70 // create for it. | 83 // on the active unit. |
| 71 void AttachSurfaceTextureToContext(); | 84 void AttachSurfaceTextureToContext(); |
| 72 | 85 |
| 73 // Install the current texture matrix into the shader. | 86 // Make shared_state_->context() current if it isn't already. |
| 74 void InstallTextureMatrix(); | 87 scoped_ptr<ui::ScopedMakeCurrent> MakeCurrentIfNeeded(); |
| 88 |
| 89 // Return whether or not the current context is in the same share group as |
| 90 // |surface_texture_|'s client texture. |
| 91 // TODO(liberato): is this needed? |
| 92 bool IsCorrectShareGroup() const; |
| 93 |
| 94 // Return whether there is a codec buffer that we haven't rendered yet. Will |
| 95 // return false also if there's no codec or we otherwise can't update. |
| 96 bool IsCodecBufferOutstanding() const; |
| 75 | 97 |
| 76 // Shared state between the AVDA and all AVDACodecImages. | 98 // Shared state between the AVDA and all AVDACodecImages. |
| 77 scoped_refptr<AVDASharedState> shared_state_; | 99 scoped_refptr<AVDASharedState> shared_state_; |
| 78 | 100 |
| 79 // The MediaCodec buffer index that we should render. Only valid if not equal | 101 // The MediaCodec buffer index that we should render. Only valid if not equal |
| 80 // to |kInvalidCodecBufferIndex|. | 102 // to |kInvalidCodecBufferIndex|. |
| 81 int codec_buffer_index_; | 103 int codec_buffer_index_; |
| 82 | 104 |
| 83 // Our image size. | 105 // Our image size. |
| 84 gfx::Size size_; | 106 gfx::Size size_; |
| 85 | 107 |
| 86 // May be null. | 108 // May be null. |
| 87 media::MediaCodecBridge* media_codec_; | 109 media::MediaCodecBridge* media_codec_; |
| 88 | 110 |
| 89 const base::WeakPtr<gpu::gles2::GLES2Decoder> decoder_; | 111 const base::WeakPtr<gpu::gles2::GLES2Decoder> decoder_; |
| 90 | 112 |
| 91 // The SurfaceTexture to render to. This is null when rendering to a | 113 // The SurfaceTexture to render to. This is null when rendering to a |
| 92 // SurfaceView. | 114 // SurfaceView. |
| 93 const scoped_refptr<gfx::SurfaceTexture> surface_texture_; | 115 const scoped_refptr<gfx::SurfaceTexture> surface_texture_; |
| 94 | 116 |
| 95 // Should we detach |surface_texture_| from its GL context when we are | 117 // Should we detach |surface_texture_| from its GL context when we are |
| 96 // deleted? This happens when it's using our Texture's texture handle. | 118 // deleted? This happens when it's using our Texture's texture handle. |
| 97 bool detach_surface_texture_on_destruction_; | 119 bool detach_surface_texture_on_destruction_; |
| 98 | 120 |
| 99 // The texture that we're attached to. | 121 // The texture that we're attached to. |
| 100 gpu::gles2::Texture* texture_; | 122 gpu::gles2::Texture* texture_; |
| 101 | 123 |
| 102 // Have we cached |texmatrix_uniform_location_| yet? | |
| 103 bool need_shader_info_; | |
| 104 | |
| 105 // Uniform ID of the texture matrix in the shader. | |
| 106 GLint texmatrix_uniform_location_; | |
| 107 | |
| 108 // Texture matrix of the front buffer of the surface texture. | 124 // Texture matrix of the front buffer of the surface texture. |
| 109 float gl_matrix_[16]; | 125 float gl_matrix_[16]; |
| 110 | 126 |
| 111 DISALLOW_COPY_AND_ASSIGN(AVDACodecImage); | 127 DISALLOW_COPY_AND_ASSIGN(AVDACodecImage); |
| 112 }; | 128 }; |
| 113 | 129 |
| 114 } // namespace content | 130 } // namespace content |
| 115 | 131 |
| 116 #endif // CONTENT_COMMON_GPU_MEDIA_AVDA_CODEC_IMAGE_H_ | 132 #endif // CONTENT_COMMON_GPU_MEDIA_AVDA_CODEC_IMAGE_H_ |
| OLD | NEW |