| 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 "base/macros.h" | |
| 11 #include "content/common/gpu/media/avda_shared_state.h" | |
| 12 #include "gpu/command_buffer/service/gl_stream_texture_image.h" | |
| 13 | |
| 14 namespace ui { | |
| 15 class ScopedMakeCurrent; | |
| 16 } | |
| 17 | |
| 18 namespace content { | |
| 19 | |
| 20 // GLImage that renders MediaCodec buffers to a SurfaceTexture or SurfaceView as | |
| 21 // needed in order to draw them. | |
| 22 class AVDACodecImage : public gpu::gles2::GLStreamTextureImage { | |
| 23 public: | |
| 24 AVDACodecImage(const scoped_refptr<AVDASharedState>&, | |
| 25 media::VideoCodecBridge* codec, | |
| 26 const base::WeakPtr<gpu::gles2::GLES2Decoder>& decoder, | |
| 27 const scoped_refptr<gfx::SurfaceTexture>& surface_texture); | |
| 28 | |
| 29 protected: | |
| 30 ~AVDACodecImage() override; | |
| 31 | |
| 32 public: | |
| 33 // gl::GLImage implementation | |
| 34 void Destroy(bool have_context) override; | |
| 35 gfx::Size GetSize() override; | |
| 36 unsigned GetInternalFormat() override; | |
| 37 bool BindTexImage(unsigned target) override; | |
| 38 void ReleaseTexImage(unsigned target) override; | |
| 39 bool CopyTexImage(unsigned target) override; | |
| 40 bool CopyTexSubImage(unsigned target, | |
| 41 const gfx::Point& offset, | |
| 42 const gfx::Rect& rect) override; | |
| 43 bool ScheduleOverlayPlane(gfx::AcceleratedWidget widget, | |
| 44 int z_order, | |
| 45 gfx::OverlayTransform transform, | |
| 46 const gfx::Rect& bounds_rect, | |
| 47 const gfx::RectF& crop_rect) override; | |
| 48 void OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd, | |
| 49 uint64_t process_tracing_id, | |
| 50 const std::string& dump_name) override; | |
| 51 // gpu::gles2::GLStreamTextureMatrix implementation | |
| 52 void GetTextureMatrix(float xform[16]) override; | |
| 53 | |
| 54 public: | |
| 55 // Decoded buffer index that has the image for us to display. | |
| 56 void SetMediaCodecBufferIndex(int buffer_index); | |
| 57 | |
| 58 // Return the codec buffer that we will return to the codec, or | |
| 59 // <0 if there is no such buffer. | |
| 60 int GetMediaCodecBufferIndex() const; | |
| 61 | |
| 62 // Set the size of the current image. | |
| 63 void SetSize(const gfx::Size& size); | |
| 64 | |
| 65 void SetMediaCodec(media::MediaCodecBridge* codec); | |
| 66 | |
| 67 void SetTexture(gpu::gles2::Texture* texture); | |
| 68 | |
| 69 private: | |
| 70 enum { kInvalidCodecBufferIndex = -1 }; | |
| 71 | |
| 72 // Make sure that the surface texture's front buffer is current. This will | |
| 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); | |
| 81 | |
| 82 // Attach the surface texture to our GL context to whatever texture is bound | |
| 83 // on the active unit. | |
| 84 void AttachSurfaceTextureToContext(); | |
| 85 | |
| 86 // Make shared_state_->context() current if it isn't already. | |
| 87 std::unique_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; | |
| 97 | |
| 98 // Shared state between the AVDA and all AVDACodecImages. | |
| 99 scoped_refptr<AVDASharedState> shared_state_; | |
| 100 | |
| 101 // The MediaCodec buffer index that we should render. Only valid if not equal | |
| 102 // to |kInvalidCodecBufferIndex|. | |
| 103 int codec_buffer_index_; | |
| 104 | |
| 105 // Our image size. | |
| 106 gfx::Size size_; | |
| 107 | |
| 108 // May be null. | |
| 109 media::MediaCodecBridge* media_codec_; | |
| 110 | |
| 111 const base::WeakPtr<gpu::gles2::GLES2Decoder> decoder_; | |
| 112 | |
| 113 // The SurfaceTexture to render to. This is null when rendering to a | |
| 114 // SurfaceView. | |
| 115 const scoped_refptr<gfx::SurfaceTexture> surface_texture_; | |
| 116 | |
| 117 // Should we detach |surface_texture_| from its GL context when we are | |
| 118 // deleted? This happens when it's using our Texture's texture handle. | |
| 119 bool detach_surface_texture_on_destruction_; | |
| 120 | |
| 121 // The texture that we're attached to. | |
| 122 gpu::gles2::Texture* texture_; | |
| 123 | |
| 124 // Texture matrix of the front buffer of the surface texture. | |
| 125 float gl_matrix_[16]; | |
| 126 | |
| 127 DISALLOW_COPY_AND_ASSIGN(AVDACodecImage); | |
| 128 }; | |
| 129 | |
| 130 } // namespace content | |
| 131 | |
| 132 #endif // CONTENT_COMMON_GPU_MEDIA_AVDA_CODEC_IMAGE_H_ | |
| OLD | NEW |