aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/SkGpuDevice_drawTexture.cpp
diff options
context:
space:
mode:
authorGravatar Brian Salomon <bsalomon@google.com>2017-08-18 09:16:57 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-08-18 14:37:09 +0000
commit20af6d12eefd8d937bc13bdb7fa0a9ac86b699af (patch)
tree6773b3029cb9c426c5e3daaed28b1f4e34740e4d /src/gpu/SkGpuDevice_drawTexture.cpp
parentf6df1cd993c4cd717b40c5f19c2b96029250ac9b (diff)
Revert "Revert "Add GrTextureOp and use to implement SkGpuDevice::drawImage[Rect]() when possible""
This reverts commit ceef4fb5c498003be77a32a46cedfbf5da22a274. Bug: skia: Change-Id: I50b738169b4cf9e06cbe0b5fad0234b506717b66 Reviewed-on: https://skia-review.googlesource.com/36201 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.cpp98
1 files changed, 91 insertions, 7 deletions
diff --git a/src/gpu/SkGpuDevice_drawTexture.cpp b/src/gpu/SkGpuDevice_drawTexture.cpp
index 6fa171113b..c861cc919e 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,14 +85,98 @@ 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);
@@ -141,7 +225,7 @@ void SkGpuDevice::drawTextureProducer(GrTextureProducer* producer,
LogDrawScaleFactor(SkMatrix::Concat(viewMatrix, srcToDstMatrix), paint.getFilterQuality());
this->drawTextureProducerImpl(producer, clippedSrcRect, clippedDstRect, constraint, viewMatrix,
- srcToDstMatrix, clip, paint);
+ srcToDstMatrix, paint);
}
void SkGpuDevice::drawTextureProducerImpl(GrTextureProducer* producer,
@@ -150,7 +234,6 @@ 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
@@ -215,13 +298,14 @@ void SkGpuDevice::drawTextureProducerImpl(GrTextureProducer* producer,
}
GrAA aa = GrBoolToAA(paint.isAntiAlias());
if (canUseTextureCoordsAsLocalCoords) {
- fRenderTargetContext->fillRectToRect(clip, std::move(grPaint), aa, viewMatrix,
+ fRenderTargetContext->fillRectToRect(this->clip(), std::move(grPaint), aa, viewMatrix,
clippedDstRect, clippedSrcRect);
return;
}
if (!mf) {
- fRenderTargetContext->drawRect(clip, std::move(grPaint), aa, viewMatrix, clippedDstRect);
+ fRenderTargetContext->drawRect(this->clip(), std::move(grPaint), aa, viewMatrix,
+ clippedDstRect);
return;
}
@@ -234,7 +318,7 @@ void SkGpuDevice::drawTextureProducerImpl(GrTextureProducer* producer,
if (mf->directFilterRRectMaskGPU(fContext.get(),
fRenderTargetContext.get(),
std::move(grPaint),
- clip,
+ this->clip(),
viewMatrix,
rec,
SkRRect::MakeRect(clippedDstRect),