diff options
Diffstat (limited to 'src/gpu/GrContext.cpp')
-rw-r--r-- | src/gpu/GrContext.cpp | 61 |
1 files changed, 42 insertions, 19 deletions
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index c13cd539c2..eedb3e475f 100644 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -62,6 +62,26 @@ SkASSERT(!(P) || !((P)->priv().peekTexture()) || (P)->priv().peekTexture()->getC //////////////////////////////////////////////////////////////////////////////// +class SK_API GrDirectContext : public GrContext { +public: + GrDirectContext(GrBackend backend) : INHERITED(backend) { } + +protected: + +private: + typedef GrContext INHERITED; +}; + +class SK_API GrDDLContext : public GrContext { +public: + GrDDLContext(GrContextThreadSafeProxy* proxy) : INHERITED(proxy) {} + +protected: + +private: + typedef GrContext INHERITED; +}; + GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext) { GrContextOptions defaultOptions; return Create(backend, backendContext, defaultOptions); @@ -70,7 +90,7 @@ GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext) GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext, const GrContextOptions& options) { - sk_sp<GrContext> context(new GrContext(backend)); + sk_sp<GrContext> context(new GrDirectContext(backend)); context->fGpu = GrGpu::Make(backend, backendContext, options, context.get()); if (!context->fGpu) { @@ -91,7 +111,7 @@ sk_sp<GrContext> GrContext::MakeGL(sk_sp<const GrGLInterface> interface) { sk_sp<GrContext> GrContext::MakeGL(sk_sp<const GrGLInterface> interface, const GrContextOptions& options) { - sk_sp<GrContext> context(new GrContext(kOpenGL_GrBackend)); + sk_sp<GrContext> context(new GrDirectContext(kOpenGL_GrBackend)); context->fGpu = GrGLGpu::Make(std::move(interface), options, context.get()); if (!context->fGpu) { @@ -119,7 +139,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 GrContext(kMock_GrBackend)); + sk_sp<GrContext> context(new GrDirectContext(kMock_GrBackend)); context->fGpu = GrMockGpu::Make(mockOptions, options, context.get()); if (!context->fGpu) { @@ -139,7 +159,7 @@ sk_sp<GrContext> GrContext::MakeVulkan(sk_sp<const GrVkBackendContext> backendCo sk_sp<GrContext> GrContext::MakeVulkan(sk_sp<const GrVkBackendContext> backendContext, const GrContextOptions& options) { - sk_sp<GrContext> context(new GrContext(kVulkan_GrBackend)); + sk_sp<GrContext> context(new GrDirectContext(kVulkan_GrBackend)); context->fGpu = GrVkGpu::Make(std::move(backendContext), options, context.get()); if (!context->fGpu) { @@ -182,12 +202,10 @@ static int32_t next_id() { } sk_sp<GrContext> GrContextPriv::MakeDDL(GrContextThreadSafeProxy* proxy) { - sk_sp<GrContext> context(new GrContext(proxy)); + sk_sp<GrContext> context(new GrDDLContext(proxy)); - context->fGpu = GrDDLGpu::Make(context.get(), proxy->fCaps); - if (!context->fGpu) { - return nullptr; - } + // Note: we aren't creating a Gpu here. This causes the resource provider & cache to + // also not be created if (!context->init(proxy->fOptions)) { return nullptr; } @@ -204,7 +222,8 @@ GrContext::GrContext(GrBackend backend) } GrContext::GrContext(GrContextThreadSafeProxy* proxy) - : fUniqueID(proxy->fContextUniqueID) + : fCaps(proxy->fCaps) + , fUniqueID(proxy->fContextUniqueID) , fBackend(proxy->fBackend) { fResourceCache = nullptr; fResourceProvider = nullptr; @@ -214,11 +233,18 @@ GrContext::GrContext(GrContextThreadSafeProxy* proxy) bool GrContext::init(const GrContextOptions& options) { ASSERT_SINGLE_OWNER - fCaps = fGpu->refCaps(); - fResourceCache = new GrResourceCache(fCaps.get(), fUniqueID); - fResourceProvider = new GrResourceProvider(fGpu.get(), fResourceCache, &fSingleOwner); + + if (fGpu) { + fCaps = fGpu->refCaps(); + fResourceCache = new GrResourceCache(fCaps.get(), fUniqueID); + fResourceProvider = new GrResourceProvider(fGpu.get(), fResourceCache, &fSingleOwner); + } + fProxyProvider = new GrProxyProvider(fResourceProvider, fResourceCache, fCaps, &fSingleOwner); - fResourceCache->setProxyProvider(fProxyProvider); + + if (fResourceCache) { + fResourceCache->setProxyProvider(fProxyProvider); + } // DDL TODO: we need to think through how the task group & persistent cache // get passed on to/shared between all the DDLRecorders created with this context. @@ -284,13 +310,10 @@ bool GrContext::init(const GrContextOptions& options) { GrContext::~GrContext() { ASSERT_SINGLE_OWNER - if (!fGpu) { - SkASSERT(!fCaps); - return; + if (fGpu) { + this->flush(); } - this->flush(); - fDrawingManager->cleanup(); for (int i = 0; i < fCleanUpData.count(); ++i) { |