Fix creation of extra GrContextThreadSafeProxies in DDL world

For the DDLContexts we simply want to reuse the threadSafeProxy from the main thread but we, obviously, still need to create one for the main DirectContext.

TBR=bsalomon@google.com
Change-Id: I99449bc375172c9004e2e80c21d95ab2d7708309
Reviewed-on: https://skia-review.googlesource.com/110781
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
This commit is contained in:
Robert Phillips 2018-03-02 08:53:14 -05:00 committed by Skia Commit-Bot
parent e35a99ed70
commit fde6fa0903
5 changed files with 43 additions and 35 deletions

View File

@ -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;
};

View File

@ -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; }

View File

@ -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,

View File

@ -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);
}

View File

@ -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(); }