renderable_gpu_memory_buffer_video_frame_pool.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Copyright 2021 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. #ifndef MEDIA_VIDEO_RENDERABLE_GPU_MEMORY_BUFFER_VIDEO_FRAME_POOL_H_
  5. #define MEDIA_VIDEO_RENDERABLE_GPU_MEMORY_BUFFER_VIDEO_FRAME_POOL_H_
  6. #include <memory>
  7. #include "base/memory/ref_counted.h"
  8. #include "media/base/media_export.h"
  9. #include "media/base/video_types.h"
  10. #include "third_party/skia/include/core/SkImageInfo.h"
  11. #include "third_party/skia/include/gpu/GrTypes.h"
  12. #include "ui/gfx/buffer_types.h"
  13. namespace gfx {
  14. class ColorSpace;
  15. class GpuMemoryBuffer;
  16. class Size;
  17. } // namespace gfx
  18. namespace gpu {
  19. class GpuMemoryBufferManager;
  20. class SharedImageInterface;
  21. struct Mailbox;
  22. struct SyncToken;
  23. } // namespace gpu
  24. namespace media {
  25. class VideoFrame;
  26. // A video frame pool that returns GpuMemoryBuffer-backed VideoFrames. All
  27. // access to this class must be on the thread on which it was created.
  28. class MEDIA_EXPORT RenderableGpuMemoryBufferVideoFramePool {
  29. public:
  30. // Interface to GPU functionality. This particular interface (as opposed to,
  31. // say, exposing a GpuMemoryBufferManager and SharedImageInterface) is
  32. // chosen for testing.
  33. class Context {
  34. public:
  35. // Allocate a GpuMemoryBuffer.
  36. virtual std::unique_ptr<gfx::GpuMemoryBuffer> CreateGpuMemoryBuffer(
  37. const gfx::Size& size,
  38. gfx::BufferFormat format,
  39. gfx::BufferUsage usage) = 0;
  40. // Create a SharedImage representation of a plane of a GpuMemoryBuffer
  41. // allocated by this interface. Populate `mailbox` and `sync_token`.
  42. virtual void CreateSharedImage(gfx::GpuMemoryBuffer* gpu_memory_buffer,
  43. gfx::BufferPlane plane,
  44. const gfx::ColorSpace& color_space,
  45. GrSurfaceOrigin surface_origin,
  46. SkAlphaType alpha_type,
  47. uint32_t usage,
  48. gpu::Mailbox& mailbox,
  49. gpu::SyncToken& sync_token) = 0;
  50. // Destroy a SharedImage created by this interface.
  51. virtual void DestroySharedImage(const gpu::SyncToken& sync_token,
  52. const gpu::Mailbox& mailbox) = 0;
  53. virtual ~Context() = default;
  54. };
  55. // Create a frame pool. The supplied `context` will live until all frames
  56. // created by the pool have been destroyed (so it may outlive the returned
  57. // pool).
  58. static std::unique_ptr<RenderableGpuMemoryBufferVideoFramePool> Create(
  59. std::unique_ptr<Context> context);
  60. // Returns a GpuMemoryBuffer-backed VideoFrame that can be rendered to. This
  61. // may return nullptr on an unsupported parameter, or may return nullptr
  62. // forever in response to a context lost.
  63. virtual scoped_refptr<VideoFrame> MaybeCreateVideoFrame(
  64. const gfx::Size& coded_size,
  65. const gfx::ColorSpace& color_space) = 0;
  66. virtual ~RenderableGpuMemoryBufferVideoFramePool() = default;
  67. };
  68. } // namespace media
  69. #endif // MEDIA_VIDEO_RENDERABLE_GPU_MEMORY_BUFFER_VIDEO_FRAME_POOL_H_