Update the sk_app WindowContext to hold a GrDirectContext
This CL is working towards replacing GrContext with the GrDirectContext/ GrRecordingContext pair. Change-Id: Id4488e1280d76a16c37d58bd8d29fb7f8dde6b1d Reviewed-on: https://skia-review.googlesource.com/c/skia/+/301940 Reviewed-by: Adlai Holler <adlai@google.com> Commit-Queue: Robert Phillips <robertphillips@google.com>
This commit is contained in:
parent
71dc916852
commit
ed65339084
1
BUILD.gn
1
BUILD.gn
@ -2247,6 +2247,7 @@ if (skia_enable_tools) {
|
||||
"tools/sk_app/RasterWindowContext.h",
|
||||
"tools/sk_app/Window.cpp",
|
||||
"tools/sk_app/Window.h",
|
||||
"tools/sk_app/WindowContext.cpp",
|
||||
"tools/sk_app/WindowContext.h",
|
||||
]
|
||||
libs = []
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
#include "include/core/SkSurface.h"
|
||||
#include "include/gpu/GrBackendSurface.h"
|
||||
#include "include/gpu/GrContext.h"
|
||||
#include "include/gpu/GrDirectContext.h"
|
||||
#include "src/core/SkAutoMalloc.h"
|
||||
#include "tools/sk_app/DawnWindowContext.h"
|
||||
|
||||
@ -31,11 +31,15 @@ DawnWindowContext::DawnWindowContext(const DisplayParams& params,
|
||||
}
|
||||
|
||||
void DawnWindowContext::initializeContext(int width, int height) {
|
||||
SkASSERT(!fContext);
|
||||
|
||||
fWidth = width;
|
||||
fHeight = height;
|
||||
fDevice = onInitializeContext();
|
||||
fContext = GrContext::MakeDawn(fDevice, fDisplayParams.fGrContextOptions);
|
||||
|
||||
// CONTEXT TODO: MakeDawn should return an sk_sp<GrDirectContext>
|
||||
auto tmp = GrContext::MakeDawn(fDevice, fDisplayParams.fGrContextOptions);
|
||||
fContext = sk_ref_sp<GrDirectContext>(tmp->asDirectContext());
|
||||
if (!fContext) {
|
||||
return;
|
||||
}
|
||||
|
@ -15,8 +15,6 @@
|
||||
#include "dawn_native/DawnNative.h"
|
||||
#include "dawn/dawn_wsi.h"
|
||||
|
||||
class GrContext;
|
||||
|
||||
namespace sk_app {
|
||||
|
||||
class DawnWindowContext : public WindowContext {
|
||||
|
@ -9,7 +9,7 @@
|
||||
#include "include/core/SkCanvas.h"
|
||||
#include "include/core/SkSurface.h"
|
||||
#include "include/gpu/GrBackendSurface.h"
|
||||
#include "include/gpu/GrContext.h"
|
||||
#include "include/gpu/GrDirectContext.h"
|
||||
#include "src/core/SkMathPriv.h"
|
||||
#include "src/gpu/GrCaps.h"
|
||||
#include "src/gpu/GrContextPriv.h"
|
||||
@ -21,9 +21,9 @@
|
||||
namespace sk_app {
|
||||
|
||||
GLWindowContext::GLWindowContext(const DisplayParams& params)
|
||||
: WindowContext(params)
|
||||
, fBackendContext(nullptr)
|
||||
, fSurface(nullptr) {
|
||||
: WindowContext(params)
|
||||
, fBackendContext(nullptr)
|
||||
, fSurface(nullptr) {
|
||||
fDisplayParams.fMSAASampleCount = GrNextPow2(fDisplayParams.fMSAASampleCount);
|
||||
}
|
||||
|
||||
@ -31,7 +31,10 @@ void GLWindowContext::initializeContext() {
|
||||
SkASSERT(!fContext);
|
||||
|
||||
fBackendContext = this->onInitializeContext();
|
||||
fContext = GrContext::MakeGL(fBackendContext, fDisplayParams.fGrContextOptions);
|
||||
|
||||
// CONTEXT TODO: MakeGL should return an sk_sp<GrDirectContext>
|
||||
auto tmp = GrContext::MakeGL(fBackendContext, fDisplayParams.fGrContextOptions);
|
||||
fContext = sk_ref_sp<GrDirectContext>(tmp->asDirectContext());
|
||||
if (!fContext && fDisplayParams.fMSAASampleCount > 1) {
|
||||
fDisplayParams.fMSAASampleCount /= 2;
|
||||
this->initializeContext();
|
||||
|
@ -16,8 +16,6 @@
|
||||
|
||||
#include "tools/sk_app/WindowContext.h"
|
||||
|
||||
class GrContext;
|
||||
|
||||
namespace sk_app {
|
||||
|
||||
class GLWindowContext : public WindowContext {
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include "include/core/SkCanvas.h"
|
||||
#include "include/core/SkSurface.h"
|
||||
#include "include/gpu/GrBackendSurface.h"
|
||||
#include "include/gpu/GrContext.h"
|
||||
#include "include/gpu/GrDirectContext.h"
|
||||
#include "include/gpu/mtl/GrMtlTypes.h"
|
||||
#include "src/core/SkMathPriv.h"
|
||||
#include "src/gpu/GrCaps.h"
|
||||
@ -22,8 +22,8 @@ using sk_app::MetalWindowContext;
|
||||
namespace sk_app {
|
||||
|
||||
MetalWindowContext::MetalWindowContext(const DisplayParams& params)
|
||||
: WindowContext(params)
|
||||
, fValid(false) {
|
||||
: WindowContext(params)
|
||||
, fValid(false) {
|
||||
|
||||
fDisplayParams.fMSAASampleCount = GrNextPow2(fDisplayParams.fMSAASampleCount);
|
||||
}
|
||||
@ -48,8 +48,10 @@ void MetalWindowContext::initializeContext() {
|
||||
|
||||
fValid = this->onInitializeContext();
|
||||
|
||||
fContext = GrContext::MakeMetal((__bridge void*)fDevice, (__bridge void*)fQueue,
|
||||
// CONTEXT TODO: MakeMetal should return an sk_sp<GrDirectContext>
|
||||
auto tmp = GrContext::MakeMetal((__bridge void*)fDevice, (__bridge void*)fQueue,
|
||||
fDisplayParams.fGrContextOptions);
|
||||
fContext = sk_ref_sp<GrDirectContext>(tmp->asDirectContext());
|
||||
if (!fContext && fDisplayParams.fMSAASampleCount > 1) {
|
||||
fDisplayParams.fMSAASampleCount /= 2;
|
||||
this->initializeContext();
|
||||
|
@ -49,6 +49,7 @@ VulkanWindowContext::VulkanWindowContext(const DisplayParams& params,
|
||||
}
|
||||
|
||||
void VulkanWindowContext::initializeContext() {
|
||||
SkASSERT(!fContext);
|
||||
// any config code here (particularly for msaa)?
|
||||
|
||||
PFN_vkGetInstanceProcAddr getInstanceProc = fGetInstanceProcAddr;
|
||||
@ -117,7 +118,9 @@ void VulkanWindowContext::initializeContext() {
|
||||
GET_DEV_PROC(QueuePresentKHR);
|
||||
GET_DEV_PROC(GetDeviceQueue);
|
||||
|
||||
fContext = GrContext::MakeVulkan(backendContext, fDisplayParams.fGrContextOptions);
|
||||
// CONTEXT TODO: MakeVulkan should return an sk_sp<GrDirectContext>
|
||||
auto tmp = GrContext::MakeVulkan(backendContext, fDisplayParams.fGrContextOptions);
|
||||
fContext = sk_ref_sp<GrDirectContext>(tmp->asDirectContext());
|
||||
|
||||
fSurface = fCreateVkSurfaceFn(fInstance);
|
||||
if (VK_NULL_HANDLE == fSurface) {
|
||||
|
@ -137,11 +137,11 @@ int Window::stencilBits() const {
|
||||
return fWindowContext->stencilBits();
|
||||
}
|
||||
|
||||
GrContext* Window::getGrContext() const {
|
||||
GrDirectContext* Window::directContext() const {
|
||||
if (!fWindowContext) {
|
||||
return nullptr;
|
||||
}
|
||||
return fWindowContext->getGrContext();
|
||||
return fWindowContext->directContext();
|
||||
}
|
||||
|
||||
void Window::inval() {
|
||||
|
@ -16,7 +16,7 @@
|
||||
#include "tools/skui/Key.h"
|
||||
#include "tools/skui/ModifierKey.h"
|
||||
|
||||
class GrContext;
|
||||
class GrDirectContext;
|
||||
class SkCanvas;
|
||||
class SkSurface;
|
||||
class SkSurfaceProps;
|
||||
@ -135,7 +135,7 @@ public:
|
||||
int stencilBits() const;
|
||||
|
||||
// Returns null if there is not a GPU backend or if the backend is not yet created.
|
||||
GrContext* getGrContext() const;
|
||||
GrDirectContext* directContext() const;
|
||||
|
||||
protected:
|
||||
Window();
|
||||
|
21
tools/sk_app/WindowContext.cpp
Normal file
21
tools/sk_app/WindowContext.cpp
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright 2020 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/WindowContext.h"
|
||||
|
||||
#include "include/gpu/GrDirectContext.h"
|
||||
|
||||
namespace sk_app {
|
||||
|
||||
WindowContext::WindowContext(const DisplayParams& params)
|
||||
: fDisplayParams(params)
|
||||
, fSampleCount(1)
|
||||
, fStencilBits(0) {}
|
||||
|
||||
WindowContext::~WindowContext() {}
|
||||
|
||||
} //namespace sk_app
|
@ -9,24 +9,19 @@
|
||||
|
||||
#include "include/core/SkRefCnt.h"
|
||||
#include "include/core/SkSurfaceProps.h"
|
||||
#include "include/gpu/GrContext.h"
|
||||
#include "include/gpu/GrTypes.h"
|
||||
#include "tools/sk_app/DisplayParams.h"
|
||||
|
||||
class GrDirectContext;
|
||||
class SkSurface;
|
||||
class GrRenderTarget;
|
||||
|
||||
namespace sk_app {
|
||||
|
||||
class WindowContext {
|
||||
public:
|
||||
WindowContext(const DisplayParams& params)
|
||||
: fContext(nullptr)
|
||||
, fDisplayParams(params)
|
||||
, fSampleCount(1)
|
||||
, fStencilBits(0) {}
|
||||
WindowContext(const DisplayParams&);
|
||||
|
||||
virtual ~WindowContext() {}
|
||||
virtual ~WindowContext();
|
||||
|
||||
virtual sk_sp<SkSurface> getBackbufferSurface() = 0;
|
||||
|
||||
@ -39,7 +34,7 @@ public:
|
||||
const DisplayParams& getDisplayParams() { return fDisplayParams; }
|
||||
virtual void setDisplayParams(const DisplayParams& params) = 0;
|
||||
|
||||
GrContext* getGrContext() const { return fContext.get(); }
|
||||
GrDirectContext* directContext() const { return fContext.get(); }
|
||||
|
||||
int width() const { return fWidth; }
|
||||
int height() const { return fHeight; }
|
||||
@ -49,7 +44,7 @@ public:
|
||||
protected:
|
||||
virtual bool isGpuContext() { return true; }
|
||||
|
||||
sk_sp<GrContext> fContext;
|
||||
sk_sp<GrDirectContext> fContext;
|
||||
|
||||
int fWidth;
|
||||
int fHeight;
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "tools/gpu/d3d/D3DTestUtils.h"
|
||||
|
||||
#include "include/core/SkSurface.h"
|
||||
#include "include/gpu/GrDirectContext.h"
|
||||
#include "include/gpu/d3d/GrD3DBackendContext.h"
|
||||
|
||||
#include <d3d12.h>
|
||||
@ -81,7 +82,9 @@ void D3D12WindowContext::initializeContext() {
|
||||
fDevice = backendContext.fDevice;
|
||||
fQueue = backendContext.fQueue;
|
||||
|
||||
fContext = GrContext::MakeDirect3D(backendContext, fDisplayParams.fGrContextOptions);
|
||||
// CONTEXT TODO: MakeDirect3D should return an sk_sp<GrDirectContext>
|
||||
auto tmp = GrContext::MakeDirect3D(backendContext, fDisplayParams.fGrContextOptions);
|
||||
fContext = sk_ref_sp<GrDirectContext>(tmp->asDirectContext());
|
||||
SkASSERT(fContext);
|
||||
|
||||
// Make the swapchain
|
||||
|
@ -11,7 +11,7 @@
|
||||
#include "include/core/SkPictureRecorder.h"
|
||||
#include "include/core/SkStream.h"
|
||||
#include "include/core/SkSurface.h"
|
||||
#include "include/gpu/GrContext.h"
|
||||
#include "include/gpu/GrDirectContext.h"
|
||||
#include "include/private/SkTo.h"
|
||||
#include "include/utils/SkPaintFilterCanvas.h"
|
||||
#include "src/core/SkColorSpacePriv.h"
|
||||
@ -1517,9 +1517,9 @@ void Viewer::onPaint(SkSurface* surface) {
|
||||
|
||||
this->drawImGui();
|
||||
|
||||
if (GrContext* ctx = fWindow->getGrContext()) {
|
||||
if (auto direct = fWindow->directContext()) {
|
||||
// Clean out cache items that haven't been used in more than 10 seconds.
|
||||
ctx->performDeferredCleanup(std::chrono::seconds(10));
|
||||
direct->performDeferredCleanup(std::chrono::seconds(10));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1743,7 +1743,7 @@ void Viewer::drawImGui() {
|
||||
ImGui::SetNextWindowSize(ImVec2(400, 400), ImGuiCond_FirstUseEver);
|
||||
DisplayParams params = fWindow->getRequestedDisplayParams();
|
||||
bool paramsChanged = false;
|
||||
const GrContext* ctx = fWindow->getGrContext();
|
||||
auto ctx = fWindow->directContext();
|
||||
|
||||
if (ImGui::Begin("Tools", &fShowImGuiDebugWindow,
|
||||
ImGuiWindowFlags_AlwaysVerticalScrollbar)) {
|
||||
@ -2321,7 +2321,7 @@ void Viewer::drawImGui() {
|
||||
|
||||
if (doLoad) {
|
||||
fPersistentCache.reset();
|
||||
fWindow->getGrContext()->priv().getGpu()->resetShaderCacheForTesting();
|
||||
ctx->priv().getGpu()->resetShaderCacheForTesting();
|
||||
gLoadPending = true;
|
||||
}
|
||||
// We don't support updating SPIRV shaders. We could re-assemble them (with edits),
|
||||
@ -2331,7 +2331,7 @@ void Viewer::drawImGui() {
|
||||
}
|
||||
if (doSave) {
|
||||
fPersistentCache.reset();
|
||||
fWindow->getGrContext()->priv().getGpu()->resetShaderCacheForTesting();
|
||||
ctx->priv().getGpu()->resetShaderCacheForTesting();
|
||||
for (auto& entry : fCachedShaders) {
|
||||
SkSL::String backup = entry.fShader[kFragment_GrShaderType];
|
||||
if (entry.fHovered) {
|
||||
@ -2527,7 +2527,7 @@ void Viewer::updateUIState() {
|
||||
GpuPathRenderers pr = fWindow->getRequestedDisplayParams().fGrContextOptions.fGpuPathRenderers;
|
||||
WriteStateObject(writer, kPathRendererStateName, gPathRendererNames[pr].c_str(),
|
||||
[this](SkJSONWriter& writer) {
|
||||
const GrContext* ctx = fWindow->getGrContext();
|
||||
auto ctx = fWindow->directContext();
|
||||
if (!ctx) {
|
||||
writer.appendString("Software");
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user