From e7a5fabf48243c3776a58e3f2d8327389a27e08f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E4=BF=8A=E5=98=89?= Date: Thu, 6 May 2021 08:28:44 +0000 Subject: [PATCH] Remove unnecessary "#if def"s and type conversion in windows compilation. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove unnecessary "#if def"s. Forward declare IUnknown in Surface.h. Change Surface.GetCoreWindow's return type to IUnknown*. Remove unnecessary type conversion in SwapChainD3D12.cpp. Bug: dawn:766 Change-Id: Id9f4ae20a5ed52fe8338d4e1673588c828c4c5df Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/50080 Commit-Queue: 陈俊嘉 Commit-Queue: Corentin Wallez Reviewed-by: Corentin Wallez --- src/dawn_native/Surface.cpp | 4 +--- src/dawn_native/Surface.h | 7 ++++++- src/dawn_native/d3d12/SwapChainD3D12.cpp | 12 +++++------- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/dawn_native/Surface.cpp b/src/dawn_native/Surface.cpp index 3a68832c28..d78f3f3cf3 100644 --- a/src/dawn_native/Surface.cpp +++ b/src/dawn_native/Surface.cpp @@ -124,11 +124,9 @@ namespace dawn_native { mType = Type::MetalLayer; mMetalLayer = metalDesc->layer; } else if (hwndDesc) { -#if defined(DAWN_PLATFORM_WIN32) mType = Type::WindowsHWND; mHInstance = hwndDesc->hinstance; mHWND = hwndDesc->hwnd; -#endif // defined(DAWN_PLATFORM_WIN32) } else if (coreWindowDesc) { #if defined(DAWN_PLATFORM_WINDOWS) mType = Type::WindowsCoreWindow; @@ -180,7 +178,7 @@ namespace dawn_native { return mHWND; } - void* Surface::GetCoreWindow() const { + IUnknown* Surface::GetCoreWindow() const { ASSERT(mType == Type::WindowsCoreWindow); #if defined(DAWN_PLATFORM_WINDOWS) return mCoreWindow.Get(); diff --git a/src/dawn_native/Surface.h b/src/dawn_native/Surface.h index 2871bbb1ab..bdab2b45bc 100644 --- a/src/dawn_native/Surface.h +++ b/src/dawn_native/Surface.h @@ -27,6 +27,11 @@ # include "dawn_native/d3d12/d3d12_platform.h" #endif // defined(DAWN_PLATFORM_WINDOWS) +// Forward declare IUnknown +// GetCoreWindow needs to return an IUnknown pointer +// non-windows platforms don't have this type +struct IUnknown; + namespace dawn_native { MaybeError ValidateSurfaceDescriptor(const InstanceBase* instance, @@ -57,7 +62,7 @@ namespace dawn_native { void* GetHWND() const; // Valid to call if the type is WindowsCoreWindow - void* GetCoreWindow() const; + IUnknown* GetCoreWindow() const; // Valid to call if the type is WindowsXlib void* GetXDisplay() const; diff --git a/src/dawn_native/d3d12/SwapChainD3D12.cpp b/src/dawn_native/d3d12/SwapChainD3D12.cpp index 166551338c..9002cc4c2d 100644 --- a/src/dawn_native/d3d12/SwapChainD3D12.cpp +++ b/src/dawn_native/d3d12/SwapChainD3D12.cpp @@ -245,7 +245,6 @@ namespace dawn_native { namespace d3d12 { ComPtr swapChain1; switch (GetSurface()->GetType()) { -#if defined(DAWN_PLATFORM_WIN32) case Surface::Type::WindowsHWND: { DAWN_TRY(CheckHRESULT( factory2->CreateSwapChainForHwnd(device->GetCommandQueue().Get(), @@ -254,13 +253,12 @@ namespace dawn_native { namespace d3d12 { "Creating the IDXGISwapChain1")); break; } -#endif // defined(DAWN_PLATFORM_WIN32) case Surface::Type::WindowsCoreWindow: { - DAWN_TRY(CheckHRESULT(factory2->CreateSwapChainForCoreWindow( - device->GetCommandQueue().Get(), - static_cast(GetSurface()->GetCoreWindow()), - &swapChainDesc, nullptr, &swapChain1), - "Creating the IDXGISwapChain1")); + DAWN_TRY(CheckHRESULT( + factory2->CreateSwapChainForCoreWindow(device->GetCommandQueue().Get(), + GetSurface()->GetCoreWindow(), + &swapChainDesc, nullptr, &swapChain1), + "Creating the IDXGISwapChain1")); break; } default: