diff options
author | Greg Daniel <egdaniel@google.com> | 2017-11-01 16:38:48 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-11-02 13:11:31 +0000 |
commit | c77085d2e0a3ff7e908a7164ac6224ea10686739 (patch) | |
tree | ca804bb45e7e257e324cd31a1e2215b93ad0ba07 /src/gpu | |
parent | d1b2eec0d0f95977b52669025cb25038618c0335 (diff) |
Remove content area from GrTextureAdjuster.
Bug: skia:
Change-Id: I77854ee22303afe5787bf3094bca2db1a3dcf5ef
Reviewed-on: https://skia-review.googlesource.com/66149
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
Diffstat (limited to 'src/gpu')
-rw-r--r-- | src/gpu/GrTextureAdjuster.cpp | 53 | ||||
-rw-r--r-- | src/gpu/GrTextureAdjuster.h | 8 | ||||
-rw-r--r-- | src/gpu/GrTextureMaker.cpp | 7 | ||||
-rw-r--r-- | src/gpu/GrTextureProducer.cpp | 70 | ||||
-rw-r--r-- | src/gpu/GrTextureProducer.h | 3 | ||||
-rw-r--r-- | src/gpu/SkGpuDevice.cpp | 8 | ||||
-rw-r--r-- | src/gpu/SkGpuDevice_drawTexture.cpp | 5 |
7 files changed, 37 insertions, 117 deletions
diff --git a/src/gpu/GrTextureAdjuster.cpp b/src/gpu/GrTextureAdjuster.cpp index 2ae95a929e..d8985fed12 100644 --- a/src/gpu/GrTextureAdjuster.cpp +++ b/src/gpu/GrTextureAdjuster.cpp @@ -15,21 +15,15 @@ GrTextureAdjuster::GrTextureAdjuster(GrContext* context, sk_sp<GrTextureProxy> original, SkAlphaType alphaType, - const SkIRect& contentArea, uint32_t uniqueID, + uint32_t uniqueID, SkColorSpace* cs) - : INHERITED(contentArea.width(), contentArea.height(), + : INHERITED(original->width(), original->height(), GrPixelConfigIsAlphaOnly(original->config())) , fContext(context) , fOriginal(std::move(original)) , fAlphaType(alphaType) , fColorSpace(cs) - , fUniqueID(uniqueID) { - SkASSERT(SkIRect::MakeWH(fOriginal->width(), fOriginal->height()).contains(contentArea)); - SkASSERT(0 == contentArea.fLeft && 0 == contentArea.fTop); - if (contentArea.fRight < fOriginal->width() || contentArea.fBottom < fOriginal->height()) { - fContentArea.set(contentArea); - } -} + , fUniqueID(uniqueID) {} void GrTextureAdjuster::makeCopyKey(const CopyParams& params, GrUniqueKey* copyKey, SkColorSpace* dstColorSpace) { @@ -57,10 +51,8 @@ sk_sp<GrTextureProxy> GrTextureAdjuster::refTextureProxyCopy(const CopyParams& c } sk_sp<GrTextureProxy> proxy = this->originalProxyRef(); - const SkIRect* contentArea = this->contentAreaOrNull(); - sk_sp<GrTextureProxy> copy = CopyOnGpu(fContext, std::move(proxy), contentArea, copyParams, - willBeMipped); + sk_sp<GrTextureProxy> copy = CopyOnGpu(fContext, std::move(proxy), copyParams, willBeMipped); if (copy) { if (key.isValid()) { SkASSERT(copy->origin() == this->originalProxy()->origin()); @@ -75,46 +67,29 @@ sk_sp<GrTextureProxy> GrTextureAdjuster::refTextureProxySafeForParams(const GrSa SkScalar scaleAdjust[2]) { sk_sp<GrTextureProxy> proxy = this->originalProxyRef(); CopyParams copyParams; - const SkIRect* contentArea = this->contentAreaOrNull(); if (!fContext) { // The texture was abandoned. return nullptr; } - bool willBeMipped = GrSamplerState::Filter::kMipMap == params.filter(); - if (contentArea && willBeMipped) { - // If we generate a MIP chain for texture it will read pixel values from outside the content - // area. - copyParams.fWidth = contentArea->width(); - copyParams.fHeight = contentArea->height(); - copyParams.fFilter = GrSamplerState::Filter::kBilerp; - } else if (!fContext->getGpu()->isACopyNeededForTextureParams(proxy.get(), params, ©Params, - scaleAdjust)) { + if (!fContext->getGpu()->isACopyNeededForTextureParams(proxy.get(), params, ©Params, + scaleAdjust)) { return proxy; } + bool willBeMipped = GrSamplerState::Filter::kMipMap == params.filter(); return this->refTextureProxyCopy(copyParams, willBeMipped); } std::unique_ptr<GrFragmentProcessor> GrTextureAdjuster::createFragmentProcessor( const SkMatrix& origTextureMatrix, - const SkRect& origConstraintRect, + const SkRect& constraintRect, FilterConstraint filterConstraint, bool coordsLimitedToConstraintRect, const GrSamplerState::Filter* filterOrNullForBicubic, SkColorSpace* dstColorSpace) { SkMatrix textureMatrix = origTextureMatrix; - const SkIRect* contentArea = this->contentAreaOrNull(); - // Convert the constraintRect to be relative to the texture rather than the content area so - // that both rects are in the same coordinate system. - SkTCopyOnFirstWrite<SkRect> constraintRect(origConstraintRect); - if (contentArea) { - SkScalar l = SkIntToScalar(contentArea->fLeft); - SkScalar t = SkIntToScalar(contentArea->fTop); - constraintRect.writable()->offset(l, t); - textureMatrix.postTranslate(l, t); - } SkRect domain; GrSamplerState samplerState; @@ -130,15 +105,12 @@ std::unique_ptr<GrFragmentProcessor> GrTextureAdjuster::createFragmentProcessor( // If we made a copy then we only copied the contentArea, in which case the new texture is all // content. if (proxy.get() != this->originalProxy()) { - contentArea = nullptr; textureMatrix.postScale(scaleAdjust[0], scaleAdjust[1]); } DomainMode domainMode = - DetermineDomainMode(*constraintRect, filterConstraint, coordsLimitedToConstraintRect, - proxy.get(), - contentArea, filterOrNullForBicubic, - &domain); + DetermineDomainMode(constraintRect, filterConstraint, coordsLimitedToConstraintRect, + proxy.get(), filterOrNullForBicubic, &domain); if (kTightCopy_DomainMode == domainMode) { // TODO: Copy the texture and adjust the texture matrix (both parts need to consider // non-int constraint rect) @@ -149,9 +121,8 @@ std::unique_ptr<GrFragmentProcessor> GrTextureAdjuster::createFragmentProcessor( GrSamplerState::Filter::kMipMap == *filterOrNullForBicubic); static const GrSamplerState::Filter kBilerp = GrSamplerState::Filter::kBilerp; domainMode = - DetermineDomainMode(*constraintRect, filterConstraint, coordsLimitedToConstraintRect, - proxy.get(), - contentArea, &kBilerp, &domain); + DetermineDomainMode(constraintRect, filterConstraint, coordsLimitedToConstraintRect, + proxy.get(), &kBilerp, &domain); SkASSERT(kTightCopy_DomainMode != domainMode); } SkASSERT(kNoDomain_DomainMode == domainMode || diff --git a/src/gpu/GrTextureAdjuster.h b/src/gpu/GrTextureAdjuster.h index ca5b0e90c7..a0ce8c40db 100644 --- a/src/gpu/GrTextureAdjuster.h +++ b/src/gpu/GrTextureAdjuster.h @@ -35,8 +35,8 @@ public: // We do not ref the texture nor the colorspace, so the caller must keep them in scope while // this Adjuster is alive. - GrTextureAdjuster(GrContext*, sk_sp<GrTextureProxy>, SkAlphaType, const SkIRect& area, - uint32_t uniqueID, SkColorSpace*); + GrTextureAdjuster(GrContext*, sk_sp<GrTextureProxy>, SkAlphaType, uint32_t uniqueID, + SkColorSpace*); protected: SkAlphaType alphaType() const override { return fAlphaType; } @@ -47,11 +47,7 @@ protected: GrTextureProxy* originalProxy() const { return fOriginal.get(); } sk_sp<GrTextureProxy> originalProxyRef() const { return fOriginal; } - /** Returns the content area or null for the whole original texture */ - const SkIRect* contentAreaOrNull() { return fContentArea.getMaybeNull(); } - private: - SkTLazy<SkIRect> fContentArea; GrContext* fContext; sk_sp<GrTextureProxy> fOriginal; SkAlphaType fAlphaType; diff --git a/src/gpu/GrTextureMaker.cpp b/src/gpu/GrTextureMaker.cpp index e234180d4b..b3a16f5d8c 100644 --- a/src/gpu/GrTextureMaker.cpp +++ b/src/gpu/GrTextureMaker.cpp @@ -73,7 +73,7 @@ sk_sp<GrTextureProxy> GrTextureMaker::refTextureProxyForParams(const GrSamplerSt return nullptr; } - result = CopyOnGpu(fContext, std::move(result), nullptr, copyParams, willBeMipped); + result = CopyOnGpu(fContext, std::move(result), copyParams, willBeMipped); if (!result) { return nullptr; @@ -133,8 +133,7 @@ std::unique_ptr<GrFragmentProcessor> GrTextureMaker::createFragmentProcessor( SkRect domain; DomainMode domainMode = DetermineDomainMode(constraintRect, filterConstraint, coordsLimitedToConstraintRect, - proxy.get(), - nullptr, fmForDetermineDomain, &domain); + proxy.get(), fmForDetermineDomain, &domain); SkASSERT(kTightCopy_DomainMode != domainMode); GrPixelConfig config = proxy->config(); auto fp = CreateFragmentProcessorForDomainAndFilter(std::move(proxy), adjustedMatrix, @@ -151,5 +150,5 @@ sk_sp<GrTextureProxy> GrTextureMaker::generateTextureProxyForParams(const CopyPa return nullptr; } - return CopyOnGpu(fContext, std::move(original), nullptr, copyParams, willBeMipped); + return CopyOnGpu(fContext, std::move(original), copyParams, willBeMipped); } diff --git a/src/gpu/GrTextureProducer.cpp b/src/gpu/GrTextureProducer.cpp index f5ae0ad565..1be75f9649 100644 --- a/src/gpu/GrTextureProducer.cpp +++ b/src/gpu/GrTextureProducer.cpp @@ -16,10 +16,8 @@ sk_sp<GrTextureProxy> GrTextureProducer::CopyOnGpu(GrContext* context, sk_sp<GrTextureProxy> inputProxy, - const SkIRect* subset, const CopyParams& copyParams, bool dstWillRequireMipMaps) { - SkASSERT(!subset || !subset->isEmpty()); SkASSERT(context); const SkRect dstRect = SkRect::MakeIWH(copyParams.fWidth, copyParams.fHeight); @@ -35,23 +33,13 @@ sk_sp<GrTextureProxy> GrTextureProducer::CopyOnGpu(GrContext* context, GrPaint paint; paint.setGammaCorrect(true); - SkRect localRect; - if (subset) { - localRect = SkRect::Make(*subset); - } else { - localRect = SkRect::MakeWH(inputProxy->width(), inputProxy->height()); - } + SkRect localRect = SkRect::MakeWH(inputProxy->width(), inputProxy->height()); bool needsDomain = false; if (copyParams.fFilter != GrSamplerState::Filter::kNearest) { bool resizing = localRect.width() != dstRect.width() || localRect.height() != dstRect.height(); - - if (GrResourceProvider::IsFunctionallyExact(inputProxy.get())) { - needsDomain = subset && resizing; - } else { - needsDomain = resizing; - } + needsDomain = resizing && !GrResourceProvider::IsFunctionallyExact(inputProxy.get()); } if (needsDomain) { @@ -90,17 +78,11 @@ GrTextureProducer::DomainMode GrTextureProducer::DetermineDomainMode( FilterConstraint filterConstraint, bool coordsLimitedToConstraintRect, GrTextureProxy* proxy, - const SkIRect* contentRect, const GrSamplerState::Filter* filterModeOrNullForBicubic, SkRect* domainRect) { const SkIRect proxyBounds = SkIRect::MakeWH(proxy->width(), proxy->height()); SkASSERT(proxyBounds.contains(constraintRect)); - // We only expect a content area rect if there is some non-content area. - SkASSERT(!contentRect || - (!contentRect->contains(proxyBounds) && - proxyBounds.contains(*contentRect) && - contentRect->contains(constraintRect))); const bool proxyIsExact = GrResourceProvider::IsFunctionallyExact(proxy); @@ -109,16 +91,12 @@ GrTextureProducer::DomainMode GrTextureProducer::DetermineDomainMode( return kNoDomain_DomainMode; } - if (!contentRect && !proxyIsExact) { - contentRect = &proxyBounds; - } - bool restrictFilterToRect = (filterConstraint == GrTextureProducer::kYes_FilterConstraint); // If we can filter outside the constraint rect, and there is no non-content area of the // proxy, and we aren't going to generate sample coords outside the constraint rect then we // don't need a domain. - if (!restrictFilterToRect && !contentRect && coordsLimitedToConstraintRect) { + if (!restrictFilterToRect && proxyIsExact && coordsLimitedToConstraintRect) { return kNoDomain_DomainMode; } @@ -137,7 +115,7 @@ GrTextureProducer::DomainMode GrTextureProducer::DetermineDomainMode( filterHalfWidth = .5f; break; case GrSamplerState::Filter::kMipMap: - if (restrictFilterToRect || contentRect) { + if (restrictFilterToRect || !proxyIsExact) { // No domain can save us here. return kTightCopy_DomainMode; } @@ -157,10 +135,10 @@ GrTextureProducer::DomainMode GrTextureProducer::DetermineDomainMode( // the domain. if (restrictFilterToRect) { *domainRect = constraintRect.makeInset(kDomainInset, kDomainInset); - } else if (contentRect) { - // If we got here then: there is a contentRect, the coords are limited to the + } else if (!proxyIsExact) { + // If we got here then: proxy is not exact, the coords are limited to the // constraint rect, and we're allowed to filter across the constraint rect boundary. So - // we check whether the filter would reach across the edge of the content area. + // we check whether the filter would reach across the edge of the proxy. // We will only set the sides that are required. domainRect->setLargest(); @@ -168,24 +146,12 @@ GrTextureProducer::DomainMode GrTextureProducer::DetermineDomainMode( // We may be able to use the fact that the texture coords are limited to the constraint // rect in order to avoid having to add a domain. bool needContentAreaConstraint = false; - if (contentRect->fLeft > 0 && - contentRect->fLeft + filterHalfWidth > constraintRect.fLeft) { - domainRect->fLeft = contentRect->fLeft + kDomainInset; + if (proxyBounds.fRight - filterHalfWidth < constraintRect.fRight) { + domainRect->fRight = proxyBounds.fRight - kDomainInset; needContentAreaConstraint = true; } - if (contentRect->fTop > 0 && - contentRect->fTop + filterHalfWidth > constraintRect.fTop) { - domainRect->fTop = contentRect->fTop + kDomainInset; - needContentAreaConstraint = true; - } - if ((!proxyIsExact || contentRect->fRight < proxy->width()) && - contentRect->fRight - filterHalfWidth < constraintRect.fRight) { - domainRect->fRight = contentRect->fRight - kDomainInset; - needContentAreaConstraint = true; - } - if ((!proxyIsExact || contentRect->fBottom < proxy->height()) && - contentRect->fBottom - filterHalfWidth < constraintRect.fBottom) { - domainRect->fBottom = contentRect->fBottom - kDomainInset; + if (proxyBounds.fBottom - filterHalfWidth < constraintRect.fBottom) { + domainRect->fBottom = proxyBounds.fBottom - kDomainInset; needContentAreaConstraint = true; } if (!needContentAreaConstraint) { @@ -194,18 +160,8 @@ GrTextureProducer::DomainMode GrTextureProducer::DetermineDomainMode( } else { // Our sample coords for the texture are allowed to be outside the constraintRect so we // don't consider it when computing the domain. - if (contentRect->fLeft > 0) { - domainRect->fLeft = contentRect->fLeft + kDomainInset; - } - if (contentRect->fTop > 0) { - domainRect->fTop = contentRect->fTop + kDomainInset; - } - if (!proxyIsExact || contentRect->fRight < proxy->width()) { - domainRect->fRight = contentRect->fRight - kDomainInset; - } - if (!proxyIsExact || contentRect->fBottom < proxy->height()) { - domainRect->fBottom = contentRect->fBottom - kDomainInset; - } + domainRect->fRight = proxyBounds.fRight - kDomainInset; + domainRect->fBottom = proxyBounds.fBottom - kDomainInset; } } else { return kNoDomain_DomainMode; diff --git a/src/gpu/GrTextureProducer.h b/src/gpu/GrTextureProducer.h index 432e7b35b3..88ba14afa8 100644 --- a/src/gpu/GrTextureProducer.h +++ b/src/gpu/GrTextureProducer.h @@ -124,14 +124,13 @@ protected: }; static sk_sp<GrTextureProxy> CopyOnGpu(GrContext*, sk_sp<GrTextureProxy> inputProxy, - const SkIRect* subset, const CopyParams& copyParams, + const CopyParams& copyParams, bool dstWillRequireMipMaps); static DomainMode DetermineDomainMode(const SkRect& constraintRect, FilterConstraint filterConstraint, bool coordsLimitedToConstraintRect, GrTextureProxy*, - const SkIRect* textureContentArea, const GrSamplerState::Filter* filterModeOrNullForBicubic, SkRect* domainRect); diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index 760e6064bb..33837d391c 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -1395,8 +1395,8 @@ void SkGpuDevice::drawImageNine(const SkImage* image, uint32_t pinnedUniqueID; if (sk_sp<GrTextureProxy> proxy = as_IB(image)->refPinnedTextureProxy(&pinnedUniqueID)) { GrTextureAdjuster adjuster(this->context(), std::move(proxy), - image->alphaType(), image->bounds(), - pinnedUniqueID, as_IB(image)->onImageInfo().colorSpace()); + image->alphaType(), pinnedUniqueID, + as_IB(image)->onImageInfo().colorSpace()); this->drawProducerNine(&adjuster, center, dst, paint); } else { SkBitmap bm; @@ -1451,8 +1451,8 @@ void SkGpuDevice::drawImageLattice(const SkImage* image, uint32_t pinnedUniqueID; if (sk_sp<GrTextureProxy> proxy = as_IB(image)->refPinnedTextureProxy(&pinnedUniqueID)) { GrTextureAdjuster adjuster(this->context(), std::move(proxy), - image->alphaType(), image->bounds(), - pinnedUniqueID, as_IB(image)->onImageInfo().colorSpace()); + image->alphaType(), pinnedUniqueID, + as_IB(image)->onImageInfo().colorSpace()); this->drawProducerLattice(&adjuster, lattice, dst, paint); } else { SkBitmap bm; diff --git a/src/gpu/SkGpuDevice_drawTexture.cpp b/src/gpu/SkGpuDevice_drawTexture.cpp index 9838f46ee2..c823ebd082 100644 --- a/src/gpu/SkGpuDevice_drawTexture.cpp +++ b/src/gpu/SkGpuDevice_drawTexture.cpp @@ -147,9 +147,8 @@ void SkGpuDevice::drawPinnedTextureProxy(sk_sp<GrTextureProxy> proxy, uint32_t p this->clip(), fRenderTargetContext.get()); return; } - auto contentRect = SkIRect::MakeWH(proxy->width(), proxy->height()); - GrTextureAdjuster adjuster(this->context(), std::move(proxy), alphaType, contentRect, - pinnedUniqueID, colorSpace); + GrTextureAdjuster adjuster(this->context(), std::move(proxy), alphaType, pinnedUniqueID, + colorSpace); this->drawTextureProducer(&adjuster, srcRect, dstRect, constraint, viewMatrix, paint); } |