| // Copyright 2023 The Chromium Authors |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #ifndef GPU_COMMAND_BUFFER_CLIENT_CLIENT_SHARED_IMAGE_H_ |
| #define GPU_COMMAND_BUFFER_CLIENT_CLIENT_SHARED_IMAGE_H_ |
| |
| #include "base/memory/scoped_refptr.h" |
| #include "gpu/command_buffer/client/shared_image_interface.h" |
| #include "gpu/command_buffer/common/mailbox.h" |
| #include "gpu/command_buffer/common/shared_image_trace_utils.h" |
| #include "gpu/gpu_export.h" |
| #include "ui/gfx/gpu_memory_buffer.h" |
| |
| namespace gpu { |
| |
| class GPU_EXPORT ClientSharedImage |
| : public base::RefCountedThreadSafe<ClientSharedImage> { |
| public: |
| explicit ClientSharedImage(const Mailbox& mailbox); |
| ClientSharedImage(const Mailbox& mailbox, |
| std::unique_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer); |
| |
| const Mailbox& mailbox() { return mailbox_; } |
| |
| base::trace_event::MemoryAllocatorDumpGuid GetGUIDForTracing() { |
| return gpu::GetSharedImageGUIDForTracing(mailbox_); |
| } |
| |
| // Maps |mailbox| into CPU visible memory and returns a ScopedMapping object |
| // which can be used to read/write to the CPU mapped memory. The SharedImage |
| // backing this ClientSI must have been created with CPU_READ/CPU_WRITE usage. |
| std::unique_ptr<SharedImageInterface::ScopedMapping> Map(); |
| |
| static scoped_refptr<ClientSharedImage> CreateForTesting() { |
| return base::MakeRefCounted<ClientSharedImage>( |
| Mailbox::GenerateForSharedImage()); |
| } |
| |
| private: |
| friend class base::RefCountedThreadSafe<ClientSharedImage>; |
| ~ClientSharedImage(); |
| |
| const Mailbox mailbox_; |
| std::unique_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer_; |
| }; |
| |
| } // namespace gpu |
| |
| #endif // GPU_COMMAND_BUFFER_CLIENT_CLIENT_SHARED_IMAGE_H_ |