aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/viewer
diff options
context:
space:
mode:
Diffstat (limited to 'tools/viewer')
-rw-r--r--tools/viewer/Viewer.cpp26
-rw-r--r--tools/viewer/Viewer.h2
-rw-r--r--tools/viewer/sk_app/DisplayParams.h8
-rw-r--r--tools/viewer/sk_app/GLWindowContext.cpp112
-rw-r--r--tools/viewer/sk_app/GLWindowContext.h63
-rw-r--r--tools/viewer/sk_app/VulkanWindowContext.cpp29
-rw-r--r--tools/viewer/sk_app/VulkanWindowContext.h28
-rw-r--r--tools/viewer/sk_app/Window.cpp3
-rw-r--r--tools/viewer/sk_app/Window.h11
-rw-r--r--tools/viewer/sk_app/WindowContext.h34
-rw-r--r--tools/viewer/sk_app/android/Window_android.cpp2
-rw-r--r--tools/viewer/sk_app/android/Window_android.h2
-rw-r--r--tools/viewer/sk_app/win/GLWindowContext_win.cpp110
-rw-r--r--tools/viewer/sk_app/win/GLWindowContext_win.h37
-rw-r--r--tools/viewer/sk_app/win/VulkanWindowContext_win.cpp3
-rw-r--r--tools/viewer/sk_app/win/VulkanWindowContext_win.h28
-rw-r--r--tools/viewer/sk_app/win/Window_win.cpp20
-rw-r--r--tools/viewer/sk_app/win/Window_win.h8
18 files changed, 80 insertions, 446 deletions
diff --git a/tools/viewer/Viewer.cpp b/tools/viewer/Viewer.cpp
index 7f18652c2c..d492cdeefe 100644
--- a/tools/viewer/Viewer.cpp
+++ b/tools/viewer/Viewer.cpp
@@ -48,15 +48,9 @@ DEFINE_string2(match, m, nullptr,
"it is skipped unless some list entry starts with ~");
DEFINE_string(skps, "skps", "Directory to read skps from.");
-const char *kBackendTypeStrings[sk_app::Window::kBackendTypeCount] = {
- " [OpenGL]",
- " [Vulkan]"
-};
-
Viewer::Viewer(int argc, char** argv, void* platformData)
: fCurrentMeasurement(0)
, fDisplayStats(false)
- , fBackendType(sk_app::Window::kVulkan_BackendType)
, fZoomCenterX(0.0f)
, fZoomCenterY(0.0f)
, fZoomLevel(0.0f)
@@ -73,7 +67,7 @@ Viewer::Viewer(int argc, char** argv, void* platformData)
SkCommandLineFlags::Parse(argc, argv);
fWindow = Window::CreateNativeWindow(platformData);
- fWindow->attach(fBackendType, DisplayParams());
+ fWindow->attach(Window::kVulkan_BackendType, DisplayParams());
// register callbacks
fCommands.attach(fWindow);
@@ -117,22 +111,6 @@ Viewer::Viewer(int argc, char** argv, void* platformData)
this->changeZoomLevel(-1.f / 32.f);
fWindow->inval();
});
-#ifndef SK_BUILD_FOR_ANDROID
- fCommands.addCommand('d', "Modes", "Change rendering backend", [this]() {
- fWindow->detach();
-
- if (sk_app::Window::kVulkan_BackendType == fBackendType) {
- fBackendType = sk_app::Window::kNativeGL_BackendType;
- }
- // TODO: get Vulkan -> OpenGL working without swapchain creation failure
- //else if (sk_app::Window::kNativeGL_BackendType == fBackendType) {
- // fBackendType = sk_app::Window::kVulkan_BackendType;
- //}
-
- fWindow->attach(fBackendType, DisplayParams());
- this->updateTitle();
- });
-#endif
// set up slides
this->initSlides();
@@ -208,7 +186,6 @@ void Viewer::updateTitle() {
if (kSRGB_SkColorProfileType == fWindow->getDisplayParams().fProfileType) {
title.append(" sRGB");
}
- title.append(kBackendTypeStrings[fBackendType]);
fWindow->setTitle(title.c_str());
}
@@ -260,6 +237,7 @@ SkMatrix Viewer::computeMatrix() {
}
void Viewer::onPaint(SkCanvas* canvas) {
+
int count = canvas->save();
if (fWindow->supportsContentRect()) {
diff --git a/tools/viewer/Viewer.h b/tools/viewer/Viewer.h
index c785cff78e..13cfada9d2 100644
--- a/tools/viewer/Viewer.h
+++ b/tools/viewer/Viewer.h
@@ -48,8 +48,6 @@ private:
bool fDisplayStats;
- sk_app::Window::BackendType fBackendType;
-
// transform data
SkScalar fZoomCenterX;
SkScalar fZoomCenterY;
diff --git a/tools/viewer/sk_app/DisplayParams.h b/tools/viewer/sk_app/DisplayParams.h
index 8756ff0aac..836b02ec92 100644
--- a/tools/viewer/sk_app/DisplayParams.h
+++ b/tools/viewer/sk_app/DisplayParams.h
@@ -15,13 +15,11 @@ struct DisplayParams {
DisplayParams()
: fColorType(kN32_SkColorType)
, fProfileType(kLinear_SkColorProfileType)
- , fMSAASampleCount(0)
- , fDeepColor(false) {}
+ , fMSAASampleCount(0) {}
- SkColorType fColorType;
+ SkColorType fColorType;
SkColorProfileType fProfileType;
- int fMSAASampleCount;
- bool fDeepColor;
+ int fMSAASampleCount;
};
} // namespace sk_app
diff --git a/tools/viewer/sk_app/GLWindowContext.cpp b/tools/viewer/sk_app/GLWindowContext.cpp
deleted file mode 100644
index a491321a2a..0000000000
--- a/tools/viewer/sk_app/GLWindowContext.cpp
+++ /dev/null
@@ -1,112 +0,0 @@
-
-/*
- * Copyright 2015 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "GrContext.h"
-#include "SkSurface.h"
-#include "GLWindowContext.h"
-
-#include "gl/GrGLDefines.h"
-
-#include "gl/GrGLUtil.h"
-#include "GrRenderTarget.h"
-#include "GrContext.h"
-
-#include "SkCanvas.h"
-#include "SkImage_Base.h"
-
-namespace sk_app {
-
-GLWindowContext::GLWindowContext(void* platformData, const DisplayParams& params)
- : WindowContext()
- , fBackendContext(nullptr)
- , fRenderTarget(nullptr)
- , fSurface(nullptr) {
-}
-
-void GLWindowContext::initializeContext(void* platformData, const DisplayParams& params) {
-
- this->onInitializeContext(platformData, params);
-
- fDisplayParams = params;
-
- SkAutoTUnref<const GrGLInterface> glInterface;
- glInterface.reset(GrGLCreateNativeInterface());
- fBackendContext.reset(GrGLInterfaceRemoveNVPR(glInterface.get()));
-
- SkASSERT(nullptr == fContext);
- fContext = GrContext::Create(kOpenGL_GrBackend, (GrBackendContext)fBackendContext.get());
-
- // We may not have real sRGB support (ANGLE, in particular), so check for
- // that, and fall back to L32:
- //
- // ... and, if we're using a 10-bit/channel FB0, it doesn't do sRGB conversion on write,
- // so pretend that it's non-sRGB 8888:
- fPixelConfig = fContext->caps()->srgbSupport() &&
- SkColorAndProfileAreGammaCorrect(fDisplayParams.fColorType,
- fDisplayParams.fProfileType) &&
- (fColorBits != 30) ? kSkiaGamma8888_GrPixelConfig : kSkia8888_GrPixelConfig;
-}
-
-void GLWindowContext::destroyContext() {
- fSurface.reset(nullptr);
- fRenderTarget.reset(nullptr);
-
- if (fContext) {
- // in case we have outstanding refs to this guy (lua?)
- fContext->abandonContext();
- fContext->unref();
- fContext = nullptr;
- }
-
- fBackendContext.reset(nullptr);
-
- this->onDestroyContext();
-}
-
-sk_sp<SkSurface> GLWindowContext::getBackbufferSurface() {
- if (nullptr == fSurface) {
- fActualColorBits = SkTMax(fColorBits, 24);
-
- if (fContext) {
- GrBackendRenderTargetDesc desc;
- desc.fWidth = this->fWidth;
- desc.fHeight = this->fHeight;
- desc.fConfig = fPixelConfig;
- desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
- desc.fSampleCnt = fSampleCount;
- desc.fStencilBits = fStencilBits;
- GrGLint buffer;
- GR_GL_CALL(fBackendContext, GetIntegerv(GR_GL_FRAMEBUFFER_BINDING, &buffer));
- desc.fRenderTargetHandle = buffer;
- fRenderTarget.reset(fContext->textureProvider()->wrapBackendRenderTarget(desc));
-
- fSurface = this->createRenderSurface(fRenderTarget, fActualColorBits);
- }
- }
-
- return fSurface;
-}
-
-void GLWindowContext::swapBuffers() {
- this->presentRenderSurface(fSurface, fRenderTarget, fActualColorBits);
- this->onSwapBuffers();
-}
-
-void GLWindowContext::resize(uint32_t w, uint32_t h) {
- this->destroyContext();
-
- this->initializeContext(nullptr, fDisplayParams);
-}
-
-void GLWindowContext::setDisplayParams(const DisplayParams& params) {
- this->destroyContext();
-
- this->initializeContext(nullptr, params);
-}
-
-} //namespace sk_app
diff --git a/tools/viewer/sk_app/GLWindowContext.h b/tools/viewer/sk_app/GLWindowContext.h
deleted file mode 100644
index 6fb5e09889..0000000000
--- a/tools/viewer/sk_app/GLWindowContext.h
+++ /dev/null
@@ -1,63 +0,0 @@
-
-/*
- * 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 GLWindowContext_DEFINED
-#define GLWindowContext_DEFINED
-
-
-#include "gl/GrGLInterface.h"
-
-#include "SkRefCnt.h"
-#include "GrRenderTarget.h"
-#include "SkSurface.h"
-
-#include "WindowContext.h"
-
-class GrContext;
-
-namespace sk_app {
-
-class GLWindowContext : public WindowContext {
-public:
- // This is defined in the platform .cpp file
- static GLWindowContext* Create(void* platformData, const DisplayParams& params);
-
- sk_sp<SkSurface> getBackbufferSurface() override;
-
- bool isValid() override { return SkToBool(fBackendContext.get()); }
-
- void resize(uint32_t w, uint32_t h) override;
- void swapBuffers() override;
-
- void setDisplayParams(const DisplayParams& params) override;
-
- GrBackendContext getBackendContext() override {
- return (GrBackendContext) fBackendContext.get();
- }
-
-protected:
- GLWindowContext(void*, const DisplayParams&);
- void initializeContext(void*, const DisplayParams&);
- virtual void onInitializeContext(void*, const DisplayParams&) = 0;
- void destroyContext();
- virtual void onDestroyContext() = 0;
- virtual void onSwapBuffers() = 0;
-
- SkAutoTUnref<const GrGLInterface> fBackendContext;
- sk_sp<GrRenderTarget> fRenderTarget;
- sk_sp<SkSurface> fSurface;
-
- // parameters obtained from the native window
- int fSampleCount;
- int fStencilBits;
- int fColorBits;
- int fActualColorBits;
-};
-
-} // namespace sk_app
-
-#endif
diff --git a/tools/viewer/sk_app/VulkanWindowContext.cpp b/tools/viewer/sk_app/VulkanWindowContext.cpp
index bc200de427..2570e826a3 100644
--- a/tools/viewer/sk_app/VulkanWindowContext.cpp
+++ b/tools/viewer/sk_app/VulkanWindowContext.cpp
@@ -7,7 +7,6 @@
*/
#include "GrContext.h"
-#include "GrRenderTarget.h"
#include "SkSurface.h"
#include "VulkanWindowContext.h"
@@ -26,12 +25,8 @@
namespace sk_app {
VulkanWindowContext::VulkanWindowContext(void* platformData, const DisplayParams& params)
- : WindowContext()
- , fSurface(VK_NULL_HANDLE)
+ : fSurface(VK_NULL_HANDLE)
, fSwapchain(VK_NULL_HANDLE)
- , fImages(nullptr)
- , fImageLayouts(nullptr)
- , fSurfaces(nullptr)
, fCommandPool(VK_NULL_HANDLE)
, fBackbuffers(nullptr) {
@@ -255,7 +250,6 @@ void VulkanWindowContext::createBuffers(VkFormat format) {
// set up initial image layouts and create surfaces
fImageLayouts = new VkImageLayout[fImageCount];
- fRenderTargets = new sk_sp<GrRenderTarget>[fImageCount];
fSurfaces = new sk_sp<SkSurface>[fImageCount];
for (uint32_t i = 0; i < fImageCount; ++i) {
fImageLayouts[i] = VK_IMAGE_LAYOUT_UNDEFINED;
@@ -275,9 +269,10 @@ void VulkanWindowContext::createBuffers(VkFormat format) {
desc.fSampleCnt = 0;
desc.fStencilBits = 0;
desc.fRenderTargetHandle = (GrBackendObject) &info;
- fRenderTargets[i].reset(fContext->textureProvider()->wrapBackendRenderTarget(desc));
-
- fSurfaces[i] = this->createRenderSurface(fRenderTargets[i], 24);
+ SkSurfaceProps props(GrPixelConfigIsSRGB(fPixelConfig)
+ ? SkSurfaceProps::kGammaCorrect_Flag : 0,
+ kUnknown_SkPixelGeometry);
+ fSurfaces[i] = SkSurface::MakeFromBackendRenderTarget(fContext, desc, &props);
}
// create the command pool for the command buffers
@@ -366,11 +361,8 @@ void VulkanWindowContext::destroyBuffers() {
delete[] fBackbuffers;
fBackbuffers = nullptr;
- // Does this actually free the surfaces?
delete[] fSurfaces;
fSurfaces = nullptr;
- delete[] fRenderTargets;
- fRenderTargets = nullptr;
delete[] fImageLayouts;
fImageLayouts = nullptr;
delete[] fImages;
@@ -406,8 +398,7 @@ void VulkanWindowContext::destroyContext() {
fSurface = VK_NULL_HANDLE;
}
- fContext->abandonContext();
- fContext->unref();
+ delete fContext;
fBackendContext.reset(nullptr);
}
@@ -428,7 +419,7 @@ VulkanWindowContext::BackbufferInfo* VulkanWindowContext::getAvailableBackbuffer
return backbuffer;
}
-sk_sp<SkSurface> VulkanWindowContext::getBackbufferSurface() {
+SkSurface* VulkanWindowContext::getBackbufferSurface() {
BackbufferInfo* backbuffer = this->getAvailableBackbuffer();
SkASSERT(backbuffer);
@@ -519,16 +510,14 @@ sk_sp<SkSurface> VulkanWindowContext::getBackbufferSurface() {
QueueSubmit(fBackendContext->fQueue, 1, &submitInfo,
backbuffer->fUsageFences[0]));
- return sk_ref_sp(fSurfaces[backbuffer->fImageIndex].get());
+ return fSurfaces[backbuffer->fImageIndex].get();
}
+
void VulkanWindowContext::swapBuffers() {
BackbufferInfo* backbuffer = fBackbuffers + fCurrentBackbufferIndex;
- this->presentRenderSurface(fSurfaces[backbuffer->fImageIndex],
- fRenderTargets[backbuffer->fImageIndex], 24);
-
VkImageLayout layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
VkPipelineStageFlags srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
diff --git a/tools/viewer/sk_app/VulkanWindowContext.h b/tools/viewer/sk_app/VulkanWindowContext.h
index 8480a9efa8..ec80a3251d 100644
--- a/tools/viewer/sk_app/VulkanWindowContext.h
+++ b/tools/viewer/sk_app/VulkanWindowContext.h
@@ -13,7 +13,8 @@
#include "vk/GrVkBackendContext.h"
#include "WindowContext.h"
-class GrRenderTarget;
+class SkSurface;
+class GrContext;
namespace sk_app {
@@ -34,15 +35,18 @@ public:
return ctx;
}
- sk_sp<SkSurface> getBackbufferSurface() override;
+ SkSurface* getBackbufferSurface() override;
void swapBuffers() override;
+ bool makeCurrent() override { return true; }
+
bool isValid() override { return SkToBool(fBackendContext.get()); }
void resize(uint32_t w, uint32_t h) override {
this->createSwapchain(w, h, fDisplayParams);
}
+ const DisplayParams& getDisplayParams() override { return fDisplayParams; }
void setDisplayParams(const DisplayParams& params) override {
this->createSwapchain(fWidth, fHeight, params);
}
@@ -95,21 +99,23 @@ private:
VkPtr<PFN_vkQueuePresentKHR> fQueuePresentKHR;
VkPtr<PFN_vkCreateSharedSwapchainsKHR> fCreateSharedSwapchainsKHR;
+ GrContext* fContext;
VkSurfaceKHR fSurface;
VkSwapchainKHR fSwapchain;
uint32_t fPresentQueueIndex;
VkQueue fPresentQueue;
int fWidth;
int fHeight;
-
- uint32_t fImageCount;
- VkImage* fImages; // images in the swapchain
- VkImageLayout* fImageLayouts; // layouts of these images when not color attachment
- sk_sp<GrRenderTarget>* fRenderTargets; // wrapped rendertargets for those images
- sk_sp<SkSurface>* fSurfaces; // surfaces client renders to (may not be based on rts)
- VkCommandPool fCommandPool;
- BackbufferInfo* fBackbuffers;
- uint32_t fCurrentBackbufferIndex;
+ DisplayParams fDisplayParams;
+ GrPixelConfig fPixelConfig;
+
+ uint32_t fImageCount;
+ VkImage* fImages; // images in the swapchain
+ VkImageLayout* fImageLayouts; // layouts of these images when not color attachment
+ sk_sp<SkSurface>* fSurfaces; // wrapped surface for those images
+ VkCommandPool fCommandPool;
+ BackbufferInfo* fBackbuffers;
+ uint32_t fCurrentBackbufferIndex;
};
} // namespace sk_app
diff --git a/tools/viewer/sk_app/Window.cpp b/tools/viewer/sk_app/Window.cpp
index 0a7bcf8a70..997500c515 100644
--- a/tools/viewer/sk_app/Window.cpp
+++ b/tools/viewer/sk_app/Window.cpp
@@ -63,7 +63,7 @@ bool Window::onTouch(int owner, InputState state, float x, float y) {
}
void Window::onPaint() {
- sk_sp<SkSurface> backbuffer = fWindowContext->getBackbufferSurface();
+ SkSurface* backbuffer = fWindowContext->getBackbufferSurface();
if (backbuffer) {
// draw into the canvas of this surface
SkCanvas* canvas = backbuffer->getCanvas();
@@ -76,6 +76,7 @@ void Window::onPaint() {
} else {
// try recreating testcontext
}
+
}
void Window::onResize(uint32_t w, uint32_t h) {
diff --git a/tools/viewer/sk_app/Window.h b/tools/viewer/sk_app/Window.h
index 63d5e19e55..72db5cb591 100644
--- a/tools/viewer/sk_app/Window.h
+++ b/tools/viewer/sk_app/Window.h
@@ -33,17 +33,12 @@ public:
virtual bool supportsContentRect() const { return false; }
virtual SkRect getContentRect() { return SkRect::MakeEmpty(); }
- enum BackendType {
+ enum BackEndType {
kNativeGL_BackendType,
- kVulkan_BackendType,
-
- kLast_BackendType = kVulkan_BackendType
- };
- enum {
- kBackendTypeCount = kLast_BackendType + 1
+ kVulkan_BackendType
};
- virtual bool attach(BackendType attachType, const DisplayParams& params) = 0;
+ virtual bool attach(BackEndType attachType, const DisplayParams& params) = 0;
void detach();
// input handling
diff --git a/tools/viewer/sk_app/WindowContext.h b/tools/viewer/sk_app/WindowContext.h
index 1fd921afb2..d48e38e746 100644
--- a/tools/viewer/sk_app/WindowContext.h
+++ b/tools/viewer/sk_app/WindowContext.h
@@ -9,54 +9,30 @@
#include "DisplayParams.h"
#include "GrTypes.h"
-#include "SkRefCnt.h"
-#include "SkSurfaceProps.h"
-class GrContext;
class SkSurface;
-class GrRenderTarget;
namespace sk_app {
+// TODO: fill this out with an interface
class WindowContext {
public:
- WindowContext() : fContext(nullptr)
- , fSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType) {}
-
virtual ~WindowContext() {}
- virtual sk_sp<SkSurface> getBackbufferSurface() = 0;
+ 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;
- const DisplayParams& getDisplayParams() { return fDisplayParams; }
+ virtual const DisplayParams& getDisplayParams() = 0;
virtual void setDisplayParams(const DisplayParams& params) = 0;
- SkSurfaceProps getSurfaceProps() const { return fSurfaceProps; }
- void setSurfaceProps(const SkSurfaceProps& props) {
- fSurfaceProps = props;
- }
-
virtual GrBackendContext getBackendContext() = 0;
-
- sk_sp<SkSurface> createRenderSurface(sk_sp<GrRenderTarget>, int colorBits);
- void presentRenderSurface(sk_sp<SkSurface> renderSurface, sk_sp<GrRenderTarget> rt,
- int colorBits);
-
-protected:
- virtual bool isGpuContext() { return true; }
-
- GrContext* fContext;
-
- int fWidth;
- int fHeight;
- DisplayParams fDisplayParams;
- GrPixelConfig fPixelConfig;
- SkSurfaceProps fSurfaceProps;
};
} // namespace sk_app
diff --git a/tools/viewer/sk_app/android/Window_android.cpp b/tools/viewer/sk_app/android/Window_android.cpp
index 106c40b7b0..9bc79e563e 100644
--- a/tools/viewer/sk_app/android/Window_android.cpp
+++ b/tools/viewer/sk_app/android/Window_android.cpp
@@ -41,7 +41,7 @@ void Window_android::setTitle(const char* title) {
fSkiaAndroidApp->setTitle(title);
}
-bool Window_android::attach(BackendType attachType, const DisplayParams& params) {
+bool Window_android::attach(BackEndType attachType, const DisplayParams& params) {
if (kVulkan_BackendType != attachType) {
return false;
}
diff --git a/tools/viewer/sk_app/android/Window_android.h b/tools/viewer/sk_app/android/Window_android.h
index c1cd1eb200..2bf7bfeaba 100644
--- a/tools/viewer/sk_app/android/Window_android.h
+++ b/tools/viewer/sk_app/android/Window_android.h
@@ -26,7 +26,7 @@ public:
void setTitle(const char*) override;
void show() override {}
- bool attach(BackendType attachType, const DisplayParams& params) override;
+ bool attach(BackEndType attachType, const DisplayParams& params) override;
void inval() override;
bool scaleContentToFit() const override { return true; }
diff --git a/tools/viewer/sk_app/win/GLWindowContext_win.cpp b/tools/viewer/sk_app/win/GLWindowContext_win.cpp
deleted file mode 100644
index 0694db308f..0000000000
--- a/tools/viewer/sk_app/win/GLWindowContext_win.cpp
+++ /dev/null
@@ -1,110 +0,0 @@
-
-/*
- * Copyright 2015 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "GLWindowContext_win.h"
-
-#include <GL/gl.h>
-
- // windows stuff
-#include "win/SkWGL.h"
-#include "Window_win.h"
-
-namespace sk_app {
-
-// platform-dependent create
-GLWindowContext* GLWindowContext::Create(void* platformData, const DisplayParams& params) {
- GLWindowContext_win* ctx = new GLWindowContext_win(platformData, params);
- if (!ctx->isValid()) {
- delete ctx;
- return nullptr;
- }
- return ctx;
-}
-
-GLWindowContext_win::GLWindowContext_win(void* platformData, const DisplayParams& params)
- : GLWindowContext(platformData, params)
- , fHWND(0)
- , fHGLRC(NULL) {
-
- // any config code here (particularly for msaa)?
-
- this->initializeContext(platformData, params);
-}
-
-GLWindowContext_win::~GLWindowContext_win() {
- this->destroyContext();
-}
-
-void GLWindowContext_win::onInitializeContext(void* platformData, const DisplayParams& params) {
-
- ContextPlatformData_win* winPlatformData =
- reinterpret_cast<ContextPlatformData_win*>(platformData);
-
- if (winPlatformData) {
- fHWND = winPlatformData->fHWnd;
- }
- HDC dc = GetDC(fHWND);
-
- fHGLRC = SkCreateWGLContext(dc, params.fMSAASampleCount, params.fDeepColor,
- kGLPreferCompatibilityProfile_SkWGLContextRequest);
- if (NULL == fHGLRC) {
- return;
- }
-
- if (wglMakeCurrent(dc, fHGLRC)) {
- glClearStencil(0);
- glClearColor(0, 0, 0, 0);
- glStencilMask(0xffffffff);
- glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
-
- // use DescribePixelFormat to get the stencil and color bit depth.
- int pixelFormat = GetPixelFormat(dc);
- PIXELFORMATDESCRIPTOR pfd;
- DescribePixelFormat(dc, pixelFormat, sizeof(pfd), &pfd);
- fStencilBits = pfd.cStencilBits;
- // pfd.cColorBits includes alpha, so it will be 32 in 8/8/8/8 and 10/10/10/2
- fColorBits = pfd.cRedBits + pfd.cGreenBits + pfd.cBlueBits;
-
- // Get sample count if the MSAA WGL extension is present
- SkWGLExtensions extensions;
- if (extensions.hasExtension(dc, "WGL_ARB_multisample")) {
- static const int kSampleCountAttr = SK_WGL_SAMPLES;
- extensions.getPixelFormatAttribiv(dc,
- pixelFormat,
- 0,
- 1,
- &kSampleCountAttr,
- &fSampleCount);
- } else {
- fSampleCount = 0;
- }
-
- RECT rect;
- GetClientRect(fHWND, &rect);
- fWidth = rect.right - rect.left;
- fHeight = rect.bottom - rect.top;
- glViewport(0, 0, fWidth, fHeight);
- }
-}
-
-
-void GLWindowContext_win::onDestroyContext() {
- wglMakeCurrent(wglGetCurrentDC(), NULL);
- wglDeleteContext(fHGLRC);
- fHGLRC = NULL;
-}
-
-
-void GLWindowContext_win::onSwapBuffers() {
- HDC dc = GetDC((HWND)fHWND);
- SwapBuffers(dc);
- ReleaseDC((HWND)fHWND, dc);
-}
-
-
-} //namespace sk_app
diff --git a/tools/viewer/sk_app/win/GLWindowContext_win.h b/tools/viewer/sk_app/win/GLWindowContext_win.h
deleted file mode 100644
index f30a805e72..0000000000
--- a/tools/viewer/sk_app/win/GLWindowContext_win.h
+++ /dev/null
@@ -1,37 +0,0 @@
-
-/*
- * 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 GLWindowContext_win_DEFINED
-#define GLWindowContext_win_DEFINED
-
-#include <windows.h>
-#include "../GLWindowContext.h"
-
-namespace sk_app {
-
-class GLWindowContext_win : public GLWindowContext {
-public:
- friend GLWindowContext* GLWindowContext::Create(void* platformData, const DisplayParams&);
-
- ~GLWindowContext_win() override;
-
- void onSwapBuffers() override;
-
- void onInitializeContext(void*, const DisplayParams&) override;
- void onDestroyContext() override;
-
-private:
- GLWindowContext_win(void*, const DisplayParams&);
-
- HWND fHWND;
- HGLRC fHGLRC;
-};
-
-
-}
-
-#endif
diff --git a/tools/viewer/sk_app/win/VulkanWindowContext_win.cpp b/tools/viewer/sk_app/win/VulkanWindowContext_win.cpp
index 460dba1da3..05f3bddd31 100644
--- a/tools/viewer/sk_app/win/VulkanWindowContext_win.cpp
+++ b/tools/viewer/sk_app/win/VulkanWindowContext_win.cpp
@@ -6,8 +6,7 @@
* found in the LICENSE file.
*/
-#include "../VulkanWindowContext.h"
-#include "Window_win.h"
+#include "VulkanWindowContext_win.h"
#include "vk/GrVkInterface.h"
#include "vk/GrVkUtil.h"
diff --git a/tools/viewer/sk_app/win/VulkanWindowContext_win.h b/tools/viewer/sk_app/win/VulkanWindowContext_win.h
new file mode 100644
index 0000000000..e0b5a156f9
--- /dev/null
+++ b/tools/viewer/sk_app/win/VulkanWindowContext_win.h
@@ -0,0 +1,28 @@
+
+/*
+ * 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 VULKANTESTCONTEXT_WIN_DEFINED
+#define VULKANTESTCONTEXT_WIN_DEFINED
+
+#ifdef SK_VULKAN
+
+#include <windows.h>
+#include "../VulkanWindowContext.h"
+
+namespace sk_app {
+
+// for Windows
+struct ContextPlatformData_win {
+ HINSTANCE fHInstance;
+ HWND fHWnd;
+};
+
+}
+
+#endif // SK_VULKAN
+
+#endif
diff --git a/tools/viewer/sk_app/win/Window_win.cpp b/tools/viewer/sk_app/win/Window_win.cpp
index 8355c7295a..241a41caba 100644
--- a/tools/viewer/sk_app/win/Window_win.cpp
+++ b/tools/viewer/sk_app/win/Window_win.cpp
@@ -12,8 +12,7 @@
#include <windowsx.h>
#include "SkUtils.h"
-#include "../GLWindowContext.h"
-#include "../VulkanWindowContext.h"
+#include "VulkanWindowContext_win.h"
namespace sk_app {
@@ -265,21 +264,16 @@ void Window_win::show() {
}
-bool Window_win::attach(BackendType attachType, const DisplayParams& params) {
+bool Window_win::attach(BackEndType attachType, const DisplayParams& params) {
+ if (kVulkan_BackendType != attachType) {
+ return false;
+ }
+
ContextPlatformData_win platformData;
platformData.fHInstance = fHInstance;
platformData.fHWnd = fHWnd;
- switch (attachType) {
- case kNativeGL_BackendType:
- default:
- fWindowContext = GLWindowContext::Create((void*)&platformData, params);
- break;
-
- case kVulkan_BackendType:
- fWindowContext = VulkanWindowContext::Create((void*)&platformData, params);
- break;
- }
+ 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 4dd829a914..3501b06ae4 100644
--- a/tools/viewer/sk_app/win/Window_win.h
+++ b/tools/viewer/sk_app/win/Window_win.h
@@ -13,12 +13,6 @@
namespace sk_app {
-// for Windows
-struct ContextPlatformData_win {
- HINSTANCE fHInstance;
- HWND fHWnd;
-};
-
class Window_win : public Window {
public:
Window_win() : Window() {}
@@ -29,7 +23,7 @@ public:
void setTitle(const char*) override;
void show() override;
- bool attach(BackendType attachType, const DisplayParams& params) override;
+ bool attach(BackEndType attachType, const DisplayParams& params) override;
void inval() override;