diff options
author | brianosman <brianosman@google.com> | 2016-05-06 13:28:57 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-05-06 13:28:57 -0700 |
commit | 05de216ffb864cb1f3a4fa37a2c3a772be38a0c9 (patch) | |
tree | c4562570a3d8d9cb550c642728995d39cb821bfe /tools | |
parent | 67a58dcd4a1e79e5832161ae953526d27893aa61 (diff) |
Add sRGB mode toggle to Viewer.
Unlike SampleApp, this just switches out the format of the window
surface (and then adjusts the gamma-correct flag on the SkSurfaces).
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1950983007
Review-Url: https://codereview.chromium.org/1950983007
Diffstat (limited to 'tools')
-rw-r--r-- | tools/viewer/Viewer.cpp | 31 | ||||
-rw-r--r-- | tools/viewer/Viewer.h | 1 | ||||
-rw-r--r-- | tools/viewer/sk_app/DisplayParams.h | 27 | ||||
-rw-r--r-- | tools/viewer/sk_app/VulkanWindowContext.cpp | 38 | ||||
-rw-r--r-- | tools/viewer/sk_app/VulkanWindowContext.h | 19 | ||||
-rw-r--r-- | tools/viewer/sk_app/Window.cpp | 8 | ||||
-rw-r--r-- | tools/viewer/sk_app/Window.h | 6 | ||||
-rw-r--r-- | tools/viewer/sk_app/WindowContext.h | 4 | ||||
-rw-r--r-- | tools/viewer/sk_app/android/Window_android.cpp | 6 | ||||
-rw-r--r-- | tools/viewer/sk_app/android/Window_android.h | 4 | ||||
-rw-r--r-- | tools/viewer/sk_app/win/Window_win.cpp | 4 | ||||
-rw-r--r-- | tools/viewer/sk_app/win/Window_win.h | 2 |
12 files changed, 115 insertions, 35 deletions
diff --git a/tools/viewer/Viewer.cpp b/tools/viewer/Viewer.cpp index ededc1f1c1..62c3048d91 100644 --- a/tools/viewer/Viewer.cpp +++ b/tools/viewer/Viewer.cpp @@ -73,7 +73,7 @@ Viewer::Viewer(int argc, char** argv, void* platformData) SkCommandLineFlags::Parse(argc, argv); fWindow = Window::CreateNativeWindow(platformData); - fWindow->attach(Window::kVulkan_BackendType, 0); + fWindow->attach(Window::kVulkan_BackendType, DisplayParams()); // register callbacks fWindow->registerKeyFunc(on_key_handler, this); @@ -149,14 +149,21 @@ Viewer::~Viewer() { delete fWindow; } -void Viewer::setupCurrentSlide(int previousSlide) { +void Viewer::updateTitle() { SkString title("Viewer: "); title.append(fSlides[fCurrentSlide]->getName()); + if (kSRGB_SkColorProfileType == fWindow->getDisplayParams().fProfileType) { + title.append(" sRGB"); + } + fWindow->setTitle(title.c_str()); +} + +void Viewer::setupCurrentSlide(int previousSlide) { + this->updateTitle(); fSlides[fCurrentSlide]->load(); if (previousSlide >= 0) { fSlides[previousSlide]->unload(); } - fWindow->setTitle(title.c_str()); fWindow->inval(); } @@ -220,9 +227,6 @@ bool Viewer::onKey(Window::Key key, Window::InputState state, uint32_t modifiers if (fCurrentSlide < 0) { fCurrentSlide = fSlides.count() - 1; } - SkString title("Viewer: "); - title.append(fSlides[fCurrentSlide]->getName()); - fWindow->setTitle(title.c_str()); setupCurrentSlide(previousSlide); return true; } @@ -248,9 +252,18 @@ bool Viewer::onKey(Window::Key key, Window::InputState state, uint32_t modifiers } bool Viewer::onChar(SkUnichar c, uint32_t modifiers) { - if ('s' == c) { - fDisplayStats = !fDisplayStats; - return true; + switch (c) { + case 's': + fDisplayStats = !fDisplayStats; + return true; + case 'c': + DisplayParams params = fWindow->getDisplayParams(); + params.fProfileType = (kLinear_SkColorProfileType == params.fProfileType) + ? kSRGB_SkColorProfileType : kLinear_SkColorProfileType; + fWindow->setDisplayParams(params); + this->updateTitle(); + fWindow->inval(); + return true; } return false; diff --git a/tools/viewer/Viewer.h b/tools/viewer/Viewer.h index 2ae7ae39f9..2e9650a846 100644 --- a/tools/viewer/Viewer.h +++ b/tools/viewer/Viewer.h @@ -28,6 +28,7 @@ public: private: void initSlides(); + void updateTitle(); void setupCurrentSlide(int previousSlide); void drawStats(SkCanvas* canvas); diff --git a/tools/viewer/sk_app/DisplayParams.h b/tools/viewer/sk_app/DisplayParams.h new file mode 100644 index 0000000000..836b02ec92 --- /dev/null +++ b/tools/viewer/sk_app/DisplayParams.h @@ -0,0 +1,27 @@ +/* + * 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 DisplayParams_DEFINED +#define DisplayParams_DEFINED + +#include "SkImageInfo.h" + +namespace sk_app { + +struct DisplayParams { + DisplayParams() + : fColorType(kN32_SkColorType) + , fProfileType(kLinear_SkColorProfileType) + , fMSAASampleCount(0) {} + + SkColorType fColorType; + SkColorProfileType fProfileType; + int fMSAASampleCount; +}; + +} // namespace sk_app + +#endif diff --git a/tools/viewer/sk_app/VulkanWindowContext.cpp b/tools/viewer/sk_app/VulkanWindowContext.cpp index 8f5f4209a4..f21ec9c0cb 100644 --- a/tools/viewer/sk_app/VulkanWindowContext.cpp +++ b/tools/viewer/sk_app/VulkanWindowContext.cpp @@ -24,7 +24,7 @@ namespace sk_app { -VulkanWindowContext::VulkanWindowContext(void* platformData, int msaaSampleCount) +VulkanWindowContext::VulkanWindowContext(void* platformData, const DisplayParams& params) : fSurface(VK_NULL_HANDLE) , fSwapchain(VK_NULL_HANDLE) , fCommandPool(VK_NULL_HANDLE) @@ -32,10 +32,10 @@ VulkanWindowContext::VulkanWindowContext(void* platformData, int msaaSampleCount // any config code here (particularly for msaa)? - this->initializeContext(platformData); + this->initializeContext(platformData, params); } -void VulkanWindowContext::initializeContext(void* platformData) { +void VulkanWindowContext::initializeContext(void* platformData, const DisplayParams& params) { fBackendContext.reset(GrVkBackendContext::Create(&fPresentQueueIndex, canPresent)); if (!(fBackendContext->fExtensions & kKHR_surface_GrVkExtensionFlag) || @@ -74,7 +74,7 @@ void VulkanWindowContext::initializeContext(void* platformData) { return; } - if (!this->createSwapchain(-1, -1)) { + if (!this->createSwapchain(-1, -1, params)) { this->destroyContext(); return; } @@ -83,7 +83,8 @@ void VulkanWindowContext::initializeContext(void* platformData) { vkGetDeviceQueue(fBackendContext->fDevice, fPresentQueueIndex, 0, &fPresentQueue); } -bool VulkanWindowContext::createSwapchain(uint32_t width, uint32_t height) { +bool VulkanWindowContext::createSwapchain(uint32_t width, uint32_t height, + const DisplayParams& params) { // check for capabilities VkSurfaceCapabilitiesKHR caps; VkResult res = fGetPhysicalDeviceSurfaceCapabilitiesKHR(fBackendContext->fPhysicalDevice, @@ -162,9 +163,24 @@ bool VulkanWindowContext::createSwapchain(uint32_t width, uint32_t height) { VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR : VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR; - // Pick our surface format -- for now, the first one - VkFormat surfaceFormat = surfaceFormats[0].format; - VkColorSpaceKHR colorSpace = surfaceFormats[0].colorSpace; + // Pick our surface format. For now, just make sure it matches our sRGB request: + VkFormat surfaceFormat = VK_FORMAT_UNDEFINED; + VkColorSpaceKHR colorSpace = VK_COLORSPACE_SRGB_NONLINEAR_KHR; + bool wantSRGB = kSRGB_SkColorProfileType == params.fProfileType; + for (uint32_t i = 0; i < surfaceFormatCount; ++i) { + GrPixelConfig config; + if (GrVkFormatToPixelConfig(surfaceFormats[i].format, &config) && + GrPixelConfigIsSRGB(config) == wantSRGB) { + surfaceFormat = surfaceFormats[i].format; + colorSpace = surfaceFormats[i].colorSpace; + break; + } + } + fDisplayParams = params; + + if (VK_FORMAT_UNDEFINED == surfaceFormat) { + return false; + } // If mailbox mode is available, use it, as it is the lowest-latency non- // tearing mode. If not, fall back to FIFO which is always available. @@ -252,7 +268,9 @@ void VulkanWindowContext::createBuffers(VkFormat format) { desc.fSampleCnt = 0; desc.fStencilBits = 0; desc.fRenderTargetHandle = (GrBackendObject) &info; - SkSurfaceProps props(0, kUnknown_SkPixelGeometry); + SkSurfaceProps props(GrPixelConfigIsSRGB(fPixelConfig) + ? SkSurfaceProps::kGammaCorrect_Flag : 0, + kUnknown_SkPixelGeometry); fSurfaces[i] = SkSurface::MakeFromBackendRenderTarget(fContext, desc, &props); } @@ -420,7 +438,7 @@ SkSurface* VulkanWindowContext::getBackbufferSurface() { } if (VK_ERROR_OUT_OF_DATE_KHR == res) { // tear swapchain down and try again - if (!this->createSwapchain(0, 0)) { + if (!this->createSwapchain(0, 0, fDisplayParams)) { return nullptr; } diff --git a/tools/viewer/sk_app/VulkanWindowContext.h b/tools/viewer/sk_app/VulkanWindowContext.h index 48f8ed536b..e186881565 100644 --- a/tools/viewer/sk_app/VulkanWindowContext.h +++ b/tools/viewer/sk_app/VulkanWindowContext.h @@ -26,8 +26,8 @@ public: static VkSurfaceKHR createVkSurface(VkInstance, void* platformData); static bool canPresent(VkInstance, VkPhysicalDevice, uint32_t queueFamilyIndex); - static VulkanWindowContext* Create(void* platformData, int msaaSampleCount) { - VulkanWindowContext* ctx = new VulkanWindowContext(platformData, msaaSampleCount); + static VulkanWindowContext* Create(void* platformData, const DisplayParams& params) { + VulkanWindowContext* ctx = new VulkanWindowContext(platformData, params); if (!ctx->isValid()) { delete ctx; return nullptr; @@ -43,7 +43,12 @@ public: bool isValid() override { return SkToBool(fBackendContext.get()); } void resize(uint32_t w, uint32_t h) override { - this->createSwapchain(w, h); + this->createSwapchain(w, h, fDisplayParams); + } + + const DisplayParams& getDisplayParams() { return fDisplayParams; } + void setDisplayParams(const DisplayParams& params) { + this->createSwapchain(fWidth, fHeight, params); } GrBackendContext getBackendContext() override { @@ -51,9 +56,8 @@ public: } private: - VulkanWindowContext(); - VulkanWindowContext(void*, int msaaSampleCount); - void initializeContext(void*); + VulkanWindowContext(void*, const DisplayParams&); + void initializeContext(void*, const DisplayParams&); void destroyContext(); struct BackbufferInfo { @@ -65,7 +69,7 @@ private: }; BackbufferInfo* getAvailableBackbuffer(); - bool createSwapchain(uint32_t width, uint32_t height); + bool createSwapchain(uint32_t width, uint32_t height, const DisplayParams& params); void createBuffers(VkFormat format); void destroyBuffers(); @@ -102,6 +106,7 @@ private: VkQueue fPresentQueue; int fWidth; int fHeight; + DisplayParams fDisplayParams; GrPixelConfig fPixelConfig; uint32_t fImageCount; diff --git a/tools/viewer/sk_app/Window.cpp b/tools/viewer/sk_app/Window.cpp index a7fd6b0cf6..47053be5af 100644 --- a/tools/viewer/sk_app/Window.cpp +++ b/tools/viewer/sk_app/Window.cpp @@ -75,4 +75,12 @@ void Window::onResize(uint32_t w, uint32_t h) { fWindowContext->resize(w, h); } +const DisplayParams& Window::getDisplayParams() { + return fWindowContext->getDisplayParams(); +} + +void Window::setDisplayParams(const DisplayParams& params) { + fWindowContext->setDisplayParams(params); +} + } // namespace sk_app diff --git a/tools/viewer/sk_app/Window.h b/tools/viewer/sk_app/Window.h index 3dd558e75a..56444a67b7 100644 --- a/tools/viewer/sk_app/Window.h +++ b/tools/viewer/sk_app/Window.h @@ -8,6 +8,7 @@ #ifndef Window_DEFINED #define Window_DEFINED +#include "DisplayParams.h" #include "SkTypes.h" #include "SkRect.h" @@ -36,7 +37,7 @@ public: kVulkan_BackendType }; - virtual bool attach(BackEndType attachType, int msaaSampleCount) = 0; + virtual bool attach(BackEndType attachType, const DisplayParams& params) = 0; void detach(); // input handling @@ -129,6 +130,9 @@ public: uint32_t width() { return fWidth; } uint32_t height() { return fHeight; } + const DisplayParams& getDisplayParams(); + void setDisplayParams(const DisplayParams& params); + protected: Window(); diff --git a/tools/viewer/sk_app/WindowContext.h b/tools/viewer/sk_app/WindowContext.h index 5811bedd32..d48e38e746 100644 --- a/tools/viewer/sk_app/WindowContext.h +++ b/tools/viewer/sk_app/WindowContext.h @@ -7,6 +7,7 @@ #ifndef WindowContext_DEFINED #define WindowContext_DEFINED +#include "DisplayParams.h" #include "GrTypes.h" class SkSurface; @@ -28,6 +29,9 @@ public: virtual void resize(uint32_t w, uint32_t h) = 0; + virtual const DisplayParams& getDisplayParams() = 0; + virtual void setDisplayParams(const DisplayParams& params) = 0; + virtual GrBackendContext getBackendContext() = 0; }; diff --git a/tools/viewer/sk_app/android/Window_android.cpp b/tools/viewer/sk_app/android/Window_android.cpp index 94be02c933..9def29fbf4 100644 --- a/tools/viewer/sk_app/android/Window_android.cpp +++ b/tools/viewer/sk_app/android/Window_android.cpp @@ -37,12 +37,12 @@ void Window_android::setTitle(const char* title) { SkDebugf("Title: %s", title); } -bool Window_android::attach(BackEndType attachType, int msaaSampleCount) { +bool Window_android::attach(BackEndType attachType, const DisplayParams& params) { if (kVulkan_BackendType != attachType) { return false; } - mSampleCount = msaaSampleCount; + fDisplayParams = params; // We delay the creation of fTestContext until Android informs us that // the native window is ready to use. @@ -53,7 +53,7 @@ void Window_android::initDisplay(ANativeWindow* window) { SkASSERT(window); ContextPlatformData_android platformData; platformData.fNativeWindow = window; - fWindowContext = VulkanWindowContext::Create((void*)&platformData, mSampleCount); + fWindowContext = VulkanWindowContext::Create((void*)&platformData, mSampleCount, fSRGB); } static void android_app_write_cmd(struct android_app* android_app, int8_t cmd) { diff --git a/tools/viewer/sk_app/android/Window_android.h b/tools/viewer/sk_app/android/Window_android.h index d41f0a54c2..b570615075 100644 --- a/tools/viewer/sk_app/android/Window_android.h +++ b/tools/viewer/sk_app/android/Window_android.h @@ -31,7 +31,7 @@ public: void setTitle(const char*) override; void show() override {} - bool attach(BackEndType attachType, int msaaSampleCount, bool deepColor) override; + bool attach(BackEndType attachType, const DisplayParams& params) override; void inval() override; void paintIfNeeded(); @@ -44,7 +44,7 @@ public: private: android_app* mApp = nullptr; SkRect mContentRect; - int mSampleCount = 0; + DisplayParams fDisplayParams; }; } // namespace sk_app diff --git a/tools/viewer/sk_app/win/Window_win.cpp b/tools/viewer/sk_app/win/Window_win.cpp index 1dd07a6c9c..16afcc7275 100644 --- a/tools/viewer/sk_app/win/Window_win.cpp +++ b/tools/viewer/sk_app/win/Window_win.cpp @@ -264,7 +264,7 @@ void Window_win::show() { } -bool Window_win::attach(BackEndType attachType, int msaaSampleCount) { +bool Window_win::attach(BackEndType attachType, const DisplayParams& params) { if (kVulkan_BackendType != attachType) { return false; } @@ -273,7 +273,7 @@ bool Window_win::attach(BackEndType attachType, int msaaSampleCount) { platformData.fHInstance = fHInstance; platformData.fHWnd = fHWnd; - fWindowContext = VulkanWindowContext::Create((void*)&platformData, msaaSampleCount); + fWindowContext = VulkanWindowContext::Create((void*)&platformData, params); return (SkToBool(fWindowContext)); } diff --git a/tools/viewer/sk_app/win/Window_win.h b/tools/viewer/sk_app/win/Window_win.h index e295212f31..3501b06ae4 100644 --- a/tools/viewer/sk_app/win/Window_win.h +++ b/tools/viewer/sk_app/win/Window_win.h @@ -23,7 +23,7 @@ public: void setTitle(const char*) override; void show() override; - bool attach(BackEndType attachType, int msaaSampleCount) override; + bool attach(BackEndType attachType, const DisplayParams& params) override; void inval() override; |