From a8d0d6c8bad00e713bc33e5f0d47ca4fec104433 Mon Sep 17 00:00:00 2001 From: jvanverth Date: Thu, 5 May 2016 12:32:03 -0700 Subject: [PATCH] More refactoring for Viewer * Move support files into sk_app and main files up to top directory * Rename VulkanTestContext and create WindowContext parent class * Place VulkanWindowContext et al. in sk_app namespace. GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1944413005 Review-Url: https://codereview.chromium.org/1944413005 --- tools/viewer/{viewer => }/GMSlide.cpp | 0 tools/viewer/{viewer => }/GMSlide.h | 0 tools/viewer/{viewer => }/SKPSlide.cpp | 0 tools/viewer/{viewer => }/SKPSlide.h | 0 tools/viewer/{viewer => }/Slide.h | 0 tools/viewer/{viewer => }/Viewer.cpp | 0 tools/viewer/{viewer => }/Viewer.h | 4 +- tools/viewer/{ => sk_app}/Application.h | 0 .../VulkanWindowContext.cpp} | 77 +++++++++++----------- .../VulkanWindowContext.h} | 40 ++++++----- tools/viewer/{ => sk_app}/Window.cpp | 12 ++-- tools/viewer/{ => sk_app}/Window.h | 5 +- tools/viewer/sk_app/WindowContext.h | 36 ++++++++++ .../android/VulkanWindowContext_android.cpp} | 10 ++- .../android/VulkanWindowContext_android.h} | 5 +- .../viewer/{ => sk_app}/android/Window_android.cpp | 4 +- tools/viewer/{ => sk_app}/android/Window_android.h | 0 tools/viewer/{ => sk_app}/android/main_android.cpp | 0 .../win/VulkanWindowContext_win.cpp} | 26 ++++---- .../win/VulkanWindowContext_win.h} | 6 +- tools/viewer/{ => sk_app}/win/Window_win.cpp | 6 +- tools/viewer/{ => sk_app}/win/Window_win.h | 0 tools/viewer/{ => sk_app}/win/main_win.cpp | 0 23 files changed, 146 insertions(+), 85 deletions(-) rename tools/viewer/{viewer => }/GMSlide.cpp (100%) rename tools/viewer/{viewer => }/GMSlide.h (100%) rename tools/viewer/{viewer => }/SKPSlide.cpp (100%) rename tools/viewer/{viewer => }/SKPSlide.h (100%) rename tools/viewer/{viewer => }/Slide.h (100%) rename tools/viewer/{viewer => }/Viewer.cpp (100%) rename tools/viewer/{viewer => }/Viewer.h (95%) rename tools/viewer/{ => sk_app}/Application.h (100%) rename tools/viewer/{VulkanTestContext.cpp => sk_app/VulkanWindowContext.cpp} (92%) rename tools/viewer/{VulkanTestContext.h => sk_app/VulkanWindowContext.h} (78%) rename tools/viewer/{ => sk_app}/Window.cpp (88%) rename tools/viewer/{ => sk_app}/Window.h (98%) create mode 100644 tools/viewer/sk_app/WindowContext.h rename tools/viewer/{android/VulkanTestContext_android.cpp => sk_app/android/VulkanWindowContext_android.cpp} (84%) rename tools/viewer/{android/VulkanTestContext_android.h => sk_app/android/VulkanWindowContext_android.h} (86%) rename tools/viewer/{ => sk_app}/android/Window_android.cpp (97%) rename tools/viewer/{ => sk_app}/android/Window_android.h (100%) rename tools/viewer/{ => sk_app}/android/main_android.cpp (100%) rename tools/viewer/{win/VulkanTestContext_win.cpp => sk_app/win/VulkanWindowContext_win.cpp} (62%) rename tools/viewer/{win/VulkanTestContext_win.h => sk_app/win/VulkanWindowContext_win.h} (86%) rename tools/viewer/{ => sk_app}/win/Window_win.cpp (98%) rename tools/viewer/{ => sk_app}/win/Window_win.h (100%) rename tools/viewer/{ => sk_app}/win/main_win.cpp (100%) diff --git a/tools/viewer/viewer/GMSlide.cpp b/tools/viewer/GMSlide.cpp similarity index 100% rename from tools/viewer/viewer/GMSlide.cpp rename to tools/viewer/GMSlide.cpp diff --git a/tools/viewer/viewer/GMSlide.h b/tools/viewer/GMSlide.h similarity index 100% rename from tools/viewer/viewer/GMSlide.h rename to tools/viewer/GMSlide.h diff --git a/tools/viewer/viewer/SKPSlide.cpp b/tools/viewer/SKPSlide.cpp similarity index 100% rename from tools/viewer/viewer/SKPSlide.cpp rename to tools/viewer/SKPSlide.cpp diff --git a/tools/viewer/viewer/SKPSlide.h b/tools/viewer/SKPSlide.h similarity index 100% rename from tools/viewer/viewer/SKPSlide.h rename to tools/viewer/SKPSlide.h diff --git a/tools/viewer/viewer/Slide.h b/tools/viewer/Slide.h similarity index 100% rename from tools/viewer/viewer/Slide.h rename to tools/viewer/Slide.h diff --git a/tools/viewer/viewer/Viewer.cpp b/tools/viewer/Viewer.cpp similarity index 100% rename from tools/viewer/viewer/Viewer.cpp rename to tools/viewer/Viewer.cpp diff --git a/tools/viewer/viewer/Viewer.h b/tools/viewer/Viewer.h similarity index 95% rename from tools/viewer/viewer/Viewer.h rename to tools/viewer/Viewer.h index 43d29ba..2ae7ae3 100644 --- a/tools/viewer/viewer/Viewer.h +++ b/tools/viewer/Viewer.h @@ -8,8 +8,8 @@ #ifndef Viewer_DEFINED #define Viewer_DEFINED -#include "../Application.h" -#include "../Window.h" +#include "sk_app/Application.h" +#include "sk_app/Window.h" #include "gm.h" #include "SkAnimTimer.h" #include "Slide.h" diff --git a/tools/viewer/Application.h b/tools/viewer/sk_app/Application.h similarity index 100% rename from tools/viewer/Application.h rename to tools/viewer/sk_app/Application.h diff --git a/tools/viewer/VulkanTestContext.cpp b/tools/viewer/sk_app/VulkanWindowContext.cpp similarity index 92% rename from tools/viewer/VulkanTestContext.cpp rename to tools/viewer/sk_app/VulkanWindowContext.cpp index e9137c0..8f5f420 100644 --- a/tools/viewer/VulkanTestContext.cpp +++ b/tools/viewer/sk_app/VulkanWindowContext.cpp @@ -8,7 +8,7 @@ #include "GrContext.h" #include "SkSurface.h" -#include "VulkanTestContext.h" +#include "VulkanWindowContext.h" #include "vk/GrVkInterface.h" #include "vk/GrVkUtil.h" @@ -22,18 +22,20 @@ #define GET_PROC(F) f ## F = (PFN_vk ## F) vkGetInstanceProcAddr(instance, "vk" #F) #define GET_DEV_PROC(F) f ## F = (PFN_vk ## F) vkGetDeviceProcAddr(device, "vk" #F) -VulkanTestContext::VulkanTestContext(void* platformData, int msaaSampleCount) - : fSurface(VK_NULL_HANDLE) - , fSwapchain(VK_NULL_HANDLE) - , fCommandPool(VK_NULL_HANDLE) - , fBackbuffers(nullptr) { +namespace sk_app { + +VulkanWindowContext::VulkanWindowContext(void* platformData, int msaaSampleCount) + : fSurface(VK_NULL_HANDLE) + , fSwapchain(VK_NULL_HANDLE) + , fCommandPool(VK_NULL_HANDLE) + , fBackbuffers(nullptr) { // any config code here (particularly for msaa)? this->initializeContext(platformData); } -void VulkanTestContext::initializeContext(void* platformData) { +void VulkanWindowContext::initializeContext(void* platformData) { fBackendContext.reset(GrVkBackendContext::Create(&fPresentQueueIndex, canPresent)); if (!(fBackendContext->fExtensions & kKHR_surface_GrVkExtensionFlag) || @@ -55,7 +57,7 @@ void VulkanTestContext::initializeContext(void* platformData) { GET_DEV_PROC(AcquireNextImageKHR); GET_DEV_PROC(QueuePresentKHR); - fContext = GrContext::Create(kVulkan_GrBackend, (GrBackendContext)fBackendContext.get()); + fContext = GrContext::Create(kVulkan_GrBackend, (GrBackendContext) fBackendContext.get()); fSurface = createVkSurface(instance, platformData); if (VK_NULL_HANDLE == fSurface) { @@ -81,8 +83,7 @@ void VulkanTestContext::initializeContext(void* platformData) { vkGetDeviceQueue(fBackendContext->fDevice, fPresentQueueIndex, 0, &fPresentQueue); } -bool VulkanTestContext::createSwapchain(uint32_t width, uint32_t height) -{ +bool VulkanWindowContext::createSwapchain(uint32_t width, uint32_t height) { // check for capabilities VkSurfaceCapabilitiesKHR caps; VkResult res = fGetPhysicalDeviceSurfaceCapabilitiesKHR(fBackendContext->fPhysicalDevice, @@ -116,7 +117,7 @@ bool VulkanTestContext::createSwapchain(uint32_t width, uint32_t height) SkAutoMalloc presentModeAlloc(presentModeCount * sizeof(VkPresentModeKHR)); VkPresentModeKHR* presentModes = (VkPresentModeKHR*)presentModeAlloc.get(); res = fGetPhysicalDeviceSurfacePresentModesKHR(fBackendContext->fPhysicalDevice, fSurface, - &presentModeCount, presentModes); + &presentModeCount, presentModes); if (VK_SUCCESS != res) { return false; } @@ -223,7 +224,7 @@ bool VulkanTestContext::createSwapchain(uint32_t width, uint32_t height) return true; } -void VulkanTestContext::createBuffers(VkFormat format) { +void VulkanWindowContext::createBuffers(VkFormat format) { GrVkFormatToPixelConfig(format, &fPixelConfig); fGetSwapchainImagesKHR(fBackendContext->fDevice, fSwapchain, &fImageCount, nullptr); @@ -311,14 +312,14 @@ void VulkanTestContext::createBuffers(VkFormat format) { fCurrentBackbufferIndex = fImageCount; } -void VulkanTestContext::destroyBuffers() { +void VulkanWindowContext::destroyBuffers() { if (fBackbuffers) { for (uint32_t i = 0; i < fImageCount + 1; ++i) { GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, - WaitForFences(fBackendContext->fDevice, 2, + WaitForFences(fBackendContext->fDevice, 2, fBackbuffers[i].fUsageFences, - true, UINT64_MAX)); + true, UINT64_MAX)); fBackbuffers[i].fImageIndex = -1; GR_VK_CALL(fBackendContext->fInterface, DestroySemaphore(fBackendContext->fDevice, @@ -349,11 +350,11 @@ void VulkanTestContext::destroyBuffers() { fImages = nullptr; } -VulkanTestContext::~VulkanTestContext() { +VulkanWindowContext::~VulkanWindowContext() { this->destroyContext(); } -void VulkanTestContext::destroyContext() { +void VulkanWindowContext::destroyContext() { if (!fBackendContext.get()) { return; } @@ -383,7 +384,7 @@ void VulkanTestContext::destroyContext() { fBackendContext.reset(nullptr); } -VulkanTestContext::BackbufferInfo* VulkanTestContext::getAvailableBackbuffer() { +VulkanWindowContext::BackbufferInfo* VulkanWindowContext::getAvailableBackbuffer() { SkASSERT(fBackbuffers); ++fCurrentBackbufferIndex; @@ -399,7 +400,7 @@ VulkanTestContext::BackbufferInfo* VulkanTestContext::getAvailableBackbuffer() { return backbuffer; } -SkSurface* VulkanTestContext::getBackbufferSurface() { +SkSurface* VulkanWindowContext::getBackbufferSurface() { BackbufferInfo* backbuffer = this->getAvailableBackbuffer(); SkASSERT(backbuffer); @@ -424,7 +425,7 @@ SkSurface* VulkanTestContext::getBackbufferSurface() { } // acquire the image - res = fAcquireNextImageKHR(fBackendContext->fDevice, fSwapchain, UINT64_MAX, + res = fAcquireNextImageKHR(fBackendContext->fDevice, fSwapchain, UINT64_MAX, backbuffer->fAcquireSemaphore, VK_NULL_HANDLE, &backbuffer->fImageIndex); @@ -439,7 +440,7 @@ SkSurface* VulkanTestContext::getBackbufferSurface() { VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT : VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT; VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT; - VkAccessFlags srcAccessMask = (VK_IMAGE_LAYOUT_UNDEFINED == layout) ? + VkAccessFlags srcAccessMask = (VK_IMAGE_LAYOUT_UNDEFINED == layout) ? 0 : VK_ACCESS_MEMORY_READ_BIT; VkAccessFlags dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; @@ -464,15 +465,15 @@ SkSurface* VulkanTestContext::getBackbufferSurface() { GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, BeginCommandBuffer(backbuffer->fTransitionCmdBuffers[0], &info)); - GR_VK_CALL(fBackendContext->fInterface, - CmdPipelineBarrier(backbuffer->fTransitionCmdBuffers[0], - srcStageMask, dstStageMask, 0, - 0, nullptr, - 0, nullptr, - 1, &imageMemoryBarrier)); + GR_VK_CALL(fBackendContext->fInterface, + CmdPipelineBarrier(backbuffer->fTransitionCmdBuffers[0], + srcStageMask, dstStageMask, 0, + 0, nullptr, + 0, nullptr, + 1, &imageMemoryBarrier)); GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, - EndCommandBuffer(backbuffer->fTransitionCmdBuffers[0])); + EndCommandBuffer(backbuffer->fTransitionCmdBuffers[0])); VkPipelineStageFlags waitDstStageFlags = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT; // insert the layout transfer into the queue and wait on the acquire @@ -485,16 +486,16 @@ SkSurface* VulkanTestContext::getBackbufferSurface() { submitInfo.commandBufferCount = 1; submitInfo.pCommandBuffers = &backbuffer->fTransitionCmdBuffers[0]; submitInfo.signalSemaphoreCount = 0; - + GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, - QueueSubmit(fBackendContext->fQueue, 1, &submitInfo, + QueueSubmit(fBackendContext->fQueue, 1, &submitInfo, backbuffer->fUsageFences[0])); return fSurfaces[backbuffer->fImageIndex].get(); } -void VulkanTestContext::swapBuffers() { +void VulkanWindowContext::swapBuffers() { BackbufferInfo* backbuffer = fBackbuffers + fCurrentBackbufferIndex; @@ -525,11 +526,11 @@ void VulkanTestContext::swapBuffers() { GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, BeginCommandBuffer(backbuffer->fTransitionCmdBuffers[1], &info)); GR_VK_CALL(fBackendContext->fInterface, - CmdPipelineBarrier(backbuffer->fTransitionCmdBuffers[1], - srcStageMask, dstStageMask, 0, - 0, nullptr, - 0, nullptr, - 1, &imageMemoryBarrier)); + CmdPipelineBarrier(backbuffer->fTransitionCmdBuffers[1], + srcStageMask, dstStageMask, 0, + 0, nullptr, + 0, nullptr, + 1, &imageMemoryBarrier)); GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, EndCommandBuffer(backbuffer->fTransitionCmdBuffers[1])); @@ -547,7 +548,7 @@ void VulkanTestContext::swapBuffers() { submitInfo.pSignalSemaphores = &backbuffer->fRenderSemaphore; GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, - QueueSubmit(fBackendContext->fQueue, 1, &submitInfo, + QueueSubmit(fBackendContext->fQueue, 1, &submitInfo, backbuffer->fUsageFences[1])); // Submit present operation to present queue @@ -566,3 +567,5 @@ void VulkanTestContext::swapBuffers() { fQueuePresentKHR(fPresentQueue, &presentInfo); } + +} //namespace sk_app diff --git a/tools/viewer/VulkanTestContext.h b/tools/viewer/sk_app/VulkanWindowContext.h similarity index 78% rename from tools/viewer/VulkanTestContext.h rename to tools/viewer/sk_app/VulkanWindowContext.h index 60b3b80..48f8ed5 100644 --- a/tools/viewer/VulkanTestContext.h +++ b/tools/viewer/sk_app/VulkanWindowContext.h @@ -5,27 +5,29 @@ * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ -#ifndef VulkanTestContext_DEFINED -#define VulkanTestContext_DEFINED +#ifndef VulkanWindowContext_DEFINED +#define VulkanWindowContext_DEFINED #ifdef SK_VULKAN -#include "GrTypes.h" #include "vk/GrVkBackendContext.h" +#include "WindowContext.h" class SkSurface; class GrContext; -class VulkanTestContext { +namespace sk_app { + +class VulkanWindowContext : public WindowContext { public: - ~VulkanTestContext(); + ~VulkanWindowContext() override; // each platform will have to implement these in its CPP file static VkSurfaceKHR createVkSurface(VkInstance, void* platformData); static bool canPresent(VkInstance, VkPhysicalDevice, uint32_t queueFamilyIndex); - static VulkanTestContext* Create(void* platformData, int msaaSampleCount) { - VulkanTestContext* ctx = new VulkanTestContext(platformData, msaaSampleCount); + static VulkanWindowContext* Create(void* platformData, int msaaSampleCount) { + VulkanWindowContext* ctx = new VulkanWindowContext(platformData, msaaSampleCount); if (!ctx->isValid()) { delete ctx; return nullptr; @@ -33,22 +35,24 @@ public: return ctx; } - SkSurface* getBackbufferSurface(); - void swapBuffers(); + SkSurface* getBackbufferSurface() override; + void swapBuffers() override; - bool makeCurrent() { return true; } + bool makeCurrent() override { return true; } - bool isValid() { return SkToBool(fBackendContext.get()); } + bool isValid() override { return SkToBool(fBackendContext.get()); } - void resize(uint32_t w, uint32_t h) { - this->createSwapchain(w, h); + void resize(uint32_t w, uint32_t h) override { + this->createSwapchain(w, h); } - GrBackendContext getBackendContext() { return (GrBackendContext)fBackendContext.get(); } + GrBackendContext getBackendContext() override { + return (GrBackendContext) fBackendContext.get(); + } private: - VulkanTestContext(); - VulkanTestContext(void*, int msaaSampleCount); + VulkanWindowContext(); + VulkanWindowContext(void*, int msaaSampleCount); void initializeContext(void*); void destroyContext(); @@ -76,7 +80,7 @@ private: private: FNPTR_TYPE fPtr; }; - + // WSI interface functions VkPtr fDestroySurfaceKHR; VkPtr fGetPhysicalDeviceSurfaceSupportKHR; @@ -109,6 +113,8 @@ private: uint32_t fCurrentBackbufferIndex; }; +} // namespace sk_app + #endif // SK_VULKAN #endif diff --git a/tools/viewer/Window.cpp b/tools/viewer/sk_app/Window.cpp similarity index 88% rename from tools/viewer/Window.cpp rename to tools/viewer/sk_app/Window.cpp index 6a83a3b..a7fd6b0 100644 --- a/tools/viewer/Window.cpp +++ b/tools/viewer/sk_app/Window.cpp @@ -9,7 +9,7 @@ #include "SkSurface.h" #include "SkCanvas.h" -#include "VulkanTestContext.h" +#include "VulkanWindowContext.h" namespace sk_app { @@ -36,8 +36,8 @@ Window::Window() : fCharFunc(default_char_func) } void Window::detach() { - delete fTestContext; - fTestContext = nullptr; + delete fWindowContext; + fWindowContext = nullptr; } bool Window::onChar(SkUnichar c, uint32_t modifiers) { @@ -53,7 +53,7 @@ bool Window::onMouse(int x, int y, InputState state, uint32_t modifiers) { } void Window::onPaint() { - SkSurface* backbuffer = fTestContext->getBackbufferSurface(); + SkSurface* backbuffer = fWindowContext->getBackbufferSurface(); if (backbuffer) { // draw into the canvas of this surface SkCanvas* canvas = backbuffer->getCanvas(); @@ -62,7 +62,7 @@ void Window::onPaint() { canvas->flush(); - fTestContext->swapBuffers(); + fWindowContext->swapBuffers(); } else { // try recreating testcontext } @@ -72,7 +72,7 @@ void Window::onPaint() { void Window::onResize(uint32_t w, uint32_t h) { fWidth = w; fHeight = h; - fTestContext->resize(w, h); + fWindowContext->resize(w, h); } } // namespace sk_app diff --git a/tools/viewer/Window.h b/tools/viewer/sk_app/Window.h similarity index 98% rename from tools/viewer/Window.h rename to tools/viewer/sk_app/Window.h index 913d2da..3dd558e 100644 --- a/tools/viewer/Window.h +++ b/tools/viewer/sk_app/Window.h @@ -12,10 +12,11 @@ #include "SkRect.h" class SkCanvas; -class VulkanTestContext; namespace sk_app { +class WindowContext; + class Window { public: static Window* CreateNativeWindow(void* platformData); @@ -143,7 +144,7 @@ protected: OnPaintFunc fPaintFunc; void* fPaintUserData; - VulkanTestContext* fTestContext; + WindowContext* fWindowContext; }; } // namespace sk_app diff --git a/tools/viewer/sk_app/WindowContext.h b/tools/viewer/sk_app/WindowContext.h new file mode 100644 index 0000000..5811bed --- /dev/null +++ b/tools/viewer/sk_app/WindowContext.h @@ -0,0 +1,36 @@ +/* + * Copyright 2016 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ +#ifndef WindowContext_DEFINED +#define WindowContext_DEFINED + +#include "GrTypes.h" + +class SkSurface; + +namespace sk_app { + +// TODO: fill this out with an interface +class WindowContext { +public: + virtual ~WindowContext() {} + + virtual SkSurface* getBackbufferSurface() = 0; + + virtual void swapBuffers() = 0; + + virtual bool makeCurrent() = 0; + + virtual bool isValid() = 0; + + virtual void resize(uint32_t w, uint32_t h) = 0; + + virtual GrBackendContext getBackendContext() = 0; +}; + +} // namespace sk_app + +#endif diff --git a/tools/viewer/android/VulkanTestContext_android.cpp b/tools/viewer/sk_app/android/VulkanWindowContext_android.cpp similarity index 84% rename from tools/viewer/android/VulkanTestContext_android.cpp rename to tools/viewer/sk_app/android/VulkanWindowContext_android.cpp index 58dbcb2..1ef994a 100644 --- a/tools/viewer/android/VulkanTestContext_android.cpp +++ b/tools/viewer/sk_app/android/VulkanWindowContext_android.cpp @@ -6,12 +6,14 @@ * found in the LICENSE file. */ -#include "VulkanTestContext_android.h" +#include "VulkanWindowContext_android.h" #include "vk/GrVkInterface.h" #include "vk/GrVkUtil.h" -VkSurfaceKHR VulkanTestContext::createVkSurface(VkInstance instance, void* platformData) { +namespace sk_app { + +VkSurfaceKHR VulkanWindowContext::createVkSurface(VkInstance instance, void* platformData) { static PFN_vkCreateAndroidSurfaceKHR createAndroidSurfaceKHR = nullptr; if (!createAndroidSurfaceKHR) { createAndroidSurfaceKHR = (PFN_vkCreateAndroidSurfaceKHR)vkGetInstanceProcAddr(instance, @@ -37,7 +39,9 @@ VkSurfaceKHR VulkanTestContext::createVkSurface(VkInstance instance, void* platf return (VK_SUCCESS == res) ? surface : VK_NULL_HANDLE; } -bool VulkanTestContext::canPresent(VkInstance instance, VkPhysicalDevice physDev, +bool VulkanWindowContext::canPresent(VkInstance instance, VkPhysicalDevice physDev, uint32_t queueFamilyIndex) { return true; } + +} // namespace sk_app diff --git a/tools/viewer/android/VulkanTestContext_android.h b/tools/viewer/sk_app/android/VulkanWindowContext_android.h similarity index 86% rename from tools/viewer/android/VulkanTestContext_android.h rename to tools/viewer/sk_app/android/VulkanWindowContext_android.h index 66ed35c..dd53e13 100644 --- a/tools/viewer/android/VulkanTestContext_android.h +++ b/tools/viewer/sk_app/android/VulkanWindowContext_android.h @@ -10,14 +10,17 @@ #ifdef SK_VULKAN -#include "../VulkanTestContext.h" +#include "../VulkanWindowContext.h" struct ANativeWindow; +namespace sk_app { + struct ContextPlatformData_android { ANativeWindow* fNativeWindow; }; +} #endif // SK_VULKAN #endif diff --git a/tools/viewer/android/Window_android.cpp b/tools/viewer/sk_app/android/Window_android.cpp similarity index 97% rename from tools/viewer/android/Window_android.cpp rename to tools/viewer/sk_app/android/Window_android.cpp index ebccb8b..94be02c 100644 --- a/tools/viewer/android/Window_android.cpp +++ b/tools/viewer/sk_app/android/Window_android.cpp @@ -7,7 +7,7 @@ #include "Window_android.h" -#include "VulkanTestContext_android.h" +#include "VulkanWindowContext_android.h" namespace sk_app { @@ -53,7 +53,7 @@ void Window_android::initDisplay(ANativeWindow* window) { SkASSERT(window); ContextPlatformData_android platformData; platformData.fNativeWindow = window; - fTestContext = VulkanTestContext::Create((void*)&platformData, mSampleCount); + fWindowContext = VulkanWindowContext::Create((void*)&platformData, mSampleCount); } static void android_app_write_cmd(struct android_app* android_app, int8_t cmd) { diff --git a/tools/viewer/android/Window_android.h b/tools/viewer/sk_app/android/Window_android.h similarity index 100% rename from tools/viewer/android/Window_android.h rename to tools/viewer/sk_app/android/Window_android.h diff --git a/tools/viewer/android/main_android.cpp b/tools/viewer/sk_app/android/main_android.cpp similarity index 100% rename from tools/viewer/android/main_android.cpp rename to tools/viewer/sk_app/android/main_android.cpp diff --git a/tools/viewer/win/VulkanTestContext_win.cpp b/tools/viewer/sk_app/win/VulkanWindowContext_win.cpp similarity index 62% rename from tools/viewer/win/VulkanTestContext_win.cpp rename to tools/viewer/sk_app/win/VulkanWindowContext_win.cpp index 37ef667..05f3bdd 100644 --- a/tools/viewer/win/VulkanTestContext_win.cpp +++ b/tools/viewer/sk_app/win/VulkanWindowContext_win.cpp @@ -6,24 +6,26 @@ * found in the LICENSE file. */ -#include "VulkanTestContext_win.h" +#include "VulkanWindowContext_win.h" #include "vk/GrVkInterface.h" #include "vk/GrVkUtil.h" +namespace sk_app { + // Platform dependant call -VkSurfaceKHR VulkanTestContext::createVkSurface(VkInstance instance, void* platformData) { +VkSurfaceKHR VulkanWindowContext::createVkSurface(VkInstance instance, void* platformData) { static PFN_vkCreateWin32SurfaceKHR createWin32SurfaceKHR = nullptr; if (!createWin32SurfaceKHR) { - createWin32SurfaceKHR = (PFN_vkCreateWin32SurfaceKHR)vkGetInstanceProcAddr(instance, - "vkCreateWin32SurfaceKHR"); + createWin32SurfaceKHR = (PFN_vkCreateWin32SurfaceKHR) vkGetInstanceProcAddr(instance, + "vkCreateWin32SurfaceKHR"); } if (!platformData) { return VK_NULL_HANDLE; } - ContextPlatformData_win* winPlatformData = - reinterpret_cast(platformData); + ContextPlatformData_win* winPlatformData = + reinterpret_cast(platformData); VkSurfaceKHR surface; VkWin32SurfaceCreateInfoKHR surfaceCreateInfo; @@ -43,16 +45,18 @@ VkSurfaceKHR VulkanTestContext::createVkSurface(VkInstance instance, void* platf } // Platform dependant call -bool VulkanTestContext::canPresent(VkInstance instance, VkPhysicalDevice physDev, +bool VulkanWindowContext::canPresent(VkInstance instance, VkPhysicalDevice physDev, uint32_t queueFamilyIndex) { - static PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR - getPhysicalDeviceWin32PresentationSupportKHR = nullptr; + static PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR + getPhysicalDeviceWin32PresentationSupportKHR = nullptr; if (!getPhysicalDeviceWin32PresentationSupportKHR) { - getPhysicalDeviceWin32PresentationSupportKHR = + getPhysicalDeviceWin32PresentationSupportKHR = (PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR) vkGetInstanceProcAddr(instance, - "vkGetPhysicalDeviceWin32PresentationSupportKHR"); + "vkGetPhysicalDeviceWin32PresentationSupportKHR"); } VkBool32 check = getPhysicalDeviceWin32PresentationSupportKHR(physDev, queueFamilyIndex); return (VK_FALSE != check); } + +} // namespace sk_app diff --git a/tools/viewer/win/VulkanTestContext_win.h b/tools/viewer/sk_app/win/VulkanWindowContext_win.h similarity index 86% rename from tools/viewer/win/VulkanTestContext_win.h rename to tools/viewer/sk_app/win/VulkanWindowContext_win.h index 59b5c2c..e0b5a15 100644 --- a/tools/viewer/win/VulkanTestContext_win.h +++ b/tools/viewer/sk_app/win/VulkanWindowContext_win.h @@ -11,7 +11,9 @@ #ifdef SK_VULKAN #include -#include "../VulkanTestContext.h" +#include "../VulkanWindowContext.h" + +namespace sk_app { // for Windows struct ContextPlatformData_win { @@ -19,6 +21,8 @@ struct ContextPlatformData_win { HWND fHWnd; }; +} + #endif // SK_VULKAN #endif diff --git a/tools/viewer/win/Window_win.cpp b/tools/viewer/sk_app/win/Window_win.cpp similarity index 98% rename from tools/viewer/win/Window_win.cpp rename to tools/viewer/sk_app/win/Window_win.cpp index d5711b7..1dd07a6 100644 --- a/tools/viewer/win/Window_win.cpp +++ b/tools/viewer/sk_app/win/Window_win.cpp @@ -12,7 +12,7 @@ #include #include "SkUtils.h" -#include "VulkanTestContext_win.h" +#include "VulkanWindowContext_win.h" namespace sk_app { @@ -273,9 +273,9 @@ bool Window_win::attach(BackEndType attachType, int msaaSampleCount) { platformData.fHInstance = fHInstance; platformData.fHWnd = fHWnd; - fTestContext = VulkanTestContext::Create((void*)&platformData, msaaSampleCount); + fWindowContext = VulkanWindowContext::Create((void*)&platformData, msaaSampleCount); - return (SkToBool(fTestContext)); + return (SkToBool(fWindowContext)); } void Window_win::inval() { diff --git a/tools/viewer/win/Window_win.h b/tools/viewer/sk_app/win/Window_win.h similarity index 100% rename from tools/viewer/win/Window_win.h rename to tools/viewer/sk_app/win/Window_win.h diff --git a/tools/viewer/win/main_win.cpp b/tools/viewer/sk_app/win/main_win.cpp similarity index 100% rename from tools/viewer/win/main_win.cpp rename to tools/viewer/sk_app/win/main_win.cpp -- 2.7.4