Take GrContext private, GrDDLContext inherit from GrRecordingContext

Woo!

Change-Id: I8d201b709343dc18cad31ea740575285dd035f35
Docs-Preview: https://skia.org/?cl=317436
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/317436
Reviewed-by: Robert Phillips <robertphillips@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Adlai Holler <adlai@google.com>
This commit is contained in:
Adlai Holler 2020-09-22 10:21:31 -04:00 committed by Skia Commit-Bot
parent 331699c9ea
commit d2daa94ede
11 changed files with 36 additions and 201 deletions

View File

@ -31,7 +31,7 @@
#ifdef SK_GL
#include "include/core/SkImageInfo.h"
#include "include/gpu/GrBackendSurface.h"
#include "include/gpu/GrContext.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/gl/GrGLInterface.h"
#include "include/gpu/gl/GrGLTypes.h"
@ -214,6 +214,7 @@ SkImageInfo toSkImageInfo(const SimpleImageInfo& sii) {
}
#ifdef SK_GL
// TODO: Migrate this to GrDirectContext.
sk_sp<GrContext> MakeGrContext(EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context)
{
EMSCRIPTEN_RESULT r = emscripten_webgl_make_context_current(context);
@ -221,10 +222,10 @@ sk_sp<GrContext> MakeGrContext(EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context)
printf("failed to make webgl context current %d\n", r);
return nullptr;
}
// setup GrContext
// setup GrDirectContext
auto interface = GrGLMakeNativeInterface();
// setup contexts
sk_sp<GrContext> grContext(GrContext::MakeGL(interface));
sk_sp<GrContext> grContext(GrDirectContext::MakeGL(interface));
return grContext;
}

View File

@ -33,7 +33,7 @@
#ifdef SK_GL
#include "include/gpu/GrBackendSurface.h"
#include "include/gpu/GrContext.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/gl/GrGLInterface.h"
#include "include/gpu/gl/GrGLTypes.h"
@ -436,7 +436,7 @@ sk_sp<GrContext> MakeGrContext(EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context)
return nullptr;
}
// setup contexts
sk_sp<GrContext> grContext(GrContext::MakeGL(interface));
sk_sp<GrContext> grContext(GrDirectContext::MakeGL(interface));
return grContext;
}

View File

@ -13,7 +13,6 @@ skia_gpu_sources = [
"$_include/gpu/GrBackendSurface.h",
"$_include/gpu/GrBackendSurfaceMutableState.h",
"$_include/gpu/GrConfig.h",
"$_include/gpu/GrContext.h",
"$_include/gpu/GrContextOptions.h",
"$_include/gpu/GrContextThreadSafeProxy.h",
"$_include/gpu/GrDirectContext.h",
@ -22,6 +21,7 @@ skia_gpu_sources = [
"$_include/gpu/GrTypes.h",
# Private includes
"$_include/private/GrContext.h",
"$_include/private/GrContext_Base.h",
"$_include/private/GrGLTypesPriv.h",
"$_include/private/GrImageContext.h",

View File

@ -8,7 +8,7 @@
#ifndef GrDirectContext_DEFINED
#define GrDirectContext_DEFINED
#include "include/gpu/GrContext.h"
#include "include/private/GrContext.h"
class GrAtlasManager;
class GrSmallPathAtlasMgr;

View File

@ -49,62 +49,6 @@ class SkTraceMemoryDump;
class SK_API GrContext : public GrRecordingContext {
public:
#ifndef SK_DISABLE_LEGACY_CONTEXT_FACTORIES
#ifdef SK_GL
/**
* Creates a GrContext for a backend context. If no GrGLInterface is provided then the result of
* GrGLMakeNativeInterface() is used if it succeeds.
*/
static sk_sp<GrContext> MakeGL(sk_sp<const GrGLInterface>, const GrContextOptions&);
static sk_sp<GrContext> MakeGL(sk_sp<const GrGLInterface>);
static sk_sp<GrContext> MakeGL(const GrContextOptions&);
static sk_sp<GrContext> MakeGL();
#endif
#ifdef SK_VULKAN
/**
* The Vulkan context (VkQueue, VkDevice, VkInstance) must be kept alive until the returned
* GrContext is destroyed. This also means that any objects created with this GrContext (e.g.
* SkSurfaces, SkImages, etc.) must also be released as they may hold refs on the GrContext.
* Once all these objects and the GrContext are released, then it is safe to delete the vulkan
* objects.
*/
static sk_sp<GrContext> MakeVulkan(const GrVkBackendContext&, const GrContextOptions&);
static sk_sp<GrContext> MakeVulkan(const GrVkBackendContext&);
#endif
#ifdef SK_METAL
/**
* Makes a GrContext which uses Metal as the backend. The device parameter is an MTLDevice
* and queue is an MTLCommandQueue which should be used by the backend. These objects must
* have a ref on them which can be transferred to Ganesh which will release the ref when the
* GrContext is destroyed.
*/
static sk_sp<GrContext> MakeMetal(void* device, void* queue, const GrContextOptions& options);
static sk_sp<GrContext> MakeMetal(void* device, void* queue);
#endif
#ifdef SK_DIRECT3D
/**
* Makes a GrContext which uses Direct3D as the backend. The Direct3D context
* must be kept alive until the returned GrContext is first destroyed or abandoned.
*/
static sk_sp<GrContext> MakeDirect3D(const GrD3DBackendContext&,
const GrContextOptions& options);
static sk_sp<GrContext> MakeDirect3D(const GrD3DBackendContext&);
#endif
#ifdef SK_DAWN
static sk_sp<GrContext> MakeDawn(const wgpu::Device& device, const GrContextOptions& options);
static sk_sp<GrContext> MakeDawn(const wgpu::Device& device);
#endif
static sk_sp<GrContext> MakeMock(const GrMockOptions*, const GrContextOptions&);
static sk_sp<GrContext> MakeMock(const GrMockOptions*);
#endif // SK_DISABLE_LEGACY_CONTEXT_FACTORIES
~GrContext() override;
// TODO: Remove this from public after migrating Chrome.

View File

@ -150,21 +150,21 @@ struct ColorSettings {
GrGLenum pixFormat;
};
sk_sp<GrContext> MakeGrContext(EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context)
sk_sp<GrDirectContext> MakeGrContext(EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context)
{
EMSCRIPTEN_RESULT r = emscripten_webgl_make_context_current(context);
if (r < 0) {
printf("failed to make webgl context current %d\n", r);
return nullptr;
}
// setup GrContext
// setup GrDirectContext
auto interface = GrGLMakeNativeInterface();
// setup contexts
sk_sp<GrContext> grContext(GrContext::MakeGL(interface));
return grContext;
sk_sp<GrDirectContext> dContext(GrDirectContext::MakeGL(interface));
return dContext;
}
sk_sp<SkSurface> MakeOnScreenGLSurface(sk_sp<GrContext> grContext, int width, int height,
sk_sp<SkSurface> MakeOnScreenGLSurface(sk_sp<GrDirectContext> dContext, int width, int height,
sk_sp<SkColorSpace> colorSpace) {
// WebGL should already be clearing the color and stencil buffers, but do it again here to
// ensure Skia receives them in the expected state.
@ -172,7 +172,7 @@ sk_sp<SkSurface> MakeOnScreenGLSurface(sk_sp<GrContext> grContext, int width, in
glClearColor(0, 0, 0, 0);
glClearStencil(0);
glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
grContext->resetContext(kRenderTarget_GrGLBackendState | kMisc_GrGLBackendState);
dContext->resetContext(kRenderTarget_GrGLBackendState | kMisc_GrGLBackendState);
// The on-screen canvas is FBO 0. Wrap it in a Skia render target so Skia can render to it.
GrGLFramebufferInfo info;
@ -187,15 +187,15 @@ sk_sp<SkSurface> MakeOnScreenGLSurface(sk_sp<GrContext> grContext, int width, in
const auto colorSettings = ColorSettings(colorSpace);
info.fFormat = colorSettings.pixFormat;
GrBackendRenderTarget target(width, height, sampleCnt, stencil, info);
sk_sp<SkSurface> surface(SkSurface::MakeFromBackendRenderTarget(grContext.get(), target,
sk_sp<SkSurface> surface(SkSurface::MakeFromBackendRenderTarget(dContext.get(), target,
kBottomLeft_GrSurfaceOrigin, colorSettings.colorType, colorSpace, nullptr));
return surface;
}
sk_sp<SkSurface> MakeRenderTarget(sk_sp<GrContext> grContext, int width, int height) {
sk_sp<SkSurface> MakeRenderTarget(sk_sp<GrDirectContext> dContext, int width, int height) {
SkImageInfo info = SkImageInfo::MakeN32(width, height, SkAlphaType::kPremul_SkAlphaType);
sk_sp<SkSurface> surface(SkSurface::MakeRenderTarget(grContext.get(),
sk_sp<SkSurface> surface(SkSurface::MakeRenderTarget(dContext.get(),
SkBudgeted::kYes,
info, 0,
kBottomLeft_GrSurfaceOrigin,
@ -203,8 +203,8 @@ sk_sp<SkSurface> MakeRenderTarget(sk_sp<GrContext> grContext, int width, int hei
return surface;
}
sk_sp<SkSurface> MakeRenderTarget(sk_sp<GrContext> grContext, SimpleImageInfo sii) {
sk_sp<SkSurface> surface(SkSurface::MakeRenderTarget(grContext.get(),
sk_sp<SkSurface> MakeRenderTarget(sk_sp<GrDirectContext> dContext, SimpleImageInfo sii) {
sk_sp<SkSurface> surface(SkSurface::MakeRenderTarget(dContext.get(),
SkBudgeted::kYes,
toSkImageInfo(sii), 0,
kBottomLeft_GrSurfaceOrigin,
@ -736,8 +736,8 @@ EMSCRIPTEN_BINDINGS(Skia) {
function("setCurrentContext", &emscripten_webgl_make_context_current);
function("MakeGrContext", &MakeGrContext);
function("MakeOnScreenGLSurface", &MakeOnScreenGLSurface);
function("MakeRenderTarget", select_overload<sk_sp<SkSurface>(sk_sp<GrContext>, int, int)>(&MakeRenderTarget));
function("MakeRenderTarget", select_overload<sk_sp<SkSurface>(sk_sp<GrContext>, SimpleImageInfo)>(&MakeRenderTarget));
function("MakeRenderTarget", select_overload<sk_sp<SkSurface>(sk_sp<GrDirectContext>, int, int)>(&MakeRenderTarget));
function("MakeRenderTarget", select_overload<sk_sp<SkSurface>(sk_sp<GrDirectContext>, SimpleImageInfo)>(&MakeRenderTarget));
constant("gpu", true);
#endif
@ -908,22 +908,26 @@ EMSCRIPTEN_BINDINGS(Skia) {
}), allow_raw_pointers());
#ifdef SK_GL
class_<GrContext>("GrContext")
.smart_ptr<sk_sp<GrContext>>("sk_sp<GrContext>")
.function("getResourceCacheLimitBytes", optional_override([](GrContext& self)->size_t {
class_<GrDirectContext>("GrDirectContext")
.smart_ptr<sk_sp<GrDirectContext>>("sk_sp<GrDirectContext>")
.function("getResourceCacheLimitBytes",
optional_override([](GrDirectContext& self)->size_t {
int maxResources = 0;// ignored
size_t currMax = 0;
self.getResourceCacheLimits(&maxResources, &currMax);
return currMax;
}))
.function("getResourceCacheUsageBytes", optional_override([](GrContext& self)->size_t {
.function("getResourceCacheUsageBytes",
optional_override([](GrDirectContext& self)->size_t {
int usedResources = 0;// ignored
size_t currUsage = 0;
self.getResourceCacheUsage(&usedResources, &currUsage);
return currUsage;
}))
.function("releaseResourcesAndAbandonContext", &GrContext::releaseResourcesAndAbandonContext)
.function("setResourceCacheLimitBytes", optional_override([](GrContext& self, size_t maxResourceBytes)->void {
.function("releaseResourcesAndAbandonContext",
&GrDirectContext::releaseResourcesAndAbandonContext)
.function("setResourceCacheLimitBytes",
optional_override([](GrDirectContext& self, size_t maxResourceBytes)->void {
int maxResources = 0;
size_t currMax = 0; // ignored
self.getResourceCacheLimits(&maxResources, &currMax);

View File

@ -9,7 +9,6 @@
#include <emscripten/bind.h>
#include "include/core/SkCanvas.h"
#include "include/core/SkSurface.h"
#include "include/gpu/GrContext.h"
#include "tools/skui/InputState.h"
#include "tools/skui/ModifierKey.h"
#include "tools/viewer/SKPSlide.h"

View File

@ -84,7 +84,7 @@ has been made current to the current thread when Skia calls are made.
<!--?prettify lang=cc?-->
#include "GrContext.h"
#include "GrDirectContext.h"
#include "gl/GrGLInterface.h"
#include "SkData.h"
#include "SkImage.h"

View File

@ -5,7 +5,7 @@
* found in the LICENSE file.
*/
#include "include/gpu/GrContext.h"
#include "include/gpu/GrRecordingContext.h"
#include "src/core/SkLRUCache.h"
#include "src/gpu/GrCaps.h"
#include "src/gpu/GrContextThreadSafeProxyPriv.h"
@ -18,7 +18,7 @@
* The DDL Context is the one in effect during DDL Recording. It isn't backed by a GrGPU and
* cannot allocate any GPU resources.
*/
class GrDDLContext final : public GrContext {
class GrDDLContext final : public GrRecordingContext {
public:
GrDDLContext(sk_sp<GrContextThreadSafeProxy> proxy)
: INHERITED(std::move(proxy)) {
@ -31,21 +31,7 @@ public:
INHERITED::abandonContext();
}
void releaseResourcesAndAbandonContext() override {
SkASSERT(0); // abandoning in a DDL Recorder doesn't make a whole lot of sense
INHERITED::releaseResourcesAndAbandonContext();
}
void freeGpuResources() override {
// freeing resources in a DDL Recorder doesn't make a whole lot of sense but some of
// our tests do it anyways
}
private:
// TODO: Here we're pretending this isn't derived from GrContext. Switch this to be derived from
// GrRecordingContext!
GrDirectContext* asDirectContext() override { return nullptr; }
bool init() override {
if (!INHERITED::init()) {
return false;
@ -58,16 +44,6 @@ private:
return true;
}
GrAtlasManager* onGetAtlasManager() override {
SkASSERT(0); // the DDL Recorders should never invoke this
return nullptr;
}
GrSmallPathAtlasMgr* onGetSmallPathAtlasMgr() override {
SkASSERT(0); // DDL recorders should never invoke this
return nullptr;
}
// Add to the set of unique program infos required by this DDL
void recordProgramInfo(const GrProgramInfo* programInfo) final {
if (!programInfo) {
@ -149,7 +125,7 @@ private:
ProgramInfoMap fProgramInfoMap;
using INHERITED = GrContext;
using INHERITED = GrRecordingContext;
};
sk_sp<GrRecordingContext> GrRecordingContextPriv::MakeDDL(sk_sp<GrContextThreadSafeProxy> proxy) {

View File

@ -138,27 +138,6 @@ GrSmallPathAtlasMgr* GrDirectContext::onGetSmallPathAtlasMgr() {
}
#ifdef SK_GL
/*************************************************************************************************/
#ifndef SK_DISABLE_LEGACY_CONTEXT_FACTORIES
sk_sp<GrContext> GrContext::MakeGL(sk_sp<const GrGLInterface> glInterface) {
return GrDirectContext::MakeGL(std::move(glInterface));
}
sk_sp<GrContext> GrContext::MakeGL(const GrContextOptions& options) {
return GrDirectContext::MakeGL(options);
}
sk_sp<GrContext> GrContext::MakeGL() {
return GrDirectContext::MakeGL();
}
sk_sp<GrContext> GrContext::MakeGL(sk_sp<const GrGLInterface> glInterface,
const GrContextOptions& options) {
return GrDirectContext::MakeGL(std::move(glInterface), options);
}
#endif
/*************************************************************************************************/
sk_sp<GrDirectContext> GrDirectContext::MakeGL(sk_sp<const GrGLInterface> glInterface) {
@ -227,20 +206,6 @@ sk_sp<GrDirectContext> GrDirectContext::MakeGL(sk_sp<const GrGLInterface> glInte
}
#endif
/*************************************************************************************************/
#ifndef SK_DISABLE_LEGACY_CONTEXT_FACTORIES
sk_sp<GrContext> GrContext::MakeMock(const GrMockOptions* mockOptions) {
return GrDirectContext::MakeMock(mockOptions);
}
sk_sp<GrContext> GrContext::MakeMock(const GrMockOptions* mockOptions,
const GrContextOptions& options) {
return GrDirectContext::MakeMock(mockOptions, options);
}
#endif
/*************************************************************************************************/
sk_sp<GrDirectContext> GrDirectContext::MakeMock(const GrMockOptions* mockOptions) {
GrContextOptions defaultOptions;
@ -260,20 +225,6 @@ sk_sp<GrDirectContext> GrDirectContext::MakeMock(const GrMockOptions* mockOption
}
#ifdef SK_VULKAN
/*************************************************************************************************/
#ifndef SK_DISABLE_LEGACY_CONTEXT_FACTORIES
sk_sp<GrContext> GrContext::MakeVulkan(const GrVkBackendContext& backendContext) {
return GrDirectContext::MakeVulkan(backendContext);
}
sk_sp<GrContext> GrContext::MakeVulkan(const GrVkBackendContext& backendContext,
const GrContextOptions& options) {
return GrDirectContext::MakeVulkan(backendContext, options);
}
#endif
/*************************************************************************************************/
sk_sp<GrDirectContext> GrDirectContext::MakeVulkan(const GrVkBackendContext& backendContext) {
GrContextOptions defaultOptions;
@ -294,19 +245,6 @@ sk_sp<GrDirectContext> GrDirectContext::MakeVulkan(const GrVkBackendContext& bac
#endif
#ifdef SK_METAL
/*************************************************************************************************/
#ifndef SK_DISABLE_LEGACY_CONTEXT_FACTORIES
sk_sp<GrContext> GrContext::MakeMetal(void* device, void* queue) {
return GrDirectContext::MakeMetal(device, queue);
}
sk_sp<GrContext> GrContext::MakeMetal(void* device, void* queue, const GrContextOptions& options) {
return GrDirectContext::MakeMetal(device, queue, options);
}
#endif
/*************************************************************************************************/
sk_sp<GrDirectContext> GrDirectContext::MakeMetal(void* device, void* queue) {
GrContextOptions defaultOptions;
@ -327,20 +265,6 @@ sk_sp<GrDirectContext> GrDirectContext::MakeMetal(void* device, void* queue,
#endif
#ifdef SK_DIRECT3D
/*************************************************************************************************/
#ifndef SK_DISABLE_LEGACY_CONTEXT_FACTORIES
sk_sp<GrContext> GrContext::MakeDirect3D(const GrD3DBackendContext& backendContext) {
return GrDirectContext::MakeDirect3D(backendContext);
}
sk_sp<GrContext> GrContext::MakeDirect3D(const GrD3DBackendContext& backendContext,
const GrContextOptions& options) {
return GrDirectContext::MakeDirect3D(backendContext, options);
}
#endif
/*************************************************************************************************/
sk_sp<GrDirectContext> GrDirectContext::MakeDirect3D(const GrD3DBackendContext& backendContext) {
GrContextOptions defaultOptions;
@ -361,19 +285,6 @@ sk_sp<GrDirectContext> GrDirectContext::MakeDirect3D(const GrD3DBackendContext&
#endif
#ifdef SK_DAWN
/*************************************************************************************************/
#ifndef SK_DISABLE_LEGACY_CONTEXT_FACTORIES
sk_sp<GrContext> GrContext::MakeDawn(const wgpu::Device& device) {
return GrDirectContext::MakeDawn(device);
}
sk_sp<GrContext> GrContext::MakeDawn(const wgpu::Device& device, const GrContextOptions& options) {
return GrDirectContext::MakeDawn(device, options);
}
#endif
/*************************************************************************************************/
sk_sp<GrDirectContext> GrDirectContext::MakeDawn(const wgpu::Device& device) {
GrContextOptions defaultOptions;

View File

@ -13,7 +13,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/gpu/gl/GrGLAssembleInterface.h"
#include "include/gpu/gl/GrGLInterface.h"
#else