| 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 MEDIA_GPU_ANDROID_DEFERRED_RENDERING_BACKING_STRATEGY_H_ | |
| 6 #define MEDIA_GPU_ANDROID_DEFERRED_RENDERING_BACKING_STRATEGY_H_ | |
| 7 | |
| 8 #include <stdint.h> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/macros.h" | |
| 12 #include "media/gpu/android_video_decode_accelerator.h" | |
| 13 #include "media/gpu/media_gpu_export.h" | |
| 14 | |
| 15 namespace gl { | |
| 16 class GLImage; | |
| 17 } | |
| 18 | |
| 19 namespace gpu { | |
| 20 namespace gles2 { | |
| 21 class GLStreamTextureImage; | |
| 22 class TextureRef; | |
| 23 } | |
| 24 } | |
| 25 | |
| 26 namespace media { | |
| 27 | |
| 28 class AVDACodecImage; | |
| 29 class AVDASharedState; | |
| 30 | |
| 31 // A BackingStrategy implementation that defers releasing codec buffers until | |
| 32 // a PictureBuffer's texture is used to draw, then draws using the surface | |
| 33 // texture's front buffer rather than a copy. To do this, it uses a GLImage | |
| 34 // implementation to talk to MediaCodec. | |
| 35 class MEDIA_GPU_EXPORT AndroidDeferredRenderingBackingStrategy | |
| 36 : public AndroidVideoDecodeAccelerator::BackingStrategy { | |
| 37 public: | |
| 38 explicit AndroidDeferredRenderingBackingStrategy( | |
| 39 AVDAStateProvider* state_provider); | |
| 40 ~AndroidDeferredRenderingBackingStrategy() override; | |
| 41 | |
| 42 // AndroidVideoDecodeAccelerator::BackingStrategy | |
| 43 gl::ScopedJavaSurface Initialize(int surface_view_id) override; | |
| 44 void BeginCleanup( | |
| 45 bool have_context, | |
| 46 const AndroidVideoDecodeAccelerator::OutputBufferMap& buffers) override; | |
| 47 void EndCleanup() override; | |
| 48 scoped_refptr<gl::SurfaceTexture> GetSurfaceTexture() const override; | |
| 49 uint32_t GetTextureTarget() const override; | |
| 50 gfx::Size GetPictureBufferSize() const override; | |
| 51 void UseCodecBufferForPictureBuffer( | |
| 52 int32_t codec_buffer_index, | |
| 53 const PictureBuffer& picture_buffer) override; | |
| 54 void AssignOnePictureBuffer(const PictureBuffer&, bool) override; | |
| 55 void ReuseOnePictureBuffer(const PictureBuffer& picture_buffer) override; | |
| 56 void MaybeRenderEarly() override; | |
| 57 void CodecChanged(VideoCodecBridge* codec) override; | |
| 58 void ReleaseCodecBuffers( | |
| 59 const AndroidVideoDecodeAccelerator::OutputBufferMap& buffers) override; | |
| 60 void OnFrameAvailable() override; | |
| 61 bool ArePicturesOverlayable() override; | |
| 62 void UpdatePictureBufferSize(PictureBuffer* picture_buffer, | |
| 63 const gfx::Size& new_size) override; | |
| 64 | |
| 65 private: | |
| 66 // Release any codec buffer that is associated with the given picture buffer | |
| 67 // back to the codec. It is okay if there is no such buffer. | |
| 68 void ReleaseCodecBufferForPicture(const PictureBuffer& picture_buffer); | |
| 69 | |
| 70 // Sets up the texture references (as found by |picture_buffer|), for the | |
| 71 // specified |image|. If |image| is null, clears any ref on the texture | |
| 72 // associated with |picture_buffer|. | |
| 73 void SetImageForPicture( | |
| 74 const PictureBuffer& picture_buffer, | |
| 75 const scoped_refptr<gpu::gles2::GLStreamTextureImage>& image); | |
| 76 | |
| 77 // Make a copy of the SurfaceTexture's front buffer and associate all given | |
| 78 // picture buffer textures with it. The picture buffer textures will not | |
| 79 // dependend on |this|, the SurfaceTexture, the MediaCodec or the VDA, so it's | |
| 80 // used to back the picture buffers when the VDA is being destroyed. | |
| 81 void CopySurfaceTextureToPictures( | |
| 82 const AndroidVideoDecodeAccelerator::OutputBufferMap& buffers); | |
| 83 | |
| 84 // Return true if and only if CopySurfaceTextureToPictures is expected to work | |
| 85 // on this device. | |
| 86 bool ShouldCopyPictures() const; | |
| 87 | |
| 88 scoped_refptr<AVDASharedState> shared_state_; | |
| 89 | |
| 90 AVDAStateProvider* state_provider_; | |
| 91 | |
| 92 // The SurfaceTexture to render to. Non-null after Initialize() if | |
| 93 // we're not rendering to a SurfaceView. | |
| 94 scoped_refptr<gl::SurfaceTexture> surface_texture_; | |
| 95 | |
| 96 VideoCodecBridge* media_codec_; | |
| 97 | |
| 98 // Picture buffer IDs that are out for display. Stored in order of frames as | |
| 99 // they are returned from the decoder. | |
| 100 std::vector<int32_t> pictures_out_for_display_; | |
| 101 | |
| 102 DISALLOW_COPY_AND_ASSIGN(AndroidDeferredRenderingBackingStrategy); | |
| 103 }; | |
| 104 | |
| 105 } // namespace media | |
| 106 | |
| 107 #endif // MEDIA_GPU_ANDROID_DEFERRED_RENDERING_BACKING_STRATEGY_H_ | |
| OLD | NEW |