diff options
-rw-r--r-- | include/gpu/GrContext.h | 10 | ||||
-rw-r--r-- | src/core/SkDeferredDisplayListRecorder.cpp | 2 | ||||
-rw-r--r-- | src/gpu/GrContext.cpp | 61 | ||||
-rw-r--r-- | src/gpu/GrDrawOpAtlas.cpp | 15 | ||||
-rw-r--r-- | src/gpu/GrDrawingManager.cpp | 7 | ||||
-rw-r--r-- | src/gpu/GrDrawingManager.h | 3 | ||||
-rw-r--r-- | src/gpu/GrOpFlushState.cpp | 26 | ||||
-rw-r--r-- | src/gpu/GrRenderTargetOpList.cpp | 5 | ||||
-rw-r--r-- | src/gpu/GrRenderTargetOpList.h | 2 |
9 files changed, 77 insertions, 54 deletions
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h index 6b5d7500fa..71f903c399 100644 --- a/include/gpu/GrContext.h +++ b/include/gpu/GrContext.h @@ -115,7 +115,7 @@ public: } /** - * Abandons all GPU resources and assumes the underlying backend 3D API context is not longer + * Abandons all GPU resources and assumes the underlying backend 3D API context is no longer * usable. Call this if you have lost the associated GPU context, and thus internal texture, * buffer, etc. references/IDs are now invalid. Calling this ensures that the destructors of the * GrContext and any of its created resource objects will not make backend 3D API calls. Content @@ -349,6 +349,10 @@ public: GrContextPriv contextPriv(); const GrContextPriv contextPriv() const; +protected: + GrContext(GrContextThreadSafeProxy*); + GrContext(GrBackend); + private: sk_sp<GrGpu> fGpu; sk_sp<const GrCaps> fCaps; @@ -393,9 +397,7 @@ private: // TODO: have the GrClipStackClip use renderTargetContexts and rm this friending friend class GrContextPriv; - GrContext(GrBackend); // init must be called after the constructor. - GrContext(GrContextThreadSafeProxy*); - bool init(const GrContextOptions&); + bool init(const GrContextOptions&); // init must be called after either constructor. /** * These functions create premul <-> unpremul effects. If the second argument is 'true', they diff --git a/src/core/SkDeferredDisplayListRecorder.cpp b/src/core/SkDeferredDisplayListRecorder.cpp index 7c63fd7832..ee168c9aaa 100644 --- a/src/core/SkDeferredDisplayListRecorder.cpp +++ b/src/core/SkDeferredDisplayListRecorder.cpp @@ -34,7 +34,7 @@ bool SkDeferredDisplayListRecorder::init() { fSurface = SkSurface::MakeRaster(ii, &fCharacterization.surfaceProps()); #else if (!fContext) { - fContext = GrContextPriv::MakeStubbedOut(fCharacterization.contextInfo()); + fContext = GrContextPriv::MakeDDL(fCharacterization.contextInfo()); if (!fContext) { return false; } diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index c13cd539c2..eedb3e475f 100644 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -62,6 +62,26 @@ SkASSERT(!(P) || !((P)->priv().peekTexture()) || (P)->priv().peekTexture()->getC //////////////////////////////////////////////////////////////////////////////// +class SK_API GrDirectContext : public GrContext { +public: + GrDirectContext(GrBackend backend) : INHERITED(backend) { } + +protected: + +private: + typedef GrContext INHERITED; +}; + +class SK_API GrDDLContext : public GrContext { +public: + GrDDLContext(GrContextThreadSafeProxy* proxy) : INHERITED(proxy) {} + +protected: + +private: + typedef GrContext INHERITED; +}; + GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext) { GrContextOptions defaultOptions; return Create(backend, backendContext, defaultOptions); @@ -70,7 +90,7 @@ GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext) GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext, const GrContextOptions& options) { - sk_sp<GrContext> context(new GrContext(backend)); + sk_sp<GrContext> context(new GrDirectContext(backend)); context->fGpu = GrGpu::Make(backend, backendContext, options, context.get()); if (!context->fGpu) { @@ -91,7 +111,7 @@ sk_sp<GrContext> GrContext::MakeGL(sk_sp<const GrGLInterface> interface) { sk_sp<GrContext> GrContext::MakeGL(sk_sp<const GrGLInterface> interface, const GrContextOptions& options) { - sk_sp<GrContext> context(new GrContext(kOpenGL_GrBackend)); + sk_sp<GrContext> context(new GrDirectContext(kOpenGL_GrBackend)); context->fGpu = GrGLGpu::Make(std::move(interface), options, context.get()); if (!context->fGpu) { @@ -119,7 +139,7 @@ sk_sp<GrContext> GrContext::MakeMock(const GrMockOptions* mockOptions) { sk_sp<GrContext> GrContext::MakeMock(const GrMockOptions* mockOptions, const GrContextOptions& options) { - sk_sp<GrContext> context(new GrContext(kMock_GrBackend)); + sk_sp<GrContext> context(new GrDirectContext(kMock_GrBackend)); context->fGpu = GrMockGpu::Make(mockOptions, options, context.get()); if (!context->fGpu) { @@ -139,7 +159,7 @@ sk_sp<GrContext> GrContext::MakeVulkan(sk_sp<const GrVkBackendContext> backendCo sk_sp<GrContext> GrContext::MakeVulkan(sk_sp<const GrVkBackendContext> backendContext, const GrContextOptions& options) { - sk_sp<GrContext> context(new GrContext(kVulkan_GrBackend)); + sk_sp<GrContext> context(new GrDirectContext(kVulkan_GrBackend)); context->fGpu = GrVkGpu::Make(std::move(backendContext), options, context.get()); if (!context->fGpu) { @@ -182,12 +202,10 @@ static int32_t next_id() { } sk_sp<GrContext> GrContextPriv::MakeDDL(GrContextThreadSafeProxy* proxy) { - sk_sp<GrContext> context(new GrContext(proxy)); + sk_sp<GrContext> context(new GrDDLContext(proxy)); - context->fGpu = GrDDLGpu::Make(context.get(), proxy->fCaps); - if (!context->fGpu) { - return nullptr; - } + // 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; } @@ -204,7 +222,8 @@ GrContext::GrContext(GrBackend backend) } GrContext::GrContext(GrContextThreadSafeProxy* proxy) - : fUniqueID(proxy->fContextUniqueID) + : fCaps(proxy->fCaps) + , fUniqueID(proxy->fContextUniqueID) , fBackend(proxy->fBackend) { fResourceCache = nullptr; fResourceProvider = nullptr; @@ -214,11 +233,18 @@ GrContext::GrContext(GrContextThreadSafeProxy* proxy) bool GrContext::init(const GrContextOptions& options) { ASSERT_SINGLE_OWNER - fCaps = fGpu->refCaps(); - fResourceCache = new GrResourceCache(fCaps.get(), fUniqueID); - fResourceProvider = new GrResourceProvider(fGpu.get(), fResourceCache, &fSingleOwner); + + if (fGpu) { + fCaps = fGpu->refCaps(); + fResourceCache = new GrResourceCache(fCaps.get(), fUniqueID); + fResourceProvider = new GrResourceProvider(fGpu.get(), fResourceCache, &fSingleOwner); + } + fProxyProvider = new GrProxyProvider(fResourceProvider, fResourceCache, fCaps, &fSingleOwner); - fResourceCache->setProxyProvider(fProxyProvider); + + if (fResourceCache) { + 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. @@ -284,13 +310,10 @@ bool GrContext::init(const GrContextOptions& options) { GrContext::~GrContext() { ASSERT_SINGLE_OWNER - if (!fGpu) { - SkASSERT(!fCaps); - return; + if (fGpu) { + this->flush(); } - this->flush(); - fDrawingManager->cleanup(); for (int i = 0; i < fCleanUpData.count(); ++i) { diff --git a/src/gpu/GrDrawOpAtlas.cpp b/src/gpu/GrDrawOpAtlas.cpp index 1d41060eb7..e564e63b04 100644 --- a/src/gpu/GrDrawOpAtlas.cpp +++ b/src/gpu/GrDrawOpAtlas.cpp @@ -464,18 +464,9 @@ bool GrDrawOpAtlas::createNewPage() { desc.fHeight = fTextureHeight; desc.fConfig = fPixelConfig; - // We don't want to flush the context so we claim we're in the middle of flushing so as to - // guarantee we do not recieve a texture with pending IO - // TODO: Determine how to avoid having to do this. (https://bug.skia.org/4156) - static const uint32_t kFlags = GrResourceProvider::kNoPendingIO_Flag; - // MDB TODO: for now, wrap an instantiated texture. Having the deferred instantiation - // possess the correct properties (e.g., no pendingIO) should fall out of the system but - // should receive special attention. - // Note: When switching over to the deferred proxy, use the kExact flag to create - // the atlas and assert that the width & height are powers of 2. - // DDL TODO: remove this use of createInstantitateProxy & convert it to a testing-only method. - fProxies[fNumPages] = proxyProvider->createInstantiatedProxy(desc, SkBackingFit::kApprox, - SkBudgeted::kYes, kFlags); + SkASSERT(SkIsPow2(fTextureWidth) && SkIsPow2(fTextureHeight)); + fProxies[fNumPages] = proxyProvider->createProxy(desc, SkBackingFit::kExact, SkBudgeted::kYes, + GrResourceProvider::kNoPendingIO_Flag); if (!fProxies[fNumPages]) { return false; } diff --git a/src/gpu/GrDrawingManager.cpp b/src/gpu/GrDrawingManager.cpp index 3f6c77379a..e25b33c7be 100644 --- a/src/gpu/GrDrawingManager.cpp +++ b/src/gpu/GrDrawingManager.cpp @@ -322,9 +322,10 @@ sk_sp<GrRenderTargetOpList> GrDrawingManager::newRTOpList(GrRenderTargetProxy* r fOpLists.back()->makeClosed(*fContext->caps()); } - sk_sp<GrRenderTargetOpList> opList(new GrRenderTargetOpList(rtp, - fContext->getGpu(), - fContext->getAuditTrail())); + sk_sp<GrRenderTargetOpList> opList(new GrRenderTargetOpList( + rtp, + fContext->contextPriv().resourceProvider(), + fContext->getAuditTrail())); SkASSERT(rtp->getLastOpList() == opList.get()); if (managedOpList) { diff --git a/src/gpu/GrDrawingManager.h b/src/gpu/GrDrawingManager.h index e9e98af4a7..2b01fc3119 100644 --- a/src/gpu/GrDrawingManager.h +++ b/src/gpu/GrDrawingManager.h @@ -64,7 +64,8 @@ public: GrCoverageCountingPathRenderer* getCoverageCountingPathRenderer(); void flushIfNecessary() { - if (fContext->contextPriv().getResourceCache()->requestsFlush()) { + GrResourceCache* resourceCache = fContext->contextPriv().getResourceCache(); + if (resourceCache && resourceCache->requestsFlush()) { this->internalFlush(nullptr, GrResourceCache::kCacheRequested, 0, nullptr); } } diff --git a/src/gpu/GrOpFlushState.cpp b/src/gpu/GrOpFlushState.cpp index 5e4ed35826..06ee4d96db 100644 --- a/src/gpu/GrOpFlushState.cpp +++ b/src/gpu/GrOpFlushState.cpp @@ -78,33 +78,37 @@ void GrOpFlushState::reset() { } void GrOpFlushState::doUpload(GrDeferredTextureUploadFn& upload) { - GrDeferredTextureUploadWritePixelsFn wp = [this](GrTextureProxy* proxy, int left, int top, - int width, int height, GrPixelConfig config, + GrDeferredTextureUploadWritePixelsFn wp = [this](GrTextureProxy* dstProxy, int left, int top, + int width, int height, GrPixelConfig srcConfig, const void* buffer, size_t rowBytes) { - GrSurface* surface = proxy->priv().peekSurface(); + GrSurface* dstSurface = dstProxy->priv().peekSurface(); GrGpu::DrawPreference drawPreference = GrGpu::kNoDraw_DrawPreference; GrGpu::WritePixelTempDrawInfo tempInfo; - fGpu->getWritePixelsInfo(surface, proxy->origin(), width, height, proxy->config(), - &drawPreference, &tempInfo); + if (!fGpu->getWritePixelsInfo(dstSurface, dstProxy->origin(), + width, height, srcConfig, + &drawPreference, &tempInfo)) { + return false; + } if (GrGpu::kNoDraw_DrawPreference == drawPreference) { - return this->fGpu->writePixels(surface, proxy->origin(), left, top, width, height, - config, buffer, rowBytes); + return this->fGpu->writePixels(dstSurface, dstProxy->origin(), + left, top, width, height, + srcConfig, buffer, rowBytes); } GrSurfaceDesc desc; - desc.fOrigin = proxy->origin(); + desc.fOrigin = dstProxy->origin(); desc.fWidth = width; desc.fHeight = height; - desc.fConfig = proxy->config(); + desc.fConfig = dstProxy->config(); sk_sp<GrTexture> temp(this->fResourceProvider->createApproxTexture( desc, GrResourceProvider::kNoPendingIO_Flag)); if (!temp) { return false; } - if (!fGpu->writePixels(temp.get(), proxy->origin(), 0, 0, width, height, desc.fConfig, + if (!fGpu->writePixels(temp.get(), dstProxy->origin(), 0, 0, width, height, desc.fConfig, buffer, rowBytes)) { return false; } - return fGpu->copySurface(surface, proxy->origin(), temp.get(), proxy->origin(), + return fGpu->copySurface(dstSurface, dstProxy->origin(), temp.get(), dstProxy->origin(), SkIRect::MakeWH(width, height), {left, top}); }; upload(wp); diff --git a/src/gpu/GrRenderTargetOpList.cpp b/src/gpu/GrRenderTargetOpList.cpp index 0f62bc6a35..0c806bfe2c 100644 --- a/src/gpu/GrRenderTargetOpList.cpp +++ b/src/gpu/GrRenderTargetOpList.cpp @@ -24,9 +24,10 @@ static const int kMaxOpLookback = 10; static const int kMaxOpLookahead = 10; -GrRenderTargetOpList::GrRenderTargetOpList(GrRenderTargetProxy* proxy, GrGpu* gpu, +GrRenderTargetOpList::GrRenderTargetOpList(GrRenderTargetProxy* proxy, + GrResourceProvider* resourceProvider, GrAuditTrail* auditTrail) - : INHERITED(gpu->getContext()->contextPriv().resourceProvider(), proxy, auditTrail) + : INHERITED(resourceProvider, proxy, auditTrail) , fLastClipStackGenID(SK_InvalidUniqueID) SkDEBUGCODE(, fNumClips(0)) { } diff --git a/src/gpu/GrRenderTargetOpList.h b/src/gpu/GrRenderTargetOpList.h index 5803d38f37..6b736338f7 100644 --- a/src/gpu/GrRenderTargetOpList.h +++ b/src/gpu/GrRenderTargetOpList.h @@ -32,7 +32,7 @@ private: using DstProxy = GrXferProcessor::DstProxy; public: - GrRenderTargetOpList(GrRenderTargetProxy*, GrGpu*, GrAuditTrail*); + GrRenderTargetOpList(GrRenderTargetProxy*, GrResourceProvider*, GrAuditTrail*); ~GrRenderTargetOpList() override; |