aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Robert Phillips <robertphillips@google.com>2018-02-27 18:00:22 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-02-28 00:20:06 +0000
commite5b7ceeac865fb8a3bab82a73d65752c78682718 (patch)
tree6cc0268dfc31e90677213b5d8cc67f8f33533b11 /src
parent23243aee3ae314aeb7438f1a36a6775c3086c416 (diff)
Move atlas manager creation to GrContext derived classes
This CL relies on: https://skia-review.googlesource.com/c/skia/+/108001 (Fission GrAtlasGlyphCache in two) TBR=bsalomon@google.com Change-Id: Ic3f91cea2238221b970f8ebbda99b10202925cd8 Reviewed-on: https://skia-review.googlesource.com/110621 Commit-Queue: Robert Phillips <robertphillips@google.com> Reviewed-by: Greg Daniel <egdaniel@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/gpu/GrContext.cpp139
-rw-r--r--src/gpu/GrContextPriv.h12
2 files changed, 110 insertions, 41 deletions
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 8ccbb2b754..5b3d6644d7 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -64,22 +64,123 @@ SkASSERT(!(P) || !((P)->priv().peekTexture()) || (P)->priv().peekTexture()->getC
class SK_API GrDirectContext : public GrContext {
public:
- GrDirectContext(GrBackend backend) : INHERITED(backend) { }
+ GrDirectContext(GrBackend backend)
+ : INHERITED(backend)
+ , fFullAtlasManager(nullptr) {
+ }
+
+ ~GrDirectContext() override {
+ this->flush();
+
+ delete fFullAtlasManager;
+ }
+
+ void abandonContext() override {
+ INHERITED::abandonContext();
+ fFullAtlasManager->freeAll();
+ }
+
+ void releaseResourcesAndAbandonContext() override {
+ INHERITED::releaseResourcesAndAbandonContext();
+ fFullAtlasManager->freeAll();
+ }
+
+ void freeGpuResources() override {
+ this->flush();
+ fFullAtlasManager->freeAll();
+
+ INHERITED::freeGpuResources();
+ }
protected:
+ bool init(const GrContextOptions& options) override {
+ if (!INHERITED::init(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();
+
+ fFullAtlasManager = new GrAtlasManager(proxyProvider, glyphCache,
+ options.fGlyphCacheTextureMaximumBytes,
+ allowMultitexturing);
+ this->contextPriv().addOnFlushCallbackObject(fFullAtlasManager);
+
+ glyphCache->setGlyphSizeLimit(fFullAtlasManager->getGlyphSizeLimit());
+ return true;
+ }
+
+ GrRestrictedAtlasManager* onGetRestrictedAtlasManager() override { return fFullAtlasManager; }
+ GrAtlasManager* onGetFullAtlasManager() override { return fFullAtlasManager; }
private:
+ GrAtlasManager* fFullAtlasManager;
+
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(GrContextThreadSafeProxy* proxy) : INHERITED(proxy) {}
+ GrDDLContext(GrContextThreadSafeProxy* proxy)
+ : INHERITED(proxy)
+ , fRestrictedAtlasManager(nullptr) {
+ }
+
+ ~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:
- // DDL TODO: grab a GrRestrictedAtlasManager from the proxy
+ bool init(const GrContextOptions& options) override {
+ if (!INHERITED::init(options)) {
+ return false;
+ }
+
+ // DDL TODO: in DDL-mode grab a GrRestrictedAtlasManager from the thread-proxy and
+ // do not add an onFlushCB
+ return true;
+ }
+
+ GrRestrictedAtlasManager* onGetRestrictedAtlasManager() override {
+ return fRestrictedAtlasManager;
+ }
+
+ GrAtlasManager* onGetFullAtlasManager() override {
+ SkASSERT(0); // the DDL Recorders should never invoke this
+ return nullptr;
+ }
private:
+ GrRestrictedAtlasManager* fRestrictedAtlasManager;
+
typedef GrContext INHERITED;
};
@@ -180,7 +281,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 GrContext(kMetal_GrBackend));
+ sk_sp<GrContext> context(new GrDirectContext(kMetal_GrBackend));
context->fGpu = GrMtlTrampoline::MakeGpu(context.get(), options, device, queue);
if (!context->fGpu) {
@@ -220,7 +321,6 @@ GrContext::GrContext(GrBackend backend)
fResourceProvider = nullptr;
fProxyProvider = nullptr;
fGlyphCache = nullptr;
- fFullAtlasManager = nullptr;
}
GrContext::GrContext(GrContextThreadSafeProxy* proxy)
@@ -231,7 +331,6 @@ GrContext::GrContext(GrContextThreadSafeProxy* proxy)
fResourceProvider = nullptr;
fProxyProvider = nullptr;
fGlyphCache = nullptr;
- fFullAtlasManager = nullptr;
}
bool GrContext::init(const GrContextOptions& options) {
@@ -288,26 +387,8 @@ bool GrContext::init(const GrContextOptions& options) {
fDrawingManager.reset(new GrDrawingManager(this, prcOptions, atlasTextContextOptions,
&fSingleOwner, options.fSortRenderTargets));
- 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;
- }
-
fGlyphCache = new GrGlyphCache;
- // DDL TODO: in DDL-mode grab a GrRestrictedAtlasManager from the thread-proxy and
- // do not add an onFlushCB
- fFullAtlasManager = new GrAtlasManager(fProxyProvider, fGlyphCache,
- options.fGlyphCacheTextureMaximumBytes,
- allowMultitexturing);
- this->contextPriv().addOnFlushCallbackObject(fFullAtlasManager);
-
- fGlyphCache->setGlyphSizeLimit(fFullAtlasManager->getGlyphSizeLimit());
-
fTextBlobCache.reset(new GrTextBlobCache(TextBlobCacheOverBudgetCB,
this, this->uniqueID(), SkToBool(fGpu)));
@@ -323,10 +404,6 @@ bool GrContext::init(const GrContextOptions& options) {
GrContext::~GrContext() {
ASSERT_SINGLE_OWNER
- if (fGpu) {
- this->flush();
- }
-
if (fDrawingManager) {
fDrawingManager->cleanup();
}
@@ -339,7 +416,6 @@ GrContext::~GrContext() {
delete fResourceCache;
delete fProxyProvider;
delete fGlyphCache;
- delete fFullAtlasManager;
}
sk_sp<GrContextThreadSafeProxy> GrContext::threadSafeProxy() {
@@ -399,7 +475,6 @@ void GrContext::abandonContext() {
fGpu->disconnect(GrGpu::DisconnectType::kAbandon);
fGlyphCache->freeAll();
- fFullAtlasManager->freeAll();
fTextBlobCache->freeAll();
}
@@ -419,7 +494,6 @@ void GrContext::releaseResourcesAndAbandonContext() {
fGpu->disconnect(GrGpu::DisconnectType::kCleanup);
fGlyphCache->freeAll();
- fFullAtlasManager->freeAll();
fTextBlobCache->freeAll();
}
@@ -431,10 +505,7 @@ void GrContext::resetContext(uint32_t state) {
void GrContext::freeGpuResources() {
ASSERT_SINGLE_OWNER
- this->flush();
-
fGlyphCache->freeAll();
- fFullAtlasManager->freeAll();
fDrawingManager->freeGpuResources();
diff --git a/src/gpu/GrContextPriv.h b/src/gpu/GrContextPriv.h
index c2e525d9b9..a8fda09efe 100644
--- a/src/gpu/GrContextPriv.h
+++ b/src/gpu/GrContextPriv.h
@@ -190,16 +190,14 @@ public:
GrGlyphCache* getGlyphCache() { return fContext->fGlyphCache; }
GrTextBlobCache* getTextBlobCache() { return fContext->fTextBlobCache.get(); }
- GrRestrictedAtlasManager* getRestrictedAtlasManager() { return fContext->fFullAtlasManager; }
+
+ GrRestrictedAtlasManager* getRestrictedAtlasManager() {
+ return fContext->onGetRestrictedAtlasManager();
+ }
// This accessor should only ever be called by the GrOpFlushState.
GrAtlasManager* getFullAtlasManager() {
- if (fContext->fResourceProvider) {
- // Disallow access to the full atlasManager when recording DDLs
- return fContext->fFullAtlasManager;
- }
-
- return nullptr;
+ return fContext->onGetFullAtlasManager();
}
void moveOpListsToDDL(SkDeferredDisplayList*);