| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CONTENT_COMMON_GPU_MEDIA_AVDA_CODEC_IMAGE_H_ | |
| 6 #define CONTENT_COMMON_GPU_MEDIA_AVDA_CODEC_IMAGE_H_ | |
| 7 | |
| 8 #include <stdint.h> | |
| 9 | |
| 10 #include <memory> | |
| 11 | |
| 12 #include "base/macros.h" | |
| 13 #include "content/common/gpu/media/avda_shared_state.h" | |
| 14 #include "gpu/command_buffer/service/gl_stream_texture_image.h" | |
| 15 | |
| 16 namespace ui { | |
| 17 class ScopedMakeCurrent; | |
| 18 } | |
| 19 | |
| 20 namespace content { | |
| 21 | |
| 22 // GLImage that renders MediaCodec buffers to a SurfaceTexture or SurfaceView as | |
| 23 // needed in order to draw them. | |
| 24 class AVDACodecImage : public gpu::gles2::GLStreamTextureImage { | |
| 25 public: | |
| 26 AVDACodecImage(int picture_buffer_id, | |
| 27 const scoped_refptr<AVDASharedState>& shared_state, | |
| 28 media::VideoCodecBridge* codec, | |
| 29 const base::WeakPtr<gpu::gles2::GLES2Decoder>& decoder, | |
| 30 const scoped_refptr<gfx::SurfaceTexture>& surface_texture); | |
| 31 | |
| 32 // gl::GLImage implementation | |
| 33 void Destroy(bool have_context) override; | |
| 34 gfx::Size GetSize() override; | |
| 35 unsigned GetInternalFormat() override; | |
| 36 bool BindTexImage(unsigned target) override; | |
| 37 void ReleaseTexImage(unsigned target) override; | |
| 38 bool CopyTexImage(unsigned target) override; | |
| 39 bool CopyTexSubImage(unsigned target, | |
| 40 const gfx::Point& offset, | |
| 41 const gfx::Rect& rect) override; | |
| 42 bool ScheduleOverlayPlane(gfx::AcceleratedWidget widget, | |
| 43 int z_order, | |
| 44 gfx::OverlayTransform transform, | |
| 45 const gfx::Rect& bounds_rect, | |
| 46 const gfx::RectF& crop_rect) override; | |
| 47 void OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd, | |
| 48 uint64_t process_tracing_id, | |
| 49 const std::string& dump_name) override; | |
| 50 // gpu::gles2::GLStreamTextureMatrix implementation | |
| 51 void GetTextureMatrix(float xform[16]) override; | |
| 52 | |
| 53 // Decoded buffer index that has the image for us to display. | |
| 54 void SetMediaCodecBufferIndex(int buffer_index); | |
| 55 | |
| 56 // Set the size of the current image. | |
| 57 void SetSize(const gfx::Size& size); | |
| 58 | |
| 59 enum class UpdateMode { | |
| 60 // Discards the codec buffer, no UpdateTexImage(). | |
| 61 DISCARD_CODEC_BUFFER, | |
| 62 | |
| 63 // Renders to back buffer, no UpdateTexImage(); can only be used with a | |
| 64 // valid |surface_texture_|. | |
| 65 RENDER_TO_BACK_BUFFER, | |
| 66 | |
| 67 // Renders to the back buffer. When used with a SurfaceView, promotion to | |
| 68 // the front buffer is automatic. When using a |surface_texture_|, | |
| 69 // UpdateTexImage() is called to promote the back buffer into the front. | |
| 70 RENDER_TO_FRONT_BUFFER | |
| 71 }; | |
| 72 | |
| 73 // Releases the attached codec buffer (if not already released) indicated by | |
| 74 // |codec_buffer_index_| and updates the surface if specified by the given | |
| 75 // |update_mode|. See UpdateMode documentation for details. | |
| 76 void UpdateSurface(UpdateMode update_mode); | |
| 77 | |
| 78 // Updates the MediaCodec for this image; clears |codec_buffer_index_|. | |
| 79 void CodecChanged(media::MediaCodecBridge* codec); | |
| 80 | |
| 81 void SetTexture(gpu::gles2::Texture* texture); | |
| 82 | |
| 83 // Indicates if the codec buffer has been released to the back buffer. | |
| 84 bool is_rendered_to_back_buffer() const { | |
| 85 return codec_buffer_index_ == kUpdateOnly; | |
| 86 } | |
| 87 | |
| 88 // Indicates if the codec buffer has been released to the front or back | |
| 89 // buffer. | |
| 90 bool is_rendered() const { | |
| 91 return codec_buffer_index_ <= kInvalidCodecBufferIndex; | |
| 92 } | |
| 93 | |
| 94 protected: | |
| 95 ~AVDACodecImage() override; | |
| 96 | |
| 97 private: | |
| 98 enum { kInvalidCodecBufferIndex = -1, kUpdateOnly = -2 }; | |
| 99 | |
| 100 // 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 | |
| 102 // 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 | |
| 104 // 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 | |
| 106 // okay to change the binding in the current context. | |
| 107 enum RestoreBindingsMode { kDontRestoreBindings, kDoRestoreBindings }; | |
| 108 void UpdateSurfaceTexture(RestoreBindingsMode mode); | |
| 109 | |
| 110 // Internal helper for UpdateSurface() that allows callers to specify the | |
| 111 // RestoreBindingsMode when a SurfaceTexture is already attached prior to | |
| 112 // calling this method. | |
| 113 void UpdateSurfaceInternal(UpdateMode update_mode, | |
| 114 RestoreBindingsMode attached_bindings_mode); | |
| 115 | |
| 116 // Releases the attached codec buffer (if not already released) indicated by | |
| 117 // |codec_buffer_index_|. Never updates the actual surface. See UpdateMode | |
| 118 // documentation for details. For the purposes of this function the values | |
| 119 // RENDER_TO_FRONT_BUFFER and RENDER_TO_BACK_BUFFER do the same thing. | |
| 120 void ReleaseOutputBuffer(UpdateMode update_mode); | |
| 121 | |
| 122 // Attach the surface texture to our GL context to whatever texture is bound | |
| 123 // on the active unit. | |
| 124 void AttachSurfaceTextureToContext(); | |
| 125 | |
| 126 // Make shared_state_->context() current if it isn't already. | |
| 127 std::unique_ptr<ui::ScopedMakeCurrent> MakeCurrentIfNeeded(); | |
| 128 | |
| 129 // Return whether there is a codec buffer that we haven't rendered yet. Will | |
| 130 // return false also if there's no codec or we otherwise can't update. | |
| 131 bool IsCodecBufferOutstanding() const; | |
| 132 | |
| 133 // Shared state between the AVDA and all AVDACodecImages. | |
| 134 scoped_refptr<AVDASharedState> shared_state_; | |
| 135 | |
| 136 // The MediaCodec buffer index that we should render. Only valid if not equal | |
| 137 // to |kInvalidCodecBufferIndex|. | |
| 138 int codec_buffer_index_; | |
| 139 | |
| 140 // Our image size. | |
| 141 gfx::Size size_; | |
| 142 | |
| 143 // May be null. | |
| 144 media::MediaCodecBridge* media_codec_; | |
| 145 | |
| 146 const base::WeakPtr<gpu::gles2::GLES2Decoder> decoder_; | |
| 147 | |
| 148 // The SurfaceTexture to render to. This is null when rendering to a | |
| 149 // SurfaceView. | |
| 150 const scoped_refptr<gfx::SurfaceTexture> surface_texture_; | |
| 151 | |
| 152 // Should we detach |surface_texture_| from its GL context when we are | |
| 153 // deleted? This happens when it's using our Texture's texture handle. | |
| 154 bool detach_surface_texture_on_destruction_; | |
| 155 | |
| 156 // The texture that we're attached to. | |
| 157 gpu::gles2::Texture* texture_; | |
| 158 | |
| 159 // Texture matrix of the front buffer of the surface texture. | |
| 160 float gl_matrix_[16]; | |
| 161 | |
| 162 // The picture buffer id attached to this image. | |
| 163 int picture_buffer_id_; | |
| 164 | |
| 165 DISALLOW_COPY_AND_ASSIGN(AVDACodecImage); | |
| 166 }; | |
| 167 | |
| 168 } // namespace content | |
| 169 | |
| 170 #endif // CONTENT_COMMON_GPU_MEDIA_AVDA_CODEC_IMAGE_H_ | |
| OLD | NEW |