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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "src/gpu/SkGpuDevice.h" |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "include/core/SkYUVAIndex.h" |
| 11 | #include "src/core/SkDraw.h" |
| 12 | #include "src/core/SkMaskFilterBase.h" |
| 13 | #include "src/gpu/GrBitmapTextureMaker.h" |
| 14 | #include "src/gpu/GrBlurUtils.h" |
| 15 | #include "src/gpu/GrCaps.h" |
| 16 | #include "src/gpu/GrColorSpaceXform.h" |
| 17 | #include "src/gpu/GrImageTextureMaker.h" |
| 18 | #include "src/gpu/GrRenderTargetContext.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 19 | #include "src/gpu/GrStyle.h" |
| 20 | #include "src/gpu/GrTextureAdjuster.h" |
| 21 | #include "src/gpu/GrTextureMaker.h" |
| 22 | #include "src/gpu/SkGr.h" |
| 23 | #include "src/gpu/effects/GrBicubicEffect.h" |
| 24 | #include "src/gpu/effects/GrTextureDomain.h" |
| 25 | #include "src/gpu/effects/generated/GrSimpleTextureEffect.h" |
Michael Ludwig | 663afe5 | 2019-06-03 16:46:19 -0400 | [diff] [blame] | 26 | #include "src/gpu/geometry/GrShape.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 27 | #include "src/image/SkImage_Base.h" |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 28 | |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 29 | namespace { |
| 30 | |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 31 | static inline bool use_shader(bool textureIsAlphaOnly, const SkPaint& paint) { |
| 32 | return textureIsAlphaOnly && paint.getShader(); |
| 33 | } |
| 34 | |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 35 | ////////////////////////////////////////////////////////////////////////////// |
| 36 | // Helper functions for dropping src rect constraint in bilerp mode. |
| 37 | |
| 38 | static const SkScalar kColorBleedTolerance = 0.001f; |
| 39 | |
| 40 | static bool has_aligned_samples(const SkRect& srcRect, const SkRect& transformedRect) { |
| 41 | // detect pixel disalignment |
Brian Salomon | a911f8f | 2015-11-18 15:19:57 -0500 | [diff] [blame] | 42 | if (SkScalarAbs(SkScalarRoundToScalar(transformedRect.left()) - transformedRect.left()) < kColorBleedTolerance && |
| 43 | SkScalarAbs(SkScalarRoundToScalar(transformedRect.top()) - transformedRect.top()) < kColorBleedTolerance && |
| 44 | SkScalarAbs(transformedRect.width() - srcRect.width()) < kColorBleedTolerance && |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 45 | SkScalarAbs(transformedRect.height() - srcRect.height()) < kColorBleedTolerance) { |
| 46 | return true; |
| 47 | } |
| 48 | return false; |
| 49 | } |
| 50 | |
| 51 | static bool may_color_bleed(const SkRect& srcRect, |
| 52 | const SkRect& transformedRect, |
| 53 | const SkMatrix& m, |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 54 | int numSamples) { |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 55 | // Only gets called if has_aligned_samples returned false. |
| 56 | // So we can assume that sampling is axis aligned but not texel aligned. |
| 57 | SkASSERT(!has_aligned_samples(srcRect, transformedRect)); |
| 58 | SkRect innerSrcRect(srcRect), innerTransformedRect, outerTransformedRect(transformedRect); |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 59 | if (numSamples > 1) { |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 60 | innerSrcRect.inset(SK_Scalar1, SK_Scalar1); |
| 61 | } else { |
| 62 | innerSrcRect.inset(SK_ScalarHalf, SK_ScalarHalf); |
| 63 | } |
| 64 | m.mapRect(&innerTransformedRect, innerSrcRect); |
| 65 | |
| 66 | // The gap between outerTransformedRect and innerTransformedRect |
| 67 | // represents the projection of the source border area, which is |
| 68 | // problematic for color bleeding. We must check whether any |
| 69 | // destination pixels sample the border area. |
| 70 | outerTransformedRect.inset(kColorBleedTolerance, kColorBleedTolerance); |
| 71 | innerTransformedRect.outset(kColorBleedTolerance, kColorBleedTolerance); |
| 72 | SkIRect outer, inner; |
| 73 | outerTransformedRect.round(&outer); |
| 74 | innerTransformedRect.round(&inner); |
| 75 | // If the inner and outer rects round to the same result, it means the |
| 76 | // border does not overlap any pixel centers. Yay! |
| 77 | return inner != outer; |
| 78 | } |
| 79 | |
| 80 | static bool can_ignore_bilerp_constraint(const GrTextureProducer& producer, |
| 81 | const SkRect& srcRect, |
| 82 | const SkMatrix& srcRectToDeviceSpace, |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 83 | int numSamples) { |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 84 | if (srcRectToDeviceSpace.rectStaysRect()) { |
| 85 | // sampling is axis-aligned |
| 86 | SkRect transformedRect; |
| 87 | srcRectToDeviceSpace.mapRect(&transformedRect, srcRect); |
| 88 | |
| 89 | if (has_aligned_samples(srcRect, transformedRect) || |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 90 | !may_color_bleed(srcRect, transformedRect, srcRectToDeviceSpace, numSamples)) { |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 91 | return true; |
| 92 | } |
| 93 | } |
| 94 | return false; |
| 95 | } |
| 96 | |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 97 | enum class ImageDrawMode { |
| 98 | // Src and dst have been restricted to the image content. May need to clamp, no need to decal. |
| 99 | kOptimized, |
| 100 | // Src and dst are their original sizes, requires use of a decal instead of plain clamping. |
| 101 | // This is used when a dst clip is provided and extends outside of the optimized dst rect. |
| 102 | kDecal, |
| 103 | // Src or dst are empty, or do not intersect the image content so don't draw anything. |
| 104 | kSkip |
| 105 | }; |
| 106 | |
| 107 | /** |
| 108 | * Optimize the src rect sampling area within an image (sized 'width' x 'height') such that |
| 109 | * 'outSrcRect' will be completely contained in the image's bounds. The corresponding rect |
| 110 | * to draw will be output to 'outDstRect'. The mapping between src and dst will be cached in |
| 111 | * 'srcToDst'. Outputs are not always updated when kSkip is returned. |
| 112 | * |
| 113 | * If 'origSrcRect' is null, implicitly use the image bounds. If 'origDstRect' is null, use the |
| 114 | * original src rect. 'dstClip' should be null when there is no additional clipping. |
| 115 | */ |
| 116 | static ImageDrawMode optimize_sample_area(const SkISize& image, const SkRect* origSrcRect, |
| 117 | const SkRect* origDstRect, const SkPoint dstClip[4], |
| 118 | SkRect* outSrcRect, SkRect* outDstRect, |
| 119 | SkMatrix* srcToDst) { |
| 120 | SkRect srcBounds = SkRect::MakeIWH(image.fWidth, image.fHeight); |
| 121 | |
| 122 | SkRect src = origSrcRect ? *origSrcRect : srcBounds; |
| 123 | SkRect dst = origDstRect ? *origDstRect : src; |
| 124 | |
| 125 | if (src.isEmpty() || dst.isEmpty()) { |
| 126 | return ImageDrawMode::kSkip; |
| 127 | } |
| 128 | |
| 129 | if (outDstRect) { |
| 130 | srcToDst->setRectToRect(src, dst, SkMatrix::kFill_ScaleToFit); |
| 131 | } else { |
| 132 | srcToDst->setIdentity(); |
| 133 | } |
| 134 | |
| 135 | if (origSrcRect && !srcBounds.contains(src)) { |
| 136 | if (!src.intersect(srcBounds)) { |
| 137 | return ImageDrawMode::kSkip; |
| 138 | } |
| 139 | srcToDst->mapRect(&dst, src); |
| 140 | |
| 141 | // Both src and dst have gotten smaller. If dstClip is provided, confirm it is still |
| 142 | // contained in dst, otherwise cannot optimize the sample area and must use a decal instead |
| 143 | if (dstClip) { |
| 144 | for (int i = 0; i < 4; ++i) { |
| 145 | if (!dst.contains(dstClip[i].fX, dstClip[i].fY)) { |
| 146 | // Must resort to using a decal mode restricted to the clipped 'src', and |
| 147 | // use the original dst rect (filling in src bounds as needed) |
| 148 | *outSrcRect = src; |
| 149 | *outDstRect = (origDstRect ? *origDstRect |
| 150 | : (origSrcRect ? *origSrcRect : srcBounds)); |
| 151 | return ImageDrawMode::kDecal; |
| 152 | } |
| 153 | } |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | // The original src and dst were fully contained in the image, or there was no dst clip to |
| 158 | // worry about, or the clip was still contained in the restricted dst rect. |
| 159 | *outSrcRect = src; |
| 160 | *outDstRect = dst; |
| 161 | return ImageDrawMode::kOptimized; |
| 162 | } |
| 163 | |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 164 | /** |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 165 | * Checks whether the paint is compatible with using GrRenderTargetContext::drawTexture. It is more |
| 166 | * efficient than the GrTextureProducer general case. |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 167 | */ |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 168 | static bool can_use_draw_texture(const SkPaint& paint) { |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 169 | return (!paint.getColorFilter() && !paint.getShader() && !paint.getMaskFilter() && |
Michael Ludwig | d54ca8f | 2019-02-13 13:25:21 -0500 | [diff] [blame] | 170 | !paint.getImageFilter() && paint.getFilterQuality() < kMedium_SkFilterQuality); |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 171 | } |
| 172 | |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 173 | // Assumes srcRect and dstRect have already been optimized to fit the proxy |
| 174 | static void draw_texture(GrRenderTargetContext* rtc, const GrClip& clip, const SkMatrix& ctm, |
| 175 | const SkPaint& paint, const SkRect& srcRect, const SkRect& dstRect, |
| 176 | const SkPoint dstClip[4], GrAA aa, GrQuadAAFlags aaFlags, |
| 177 | SkCanvas::SrcRectConstraint constraint, sk_sp<GrTextureProxy> proxy, |
| 178 | SkAlphaType alphaType, SkColorSpace* colorSpace) { |
Brian Osman | 3d139a4 | 2018-11-19 10:42:10 -0500 | [diff] [blame] | 179 | const GrColorSpaceInfo& dstInfo(rtc->colorSpaceInfo()); |
Mike Klein | e03a176 | 2018-08-22 11:52:16 -0400 | [diff] [blame] | 180 | auto textureXform = |
Brian Osman | 3d139a4 | 2018-11-19 10:42:10 -0500 | [diff] [blame] | 181 | GrColorSpaceXform::Make(colorSpace , alphaType, |
| 182 | dstInfo.colorSpace(), kPremul_SkAlphaType); |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 183 | GrSamplerState::Filter filter; |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 184 | switch (paint.getFilterQuality()) { |
| 185 | case kNone_SkFilterQuality: |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 186 | filter = GrSamplerState::Filter::kNearest; |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 187 | break; |
| 188 | case kLow_SkFilterQuality: |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 189 | filter = GrSamplerState::Filter::kBilerp; |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 190 | break; |
| 191 | case kMedium_SkFilterQuality: |
| 192 | case kHigh_SkFilterQuality: |
| 193 | SK_ABORT("Quality level not allowed."); |
| 194 | } |
Michael Ludwig | d54ca8f | 2019-02-13 13:25:21 -0500 | [diff] [blame] | 195 | |
| 196 | // Must specify the strict constraint when the proxy is not functionally exact and the src |
| 197 | // rect would access pixels outside the proxy's content area without the constraint. |
| 198 | if (constraint != SkCanvas::kStrict_SrcRectConstraint && |
| 199 | !GrProxyProvider::IsFunctionallyExact(proxy.get())) { |
| 200 | // Conservative estimate of how much a coord could be outset from src rect: |
| 201 | // 1/2 pixel for AA and 1/2 pixel for bilerp |
| 202 | float buffer = 0.5f * (aa == GrAA::kYes) + |
| 203 | 0.5f * (filter == GrSamplerState::Filter::kBilerp); |
| 204 | SkRect safeBounds = SkRect::MakeWH(proxy->width(), proxy->height()); |
| 205 | safeBounds.inset(buffer, buffer); |
| 206 | if (!safeBounds.contains(srcRect)) { |
| 207 | constraint = SkCanvas::kStrict_SrcRectConstraint; |
| 208 | } |
| 209 | } |
Brian Osman | 3d139a4 | 2018-11-19 10:42:10 -0500 | [diff] [blame] | 210 | SkPMColor4f color; |
Brian Osman | 3ebd354 | 2018-07-30 14:36:53 -0400 | [diff] [blame] | 211 | if (GrPixelConfigIsAlphaOnly(proxy->config())) { |
Brian Osman | 8fa7ab4 | 2019-03-18 10:22:42 -0400 | [diff] [blame] | 212 | color = SkColor4fPrepForDst(paint.getColor4f(), dstInfo).premul(); |
Brian Osman | 3ebd354 | 2018-07-30 14:36:53 -0400 | [diff] [blame] | 213 | } else { |
Brian Osman | 3d139a4 | 2018-11-19 10:42:10 -0500 | [diff] [blame] | 214 | float paintAlpha = paint.getColor4f().fA; |
| 215 | color = { paintAlpha, paintAlpha, paintAlpha, paintAlpha }; |
Brian Osman | 3ebd354 | 2018-07-30 14:36:53 -0400 | [diff] [blame] | 216 | } |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 217 | |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 218 | if (dstClip) { |
| 219 | // Get source coords corresponding to dstClip |
| 220 | SkPoint srcQuad[4]; |
| 221 | GrMapRectPoints(dstRect, srcRect, dstClip, srcQuad, 4); |
Michael Ludwig | 24adb3a | 2019-02-27 19:42:20 +0000 | [diff] [blame] | 222 | |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 223 | rtc->drawTextureQuad(clip, std::move(proxy), filter, paint.getBlendMode(), color, |
| 224 | srcQuad, dstClip, aa, aaFlags, |
| 225 | constraint == SkCanvas::kStrict_SrcRectConstraint ? &srcRect : nullptr, |
| 226 | ctm, std::move(textureXform)); |
| 227 | } else { |
| 228 | rtc->drawTexture(clip, std::move(proxy), filter, paint.getBlendMode(), color, srcRect, |
| 229 | dstRect, aa, aaFlags, constraint, ctm, std::move(textureXform)); |
Michael Ludwig | 24adb3a | 2019-02-27 19:42:20 +0000 | [diff] [blame] | 230 | } |
Michael Ludwig | 24adb3a | 2019-02-27 19:42:20 +0000 | [diff] [blame] | 231 | } |
| 232 | |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 233 | // Assumes srcRect and dstRect have already been optimized to fit the proxy. |
| 234 | static void draw_texture_producer(GrContext* context, GrRenderTargetContext* rtc, |
| 235 | const GrClip& clip, const SkMatrix& ctm, |
| 236 | const SkPaint& paint, GrTextureProducer* producer, |
| 237 | const SkRect& src, const SkRect& dst, const SkPoint dstClip[4], |
| 238 | const SkMatrix& srcToDst, GrAA aa, GrQuadAAFlags aaFlags, |
| 239 | SkCanvas::SrcRectConstraint constraint, bool attemptDrawTexture) { |
Jim Van Verth | 30e0d7f | 2018-11-02 13:36:42 -0400 | [diff] [blame] | 240 | if (attemptDrawTexture && can_use_draw_texture(paint)) { |
Jim Van Verth | 30e0d7f | 2018-11-02 13:36:42 -0400 | [diff] [blame] | 241 | // We've done enough checks above to allow us to pass ClampNearest() and not check for |
| 242 | // scaling adjustments. |
| 243 | auto proxy = producer->refTextureProxyForParams(GrSamplerState::ClampNearest(), nullptr); |
| 244 | if (!proxy) { |
| 245 | return; |
| 246 | } |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 247 | |
| 248 | draw_texture(rtc, clip, ctm, paint, src, dst, dstClip, aa, aaFlags, constraint, |
| 249 | std::move(proxy), producer->alphaType(), producer->colorSpace()); |
Jim Van Verth | 30e0d7f | 2018-11-02 13:36:42 -0400 | [diff] [blame] | 250 | return; |
| 251 | } |
| 252 | |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 253 | const SkMaskFilter* mf = paint.getMaskFilter(); |
Michael Ludwig | b7d64b9 | 2019-02-11 11:09:15 -0500 | [diff] [blame] | 254 | |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 255 | // The shader expects proper local coords, so we can't replace local coords with texture coords |
| 256 | // if the shader will be used. If we have a mask filter we will change the underlying geometry |
| 257 | // that is rendered. |
bsalomon | f1ecd21 | 2015-12-09 17:06:02 -0800 | [diff] [blame] | 258 | bool canUseTextureCoordsAsLocalCoords = !use_shader(producer->isAlphaOnly(), paint) && !mf; |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 259 | |
Michael Ludwig | b7d64b9 | 2019-02-11 11:09:15 -0500 | [diff] [blame] | 260 | // Specifying the texture coords as local coordinates is an attempt to enable more GrDrawOp |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 261 | // combining by not baking anything about the srcRect, dstRect, or ctm, into the texture |
Michael Ludwig | b7d64b9 | 2019-02-11 11:09:15 -0500 | [diff] [blame] | 262 | // FP. In the future this should be an opaque optimization enabled by the combination of |
| 263 | // GrDrawOp/GP and FP. |
| 264 | if (mf && as_MFB(mf)->hasFragmentProcessor()) { |
| 265 | mf = nullptr; |
| 266 | } |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 267 | bool doBicubic; |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 268 | GrSamplerState::Filter fm = GrSkFilterQualityToGrFilterMode( |
Chris Dalton | 309c6c0 | 2019-08-13 10:32:47 -0600 | [diff] [blame] | 269 | producer->width(), producer->height(), paint.getFilterQuality(), ctm, srcToDst, |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 270 | context->priv().options().fSharpenMipmappedTextures, &doBicubic); |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 271 | const GrSamplerState::Filter* filterMode = doBicubic ? nullptr : &fm; |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 272 | |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 273 | GrTextureProducer::FilterConstraint constraintMode; |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 274 | if (SkCanvas::kFast_SrcRectConstraint == constraint) { |
| 275 | constraintMode = GrTextureAdjuster::kNo_FilterConstraint; |
| 276 | } else { |
| 277 | constraintMode = GrTextureAdjuster::kYes_FilterConstraint; |
| 278 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 279 | |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 280 | // If we have to outset for AA then we will generate texture coords outside the src rect. The |
| 281 | // same happens for any mask filter that extends the bounds rendered in the dst. |
| 282 | // This is conservative as a mask filter does not have to expand the bounds rendered. |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 283 | bool coordsAllInsideSrcRect = aaFlags == GrQuadAAFlags::kNone && !mf; |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 284 | |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 285 | // Check for optimization to drop the src rect constraint when on bilerp. |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 286 | if (filterMode && GrSamplerState::Filter::kBilerp == *filterMode && |
Michael Ludwig | a6a8400 | 2019-04-12 15:03:02 -0400 | [diff] [blame] | 287 | GrTextureAdjuster::kYes_FilterConstraint == constraintMode && coordsAllInsideSrcRect && |
| 288 | !producer->hasMixedResolutions()) { |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 289 | SkMatrix combinedMatrix; |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 290 | combinedMatrix.setConcat(ctm, srcToDst); |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 291 | if (can_ignore_bilerp_constraint(*producer, src, combinedMatrix, rtc->numSamples())) { |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 292 | constraintMode = GrTextureAdjuster::kNo_FilterConstraint; |
| 293 | } |
| 294 | } |
| 295 | |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 296 | SkMatrix textureMatrix; |
bsalomon | 3aa5fce | 2015-11-12 09:59:44 -0800 | [diff] [blame] | 297 | if (canUseTextureCoordsAsLocalCoords) { |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 298 | textureMatrix = SkMatrix::I(); |
bsalomon | 3aa5fce | 2015-11-12 09:59:44 -0800 | [diff] [blame] | 299 | } else { |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 300 | if (!srcToDst.invert(&textureMatrix)) { |
bsalomon | 3aa5fce | 2015-11-12 09:59:44 -0800 | [diff] [blame] | 301 | return; |
| 302 | } |
bsalomon | 3aa5fce | 2015-11-12 09:59:44 -0800 | [diff] [blame] | 303 | } |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 304 | auto fp = producer->createFragmentProcessor(textureMatrix, src, constraintMode, |
Brian Osman | 05c8f46 | 2018-10-22 17:13:36 -0400 | [diff] [blame] | 305 | coordsAllInsideSrcRect, filterMode); |
| 306 | fp = GrColorSpaceXformEffect::Make(std::move(fp), producer->colorSpace(), producer->alphaType(), |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 307 | rtc->colorSpaceInfo().colorSpace()); |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 308 | if (!fp) { |
| 309 | return; |
| 310 | } |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 311 | |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 312 | GrPaint grPaint; |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 313 | if (!SkPaintToGrPaintWithTexture(context, rtc->colorSpaceInfo(), paint, ctm, |
| 314 | std::move(fp), producer->isAlphaOnly(), &grPaint)) { |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 315 | return; |
| 316 | } |
| 317 | |
| 318 | if (!mf) { |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 319 | // Can draw the image directly (any mask filter on the paint was converted to an FP already) |
| 320 | if (dstClip) { |
| 321 | SkPoint srcClipPoints[4]; |
| 322 | SkPoint* srcClip = nullptr; |
| 323 | if (canUseTextureCoordsAsLocalCoords) { |
| 324 | // Calculate texture coordinates that match the dst clip |
| 325 | GrMapRectPoints(dst, src, dstClip, srcClipPoints, 4); |
| 326 | srcClip = srcClipPoints; |
| 327 | } |
| 328 | rtc->fillQuadWithEdgeAA(clip, std::move(grPaint), aa, aaFlags, ctm, dstClip, srcClip); |
| 329 | } else { |
| 330 | // Provide explicit texture coords when possible, otherwise rely on texture matrix |
| 331 | rtc->fillRectWithEdgeAA(clip, std::move(grPaint), aa, aaFlags, ctm, dst, |
| 332 | canUseTextureCoordsAsLocalCoords ? &src : nullptr); |
| 333 | } |
| 334 | } else { |
| 335 | // Must draw the mask filter as a GrShape. For now, this loses the per-edge AA information |
| 336 | // since it always draws with AA, but that is should not be noticeable since the mask filter |
| 337 | // is probably a blur. |
| 338 | GrShape shape; |
| 339 | if (dstClip) { |
| 340 | // Represent it as an SkPath formed from the dstClip |
| 341 | SkPath path; |
| 342 | path.addPoly(dstClip, 4, true); |
| 343 | shape = GrShape(path); |
| 344 | } else { |
| 345 | shape = GrShape(dst); |
| 346 | } |
| 347 | |
| 348 | GrBlurUtils::drawShapeWithMaskFilter( |
| 349 | context, rtc, clip, shape, std::move(grPaint), ctm, mf); |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | } // anonymous namespace |
| 354 | |
| 355 | ////////////////////////////////////////////////////////////////////////////// |
| 356 | |
| 357 | void SkGpuDevice::drawImageQuad(const SkImage* image, const SkRect* srcRect, const SkRect* dstRect, |
| 358 | const SkPoint dstClip[4], GrAA aa, GrQuadAAFlags aaFlags, |
Michael Ludwig | 7ae2ab5 | 2019-03-05 16:00:20 -0500 | [diff] [blame] | 359 | const SkMatrix* preViewMatrix, const SkPaint& paint, |
| 360 | SkCanvas::SrcRectConstraint constraint) { |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 361 | SkRect src; |
| 362 | SkRect dst; |
| 363 | SkMatrix srcToDst; |
| 364 | ImageDrawMode mode = optimize_sample_area(SkISize::Make(image->width(), image->height()), |
| 365 | srcRect, dstRect, dstClip, &src, &dst, &srcToDst); |
| 366 | if (mode == ImageDrawMode::kSkip) { |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 367 | return; |
| 368 | } |
| 369 | |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 370 | if (src.contains(image->bounds())) { |
| 371 | constraint = SkCanvas::kFast_SrcRectConstraint; |
| 372 | } |
| 373 | // Depending on the nature of image, it can flow through more or less optimal pipelines |
| 374 | bool useDecal = mode == ImageDrawMode::kDecal; |
| 375 | bool attemptDrawTexture = !useDecal; // rtc->drawTexture() only clamps |
Robert Phillips | 27927a5 | 2018-08-20 13:18:12 -0400 | [diff] [blame] | 376 | |
Michael Ludwig | 7ae2ab5 | 2019-03-05 16:00:20 -0500 | [diff] [blame] | 377 | // Get final CTM matrix |
| 378 | SkMatrix ctm = this->ctm(); |
| 379 | if (preViewMatrix) { |
| 380 | ctm.preConcat(*preViewMatrix); |
| 381 | } |
| 382 | |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 383 | // YUVA images can be stored in multiple images with different plane resolutions, so this |
| 384 | // uses an effect to combine them dynamically on the GPU. This is done before requesting a |
| 385 | // pinned texture proxy because YUV images force-flatten to RGBA in that scenario. |
| 386 | if (as_IB(image)->isYUVA()) { |
| 387 | SK_HISTOGRAM_BOOLEAN("DrawTiled", false); |
Michael Ludwig | 7ae2ab5 | 2019-03-05 16:00:20 -0500 | [diff] [blame] | 388 | LogDrawScaleFactor(ctm, srcToDst, paint.getFilterQuality()); |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 389 | |
| 390 | GrYUVAImageTextureMaker maker(fContext.get(), image, useDecal); |
Michael Ludwig | 7ae2ab5 | 2019-03-05 16:00:20 -0500 | [diff] [blame] | 391 | draw_texture_producer(fContext.get(), fRenderTargetContext.get(), this->clip(), ctm, |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 392 | paint, &maker, src, dst, dstClip, srcToDst, aa, aaFlags, constraint, |
| 393 | /* attempt draw texture */ false); |
| 394 | return; |
| 395 | } |
| 396 | |
| 397 | // Pinned texture proxies can be rendered directly as textures, or with relatively simple |
| 398 | // adjustments applied to the image content (scaling, mipmaps, color space, etc.) |
| 399 | uint32_t pinnedUniqueID; |
Robert Phillips | 6603a17 | 2019-03-05 12:35:44 -0500 | [diff] [blame] | 400 | if (sk_sp<GrTextureProxy> proxy = as_IB(image)->refPinnedTextureProxy(this->context(), |
| 401 | &pinnedUniqueID)) { |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 402 | SK_HISTOGRAM_BOOLEAN("DrawTiled", false); |
Michael Ludwig | 7ae2ab5 | 2019-03-05 16:00:20 -0500 | [diff] [blame] | 403 | LogDrawScaleFactor(ctm, srcToDst, paint.getFilterQuality()); |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 404 | |
| 405 | SkAlphaType alphaType = image->alphaType(); |
| 406 | SkColorSpace* colorSpace = as_IB(image)->colorSpace(); |
| 407 | |
| 408 | if (attemptDrawTexture && can_use_draw_texture(paint)) { |
Michael Ludwig | 7ae2ab5 | 2019-03-05 16:00:20 -0500 | [diff] [blame] | 409 | draw_texture(fRenderTargetContext.get(), this->clip(), ctm, paint, src, dst, |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 410 | dstClip, aa, aaFlags, constraint, std::move(proxy), alphaType, colorSpace); |
| 411 | return; |
| 412 | } |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 413 | auto colorType = SkColorTypeToGrColorType(image->colorType()); |
| 414 | GrTextureAdjuster adjuster(fContext.get(), std::move(proxy), colorType, alphaType, |
| 415 | pinnedUniqueID, colorSpace, useDecal); |
Michael Ludwig | 7ae2ab5 | 2019-03-05 16:00:20 -0500 | [diff] [blame] | 416 | draw_texture_producer(fContext.get(), fRenderTargetContext.get(), this->clip(), ctm, |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 417 | paint, &adjuster, src, dst, dstClip, srcToDst, aa, aaFlags, |
| 418 | constraint, /* attempt draw_texture */ false); |
| 419 | return; |
| 420 | } |
| 421 | |
| 422 | // Next up, try tiling the image |
| 423 | // TODO (michaelludwig): Implement this with per-edge AA flags to handle seaming properly |
| 424 | // instead of going through drawBitmapRect (which will be removed from SkDevice in the future) |
| 425 | SkBitmap bm; |
Michael Ludwig | 7ae2ab5 | 2019-03-05 16:00:20 -0500 | [diff] [blame] | 426 | if (this->shouldTileImage(image, &src, constraint, paint.getFilterQuality(), ctm, srcToDst)) { |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 427 | // only support tiling as bitmap at the moment, so force raster-version |
| 428 | if (!as_IB(image)->getROPixels(&bm)) { |
| 429 | return; |
| 430 | } |
| 431 | this->drawBitmapRect(bm, &src, dst, paint, constraint); |
| 432 | return; |
| 433 | } |
| 434 | |
| 435 | // This is the funnel for all non-tiled bitmap/image draw calls. Log a histogram entry. |
| 436 | SK_HISTOGRAM_BOOLEAN("DrawTiled", false); |
Michael Ludwig | 7ae2ab5 | 2019-03-05 16:00:20 -0500 | [diff] [blame] | 437 | LogDrawScaleFactor(ctm, srcToDst, paint.getFilterQuality()); |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 438 | |
| 439 | // Lazily generated images must get drawn as a texture producer that handles the final |
| 440 | // texture creation. |
| 441 | if (image->isLazyGenerated()) { |
| 442 | GrImageTextureMaker maker(fContext.get(), image, SkImage::kAllow_CachingHint, useDecal); |
Michael Ludwig | 7ae2ab5 | 2019-03-05 16:00:20 -0500 | [diff] [blame] | 443 | draw_texture_producer(fContext.get(), fRenderTargetContext.get(), this->clip(), ctm, |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 444 | paint, &maker, src, dst, dstClip, srcToDst, aa, aaFlags, constraint, |
| 445 | attemptDrawTexture); |
| 446 | return; |
| 447 | } |
| 448 | if (as_IB(image)->getROPixels(&bm)) { |
| 449 | GrBitmapTextureMaker maker(fContext.get(), bm, useDecal); |
Michael Ludwig | 7ae2ab5 | 2019-03-05 16:00:20 -0500 | [diff] [blame] | 450 | draw_texture_producer(fContext.get(), fRenderTargetContext.get(), this->clip(), ctm, |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 451 | paint, &maker, src, dst, dstClip, srcToDst, aa, aaFlags, constraint, |
| 452 | attemptDrawTexture); |
| 453 | } |
| 454 | |
| 455 | // Otherwise don't know how to draw it |
| 456 | } |
| 457 | |
Michael Ludwig | 390f0cc | 2019-03-19 09:16:38 -0400 | [diff] [blame] | 458 | void SkGpuDevice::drawEdgeAAImageSet(const SkCanvas::ImageSetEntry set[], int count, |
| 459 | const SkPoint dstClips[], const SkMatrix preViewMatrices[], |
| 460 | const SkPaint& paint, SkCanvas::SrcRectConstraint constraint) { |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 461 | SkASSERT(count > 0); |
Michael Ludwig | 31ba718 | 2019-04-03 10:38:06 -0400 | [diff] [blame] | 462 | if (!can_use_draw_texture(paint)) { |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 463 | // Send every entry through drawImageQuad() to handle the more complicated paint |
| 464 | int dstClipIndex = 0; |
| 465 | for (int i = 0; i < count; ++i) { |
| 466 | // Only no clip or quad clip are supported |
Michael Ludwig | 390f0cc | 2019-03-19 09:16:38 -0400 | [diff] [blame] | 467 | SkASSERT(!set[i].fHasClip || dstClips); |
| 468 | SkASSERT(set[i].fMatrixIndex < 0 || preViewMatrices); |
Michael Ludwig | 7ae2ab5 | 2019-03-05 16:00:20 -0500 | [diff] [blame] | 469 | |
Brian Salomon | db151e0 | 2019-09-17 12:11:16 -0400 | [diff] [blame] | 470 | SkTCopyOnFirstWrite<SkPaint> entryPaint(paint); |
| 471 | if (set[i].fAlpha != 1.f) { |
| 472 | auto paintAlpha = paint.getAlphaf(); |
| 473 | entryPaint.writable()->setAlphaf(paintAlpha * set[i].fAlpha); |
| 474 | } |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 475 | // Always send GrAA::kYes to preserve seaming across tiling in MSAA |
Brian Salomon | db151e0 | 2019-09-17 12:11:16 -0400 | [diff] [blame] | 476 | this->drawImageQuad( |
| 477 | set[i].fImage.get(), &set[i].fSrcRect, &set[i].fDstRect, |
| 478 | set[i].fHasClip ? dstClips + dstClipIndex : nullptr, GrAA::kYes, |
| 479 | SkToGrQuadAAFlags(set[i].fAAFlags), |
Michael Ludwig | 390f0cc | 2019-03-19 09:16:38 -0400 | [diff] [blame] | 480 | set[i].fMatrixIndex < 0 ? nullptr : preViewMatrices + set[i].fMatrixIndex, |
Brian Salomon | db151e0 | 2019-09-17 12:11:16 -0400 | [diff] [blame] | 481 | *entryPaint, constraint); |
Michael Ludwig | 390f0cc | 2019-03-19 09:16:38 -0400 | [diff] [blame] | 482 | dstClipIndex += 4 * set[i].fHasClip; |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 483 | } |
| 484 | return; |
| 485 | } |
| 486 | |
| 487 | GrSamplerState::Filter filter = kNone_SkFilterQuality == paint.getFilterQuality() ? |
| 488 | GrSamplerState::Filter::kNearest : GrSamplerState::Filter::kBilerp; |
| 489 | SkBlendMode mode = paint.getBlendMode(); |
| 490 | |
| 491 | SkAutoTArray<GrRenderTargetContext::TextureSetEntry> textures(count); |
| 492 | // We accumulate compatible proxies until we find an an incompatible one or reach the end and |
| 493 | // issue the accumulated 'n' draws starting at 'base'. |
| 494 | int base = 0, n = 0; |
| 495 | auto draw = [&] { |
| 496 | if (n > 0) { |
| 497 | auto textureXform = GrColorSpaceXform::Make( |
| 498 | set[base].fImage->colorSpace(), set[base].fImage->alphaType(), |
| 499 | fRenderTargetContext->colorSpaceInfo().colorSpace(), kPremul_SkAlphaType); |
| 500 | fRenderTargetContext->drawTextureSet(this->clip(), textures.get() + base, n, |
Michael Ludwig | 31ba718 | 2019-04-03 10:38:06 -0400 | [diff] [blame] | 501 | filter, mode, GrAA::kYes, constraint, this->ctm(), |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 502 | std::move(textureXform)); |
| 503 | } |
| 504 | }; |
| 505 | int dstClipIndex = 0; |
| 506 | for (int i = 0; i < count; ++i) { |
Michael Ludwig | d9958f8 | 2019-03-21 13:08:36 -0400 | [diff] [blame] | 507 | SkASSERT(!set[i].fHasClip || dstClips); |
| 508 | SkASSERT(set[i].fMatrixIndex < 0 || preViewMatrices); |
| 509 | |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 510 | // Manage the dst clip pointer tracking before any continues are used so we don't lose |
| 511 | // our place in the dstClips array. |
Michael Ludwig | 390f0cc | 2019-03-19 09:16:38 -0400 | [diff] [blame] | 512 | const SkPoint* clip = set[i].fHasClip ? dstClips + dstClipIndex : nullptr; |
| 513 | dstClipIndex += 4 * set[i].fHasClip; |
| 514 | |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 515 | // The default SkBaseDevice implementation is based on drawImageRect which does not allow |
| 516 | // non-sorted src rects. TODO: Decide this is OK or make sure we handle it. |
| 517 | if (!set[i].fSrcRect.isSorted()) { |
| 518 | draw(); |
| 519 | base = i + 1; |
| 520 | n = 0; |
| 521 | continue; |
| 522 | } |
| 523 | |
Michael Ludwig | d9958f8 | 2019-03-21 13:08:36 -0400 | [diff] [blame] | 524 | sk_sp<GrTextureProxy> proxy; |
| 525 | const SkImage_Base* image = as_IB(set[i].fImage.get()); |
| 526 | // Extract proxy from image, but skip YUV images so they get processed through |
| 527 | // drawImageQuad and the proper effect to dynamically sample their planes. |
| 528 | if (!image->isYUVA()) { |
| 529 | uint32_t uniqueID; |
| 530 | proxy = image->refPinnedTextureProxy(this->context(), &uniqueID); |
| 531 | if (!proxy) { |
| 532 | proxy = image->asTextureProxyRef(this->context(), GrSamplerState::ClampBilerp(), |
| 533 | nullptr); |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 534 | } |
| 535 | } |
Michael Ludwig | 7ae2ab5 | 2019-03-05 16:00:20 -0500 | [diff] [blame] | 536 | |
Michael Ludwig | d9958f8 | 2019-03-21 13:08:36 -0400 | [diff] [blame] | 537 | if (!proxy) { |
| 538 | // This image can't go through the texture op, send through general image pipeline |
| 539 | // after flushing current batch. |
| 540 | draw(); |
| 541 | base = i + 1; |
| 542 | n = 0; |
Brian Salomon | db151e0 | 2019-09-17 12:11:16 -0400 | [diff] [blame] | 543 | SkTCopyOnFirstWrite<SkPaint> entryPaint(paint); |
| 544 | if (set[i].fAlpha != 1.f) { |
| 545 | auto paintAlpha = paint.getAlphaf(); |
| 546 | entryPaint.writable()->setAlphaf(paintAlpha * set[i].fAlpha); |
| 547 | } |
| 548 | this->drawImageQuad( |
| 549 | image, &set[i].fSrcRect, &set[i].fDstRect, clip, GrAA::kYes, |
Michael Ludwig | d9958f8 | 2019-03-21 13:08:36 -0400 | [diff] [blame] | 550 | SkToGrQuadAAFlags(set[i].fAAFlags), |
| 551 | set[i].fMatrixIndex < 0 ? nullptr : preViewMatrices + set[i].fMatrixIndex, |
Brian Salomon | db151e0 | 2019-09-17 12:11:16 -0400 | [diff] [blame] | 552 | *entryPaint, constraint); |
Michael Ludwig | d9958f8 | 2019-03-21 13:08:36 -0400 | [diff] [blame] | 553 | continue; |
| 554 | } |
Michael Ludwig | 7ae2ab5 | 2019-03-05 16:00:20 -0500 | [diff] [blame] | 555 | |
Michael Ludwig | d9958f8 | 2019-03-21 13:08:36 -0400 | [diff] [blame] | 556 | textures[i].fProxy = std::move(proxy); |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 557 | textures[i].fSrcRect = set[i].fSrcRect; |
| 558 | textures[i].fDstRect = set[i].fDstRect; |
| 559 | textures[i].fDstClipQuad = clip; |
Michael Ludwig | 390f0cc | 2019-03-19 09:16:38 -0400 | [diff] [blame] | 560 | textures[i].fPreViewMatrix = |
| 561 | set[i].fMatrixIndex < 0 ? nullptr : preViewMatrices + set[i].fMatrixIndex; |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 562 | textures[i].fAlpha = set[i].fAlpha * paint.getAlphaf(); |
| 563 | textures[i].fAAFlags = SkToGrQuadAAFlags(set[i].fAAFlags); |
| 564 | |
| 565 | if (n > 0 && |
| 566 | (!GrTextureProxy::ProxiesAreCompatibleAsDynamicState(textures[i].fProxy.get(), |
| 567 | textures[base].fProxy.get()) || |
| 568 | set[i].fImage->alphaType() != set[base].fImage->alphaType() || |
| 569 | !SkColorSpace::Equals(set[i].fImage->colorSpace(), set[base].fImage->colorSpace()))) { |
| 570 | draw(); |
| 571 | base = i; |
| 572 | n = 1; |
| 573 | } else { |
| 574 | ++n; |
| 575 | } |
| 576 | } |
| 577 | draw(); |
| 578 | } |
| 579 | |
| 580 | // TODO (michaelludwig) - to be removed when drawBitmapRect doesn't need it anymore |
| 581 | void SkGpuDevice::drawTextureProducer(GrTextureProducer* producer, |
| 582 | const SkRect* srcRect, |
| 583 | const SkRect* dstRect, |
| 584 | SkCanvas::SrcRectConstraint constraint, |
| 585 | const SkMatrix& viewMatrix, |
| 586 | const SkPaint& paint, |
| 587 | bool attemptDrawTexture) { |
| 588 | // The texture refactor split the old logic of drawTextureProducer into the beginning of |
| 589 | // drawImageQuad() and into the static draw_texture_producer. Replicate necessary logic that |
| 590 | // drawImageQuad() handles. |
| 591 | SkRect src; |
| 592 | SkRect dst; |
| 593 | SkMatrix srcToDst; |
| 594 | ImageDrawMode mode = optimize_sample_area(SkISize::Make(producer->width(), producer->height()), |
| 595 | srcRect, dstRect, nullptr, &src, &dst, &srcToDst); |
| 596 | if (mode == ImageDrawMode::kSkip) { |
| 597 | return; |
| 598 | } |
| 599 | // There's no dstClip to worry about and the producer is already made so we wouldn't be able |
| 600 | // to tell it to use decals if we had to |
| 601 | SkASSERT(mode != ImageDrawMode::kDecal); |
| 602 | |
| 603 | draw_texture_producer(fContext.get(), fRenderTargetContext.get(), this->clip(), viewMatrix, |
| 604 | paint, producer, src, dst, /* clip */ nullptr, srcToDst, |
| 605 | GrAA(paint.isAntiAlias()), |
| 606 | paint.isAntiAlias() ? GrQuadAAFlags::kAll : GrQuadAAFlags::kNone, |
| 607 | constraint, attemptDrawTexture); |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 608 | } |