shared_image_video_provider.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // Copyright 2019 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_GPU_ANDROID_SHARED_IMAGE_VIDEO_PROVIDER_H_
  5. #define MEDIA_GPU_ANDROID_SHARED_IMAGE_VIDEO_PROVIDER_H_
  6. #include "base/callback.h"
  7. #include "gpu/command_buffer/service/mailbox_manager.h"
  8. #include "gpu/ipc/common/vulkan_ycbcr_info.h"
  9. #include "media/gpu/android/codec_image_group.h"
  10. #include "media/gpu/android/promotion_hint_aggregator.h"
  11. #include "media/gpu/media_gpu_export.h"
  12. #include "ui/gfx/geometry/size.h"
  13. namespace gpu {
  14. class CommandBufferStub;
  15. class SharedContextState;
  16. struct SyncToken;
  17. } // namespace gpu
  18. namespace media {
  19. // Provider class for shared images.
  20. class MEDIA_GPU_EXPORT SharedImageVideoProvider {
  21. public:
  22. using GetStubCB = base::RepeatingCallback<gpu::CommandBufferStub*()>;
  23. using GpuInitCB =
  24. base::OnceCallback<void(scoped_refptr<gpu::SharedContextState>)>;
  25. // Description of the underlying properties of the shared image.
  26. struct ImageSpec {
  27. ImageSpec();
  28. ImageSpec(const gfx::Size& coded_size, uint64_t generation_id);
  29. ImageSpec(const ImageSpec&);
  30. ~ImageSpec();
  31. // Size of the underlying texture.
  32. gfx::Size coded_size;
  33. // Color space used for the SharedImage.
  34. gfx::ColorSpace color_space;
  35. // This is a hack to allow us to discard pooled images if the TextureOwner
  36. // changes. We don't want to keep a ref to the TextureOwner here, so we
  37. // just use a generation counter. Note that this is temporary anyway; we
  38. // only need it for legacy mailbox support to construct a per-video-frame
  39. // texture with the TextureOwner's service id (unowned texture hack). Once
  40. // legacy mailboxes aren't needed, SharedImageVideo::BeginAccess can just
  41. // ask the CodecImage for whatever TextureOwner it is using currently, which
  42. // is set by the client via CodecImage::Initialize.
  43. uint64_t generation_id = 0;
  44. // TODO: Include other properties, if they matter, like texture format.
  45. bool operator==(const ImageSpec&) const;
  46. bool operator!=(const ImageSpec&) const;
  47. };
  48. using ReleaseCB = base::OnceCallback<void(const gpu::SyncToken&)>;
  49. // Description of the image that's being provided to the client.
  50. struct ImageRecord {
  51. ImageRecord();
  52. ImageRecord(ImageRecord&&);
  53. ImageRecord(const ImageRecord&) = delete;
  54. ImageRecord& operator=(const ImageRecord&) = delete;
  55. ~ImageRecord();
  56. // Mailbox to which this shared image is bound.
  57. gpu::Mailbox mailbox;
  58. // Release callback. When this is called (or dropped), the image will be
  59. // considered to be unused.
  60. ReleaseCB release_cb;
  61. // CodecImage that one can use for MaybeRenderEarly, and to attach a codec
  62. // output buffer.
  63. scoped_refptr<CodecImageHolder> codec_image_holder;
  64. // Is the underlying context Vulkan? If so, then one must provide YCbCrInfo
  65. // with the VideoFrame.
  66. bool is_vulkan = false;
  67. };
  68. SharedImageVideoProvider() = default;
  69. SharedImageVideoProvider(const SharedImageVideoProvider&) = delete;
  70. SharedImageVideoProvider& operator=(const SharedImageVideoProvider&) = delete;
  71. virtual ~SharedImageVideoProvider() = default;
  72. using ImageReadyCB = base::OnceCallback<void(ImageRecord)>;
  73. // Initialize this provider. On success, |gpu_init_cb| will be run with the
  74. // SharedContextState (and the context current), on the gpu main thread. This
  75. // is mostly a hack to allow VideoFrameFactoryImpl to create a TextureOwner on
  76. // the right context. Will call |gpu_init_cb| with nullptr otherwise.
  77. virtual void Initialize(GpuInitCB gpu_init_cb) = 0;
  78. // Call |cb| when we have a shared image that matches |spec|. We may call
  79. // |cb| back before returning, or we might post it for later.
  80. virtual void RequestImage(ImageReadyCB cb, const ImageSpec& spec) = 0;
  81. };
  82. } // namespace media
  83. #endif // MEDIA_GPU_ANDROID_SHARED_IMAGE_VIDEO_PROVIDER_H_