SharedTextureDMABuf.h (2191B)
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 #ifndef GPU_SharedTextureDMABuf_H_ 7 #define GPU_SharedTextureDMABuf_H_ 8 9 #include "mozilla/WeakPtr.h" 10 #include "mozilla/gfx/FileHandleWrapper.h" 11 #include "mozilla/webgpu/SharedTexture.h" 12 #include "nsTArrayForwardDeclare.h" 13 14 class DMABufSurface; 15 16 namespace mozilla { 17 18 namespace webgpu { 19 20 class VkImageHandle; 21 class VkSemaphoreHandle; 22 23 class SharedTextureDMABuf final : public SharedTexture { 24 public: 25 static UniquePtr<SharedTextureDMABuf> Create( 26 WebGPUParent* aParent, const ffi::WGPUDeviceId aDeviceId, 27 const uint32_t aWidth, const uint32_t aHeight, 28 const struct ffi::WGPUTextureFormat aFormat, 29 const ffi::WGPUTextureUsages aUsage); 30 31 SharedTextureDMABuf( 32 WebGPUParent* aParent, const ffi::WGPUDeviceId aDeviceId, 33 UniquePtr<VkImageHandle>&& aVkImageHandle, const uint32_t aWidth, 34 const uint32_t aHeight, const struct ffi::WGPUTextureFormat aFormat, 35 const ffi::WGPUTextureUsages aUsage, RefPtr<DMABufSurface>&& aSurface, 36 const layers::SurfaceDescriptorDMABuf& aSurfaceDescriptor); 37 virtual ~SharedTextureDMABuf(); 38 39 Maybe<layers::SurfaceDescriptor> ToSurfaceDescriptor() override; 40 41 void GetSnapshot(const ipc::Shmem& aDestShmem, 42 const gfx::IntSize& aSize) override; 43 44 SharedTextureDMABuf* AsSharedTextureDMABuf() override { return this; } 45 46 void onBeforeQueueSubmit(RawId aQueueId) override; 47 48 void CleanForRecycling() override; 49 50 UniqueFileHandle CloneDmaBufFd(); 51 52 const ffi::WGPUVkImageHandle* GetHandle(); 53 54 protected: 55 const WeakPtr<WebGPUParent> mParent; 56 const RawId mDeviceId; 57 UniquePtr<VkImageHandle> mVkImageHandle; 58 nsTArray<UniquePtr<VkSemaphoreHandle>> mVkSemaphoreHandles; 59 RefPtr<DMABufSurface> mSurface; 60 const layers::SurfaceDescriptorDMABuf mSurfaceDescriptor; 61 nsTArray<RefPtr<gfx::FileHandleWrapper>> mSemaphoreFds; 62 }; 63 64 } // namespace webgpu 65 } // namespace mozilla 66 67 #endif // GPU_Texture_H_