Make the GrDirectContext a thing and move it to include/private
This is somewhat of a departure from the original context refactoring plan (i.e., keep GrLegacyDirectContext hidden and switch GrContext over to be the GrDirectContext at some point). Having a GrDirectContext earlier will allow us to change some important signatures earlier (e.g., asDirectContext) and, hopefully, clarify some of the confusion about the context class hierarchy. Additionally, this will let us make onGpuSetup take a direct context - clarifying its purpose vis a vis onDraw (which now takes a recording context). Change-Id: I8298a0649bc95843d20bee33ba7fe1d7e73bb839 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/299768 Reviewed-by: Adlai Holler <adlai@google.com> Commit-Queue: Robert Phillips <robertphillips@google.com>
This commit is contained in:
parent
41abd4f5cc
commit
ad2484520d
@ -21,6 +21,7 @@ skia_gpu_sources = [
|
||||
|
||||
# Private includes
|
||||
"$_include/private/GrContext_Base.h",
|
||||
"$_include/private/GrDirectContext.h",
|
||||
"$_include/private/GrGLTypesPriv.h",
|
||||
"$_include/private/GrImageContext.h",
|
||||
"$_include/private/GrRecordingContext.h",
|
||||
@ -81,6 +82,7 @@ skia_gpu_sources = [
|
||||
"$_src/gpu/GrDefaultGeoProcFactory.h",
|
||||
"$_src/gpu/GrDeferredProxyUploader.h",
|
||||
"$_src/gpu/GrDeferredUpload.h",
|
||||
"$_src/gpu/GrDirectContext.cpp",
|
||||
"$_src/gpu/GrDistanceFieldGenFromVector.cpp",
|
||||
"$_src/gpu/GrDistanceFieldGenFromVector.h",
|
||||
"$_src/gpu/GrDrawOpAtlas.cpp",
|
||||
@ -115,7 +117,6 @@ skia_gpu_sources = [
|
||||
"$_src/gpu/GrImageInfo.h",
|
||||
"$_src/gpu/GrImageTextureMaker.cpp",
|
||||
"$_src/gpu/GrImageTextureMaker.h",
|
||||
"$_src/gpu/GrLegacyDirectContext.cpp",
|
||||
"$_src/gpu/GrManagedResource.cpp",
|
||||
"$_src/gpu/GrManagedResource.h",
|
||||
"$_src/gpu/GrMemoryPool.cpp",
|
||||
|
39
include/private/GrDirectContext.h
Normal file
39
include/private/GrDirectContext.h
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2020 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef GrDirectContext_DEFINED
|
||||
#define GrDirectContext_DEFINED
|
||||
|
||||
#include "include/gpu/GrContext.h"
|
||||
|
||||
class GrAtlasManager;
|
||||
|
||||
class GrDirectContext : public GrContext {
|
||||
public:
|
||||
GrDirectContext(GrBackendApi backend, const GrContextOptions& options);
|
||||
|
||||
~GrDirectContext() override;
|
||||
|
||||
void abandonContext() override;
|
||||
|
||||
void releaseResourcesAndAbandonContext() override;
|
||||
|
||||
void freeGpuResources() override;
|
||||
|
||||
protected:
|
||||
bool init() override;
|
||||
|
||||
GrAtlasManager* onGetAtlasManager() override { return fAtlasManager; }
|
||||
|
||||
private:
|
||||
GrAtlasManager* fAtlasManager;
|
||||
|
||||
typedef GrContext INHERITED;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
@ -6,7 +6,7 @@
|
||||
*/
|
||||
|
||||
|
||||
#include "include/gpu/GrContext.h"
|
||||
#include "include/private/GrDirectContext.h"
|
||||
|
||||
#include "include/gpu/GrContextThreadSafeProxy.h"
|
||||
#include "src/gpu/GrContextPriv.h"
|
||||
@ -44,14 +44,12 @@ static const bool kDefaultReduceOpsTaskSplitting = false;
|
||||
static const bool kDefaultReduceOpsTaskSplitting = false;
|
||||
#endif
|
||||
|
||||
class GrLegacyDirectContext : public GrContext {
|
||||
public:
|
||||
GrLegacyDirectContext(GrBackendApi backend, const GrContextOptions& options)
|
||||
GrDirectContext::GrDirectContext(GrBackendApi backend, const GrContextOptions& options)
|
||||
: INHERITED(GrContextThreadSafeProxyPriv::Make(backend, options))
|
||||
, fAtlasManager(nullptr) {
|
||||
}
|
||||
}
|
||||
|
||||
~GrLegacyDirectContext() override {
|
||||
GrDirectContext::~GrDirectContext() {
|
||||
// this if-test protects against the case where the context is being destroyed
|
||||
// before having been fully created
|
||||
if (this->priv().getGpu()) {
|
||||
@ -59,27 +57,26 @@ public:
|
||||
}
|
||||
|
||||
delete fAtlasManager;
|
||||
}
|
||||
}
|
||||
|
||||
void abandonContext() override {
|
||||
void GrDirectContext::abandonContext() {
|
||||
INHERITED::abandonContext();
|
||||
fAtlasManager->freeAll();
|
||||
}
|
||||
}
|
||||
|
||||
void releaseResourcesAndAbandonContext() override {
|
||||
void GrDirectContext::releaseResourcesAndAbandonContext() {
|
||||
INHERITED::releaseResourcesAndAbandonContext();
|
||||
fAtlasManager->freeAll();
|
||||
}
|
||||
}
|
||||
|
||||
void freeGpuResources() override {
|
||||
void GrDirectContext::freeGpuResources() {
|
||||
this->flushAndSubmit();
|
||||
fAtlasManager->freeAll();
|
||||
|
||||
INHERITED::freeGpuResources();
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
bool init() override {
|
||||
bool GrDirectContext::init() {
|
||||
const GrGpu* gpu = this->priv().getGpu();
|
||||
if (!gpu) {
|
||||
return false;
|
||||
@ -117,15 +114,7 @@ protected:
|
||||
this->priv().addOnFlushCallbackObject(fAtlasManager);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
GrAtlasManager* onGetAtlasManager() override { return fAtlasManager; }
|
||||
|
||||
private:
|
||||
GrAtlasManager* fAtlasManager;
|
||||
|
||||
typedef GrContext INHERITED;
|
||||
};
|
||||
}
|
||||
|
||||
#ifdef SK_GL
|
||||
sk_sp<GrContext> GrContext::MakeGL(sk_sp<const GrGLInterface> glInterface) {
|
||||
@ -173,7 +162,7 @@ GrGLFunction<GrGLGetErrorFn> make_get_error_with_random_oom(GrGLFunction<GrGLGet
|
||||
|
||||
sk_sp<GrContext> GrContext::MakeGL(sk_sp<const GrGLInterface> glInterface,
|
||||
const GrContextOptions& options) {
|
||||
sk_sp<GrContext> context(new GrLegacyDirectContext(GrBackendApi::kOpenGL, options));
|
||||
sk_sp<GrContext> context(new GrDirectContext(GrBackendApi::kOpenGL, options));
|
||||
#if GR_TEST_UTILS
|
||||
if (options.fRandomGLOOM) {
|
||||
auto copy = sk_make_sp<GrGLInterface>(*glInterface);
|
||||
@ -201,7 +190,7 @@ sk_sp<GrContext> GrContext::MakeMock(const GrMockOptions* mockOptions) {
|
||||
|
||||
sk_sp<GrContext> GrContext::MakeMock(const GrMockOptions* mockOptions,
|
||||
const GrContextOptions& options) {
|
||||
sk_sp<GrContext> context(new GrLegacyDirectContext(GrBackendApi::kMock, options));
|
||||
sk_sp<GrContext> context(new GrDirectContext(GrBackendApi::kMock, options));
|
||||
|
||||
context->fGpu = GrMockGpu::Make(mockOptions, options, context.get());
|
||||
if (!context->init()) {
|
||||
@ -223,7 +212,7 @@ sk_sp<GrContext> GrContext::MakeVulkan(const GrVkBackendContext& backendContext)
|
||||
sk_sp<GrContext> GrContext::MakeVulkan(const GrVkBackendContext& backendContext,
|
||||
const GrContextOptions& options) {
|
||||
#ifdef SK_VULKAN
|
||||
sk_sp<GrContext> context(new GrLegacyDirectContext(GrBackendApi::kVulkan, options));
|
||||
sk_sp<GrContext> context(new GrDirectContext(GrBackendApi::kVulkan, options));
|
||||
|
||||
context->fGpu = GrVkGpu::Make(backendContext, options, context.get());
|
||||
if (!context->init()) {
|
||||
@ -243,7 +232,7 @@ sk_sp<GrContext> GrContext::MakeMetal(void* device, void* queue) {
|
||||
}
|
||||
|
||||
sk_sp<GrContext> GrContext::MakeMetal(void* device, void* queue, const GrContextOptions& options) {
|
||||
sk_sp<GrContext> context(new GrLegacyDirectContext(GrBackendApi::kMetal, options));
|
||||
sk_sp<GrContext> context(new GrDirectContext(GrBackendApi::kMetal, options));
|
||||
|
||||
context->fGpu = GrMtlTrampoline::MakeGpu(context.get(), options, device, queue);
|
||||
if (!context->init()) {
|
||||
@ -262,7 +251,7 @@ sk_sp<GrContext> GrContext::MakeDirect3D(const GrD3DBackendContext& backendConte
|
||||
|
||||
sk_sp<GrContext> GrContext::MakeDirect3D(const GrD3DBackendContext& backendContext,
|
||||
const GrContextOptions& options) {
|
||||
sk_sp<GrContext> context(new GrLegacyDirectContext(GrBackendApi::kDirect3D, options));
|
||||
sk_sp<GrContext> context(new GrDirectContext(GrBackendApi::kDirect3D, options));
|
||||
|
||||
context->fGpu = GrD3DGpu::Make(backendContext, options, context.get());
|
||||
if (!context->init()) {
|
||||
@ -280,7 +269,7 @@ sk_sp<GrContext> GrContext::MakeDawn(const wgpu::Device& device) {
|
||||
}
|
||||
|
||||
sk_sp<GrContext> GrContext::MakeDawn(const wgpu::Device& device, const GrContextOptions& options) {
|
||||
sk_sp<GrContext> context(new GrLegacyDirectContext(GrBackendApi::kDawn, options));
|
||||
sk_sp<GrContext> context(new GrDirectContext(GrBackendApi::kDawn, options));
|
||||
|
||||
context->fGpu = GrDawnGpu::Make(device, options, context.get());
|
||||
if (!context->init()) {
|
Loading…
Reference in New Issue
Block a user