From 17be9deed677037159e938c06b535d2d8d63d38b Mon Sep 17 00:00:00 2001 From: Kai Ninomiya Date: Mon, 7 Jan 2019 19:54:36 +0000 Subject: [PATCH] Fix samples on null backend (add swapchain impl) BUG= Change-Id: I96e6c58b4ec46af58f7c0a97c88308075efe68dd Reviewed-on: https://dawn-review.googlesource.com/c/3700 Commit-Queue: Kai Ninomiya Reviewed-by: Corentin Wallez --- src/dawn_native/null/NullBackend.cpp | 32 +++++++++++++++++++++++++++ src/include/dawn_native/NullBackend.h | 2 ++ src/utils/NullBinding.cpp | 8 ++++++- 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/dawn_native/null/NullBackend.cpp b/src/dawn_native/null/NullBackend.cpp index 196f8dec51..3cd5a4125a 100644 --- a/src/dawn_native/null/NullBackend.cpp +++ b/src/dawn_native/null/NullBackend.cpp @@ -14,6 +14,7 @@ #include "dawn_native/null/NullBackend.h" +#include "common/SwapChainUtils.h" #include "dawn_native/BackendConnection.h" #include "dawn_native/Commands.h" #include "dawn_native/NullBackend.h" @@ -261,4 +262,35 @@ namespace dawn_native { namespace null { void SwapChain::OnBeforePresent(TextureBase*) { } + // CreateNativeSwapChainImpl + + class NativeSwapChainImpl { + public: + using WSIContext = struct {}; + void Init(WSIContext* context) { + } + dawnSwapChainError Configure(dawnTextureFormat format, + dawnTextureUsageBit, + uint32_t width, + uint32_t height) { + return DAWN_SWAP_CHAIN_NO_ERROR; + } + dawnSwapChainError GetNextTexture(dawnSwapChainNextTexture* nextTexture) { + return DAWN_SWAP_CHAIN_NO_ERROR; + } + dawnSwapChainError Present() { + return DAWN_SWAP_CHAIN_NO_ERROR; + } + dawn::TextureFormat GetPreferredFormat() const { + return dawn::TextureFormat::R8G8B8A8Unorm; + } + }; + + DAWN_NATIVE_EXPORT dawnSwapChainImplementation CreateNativeSwapChainImpl() { + dawnSwapChainImplementation impl; + impl = CreateSwapChainImplementation(new NativeSwapChainImpl()); + impl.textureUsage = DAWN_TEXTURE_USAGE_BIT_PRESENT; + return impl; + } + }} // namespace dawn_native::null diff --git a/src/include/dawn_native/NullBackend.h b/src/include/dawn_native/NullBackend.h index be7c3e715e..21fe1d039e 100644 --- a/src/include/dawn_native/NullBackend.h +++ b/src/include/dawn_native/NullBackend.h @@ -16,10 +16,12 @@ #define DAWNNATIVE_NULLBACKEND_H_ #include +#include #include namespace dawn_native { namespace null { DAWN_NATIVE_EXPORT dawnDevice CreateDevice(); + DAWN_NATIVE_EXPORT dawnSwapChainImplementation CreateNativeSwapChainImpl(); }} // namespace dawn_native::null #endif // DAWNNATIVE_NULLBACKEND_H_ diff --git a/src/utils/NullBinding.cpp b/src/utils/NullBinding.cpp index 558531e33c..1620dd21cf 100644 --- a/src/utils/NullBinding.cpp +++ b/src/utils/NullBinding.cpp @@ -26,11 +26,17 @@ namespace utils { return dawn_native::null::CreateDevice(); } uint64_t GetSwapChainImplementation() override { - return 0; + if (mSwapchainImpl.userData == nullptr) { + mSwapchainImpl = dawn_native::null::CreateNativeSwapChainImpl(); + } + return reinterpret_cast(&mSwapchainImpl); } dawnTextureFormat GetPreferredSwapChainTextureFormat() override { return DAWN_TEXTURE_FORMAT_R8_G8_B8_A8_UNORM; } + + private: + dawnSwapChainImplementation mSwapchainImpl = {}; }; BackendBinding* CreateNullBinding() {