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>
diff --git a/src/gpu/GrTextureAdjuster.cpp b/src/gpu/GrTextureAdjuster.cpp
index 2ae95a9..d8985fe 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> 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 @@
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 @@
// 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 @@
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 ca5b0e9..a0ce8c4 100644
--- a/src/gpu/GrTextureAdjuster.h
+++ b/src/gpu/GrTextureAdjuster.h
@@ -35,8 +35,8 @@
// 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 @@
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 e234180..b3a16f5 100644
--- a/src/gpu/GrTextureMaker.cpp
+++ b/src/gpu/GrTextureMaker.cpp
@@ -73,7 +73,7 @@
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 @@
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 @@
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 f5ae0ad..1be75f9 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 @@
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 @@
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 @@
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 @@
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 @@
// 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 @@
// 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 @@
} 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 432e7b3..88ba14a 100644
--- a/src/gpu/GrTextureProducer.h
+++ b/src/gpu/GrTextureProducer.h
@@ -124,14 +124,13 @@
};
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 760e606..33837d3 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -1395,8 +1395,8 @@
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 @@
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 9838f46..c823ebd 100644
--- a/src/gpu/SkGpuDevice_drawTexture.cpp
+++ b/src/gpu/SkGpuDevice_drawTexture.cpp
@@ -147,9 +147,8 @@
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);
}
diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp
index 856b3b8..d279188 100644
--- a/src/image/SkImage_Gpu.cpp
+++ b/src/image/SkImage_Gpu.cpp
@@ -125,8 +125,8 @@
*texColorSpace = this->fColorSpace;
}
- GrTextureAdjuster adjuster(fContext, fProxy, this->alphaType(), this->bounds(),
- this->uniqueID(), this->fColorSpace.get());
+ GrTextureAdjuster adjuster(fContext, fProxy, this->alphaType(), this->uniqueID(),
+ this->fColorSpace.get());
return adjuster.refTextureProxySafeForParams(params, scaleAdjust);
}
diff --git a/src/image/SkImage_Raster.cpp b/src/image/SkImage_Raster.cpp
index db91621..fc9e167 100644
--- a/src/image/SkImage_Raster.cpp
+++ b/src/image/SkImage_Raster.cpp
@@ -186,9 +186,8 @@
uint32_t uniqueID;
sk_sp<GrTextureProxy> tex = this->refPinnedTextureProxy(&uniqueID);
if (tex) {
- GrTextureAdjuster adjuster(context, fPinnedProxy,
- fBitmap.alphaType(), fBitmap.bounds(),
- fPinnedUniqueID, fBitmap.colorSpace());
+ GrTextureAdjuster adjuster(context, fPinnedProxy, fBitmap.alphaType(), fPinnedUniqueID,
+ fBitmap.colorSpace());
return adjuster.refTextureProxySafeForParams(params, scaleAdjust);
}