shared_image_stub.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. // Copyright 2018 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 GPU_IPC_SERVICE_SHARED_IMAGE_STUB_H_
  5. #define GPU_IPC_SERVICE_SHARED_IMAGE_STUB_H_
  6. #include "base/memory/raw_ptr.h"
  7. #include "base/memory/weak_ptr.h"
  8. #include "base/trace_event/memory_dump_provider.h"
  9. #include "build/build_config.h"
  10. #include "components/viz/common/resources/resource_format.h"
  11. #include "gpu/command_buffer/service/memory_tracking.h"
  12. #include "gpu/command_buffer/service/sequence_id.h"
  13. #include "gpu/command_buffer/service/sync_point_manager.h"
  14. #include "gpu/ipc/common/command_buffer_id.h"
  15. #include "gpu/ipc/common/gpu_channel.mojom.h"
  16. #include "gpu/ipc/service/gpu_ipc_service_export.h"
  17. namespace gpu {
  18. class SharedContextState;
  19. struct Mailbox;
  20. class GpuChannel;
  21. class SharedImageFactory;
  22. class GPU_IPC_SERVICE_EXPORT SharedImageStub
  23. : public MemoryTracker,
  24. public base::trace_event::MemoryDumpProvider {
  25. public:
  26. ~SharedImageStub() override;
  27. using SharedImageDestructionCallback =
  28. base::OnceCallback<void(const gpu::SyncToken&)>;
  29. static std::unique_ptr<SharedImageStub> Create(GpuChannel* channel,
  30. int32_t route_id);
  31. // Executes a DeferredRequest routed to this stub by a GpuChannel.
  32. void ExecuteDeferredRequest(mojom::DeferredSharedImageRequestPtr request);
  33. // MemoryTracker implementation:
  34. void TrackMemoryAllocatedChange(int64_t delta) override;
  35. uint64_t GetSize() const override;
  36. uint64_t ClientTracingId() const override;
  37. int ClientId() const override;
  38. uint64_t ContextGroupTracingId() const override;
  39. // base::trace_event::MemoryDumpProvider implementation:
  40. bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args,
  41. base::trace_event::ProcessMemoryDump* pmd) override;
  42. SequenceId sequence() const { return sequence_; }
  43. SharedImageFactory* factory() const { return factory_.get(); }
  44. GpuChannel* channel() const { return channel_; }
  45. SharedImageDestructionCallback GetSharedImageDestructionCallback(
  46. const Mailbox& mailbox);
  47. bool CreateSharedImage(const Mailbox& mailbox,
  48. int client_id,
  49. gfx::GpuMemoryBufferHandle handle,
  50. gfx::BufferFormat format,
  51. gfx::BufferPlane plane,
  52. SurfaceHandle surface_handle,
  53. const gfx::Size& size,
  54. const gfx::ColorSpace& color_space,
  55. GrSurfaceOrigin surface_origin,
  56. SkAlphaType alpha_type,
  57. uint32_t usage);
  58. bool UpdateSharedImage(const Mailbox& mailbox,
  59. gfx::GpuFenceHandle in_fence_handle);
  60. #if BUILDFLAG(IS_FUCHSIA)
  61. void RegisterSysmemBufferCollection(gfx::SysmemBufferCollectionId id,
  62. zx::channel token,
  63. gfx::BufferFormat format,
  64. gfx::BufferUsage usage,
  65. bool register_with_image_pipe);
  66. void ReleaseSysmemBufferCollection(gfx::SysmemBufferCollectionId id);
  67. #endif // BUILDFLAG(IS_FUCHSIA)
  68. private:
  69. SharedImageStub(GpuChannel* channel, int32_t route_id);
  70. void OnCreateSharedImage(mojom::CreateSharedImageParamsPtr params);
  71. void OnCreateSharedImageWithData(
  72. mojom::CreateSharedImageWithDataParamsPtr params);
  73. void OnCreateGMBSharedImage(mojom::CreateGMBSharedImageParamsPtr params);
  74. void OnUpdateSharedImage(const Mailbox& mailbox,
  75. uint32_t release_id,
  76. gfx::GpuFenceHandle in_fence_handle);
  77. void OnDestroySharedImage(const Mailbox& mailbox);
  78. void OnRegisterSharedImageUploadBuffer(base::ReadOnlySharedMemoryRegion shm);
  79. #if BUILDFLAG(IS_WIN)
  80. void OnCreateSharedImageVideoPlanes(
  81. mojom::CreateSharedImageVideoPlanesParamsPtr params);
  82. void OnCopyToGpuMemoryBuffer(const Mailbox& mailbox, uint32_t release_id);
  83. void OnCreateSwapChain(mojom::CreateSwapChainParamsPtr params);
  84. void OnPresentSwapChain(const Mailbox& mailbox, uint32_t release_id);
  85. #endif // BUILDFLAG(IS_WIN)
  86. bool MakeContextCurrent(bool needs_gl = false);
  87. ContextResult MakeContextCurrentAndCreateFactory();
  88. void OnError();
  89. // Wait on the sync token if any and destroy the shared image.
  90. void DestroySharedImage(const Mailbox& mailbox, const SyncToken& sync_token);
  91. raw_ptr<GpuChannel> channel_;
  92. // While this is not a CommandBuffer, this provides a unique identifier for
  93. // a SharedImageStub, comprised of identifiers which it was already using.
  94. // TODO(jonross): Look into a rename of CommandBufferId to reflect that it can
  95. // be a unique identifier for numerous gpu constructs.
  96. CommandBufferId command_buffer_id_;
  97. const SequenceId sequence_;
  98. scoped_refptr<gpu::SyncPointClientState> sync_point_client_state_;
  99. scoped_refptr<SharedContextState> context_state_;
  100. std::unique_ptr<SharedImageFactory> factory_;
  101. uint64_t size_ = 0;
  102. // Holds shared memory used in initial data uploads.
  103. base::ReadOnlySharedMemoryRegion upload_memory_;
  104. base::ReadOnlySharedMemoryMapping upload_memory_mapping_;
  105. base::WeakPtrFactory<SharedImageStub> weak_factory_{this};
  106. };
  107. } // namespace gpu
  108. #endif // GPU_IPC_SERVICE_SHARED_IMAGE_STUB_H_