SharedTexture.cpp (2703B)
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 #include "SharedTexture.h" 7 8 #include "mozilla/webgpu/WebGPUParent.h" 9 10 #ifdef XP_WIN 11 # include "mozilla/webgpu/SharedTextureD3D11.h" 12 #endif 13 14 #if defined(XP_LINUX) && !defined(MOZ_WIDGET_ANDROID) 15 # include "mozilla/webgpu/SharedTextureDMABuf.h" 16 #endif 17 18 #ifdef XP_MACOSX 19 # include "mozilla/webgpu/SharedTextureMacIOSurface.h" 20 #endif 21 22 namespace mozilla::webgpu { 23 24 // static 25 UniquePtr<SharedTexture> SharedTexture::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 MOZ_ASSERT(aParent); 31 32 UniquePtr<SharedTexture> texture; 33 #ifdef XP_WIN 34 texture = SharedTextureD3D11::Create(aParent, aDeviceId, aWidth, aHeight, 35 aFormat, aUsage); 36 #elif defined(XP_LINUX) && !defined(MOZ_WIDGET_ANDROID) 37 texture = SharedTextureDMABuf::Create(aParent, aDeviceId, aWidth, aHeight, 38 aFormat, aUsage); 39 #elif defined(XP_MACOSX) 40 texture = SharedTextureMacIOSurface::Create(aParent, aDeviceId, aWidth, 41 aHeight, aFormat, aUsage); 42 #endif 43 return texture; 44 } 45 46 SharedTexture::SharedTexture(const uint32_t aWidth, const uint32_t aHeight, 47 const struct ffi::WGPUTextureFormat aFormat, 48 const ffi::WGPUTextureUsages aUsage) 49 : mWidth(aWidth), mHeight(aHeight), mFormat(aFormat), mUsage(aUsage) {} 50 51 SharedTexture::~SharedTexture() {} 52 53 void SharedTexture::SetSubmissionIndex(uint64_t aSubmissionIndex) { 54 MOZ_ASSERT(aSubmissionIndex != 0); 55 56 mSubmissionIndex = aSubmissionIndex; 57 } 58 59 UniquePtr<SharedTextureReadBackPresent> SharedTextureReadBackPresent::Create( 60 const uint32_t aWidth, const uint32_t aHeight, 61 const struct ffi::WGPUTextureFormat aFormat, 62 const ffi::WGPUTextureUsages aUsage) { 63 return MakeUnique<SharedTextureReadBackPresent>(aWidth, aHeight, aFormat, 64 aUsage); 65 } 66 67 SharedTextureReadBackPresent::SharedTextureReadBackPresent( 68 const uint32_t aWidth, const uint32_t aHeight, 69 const struct ffi::WGPUTextureFormat aFormat, 70 const ffi::WGPUTextureUsages aUsage) 71 : SharedTexture(aWidth, aHeight, aFormat, aUsage) {} 72 73 SharedTextureReadBackPresent::~SharedTextureReadBackPresent() {} 74 75 } // namespace mozilla::webgpu