Move atlas manager creation to GrContext derived classes (take 2)
TBR=bsalomon@google.com Change-Id: Ie10b7e770e24104d10c36ce7882126dd8551a8ba Reviewed-on: https://skia-review.googlesource.com/110822 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Robert Phillips <robertphillips@google.com>
This commit is contained in:
parent
4f16db62e5
commit
1056eb821f
@ -36,6 +36,7 @@ class GrRenderTargetContext;
|
||||
class GrResourceEntry;
|
||||
class GrResourceCache;
|
||||
class GrResourceProvider;
|
||||
class GrRestrictedAtlasManager;
|
||||
class GrSamplerState;
|
||||
class GrSurfaceProxy;
|
||||
class GrSwizzle;
|
||||
@ -127,7 +128,7 @@ public:
|
||||
* The typical use case for this function is that the underlying 3D context was lost and further
|
||||
* API calls may crash.
|
||||
*/
|
||||
void abandonContext();
|
||||
virtual void abandonContext();
|
||||
|
||||
/**
|
||||
* This is similar to abandonContext() however the underlying 3D context is not yet lost and
|
||||
@ -138,7 +139,7 @@ public:
|
||||
* but can't guarantee that GrContext will be destroyed first (perhaps because it may be ref'ed
|
||||
* elsewhere by either the client or Skia objects).
|
||||
*/
|
||||
void releaseResourcesAndAbandonContext();
|
||||
virtual void releaseResourcesAndAbandonContext();
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Resource Cache
|
||||
@ -183,7 +184,7 @@ public:
|
||||
* Frees GPU created by the context. Can be called to reduce GPU memory
|
||||
* pressure.
|
||||
*/
|
||||
void freeGpuResources();
|
||||
virtual void freeGpuResources();
|
||||
|
||||
/**
|
||||
* Purge all the unlocked resources from the cache.
|
||||
@ -358,9 +359,15 @@ protected:
|
||||
GrContext(GrContextThreadSafeProxy*);
|
||||
GrContext(GrBackend);
|
||||
|
||||
virtual bool init(const GrContextOptions&); // init must be called after either constructor.
|
||||
|
||||
virtual GrAtlasManager* onGetFullAtlasManager() = 0;
|
||||
virtual GrRestrictedAtlasManager* onGetRestrictedAtlasManager() = 0;
|
||||
|
||||
sk_sp<const GrCaps> fCaps;
|
||||
|
||||
private:
|
||||
sk_sp<GrGpu> fGpu;
|
||||
sk_sp<const GrCaps> fCaps;
|
||||
GrResourceCache* fResourceCache;
|
||||
GrResourceProvider* fResourceProvider;
|
||||
GrProxyProvider* fProxyProvider;
|
||||
@ -368,7 +375,6 @@ private:
|
||||
sk_sp<GrContextThreadSafeProxy> fThreadSafeProxy;
|
||||
|
||||
GrGlyphCache* fGlyphCache;
|
||||
GrAtlasManager* fFullAtlasManager;
|
||||
std::unique_ptr<GrTextBlobCache> fTextBlobCache;
|
||||
|
||||
bool fDisableGpuYUVConversion;
|
||||
@ -404,8 +410,6 @@ private:
|
||||
// TODO: have the GrClipStackClip use renderTargetContexts and rm this friending
|
||||
friend class GrContextPriv;
|
||||
|
||||
bool init(const GrContextOptions&); // init must be called after either constructor.
|
||||
|
||||
/**
|
||||
* These functions create premul <-> unpremul effects. If the second argument is 'true', they
|
||||
* use the specialized round-trip effects from GrConfigConversionEffect, otherwise they
|
||||
|
@ -64,22 +64,127 @@ 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 if-test protects against the case where the context is being destroyed
|
||||
// before having been fully created
|
||||
if (this->contextPriv().getGpu()) {
|
||||
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 +285,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 +325,6 @@ GrContext::GrContext(GrBackend backend)
|
||||
fResourceProvider = nullptr;
|
||||
fProxyProvider = nullptr;
|
||||
fGlyphCache = nullptr;
|
||||
fFullAtlasManager = nullptr;
|
||||
}
|
||||
|
||||
GrContext::GrContext(GrContextThreadSafeProxy* proxy)
|
||||
@ -231,7 +335,6 @@ GrContext::GrContext(GrContextThreadSafeProxy* proxy)
|
||||
fResourceProvider = nullptr;
|
||||
fProxyProvider = nullptr;
|
||||
fGlyphCache = nullptr;
|
||||
fFullAtlasManager = nullptr;
|
||||
}
|
||||
|
||||
bool GrContext::init(const GrContextOptions& options) {
|
||||
@ -288,26 +391,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 +408,6 @@ bool GrContext::init(const GrContextOptions& options) {
|
||||
GrContext::~GrContext() {
|
||||
ASSERT_SINGLE_OWNER
|
||||
|
||||
if (fGpu) {
|
||||
this->flush();
|
||||
}
|
||||
|
||||
if (fDrawingManager) {
|
||||
fDrawingManager->cleanup();
|
||||
}
|
||||
@ -339,7 +420,6 @@ GrContext::~GrContext() {
|
||||
delete fResourceCache;
|
||||
delete fProxyProvider;
|
||||
delete fGlyphCache;
|
||||
delete fFullAtlasManager;
|
||||
}
|
||||
|
||||
sk_sp<GrContextThreadSafeProxy> GrContext::threadSafeProxy() {
|
||||
@ -399,7 +479,6 @@ void GrContext::abandonContext() {
|
||||
fGpu->disconnect(GrGpu::DisconnectType::kAbandon);
|
||||
|
||||
fGlyphCache->freeAll();
|
||||
fFullAtlasManager->freeAll();
|
||||
fTextBlobCache->freeAll();
|
||||
}
|
||||
|
||||
@ -419,7 +498,6 @@ void GrContext::releaseResourcesAndAbandonContext() {
|
||||
fGpu->disconnect(GrGpu::DisconnectType::kCleanup);
|
||||
|
||||
fGlyphCache->freeAll();
|
||||
fFullAtlasManager->freeAll();
|
||||
fTextBlobCache->freeAll();
|
||||
}
|
||||
|
||||
@ -431,10 +509,7 @@ void GrContext::resetContext(uint32_t state) {
|
||||
void GrContext::freeGpuResources() {
|
||||
ASSERT_SINGLE_OWNER
|
||||
|
||||
this->flush();
|
||||
|
||||
fGlyphCache->freeAll();
|
||||
fFullAtlasManager->freeAll();
|
||||
|
||||
fDrawingManager->freeGpuResources();
|
||||
|
||||
|
@ -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*);
|
||||
|
@ -94,7 +94,10 @@ void GrContext::setTextBlobCacheLimit_ForTesting(size_t bytes) {
|
||||
}
|
||||
|
||||
void GrContext::setTextContextAtlasSizes_ForTesting(const GrDrawOpAtlasConfig* configs) {
|
||||
fFullAtlasManager->setAtlasSizes_ForTesting(configs);
|
||||
GrAtlasManager* atlasManager = this->contextPriv().getFullAtlasManager();
|
||||
if (atlasManager) {
|
||||
atlasManager->setAtlasSizes_ForTesting(configs);
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
Loading…
Reference in New Issue
Block a user