diff options
-rw-r--r-- | include/gpu/GrContext.h | 17 | ||||
-rw-r--r-- | include/private/SkSurfaceCharacterization.h | 1 | ||||
-rw-r--r-- | src/core/SkDeferredDisplayListRecorder.cpp | 3 | ||||
-rw-r--r-- | src/gpu/GrContext.cpp | 55 | ||||
-rw-r--r-- | src/gpu/GrContextPriv.h | 2 |
5 files changed, 43 insertions, 35 deletions
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h index 1b43d99f2e..6578638183 100644 --- a/include/gpu/GrContext.h +++ b/include/gpu/GrContext.h @@ -356,15 +356,17 @@ public: const GrContextPriv contextPriv() const; protected: - GrContext(GrContextThreadSafeProxy*); - GrContext(GrBackend); + GrContext(GrBackend, int32_t id = SK_InvalidGenID); - virtual bool init(const GrContextOptions&); // init must be called after either constructor. + bool initCommon(const GrContextOptions&); + virtual bool init(const GrContextOptions&) = 0; // must be called after the ctor! virtual GrAtlasManager* onGetFullAtlasManager() = 0; virtual GrRestrictedAtlasManager* onGetRestrictedAtlasManager() = 0; + const GrBackend fBackend; sk_sp<const GrCaps> fCaps; + sk_sp<GrContextThreadSafeProxy> fThreadSafeProxy; private: sk_sp<GrGpu> fGpu; @@ -372,7 +374,6 @@ private: GrResourceProvider* fResourceProvider; GrProxyProvider* fProxyProvider; - sk_sp<GrContextThreadSafeProxy> fThreadSafeProxy; GrGlyphCache* fGlyphCache; std::unique_ptr<GrTextBlobCache> fTextBlobCache; @@ -403,8 +404,6 @@ private: GrAuditTrail fAuditTrail; - const GrBackend fBackend; - GrContextOptions::PersistentCache* fPersistentCache; // TODO: have the GrClipStackClip use renderTargetContexts and rm this friending @@ -495,9 +494,9 @@ private: const GrBackend fBackend; const GrContextOptions fOptions; - friend class GrContext; - friend class GrContextPriv; - friend class SkImage; + friend class GrDirectContext; // To construct this object + friend class GrContextPriv; // for access to 'fOptions' in MakeDDL + friend class GrDDLContext; // to implement the GrDDLContext ctor (access to all members) typedef SkRefCnt INHERITED; }; diff --git a/include/private/SkSurfaceCharacterization.h b/include/private/SkSurfaceCharacterization.h index 48c22351b3..9327a538b6 100644 --- a/include/private/SkSurfaceCharacterization.h +++ b/include/private/SkSurfaceCharacterization.h @@ -55,6 +55,7 @@ public: SkSurfaceCharacterization& operator=(const SkSurfaceCharacterization& other) = default; GrContextThreadSafeProxy* contextInfo() const { return fContextInfo.get(); } + sk_sp<GrContextThreadSafeProxy> refContextInfo() const { return fContextInfo; } size_t cacheMaxResourceBytes() const { return fCacheMaxResourceBytes; } bool isValid() const { return kUnknown_GrPixelConfig != fConfig; } diff --git a/src/core/SkDeferredDisplayListRecorder.cpp b/src/core/SkDeferredDisplayListRecorder.cpp index a9dbcd45b2..acd7b67b4c 100644 --- a/src/core/SkDeferredDisplayListRecorder.cpp +++ b/src/core/SkDeferredDisplayListRecorder.cpp @@ -58,7 +58,7 @@ bool SkDeferredDisplayListRecorder::init() { #if SK_SUPPORT_GPU if (!fContext) { - fContext = GrContextPriv::MakeDDL(fCharacterization.contextInfo()); + fContext = GrContextPriv::MakeDDL(fCharacterization.refContextInfo()); if (!fContext) { return false; } @@ -95,6 +95,7 @@ bool SkDeferredDisplayListRecorder::init() { return sk_ref_sp<GrSurface>(lazyProxyData->fReplayDest->priv().peekSurface()); }, desc, + GrRenderTargetFlags::kNone, GrProxyProvider::Textureable(fCharacterization.isTextureable()), GrMipMapped::kNo, SkBackingFit::kExact, diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index 7cca4a44ad..83b876ba47 100644 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -98,7 +98,13 @@ public: protected: bool init(const GrContextOptions& options) override { - if (!INHERITED::init(options)) { + 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; } @@ -138,9 +144,11 @@ private: */ class SK_API GrDDLContext : public GrContext { public: - GrDDLContext(GrContextThreadSafeProxy* proxy) - : INHERITED(proxy) + GrDDLContext(sk_sp<GrContextThreadSafeProxy> proxy) + : INHERITED(proxy->fBackend, proxy->fContextUniqueID) , fRestrictedAtlasManager(nullptr) { + fCaps = proxy->fCaps; + fThreadSafeProxy = std::move(proxy); } ~GrDDLContext() override { @@ -164,7 +172,10 @@ public: protected: bool init(const GrContextOptions& options) override { - if (!INHERITED::init(options)) { + SkASSERT(fCaps); // should've been set in ctor + SkASSERT(fThreadSafeProxy); // should've been set in the ctor + + if (!INHERITED::initCommon(options)) { return false; } @@ -203,6 +214,7 @@ GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext, return nullptr; } + context->fCaps = context->fGpu->refCaps(); if (!context->init(options)) { return nullptr; } @@ -223,6 +235,8 @@ sk_sp<GrContext> GrContext::MakeGL(sk_sp<const GrGLInterface> interface, if (!context->fGpu) { return nullptr; } + + context->fCaps = context->fGpu->refCaps(); if (!context->init(options)) { return nullptr; } @@ -251,6 +265,8 @@ sk_sp<GrContext> GrContext::MakeMock(const GrMockOptions* mockOptions, if (!context->fGpu) { return nullptr; } + + context->fCaps = context->fGpu->refCaps(); if (!context->init(options)) { return nullptr; } @@ -271,6 +287,8 @@ sk_sp<GrContext> GrContext::MakeVulkan(sk_sp<const GrVkBackendContext> backendCo if (!context->fGpu) { return nullptr; } + + context->fCaps = context->fGpu->refCaps(); if (!context->init(options)) { return nullptr; } @@ -307,7 +325,7 @@ static int32_t next_id() { return id; } -sk_sp<GrContext> GrContextPriv::MakeDDL(GrContextThreadSafeProxy* proxy) { +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 @@ -318,27 +336,19 @@ sk_sp<GrContext> GrContextPriv::MakeDDL(GrContextThreadSafeProxy* proxy) { return context; } -GrContext::GrContext(GrBackend backend) - : fUniqueID(next_id()) - , fBackend(backend) { +GrContext::GrContext(GrBackend backend, int32_t id) + : fBackend(backend) + , fUniqueID(SK_InvalidGenID == id ? next_id() : id) { fResourceCache = nullptr; fResourceProvider = nullptr; fProxyProvider = nullptr; fGlyphCache = nullptr; } -GrContext::GrContext(GrContextThreadSafeProxy* proxy) - : fCaps(proxy->fCaps) - , fUniqueID(proxy->fContextUniqueID) - , fBackend(proxy->fBackend) { - fResourceCache = nullptr; - fResourceProvider = nullptr; - fProxyProvider = nullptr; - fGlyphCache = nullptr; -} - -bool GrContext::init(const GrContextOptions& options) { +bool GrContext::initCommon(const GrContextOptions& options) { ASSERT_SINGLE_OWNER + SkASSERT(fCaps); // needs to have been initialized by derived classes + SkASSERT(fThreadSafeProxy); // needs to have been initialized by derived classes if (fGpu) { fCaps = fGpu->refCaps(); @@ -353,11 +363,6 @@ bool GrContext::init(const GrContextOptions& options) { 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. - fThreadSafeProxy.reset(new GrContextThreadSafeProxy(fCaps, this->uniqueID(), fBackend, - options)); - fDisableGpuYUVConversion = options.fDisableGpuYUVConversion; fSharpenMipmappedTextures = options.fSharpenMipmappedTextures; fDidTestPMConversions = false; @@ -396,6 +401,8 @@ bool GrContext::init(const GrContextOptions& options) { fTextBlobCache.reset(new GrTextBlobCache(TextBlobCacheOverBudgetCB, this, this->uniqueID(), SkToBool(fGpu))); + // 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. if (options.fExecutor) { fTaskGroup = skstd::make_unique<SkTaskGroup>(*options.fExecutor); } diff --git a/src/gpu/GrContextPriv.h b/src/gpu/GrContextPriv.h index a8fda09efe..d8baef8f2d 100644 --- a/src/gpu/GrContextPriv.h +++ b/src/gpu/GrContextPriv.h @@ -28,7 +28,7 @@ public: /** * Create a GrContext without a resource cache */ - static sk_sp<GrContext> MakeDDL(GrContextThreadSafeProxy*); + static sk_sp<GrContext> MakeDDL(sk_sp<GrContextThreadSafeProxy>); GrDrawingManager* drawingManager() { return fContext->fDrawingManager.get(); } |