From 63410e921c68d733d833f1f1bb77e44c848f3f3b Mon Sep 17 00:00:00 2001 From: Brian Salomon Date: Mon, 23 Mar 2020 18:32:50 -0400 Subject: [PATCH] Pass description of GrSurface to GrSurfaceProxy lazy callbacks. Also make GrDynamicAtlas directly use the GrSurface callback type rather than go through a springboard. Change-Id: I3e3c155bbc1e2e794e0d6828b0ea3c64c6a7f3e9 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/283226 Commit-Queue: Brian Salomon Reviewed-by: Greg Daniel Reviewed-by: Robert Phillips --- src/core/SkDeferredDisplayListRecorder.cpp | 3 +- src/gpu/GrAHardwareBufferImageGenerator.cpp | 22 +++++++------ src/gpu/GrBackendTextureImageGenerator.cpp | 3 +- src/gpu/GrDynamicAtlas.cpp | 19 +++++------- src/gpu/GrDynamicAtlas.h | 14 +++++---- src/gpu/GrProxyProvider.cpp | 23 +++++++------- src/gpu/GrProxyProvider.h | 1 + src/gpu/GrRenderTargetProxy.cpp | 16 ++++++++++ src/gpu/GrRenderTargetProxy.h | 2 ++ src/gpu/GrSurfaceProxy.cpp | 2 +- src/gpu/GrSurfaceProxy.h | 20 +++++++++++- src/gpu/GrTextureProxy.cpp | 22 +++++++++++++ src/gpu/GrTextureProxy.h | 2 ++ src/gpu/GrTextureRenderTargetProxy.cpp | 22 +++++++++++++ src/gpu/GrTextureRenderTargetProxy.h | 2 +- src/gpu/ccpr/GrCCAtlas.h | 12 +++++--- src/gpu/ccpr/GrCCClipPath.cpp | 5 +-- src/gpu/ccpr/GrCCClipPath.h | 6 ++-- src/image/SkImage_GpuBase.cpp | 3 +- src/image/SkSurface_GpuMtl.mm | 29 +++++++++--------- tests/GrSurfaceTest.cpp | 3 +- tests/LazyProxyTest.cpp | 34 +++++++++++---------- tests/OnFlushCallbackTest.cpp | 10 +++--- tests/ResourceAllocatorTest.cpp | 19 ++++++------ 24 files changed, 194 insertions(+), 100 deletions(-) diff --git a/src/core/SkDeferredDisplayListRecorder.cpp b/src/core/SkDeferredDisplayListRecorder.cpp index f45baa08d6..d2e14d7154 100644 --- a/src/core/SkDeferredDisplayListRecorder.cpp +++ b/src/core/SkDeferredDisplayListRecorder.cpp @@ -153,7 +153,8 @@ bool SkDeferredDisplayListRecorder::init() { GrSwizzle readSwizzle = caps->getReadSwizzle(fCharacterization.backendFormat(), grColorType); sk_sp proxy = proxyProvider->createLazyRenderTargetProxy( - [lazyProxyData](GrResourceProvider* resourceProvider) { + [lazyProxyData](GrResourceProvider* resourceProvider, + const GrSurfaceProxy::LazySurfaceDesc&) { // The proxy backing the destination surface had better have been instantiated // prior to the proxy backing the DLL's surface. Steal its GrRenderTarget. SkASSERT(lazyProxyData->fReplayDest->peekSurface()); diff --git a/src/gpu/GrAHardwareBufferImageGenerator.cpp b/src/gpu/GrAHardwareBufferImageGenerator.cpp index 4e603f3231..08e5f52aca 100644 --- a/src/gpu/GrAHardwareBufferImageGenerator.cpp +++ b/src/gpu/GrAHardwareBufferImageGenerator.cpp @@ -117,8 +117,6 @@ GrSurfaceProxyView GrAHardwareBufferImageGenerator::makeView(GrRecordingContext* AHardwareBuffer* hardwareBuffer = fHardwareBuffer; AHardwareBuffer_acquire(hardwareBuffer); - const bool isProtectedContent = fIsProtectedContent; - class AutoAHBRelease { public: AutoAHBRelease(AHardwareBuffer* ahb) : fAhb(ahb) {} @@ -140,21 +138,25 @@ GrSurfaceProxyView GrAHardwareBufferImageGenerator::makeView(GrRecordingContext* }; sk_sp texProxy = proxyProvider->createLazyProxy( - [direct, buffer = AutoAHBRelease(hardwareBuffer), width, height, isProtectedContent, - backendFormat]( - GrResourceProvider* resourceProvider) -> GrSurfaceProxy::LazyCallbackResult { + [direct, buffer = AutoAHBRelease(hardwareBuffer)]( + GrResourceProvider* resourceProvider, + const GrSurfaceProxy::LazySurfaceDesc& desc) + -> GrSurfaceProxy::LazyCallbackResult { GrAHardwareBufferUtils::DeleteImageProc deleteImageProc = nullptr; GrAHardwareBufferUtils::UpdateImageProc updateImageProc = nullptr; GrAHardwareBufferUtils::TexImageCtx texImageCtx = nullptr; + bool isProtected = desc.fProtected == GrProtected::kYes; GrBackendTexture backendTex = - GrAHardwareBufferUtils::MakeBackendTexture(direct, buffer.get(), - width, height, + GrAHardwareBufferUtils::MakeBackendTexture(direct, + buffer.get(), + desc.fDimensions.width(), + desc.fDimensions.height(), &deleteImageProc, &updateImageProc, &texImageCtx, - isProtectedContent, - backendFormat, + isProtected, + desc.fFormat, false); if (!backendTex.isValid()) { return {}; @@ -179,7 +181,7 @@ GrSurfaceProxyView GrAHardwareBufferImageGenerator::makeView(GrRecordingContext* }, backendFormat, {width, height}, GrRenderable::kNo, 1, GrMipMapped::kNo, GrMipMapsStatus::kNotAllocated, GrInternalSurfaceFlags::kReadOnly, SkBackingFit::kExact, - SkBudgeted::kNo, GrProtected::kNo, GrSurfaceProxy::UseAllocator::kYes); + SkBudgeted::kNo, GrProtected(fIsProtectedContent), GrSurfaceProxy::UseAllocator::kYes); GrSwizzle readSwizzle = context->priv().caps()->getReadSwizzle(backendFormat, grColorType); diff --git a/src/gpu/GrBackendTextureImageGenerator.cpp b/src/gpu/GrBackendTextureImageGenerator.cpp index 24ccf07d62..54d4c75a29 100644 --- a/src/gpu/GrBackendTextureImageGenerator.cpp +++ b/src/gpu/GrBackendTextureImageGenerator.cpp @@ -161,7 +161,8 @@ GrSurfaceProxyView GrBackendTextureImageGenerator::onGenerateTexture( // be deleted before we actually execute the lambda. sk_sp proxy = proxyProvider->createLazyProxy( [refHelper = fRefHelper, releaseProcHelper, backendTexture = fBackendTexture]( - GrResourceProvider* resourceProvider) -> GrSurfaceProxy::LazyCallbackResult { + GrResourceProvider* resourceProvider, + const GrSurfaceProxy::LazySurfaceDesc&) -> GrSurfaceProxy::LazyCallbackResult { if (refHelper->fSemaphore) { resourceProvider->priv().gpu()->waitSemaphore(refHelper->fSemaphore.get()); } diff --git a/src/gpu/GrDynamicAtlas.cpp b/src/gpu/GrDynamicAtlas.cpp index 1ad8c6c030..00d0947728 100644 --- a/src/gpu/GrDynamicAtlas.cpp +++ b/src/gpu/GrDynamicAtlas.cpp @@ -46,8 +46,10 @@ private: }; sk_sp GrDynamicAtlas::MakeLazyAtlasProxy( - const LazyInstantiateAtlasCallback& callback, GrColorType colorType, - InternalMultisample internalMultisample, const GrCaps& caps, + LazyInstantiateAtlasCallback&& callback, + GrColorType colorType, + InternalMultisample internalMultisample, + const GrCaps& caps, GrSurfaceProxy::UseAllocator useAllocator) { GrBackendFormat format = caps.getDefaultBackendFormat(colorType, GrRenderable::kYes); @@ -56,12 +58,8 @@ sk_sp GrDynamicAtlas::MakeLazyAtlasProxy( sampleCount = caps.internalMultisampleCount(format); } - auto instantiate = [cb = std::move(callback), format, sampleCount](GrResourceProvider* rp) { - return cb(rp, format, sampleCount); - }; - sk_sp proxy = - GrProxyProvider::MakeFullyLazyProxy(std::move(instantiate), format, GrRenderable::kYes, + GrProxyProvider::MakeFullyLazyProxy(std::move(callback), format, GrRenderable::kYes, sampleCount, GrProtected::kNo, caps, useAllocator); return proxy; @@ -85,12 +83,11 @@ void GrDynamicAtlas::reset(SkISize initialSize, const GrCaps& caps) { fTopNode = nullptr; fDrawBounds.setEmpty(); fTextureProxy = MakeLazyAtlasProxy( - [this](GrResourceProvider* resourceProvider, const GrBackendFormat& format, - int sampleCount) { + [this](GrResourceProvider* resourceProvider, const LazyAtlasDesc& desc) { if (!fBackingTexture) { fBackingTexture = resourceProvider->createTexture( - {fWidth, fHeight}, format, GrRenderable::kYes, sampleCount, - GrMipMapped::kNo, SkBudgeted::kYes, GrProtected::kNo); + {fWidth, fHeight}, desc.fFormat, desc.fRenderable, desc.fSampleCnt, + desc.fMipMapped, desc.fBudgeted, desc.fProtected); } return GrSurfaceProxy::LazyCallbackResult(fBackingTexture); }, diff --git a/src/gpu/GrDynamicAtlas.h b/src/gpu/GrDynamicAtlas.h index 609dd5bfc6..7a7780cc8c 100644 --- a/src/gpu/GrDynamicAtlas.h +++ b/src/gpu/GrDynamicAtlas.h @@ -27,23 +27,25 @@ public: static constexpr GrSurfaceOrigin kTextureOrigin = kTopLeft_GrSurfaceOrigin; static constexpr int kPadding = 1; // Amount of padding below and to the right of each path. - using LazyInstantiateAtlasCallback = std::function; + using LazyAtlasDesc = GrSurfaceProxy::LazySurfaceDesc; + using LazyInstantiateAtlasCallback = GrSurfaceProxy::LazyInstantiateCallback; enum class InternalMultisample : bool { kNo = false, kYes = true }; - static sk_sp MakeLazyAtlasProxy(const LazyInstantiateAtlasCallback&, - GrColorType colorType, InternalMultisample, - const GrCaps&, GrSurfaceProxy::UseAllocator); + static sk_sp MakeLazyAtlasProxy(LazyInstantiateAtlasCallback&&, + GrColorType colorType, + InternalMultisample, + const GrCaps&, + GrSurfaceProxy::UseAllocator); GrDynamicAtlas(GrColorType colorType, InternalMultisample, SkISize initialSize, int maxAtlasSize, const GrCaps&); virtual ~GrDynamicAtlas(); - void reset(SkISize initialSize, const GrCaps& caps); + void reset(SkISize initialSize, const GrCaps& desc); GrTextureProxy* textureProxy() const { return fTextureProxy.get(); } bool isInstantiated() const { return fTextureProxy->isInstantiated(); } diff --git a/src/gpu/GrProxyProvider.cpp b/src/gpu/GrProxyProvider.cpp index 60ada6c5ec..cf20dd1d71 100644 --- a/src/gpu/GrProxyProvider.cpp +++ b/src/gpu/GrProxyProvider.cpp @@ -317,12 +317,13 @@ sk_sp GrProxyProvider::createNonMippedProxyFromBitmap(const SkBi } sk_sp proxy = this->createLazyProxy( - [dims, format, bitmap, fit, colorType, budgeted](GrResourceProvider* resourceProvider) { + [bitmap](GrResourceProvider* resourceProvider, const LazySurfaceDesc& desc) { + SkASSERT(desc.fMipMapped == GrMipMapped::kNo); GrMipLevel mipLevel = { bitmap.getPixels(), bitmap.rowBytes() }; - + auto colorType = SkColorTypeToGrColorType(bitmap.colorType()); return LazyCallbackResult(resourceProvider->createTexture( - dims, format, colorType, GrRenderable::kNo, 1, budgeted, fit, - GrProtected::kNo, mipLevel)); + desc.fDimensions, desc.fFormat, colorType, desc.fRenderable, + desc.fSampleCnt, desc.fBudgeted, desc.fFit, desc.fProtected, mipLevel)); }, format, dims, GrRenderable::kNo, 1, GrMipMapped::kNo, GrMipMapsStatus::kNotAllocated, GrInternalSurfaceFlags::kNone, fit, budgeted, GrProtected::kNo, UseAllocator::kYes); @@ -352,14 +353,14 @@ sk_sp GrProxyProvider::createMippedProxyFromBitmap(const SkBitma auto dims = bitmap.dimensions(); sk_sp proxy = this->createLazyProxy( - [dims, format, bitmap, mipmaps, budgeted](GrResourceProvider* resourceProvider) { + [bitmap, mipmaps](GrResourceProvider* resourceProvider, const LazySurfaceDesc& desc) { const int mipLevelCount = mipmaps->countLevels() + 1; std::unique_ptr texels(new GrMipLevel[mipLevelCount]); + auto colorType = SkColorTypeToGrColorType(bitmap.colorType()); texels[0].fPixels = bitmap.getPixels(); texels[0].fRowBytes = bitmap.rowBytes(); - auto colorType = SkColorTypeToGrColorType(bitmap.colorType()); for (int i = 1; i < mipLevelCount; ++i) { SkMipMap::Level generatedMipLevel; mipmaps->getLevel(i - 1, &generatedMipLevel); @@ -369,8 +370,8 @@ sk_sp GrProxyProvider::createMippedProxyFromBitmap(const SkBitma SkASSERT(generatedMipLevel.fPixmap.colorType() == bitmap.colorType()); } return LazyCallbackResult(resourceProvider->createTexture( - dims, format, colorType, GrRenderable::kNo, 1, budgeted, GrProtected::kNo, - texels.get(), mipLevelCount)); + desc.fDimensions, desc.fFormat, colorType, GrRenderable::kNo, 1, + desc.fBudgeted, GrProtected::kNo, texels.get(), mipLevelCount)); }, format, dims, GrRenderable::kNo, 1, GrMipMapped::kYes, GrMipMapsStatus::kValid, GrInternalSurfaceFlags::kNone, SkBackingFit::kExact, budgeted, GrProtected::kNo, @@ -457,10 +458,10 @@ sk_sp GrProxyProvider::createCompressedTextureProxy( : GrMipMapsStatus::kNotAllocated; sk_sp proxy = this->createLazyProxy( - [dimensions, format, budgeted, mipMapped, isProtected, - data](GrResourceProvider* resourceProvider) { + [data](GrResourceProvider* resourceProvider, const LazySurfaceDesc& desc) { return LazyCallbackResult(resourceProvider->createCompressedTexture( - dimensions, format, budgeted, mipMapped, isProtected, data.get())); + desc.fDimensions, desc.fFormat, desc.fBudgeted, desc.fMipMapped, + desc.fProtected, data.get())); }, format, dimensions, GrRenderable::kNo, 1, mipMapped, mipMapsStatus, GrInternalSurfaceFlags::kReadOnly, SkBackingFit::kExact, SkBudgeted::kYes, diff --git a/src/gpu/GrProxyProvider.h b/src/gpu/GrProxyProvider.h index 27cbf6a6a4..a275f29794 100644 --- a/src/gpu/GrProxyProvider.h +++ b/src/gpu/GrProxyProvider.h @@ -148,6 +148,7 @@ public: const GrVkDrawableInfo&); using LazyInstantiationKeyMode = GrSurfaceProxy::LazyInstantiationKeyMode; + using LazySurfaceDesc = GrSurfaceProxy::LazySurfaceDesc; using LazyCallbackResult = GrSurfaceProxy::LazyCallbackResult; using LazyInstantiateCallback = GrSurfaceProxy::LazyInstantiateCallback; diff --git a/src/gpu/GrRenderTargetProxy.cpp b/src/gpu/GrRenderTargetProxy.cpp index 824a599a62..ea635e9e15 100644 --- a/src/gpu/GrRenderTargetProxy.cpp +++ b/src/gpu/GrRenderTargetProxy.cpp @@ -127,6 +127,22 @@ bool GrRenderTargetProxy::refsWrappedObjects() const { return surface->resourcePriv().refsWrappedObjects(); } +GrSurfaceProxy::LazySurfaceDesc GrRenderTargetProxy::callbackDesc() const { + // We only expect exactly sized lazy RT proxies. + SkASSERT(!this->isFullyLazy()); + SkASSERT(this->isFunctionallyExact()); + return { + this->dimensions(), + SkBackingFit::kExact, + GrRenderable::kYes, + GrMipMapped::kNo, + this->numSamples(), + this->backendFormat(), + this->isProtected(), + this->isBudgeted(), + }; +} + #ifdef SK_DEBUG void GrRenderTargetProxy::onValidateSurface(const GrSurface* surface) { // We do not check that surface->asTexture returns null since, when replaying DDLs we diff --git a/src/gpu/GrRenderTargetProxy.h b/src/gpu/GrRenderTargetProxy.h index 8f58bb4c57..de21acc23c 100644 --- a/src/gpu/GrRenderTargetProxy.h +++ b/src/gpu/GrRenderTargetProxy.h @@ -143,6 +143,8 @@ private: size_t onUninstantiatedGpuMemorySize(const GrCaps&) const override; SkDEBUGCODE(void onValidateSurface(const GrSurface*) override;) + LazySurfaceDesc callbackDesc() const override; + // WARNING: Be careful when adding or removing fields here. ASAN is likely to trigger warnings // when instantiating GrTextureRenderTargetProxy. The std::function in GrSurfaceProxy makes // each class in the diamond require 16 byte alignment. Clang appears to layout the fields for diff --git a/src/gpu/GrSurfaceProxy.cpp b/src/gpu/GrSurfaceProxy.cpp index b6abd53259..4df6c3302d 100644 --- a/src/gpu/GrSurfaceProxy.cpp +++ b/src/gpu/GrSurfaceProxy.cpp @@ -391,7 +391,7 @@ bool GrSurfaceProxyPriv::doLazyInstantiation(GrResourceProvider* resourceProvide bool syncKey = true; bool releaseCallback = false; if (!surface) { - auto result = fProxy->fLazyInstantiateCallback(resourceProvider); + auto result = fProxy->fLazyInstantiateCallback(resourceProvider, fProxy->callbackDesc()); surface = std::move(result.fSurface); syncKey = result.fKeyMode == GrSurfaceProxy::LazyInstantiationKeyMode::kSynced; releaseCallback = surface && result.fReleaseCallback; diff --git a/src/gpu/GrSurfaceProxy.h b/src/gpu/GrSurfaceProxy.h index 441250595c..0bbd936127 100644 --- a/src/gpu/GrSurfaceProxy.h +++ b/src/gpu/GrSurfaceProxy.h @@ -62,6 +62,21 @@ public: kSynced }; + /** + * Specifies the expected properties of the GrSurface returned by a lazy instantiation + * callback. The dimensions will be negative in the case of a fully lazy proxy. + */ + struct LazySurfaceDesc { + SkISize fDimensions; + SkBackingFit fFit; + GrRenderable fRenderable; + GrMipMapped fMipMapped; + int fSampleCnt; + const GrBackendFormat& fFormat; + GrProtected fProtected; + SkBudgeted fBudgeted; + }; + struct LazyCallbackResult { LazyCallbackResult() = default; LazyCallbackResult(const LazyCallbackResult&) = default; @@ -85,7 +100,8 @@ public: bool fReleaseCallback = true; }; - using LazyInstantiateCallback = std::function; + using LazyInstantiateCallback = + std::function; enum class UseAllocator { /** @@ -410,6 +426,8 @@ private: virtual size_t onUninstantiatedGpuMemorySize(const GrCaps&) const = 0; + virtual LazySurfaceDesc callbackDesc() const = 0; + bool fIgnoredByResourceAllocator = false; GrProtected fIsProtected; diff --git a/src/gpu/GrTextureProxy.cpp b/src/gpu/GrTextureProxy.cpp index 573d777ff8..fa7e064fa9 100644 --- a/src/gpu/GrTextureProxy.cpp +++ b/src/gpu/GrTextureProxy.cpp @@ -171,6 +171,28 @@ void GrTextureProxy::clearUniqueKey() { fProxyProvider = nullptr; } +GrSurfaceProxy::LazySurfaceDesc GrTextureProxy::callbackDesc() const { + SkISize dims; + SkBackingFit fit; + if (this->isFullyLazy()) { + fit = SkBackingFit::kApprox; + dims = {-1, -1}; + } else { + fit = this->isFunctionallyExact() ? SkBackingFit::kExact : SkBackingFit::kApprox; + dims = this->dimensions(); + } + return { + dims, + fit, + GrRenderable::kNo, + fMipMapped, + 1, + this->backendFormat(), + this->isProtected(), + this->isBudgeted(), + }; +} + #ifdef SK_DEBUG void GrTextureProxy::onValidateSurface(const GrSurface* surface) { SkASSERT(!surface->asRenderTarget()); diff --git a/src/gpu/GrTextureProxy.h b/src/gpu/GrTextureProxy.h index f95154666c..06afa9a08c 100644 --- a/src/gpu/GrTextureProxy.h +++ b/src/gpu/GrTextureProxy.h @@ -176,6 +176,8 @@ private: GrUniqueKey fUniqueKey; GrProxyProvider* fProxyProvider; // only set when fUniqueKey is valid + LazySurfaceDesc callbackDesc() const override; + // Only used for proxies whose contents are being prepared on a worker thread. This object // stores the texture data, allowing the proxy to remain uninstantiated until flush. At that // point, the proxy is instantiated, and this data is used to perform an ASAP upload. diff --git a/src/gpu/GrTextureRenderTargetProxy.cpp b/src/gpu/GrTextureRenderTargetProxy.cpp index 93e5f17fdc..e7b6e18669 100644 --- a/src/gpu/GrTextureRenderTargetProxy.cpp +++ b/src/gpu/GrTextureRenderTargetProxy.cpp @@ -143,6 +143,28 @@ sk_sp GrTextureRenderTargetProxy::createSurface( return surface; } +GrSurfaceProxy::LazySurfaceDesc GrTextureRenderTargetProxy::callbackDesc() const { + SkISize dims; + SkBackingFit fit; + if (this->isFullyLazy()) { + fit = SkBackingFit::kApprox; + dims = {-1, -1}; + } else { + fit = this->isFunctionallyExact() ? SkBackingFit::kExact : SkBackingFit::kApprox; + dims = this->dimensions(); + } + return { + dims, + fit, + GrRenderable::kYes, + this->mipMapped(), + this->numSamples(), + this->backendFormat(), + this->isProtected(), + this->isBudgeted(), + }; +} + #ifdef SK_DEBUG void GrTextureRenderTargetProxy::onValidateSurface(const GrSurface* surface) { // Anything checked here should also be checking the GrTextureProxy version diff --git a/src/gpu/GrTextureRenderTargetProxy.h b/src/gpu/GrTextureRenderTargetProxy.h index bd52d80463..585f60c63d 100644 --- a/src/gpu/GrTextureRenderTargetProxy.h +++ b/src/gpu/GrTextureRenderTargetProxy.h @@ -64,7 +64,7 @@ private: sk_sp createSurface(GrResourceProvider*) const override; size_t onUninstantiatedGpuMemorySize(const GrCaps&) const override; - + LazySurfaceDesc callbackDesc() const override; SkDEBUGCODE(void onValidateSurface(const GrSurface*) override;) }; diff --git a/src/gpu/ccpr/GrCCAtlas.h b/src/gpu/ccpr/GrCCAtlas.h index f37910d452..f20ef3f89e 100644 --- a/src/gpu/ccpr/GrCCAtlas.h +++ b/src/gpu/ccpr/GrCCAtlas.h @@ -68,13 +68,15 @@ public: : GrCCPathProcessor::CoverageMode::kLiteral; } - - static sk_sp MakeLazyAtlasProxy(const LazyInstantiateAtlasCallback& callback, - CoverageType coverageType, const GrCaps& caps, + static sk_sp MakeLazyAtlasProxy(LazyInstantiateAtlasCallback&& callback, + CoverageType coverageType, + const GrCaps& caps, GrSurfaceProxy::UseAllocator useAllocator) { - return GrDynamicAtlas::MakeLazyAtlasProxy(callback, CoverageTypeToColorType(coverageType), + return GrDynamicAtlas::MakeLazyAtlasProxy(std::move(callback), + CoverageTypeToColorType(coverageType), CoverageTypeHasInternalMultisample(coverageType), - caps, useAllocator); + caps, + useAllocator); } GrCCAtlas(CoverageType, const Specs&, const GrCaps&); diff --git a/src/gpu/ccpr/GrCCClipPath.cpp b/src/gpu/ccpr/GrCCClipPath.cpp index 20368e666b..b2a2c07f83 100644 --- a/src/gpu/ccpr/GrCCClipPath.cpp +++ b/src/gpu/ccpr/GrCCClipPath.cpp @@ -19,8 +19,7 @@ void GrCCClipPath::init( SkASSERT(!this->isInitialized()); fAtlasLazyProxy = GrCCAtlas::MakeLazyAtlasProxy( - [this](GrResourceProvider* resourceProvider, const GrBackendFormat& format, - int sampleCount) { + [this](GrResourceProvider* resourceProvider, const GrCCAtlas::LazyAtlasDesc& desc) { SkASSERT(fHasAtlas); SkASSERT(!fHasAtlasTransform); @@ -34,8 +33,6 @@ void GrCCClipPath::init( sk_sp texture = sk_ref_sp(textureProxy->peekTexture()); SkASSERT(texture); - SkASSERT(texture->backendFormat() == format); - SkASSERT(texture->asRenderTarget()->numSamples() == sampleCount); fAtlasScale = {1.f / texture->width(), 1.f / texture->height()}; fAtlasTranslate.set(fDevToAtlasOffset.fX * fAtlasScale.x(), diff --git a/src/gpu/ccpr/GrCCClipPath.h b/src/gpu/ccpr/GrCCClipPath.h index 32e5ae49f7..0f3fef2058 100644 --- a/src/gpu/ccpr/GrCCClipPath.h +++ b/src/gpu/ccpr/GrCCClipPath.h @@ -37,8 +37,10 @@ public: } bool isInitialized() const { return fAtlasLazyProxy != nullptr; } - void init(const SkPath& deviceSpacePath, const SkIRect& accessRect, - GrCCAtlas::CoverageType atlasCoverageType, const GrCaps&); + void init(const SkPath& deviceSpacePath, + const SkIRect& desc, + GrCCAtlas::CoverageType atlasCoverageType, + const GrCaps&); void addAccess(const SkIRect& accessRect) { SkASSERT(this->isInitialized()); diff --git a/src/image/SkImage_GpuBase.cpp b/src/image/SkImage_GpuBase.cpp index ced41b0997..e156e4e368 100644 --- a/src/image/SkImage_GpuBase.cpp +++ b/src/image/SkImage_GpuBase.cpp @@ -402,7 +402,8 @@ sk_sp SkImage_GpuBase::MakePromiseImageLazyProxy( } } - GrSurfaceProxy::LazyCallbackResult operator()(GrResourceProvider* resourceProvider) { + GrSurfaceProxy::LazyCallbackResult operator()(GrResourceProvider* resourceProvider, + const GrSurfaceProxy::LazySurfaceDesc&) { // We use the unique key in a way that is unrelated to the SkImage-based key that the // proxy may receive, hence kUnsynced. static constexpr auto kKeySyncMode = diff --git a/src/image/SkSurface_GpuMtl.mm b/src/image/SkSurface_GpuMtl.mm index 6c74adf990..b560235e75 100644 --- a/src/image/SkSurface_GpuMtl.mm +++ b/src/image/SkSurface_GpuMtl.mm @@ -50,23 +50,22 @@ sk_sp SkSurface::MakeFromCAMetalLayer(GrContext* context, texInfo.fTextureType = GrTextureType::k2D; sk_sp proxy = proxyProvider->createLazyRenderTargetProxy( - [layer, drawable, sampleCnt](GrResourceProvider* resourceProvider) { + [layer, drawable](GrResourceProvider* resourceProvider, + const GrSurfaceProxy::LazySurfaceDesc& desc) { CAMetalLayer* metalLayer = (__bridge CAMetalLayer*)layer; id currentDrawable = [metalLayer nextDrawable]; - SkISize dims = {(int)metalLayer.drawableSize.width, - (int)metalLayer.drawableSize.height}; - GrMtlGpu* mtlGpu = (GrMtlGpu*) resourceProvider->priv().gpu(); sk_sp surface; if (metalLayer.framebufferOnly) { - surface = GrMtlRenderTarget::MakeWrappedRenderTarget(mtlGpu, dims, sampleCnt, - currentDrawable.texture); + surface = GrMtlRenderTarget::MakeWrappedRenderTarget( + mtlGpu, desc.fDimensions, desc.fSampleCnt, currentDrawable.texture); } else { surface = GrMtlTextureRenderTarget::MakeWrappedTextureRenderTarget( - mtlGpu, dims, sampleCnt, currentDrawable.texture, GrWrapCacheable::kNo); + mtlGpu, desc.fDimensions, desc.fSampleCnt, currentDrawable.texture, + GrWrapCacheable::kNo); } - if (surface && sampleCnt > 1) { + if (surface && desc.fSampleCnt > 1) { surface->setRequiresManualMSAAResolve(); } @@ -122,22 +121,22 @@ sk_sp SkSurface::MakeFromMTKView(GrContext* context, texInfo.fTextureType = GrTextureType::k2D; sk_sp proxy = proxyProvider->createLazyRenderTargetProxy( - [view, sampleCnt](GrResourceProvider* resourceProvider) { + [view](GrResourceProvider* resourceProvider, + const GrSurfaceProxy::LazySurfaceDesc& desc) { MTKView* mtkView = (__bridge MTKView*)view; id currentDrawable = [mtkView currentDrawable]; - SkISize dims = {(int)mtkView.drawableSize.width, (int)mtkView.drawableSize.height}; - GrMtlGpu* mtlGpu = (GrMtlGpu*) resourceProvider->priv().gpu(); sk_sp surface; if (mtkView.framebufferOnly) { - surface = GrMtlRenderTarget::MakeWrappedRenderTarget(mtlGpu, dims, sampleCnt, - currentDrawable.texture); + surface = GrMtlRenderTarget::MakeWrappedRenderTarget( + mtlGpu, desc.fDimensions, desc.fSampleCnt, currentDrawable.texture); } else { surface = GrMtlTextureRenderTarget::MakeWrappedTextureRenderTarget( - mtlGpu, dims, sampleCnt, currentDrawable.texture, GrWrapCacheable::kNo); + mtlGpu, desc.fDimensions, desc.fSampleCnt, currentDrawable.texture, + GrWrapCacheable::kNo); } - if (surface && sampleCnt > 1) { + if (surface && desc.fSampleCnt > 1) { surface->setRequiresManualMSAAResolve(); } diff --git a/tests/GrSurfaceTest.cpp b/tests/GrSurfaceTest.cpp index 53de88c90b..dc2133644d 100644 --- a/tests/GrSurfaceTest.cpp +++ b/tests/GrSurfaceTest.cpp @@ -544,7 +544,8 @@ DEF_GPUTEST(TextureIdleProcTest, reporter, options) { SkImageInfo::Make(w, h, kRGBA_8888_SkColorType, kPremul_SkAlphaType); auto rt = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info, 0, nullptr); auto rtc = rt->getCanvas()->internal_private_accessTopLayerRenderTargetContext(); - auto singleUseLazyCB = [&texture](GrResourceProvider* rp) { + auto singleUseLazyCB = [&texture](GrResourceProvider*, + const GrSurfaceProxy::LazySurfaceDesc&) { auto mode = GrSurfaceProxy::LazyInstantiationKeyMode::kSynced; if (texture->getUniqueKey().isValid()) { mode = GrSurfaceProxy::LazyInstantiationKeyMode::kUnsynced; diff --git a/tests/LazyProxyTest.cpp b/tests/LazyProxyTest.cpp index 4ba74e7ff0..d330780c5a 100644 --- a/tests/LazyProxyTest.cpp +++ b/tests/LazyProxyTest.cpp @@ -83,8 +83,9 @@ public: ctx->priv().caps()->getDefaultBackendFormat(GrColorType::kBGR_565, GrRenderable::kNo); fProxy = GrProxyProvider::MakeFullyLazyProxy( - [this, format, - nullTexture](GrResourceProvider* rp) -> GrSurfaceProxy::LazyCallbackResult { + [this, nullTexture](GrResourceProvider* rp, + const GrSurfaceProxy::LazySurfaceDesc& desc) + -> GrSurfaceProxy::LazyCallbackResult { REPORTER_ASSERT(fTest->fReporter, !fTest->fHasOpTexture); fTest->fHasOpTexture = true; if (nullTexture) { @@ -92,8 +93,8 @@ public: } else { static constexpr SkISize kDimensions = {1234, 567}; sk_sp texture = rp->createTexture( - kDimensions, format, GrRenderable::kNo, 1, GrMipMapped::kNo, - SkBudgeted::kYes, GrProtected::kNo); + kDimensions, desc.fFormat, desc.fRenderable, desc.fSampleCnt, + desc.fMipMapped, desc.fBudgeted, desc.fProtected); REPORTER_ASSERT(fTest->fReporter, texture); return texture; } @@ -137,7 +138,8 @@ public: ctx->priv().caps()->getDefaultBackendFormat(kColorType, GrRenderable::kYes); GrSwizzle readSwizzle = ctx->priv().caps()->getReadSwizzle(format, kColorType); fLazyProxy = GrProxyProvider::MakeFullyLazyProxy( - [this](GrResourceProvider* rp) -> GrSurfaceProxy::LazyCallbackResult { + [this](GrResourceProvider* rp, const GrSurfaceProxy::LazySurfaceDesc&) + -> GrSurfaceProxy::LazyCallbackResult { REPORTER_ASSERT(fTest->fReporter, !fTest->fHasClipTexture); fTest->fHasClipTexture = true; fAtlas->instantiate(rp); @@ -264,7 +266,8 @@ DEF_GPUTEST(LazyProxyReleaseTest, reporter, /* options */) { } TestCallback& operator=(const TestCallback& that) = delete; - LazyInstantiationResult operator()(GrResourceProvider* resourceProvider) const { + LazyInstantiationResult operator()(GrResourceProvider*, + const GrSurfaceProxy::LazySurfaceDesc&) const { *fValue = 1; return {fTexture, fReleaseCallback}; } @@ -328,32 +331,31 @@ private: int* testExecuteValue, bool shouldFailInstantiation) : INHERITED(ClassID()) , fTestExecuteValue(testExecuteValue) { - SkISize desc; - desc.fWidth = kSize; - desc.fHeight = kSize; + SkISize dims = {kSize, kSize}; GrBackendFormat format = ctx->priv().caps()->getDefaultBackendFormat(GrColorType::kRGBA_8888, GrRenderable::kNo); fLazyProxy = proxyProvider->createLazyProxy( - [testExecuteValue, shouldFailInstantiation, desc, - format](GrResourceProvider* rp) -> GrSurfaceProxy::LazyCallbackResult { + [testExecuteValue, shouldFailInstantiation]( + GrResourceProvider* rp, const GrSurfaceProxy::LazySurfaceDesc& desc) + -> GrSurfaceProxy::LazyCallbackResult { if (shouldFailInstantiation) { *testExecuteValue = 1; return {}; } - return {rp->createTexture(desc, format, GrRenderable::kNo, 1, GrMipMapped::kNo, - SkBudgeted::kNo, GrProtected::kNo), + return {rp->createTexture(desc.fDimensions, desc.fFormat, desc.fRenderable, + desc.fSampleCnt, desc.fMipMapped, desc.fBudgeted, + desc.fProtected), true, GrSurfaceProxy::LazyInstantiationKeyMode::kUnsynced}; }, - format, desc, GrRenderable::kNo, 1, GrMipMapped::kNo, + format, dims, GrRenderable::kNo, 1, GrMipMapped::kNo, GrMipMapsStatus::kNotAllocated, GrInternalSurfaceFlags::kNone, SkBackingFit::kExact, SkBudgeted::kNo, GrProtected::kNo, GrSurfaceProxy::UseAllocator::kYes); SkASSERT(fLazyProxy.get()); - this->setBounds(SkRect::MakeIWH(kSize, kSize), - HasAABloat::kNo, IsHairline::kNo); + this->setBounds(SkRect::Make(dims), HasAABloat::kNo, IsHairline::kNo); } const char* name() const override { return "LazyFailedInstantiationTestOp"; } diff --git a/tests/OnFlushCallbackTest.cpp b/tests/OnFlushCallbackTest.cpp index 6a819f5e5d..579097163b 100644 --- a/tests/OnFlushCallbackTest.cpp +++ b/tests/OnFlushCallbackTest.cpp @@ -336,17 +336,19 @@ public: const GrBackendFormat format = caps->getDefaultBackendFormat(GrColorType::kRGBA_8888, GrRenderable::kYes); auto proxy = GrProxyProvider::MakeFullyLazyProxy( - [format](GrResourceProvider* resourceProvider) + [](GrResourceProvider* resourceProvider, + const GrSurfaceProxy::LazySurfaceDesc& desc) -> GrSurfaceProxy::LazyCallbackResult { + SkASSERT(desc.fDimensions.width() < 0 && desc.fDimensions.height() < 0); SkISize dims; // TODO: until partial flushes in MDB lands we're stuck having // all 9 atlas draws occur dims.fWidth = 9 /*this->numOps()*/ * kAtlasTileSize; dims.fHeight = kAtlasTileSize; - return resourceProvider->createTexture(dims, format, GrRenderable::kYes, 1, - GrMipMapped::kNo, SkBudgeted::kYes, - GrProtected::kNo); + return resourceProvider->createTexture(dims, desc.fFormat, desc.fRenderable, + desc.fSampleCnt, desc.fMipMapped, + desc.fBudgeted, desc.fProtected); }, format, GrRenderable::kYes, diff --git a/tests/ResourceAllocatorTest.cpp b/tests/ResourceAllocatorTest.cpp index 2c95cddad7..bb76cd5d3c 100644 --- a/tests/ResourceAllocatorTest.cpp +++ b/tests/ResourceAllocatorTest.cpp @@ -256,21 +256,22 @@ sk_sp make_lazy(GrProxyProvider* proxyProvider, const GrCaps* ca const ProxyParams& p) { const auto format = caps->getDefaultBackendFormat(p.fColorType, p.fRenderable); - SkBackingFit fit = p.fFit; - SkISize dims = {p.fSize, p.fSize}; - auto callback = [fit, dims, format, p](GrResourceProvider* resourceProvider) { + auto callback = [](GrResourceProvider* resourceProvider, + const GrSurfaceProxy::LazySurfaceDesc& desc) { sk_sp texture; - if (fit == SkBackingFit::kApprox) { - texture = resourceProvider->createApproxTexture(dims, format, p.fRenderable, - p.fSampleCnt, GrProtected::kNo); + if (desc.fFit == SkBackingFit::kApprox) { + texture = resourceProvider->createApproxTexture(desc.fDimensions, desc.fFormat, + desc.fRenderable, desc.fSampleCnt, + desc.fProtected); } else { - texture = resourceProvider->createTexture(dims, format, p.fRenderable, p.fSampleCnt, - GrMipMapped::kNo, SkBudgeted::kNo, - GrProtected::kNo); + texture = resourceProvider->createTexture( + desc.fDimensions, desc.fFormat, desc.fRenderable, desc.fSampleCnt, + desc.fMipMapped, desc.fBudgeted, desc.fProtected); } return GrSurfaceProxy::LazyCallbackResult(std::move(texture)); }; GrInternalSurfaceFlags flags = GrInternalSurfaceFlags::kNone; + SkISize dims = {p.fSize, p.fSize}; return proxyProvider->createLazyProxy(callback, format, dims, p.fRenderable, p.fSampleCnt, GrMipMapped::kNo, GrMipMapsStatus::kNotAllocated, flags, p.fFit, p.fBudgeted, GrProtected::kNo,