bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "SkGpuDevice.h" |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 9 | #include "GrBlurUtils.h" |
| 10 | #include "GrCaps.h" |
Brian Osman | 1cb4171 | 2017-10-19 12:54:52 -0400 | [diff] [blame] | 11 | #include "GrColorSpaceXform.h" |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 12 | #include "GrRenderTargetContext.h" |
Robert Phillips | 27927a5 | 2018-08-20 13:18:12 -0400 | [diff] [blame] | 13 | #include "GrShape.h" |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 14 | #include "GrStyle.h" |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 15 | #include "GrTextureAdjuster.h" |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 16 | #include "GrTextureMaker.h" |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 17 | #include "SkDraw.h" |
Brian Osman | 3b65598 | 2017-03-07 16:58:08 -0500 | [diff] [blame] | 18 | #include "SkGr.h" |
Mike Reed | 80747ef | 2018-01-23 15:29:32 -0500 | [diff] [blame] | 19 | #include "SkMaskFilterBase.h" |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 20 | #include "effects/GrBicubicEffect.h" |
| 21 | #include "effects/GrSimpleTextureEffect.h" |
| 22 | #include "effects/GrTextureDomain.h" |
| 23 | |
| 24 | static inline bool use_shader(bool textureIsAlphaOnly, const SkPaint& paint) { |
| 25 | return textureIsAlphaOnly && paint.getShader(); |
| 26 | } |
| 27 | |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 28 | ////////////////////////////////////////////////////////////////////////////// |
| 29 | // Helper functions for dropping src rect constraint in bilerp mode. |
| 30 | |
| 31 | static const SkScalar kColorBleedTolerance = 0.001f; |
| 32 | |
| 33 | static bool has_aligned_samples(const SkRect& srcRect, const SkRect& transformedRect) { |
| 34 | // detect pixel disalignment |
Brian Salomon | a911f8f | 2015-11-18 15:19:57 -0500 | [diff] [blame] | 35 | if (SkScalarAbs(SkScalarRoundToScalar(transformedRect.left()) - transformedRect.left()) < kColorBleedTolerance && |
| 36 | SkScalarAbs(SkScalarRoundToScalar(transformedRect.top()) - transformedRect.top()) < kColorBleedTolerance && |
| 37 | SkScalarAbs(transformedRect.width() - srcRect.width()) < kColorBleedTolerance && |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 38 | SkScalarAbs(transformedRect.height() - srcRect.height()) < kColorBleedTolerance) { |
| 39 | return true; |
| 40 | } |
| 41 | return false; |
| 42 | } |
| 43 | |
| 44 | static bool may_color_bleed(const SkRect& srcRect, |
| 45 | const SkRect& transformedRect, |
| 46 | const SkMatrix& m, |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 47 | GrFSAAType fsaaType) { |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 48 | // Only gets called if has_aligned_samples returned false. |
| 49 | // So we can assume that sampling is axis aligned but not texel aligned. |
| 50 | SkASSERT(!has_aligned_samples(srcRect, transformedRect)); |
| 51 | SkRect innerSrcRect(srcRect), innerTransformedRect, outerTransformedRect(transformedRect); |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 52 | if (GrFSAAType::kUnifiedMSAA == fsaaType) { |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 53 | innerSrcRect.inset(SK_Scalar1, SK_Scalar1); |
| 54 | } else { |
| 55 | innerSrcRect.inset(SK_ScalarHalf, SK_ScalarHalf); |
| 56 | } |
| 57 | m.mapRect(&innerTransformedRect, innerSrcRect); |
| 58 | |
| 59 | // The gap between outerTransformedRect and innerTransformedRect |
| 60 | // represents the projection of the source border area, which is |
| 61 | // problematic for color bleeding. We must check whether any |
| 62 | // destination pixels sample the border area. |
| 63 | outerTransformedRect.inset(kColorBleedTolerance, kColorBleedTolerance); |
| 64 | innerTransformedRect.outset(kColorBleedTolerance, kColorBleedTolerance); |
| 65 | SkIRect outer, inner; |
| 66 | outerTransformedRect.round(&outer); |
| 67 | innerTransformedRect.round(&inner); |
| 68 | // If the inner and outer rects round to the same result, it means the |
| 69 | // border does not overlap any pixel centers. Yay! |
| 70 | return inner != outer; |
| 71 | } |
| 72 | |
| 73 | static bool can_ignore_bilerp_constraint(const GrTextureProducer& producer, |
| 74 | const SkRect& srcRect, |
| 75 | const SkMatrix& srcRectToDeviceSpace, |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 76 | GrFSAAType fsaaType) { |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 77 | if (srcRectToDeviceSpace.rectStaysRect()) { |
| 78 | // sampling is axis-aligned |
| 79 | SkRect transformedRect; |
| 80 | srcRectToDeviceSpace.mapRect(&transformedRect, srcRect); |
| 81 | |
| 82 | if (has_aligned_samples(srcRect, transformedRect) || |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 83 | !may_color_bleed(srcRect, transformedRect, srcRectToDeviceSpace, fsaaType)) { |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 84 | return true; |
| 85 | } |
| 86 | } |
| 87 | return false; |
| 88 | } |
| 89 | |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 90 | /** |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 91 | * Checks whether the paint is compatible with using GrRenderTargetContext::drawTexture. It is more |
| 92 | * efficient than the GrTextureProducer general case. |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 93 | */ |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 94 | static bool can_use_draw_texture(const SkPaint& paint) { |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 95 | return (!paint.getColorFilter() && !paint.getShader() && !paint.getMaskFilter() && |
Brian Salomon | b5ef1f9 | 2018-01-11 11:46:21 -0500 | [diff] [blame] | 96 | !paint.getImageFilter() && paint.getFilterQuality() < kMedium_SkFilterQuality && |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 97 | paint.getBlendMode() == SkBlendMode::kSrcOver); |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 98 | } |
| 99 | |
Brian Salomon | be3c1d2 | 2018-05-21 12:54:39 -0400 | [diff] [blame] | 100 | static void draw_texture(const SkPaint& paint, const SkMatrix& ctm, const SkRect* src, |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 101 | const SkRect* dst, GrAA aa, SkCanvas::SrcRectConstraint constraint, |
Brian Osman | 21fc5ce | 2018-08-27 20:36:19 +0000 | [diff] [blame] | 102 | sk_sp<GrTextureProxy> proxy, SkAlphaType alphaType, |
Brian Salomon | be3c1d2 | 2018-05-21 12:54:39 -0400 | [diff] [blame] | 103 | SkColorSpace* colorSpace, const GrClip& clip, GrRenderTargetContext* rtc) { |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 104 | SkASSERT(!(SkToBool(src) && !SkToBool(dst))); |
| 105 | SkRect srcRect = src ? *src : SkRect::MakeWH(proxy->width(), proxy->height()); |
| 106 | SkRect dstRect = dst ? *dst : srcRect; |
| 107 | if (src && !SkRect::MakeIWH(proxy->width(), proxy->height()).contains(srcRect)) { |
| 108 | // Shrink the src rect to be within bounds and proportionately shrink the dst rect. |
| 109 | SkMatrix srcToDst; |
| 110 | srcToDst.setRectToRect(srcRect, dstRect, SkMatrix::kFill_ScaleToFit); |
| 111 | SkAssertResult(srcRect.intersect(SkRect::MakeIWH(proxy->width(), proxy->height()))); |
| 112 | srcToDst.mapRect(&dstRect, srcRect); |
| 113 | } |
Mike Klein | e03a176 | 2018-08-22 11:52:16 -0400 | [diff] [blame] | 114 | auto textureXform = |
Brian Osman | 21fc5ce | 2018-08-27 20:36:19 +0000 | [diff] [blame] | 115 | GrColorSpaceXform::Make(colorSpace , alphaType, |
Mike Klein | e03a176 | 2018-08-22 11:52:16 -0400 | [diff] [blame] | 116 | rtc->colorSpaceInfo().colorSpace(), kPremul_SkAlphaType); |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 117 | GrSamplerState::Filter filter; |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 118 | switch (paint.getFilterQuality()) { |
| 119 | case kNone_SkFilterQuality: |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 120 | filter = GrSamplerState::Filter::kNearest; |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 121 | break; |
| 122 | case kLow_SkFilterQuality: |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 123 | filter = GrSamplerState::Filter::kBilerp; |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 124 | break; |
| 125 | case kMedium_SkFilterQuality: |
| 126 | case kHigh_SkFilterQuality: |
| 127 | SK_ABORT("Quality level not allowed."); |
| 128 | } |
Brian Osman | 3ebd354 | 2018-07-30 14:36:53 -0400 | [diff] [blame] | 129 | GrColor color; |
| 130 | sk_sp<GrColorSpaceXform> paintColorXform = nullptr; |
| 131 | if (GrPixelConfigIsAlphaOnly(proxy->config())) { |
| 132 | // Leave the color unpremul if we're going to transform it in the vertex shader |
| 133 | paintColorXform = rtc->colorSpaceInfo().refColorSpaceXformFromSRGB(); |
| 134 | color = paintColorXform ? SkColorToUnpremulGrColor(paint.getColor()) |
| 135 | : SkColorToPremulGrColor(paint.getColor()); |
| 136 | } else { |
Brian Osman | b0f4d0a | 2018-09-05 14:16:27 +0000 | [diff] [blame] | 137 | color = GrColorPackA4(paint.getAlpha()); |
Brian Osman | 3ebd354 | 2018-07-30 14:36:53 -0400 | [diff] [blame] | 138 | } |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 139 | rtc->drawTexture(clip, std::move(proxy), filter, color, srcRect, dstRect, aa, constraint, ctm, |
Brian Osman | 3ebd354 | 2018-07-30 14:36:53 -0400 | [diff] [blame] | 140 | std::move(textureXform), std::move(paintColorXform)); |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 141 | } |
| 142 | |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 143 | ////////////////////////////////////////////////////////////////////////////// |
| 144 | |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 145 | void SkGpuDevice::drawPinnedTextureProxy(sk_sp<GrTextureProxy> proxy, uint32_t pinnedUniqueID, |
| 146 | SkColorSpace* colorSpace, SkAlphaType alphaType, |
| 147 | const SkRect* srcRect, const SkRect* dstRect, |
| 148 | SkCanvas::SrcRectConstraint constraint, |
| 149 | const SkMatrix& viewMatrix, const SkPaint& paint) { |
Brian Salomon | 4e6cf91 | 2018-01-17 09:27:35 -0500 | [diff] [blame] | 150 | GrAA aa = GrAA(paint.isAntiAlias()); |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 151 | if (can_use_draw_texture(paint)) { |
| 152 | draw_texture(paint, viewMatrix, srcRect, dstRect, aa, constraint, std::move(proxy), |
Brian Osman | 21fc5ce | 2018-08-27 20:36:19 +0000 | [diff] [blame] | 153 | alphaType, colorSpace, this->clip(), fRenderTargetContext.get()); |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 154 | return; |
| 155 | } |
Greg Daniel | c77085d | 2017-11-01 16:38:48 -0400 | [diff] [blame] | 156 | GrTextureAdjuster adjuster(this->context(), std::move(proxy), alphaType, pinnedUniqueID, |
| 157 | colorSpace); |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 158 | this->drawTextureProducer(&adjuster, srcRect, dstRect, constraint, viewMatrix, paint); |
| 159 | } |
| 160 | |
| 161 | void SkGpuDevice::drawTextureMaker(GrTextureMaker* maker, int imageW, int imageH, |
| 162 | const SkRect* srcRect, const SkRect* dstRect, |
| 163 | SkCanvas::SrcRectConstraint constraint, |
| 164 | const SkMatrix& viewMatrix, const SkPaint& paint) { |
Brian Salomon | 4e6cf91 | 2018-01-17 09:27:35 -0500 | [diff] [blame] | 165 | GrAA aa = GrAA(paint.isAntiAlias()); |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 166 | if (can_use_draw_texture(paint)) { |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 167 | sk_sp<SkColorSpace> cs; |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 168 | // We've done enough checks above to allow us to pass ClampNearest() and not check for |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 169 | // scaling adjustments. |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 170 | auto proxy = maker->refTextureProxyForParams( |
| 171 | GrSamplerState::ClampNearest(), fRenderTargetContext->colorSpaceInfo().colorSpace(), |
| 172 | &cs, nullptr); |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 173 | if (!proxy) { |
| 174 | return; |
| 175 | } |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 176 | draw_texture(paint, viewMatrix, srcRect, dstRect, aa, constraint, std::move(proxy), |
Brian Osman | 21fc5ce | 2018-08-27 20:36:19 +0000 | [diff] [blame] | 177 | maker->alphaType(), cs.get(), this->clip(), fRenderTargetContext.get()); |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 178 | return; |
| 179 | } |
| 180 | this->drawTextureProducer(maker, srcRect, dstRect, constraint, viewMatrix, paint); |
| 181 | } |
| 182 | |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 183 | void SkGpuDevice::drawTextureProducer(GrTextureProducer* producer, |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 184 | const SkRect* srcRect, |
| 185 | const SkRect* dstRect, |
| 186 | SkCanvas::SrcRectConstraint constraint, |
| 187 | const SkMatrix& viewMatrix, |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 188 | const SkPaint& paint) { |
ericrk | 369e937 | 2016-02-05 15:32:36 -0800 | [diff] [blame] | 189 | // This is the funnel for all non-tiled bitmap/image draw calls. Log a histogram entry. |
| 190 | SK_HISTOGRAM_BOOLEAN("DrawTiled", false); |
| 191 | |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 192 | // Figure out the actual dst and src rect by clipping the src rect to the bounds of the |
| 193 | // adjuster. If the src rect is clipped then the dst rect must be recomputed. Also determine |
| 194 | // the matrix that maps the src rect to the dst rect. |
| 195 | SkRect clippedSrcRect; |
| 196 | SkRect clippedDstRect; |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 197 | const SkRect srcBounds = SkRect::MakeIWH(producer->width(), producer->height()); |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 198 | SkMatrix srcToDstMatrix; |
| 199 | if (srcRect) { |
| 200 | if (!dstRect) { |
bsalomon | 3aa5fce | 2015-11-12 09:59:44 -0800 | [diff] [blame] | 201 | dstRect = &srcBounds; |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 202 | } |
bsalomon | 3aa5fce | 2015-11-12 09:59:44 -0800 | [diff] [blame] | 203 | if (!srcBounds.contains(*srcRect)) { |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 204 | clippedSrcRect = *srcRect; |
bsalomon | 3aa5fce | 2015-11-12 09:59:44 -0800 | [diff] [blame] | 205 | if (!clippedSrcRect.intersect(srcBounds)) { |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 206 | return; |
| 207 | } |
| 208 | if (!srcToDstMatrix.setRectToRect(*srcRect, *dstRect, SkMatrix::kFill_ScaleToFit)) { |
| 209 | return; |
| 210 | } |
| 211 | srcToDstMatrix.mapRect(&clippedDstRect, clippedSrcRect); |
| 212 | } else { |
| 213 | clippedSrcRect = *srcRect; |
| 214 | clippedDstRect = *dstRect; |
| 215 | if (!srcToDstMatrix.setRectToRect(*srcRect, *dstRect, SkMatrix::kFill_ScaleToFit)) { |
| 216 | return; |
| 217 | } |
| 218 | } |
| 219 | } else { |
bsalomon | 3aa5fce | 2015-11-12 09:59:44 -0800 | [diff] [blame] | 220 | clippedSrcRect = srcBounds; |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 221 | if (dstRect) { |
| 222 | clippedDstRect = *dstRect; |
bsalomon | 3aa5fce | 2015-11-12 09:59:44 -0800 | [diff] [blame] | 223 | if (!srcToDstMatrix.setRectToRect(srcBounds, *dstRect, SkMatrix::kFill_ScaleToFit)) { |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 224 | return; |
| 225 | } |
| 226 | } else { |
bsalomon | 3aa5fce | 2015-11-12 09:59:44 -0800 | [diff] [blame] | 227 | clippedDstRect = srcBounds; |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 228 | srcToDstMatrix.reset(); |
| 229 | } |
| 230 | } |
| 231 | |
ericrk | 983294f | 2016-04-18 09:14:00 -0700 | [diff] [blame] | 232 | // Now that we have both the view and srcToDst matrices, log our scale factor. |
| 233 | LogDrawScaleFactor(SkMatrix::Concat(viewMatrix, srcToDstMatrix), paint.getFilterQuality()); |
| 234 | |
bsalomon | f1ecd21 | 2015-12-09 17:06:02 -0800 | [diff] [blame] | 235 | this->drawTextureProducerImpl(producer, clippedSrcRect, clippedDstRect, constraint, viewMatrix, |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 236 | srcToDstMatrix, paint); |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 237 | } |
| 238 | |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 239 | void SkGpuDevice::drawTextureProducerImpl(GrTextureProducer* producer, |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 240 | const SkRect& clippedSrcRect, |
| 241 | const SkRect& clippedDstRect, |
| 242 | SkCanvas::SrcRectConstraint constraint, |
| 243 | const SkMatrix& viewMatrix, |
| 244 | const SkMatrix& srcToDstMatrix, |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 245 | const SkPaint& paint) { |
Brian Salomon | 09d994e | 2016-12-21 11:14:46 -0500 | [diff] [blame] | 246 | // Specifying the texture coords as local coordinates is an attempt to enable more GrDrawOp |
| 247 | // combining by not baking anything about the srcRect, dstRect, or viewMatrix, into the texture |
| 248 | // FP. In the future this should be an opaque optimization enabled by the combination of |
| 249 | // GrDrawOp/GP and FP. |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 250 | const SkMaskFilter* mf = paint.getMaskFilter(); |
Mike Reed | 547c859 | 2018-02-05 15:59:23 -0500 | [diff] [blame] | 251 | if (mf && as_MFB(mf)->hasFragmentProcessor()) { |
| 252 | mf = nullptr; |
| 253 | } |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 254 | // The shader expects proper local coords, so we can't replace local coords with texture coords |
| 255 | // if the shader will be used. If we have a mask filter we will change the underlying geometry |
| 256 | // that is rendered. |
bsalomon | f1ecd21 | 2015-12-09 17:06:02 -0800 | [diff] [blame] | 257 | bool canUseTextureCoordsAsLocalCoords = !use_shader(producer->isAlphaOnly(), paint) && !mf; |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 258 | |
| 259 | bool doBicubic; |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 260 | GrSamplerState::Filter fm = GrSkFilterQualityToGrFilterMode( |
Brian Osman | db78cba | 2018-02-15 10:09:48 -0500 | [diff] [blame] | 261 | paint.getFilterQuality(), viewMatrix, srcToDstMatrix, |
| 262 | fContext->contextPriv().sharpenMipmappedTextures(), &doBicubic); |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 263 | const GrSamplerState::Filter* filterMode = doBicubic ? nullptr : &fm; |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 264 | |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 265 | GrTextureProducer::FilterConstraint constraintMode; |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 266 | if (SkCanvas::kFast_SrcRectConstraint == constraint) { |
| 267 | constraintMode = GrTextureAdjuster::kNo_FilterConstraint; |
| 268 | } else { |
| 269 | constraintMode = GrTextureAdjuster::kYes_FilterConstraint; |
| 270 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 271 | |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 272 | // If we have to outset for AA then we will generate texture coords outside the src rect. The |
| 273 | // same happens for any mask filter that extends the bounds rendered in the dst. |
| 274 | // This is conservative as a mask filter does not have to expand the bounds rendered. |
| 275 | bool coordsAllInsideSrcRect = !paint.isAntiAlias() && !mf; |
| 276 | |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 277 | // Check for optimization to drop the src rect constraint when on bilerp. |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 278 | if (filterMode && GrSamplerState::Filter::kBilerp == *filterMode && |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 279 | GrTextureAdjuster::kYes_FilterConstraint == constraintMode && coordsAllInsideSrcRect) { |
| 280 | SkMatrix combinedMatrix; |
| 281 | combinedMatrix.setConcat(viewMatrix, srcToDstMatrix); |
| 282 | if (can_ignore_bilerp_constraint(*producer, clippedSrcRect, combinedMatrix, |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 283 | fRenderTargetContext->fsaaType())) { |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 284 | constraintMode = GrTextureAdjuster::kNo_FilterConstraint; |
| 285 | } |
| 286 | } |
| 287 | |
bsalomon | 3aa5fce | 2015-11-12 09:59:44 -0800 | [diff] [blame] | 288 | const SkMatrix* textureMatrix; |
| 289 | SkMatrix tempMatrix; |
| 290 | if (canUseTextureCoordsAsLocalCoords) { |
| 291 | textureMatrix = &SkMatrix::I(); |
| 292 | } else { |
| 293 | if (!srcToDstMatrix.invert(&tempMatrix)) { |
| 294 | return; |
| 295 | } |
| 296 | textureMatrix = &tempMatrix; |
| 297 | } |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 298 | auto fp = producer->createFragmentProcessor( |
| 299 | *textureMatrix, clippedSrcRect, constraintMode, coordsAllInsideSrcRect, filterMode, |
| 300 | fRenderTargetContext->colorSpaceInfo().colorSpace()); |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 301 | if (!fp) { |
| 302 | return; |
| 303 | } |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 304 | |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 305 | GrPaint grPaint; |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 306 | if (!SkPaintToGrPaintWithTexture(fContext.get(), fRenderTargetContext->colorSpaceInfo(), paint, |
| 307 | viewMatrix, std::move(fp), producer->isAlphaOnly(), |
| 308 | &grPaint)) { |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 309 | return; |
| 310 | } |
Chris Dalton | 3b51df1 | 2017-11-27 14:33:06 -0700 | [diff] [blame] | 311 | GrAA aa = GrAA(paint.isAntiAlias()); |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 312 | if (canUseTextureCoordsAsLocalCoords) { |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 313 | fRenderTargetContext->fillRectToRect(this->clip(), std::move(grPaint), aa, viewMatrix, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 314 | clippedDstRect, clippedSrcRect); |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 315 | return; |
| 316 | } |
| 317 | |
| 318 | if (!mf) { |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 319 | fRenderTargetContext->drawRect(this->clip(), std::move(grPaint), aa, viewMatrix, |
| 320 | clippedDstRect); |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 321 | return; |
| 322 | } |
| 323 | |
Robert Phillips | 27927a5 | 2018-08-20 13:18:12 -0400 | [diff] [blame] | 324 | GrShape shape(clippedDstRect, GrStyle::SimpleFill()); |
| 325 | |
| 326 | GrBlurUtils::drawShapeWithMaskFilter(this->context(), fRenderTargetContext.get(), this->clip(), |
Robert Phillips | 793324c | 2018-08-24 13:53:56 -0400 | [diff] [blame] | 327 | shape, std::move(grPaint), viewMatrix, mf); |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 328 | } |