From fbdc080d3cae3695544ffbc05c6ff6f5b4514c02 Mon Sep 17 00:00:00 2001 From: Jim Van Verth Date: Tue, 2 May 2017 16:15:53 -0400 Subject: Add wireframe mode to Viewer. Change-Id: I0ff11088465a4702acf9841a791d76f286ddbaf1 Reviewed-on: https://skia-review.googlesource.com/15147 Commit-Queue: Jim Van Verth Reviewed-by: Brian Osman --- include/gpu/GrCaps.h | 5 ++++- include/gpu/GrContextOptions.h | 5 +++++ src/gpu/GrCaps.cpp | 1 + src/gpu/gl/GrGLGpu.cpp | 6 +++++- src/gpu/vk/GrVkPipeline.cpp | 6 ++++-- tools/viewer/Viewer.cpp | 6 ++++++ tools/viewer/sk_app/GLWindowContext.cpp | 3 +-- tools/viewer/sk_app/RasterWindowContext.h | 2 ++ tools/viewer/sk_app/VulkanWindowContext.cpp | 15 ++++++++++----- tools/viewer/sk_app/VulkanWindowContext.h | 9 ++++++++- tools/viewer/sk_app/WindowContext.h | 10 ++++++---- tools/viewer/sk_app/android/GLWindowContext_android.cpp | 7 +++++-- .../viewer/sk_app/android/RasterWindowContext_android.cpp | 6 ++++-- tools/viewer/sk_app/unix/GLWindowContext_unix.cpp | 4 +++- tools/viewer/sk_app/unix/RasterWindowContext_unix.cpp | 6 ++++-- tools/viewer/sk_app/win/GLWindowContext_win.cpp | 4 +++- tools/viewer/sk_app/win/RasterWindowContext_win.cpp | 7 +++++-- 17 files changed, 76 insertions(+), 26 deletions(-) diff --git a/include/gpu/GrCaps.h b/include/gpu/GrCaps.h index abd10a1c01..f99405e27f 100644 --- a/include/gpu/GrCaps.h +++ b/include/gpu/GrCaps.h @@ -178,6 +178,8 @@ public: is not initialized (even if not read by draw calls). */ bool mustClearUploadedBufferData() const { return fMustClearUploadedBufferData; } + bool wireframeMode() const { return fWireframeMode; } + bool sampleShadingSupport() const { return fSampleShadingSupport; } bool fenceSyncSupport() const { return fFenceSyncSupport; } @@ -260,7 +262,8 @@ private: virtual void onApplyOptionsOverrides(const GrContextOptions&) {} bool fSuppressPrints : 1; - bool fImmediateFlush: 1; + bool fImmediateFlush : 1; + bool fWireframeMode : 1; typedef SkRefCnt INHERITED; }; diff --git a/include/gpu/GrContextOptions.h b/include/gpu/GrContextOptions.h index f1517040e7..aa7bcf285b 100644 --- a/include/gpu/GrContextOptions.h +++ b/include/gpu/GrContextOptions.h @@ -78,6 +78,11 @@ struct GrContextOptions { */ bool fSuppressPathRendering = false; + /** + * Render everything in wireframe + */ + bool fWireframeMode = false; + /** * Allows the client to include or exclude specific GPU path renderers. */ diff --git a/src/gpu/GrCaps.cpp b/src/gpu/GrCaps.cpp index ade64d6588..e9a1893169 100644 --- a/src/gpu/GrCaps.cpp +++ b/src/gpu/GrCaps.cpp @@ -74,6 +74,7 @@ GrCaps::GrCaps(const GrContextOptions& options) { fSuppressPrints = options.fSuppressPrints; fImmediateFlush = options.fImmediateMode; + fWireframeMode = options.fWireframeMode; fBufferMapThreshold = options.fBufferMapThreshold; fUseDrawInsteadOfPartialRenderTargetWrite = options.fUseDrawInsteadOfPartialRenderTargetWrite; fUseDrawInsteadOfAllRenderTargetWrites = false; diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp index e057b3455c..4aa19203be 100644 --- a/src/gpu/gl/GrGLGpu.cpp +++ b/src/gpu/gl/GrGLGpu.cpp @@ -399,7 +399,11 @@ void GrGLGpu::onResetContext(uint32_t resetBits) { } GL_CALL(Disable(GR_GL_POLYGON_OFFSET_FILL)); - GL_CALL(PolygonMode(GR_GL_FRONT_AND_BACK, GR_GL_FILL)); + if (this->caps()->wireframeMode()) { + GL_CALL(PolygonMode(GR_GL_FRONT_AND_BACK, GR_GL_LINE)); + } else { + GL_CALL(PolygonMode(GR_GL_FRONT_AND_BACK, GR_GL_FILL)); + } #endif // Since ES doesn't support glPointSize at all we always use the VS to // set the point size diff --git a/src/gpu/vk/GrVkPipeline.cpp b/src/gpu/vk/GrVkPipeline.cpp index 7c0aeb4b15..8310199b39 100644 --- a/src/gpu/vk/GrVkPipeline.cpp +++ b/src/gpu/vk/GrVkPipeline.cpp @@ -375,6 +375,7 @@ static VkCullModeFlags draw_face_to_vk_cull_mode(GrDrawFace drawFace) { } static void setup_raster_state(const GrPipeline& pipeline, + const GrCaps* caps, VkPipelineRasterizationStateCreateInfo* rasterInfo) { memset(rasterInfo, 0, sizeof(VkPipelineRasterizationStateCreateInfo)); rasterInfo->sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; @@ -382,7 +383,8 @@ static void setup_raster_state(const GrPipeline& pipeline, rasterInfo->flags = 0; rasterInfo->depthClampEnable = VK_FALSE; rasterInfo->rasterizerDiscardEnable = VK_FALSE; - rasterInfo->polygonMode = VK_POLYGON_MODE_FILL; + rasterInfo->polygonMode = caps->wireframeMode() ? VK_POLYGON_MODE_LINE + : VK_POLYGON_MODE_FILL; rasterInfo->cullMode = draw_face_to_vk_cull_mode(pipeline.getDrawFace()); rasterInfo->frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; rasterInfo->depthBiasEnable = VK_FALSE; @@ -439,7 +441,7 @@ GrVkPipeline* GrVkPipeline::Create(GrVkGpu* gpu, const GrPipeline& pipeline, setup_color_blend_state(pipeline, &colorBlendInfo, attachmentStates); VkPipelineRasterizationStateCreateInfo rasterInfo; - setup_raster_state(pipeline, &rasterInfo); + setup_raster_state(pipeline, gpu->caps(), &rasterInfo); VkDynamicState dynamicStates[3]; VkPipelineDynamicStateCreateInfo dynamicInfo; diff --git a/tools/viewer/Viewer.cpp b/tools/viewer/Viewer.cpp index e53bd1ab64..5854451a41 100644 --- a/tools/viewer/Viewer.cpp +++ b/tools/viewer/Viewer.cpp @@ -690,6 +690,7 @@ void Viewer::setBackend(sk_app::Window::BackendType backendType) { // Switching from OpenGL to Vulkan in the same window is problematic at this point on // Windows, so we just delete the window and recreate it. if (sk_app::Window::kVulkan_BackendType == fBackendType) { + DisplayParams params = fWindow->getRequestedDisplayParams(); delete fWindow; fWindow = Window::CreateNativeWindow(nullptr); @@ -703,6 +704,7 @@ void Viewer::setBackend(sk_app::Window::BackendType backendType) { fWindow->registerMouseWheelFunc(on_mouse_wheel_handler, this); fWindow->registerKeyFunc(on_key_handler, this); fWindow->registerCharFunc(on_char_handler, this); + fWindow->setRequestedDisplayParams(params); } #endif @@ -1022,6 +1024,10 @@ void Viewer::drawImGui(SkCanvas* canvas) { if (ctx && ImGui::Checkbox("Instanced Rendering", inst)) { paramsChanged = true; } + bool* wire = ¶ms.fGrContextOptions.fWireframeMode; + if (ctx && ImGui::Checkbox("Wireframe Mode", wire)) { + paramsChanged = true; + } if (ctx) { int sampleCount = fWindow->sampleCount(); diff --git a/tools/viewer/sk_app/GLWindowContext.cpp b/tools/viewer/sk_app/GLWindowContext.cpp index 6195199ce0..faa78ab09c 100644 --- a/tools/viewer/sk_app/GLWindowContext.cpp +++ b/tools/viewer/sk_app/GLWindowContext.cpp @@ -22,10 +22,9 @@ namespace sk_app { GLWindowContext::GLWindowContext(const DisplayParams& params) - : WindowContext() + : WindowContext(params) , fBackendContext(nullptr) , fSurface(nullptr) { - fDisplayParams = params; fDisplayParams.fMSAASampleCount = fDisplayParams.fMSAASampleCount ? GrNextPow2(fDisplayParams.fMSAASampleCount) : 0; diff --git a/tools/viewer/sk_app/RasterWindowContext.h b/tools/viewer/sk_app/RasterWindowContext.h index 0393e9a0ba..75bde03ad7 100644 --- a/tools/viewer/sk_app/RasterWindowContext.h +++ b/tools/viewer/sk_app/RasterWindowContext.h @@ -14,6 +14,8 @@ namespace sk_app { class RasterWindowContext : public WindowContext { public: + RasterWindowContext(const DisplayParams& params) : WindowContext(params) {} + // Explicitly convert nullptr to GrBackendContext is needed for compiling GrBackendContext getBackendContext() override { return (GrBackendContext) nullptr; } diff --git a/tools/viewer/sk_app/VulkanWindowContext.cpp b/tools/viewer/sk_app/VulkanWindowContext.cpp index 809c6142ac..e53cc7c1c2 100644 --- a/tools/viewer/sk_app/VulkanWindowContext.cpp +++ b/tools/viewer/sk_app/VulkanWindowContext.cpp @@ -31,7 +31,9 @@ namespace sk_app { VulkanWindowContext::VulkanWindowContext(const DisplayParams& params, CreateVkSurfaceFn createVkSurface, CanPresentFn canPresent) - : WindowContext() + : WindowContext(params) + , fCreateVkSurfaceFn(createVkSurface) + , fCanPresentFn(canPresent) , fSurface(VK_NULL_HANDLE) , fSwapchain(VK_NULL_HANDLE) , fImages(nullptr) @@ -39,10 +41,13 @@ VulkanWindowContext::VulkanWindowContext(const DisplayParams& params, , fSurfaces(nullptr) , fCommandPool(VK_NULL_HANDLE) , fBackbuffers(nullptr) { + this->initializeContext(); +} +void VulkanWindowContext::initializeContext() { // any config code here (particularly for msaa)? fBackendContext.reset(GrVkBackendContext::Create(vkGetInstanceProcAddr, vkGetDeviceProcAddr, - &fPresentQueueIndex, canPresent)); + &fPresentQueueIndex, fCanPresentFn)); if (!(fBackendContext->fExtensions & kKHR_surface_GrVkExtensionFlag) || !(fBackendContext->fExtensions & kKHR_swapchain_GrVkExtensionFlag)) { @@ -64,9 +69,9 @@ VulkanWindowContext::VulkanWindowContext(const DisplayParams& params, GET_DEV_PROC(QueuePresentKHR); fContext = GrContext::Create(kVulkan_GrBackend, (GrBackendContext) fBackendContext.get(), - params.fGrContextOptions); + fDisplayParams.fGrContextOptions); - fSurface = createVkSurface(instance); + fSurface = fCreateVkSurfaceFn(instance); if (VK_NULL_HANDLE == fSurface) { fBackendContext.reset(nullptr); return; @@ -81,7 +86,7 @@ VulkanWindowContext::VulkanWindowContext(const DisplayParams& params, return; } - if (!this->createSwapchain(-1, -1, params)) { + if (!this->createSwapchain(-1, -1, fDisplayParams)) { this->destroyContext(); return; } diff --git a/tools/viewer/sk_app/VulkanWindowContext.h b/tools/viewer/sk_app/VulkanWindowContext.h index cafaeada1b..81e5f3d2d5 100644 --- a/tools/viewer/sk_app/VulkanWindowContext.h +++ b/tools/viewer/sk_app/VulkanWindowContext.h @@ -33,7 +33,9 @@ public: } void setDisplayParams(const DisplayParams& params) override { - this->createSwapchain(fWidth, fHeight, params); + this->destroyContext(); + fDisplayParams = params; + this->initializeContext(); } GrBackendContext getBackendContext() override { @@ -48,6 +50,7 @@ public: VulkanWindowContext(const DisplayParams&, CreateVkSurfaceFn, CanPresentFn); private: + void initializeContext(); void destroyContext(); struct BackbufferInfo { @@ -75,6 +78,10 @@ private: FNPTR_TYPE fPtr; }; + // Create functions + CreateVkSurfaceFn fCreateVkSurfaceFn; + CanPresentFn fCanPresentFn; + // WSI interface functions VkPtr fDestroySurfaceKHR; VkPtr fGetPhysicalDeviceSurfaceSupportKHR; diff --git a/tools/viewer/sk_app/WindowContext.h b/tools/viewer/sk_app/WindowContext.h index 75b52b9c99..fbd2756b67 100644 --- a/tools/viewer/sk_app/WindowContext.h +++ b/tools/viewer/sk_app/WindowContext.h @@ -20,10 +20,12 @@ namespace sk_app { class WindowContext { public: - WindowContext() : fContext(nullptr) - , fSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType) - , fSampleCount(0) - , fStencilBits(0) {} + WindowContext(const DisplayParams& params) + : fContext(nullptr) + , fDisplayParams(params) + , fSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType) + , fSampleCount(0) + , fStencilBits(0) {} virtual ~WindowContext() {} diff --git a/tools/viewer/sk_app/android/GLWindowContext_android.cpp b/tools/viewer/sk_app/android/GLWindowContext_android.cpp index 1529b3a4d1..b7a1fa8a90 100644 --- a/tools/viewer/sk_app/android/GLWindowContext_android.cpp +++ b/tools/viewer/sk_app/android/GLWindowContext_android.cpp @@ -36,10 +36,13 @@ private: // For setDisplayParams and resize which call onInitializeContext with null platformData ANativeWindow* fNativeWindow = nullptr; + + typedef GLWindowContext INHERITED; }; -GLWindowContext_android::GLWindowContext_android(ANativeWindow* window, const DisplayParams& params) - : GLWindowContext(params) +GLWindowContext_android::GLWindowContext_android(ANativeWindow* window, + const DisplayParams& params) + : INHERITED(params) , fDisplay(EGL_NO_DISPLAY) , fEGLContext(EGL_NO_CONTEXT) , fSurface(EGL_NO_SURFACE) diff --git a/tools/viewer/sk_app/android/RasterWindowContext_android.cpp b/tools/viewer/sk_app/android/RasterWindowContext_android.cpp index 7077e2cfee..101e51ef42 100644 --- a/tools/viewer/sk_app/android/RasterWindowContext_android.cpp +++ b/tools/viewer/sk_app/android/RasterWindowContext_android.cpp @@ -32,11 +32,13 @@ private: ANativeWindow* fNativeWindow = nullptr; ANativeWindow_Buffer fBuffer; ARect fBounds; + + typedef RasterWindowContext INHERITED; }; RasterWindowContext_android::RasterWindowContext_android(ANativeWindow* window, - const DisplayParams& params) { - fDisplayParams = params; + const DisplayParams& params) + : INHERITED(params) { fNativeWindow = window; fWidth = ANativeWindow_getWidth(fNativeWindow); fHeight = ANativeWindow_getHeight(fNativeWindow); diff --git a/tools/viewer/sk_app/unix/GLWindowContext_unix.cpp b/tools/viewer/sk_app/unix/GLWindowContext_unix.cpp index 530a5b67dd..ce2727e111 100644 --- a/tools/viewer/sk_app/unix/GLWindowContext_unix.cpp +++ b/tools/viewer/sk_app/unix/GLWindowContext_unix.cpp @@ -37,10 +37,12 @@ private: GLXFBConfig* fFBConfig; XVisualInfo* fVisualInfo; GLXContext fGLContext; + + typedef GLWindowContext INHERITED; }; GLWindowContext_xlib::GLWindowContext_xlib(const XlibWindowInfo& winInfo, const DisplayParams& params) - : GLWindowContext(params) + : INHERITED(params) , fDisplay(winInfo.fDisplay) , fWindow(winInfo.fWindow) , fFBConfig(winInfo.fFBConfig) diff --git a/tools/viewer/sk_app/unix/RasterWindowContext_unix.cpp b/tools/viewer/sk_app/unix/RasterWindowContext_unix.cpp index 73846a11ab..6bfa6fd0be 100644 --- a/tools/viewer/sk_app/unix/RasterWindowContext_unix.cpp +++ b/tools/viewer/sk_app/unix/RasterWindowContext_unix.cpp @@ -29,13 +29,15 @@ protected: Display* fDisplay; XWindow fWindow; GC fGC; + + typedef RasterWindowContext INHERITED; }; RasterWindowContext_xlib::RasterWindowContext_xlib(Display* display, XWindow window, int width, int height, const DisplayParams& params) - : fDisplay(display) + : INHERITED(params) + , fDisplay(display) , fWindow(window) { - fDisplayParams = params; fGC = XCreateGC(fDisplay, fWindow, 0, nullptr); this->resize(width, height); fWidth = width; diff --git a/tools/viewer/sk_app/win/GLWindowContext_win.cpp b/tools/viewer/sk_app/win/GLWindowContext_win.cpp index 24db9659f0..20c3d9140a 100644 --- a/tools/viewer/sk_app/win/GLWindowContext_win.cpp +++ b/tools/viewer/sk_app/win/GLWindowContext_win.cpp @@ -33,10 +33,12 @@ protected: private: HWND fHWND; HGLRC fHGLRC; + + typedef GLWindowContext INHERITED; }; GLWindowContext_win::GLWindowContext_win(HWND wnd, const DisplayParams& params) - : GLWindowContext(params) + : INHERITED(params) , fHWND(wnd) , fHGLRC(NULL) { diff --git a/tools/viewer/sk_app/win/RasterWindowContext_win.cpp b/tools/viewer/sk_app/win/RasterWindowContext_win.cpp index 96fe8f22a9..85bb65e674 100644 --- a/tools/viewer/sk_app/win/RasterWindowContext_win.cpp +++ b/tools/viewer/sk_app/win/RasterWindowContext_win.cpp @@ -31,11 +31,14 @@ protected: SkAutoMalloc fSurfaceMemory; sk_sp fBackbufferSurface; HWND fWnd; + +private: + typedef RasterWindowContext INHERITED; }; RasterWindowContext_win::RasterWindowContext_win(HWND wnd, const DisplayParams& params) - : fWnd(wnd) { - fDisplayParams = params; + : INHERITED(params) + , fWnd(wnd) { RECT rect; GetWindowRect(wnd, &rect); this->resize(rect.right - rect.left, rect.bottom - rect.top); -- cgit v1.2.3