diff options
author | Brian Salomon <bsalomon@google.com> | 2017-09-07 16:34:11 +0000 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-09-07 16:34:22 +0000 |
commit | 4df0092eac6e9bb5afc516773a0c618630193dc6 (patch) | |
tree | 7fd4a8d27fecb048c5d6e0ad00f79414696d2687 /src/gpu/GrTextureAdjuster.cpp | |
parent | 1e75f2a1020cde6698420d5d088c5c42e7c037ac (diff) |
Revert "Remove "content" rect from GrTextureAdjuster."
This reverts commit 6e4bbbefe153495cf34ea42aa72691756e6ab40e.
Reason for revert: assertion failure
Original change's description:
> Remove "content" rect from GrTextureAdjuster.
>
> Since we got rid of texture-backed bitmaps this is no longer required.
>
> Change-Id: Id15c745994a3d6a1489e193b5d29916fa0931264
> Reviewed-on: https://skia-review.googlesource.com/36340
> Commit-Queue: Brian Salomon <bsalomon@google.com>
> Reviewed-by: Robert Phillips <robertphillips@google.com>
TBR=bsalomon@google.com,robertphillips@google.com
Change-Id: I2229ec05079368ff196ff351107f88062080e5ec
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/43720
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'src/gpu/GrTextureAdjuster.cpp')
-rw-r--r-- | src/gpu/GrTextureAdjuster.cpp | 76 |
1 files changed, 59 insertions, 17 deletions
diff --git a/src/gpu/GrTextureAdjuster.cpp b/src/gpu/GrTextureAdjuster.cpp index 1508cb578f..546ea67b60 100644 --- a/src/gpu/GrTextureAdjuster.cpp +++ b/src/gpu/GrTextureAdjuster.cpp @@ -13,14 +13,22 @@ #include "SkGr.h" GrTextureAdjuster::GrTextureAdjuster(GrContext* context, sk_sp<GrTextureProxy> original, - SkAlphaType alphaType, uint32_t uniqueID, SkColorSpace* cs) - : INHERITED(original->width(), original->height(), - GrPixelConfigIsAlphaOnly(original->config())) - , fContext(context) - , fOriginal(std::move(original)) - , fAlphaType(alphaType) - , fColorSpace(cs) - , fUniqueID(uniqueID) {} + SkAlphaType alphaType, + const SkIRect& contentArea, uint32_t uniqueID, + SkColorSpace* cs) + : INHERITED(contentArea.width(), contentArea.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)); + if (contentArea.fLeft > 0 || contentArea.fTop > 0 || + contentArea.fRight < fOriginal->width() || contentArea.fBottom < fOriginal->height()) { + fContentArea.set(contentArea); + } +} void GrTextureAdjuster::makeCopyKey(const CopyParams& params, GrUniqueKey* copyKey, SkColorSpace* dstColorSpace) { @@ -46,8 +54,9 @@ 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), copyParams); + sk_sp<GrTextureProxy> copy = CopyOnGpu(fContext, std::move(proxy), contentArea, copyParams); if (copy) { if (key.isValid()) { SkASSERT(copy->origin() == this->originalProxy()->origin()); @@ -60,31 +69,60 @@ sk_sp<GrTextureProxy> GrTextureAdjuster::refTextureProxyCopy(const CopyParams& c sk_sp<GrTextureProxy> GrTextureAdjuster::refTextureProxySafeForParams( const GrSamplerParams& params, + SkIPoint* outOffset, SkScalar scaleAdjust[2]) { sk_sp<GrTextureProxy> proxy = this->originalProxyRef(); CopyParams copyParams; + const SkIRect* contentArea = this->contentAreaOrNull(); if (!fContext) { // The texture was abandoned. return nullptr; } - if (!fContext->getGpu()->isACopyNeededForTextureParams(proxy.get(), params, ©Params, - scaleAdjust)) { + + if (contentArea && GrSamplerParams::kMipMap_FilterMode == params.filterMode()) { + // 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 = GrSamplerParams::kBilerp_FilterMode; + } else if (!fContext->getGpu()->isACopyNeededForTextureParams(proxy.get(), params, ©Params, + scaleAdjust)) { + if (outOffset) { + if (contentArea) { + outOffset->set(contentArea->fLeft, contentArea->fRight); + } else { + outOffset->set(0, 0); + } + } return proxy; } sk_sp<GrTextureProxy> copy = this->refTextureProxyCopy(copyParams); + if (copy && outOffset) { + outOffset->set(0, 0); + } return copy; } std::unique_ptr<GrFragmentProcessor> GrTextureAdjuster::createFragmentProcessor( const SkMatrix& origTextureMatrix, - const SkRect& constraintRect, + const SkRect& origConstraintRect, FilterConstraint filterConstraint, bool coordsLimitedToConstraintRect, const GrSamplerParams::FilterMode* 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; GrSamplerParams params; @@ -92,19 +130,22 @@ std::unique_ptr<GrFragmentProcessor> GrTextureAdjuster::createFragmentProcessor( params.setFilterMode(*filterOrNullForBicubic); } SkScalar scaleAdjust[2] = { 1.0f, 1.0f }; - sk_sp<GrTextureProxy> proxy(this->refTextureProxySafeForParams(params, scaleAdjust)); + sk_sp<GrTextureProxy> proxy(this->refTextureProxySafeForParams(params, nullptr, scaleAdjust)); if (!proxy) { return nullptr; } // 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(), filterOrNullForBicubic, &domain); + DetermineDomainMode(*constraintRect, filterConstraint, coordsLimitedToConstraintRect, + proxy.get(), + contentArea, filterOrNullForBicubic, + &domain); if (kTightCopy_DomainMode == domainMode) { // TODO: Copy the texture and adjust the texture matrix (both parts need to consider // non-int constraint rect) @@ -115,8 +156,9 @@ std::unique_ptr<GrFragmentProcessor> GrTextureAdjuster::createFragmentProcessor( GrSamplerParams::kMipMap_FilterMode == *filterOrNullForBicubic); static const GrSamplerParams::FilterMode kBilerp = GrSamplerParams::kBilerp_FilterMode; domainMode = - DetermineDomainMode(constraintRect, filterConstraint, coordsLimitedToConstraintRect, - proxy.get(), &kBilerp, &domain); + DetermineDomainMode(*constraintRect, filterConstraint, coordsLimitedToConstraintRect, + proxy.get(), + contentArea, &kBilerp, &domain); SkASSERT(kTightCopy_DomainMode != domainMode); } SkASSERT(kNoDomain_DomainMode == domainMode || |