diff options
author | Brian Salomon <bsalomon@google.com> | 2017-08-22 17:12:10 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-08-22 21:36:40 +0000 |
commit | a184ac7e0cdb26919369151f606c194358c94ff5 (patch) | |
tree | 73e00f463d8bd71f51ce4dd99fed9ff04e7aac67 /src/gpu/SkGpuDevice_drawTexture.cpp | |
parent | 82e314534c231dc399990ccf7803d7c5032392f5 (diff) |
Revert "Revert "Revert "Add GrTextureOp and use to implement SkGpuDevice::drawImage[Rect]() when possible"""
This reverts commit 20af6d12eefd8d937bc13bdb7fa0a9ac86b699af.
Performance regressions on Android and Flutter
Change-Id: If70edbe85aa251f298eddf18a89ba2cf56ed94fb
Reviewed-on: https://skia-review.googlesource.com/37340
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'src/gpu/SkGpuDevice_drawTexture.cpp')
-rw-r--r-- | src/gpu/SkGpuDevice_drawTexture.cpp | 98 |
1 files changed, 7 insertions, 91 deletions
diff --git a/src/gpu/SkGpuDevice_drawTexture.cpp b/src/gpu/SkGpuDevice_drawTexture.cpp index c861cc919e..6fa171113b 100644 --- a/src/gpu/SkGpuDevice_drawTexture.cpp +++ b/src/gpu/SkGpuDevice_drawTexture.cpp @@ -6,12 +6,12 @@ */ #include "SkGpuDevice.h" + #include "GrBlurUtils.h" #include "GrCaps.h" #include "GrRenderTargetContext.h" #include "GrStyle.h" #include "GrTextureAdjuster.h" -#include "GrTextureMaker.h" #include "SkDraw.h" #include "SkGr.h" #include "SkMaskFilter.h" @@ -85,98 +85,14 @@ static bool can_ignore_bilerp_constraint(const GrTextureProducer& producer, return false; } -/** - * Checks whether the paint, matrix, and constraint are compatible with using - * GrRenderTargetContext::drawTextureAffine. It is more effecient than the GrTextureProducer - * general case. - */ -static bool can_use_draw_texture_affine(const SkPaint& paint, const SkMatrix& ctm, - SkCanvas::SrcRectConstraint constraint) { - return (!paint.getColorFilter() && !paint.getShader() && !paint.getMaskFilter() && - !paint.getImageFilter() && !paint.isAntiAlias() && - paint.getFilterQuality() < kMedium_SkFilterQuality && - paint.getBlendMode() == SkBlendMode::kSrcOver && !ctm.hasPerspective() && - SkCanvas::kFast_SrcRectConstraint == constraint); -} - -static void draw_texture_affine(const SkPaint& paint, const SkMatrix& ctm, const SkRect* src, - const SkRect* dst, sk_sp<GrTextureProxy> proxy, - SkColorSpace* colorSpace, const GrClip& clip, - GrRenderTargetContext* rtc) { - SkASSERT(!(SkToBool(src) && !SkToBool(dst))); - SkRect srcRect = src ? *src : SkRect::MakeWH(proxy->width(), proxy->height()); - SkRect dstRect = dst ? *dst : srcRect; - if (src && !SkRect::MakeIWH(proxy->width(), proxy->height()).contains(srcRect)) { - // Shrink the src rect to be within bounds and proportionately shrink the dst rect. - SkMatrix srcToDst; - srcToDst.setRectToRect(srcRect, dstRect, SkMatrix::kFill_ScaleToFit); - SkAssertResult(srcRect.intersect(SkRect::MakeIWH(proxy->width(), proxy->height()))); - srcToDst.mapRect(&dstRect, srcRect); - } - auto csxf = GrColorSpaceXform::Make(colorSpace, rtc->getColorSpace()); - GrSamplerParams::FilterMode filter; - switch (paint.getFilterQuality()) { - case kNone_SkFilterQuality: - filter = GrSamplerParams::kNone_FilterMode; - break; - case kLow_SkFilterQuality: - filter = GrSamplerParams::kBilerp_FilterMode; - break; - case kMedium_SkFilterQuality: - case kHigh_SkFilterQuality: - SK_ABORT("Quality level not allowed."); - } - GrColor color = GrPixelConfigIsAlphaOnly(proxy->config()) - ? SkColorToPremulGrColor(paint.getColor()) - : SkColorAlphaToGrColor(paint.getColor()); - rtc->drawTextureAffine(clip, std::move(proxy), filter, color, srcRect, dstRect, ctm, - std::move(csxf)); -} - ////////////////////////////////////////////////////////////////////////////// -void SkGpuDevice::drawPinnedTextureProxy(sk_sp<GrTextureProxy> proxy, uint32_t pinnedUniqueID, - SkColorSpace* colorSpace, SkAlphaType alphaType, - const SkRect* srcRect, const SkRect* dstRect, - SkCanvas::SrcRectConstraint constraint, - const SkMatrix& viewMatrix, const SkPaint& paint) { - if (can_use_draw_texture_affine(paint, this->ctm(), constraint)) { - draw_texture_affine(paint, viewMatrix, srcRect, dstRect, std::move(proxy), colorSpace, - this->clip(), fRenderTargetContext.get()); - return; - } - auto contentRect = SkIRect::MakeWH(proxy->width(), proxy->height()); - GrTextureAdjuster adjuster(this->context(), std::move(proxy), alphaType, contentRect, - pinnedUniqueID, colorSpace); - this->drawTextureProducer(&adjuster, srcRect, dstRect, constraint, viewMatrix, paint); -} - -void SkGpuDevice::drawTextureMaker(GrTextureMaker* maker, int imageW, int imageH, - const SkRect* srcRect, const SkRect* dstRect, - SkCanvas::SrcRectConstraint constraint, - const SkMatrix& viewMatrix, const SkPaint& paint) { - if (can_use_draw_texture_affine(paint, viewMatrix, constraint)) { - sk_sp<SkColorSpace> cs; - // We've done enough checks above to allow us to pass ClampNoFilter() and not check for - // scaling adjustments. - auto proxy = maker->refTextureProxyForParams(GrSamplerParams::ClampNoFilter(), - fRenderTargetContext->getColorSpace(), &cs, - nullptr); - if (!proxy) { - return; - } - draw_texture_affine(paint, viewMatrix, srcRect, dstRect, std::move(proxy), cs.get(), - this->clip(), fRenderTargetContext.get()); - return; - } - this->drawTextureProducer(maker, srcRect, dstRect, constraint, viewMatrix, paint); -} - void SkGpuDevice::drawTextureProducer(GrTextureProducer* producer, const SkRect* srcRect, const SkRect* dstRect, SkCanvas::SrcRectConstraint constraint, const SkMatrix& viewMatrix, + const GrClip& clip, const SkPaint& paint) { // This is the funnel for all non-tiled bitmap/image draw calls. Log a histogram entry. SK_HISTOGRAM_BOOLEAN("DrawTiled", false); @@ -225,7 +141,7 @@ void SkGpuDevice::drawTextureProducer(GrTextureProducer* producer, LogDrawScaleFactor(SkMatrix::Concat(viewMatrix, srcToDstMatrix), paint.getFilterQuality()); this->drawTextureProducerImpl(producer, clippedSrcRect, clippedDstRect, constraint, viewMatrix, - srcToDstMatrix, paint); + srcToDstMatrix, clip, paint); } void SkGpuDevice::drawTextureProducerImpl(GrTextureProducer* producer, @@ -234,6 +150,7 @@ void SkGpuDevice::drawTextureProducerImpl(GrTextureProducer* producer, SkCanvas::SrcRectConstraint constraint, const SkMatrix& viewMatrix, const SkMatrix& srcToDstMatrix, + const GrClip& clip, const SkPaint& paint) { // Specifying the texture coords as local coordinates is an attempt to enable more GrDrawOp // combining by not baking anything about the srcRect, dstRect, or viewMatrix, into the texture @@ -298,14 +215,13 @@ void SkGpuDevice::drawTextureProducerImpl(GrTextureProducer* producer, } GrAA aa = GrBoolToAA(paint.isAntiAlias()); if (canUseTextureCoordsAsLocalCoords) { - fRenderTargetContext->fillRectToRect(this->clip(), std::move(grPaint), aa, viewMatrix, + fRenderTargetContext->fillRectToRect(clip, std::move(grPaint), aa, viewMatrix, clippedDstRect, clippedSrcRect); return; } if (!mf) { - fRenderTargetContext->drawRect(this->clip(), std::move(grPaint), aa, viewMatrix, - clippedDstRect); + fRenderTargetContext->drawRect(clip, std::move(grPaint), aa, viewMatrix, clippedDstRect); return; } @@ -318,7 +234,7 @@ void SkGpuDevice::drawTextureProducerImpl(GrTextureProducer* producer, if (mf->directFilterRRectMaskGPU(fContext.get(), fRenderTargetContext.get(), std::move(grPaint), - this->clip(), + clip, viewMatrix, rec, SkRRect::MakeRect(clippedDstRect), |