diff --git a/BUILD.gn b/BUILD.gn index 263313de1e..0a87f3c3ce 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -2314,6 +2314,10 @@ if (skia_enable_tools) { ] libs = [] + if (skia_use_dawn) { + sources += [ "tools/sk_app/DawnWindowContext.cpp" ] + } + if (is_android) { sources += [ "tools/sk_app/android/GLWindowContext_android.cpp", @@ -2331,6 +2335,13 @@ if (skia_enable_tools) { "tools/sk_app/unix/keysym2ucs.c", "tools/sk_app/unix/main_unix.cpp", ] + if (skia_use_dawn) { + if (dawn_enable_vulkan) { + sources += [ "tools/sk_app/unix/DawnVulkanWindowContext_unix.cpp" ] + defines = [ "VK_USE_PLATFORM_XCB_KHR" ] + libs += [ "X11-xcb" ] + } + } libs += [ "GL", "X11", @@ -2345,6 +2356,11 @@ if (skia_enable_tools) { if (skia_use_angle) { sources += [ "tools/sk_app/win/ANGLEWindowContext_win.cpp" ] } + if (skia_use_dawn) { + if (dawn_enable_d3d12) { + sources += [ "tools/sk_app/win/DawnD3D12WindowContext_win.cpp" ] + } + } } else if (is_mac) { sources += [ "tools/sk_app/mac/GLWindowContext_mac.mm", @@ -2352,6 +2368,11 @@ if (skia_enable_tools) { "tools/sk_app/mac/Window_mac.mm", "tools/sk_app/mac/main_mac.mm", ] + if (skia_use_dawn) { + if (dawn_enable_metal) { + sources += [ "tools/sk_app/mac/DawnMTLWindowContext_mac.mm" ] + } + } libs += [ "QuartzCore.framework", "Cocoa.framework", diff --git a/tools/sk_app/DawnWindowContext.cpp b/tools/sk_app/DawnWindowContext.cpp new file mode 100644 index 0000000000..cae8196090 --- /dev/null +++ b/tools/sk_app/DawnWindowContext.cpp @@ -0,0 +1,122 @@ +/* + * Copyright 2019 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "include/core/SkSurface.h" +#include "include/gpu/GrBackendSurface.h" +#include "include/gpu/GrContext.h" +#include "src/core/SkAutoMalloc.h" +#include "tools/sk_app/DawnWindowContext.h" + +static void PrintDeviceError(const char* message, void*) { + printf("Device error: %s\n", message); + SkASSERT(false); +} + +namespace sk_app { + +DawnWindowContext::DawnWindowContext(const DisplayParams& params, + dawn::TextureFormat swapChainFormat) + : WindowContext(params) + , fSwapChainFormat(swapChainFormat) + , fInstance(std::make_unique()) { +} + +void DawnWindowContext::initializeContext(int width, int height) { + fWidth = width; + fHeight = height; + fDevice = onInitializeContext(); + fContext = GrContext::MakeDawn(fDevice, fDisplayParams.fGrContextOptions); + + if (!fContext) { + return; + } + fSwapChainImplementation = this->createSwapChainImplementation(-1, -1, fDisplayParams); + dawn::SwapChainDescriptor swapChainDesc; + swapChainDesc.implementation = reinterpret_cast(&fSwapChainImplementation); + fSwapChain = fDevice.CreateSwapChain(&swapChainDesc); + if (!fSwapChain) { + fContext.reset(); + return; + } + fSwapChain.Configure(fSwapChainFormat, dawn::TextureUsageBit::OutputAttachment, width, height); + fDevice.SetErrorCallback(PrintDeviceError, 0); +} + +DawnWindowContext::~DawnWindowContext() { +} + +void DawnWindowContext::destroyContext() { + if (!fDevice.Get()) { + return; + } + + this->onDestroyContext(); + + fContext.reset(); + fDevice = nullptr; +} + +sk_sp DawnWindowContext::getBackbufferSurface() { + GrDawnImageInfo imageInfo; + imageInfo.fTexture = fSwapChain.GetNextTexture(); + imageInfo.fFormat = fSwapChainFormat; + imageInfo.fLevelCount = 1; // FIXME + GrBackendTexture backendTexture(fWidth, fHeight, imageInfo); + fSurface = SkSurface::MakeFromBackendTextureAsRenderTarget(fContext.get(), + backendTexture, + this->getRTOrigin(), + fDisplayParams.fMSAASampleCount, + fDisplayParams.fColorType, + fDisplayParams.fColorSpace, + &fDisplayParams.fSurfaceProps); + return fSurface; +} + +void DawnWindowContext::swapBuffers() { + GrBackendRenderTarget backendRT = fSurface->getBackendRenderTarget( + SkSurface::kFlushRead_BackendHandleAccess); + GrDawnImageInfo imageInfo; + SkAssertResult(backendRT.getDawnImageInfo(&imageInfo)); + + fSwapChain.Present(imageInfo.fTexture); + this->onSwapBuffers(); +} + +void DawnWindowContext::resize(int w, int h) { + fWidth = w; + fHeight = h; + fSwapChainImplementation = this->createSwapChainImplementation(w, h, fDisplayParams); + dawn::SwapChainDescriptor swapChainDesc; + swapChainDesc.implementation = reinterpret_cast(&fSwapChainImplementation); + fSwapChain = fDevice.CreateSwapChain(&swapChainDesc); + if (!fSwapChain) { + fContext.reset(); + return; + } + fSwapChain.Configure(fSwapChainFormat, dawn::TextureUsageBit::OutputAttachment, fWidth, + fHeight); +} + +void DawnWindowContext::setDisplayParams(const DisplayParams& params) { + fDisplayParams = params; +} + +dawn::Device DawnWindowContext::createDevice(dawn_native::BackendType type) { + fInstance->DiscoverDefaultAdapters(); + DawnProcTable backendProcs = dawn_native::GetProcs(); + dawnSetProcs(&backendProcs); + + std::vector adapters = fInstance->GetAdapters(); + for (dawn_native::Adapter adapter : adapters) { + if (adapter.GetBackendType() == type) { + return adapter.CreateDevice(); + } + } + return nullptr; +} + +} //namespace sk_app diff --git a/tools/sk_app/DawnWindowContext.h b/tools/sk_app/DawnWindowContext.h new file mode 100644 index 0000000000..6c2e1c9d7d --- /dev/null +++ b/tools/sk_app/DawnWindowContext.h @@ -0,0 +1,56 @@ +/* + * Copyright 2019 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ +#ifndef DawnWindowContext_DEFINED +#define DawnWindowContext_DEFINED + +#include "include/core/SkRefCnt.h" +#include "include/core/SkSurface.h" + +#include "tools/sk_app/WindowContext.h" +#include "dawn/dawncpp.h" +#include "dawn_native/DawnNative.h" +#include "dawn/dawn_wsi.h" + +class GrContext; + +namespace sk_app { + +class DawnWindowContext : public WindowContext { +public: + DawnWindowContext(const DisplayParams&, dawn::TextureFormat swapChainFormat); + ~DawnWindowContext() override; + sk_sp getBackbufferSurface() override; + void swapBuffers() override; + bool isValid() override { return SkToBool(fDevice.Get()); } + + void resize(int w, int h) override; + + void setDisplayParams(const DisplayParams& params) override; + +protected: + bool isGpuContext() override { return true; } + void initializeContext(int width, int height); + dawn::Device createDevice(dawn_native::BackendType type); + virtual dawn::Device onInitializeContext() = 0; + virtual void onDestroyContext() = 0; + virtual void onSwapBuffers() = 0; + virtual GrSurfaceOrigin getRTOrigin() const { return kTopLeft_GrSurfaceOrigin; } + void destroyContext(); + virtual DawnSwapChainImplementation createSwapChainImplementation( int width, int height, + const DisplayParams& params) = 0; + + sk_sp fSurface; + DawnSwapChainImplementation fSwapChainImplementation; + dawn::TextureFormat fSwapChainFormat; + dawn::SwapChain fSwapChain; + dawn::Device fDevice; + std::unique_ptr fInstance; +}; + +} // namespace sk_app + +#endif diff --git a/tools/sk_app/Window.h b/tools/sk_app/Window.h index a468738ec3..38a1cc0c23 100644 --- a/tools/sk_app/Window.h +++ b/tools/sk_app/Window.h @@ -48,6 +48,9 @@ public: #if SK_ANGLE && defined(SK_BUILD_FOR_WIN) kANGLE_BackendType, #endif +#ifdef SK_DAWN + kDawn_BackendType, +#endif #ifdef SK_VULKAN kVulkan_BackendType, #endif diff --git a/tools/sk_app/mac/DawnMTLWindowContext_mac.mm b/tools/sk_app/mac/DawnMTLWindowContext_mac.mm new file mode 100644 index 0000000000..1d12506006 --- /dev/null +++ b/tools/sk_app/mac/DawnMTLWindowContext_mac.mm @@ -0,0 +1,146 @@ +/* + * Copyright 2019 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "tools/sk_app/DawnWindowContext.h" +#include "tools/sk_app/mac/WindowContextFactory_mac.h" +#include "common/SwapChainUtils.h" +#include "dawn/dawncpp.h" +#include "dawn/dawn_wsi.h" +#include "dawn_native/DawnNative.h" +#include "dawn_native/MetalBackend.h" + +#import +#import +#import + +namespace sk_app { + +using sk_app::window_context_factory::MacWindowInfo; + +class DawnMTLWindowContext : public DawnWindowContext { +public: + DawnMTLWindowContext(const MacWindowInfo& info, const DisplayParams& params); + ~DawnMTLWindowContext() override; + dawn::Device onInitializeContext() override; + void onDestroyContext() override; + DawnSwapChainImplementation createSwapChainImplementation(int width, int height, + const DisplayParams& params) override; + void onSwapBuffers() override; +private: + NSView* fMainView; + id fMTLDevice; + CAMetalLayer* fLayer; +}; + +class SwapChainImplMTL { +public: + typedef void WSIContext; + static DawnSwapChainImplementation Create(id device, CAMetalLayer* layer) { + auto impl = new SwapChainImplMTL(device, layer); + return CreateSwapChainImplementation(impl); + } + + void Init(WSIContext* ctx) {} + + SwapChainImplMTL(id device, CAMetalLayer* layer) + : fQueue([device newCommandQueue]) + , fLayer(layer) {} + + ~SwapChainImplMTL() {} + + DawnSwapChainError Configure(DawnTextureFormat format, DawnTextureUsageBit, + uint32_t width, uint32_t height) { + if (format != DAWN_TEXTURE_FORMAT_RGBA8_UNORM) { + return "unsupported format"; + } + SkASSERT(width > 0); + SkASSERT(height > 0); + + return DAWN_SWAP_CHAIN_NO_ERROR; + } + + DawnSwapChainError GetNextTexture(DawnSwapChainNextTexture* nextTexture) { + fCurrentDrawable = [fLayer nextDrawable]; + + nextTexture->texture.ptr = reinterpret_cast(fCurrentDrawable.texture); + + return DAWN_SWAP_CHAIN_NO_ERROR; + } + + DawnSwapChainError Present() { + id commandBuffer = [fQueue commandBuffer]; + [commandBuffer presentDrawable: fCurrentDrawable]; + [commandBuffer commit]; + return DAWN_SWAP_CHAIN_NO_ERROR; + } +private: + id fQueue; + CAMetalLayer* fLayer; + id fCurrentDrawable = nil; +}; + +DawnMTLWindowContext::DawnMTLWindowContext(const MacWindowInfo& info, const DisplayParams& params) + : DawnWindowContext(params, dawn::TextureFormat::BGRA8Unorm) + , fMainView(info.fMainView) { + CGSize size = fMainView.bounds.size; + this->initializeContext(size.width, size.height); +} + +DawnMTLWindowContext::~DawnMTLWindowContext() { + this->destroyContext(); +} + +DawnSwapChainImplementation DawnMTLWindowContext::createSwapChainImplementation( + int width, int height, const DisplayParams& params) { + return SwapChainImplMTL::Create(fMTLDevice, fLayer); +} + +dawn::Device DawnMTLWindowContext::onInitializeContext() { + dawn::Device device = this->createDevice(dawn_native::BackendType::Metal); + if (!device) { + return nullptr; + } + + fMTLDevice = dawn_native::metal::GetMetalDevice(device.Get()); + + CGSize size; + size.width = width(); + size.height = height(); + + fLayer = [CAMetalLayer layer]; + [fLayer setDevice:fMTLDevice]; + [fLayer setPixelFormat: MTLPixelFormatBGRA8Unorm]; + [fLayer setFramebufferOnly: YES]; + [fLayer setDrawableSize: size]; + [fLayer setColorspace: CGColorSpaceCreateDeviceRGB()]; + + [fMainView setWantsLayer: YES]; + [fMainView setLayer: fLayer]; + + return device; +} + +void DawnMTLWindowContext::onDestroyContext() { +} + +void DawnMTLWindowContext::onSwapBuffers() { +} + +namespace window_context_factory { + +std::unique_ptr MakeDawnMTLForMac(const MacWindowInfo& winInfo, + const DisplayParams& params) { + std::unique_ptr ctx(new DawnMTLWindowContext(winInfo, params)); + if (!ctx->isValid()) { + return nullptr; + } + return ctx; +} + +} + +} //namespace sk_app diff --git a/tools/sk_app/mac/WindowContextFactory_mac.h b/tools/sk_app/mac/WindowContextFactory_mac.h index 59aac577bf..683329745f 100644 --- a/tools/sk_app/mac/WindowContextFactory_mac.h +++ b/tools/sk_app/mac/WindowContextFactory_mac.h @@ -36,6 +36,10 @@ inline std::unique_ptr MakeVulkanForMac(const MacWindowInfo&, con std::unique_ptr MakeGLForMac(const MacWindowInfo&, const DisplayParams&); +#ifdef SK_DAWN +std::unique_ptr MakeDawnMTLForMac(const MacWindowInfo&, const DisplayParams&); +#endif + std::unique_ptr MakeRasterForMac(const MacWindowInfo&, const DisplayParams&); #ifdef SK_METAL std::unique_ptr MakeMetalForMac(const MacWindowInfo&, const DisplayParams&); diff --git a/tools/sk_app/mac/Window_mac.mm b/tools/sk_app/mac/Window_mac.mm index 31decafdbb..8ccaaf89f3 100644 --- a/tools/sk_app/mac/Window_mac.mm +++ b/tools/sk_app/mac/Window_mac.mm @@ -122,6 +122,11 @@ bool Window_mac::attach(BackendType attachType) { case kRaster_BackendType: fWindowContext = MakeRasterForMac(info, fRequestedDisplayParams); break; +#ifdef SK_DAWN + case kDawn_BackendType: + fWindowContext = MakeDawnMTLForMac(info, fRequestedDisplayParams); + break; +#endif #ifdef SK_VULKAN case kVulkan_BackendType: fWindowContext = MakeVulkanForMac(info, fRequestedDisplayParams); diff --git a/tools/sk_app/unix/DawnVulkanWindowContext_unix.cpp b/tools/sk_app/unix/DawnVulkanWindowContext_unix.cpp new file mode 100644 index 0000000000..b8eee27525 --- /dev/null +++ b/tools/sk_app/unix/DawnVulkanWindowContext_unix.cpp @@ -0,0 +1,107 @@ +/* + * Copyright 2019 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "tools/sk_app/DawnWindowContext.h" +#include "tools/sk_app/unix/WindowContextFactory_unix.h" +#include "dawn_native/DawnNative.h" +#include "dawn_native/VulkanBackend.h" +#include "src/ports/SkOSLibrary.h" +#include "tools/gpu/vk/VkTestUtils.h" + +#include +#include + +using sk_app::window_context_factory::XlibWindowInfo; +using sk_app::DisplayParams; +using sk_app::DawnWindowContext; + +namespace sk_app { + +class DawnVulkanWindowContext_xlib : public DawnWindowContext { +public: + DawnVulkanWindowContext_xlib(const XlibWindowInfo&, const DisplayParams&); + ~DawnVulkanWindowContext_xlib() override {} + dawn::Device onInitializeContext() override; + void onDestroyContext() override {} + DawnSwapChainImplementation createSwapChainImplementation( + int width, int height, const DisplayParams& params) override; + void onSwapBuffers() override {} + +private: + Display* fDisplay; + XWindow fWindow; + VkSurfaceKHR fVkSurface = nullptr; + + typedef DawnWindowContext INHERITED; +}; + +DawnVulkanWindowContext_xlib::DawnVulkanWindowContext_xlib(const XlibWindowInfo& winInfo, + const DisplayParams& params) + : INHERITED(params, dawn::TextureFormat::BGRA8Unorm) + , fDisplay(winInfo.fDisplay) + , fWindow(winInfo.fWindow) { + XWindow root; + int x, y; + unsigned int border_width, depth; + unsigned int width, height; + XGetGeometry(fDisplay, fWindow, &root, &x, &y, &width, &height, &border_width, &depth); + this->initializeContext(width, height); +} + +DawnSwapChainImplementation DawnVulkanWindowContext_xlib::createSwapChainImplementation( + int width, int height, const DisplayParams& params) { + return dawn_native::vulkan::CreateNativeSwapChainImpl(fDevice.Get(), fVkSurface); +} + +dawn::Device DawnVulkanWindowContext_xlib::onInitializeContext() { + dawn::Device device = this->createDevice(dawn_native::BackendType::Vulkan); + if (!device) { + return nullptr; + } + + void *vkLib = DynamicLoadLibrary("libvulkan.so.1"); + if (!vkLib) { + return nullptr; + } + VkInstance instance = dawn_native::vulkan::GetInstance(device.Get()); + if (!instance) { + return nullptr; + } + auto createXcbSurfaceKHR = + reinterpret_cast(GetProcedureAddress(vkLib, + "vkCreateXcbSurfaceKHR")); + if (!createXcbSurfaceKHR) { + printf("couldn't get extensions :(\n"); + return nullptr; + } + + VkXcbSurfaceCreateInfoKHR surfaceCreateInfo; + memset(&surfaceCreateInfo, 0, sizeof(VkXcbSurfaceCreateInfoKHR)); + surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR; + surfaceCreateInfo.pNext = nullptr; + surfaceCreateInfo.flags = 0; + surfaceCreateInfo.connection = XGetXCBConnection(fDisplay); + surfaceCreateInfo.window = fWindow; + + createXcbSurfaceKHR(instance, &surfaceCreateInfo, nullptr, &fVkSurface); + return device; +} + +namespace window_context_factory { + +std::unique_ptr MakeDawnVulkanForXlib(const XlibWindowInfo& winInfo, + const DisplayParams& params) { + std::unique_ptr ctx(new DawnVulkanWindowContext_xlib(winInfo, params)); + if (!ctx->isValid()) { + return nullptr; + } + return ctx; +} + +} + +} // namespace sk_app diff --git a/tools/sk_app/unix/WindowContextFactory_unix.h b/tools/sk_app/unix/WindowContextFactory_unix.h index 1995e89bc3..47310970d5 100644 --- a/tools/sk_app/unix/WindowContextFactory_unix.h +++ b/tools/sk_app/unix/WindowContextFactory_unix.h @@ -40,6 +40,10 @@ std::unique_ptr MakeVulkanForXlib(const XlibWindowInfo&, const Di std::unique_ptr MakeGLForXlib(const XlibWindowInfo&, const DisplayParams&); +#ifdef SK_DAWN +std::unique_ptr MakeDawnVulkanForXlib(const XlibWindowInfo&, const DisplayParams&); +#endif + std::unique_ptr MakeRasterForXlib(const XlibWindowInfo&, const DisplayParams&); } // namespace window_context_factory diff --git a/tools/sk_app/unix/Window_unix.cpp b/tools/sk_app/unix/Window_unix.cpp index fd74722897..5b5eaa566d 100644 --- a/tools/sk_app/unix/Window_unix.cpp +++ b/tools/sk_app/unix/Window_unix.cpp @@ -358,6 +358,12 @@ bool Window_unix::attach(BackendType attachType) { } switch (attachType) { +#ifdef SK_DAWN + case kDawn_BackendType: + fWindowContext = + window_context_factory::MakeDawnVulkanForXlib(winInfo, fRequestedDisplayParams); + break; +#endif #ifdef SK_VULKAN case kVulkan_BackendType: fWindowContext = diff --git a/tools/sk_app/win/DawnD3D12WindowContext_win.cpp b/tools/sk_app/win/DawnD3D12WindowContext_win.cpp new file mode 100644 index 0000000000..b5e8599045 --- /dev/null +++ b/tools/sk_app/win/DawnD3D12WindowContext_win.cpp @@ -0,0 +1,72 @@ +/* + * Copyright 2019 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "tools/sk_app/DawnWindowContext.h" +#include "tools/sk_app/win/WindowContextFactory_win.h" +#include "dawn/dawncpp.h" +#include "dawn/dawn_wsi.h" +#include "dawn_native/DawnNative.h" +#include "dawn_native/D3D12Backend.h" +#include "common/SwapChainUtils.h" + +namespace sk_app { + +class DawnD3D12WindowContext : public DawnWindowContext { +public: + DawnD3D12WindowContext(HWND hwnd, const DisplayParams& params); + virtual ~DawnD3D12WindowContext(); + dawn::Device onInitializeContext() override; + void onDestroyContext() override; + DawnSwapChainImplementation createSwapChainImplementation( + int width, int height, const DisplayParams& params) override; + void onSwapBuffers() override; +private: + HWND fWindow; +}; + +// NOTE: this texture format must match the one in D3D12's swap chain impl +DawnD3D12WindowContext::DawnD3D12WindowContext(HWND hwnd, const DisplayParams& params) + : DawnWindowContext(params, dawn::TextureFormat::RGBA8Unorm) + , fWindow(hwnd) { + RECT rect; + GetClientRect(hwnd, &rect); + this->initializeContext(rect.right - rect.left, rect.bottom - rect.top); +} + +DawnD3D12WindowContext::~DawnD3D12WindowContext() { + this->destroyContext(); +} + +DawnSwapChainImplementation DawnD3D12WindowContext::createSwapChainImplementation( + int width, int height, const DisplayParams& params) { + return dawn_native::d3d12::CreateNativeSwapChainImpl(fDevice.Get(), fWindow); +} + +dawn::Device DawnD3D12WindowContext::onInitializeContext() { + return this->createDevice(dawn_native::BackendType::D3D12); +} + +void DawnD3D12WindowContext::onDestroyContext() { +} + +void DawnD3D12WindowContext::onSwapBuffers() { +} + +namespace window_context_factory { + +std::unique_ptr MakeDawnD3D12ForWin(HWND hwnd, + const DisplayParams& params) { + std::unique_ptr ctx(new DawnD3D12WindowContext(hwnd, params)); + if (!ctx->isValid()) { + return nullptr; + } + return ctx; +} + +} + +} //namespace sk_app diff --git a/tools/sk_app/win/WindowContextFactory_win.h b/tools/sk_app/win/WindowContextFactory_win.h index 828e26b4b4..33dd6d413b 100644 --- a/tools/sk_app/win/WindowContextFactory_win.h +++ b/tools/sk_app/win/WindowContextFactory_win.h @@ -26,6 +26,10 @@ std::unique_ptr MakeGLForWin(HWND, const DisplayParams&); std::unique_ptr MakeANGLEForWin(HWND, const DisplayParams&); +#ifdef SK_DAWN +std::unique_ptr MakeDawnD3D12ForWin(HWND, const DisplayParams&); +#endif + std::unique_ptr MakeRasterForWin(HWND, const DisplayParams&); } // namespace window_context_factory diff --git a/tools/sk_app/win/Window_win.cpp b/tools/sk_app/win/Window_win.cpp index 999effe9c8..627ccdcf51 100644 --- a/tools/sk_app/win/Window_win.cpp +++ b/tools/sk_app/win/Window_win.cpp @@ -358,6 +358,12 @@ bool Window_win::attach(BackendType attachType) { fWindowContext = window_context_factory::MakeANGLEForWin(fHWnd, fRequestedDisplayParams); break; +#endif +#ifdef SK_DAWN + case kDawn_BackendType: + fWindowContext = + window_context_factory::MakeDawnD3D12ForWin(fHWnd, fRequestedDisplayParams); + break; #endif case kRaster_BackendType: fWindowContext = diff --git a/tools/viewer/Viewer.cpp b/tools/viewer/Viewer.cpp index ef26b8df9e..1189703b32 100644 --- a/tools/viewer/Viewer.cpp +++ b/tools/viewer/Viewer.cpp @@ -81,10 +81,12 @@ Application* Application::Create(int argc, char** argv, void* platformData) { static DEFINE_string(slide, "", "Start on this sample."); static DEFINE_bool(list, false, "List samples?"); -#ifdef SK_VULKAN +#if defined(SK_VULKAN) # define BACKENDS_STR "\"sw\", \"gl\", and \"vk\"" #elif defined(SK_METAL) && defined(SK_BUILD_FOR_MAC) # define BACKENDS_STR "\"sw\", \"gl\", and \"mtl\"" +#elif defined(SK_DAWN) +# define BACKENDS_STR "\"sw\", \"gl\", and \"dawn\"" #else # define BACKENDS_STR "\"sw\" and \"gl\"" #endif @@ -133,6 +135,9 @@ const char* kBackendTypeStrings[sk_app::Window::kBackendTypeCount] = { #if SK_ANGLE && defined(SK_BUILD_FOR_WIN) "ANGLE", #endif +#ifdef SK_DAWN + "Dawn", +#endif #ifdef SK_VULKAN "Vulkan", #endif @@ -143,6 +148,11 @@ const char* kBackendTypeStrings[sk_app::Window::kBackendTypeCount] = { }; static sk_app::Window::BackendType get_backend_type(const char* str) { +#ifdef SK_DAWN + if (0 == strcmp(str, "dawn")) { + return sk_app::Window::kDawn_BackendType; + } else +#endif #ifdef SK_VULKAN if (0 == strcmp(str, "vk")) { return sk_app::Window::kVulkan_BackendType; @@ -1520,6 +1530,10 @@ void Viewer::drawImGui() { ImGui::SameLine(); ImGui::RadioButton("ANGLE", &newBackend, sk_app::Window::kANGLE_BackendType); #endif +#if defined(SK_DAWN) + ImGui::SameLine(); + ImGui::RadioButton("Dawn", &newBackend, sk_app::Window::kDawn_BackendType); +#endif #if defined(SK_VULKAN) ImGui::SameLine(); ImGui::RadioButton("Vulkan", &newBackend, sk_app::Window::kVulkan_BackendType);