SharedTexture.h (3145B)
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 SharedTexture_H_ 7 #define SharedTexture_H_ 8 9 #include "mozilla/gfx/Point.h" 10 #include "mozilla/layers/LayersSurfaces.h" 11 #include "mozilla/webgpu/WebGPUTypes.h" 12 #include "mozilla/webgpu/ffi/wgpu.h" 13 14 namespace mozilla { 15 16 namespace ipc { 17 class Shmem; 18 } 19 20 namespace webgpu { 21 22 class SharedTextureD3D11; 23 class SharedTextureDMABuf; 24 class SharedTextureMacIOSurface; 25 class WebGPUParent; 26 27 // A texture is created and owned by Gecko but is shared with the WebGPU 28 // implementation. 29 class SharedTexture { 30 public: 31 static UniquePtr<SharedTexture> Create( 32 WebGPUParent* aParent, const ffi::WGPUDeviceId aDeviceId, 33 const uint32_t aWidth, const uint32_t aHeight, 34 const struct ffi::WGPUTextureFormat aFormat, 35 const ffi::WGPUTextureUsages aUsage); 36 37 SharedTexture(const uint32_t aWidth, const uint32_t aHeight, 38 const struct ffi::WGPUTextureFormat aFormat, 39 const ffi::WGPUTextureUsages aUsage); 40 virtual ~SharedTexture(); 41 42 virtual Maybe<layers::SurfaceDescriptor> ToSurfaceDescriptor() = 0; 43 44 virtual void GetSnapshot(const ipc::Shmem& aDestShmem, 45 const gfx::IntSize& aSize) {} 46 47 virtual SharedTextureDMABuf* AsSharedTextureDMABuf() { return nullptr; } 48 49 virtual SharedTextureMacIOSurface* AsSharedTextureMacIOSurface() { 50 return nullptr; 51 } 52 53 virtual SharedTextureD3D11* AsSharedTextureD3D11() { return nullptr; } 54 55 gfx::IntSize GetSize() { return gfx::IntSize(mWidth, mHeight); } 56 57 void SetSubmissionIndex(uint64_t aSubmissionIndex); 58 uint64_t GetSubmissionIndex() const { return mSubmissionIndex; } 59 60 void SetOwnerId(const layers::RemoteTextureOwnerId aOwnerId) { 61 mOwnerId = aOwnerId; 62 } 63 layers::RemoteTextureOwnerId GetOwnerId() const { 64 MOZ_ASSERT(mOwnerId.IsValid()); 65 return mOwnerId; 66 } 67 68 virtual void onBeforeQueueSubmit(RawId aQueueId) {} 69 70 virtual void CleanForRecycling() {} 71 72 const uint32_t mWidth; 73 const uint32_t mHeight; 74 const struct ffi::WGPUTextureFormat mFormat; 75 const ffi::WGPUTextureUsages mUsage; 76 77 protected: 78 uint64_t mSubmissionIndex = 0; 79 layers::RemoteTextureOwnerId mOwnerId; 80 }; 81 82 // Dummy class 83 class SharedTextureReadBackPresent final : public SharedTexture { 84 public: 85 static UniquePtr<SharedTextureReadBackPresent> Create( 86 const uint32_t aWidth, const uint32_t aHeight, 87 const struct ffi::WGPUTextureFormat aFormat, 88 const ffi::WGPUTextureUsages aUsage); 89 90 SharedTextureReadBackPresent(const uint32_t aWidth, const uint32_t aHeight, 91 const struct ffi::WGPUTextureFormat aFormat, 92 const ffi::WGPUTextureUsages aUsage); 93 virtual ~SharedTextureReadBackPresent(); 94 95 Maybe<layers::SurfaceDescriptor> ToSurfaceDescriptor() override { 96 return Nothing(); 97 } 98 }; 99 100 } // namespace webgpu 101 } // namespace mozilla 102 103 #endif // GPU_SharedTexture_H_