aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Salomon <bsalomon@google.com>2018-10-03 11:57:00 -0400
committerSkia Commit-Bot <skia-commit-bot@chromium.org>2018-10-03 17:15:02 +0000
commitf1709049243e67438020c82003b630232d9bc755 (patch)
treef5b07f115432ae96f1722301e54caa83e5bcff94
parenta55e214bbe3942a098d97906a0f008d59dd1fafb (diff)
downloadskqp-f1709049243e67438020c82003b630232d9bc755.tar.gz
Move integer rect checks from GrRenderTarget::drawTexture to GrTextureOp
Change-Id: I70502b1f2e54be5854b5549434bb9e4c0beee572 Reviewed-on: https://skia-review.googlesource.com/159153 Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Brian Salomon <bsalomon@google.com>
-rw-r--r--src/gpu/GrRenderTargetContext.cpp31
-rw-r--r--src/gpu/ops/GrTextureOp.cpp36
2 files changed, 28 insertions, 39 deletions
diff --git a/src/gpu/GrRenderTargetContext.cpp b/src/gpu/GrRenderTargetContext.cpp
index 4f8174f558..a60fda0cc1 100644
--- a/src/gpu/GrRenderTargetContext.cpp
+++ b/src/gpu/GrRenderTargetContext.cpp
@@ -732,23 +732,6 @@ void GrRenderTargetContext::fillRectToRect(const GrClip& clip,
GrShape(localRect));
}
-static bool must_filter(const SkRect& src, const SkRect& dst, const SkMatrix& ctm) {
- // We don't currently look for 90 degree rotations, mirroring, or downscales that sample at
- // texel centers.
- if (!ctm.isTranslate()) {
- return true;
- }
- if (src.width() != dst.width() || src.height() != dst.height()) {
- return true;
- }
- // Check that the device space rectangle's fractional offset is the same as the src rectangle,
- // and that therefore integers in the src image fall on integers in device space.
- SkScalar x = ctm.getTranslateX(), y = ctm.getTranslateY();
- x += dst.fLeft; y += dst.fTop;
- x -= src.fLeft; y -= src.fTop;
- return !SkScalarIsInt(x) || !SkScalarIsInt(y);
-}
-
void GrRenderTargetContext::drawTexture(const GrClip& clip, sk_sp<GrTextureProxy> proxy,
GrSamplerState::Filter filter, GrColor color,
const SkRect& srcRect, const SkRect& dstRect,
@@ -761,20 +744,12 @@ void GrRenderTargetContext::drawTexture(const GrClip& clip, sk_sp<GrTextureProxy
RETURN_IF_ABANDONED
SkDEBUGCODE(this->validate();)
GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "drawTexture", fContext);
- if (filter != GrSamplerState::Filter::kNearest && !must_filter(srcRect, dstRect, viewMatrix)) {
- filter = GrSamplerState::Filter::kNearest;
+ if (constraint == SkCanvas::kStrict_SrcRectConstraint &&
+ srcRect.contains(proxy->getWorstCaseBoundsRect())) {
+ constraint = SkCanvas::kFast_SrcRectConstraint;
}
GrAAType aaType =
this->chooseAAType(GrAA(aaFlags != GrQuadAAFlags::kNone), GrAllowMixedSamples::kNo);
- if (constraint == SkCanvas::kStrict_SrcRectConstraint) {
- // No need to use a texture domain with nearest filtering unless there is AA bloating.
- // Also, no need if the srcRect contains the entire texture.
- if (filter == GrSamplerState::Filter::kNearest && aaType != GrAAType::kCoverage) {
- constraint = SkCanvas::kFast_SrcRectConstraint;
- } else if (srcRect.contains(proxy->getWorstCaseBoundsRect())) {
- constraint = SkCanvas::kFast_SrcRectConstraint;
- }
- }
SkRect clippedDstRect = dstRect;
SkRect clippedSrcRect = srcRect;
if (!crop_filled_rect(this->width(), this->height(), clip, viewMatrix, &clippedDstRect,
diff --git a/src/gpu/ops/GrTextureOp.cpp b/src/gpu/ops/GrTextureOp.cpp
index 4fd6cade37..a5c051d9ef 100644
--- a/src/gpu/ops/GrTextureOp.cpp
+++ b/src/gpu/ops/GrTextureOp.cpp
@@ -676,18 +676,32 @@ private:
fPerspective = viewMatrix.hasPerspective();
auto quad = GrPerspQuad(dstRect, viewMatrix);
auto bounds = quad.bounds();
- if (GrAAType::kCoverage == this->aaType() && viewMatrix.rectStaysRect()) {
+ // We expect our caller to have already caught this optimization.
+ SkASSERT(!srcRect.contains(fProxy->getWorstCaseBoundsRect()) ||
+ constraint == SkCanvas::kFast_SrcRectConstraint);
+ if (viewMatrix.rectStaysRect()) {
+ // Disable filtering when there is no scaling or fractional translation.
// Disable coverage AA when rect falls on integers in device space.
- auto is_int = [](float f) { return f == sk_float_floor(f); };
- if (is_int(bounds.fLeft) && is_int(bounds.fTop) && is_int(bounds.fRight) &&
- is_int(bounds.fBottom)) {
- fAAType = static_cast<unsigned>(GrAAType::kNone);
- aaFlags = GrQuadAAFlags::kNone;
- // We may have had a strict constraint with nearest filter soley due to possible AA
- // bloat. In that case it's no longer necessary.
- if (constraint == SkCanvas::kStrict_SrcRectConstraint &&
- filter == GrSamplerState::Filter::kNearest) {
- constraint = SkCanvas::kFast_SrcRectConstraint;
+ if (SkScalarIsInt(bounds.fLeft) && SkScalarIsInt(bounds.fTop) &&
+ SkScalarIsInt(bounds.fRight) && SkScalarIsInt(bounds.fBottom)) {
+ if (viewMatrix.isScaleTranslate()) {
+ if (bounds.width() == srcRect.width() && bounds.height() == srcRect.height()) {
+ fFilter = GrSamplerState::Filter::kNearest;
+ }
+ } else {
+ if (bounds.width() == srcRect.height() && bounds.height() == srcRect.width()) {
+ fFilter = GrSamplerState::Filter::kNearest;
+ }
+ }
+ if (GrAAType::kCoverage == this->aaType()) {
+ fAAType = static_cast<unsigned>(GrAAType::kNone);
+ aaFlags = GrQuadAAFlags::kNone;
+ // We may have had a strict constraint with nearest filter solely due to
+ // possible AA bloat. In that case it's no longer necessary.
+ if (constraint == SkCanvas::kStrict_SrcRectConstraint &&
+ fFilter == GrSamplerState::Filter::kNearest) {
+ constraint = SkCanvas::kFast_SrcRectConstraint;
+ }
}
}
}