diff options
author | Robert Phillips <robertphillips@google.com> | 2018-03-08 11:30:12 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-03-08 19:52:31 +0000 |
commit | a3457b8452a24c04a77a5ab32fc6464e005c76a1 (patch) | |
tree | d70c916a1802b622f526f8711f69729815423c10 /src/gpu | |
parent | 1eb5ca41d9db5ca72f44f957fdd483d3f260f051 (diff) |
Split GrDDL- & GrDirect- Contexts into their own files
Following up on an prior CLs TODO
Change-Id: I99397d4ffa5cc67b39726900f48b399e38fdbdd9
Reviewed-on: https://skia-review.googlesource.com/113201
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'src/gpu')
-rw-r--r-- | src/gpu/GrContext.cpp | 263 | ||||
-rw-r--r-- | src/gpu/GrDDLContext.cpp | 73 | ||||
-rw-r--r-- | src/gpu/GrDirectContext.cpp | 214 |
3 files changed, 287 insertions, 263 deletions
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index ef1ce54337..f88da28970 100644 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -34,15 +34,7 @@ #include "SkTaskGroup.h" #include "SkUnPreMultiplyPriv.h" #include "effects/GrConfigConversionEffect.h" -#include "gl/GrGLGpu.h" -#include "mock/GrMockGpu.h" #include "text/GrTextBlobCache.h" -#ifdef SK_METAL -#include "mtl/GrMtlTrampoline.h" -#endif -#ifdef SK_VULKAN -#include "vk/GrVkGpu.h" -#endif #define ASSERT_OWNED_PROXY(P) \ SkASSERT(!(P) || !((P)->priv().peekTexture()) || (P)->priv().peekTexture()->getContext() == this) @@ -62,250 +54,6 @@ SkASSERT(!(P) || !((P)->priv().peekTexture()) || (P)->priv().peekTexture()->getC //////////////////////////////////////////////////////////////////////////////// -class SK_API GrDirectContext : public GrContext { -public: - GrDirectContext(GrBackend backend) - : INHERITED(backend) - , fAtlasManager(nullptr) { - } - - ~GrDirectContext() override { - // this if-test protects against the case where the context is being destroyed - // before having been fully created - if (this->contextPriv().getGpu()) { - this->flush(); - } - - delete fAtlasManager; - } - - void abandonContext() override { - INHERITED::abandonContext(); - fAtlasManager->freeAll(); - } - - void releaseResourcesAndAbandonContext() override { - INHERITED::releaseResourcesAndAbandonContext(); - fAtlasManager->freeAll(); - } - - void freeGpuResources() override { - this->flush(); - fAtlasManager->freeAll(); - - INHERITED::freeGpuResources(); - } - -protected: - bool init(const GrContextOptions& options) override { - SkASSERT(fCaps); // should've been set in ctor - SkASSERT(!fThreadSafeProxy); - - fThreadSafeProxy.reset(new GrContextThreadSafeProxy(fCaps, this->uniqueID(), - fBackend, options)); - - if (!INHERITED::initCommon(options)) { - return false; - } - - GrDrawOpAtlas::AllowMultitexturing allowMultitexturing; - if (GrContextOptions::Enable::kNo == options.fAllowMultipleGlyphCacheTextures || - // multitexturing supported only if range can represent the index + texcoords fully - !(fCaps->shaderCaps()->floatIs32Bits() || fCaps->shaderCaps()->integerSupport())) { - allowMultitexturing = GrDrawOpAtlas::AllowMultitexturing::kNo; - } else { - allowMultitexturing = GrDrawOpAtlas::AllowMultitexturing::kYes; - } - - GrGlyphCache* glyphCache = this->contextPriv().getGlyphCache(); - GrProxyProvider* proxyProvider = this->contextPriv().proxyProvider(); - - fAtlasManager = new GrAtlasManager(proxyProvider, glyphCache, - options.fGlyphCacheTextureMaximumBytes, - allowMultitexturing); - this->contextPriv().addOnFlushCallbackObject(fAtlasManager); - - SkASSERT(glyphCache->getGlyphSizeLimit() == fAtlasManager->getGlyphSizeLimit()); - return true; - } - - GrAtlasManager* onGetAtlasManager() override { return fAtlasManager; } - -private: - GrAtlasManager* fAtlasManager; - - typedef GrContext INHERITED; -}; - -/** - * 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 SK_API GrDDLContext : public GrContext { -public: - GrDDLContext(sk_sp<GrContextThreadSafeProxy> proxy) - : INHERITED(proxy->fBackend, proxy->fContextUniqueID) { - fCaps = proxy->fCaps; - fThreadSafeProxy = std::move(proxy); - } - - ~GrDDLContext() override { - // The GrDDLContext doesn't actually own the fRestrictedAtlasManager so don't delete it - } - - void abandonContext() override { - SkASSERT(0); // abandoning in a DDL Recorder doesn't make a whole lot of sense - 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 { - SkASSERT(0); // freeing resources in a DDL Recorder doesn't make a whole lot of sense - INHERITED::freeGpuResources(); - } - -protected: - bool init(const GrContextOptions& options) override { - SkASSERT(fCaps); // should've been set in ctor - SkASSERT(fThreadSafeProxy); // should've been set in the ctor - - if (!INHERITED::initCommon(options)) { - return false; - } - - return true; - } - - GrAtlasManager* onGetAtlasManager() override { - SkASSERT(0); // the DDL Recorders should never invoke this - return nullptr; - } - -private: - typedef GrContext INHERITED; -}; - -GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext) { - GrContextOptions defaultOptions; - return Create(backend, backendContext, defaultOptions); -} - -GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext, - const GrContextOptions& options) { - - sk_sp<GrContext> context(new GrDirectContext(backend)); - - context->fGpu = GrGpu::Make(backend, backendContext, options, context.get()); - if (!context->fGpu) { - return nullptr; - } - - context->fCaps = context->fGpu->refCaps(); - if (!context->init(options)) { - return nullptr; - } - - return context.release(); -} - -sk_sp<GrContext> GrContext::MakeGL(sk_sp<const GrGLInterface> interface) { - GrContextOptions defaultOptions; - return MakeGL(std::move(interface), defaultOptions); -} - -sk_sp<GrContext> GrContext::MakeGL(sk_sp<const GrGLInterface> interface, - const GrContextOptions& options) { - sk_sp<GrContext> context(new GrDirectContext(kOpenGL_GrBackend)); - - context->fGpu = GrGLGpu::Make(std::move(interface), options, context.get()); - if (!context->fGpu) { - return nullptr; - } - - context->fCaps = context->fGpu->refCaps(); - if (!context->init(options)) { - return nullptr; - } - return context; -} - -sk_sp<GrContext> GrContext::MakeGL(const GrGLInterface* interface) { - return MakeGL(sk_ref_sp(interface)); -} - -sk_sp<GrContext> GrContext::MakeGL(const GrGLInterface* interface, - const GrContextOptions& options) { - return MakeGL(sk_ref_sp(interface), options); -} - -sk_sp<GrContext> GrContext::MakeMock(const GrMockOptions* mockOptions) { - GrContextOptions defaultOptions; - return MakeMock(mockOptions, defaultOptions); -} - -sk_sp<GrContext> GrContext::MakeMock(const GrMockOptions* mockOptions, - const GrContextOptions& options) { - sk_sp<GrContext> context(new GrDirectContext(kMock_GrBackend)); - - context->fGpu = GrMockGpu::Make(mockOptions, options, context.get()); - if (!context->fGpu) { - return nullptr; - } - - context->fCaps = context->fGpu->refCaps(); - if (!context->init(options)) { - return nullptr; - } - return context; -} - -#ifdef SK_VULKAN -sk_sp<GrContext> GrContext::MakeVulkan(sk_sp<const GrVkBackendContext> backendContext) { - GrContextOptions defaultOptions; - return MakeVulkan(std::move(backendContext), defaultOptions); -} - -sk_sp<GrContext> GrContext::MakeVulkan(sk_sp<const GrVkBackendContext> backendContext, - const GrContextOptions& options) { - sk_sp<GrContext> context(new GrDirectContext(kVulkan_GrBackend)); - - context->fGpu = GrVkGpu::Make(std::move(backendContext), options, context.get()); - if (!context->fGpu) { - return nullptr; - } - - context->fCaps = context->fGpu->refCaps(); - if (!context->init(options)) { - return nullptr; - } - return context; -} -#endif - -#ifdef SK_METAL -sk_sp<GrContext> GrContext::MakeMetal(void* device, void* queue) { - GrContextOptions defaultOptions; - return MakeMetal(device, queue, defaultOptions); -} - -sk_sp<GrContext> GrContext::MakeMetal(void* device, void* queue, const GrContextOptions& options) { - sk_sp<GrContext> context(new GrDirectContext(kMetal_GrBackend)); - - context->fGpu = GrMtlTrampoline::MakeGpu(context.get(), options, device, queue); - if (!context->fGpu) { - return nullptr; - } - if (!context->init(options)) { - return nullptr; - } - return context; -} -#endif - static int32_t gNextID = 1; static int32_t next_id() { int32_t id; @@ -315,17 +63,6 @@ static int32_t next_id() { return id; } -sk_sp<GrContext> GrContextPriv::MakeDDL(sk_sp<GrContextThreadSafeProxy> proxy) { - sk_sp<GrContext> context(new GrDDLContext(proxy)); - - // 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; - } - return context; -} - GrContext::GrContext(GrBackend backend, int32_t id) : fBackend(backend) , fUniqueID(SK_InvalidGenID == id ? next_id() : id) { diff --git a/src/gpu/GrDDLContext.cpp b/src/gpu/GrDDLContext.cpp new file mode 100644 index 0000000000..eba0379aa8 --- /dev/null +++ b/src/gpu/GrDDLContext.cpp @@ -0,0 +1,73 @@ +/* + * Copyright 2018 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "GrContext.h" + +#include "GrContextPriv.h" + +/** + * 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 SK_API GrDDLContext : public GrContext { +public: + GrDDLContext(sk_sp<GrContextThreadSafeProxy> proxy) + : INHERITED(proxy->fBackend, proxy->fContextUniqueID) { + fCaps = proxy->fCaps; + fThreadSafeProxy = std::move(proxy); + } + + ~GrDDLContext() override { + // The GrDDLContext doesn't actually own the fRestrictedAtlasManager so don't delete it + } + + void abandonContext() override { + SkASSERT(0); // abandoning in a DDL Recorder doesn't make a whole lot of sense + 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 { + SkASSERT(0); // freeing resources in a DDL Recorder doesn't make a whole lot of sense + INHERITED::freeGpuResources(); + } + +protected: + bool init(const GrContextOptions& options) override { + SkASSERT(fCaps); // should've been set in ctor + SkASSERT(fThreadSafeProxy); // should've been set in the ctor + + if (!INHERITED::initCommon(options)) { + return false; + } + + return true; + } + + GrAtlasManager* onGetAtlasManager() override { + SkASSERT(0); // the DDL Recorders should never invoke this + return nullptr; + } + +private: + typedef GrContext INHERITED; +}; + +sk_sp<GrContext> GrContextPriv::MakeDDL(sk_sp<GrContextThreadSafeProxy> proxy) { + sk_sp<GrContext> context(new GrDDLContext(proxy)); + + // 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; + } + return context; +} diff --git a/src/gpu/GrDirectContext.cpp b/src/gpu/GrDirectContext.cpp new file mode 100644 index 0000000000..7302c90d5a --- /dev/null +++ b/src/gpu/GrDirectContext.cpp @@ -0,0 +1,214 @@ +/* + * Copyright 2018 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "GrContext.h" + +#include "GrContextPriv.h" +#include "GrGpu.h" + +#include "gl/GrGLGpu.h" +#include "mock/GrMockGpu.h" +#include "text/GrGlyphCache.h" +#ifdef SK_METAL +#include "mtl/GrMtlTrampoline.h" +#endif +#ifdef SK_VULKAN +#include "vk/GrVkGpu.h" +#endif + +class SK_API GrDirectContext : public GrContext { +public: + GrDirectContext(GrBackend backend) + : INHERITED(backend) + , fAtlasManager(nullptr) { + } + + ~GrDirectContext() override { + // this if-test protects against the case where the context is being destroyed + // before having been fully created + if (this->contextPriv().getGpu()) { + this->flush(); + } + + delete fAtlasManager; + } + + void abandonContext() override { + INHERITED::abandonContext(); + fAtlasManager->freeAll(); + } + + void releaseResourcesAndAbandonContext() override { + INHERITED::releaseResourcesAndAbandonContext(); + fAtlasManager->freeAll(); + } + + void freeGpuResources() override { + this->flush(); + fAtlasManager->freeAll(); + + INHERITED::freeGpuResources(); + } + +protected: + bool init(const GrContextOptions& options) override { + SkASSERT(fCaps); // should've been set in ctor + SkASSERT(!fThreadSafeProxy); + + fThreadSafeProxy.reset(new GrContextThreadSafeProxy(fCaps, this->uniqueID(), + fBackend, options)); + + if (!INHERITED::initCommon(options)) { + return false; + } + + GrDrawOpAtlas::AllowMultitexturing allowMultitexturing; + if (GrContextOptions::Enable::kNo == options.fAllowMultipleGlyphCacheTextures || + // multitexturing supported only if range can represent the index + texcoords fully + !(fCaps->shaderCaps()->floatIs32Bits() || fCaps->shaderCaps()->integerSupport())) { + allowMultitexturing = GrDrawOpAtlas::AllowMultitexturing::kNo; + } else { + allowMultitexturing = GrDrawOpAtlas::AllowMultitexturing::kYes; + } + + GrGlyphCache* glyphCache = this->contextPriv().getGlyphCache(); + GrProxyProvider* proxyProvider = this->contextPriv().proxyProvider(); + + fAtlasManager = new GrAtlasManager(proxyProvider, glyphCache, + options.fGlyphCacheTextureMaximumBytes, + allowMultitexturing); + this->contextPriv().addOnFlushCallbackObject(fAtlasManager); + + SkASSERT(glyphCache->getGlyphSizeLimit() == fAtlasManager->getGlyphSizeLimit()); + return true; + } + + GrAtlasManager* onGetAtlasManager() override { return fAtlasManager; } + +private: + GrAtlasManager* fAtlasManager; + + typedef GrContext INHERITED; +}; + +GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext) { + GrContextOptions defaultOptions; + return Create(backend, backendContext, defaultOptions); +} + +GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext, + const GrContextOptions& options) { + + sk_sp<GrContext> context(new GrDirectContext(backend)); + + context->fGpu = GrGpu::Make(backend, backendContext, options, context.get()); + if (!context->fGpu) { + return nullptr; + } + + context->fCaps = context->fGpu->refCaps(); + if (!context->init(options)) { + return nullptr; + } + + return context.release(); +} + +sk_sp<GrContext> GrContext::MakeGL(sk_sp<const GrGLInterface> interface) { + GrContextOptions defaultOptions; + return MakeGL(std::move(interface), defaultOptions); +} + +sk_sp<GrContext> GrContext::MakeGL(const GrGLInterface* interface) { + return MakeGL(sk_ref_sp(interface)); +} + +sk_sp<GrContext> GrContext::MakeGL(const GrGLInterface* interface, + const GrContextOptions& options) { + return MakeGL(sk_ref_sp(interface), options); +} + +sk_sp<GrContext> GrContext::MakeGL(sk_sp<const GrGLInterface> interface, + const GrContextOptions& options) { + sk_sp<GrContext> context(new GrDirectContext(kOpenGL_GrBackend)); + + context->fGpu = GrGLGpu::Make(std::move(interface), options, context.get()); + if (!context->fGpu) { + return nullptr; + } + + context->fCaps = context->fGpu->refCaps(); + if (!context->init(options)) { + return nullptr; + } + return context; +} + +sk_sp<GrContext> GrContext::MakeMock(const GrMockOptions* mockOptions) { + GrContextOptions defaultOptions; + return MakeMock(mockOptions, defaultOptions); +} + +sk_sp<GrContext> GrContext::MakeMock(const GrMockOptions* mockOptions, + const GrContextOptions& options) { + sk_sp<GrContext> context(new GrDirectContext(kMock_GrBackend)); + + context->fGpu = GrMockGpu::Make(mockOptions, options, context.get()); + if (!context->fGpu) { + return nullptr; + } + + context->fCaps = context->fGpu->refCaps(); + if (!context->init(options)) { + return nullptr; + } + return context; +} + +#ifdef SK_VULKAN +sk_sp<GrContext> GrContext::MakeVulkan(sk_sp<const GrVkBackendContext> backendContext) { + GrContextOptions defaultOptions; + return MakeVulkan(std::move(backendContext), defaultOptions); +} + +sk_sp<GrContext> GrContext::MakeVulkan(sk_sp<const GrVkBackendContext> backendContext, + const GrContextOptions& options) { + sk_sp<GrContext> context(new GrDirectContext(kVulkan_GrBackend)); + + context->fGpu = GrVkGpu::Make(std::move(backendContext), options, context.get()); + if (!context->fGpu) { + return nullptr; + } + + context->fCaps = context->fGpu->refCaps(); + if (!context->init(options)) { + return nullptr; + } + return context; +} +#endif + +#ifdef SK_METAL +sk_sp<GrContext> GrContext::MakeMetal(void* device, void* queue) { + GrContextOptions defaultOptions; + return MakeMetal(device, queue, defaultOptions); +} + +sk_sp<GrContext> GrContext::MakeMetal(void* device, void* queue, const GrContextOptions& options) { + sk_sp<GrContext> context(new GrDirectContext(kMetal_GrBackend)); + + context->fGpu = GrMtlTrampoline::MakeGpu(context.get(), options, device, queue); + if (!context->fGpu) { + return nullptr; + } + if (!context->init(options)) { + return nullptr; + } + return context; +} +#endif + |