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" |
Brian Salomon | b8f098d | 2020-01-07 11:15:44 -0500 | [diff] [blame] | 25 | #include "src/gpu/effects/GrTextureEffect.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 | dd86fb3 | 2020-03-10 09:55:35 -0400 | [diff] [blame^] | 97 | ////////////////////////////////////////////////////////////////////////////// |
| 98 | // Helper functions for tiling a large SkBitmap |
| 99 | |
| 100 | static const int kBmpSmallTileSize = 1 << 10; |
| 101 | |
| 102 | static inline int get_tile_count(const SkIRect& srcRect, int tileSize) { |
| 103 | int tilesX = (srcRect.fRight / tileSize) - (srcRect.fLeft / tileSize) + 1; |
| 104 | int tilesY = (srcRect.fBottom / tileSize) - (srcRect.fTop / tileSize) + 1; |
| 105 | return tilesX * tilesY; |
| 106 | } |
| 107 | |
| 108 | static int determine_tile_size(const SkIRect& src, int maxTileSize) { |
| 109 | if (maxTileSize <= kBmpSmallTileSize) { |
| 110 | return maxTileSize; |
| 111 | } |
| 112 | |
| 113 | size_t maxTileTotalTileSize = get_tile_count(src, maxTileSize); |
| 114 | size_t smallTotalTileSize = get_tile_count(src, kBmpSmallTileSize); |
| 115 | |
| 116 | maxTileTotalTileSize *= maxTileSize * maxTileSize; |
| 117 | smallTotalTileSize *= kBmpSmallTileSize * kBmpSmallTileSize; |
| 118 | |
| 119 | if (maxTileTotalTileSize > 2 * smallTotalTileSize) { |
| 120 | return kBmpSmallTileSize; |
| 121 | } else { |
| 122 | return maxTileSize; |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | // Given a bitmap, an optional src rect, and a context with a clip and matrix determine what |
| 127 | // pixels from the bitmap are necessary. |
| 128 | static void determine_clipped_src_rect(int width, int height, |
| 129 | const GrClip& clip, |
| 130 | const SkMatrix& viewMatrix, |
| 131 | const SkMatrix& srcToDstRect, |
| 132 | const SkISize& imageDimensions, |
| 133 | const SkRect* srcRectPtr, |
| 134 | SkIRect* clippedSrcIRect) { |
| 135 | clip.getConservativeBounds(width, height, clippedSrcIRect, nullptr); |
| 136 | SkMatrix inv = SkMatrix::Concat(viewMatrix, srcToDstRect); |
| 137 | if (!inv.invert(&inv)) { |
| 138 | clippedSrcIRect->setEmpty(); |
| 139 | return; |
| 140 | } |
| 141 | SkRect clippedSrcRect = SkRect::Make(*clippedSrcIRect); |
| 142 | inv.mapRect(&clippedSrcRect); |
| 143 | if (srcRectPtr) { |
| 144 | if (!clippedSrcRect.intersect(*srcRectPtr)) { |
| 145 | clippedSrcIRect->setEmpty(); |
| 146 | return; |
| 147 | } |
| 148 | } |
| 149 | clippedSrcRect.roundOut(clippedSrcIRect); |
| 150 | SkIRect bmpBounds = SkIRect::MakeSize(imageDimensions); |
| 151 | if (!clippedSrcIRect->intersect(bmpBounds)) { |
| 152 | clippedSrcIRect->setEmpty(); |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | } // temporary anonymous namespace boundary before shouldTileImageID is removed from SkGPUDevice |
| 157 | |
| 158 | bool SkGpuDevice::shouldTileImageID(uint32_t imageID, |
| 159 | const SkIRect& imageRect, |
| 160 | const SkMatrix& viewMatrix, |
| 161 | const SkMatrix& srcToDstRect, |
| 162 | const SkRect* srcRectPtr, |
| 163 | int maxTileSize, |
| 164 | int* tileSize, |
| 165 | SkIRect* clippedSubset) const { |
| 166 | // if it's larger than the max tile size, then we have no choice but tiling. |
| 167 | if (imageRect.width() > maxTileSize || imageRect.height() > maxTileSize) { |
| 168 | determine_clipped_src_rect(fRenderTargetContext->width(), fRenderTargetContext->height(), |
| 169 | this->clip(), viewMatrix, srcToDstRect, imageRect.size(), |
| 170 | srcRectPtr, clippedSubset); |
| 171 | *tileSize = determine_tile_size(*clippedSubset, maxTileSize); |
| 172 | return true; |
| 173 | } |
| 174 | |
| 175 | // If the image would only produce 4 tiles of the smaller size, don't bother tiling it. |
| 176 | const size_t area = imageRect.width() * imageRect.height(); |
| 177 | if (area < 4 * kBmpSmallTileSize * kBmpSmallTileSize) { |
| 178 | return false; |
| 179 | } |
| 180 | |
| 181 | // At this point we know we could do the draw by uploading the entire bitmap |
| 182 | // as a texture. However, if the texture would be large compared to the |
| 183 | // cache size and we don't require most of it for this draw then tile to |
| 184 | // reduce the amount of upload and cache spill. |
| 185 | |
| 186 | // assumption here is that sw bitmap size is a good proxy for its size as |
| 187 | // a texture |
| 188 | size_t bmpSize = area * sizeof(SkPMColor); // assume 32bit pixels |
| 189 | size_t cacheSize = fContext->getResourceCacheLimit(); |
| 190 | if (bmpSize < cacheSize / 2) { |
| 191 | return false; |
| 192 | } |
| 193 | |
| 194 | // Figure out how much of the src we will need based on the src rect and clipping. Reject if |
| 195 | // tiling memory savings would be < 50%. |
| 196 | determine_clipped_src_rect(fRenderTargetContext->width(), fRenderTargetContext->height(), |
| 197 | this->clip(), viewMatrix, srcToDstRect, imageRect.size(), srcRectPtr, |
| 198 | clippedSubset); |
| 199 | *tileSize = kBmpSmallTileSize; // already know whole bitmap fits in one max sized tile. |
| 200 | size_t usedTileBytes = get_tile_count(*clippedSubset, kBmpSmallTileSize) * |
| 201 | kBmpSmallTileSize * kBmpSmallTileSize * |
| 202 | sizeof(SkPMColor); // assume 32bit pixels; |
| 203 | |
| 204 | return usedTileBytes * 2 < bmpSize; |
| 205 | } |
| 206 | |
| 207 | bool SkGpuDevice::shouldTileImage(const SkImage* image, const SkRect* srcRectPtr, |
| 208 | SkCanvas::SrcRectConstraint constraint, SkFilterQuality quality, |
| 209 | const SkMatrix& viewMatrix, |
| 210 | const SkMatrix& srcToDstRect) const { |
| 211 | // If image is explicitly texture backed then we shouldn't get here. |
| 212 | SkASSERT(!image->isTextureBacked()); |
| 213 | |
| 214 | bool doBicubic; |
| 215 | GrSamplerState::Filter textureFilterMode = GrSkFilterQualityToGrFilterMode( |
| 216 | image->width(), image->height(), quality, viewMatrix, srcToDstRect, |
| 217 | fContext->priv().options().fSharpenMipmappedTextures, &doBicubic); |
| 218 | |
| 219 | int tileFilterPad; |
| 220 | if (doBicubic) { |
| 221 | tileFilterPad = GrBicubicEffect::kFilterTexelPad; |
| 222 | } else if (GrSamplerState::Filter::kNearest == textureFilterMode) { |
| 223 | tileFilterPad = 0; |
| 224 | } else { |
| 225 | tileFilterPad = 1; |
| 226 | } |
| 227 | |
| 228 | int maxTileSize = this->caps()->maxTileSize() - 2 * tileFilterPad; |
| 229 | |
| 230 | // these are output, which we safely ignore, as we just want to know the predicate |
| 231 | int outTileSize; |
| 232 | SkIRect outClippedSrcRect; |
| 233 | |
| 234 | return this->shouldTileImageID(image->unique(), image->bounds(), viewMatrix, srcToDstRect, |
| 235 | srcRectPtr, maxTileSize, &outTileSize, &outClippedSrcRect); |
| 236 | } |
| 237 | |
| 238 | namespace { |
| 239 | |
| 240 | // This method outsets 'iRect' by 'outset' all around and then clamps its extents to |
| 241 | // 'clamp'. 'offset' is adjusted to remain positioned over the top-left corner |
| 242 | // of 'iRect' for all possible outsets/clamps. |
| 243 | static inline void clamped_outset_with_offset(SkIRect* iRect, |
| 244 | int outset, |
| 245 | SkPoint* offset, |
| 246 | const SkIRect& clamp) { |
| 247 | iRect->outset(outset, outset); |
| 248 | |
| 249 | int leftClampDelta = clamp.fLeft - iRect->fLeft; |
| 250 | if (leftClampDelta > 0) { |
| 251 | offset->fX -= outset - leftClampDelta; |
| 252 | iRect->fLeft = clamp.fLeft; |
| 253 | } else { |
| 254 | offset->fX -= outset; |
| 255 | } |
| 256 | |
| 257 | int topClampDelta = clamp.fTop - iRect->fTop; |
| 258 | if (topClampDelta > 0) { |
| 259 | offset->fY -= outset - topClampDelta; |
| 260 | iRect->fTop = clamp.fTop; |
| 261 | } else { |
| 262 | offset->fY -= outset; |
| 263 | } |
| 264 | |
| 265 | if (iRect->fRight > clamp.fRight) { |
| 266 | iRect->fRight = clamp.fRight; |
| 267 | } |
| 268 | if (iRect->fBottom > clamp.fBottom) { |
| 269 | iRect->fBottom = clamp.fBottom; |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | ////////////////////////////////////////////////////////////////////////////// |
| 274 | // Helper functions for drawing an image with GrRenderTargetContext |
| 275 | |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 276 | enum class ImageDrawMode { |
| 277 | // Src and dst have been restricted to the image content. May need to clamp, no need to decal. |
| 278 | kOptimized, |
| 279 | // Src and dst are their original sizes, requires use of a decal instead of plain clamping. |
| 280 | // This is used when a dst clip is provided and extends outside of the optimized dst rect. |
| 281 | kDecal, |
| 282 | // Src or dst are empty, or do not intersect the image content so don't draw anything. |
| 283 | kSkip |
| 284 | }; |
| 285 | |
| 286 | /** |
| 287 | * Optimize the src rect sampling area within an image (sized 'width' x 'height') such that |
| 288 | * 'outSrcRect' will be completely contained in the image's bounds. The corresponding rect |
| 289 | * to draw will be output to 'outDstRect'. The mapping between src and dst will be cached in |
| 290 | * 'srcToDst'. Outputs are not always updated when kSkip is returned. |
| 291 | * |
| 292 | * If 'origSrcRect' is null, implicitly use the image bounds. If 'origDstRect' is null, use the |
| 293 | * original src rect. 'dstClip' should be null when there is no additional clipping. |
| 294 | */ |
| 295 | static ImageDrawMode optimize_sample_area(const SkISize& image, const SkRect* origSrcRect, |
| 296 | const SkRect* origDstRect, const SkPoint dstClip[4], |
| 297 | SkRect* outSrcRect, SkRect* outDstRect, |
| 298 | SkMatrix* srcToDst) { |
| 299 | SkRect srcBounds = SkRect::MakeIWH(image.fWidth, image.fHeight); |
| 300 | |
| 301 | SkRect src = origSrcRect ? *origSrcRect : srcBounds; |
| 302 | SkRect dst = origDstRect ? *origDstRect : src; |
| 303 | |
| 304 | if (src.isEmpty() || dst.isEmpty()) { |
| 305 | return ImageDrawMode::kSkip; |
| 306 | } |
| 307 | |
| 308 | if (outDstRect) { |
| 309 | srcToDst->setRectToRect(src, dst, SkMatrix::kFill_ScaleToFit); |
| 310 | } else { |
| 311 | srcToDst->setIdentity(); |
| 312 | } |
| 313 | |
| 314 | if (origSrcRect && !srcBounds.contains(src)) { |
| 315 | if (!src.intersect(srcBounds)) { |
| 316 | return ImageDrawMode::kSkip; |
| 317 | } |
| 318 | srcToDst->mapRect(&dst, src); |
| 319 | |
| 320 | // Both src and dst have gotten smaller. If dstClip is provided, confirm it is still |
| 321 | // contained in dst, otherwise cannot optimize the sample area and must use a decal instead |
| 322 | if (dstClip) { |
| 323 | for (int i = 0; i < 4; ++i) { |
| 324 | if (!dst.contains(dstClip[i].fX, dstClip[i].fY)) { |
| 325 | // Must resort to using a decal mode restricted to the clipped 'src', and |
| 326 | // use the original dst rect (filling in src bounds as needed) |
| 327 | *outSrcRect = src; |
| 328 | *outDstRect = (origDstRect ? *origDstRect |
| 329 | : (origSrcRect ? *origSrcRect : srcBounds)); |
| 330 | return ImageDrawMode::kDecal; |
| 331 | } |
| 332 | } |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | // The original src and dst were fully contained in the image, or there was no dst clip to |
| 337 | // worry about, or the clip was still contained in the restricted dst rect. |
| 338 | *outSrcRect = src; |
| 339 | *outDstRect = dst; |
| 340 | return ImageDrawMode::kOptimized; |
| 341 | } |
| 342 | |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 343 | /** |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 344 | * Checks whether the paint is compatible with using GrRenderTargetContext::drawTexture. It is more |
| 345 | * efficient than the GrTextureProducer general case. |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 346 | */ |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 347 | static bool can_use_draw_texture(const SkPaint& paint) { |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 348 | return (!paint.getColorFilter() && !paint.getShader() && !paint.getMaskFilter() && |
Michael Ludwig | d54ca8f | 2019-02-13 13:25:21 -0500 | [diff] [blame] | 349 | !paint.getImageFilter() && paint.getFilterQuality() < kMedium_SkFilterQuality); |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 350 | } |
| 351 | |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 352 | // Assumes srcRect and dstRect have already been optimized to fit the proxy |
| 353 | static void draw_texture(GrRenderTargetContext* rtc, const GrClip& clip, const SkMatrix& ctm, |
| 354 | const SkPaint& paint, const SkRect& srcRect, const SkRect& dstRect, |
| 355 | const SkPoint dstClip[4], GrAA aa, GrQuadAAFlags aaFlags, |
Greg Daniel | 2f3cd4f | 2020-02-07 11:07:25 -0500 | [diff] [blame] | 356 | SkCanvas::SrcRectConstraint constraint, GrSurfaceProxyView view, |
Greg Daniel | a4828a1 | 2019-10-11 13:51:02 -0400 | [diff] [blame] | 357 | const GrColorInfo& srcColorInfo) { |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 358 | const GrColorInfo& dstInfo(rtc->colorInfo()); |
Mike Klein | e03a176 | 2018-08-22 11:52:16 -0400 | [diff] [blame] | 359 | auto textureXform = |
Greg Daniel | a4828a1 | 2019-10-11 13:51:02 -0400 | [diff] [blame] | 360 | GrColorSpaceXform::Make(srcColorInfo.colorSpace(), srcColorInfo.alphaType(), |
Brian Osman | 3d139a4 | 2018-11-19 10:42:10 -0500 | [diff] [blame] | 361 | dstInfo.colorSpace(), kPremul_SkAlphaType); |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 362 | GrSamplerState::Filter filter; |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 363 | switch (paint.getFilterQuality()) { |
| 364 | case kNone_SkFilterQuality: |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 365 | filter = GrSamplerState::Filter::kNearest; |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 366 | break; |
| 367 | case kLow_SkFilterQuality: |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 368 | filter = GrSamplerState::Filter::kBilerp; |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 369 | break; |
| 370 | case kMedium_SkFilterQuality: |
| 371 | case kHigh_SkFilterQuality: |
| 372 | SK_ABORT("Quality level not allowed."); |
| 373 | } |
Greg Daniel | 2f3cd4f | 2020-02-07 11:07:25 -0500 | [diff] [blame] | 374 | GrSurfaceProxy* proxy = view.proxy(); |
Michael Ludwig | d54ca8f | 2019-02-13 13:25:21 -0500 | [diff] [blame] | 375 | // Must specify the strict constraint when the proxy is not functionally exact and the src |
| 376 | // rect would access pixels outside the proxy's content area without the constraint. |
Brian Salomon | 5c60b75 | 2019-12-13 15:03:43 -0500 | [diff] [blame] | 377 | if (constraint != SkCanvas::kStrict_SrcRectConstraint && !proxy->isFunctionallyExact()) { |
Michael Ludwig | d54ca8f | 2019-02-13 13:25:21 -0500 | [diff] [blame] | 378 | // Conservative estimate of how much a coord could be outset from src rect: |
| 379 | // 1/2 pixel for AA and 1/2 pixel for bilerp |
| 380 | float buffer = 0.5f * (aa == GrAA::kYes) + |
| 381 | 0.5f * (filter == GrSamplerState::Filter::kBilerp); |
Brian Salomon | 9f2b86c | 2019-10-22 10:37:46 -0400 | [diff] [blame] | 382 | SkRect safeBounds = proxy->getBoundsRect(); |
Michael Ludwig | d54ca8f | 2019-02-13 13:25:21 -0500 | [diff] [blame] | 383 | safeBounds.inset(buffer, buffer); |
| 384 | if (!safeBounds.contains(srcRect)) { |
| 385 | constraint = SkCanvas::kStrict_SrcRectConstraint; |
| 386 | } |
| 387 | } |
Brian Osman | 3d139a4 | 2018-11-19 10:42:10 -0500 | [diff] [blame] | 388 | SkPMColor4f color; |
Greg Daniel | a4828a1 | 2019-10-11 13:51:02 -0400 | [diff] [blame] | 389 | if (GrColorTypeIsAlphaOnly(srcColorInfo.colorType())) { |
Brian Osman | 8fa7ab4 | 2019-03-18 10:22:42 -0400 | [diff] [blame] | 390 | color = SkColor4fPrepForDst(paint.getColor4f(), dstInfo).premul(); |
Brian Osman | 3ebd354 | 2018-07-30 14:36:53 -0400 | [diff] [blame] | 391 | } else { |
Brian Osman | 3d139a4 | 2018-11-19 10:42:10 -0500 | [diff] [blame] | 392 | float paintAlpha = paint.getColor4f().fA; |
| 393 | color = { paintAlpha, paintAlpha, paintAlpha, paintAlpha }; |
Brian Osman | 3ebd354 | 2018-07-30 14:36:53 -0400 | [diff] [blame] | 394 | } |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 395 | |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 396 | if (dstClip) { |
| 397 | // Get source coords corresponding to dstClip |
| 398 | SkPoint srcQuad[4]; |
| 399 | GrMapRectPoints(dstRect, srcRect, dstClip, srcQuad, 4); |
Michael Ludwig | 24adb3a | 2019-02-27 19:42:20 +0000 | [diff] [blame] | 400 | |
Greg Daniel | 2f3cd4f | 2020-02-07 11:07:25 -0500 | [diff] [blame] | 401 | rtc->drawTextureQuad(clip, std::move(view), srcColorInfo.colorType(), |
Brian Salomon | fc11844 | 2019-11-22 19:09:27 -0500 | [diff] [blame] | 402 | srcColorInfo.alphaType(), filter, paint.getBlendMode(), color, srcQuad, |
| 403 | dstClip, aa, aaFlags, |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 404 | constraint == SkCanvas::kStrict_SrcRectConstraint ? &srcRect : nullptr, |
| 405 | ctm, std::move(textureXform)); |
| 406 | } else { |
Greg Daniel | 40903af | 2020-01-30 14:55:05 -0500 | [diff] [blame] | 407 | rtc->drawTexture(clip, std::move(view), srcColorInfo.alphaType(), filter, |
| 408 | paint.getBlendMode(), color, srcRect, dstRect, aa, aaFlags, constraint, |
| 409 | ctm, std::move(textureXform)); |
Michael Ludwig | 24adb3a | 2019-02-27 19:42:20 +0000 | [diff] [blame] | 410 | } |
Michael Ludwig | 24adb3a | 2019-02-27 19:42:20 +0000 | [diff] [blame] | 411 | } |
| 412 | |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 413 | // Assumes srcRect and dstRect have already been optimized to fit the proxy. |
Brian Salomon | 777e146 | 2020-02-28 21:10:31 -0500 | [diff] [blame] | 414 | static void draw_texture_producer(GrContext* context, |
| 415 | GrRenderTargetContext* rtc, |
| 416 | const GrClip& clip, |
| 417 | const SkMatrix& ctm, |
| 418 | const SkPaint& paint, |
| 419 | GrTextureProducer* producer, |
| 420 | const SkRect& src, |
| 421 | const SkRect& dst, |
| 422 | const SkPoint dstClip[4], |
| 423 | const SkMatrix& srcToDst, |
| 424 | GrAA aa, |
| 425 | GrQuadAAFlags aaFlags, |
| 426 | SkCanvas::SrcRectConstraint constraint, |
| 427 | GrSamplerState::WrapMode wm) { |
| 428 | if (wm == GrSamplerState::WrapMode::kClamp && !producer->isPlanar() && |
| 429 | can_use_draw_texture(paint)) { |
Jim Van Verth | 30e0d7f | 2018-11-02 13:36:42 -0400 | [diff] [blame] | 430 | // We've done enough checks above to allow us to pass ClampNearest() and not check for |
| 431 | // scaling adjustments. |
Brian Salomon | ecbb0fb | 2020-02-28 18:07:32 -0500 | [diff] [blame] | 432 | auto view = producer->view(GrMipMapped::kNo); |
Greg Daniel | cc21d0c | 2020-02-05 16:58:40 -0500 | [diff] [blame] | 433 | if (!view) { |
Jim Van Verth | 30e0d7f | 2018-11-02 13:36:42 -0400 | [diff] [blame] | 434 | return; |
| 435 | } |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 436 | |
Brian Salomon | ecbb0fb | 2020-02-28 18:07:32 -0500 | [diff] [blame] | 437 | draw_texture( |
| 438 | rtc, clip, ctm, paint, src, dst, dstClip, aa, aaFlags, constraint, std::move(view), |
| 439 | {producer->colorType(), producer->alphaType(), sk_ref_sp(producer->colorSpace())}); |
Jim Van Verth | 30e0d7f | 2018-11-02 13:36:42 -0400 | [diff] [blame] | 440 | return; |
| 441 | } |
| 442 | |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 443 | const SkMaskFilter* mf = paint.getMaskFilter(); |
Michael Ludwig | b7d64b9 | 2019-02-11 11:09:15 -0500 | [diff] [blame] | 444 | |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 445 | // The shader expects proper local coords, so we can't replace local coords with texture coords |
| 446 | // if the shader will be used. If we have a mask filter we will change the underlying geometry |
| 447 | // that is rendered. |
bsalomon | f1ecd21 | 2015-12-09 17:06:02 -0800 | [diff] [blame] | 448 | bool canUseTextureCoordsAsLocalCoords = !use_shader(producer->isAlphaOnly(), paint) && !mf; |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 449 | |
Michael Ludwig | b7d64b9 | 2019-02-11 11:09:15 -0500 | [diff] [blame] | 450 | // 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] | 451 | // 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] | 452 | // FP. In the future this should be an opaque optimization enabled by the combination of |
| 453 | // GrDrawOp/GP and FP. |
| 454 | if (mf && as_MFB(mf)->hasFragmentProcessor()) { |
| 455 | mf = nullptr; |
| 456 | } |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 457 | bool doBicubic; |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 458 | GrSamplerState::Filter fm = GrSkFilterQualityToGrFilterMode( |
Chris Dalton | 309c6c0 | 2019-08-13 10:32:47 -0600 | [diff] [blame] | 459 | producer->width(), producer->height(), paint.getFilterQuality(), ctm, srcToDst, |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 460 | context->priv().options().fSharpenMipmappedTextures, &doBicubic); |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 461 | const GrSamplerState::Filter* filterMode = doBicubic ? nullptr : &fm; |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 462 | |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 463 | GrTextureProducer::FilterConstraint constraintMode; |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 464 | if (SkCanvas::kFast_SrcRectConstraint == constraint) { |
| 465 | constraintMode = GrTextureAdjuster::kNo_FilterConstraint; |
| 466 | } else { |
| 467 | constraintMode = GrTextureAdjuster::kYes_FilterConstraint; |
| 468 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 469 | |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 470 | // If we have to outset for AA then we will generate texture coords outside the src rect. The |
| 471 | // same happens for any mask filter that extends the bounds rendered in the dst. |
| 472 | // 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] | 473 | bool coordsAllInsideSrcRect = aaFlags == GrQuadAAFlags::kNone && !mf; |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 474 | |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 475 | // Check for optimization to drop the src rect constraint when on bilerp. |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 476 | if (filterMode && GrSamplerState::Filter::kBilerp == *filterMode && |
Michael Ludwig | a6a8400 | 2019-04-12 15:03:02 -0400 | [diff] [blame] | 477 | GrTextureAdjuster::kYes_FilterConstraint == constraintMode && coordsAllInsideSrcRect && |
Brian Salomon | 777e146 | 2020-02-28 21:10:31 -0500 | [diff] [blame] | 478 | !producer->isPlanar()) { |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 479 | SkMatrix combinedMatrix; |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 480 | combinedMatrix.setConcat(ctm, srcToDst); |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 481 | if (can_ignore_bilerp_constraint(*producer, src, combinedMatrix, rtc->numSamples())) { |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 482 | constraintMode = GrTextureAdjuster::kNo_FilterConstraint; |
| 483 | } |
| 484 | } |
| 485 | |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 486 | SkMatrix textureMatrix; |
bsalomon | 3aa5fce | 2015-11-12 09:59:44 -0800 | [diff] [blame] | 487 | if (canUseTextureCoordsAsLocalCoords) { |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 488 | textureMatrix = SkMatrix::I(); |
bsalomon | 3aa5fce | 2015-11-12 09:59:44 -0800 | [diff] [blame] | 489 | } else { |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 490 | if (!srcToDst.invert(&textureMatrix)) { |
bsalomon | 3aa5fce | 2015-11-12 09:59:44 -0800 | [diff] [blame] | 491 | return; |
| 492 | } |
bsalomon | 3aa5fce | 2015-11-12 09:59:44 -0800 | [diff] [blame] | 493 | } |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 494 | auto fp = producer->createFragmentProcessor(textureMatrix, src, constraintMode, |
Brian Salomon | 777e146 | 2020-02-28 21:10:31 -0500 | [diff] [blame] | 495 | coordsAllInsideSrcRect, wm, wm, filterMode); |
Brian Osman | 05c8f46 | 2018-10-22 17:13:36 -0400 | [diff] [blame] | 496 | fp = GrColorSpaceXformEffect::Make(std::move(fp), producer->colorSpace(), producer->alphaType(), |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 497 | rtc->colorInfo().colorSpace()); |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 498 | if (!fp) { |
| 499 | return; |
| 500 | } |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 501 | |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 502 | GrPaint grPaint; |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 503 | if (!SkPaintToGrPaintWithTexture(context, rtc->colorInfo(), paint, ctm, std::move(fp), |
| 504 | producer->isAlphaOnly(), &grPaint)) { |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 505 | return; |
| 506 | } |
| 507 | |
| 508 | if (!mf) { |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 509 | // Can draw the image directly (any mask filter on the paint was converted to an FP already) |
| 510 | if (dstClip) { |
| 511 | SkPoint srcClipPoints[4]; |
| 512 | SkPoint* srcClip = nullptr; |
| 513 | if (canUseTextureCoordsAsLocalCoords) { |
| 514 | // Calculate texture coordinates that match the dst clip |
| 515 | GrMapRectPoints(dst, src, dstClip, srcClipPoints, 4); |
| 516 | srcClip = srcClipPoints; |
| 517 | } |
| 518 | rtc->fillQuadWithEdgeAA(clip, std::move(grPaint), aa, aaFlags, ctm, dstClip, srcClip); |
| 519 | } else { |
| 520 | // Provide explicit texture coords when possible, otherwise rely on texture matrix |
| 521 | rtc->fillRectWithEdgeAA(clip, std::move(grPaint), aa, aaFlags, ctm, dst, |
| 522 | canUseTextureCoordsAsLocalCoords ? &src : nullptr); |
| 523 | } |
| 524 | } else { |
| 525 | // Must draw the mask filter as a GrShape. For now, this loses the per-edge AA information |
| 526 | // since it always draws with AA, but that is should not be noticeable since the mask filter |
| 527 | // is probably a blur. |
| 528 | GrShape shape; |
| 529 | if (dstClip) { |
| 530 | // Represent it as an SkPath formed from the dstClip |
| 531 | SkPath path; |
| 532 | path.addPoly(dstClip, 4, true); |
| 533 | shape = GrShape(path); |
| 534 | } else { |
| 535 | shape = GrShape(dst); |
| 536 | } |
| 537 | |
| 538 | GrBlurUtils::drawShapeWithMaskFilter( |
| 539 | context, rtc, clip, shape, std::move(grPaint), ctm, mf); |
| 540 | } |
| 541 | } |
| 542 | |
| 543 | } // anonymous namespace |
| 544 | |
Michael Ludwig | dd86fb3 | 2020-03-10 09:55:35 -0400 | [diff] [blame^] | 545 | // Break 'bitmap' into several tiles to draw it since it has already |
| 546 | // been determined to be too large to fit in VRAM |
| 547 | void SkGpuDevice::drawTiledBitmap(const SkBitmap& bitmap, |
| 548 | const SkMatrix& viewMatrix, |
| 549 | const SkMatrix& dstMatrix, |
| 550 | const SkRect& srcRect, |
| 551 | const SkIRect& clippedSrcIRect, |
| 552 | GrSamplerState::Filter filter, |
| 553 | const SkPaint& origPaint, |
| 554 | SkCanvas::SrcRectConstraint constraint, |
| 555 | int tileSize, |
| 556 | bool bicubic) { |
| 557 | // This is the funnel for all paths that draw tiled bitmaps/images. Log histogram entries. |
| 558 | SK_HISTOGRAM_BOOLEAN("DrawTiled", true); |
| 559 | LogDrawScaleFactor(viewMatrix, SkMatrix::I(), origPaint.getFilterQuality()); |
| 560 | |
| 561 | const SkPaint* paint = &origPaint; |
| 562 | SkPaint tempPaint; |
| 563 | if (origPaint.isAntiAlias() && fRenderTargetContext->numSamples() <= 1) { |
| 564 | // Drop antialiasing to avoid seams at tile boundaries. |
| 565 | tempPaint = origPaint; |
| 566 | tempPaint.setAntiAlias(false); |
| 567 | paint = &tempPaint; |
| 568 | } |
| 569 | SkRect clippedSrcRect = SkRect::Make(clippedSrcIRect); |
| 570 | |
| 571 | int nx = bitmap.width() / tileSize; |
| 572 | int ny = bitmap.height() / tileSize; |
| 573 | for (int x = 0; x <= nx; x++) { |
| 574 | for (int y = 0; y <= ny; y++) { |
| 575 | SkRect tileR; |
| 576 | tileR.setLTRB(SkIntToScalar(x * tileSize), SkIntToScalar(y * tileSize), |
| 577 | SkIntToScalar((x + 1) * tileSize), SkIntToScalar((y + 1) * tileSize)); |
| 578 | |
| 579 | if (!SkRect::Intersects(tileR, clippedSrcRect)) { |
| 580 | continue; |
| 581 | } |
| 582 | |
| 583 | if (!tileR.intersect(srcRect)) { |
| 584 | continue; |
| 585 | } |
| 586 | |
| 587 | SkIRect iTileR; |
| 588 | tileR.roundOut(&iTileR); |
| 589 | SkVector offset = SkPoint::Make(SkIntToScalar(iTileR.fLeft), |
| 590 | SkIntToScalar(iTileR.fTop)); |
| 591 | SkRect rectToDraw = tileR; |
| 592 | dstMatrix.mapRect(&rectToDraw); |
| 593 | if (filter != GrSamplerState::Filter::kNearest || bicubic) { |
| 594 | SkIRect iClampRect; |
| 595 | |
| 596 | if (SkCanvas::kFast_SrcRectConstraint == constraint) { |
| 597 | // In bleed mode we want to always expand the tile on all edges |
| 598 | // but stay within the bitmap bounds |
| 599 | iClampRect = SkIRect::MakeWH(bitmap.width(), bitmap.height()); |
| 600 | } else { |
| 601 | // In texture-domain/clamp mode we only want to expand the |
| 602 | // tile on edges interior to "srcRect" (i.e., we want to |
| 603 | // not bleed across the original clamped edges) |
| 604 | srcRect.roundOut(&iClampRect); |
| 605 | } |
| 606 | int outset = bicubic ? GrBicubicEffect::kFilterTexelPad : 1; |
| 607 | clamped_outset_with_offset(&iTileR, outset, &offset, iClampRect); |
| 608 | } |
| 609 | |
| 610 | SkBitmap tmpB; |
| 611 | if (bitmap.extractSubset(&tmpB, iTileR)) { |
| 612 | // now offset it to make it "local" to our tmp bitmap |
| 613 | tileR.offset(-offset.fX, -offset.fY); |
| 614 | // de-optimized this determination |
| 615 | bool needsTextureDomain = true; |
| 616 | this->drawBitmapTile(tmpB, |
| 617 | viewMatrix, |
| 618 | rectToDraw, |
| 619 | tileR, |
| 620 | filter, |
| 621 | *paint, |
| 622 | constraint, |
| 623 | bicubic, |
| 624 | needsTextureDomain); |
| 625 | } |
| 626 | } |
| 627 | } |
| 628 | } |
| 629 | |
| 630 | void SkGpuDevice::drawBitmapTile(const SkBitmap& bitmap, |
| 631 | const SkMatrix& viewMatrix, |
| 632 | const SkRect& dstRect, |
| 633 | const SkRect& srcRect, |
| 634 | GrSamplerState::Filter filter, |
| 635 | const SkPaint& paint, |
| 636 | SkCanvas::SrcRectConstraint constraint, |
| 637 | bool bicubic, |
| 638 | bool needsTextureDomain) { |
| 639 | // We should have already handled bitmaps larger than the max texture size. |
| 640 | SkASSERT(bitmap.width() <= this->caps()->maxTextureSize() && |
| 641 | bitmap.height() <= this->caps()->maxTextureSize()); |
| 642 | // We should be respecting the max tile size by the time we get here. |
| 643 | SkASSERT(bitmap.width() <= this->caps()->maxTileSize() && |
| 644 | bitmap.height() <= this->caps()->maxTileSize()); |
| 645 | |
| 646 | GrMipMapped mipMapped = filter == GrSamplerState::Filter::kMipMap ? GrMipMapped::kYes |
| 647 | : GrMipMapped::kNo; |
| 648 | GrSurfaceProxyView view = GrRefCachedBitmapView(fContext.get(), bitmap, mipMapped); |
| 649 | if (!view) { |
| 650 | return; |
| 651 | } |
| 652 | |
| 653 | // Compute a matrix that maps the rect we will draw to the src rect. |
| 654 | SkMatrix texMatrix = SkMatrix::MakeRectToRect(dstRect, srcRect, SkMatrix::kFill_ScaleToFit); |
| 655 | |
| 656 | SkAlphaType srcAlphaType = bitmap.alphaType(); |
| 657 | |
| 658 | // Construct a GrPaint by setting the bitmap texture as the first effect and then configuring |
| 659 | // the rest from the SkPaint. |
| 660 | std::unique_ptr<GrFragmentProcessor> fp; |
| 661 | |
| 662 | const auto& caps = *this->caps(); |
| 663 | if (needsTextureDomain && (SkCanvas::kStrict_SrcRectConstraint == constraint)) { |
| 664 | if (bicubic) { |
| 665 | static constexpr auto kDir = GrBicubicEffect::Direction::kXY; |
| 666 | fp = GrBicubicEffect::MakeSubset(std::move(view), srcAlphaType, texMatrix, |
| 667 | GrSamplerState::WrapMode::kClamp, |
| 668 | GrSamplerState::WrapMode::kClamp, srcRect, kDir, caps); |
| 669 | } else { |
| 670 | fp = GrTextureEffect::MakeSubset(std::move(view), srcAlphaType, texMatrix, filter, |
| 671 | srcRect, caps); |
| 672 | } |
| 673 | } else if (bicubic) { |
| 674 | SkASSERT(GrSamplerState::Filter::kNearest == filter); |
| 675 | static constexpr auto kDir = GrBicubicEffect::Direction::kXY; |
| 676 | fp = GrBicubicEffect::Make(std::move(view), srcAlphaType, texMatrix, kDir); |
| 677 | } else { |
| 678 | fp = GrTextureEffect::Make(std::move(view), srcAlphaType, texMatrix, filter); |
| 679 | } |
| 680 | |
| 681 | fp = GrColorSpaceXformEffect::Make(std::move(fp), bitmap.colorSpace(), bitmap.alphaType(), |
| 682 | fRenderTargetContext->colorInfo().colorSpace()); |
| 683 | GrPaint grPaint; |
| 684 | if (!SkPaintToGrPaintWithTexture(this->context(), fRenderTargetContext->colorInfo(), paint, |
| 685 | viewMatrix, std::move(fp), |
| 686 | kAlpha_8_SkColorType == bitmap.colorType(), &grPaint)) { |
| 687 | return; |
| 688 | } |
| 689 | |
| 690 | // Coverage-based AA would cause seams between tiles. |
| 691 | GrAA aa = GrAA(paint.isAntiAlias() && fRenderTargetContext->numSamples() > 1); |
| 692 | fRenderTargetContext->drawRect(this->clip(), std::move(grPaint), aa, viewMatrix, dstRect); |
| 693 | } |
| 694 | |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 695 | ////////////////////////////////////////////////////////////////////////////// |
| 696 | |
| 697 | void SkGpuDevice::drawImageQuad(const SkImage* image, const SkRect* srcRect, const SkRect* dstRect, |
| 698 | const SkPoint dstClip[4], GrAA aa, GrQuadAAFlags aaFlags, |
Michael Ludwig | 7ae2ab5 | 2019-03-05 16:00:20 -0500 | [diff] [blame] | 699 | const SkMatrix* preViewMatrix, const SkPaint& paint, |
| 700 | SkCanvas::SrcRectConstraint constraint) { |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 701 | SkRect src; |
| 702 | SkRect dst; |
| 703 | SkMatrix srcToDst; |
| 704 | ImageDrawMode mode = optimize_sample_area(SkISize::Make(image->width(), image->height()), |
| 705 | srcRect, dstRect, dstClip, &src, &dst, &srcToDst); |
| 706 | if (mode == ImageDrawMode::kSkip) { |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 707 | return; |
| 708 | } |
| 709 | |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 710 | if (src.contains(image->bounds())) { |
| 711 | constraint = SkCanvas::kFast_SrcRectConstraint; |
| 712 | } |
| 713 | // Depending on the nature of image, it can flow through more or less optimal pipelines |
Brian Salomon | 777e146 | 2020-02-28 21:10:31 -0500 | [diff] [blame] | 714 | GrSamplerState::WrapMode wrapMode = mode == ImageDrawMode::kDecal |
| 715 | ? GrSamplerState::WrapMode::kClampToBorder |
| 716 | : GrSamplerState::WrapMode::kClamp; |
Robert Phillips | 27927a5 | 2018-08-20 13:18:12 -0400 | [diff] [blame] | 717 | |
Michael Ludwig | 7ae2ab5 | 2019-03-05 16:00:20 -0500 | [diff] [blame] | 718 | // Get final CTM matrix |
Michael Ludwig | c89d1b5 | 2019-10-18 11:32:56 -0400 | [diff] [blame] | 719 | SkMatrix ctm = this->localToDevice(); |
Michael Ludwig | 7ae2ab5 | 2019-03-05 16:00:20 -0500 | [diff] [blame] | 720 | if (preViewMatrix) { |
| 721 | ctm.preConcat(*preViewMatrix); |
| 722 | } |
| 723 | |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 724 | // YUVA images can be stored in multiple images with different plane resolutions, so this |
| 725 | // uses an effect to combine them dynamically on the GPU. This is done before requesting a |
| 726 | // pinned texture proxy because YUV images force-flatten to RGBA in that scenario. |
| 727 | if (as_IB(image)->isYUVA()) { |
| 728 | SK_HISTOGRAM_BOOLEAN("DrawTiled", false); |
Michael Ludwig | 7ae2ab5 | 2019-03-05 16:00:20 -0500 | [diff] [blame] | 729 | LogDrawScaleFactor(ctm, srcToDst, paint.getFilterQuality()); |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 730 | |
Brian Salomon | 777e146 | 2020-02-28 21:10:31 -0500 | [diff] [blame] | 731 | GrYUVAImageTextureMaker maker(fContext.get(), image); |
| 732 | draw_texture_producer(fContext.get(), fRenderTargetContext.get(), this->clip(), ctm, paint, |
| 733 | &maker, src, dst, dstClip, srcToDst, aa, aaFlags, constraint, |
| 734 | wrapMode); |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 735 | return; |
| 736 | } |
| 737 | |
| 738 | // Pinned texture proxies can be rendered directly as textures, or with relatively simple |
| 739 | // adjustments applied to the image content (scaling, mipmaps, color space, etc.) |
| 740 | uint32_t pinnedUniqueID; |
Greg Daniel | cc21d0c | 2020-02-05 16:58:40 -0500 | [diff] [blame] | 741 | if (GrSurfaceProxyView view = as_IB(image)->refPinnedView(this->context(), &pinnedUniqueID)) { |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 742 | SK_HISTOGRAM_BOOLEAN("DrawTiled", false); |
Michael Ludwig | 7ae2ab5 | 2019-03-05 16:00:20 -0500 | [diff] [blame] | 743 | LogDrawScaleFactor(ctm, srcToDst, paint.getFilterQuality()); |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 744 | |
Greg Daniel | 82c6b10 | 2020-01-21 10:33:22 -0500 | [diff] [blame] | 745 | GrColorInfo colorInfo; |
Greg Daniel | cc21d0c | 2020-02-05 16:58:40 -0500 | [diff] [blame] | 746 | if (fContext->priv().caps()->isFormatSRGB(view.proxy()->backendFormat())) { |
Greg Daniel | 82c6b10 | 2020-01-21 10:33:22 -0500 | [diff] [blame] | 747 | SkASSERT(image->imageInfo().colorType() == kRGBA_8888_SkColorType); |
| 748 | colorInfo = GrColorInfo(GrColorType::kRGBA_8888_SRGB, image->imageInfo().alphaType(), |
| 749 | image->imageInfo().refColorSpace()); |
| 750 | } else { |
| 751 | colorInfo = GrColorInfo(image->imageInfo().colorInfo()); |
| 752 | } |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 753 | |
Brian Salomon | 777e146 | 2020-02-28 21:10:31 -0500 | [diff] [blame] | 754 | GrTextureAdjuster adjuster(fContext.get(), std::move(view), colorInfo, pinnedUniqueID); |
| 755 | draw_texture_producer(fContext.get(), fRenderTargetContext.get(), this->clip(), ctm, paint, |
| 756 | &adjuster, src, dst, dstClip, srcToDst, aa, aaFlags, constraint, |
| 757 | wrapMode); |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 758 | return; |
| 759 | } |
| 760 | |
| 761 | // Next up, try tiling the image |
| 762 | // TODO (michaelludwig): Implement this with per-edge AA flags to handle seaming properly |
| 763 | // instead of going through drawBitmapRect (which will be removed from SkDevice in the future) |
| 764 | SkBitmap bm; |
Michael Ludwig | 7ae2ab5 | 2019-03-05 16:00:20 -0500 | [diff] [blame] | 765 | if (this->shouldTileImage(image, &src, constraint, paint.getFilterQuality(), ctm, srcToDst)) { |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 766 | // only support tiling as bitmap at the moment, so force raster-version |
Jim Van Verth | 352f4f7 | 2019-10-29 15:26:00 -0400 | [diff] [blame] | 767 | if (as_IB(image)->getROPixels(&bm)) { |
| 768 | this->drawBitmapRect(bm, &src, dst, paint, constraint); |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 769 | return; |
| 770 | } |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 771 | } |
| 772 | |
| 773 | // This is the funnel for all non-tiled bitmap/image draw calls. Log a histogram entry. |
| 774 | SK_HISTOGRAM_BOOLEAN("DrawTiled", false); |
Michael Ludwig | 7ae2ab5 | 2019-03-05 16:00:20 -0500 | [diff] [blame] | 775 | LogDrawScaleFactor(ctm, srcToDst, paint.getFilterQuality()); |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 776 | |
| 777 | // Lazily generated images must get drawn as a texture producer that handles the final |
| 778 | // texture creation. |
| 779 | if (image->isLazyGenerated()) { |
Brian Salomon | 777e146 | 2020-02-28 21:10:31 -0500 | [diff] [blame] | 780 | GrImageTextureMaker maker(fContext.get(), image, SkImage::kAllow_CachingHint); |
| 781 | draw_texture_producer(fContext.get(), fRenderTargetContext.get(), this->clip(), ctm, paint, |
| 782 | &maker, src, dst, dstClip, srcToDst, aa, aaFlags, constraint, |
| 783 | wrapMode); |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 784 | return; |
| 785 | } |
| 786 | if (as_IB(image)->getROPixels(&bm)) { |
Greg Daniel | 6f5441a | 2020-01-28 17:02:49 -0500 | [diff] [blame] | 787 | GrBitmapTextureMaker maker(fContext.get(), bm, GrBitmapTextureMaker::Cached::kYes, |
Brian Salomon | 777e146 | 2020-02-28 21:10:31 -0500 | [diff] [blame] | 788 | SkBackingFit::kExact); |
| 789 | draw_texture_producer(fContext.get(), fRenderTargetContext.get(), this->clip(), ctm, paint, |
| 790 | &maker, src, dst, dstClip, srcToDst, aa, aaFlags, constraint, |
| 791 | wrapMode); |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 792 | } |
| 793 | |
| 794 | // Otherwise don't know how to draw it |
| 795 | } |
| 796 | |
Michael Ludwig | 390f0cc | 2019-03-19 09:16:38 -0400 | [diff] [blame] | 797 | void SkGpuDevice::drawEdgeAAImageSet(const SkCanvas::ImageSetEntry set[], int count, |
| 798 | const SkPoint dstClips[], const SkMatrix preViewMatrices[], |
| 799 | const SkPaint& paint, SkCanvas::SrcRectConstraint constraint) { |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 800 | SkASSERT(count > 0); |
Michael Ludwig | 31ba718 | 2019-04-03 10:38:06 -0400 | [diff] [blame] | 801 | if (!can_use_draw_texture(paint)) { |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 802 | // Send every entry through drawImageQuad() to handle the more complicated paint |
| 803 | int dstClipIndex = 0; |
| 804 | for (int i = 0; i < count; ++i) { |
| 805 | // Only no clip or quad clip are supported |
Michael Ludwig | 390f0cc | 2019-03-19 09:16:38 -0400 | [diff] [blame] | 806 | SkASSERT(!set[i].fHasClip || dstClips); |
| 807 | SkASSERT(set[i].fMatrixIndex < 0 || preViewMatrices); |
Michael Ludwig | 7ae2ab5 | 2019-03-05 16:00:20 -0500 | [diff] [blame] | 808 | |
Brian Salomon | db151e0 | 2019-09-17 12:11:16 -0400 | [diff] [blame] | 809 | SkTCopyOnFirstWrite<SkPaint> entryPaint(paint); |
| 810 | if (set[i].fAlpha != 1.f) { |
| 811 | auto paintAlpha = paint.getAlphaf(); |
| 812 | entryPaint.writable()->setAlphaf(paintAlpha * set[i].fAlpha); |
| 813 | } |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 814 | // Always send GrAA::kYes to preserve seaming across tiling in MSAA |
Brian Salomon | db151e0 | 2019-09-17 12:11:16 -0400 | [diff] [blame] | 815 | this->drawImageQuad( |
| 816 | set[i].fImage.get(), &set[i].fSrcRect, &set[i].fDstRect, |
| 817 | set[i].fHasClip ? dstClips + dstClipIndex : nullptr, GrAA::kYes, |
| 818 | SkToGrQuadAAFlags(set[i].fAAFlags), |
Michael Ludwig | 390f0cc | 2019-03-19 09:16:38 -0400 | [diff] [blame] | 819 | set[i].fMatrixIndex < 0 ? nullptr : preViewMatrices + set[i].fMatrixIndex, |
Brian Salomon | db151e0 | 2019-09-17 12:11:16 -0400 | [diff] [blame] | 820 | *entryPaint, constraint); |
Michael Ludwig | 390f0cc | 2019-03-19 09:16:38 -0400 | [diff] [blame] | 821 | dstClipIndex += 4 * set[i].fHasClip; |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 822 | } |
| 823 | return; |
| 824 | } |
| 825 | |
| 826 | GrSamplerState::Filter filter = kNone_SkFilterQuality == paint.getFilterQuality() ? |
| 827 | GrSamplerState::Filter::kNearest : GrSamplerState::Filter::kBilerp; |
| 828 | SkBlendMode mode = paint.getBlendMode(); |
| 829 | |
| 830 | SkAutoTArray<GrRenderTargetContext::TextureSetEntry> textures(count); |
| 831 | // We accumulate compatible proxies until we find an an incompatible one or reach the end and |
Michael Ludwig | 379e496 | 2019-12-06 13:21:26 -0500 | [diff] [blame] | 832 | // issue the accumulated 'n' draws starting at 'base'. 'p' represents the number of proxy |
| 833 | // switches that occur within the 'n' entries. |
| 834 | int base = 0, n = 0, p = 0; |
| 835 | auto draw = [&](int nextBase) { |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 836 | if (n > 0) { |
| 837 | auto textureXform = GrColorSpaceXform::Make( |
| 838 | set[base].fImage->colorSpace(), set[base].fImage->alphaType(), |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 839 | fRenderTargetContext->colorInfo().colorSpace(), kPremul_SkAlphaType); |
Michael Ludwig | 379e496 | 2019-12-06 13:21:26 -0500 | [diff] [blame] | 840 | fRenderTargetContext->drawTextureSet(this->clip(), textures.get() + base, n, p, |
Michael Ludwig | c89d1b5 | 2019-10-18 11:32:56 -0400 | [diff] [blame] | 841 | filter, mode, GrAA::kYes, constraint, |
| 842 | this->localToDevice(), std::move(textureXform)); |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 843 | } |
Michael Ludwig | 379e496 | 2019-12-06 13:21:26 -0500 | [diff] [blame] | 844 | base = nextBase; |
| 845 | n = 0; |
| 846 | p = 0; |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 847 | }; |
| 848 | int dstClipIndex = 0; |
| 849 | for (int i = 0; i < count; ++i) { |
Michael Ludwig | d9958f8 | 2019-03-21 13:08:36 -0400 | [diff] [blame] | 850 | SkASSERT(!set[i].fHasClip || dstClips); |
| 851 | SkASSERT(set[i].fMatrixIndex < 0 || preViewMatrices); |
| 852 | |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 853 | // Manage the dst clip pointer tracking before any continues are used so we don't lose |
| 854 | // our place in the dstClips array. |
Michael Ludwig | 390f0cc | 2019-03-19 09:16:38 -0400 | [diff] [blame] | 855 | const SkPoint* clip = set[i].fHasClip ? dstClips + dstClipIndex : nullptr; |
| 856 | dstClipIndex += 4 * set[i].fHasClip; |
| 857 | |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 858 | // The default SkBaseDevice implementation is based on drawImageRect which does not allow |
| 859 | // non-sorted src rects. TODO: Decide this is OK or make sure we handle it. |
| 860 | if (!set[i].fSrcRect.isSorted()) { |
Michael Ludwig | 379e496 | 2019-12-06 13:21:26 -0500 | [diff] [blame] | 861 | draw(i + 1); |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 862 | continue; |
| 863 | } |
| 864 | |
Greg Daniel | cc21d0c | 2020-02-05 16:58:40 -0500 | [diff] [blame] | 865 | GrSurfaceProxyView view; |
Michael Ludwig | d9958f8 | 2019-03-21 13:08:36 -0400 | [diff] [blame] | 866 | const SkImage_Base* image = as_IB(set[i].fImage.get()); |
Greg Daniel | cc21d0c | 2020-02-05 16:58:40 -0500 | [diff] [blame] | 867 | // Extract view from image, but skip YUV images so they get processed through |
Michael Ludwig | d9958f8 | 2019-03-21 13:08:36 -0400 | [diff] [blame] | 868 | // drawImageQuad and the proper effect to dynamically sample their planes. |
| 869 | if (!image->isYUVA()) { |
| 870 | uint32_t uniqueID; |
Greg Daniel | cc21d0c | 2020-02-05 16:58:40 -0500 | [diff] [blame] | 871 | view = image->refPinnedView(this->context(), &uniqueID); |
| 872 | if (!view) { |
Brian Salomon | ecbb0fb | 2020-02-28 18:07:32 -0500 | [diff] [blame] | 873 | view = image->refView(this->context(), GrMipMapped::kNo); |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 874 | } |
| 875 | } |
Michael Ludwig | 7ae2ab5 | 2019-03-05 16:00:20 -0500 | [diff] [blame] | 876 | |
Greg Daniel | cc21d0c | 2020-02-05 16:58:40 -0500 | [diff] [blame] | 877 | if (!view) { |
Michael Ludwig | d9958f8 | 2019-03-21 13:08:36 -0400 | [diff] [blame] | 878 | // This image can't go through the texture op, send through general image pipeline |
| 879 | // after flushing current batch. |
Michael Ludwig | 379e496 | 2019-12-06 13:21:26 -0500 | [diff] [blame] | 880 | draw(i + 1); |
Brian Salomon | db151e0 | 2019-09-17 12:11:16 -0400 | [diff] [blame] | 881 | SkTCopyOnFirstWrite<SkPaint> entryPaint(paint); |
| 882 | if (set[i].fAlpha != 1.f) { |
| 883 | auto paintAlpha = paint.getAlphaf(); |
| 884 | entryPaint.writable()->setAlphaf(paintAlpha * set[i].fAlpha); |
| 885 | } |
| 886 | this->drawImageQuad( |
| 887 | image, &set[i].fSrcRect, &set[i].fDstRect, clip, GrAA::kYes, |
Michael Ludwig | d9958f8 | 2019-03-21 13:08:36 -0400 | [diff] [blame] | 888 | SkToGrQuadAAFlags(set[i].fAAFlags), |
| 889 | set[i].fMatrixIndex < 0 ? nullptr : preViewMatrices + set[i].fMatrixIndex, |
Brian Salomon | db151e0 | 2019-09-17 12:11:16 -0400 | [diff] [blame] | 890 | *entryPaint, constraint); |
Michael Ludwig | d9958f8 | 2019-03-21 13:08:36 -0400 | [diff] [blame] | 891 | continue; |
| 892 | } |
Michael Ludwig | 7ae2ab5 | 2019-03-05 16:00:20 -0500 | [diff] [blame] | 893 | |
Greg Daniel | cc21d0c | 2020-02-05 16:58:40 -0500 | [diff] [blame] | 894 | textures[i].fProxyView = std::move(view); |
Brian Salomon | fc11844 | 2019-11-22 19:09:27 -0500 | [diff] [blame] | 895 | textures[i].fSrcAlphaType = image->alphaType(); |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 896 | textures[i].fSrcRect = set[i].fSrcRect; |
| 897 | textures[i].fDstRect = set[i].fDstRect; |
| 898 | textures[i].fDstClipQuad = clip; |
Michael Ludwig | 390f0cc | 2019-03-19 09:16:38 -0400 | [diff] [blame] | 899 | textures[i].fPreViewMatrix = |
| 900 | set[i].fMatrixIndex < 0 ? nullptr : preViewMatrices + set[i].fMatrixIndex; |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 901 | textures[i].fAlpha = set[i].fAlpha * paint.getAlphaf(); |
| 902 | textures[i].fAAFlags = SkToGrQuadAAFlags(set[i].fAAFlags); |
| 903 | |
| 904 | if (n > 0 && |
Greg Daniel | 549325c | 2019-10-30 16:19:20 -0400 | [diff] [blame] | 905 | (!GrTextureProxy::ProxiesAreCompatibleAsDynamicState( |
Michael Ludwig | fcdd061 | 2019-11-25 08:34:31 -0500 | [diff] [blame] | 906 | textures[i].fProxyView.proxy(), |
| 907 | textures[base].fProxyView.proxy()) || |
Greg Daniel | 507736f | 2020-01-17 15:36:10 -0500 | [diff] [blame] | 908 | textures[i].fProxyView.swizzle() != textures[base].fProxyView.swizzle() || |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 909 | set[i].fImage->alphaType() != set[base].fImage->alphaType() || |
| 910 | !SkColorSpace::Equals(set[i].fImage->colorSpace(), set[base].fImage->colorSpace()))) { |
Michael Ludwig | 379e496 | 2019-12-06 13:21:26 -0500 | [diff] [blame] | 911 | draw(i); |
| 912 | } |
| 913 | // Whether or not we submitted a draw in the above if(), this ith entry is in the current |
| 914 | // set being accumulated so increment n, and increment p if proxies are different. |
| 915 | ++n; |
| 916 | if (n == 1 || textures[i - 1].fProxyView.proxy() != textures[i].fProxyView.proxy()) { |
| 917 | // First proxy or a different proxy (that is compatible, otherwise we'd have drawn up |
| 918 | // to i - 1). |
| 919 | ++p; |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 920 | } |
| 921 | } |
Michael Ludwig | 379e496 | 2019-12-06 13:21:26 -0500 | [diff] [blame] | 922 | draw(count); |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 923 | } |
| 924 | |
| 925 | // TODO (michaelludwig) - to be removed when drawBitmapRect doesn't need it anymore |
| 926 | void SkGpuDevice::drawTextureProducer(GrTextureProducer* producer, |
| 927 | const SkRect* srcRect, |
| 928 | const SkRect* dstRect, |
| 929 | SkCanvas::SrcRectConstraint constraint, |
| 930 | const SkMatrix& viewMatrix, |
Brian Salomon | 777e146 | 2020-02-28 21:10:31 -0500 | [diff] [blame] | 931 | const SkPaint& paint) { |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 932 | // The texture refactor split the old logic of drawTextureProducer into the beginning of |
| 933 | // drawImageQuad() and into the static draw_texture_producer. Replicate necessary logic that |
| 934 | // drawImageQuad() handles. |
| 935 | SkRect src; |
| 936 | SkRect dst; |
| 937 | SkMatrix srcToDst; |
Brian Salomon | 1a217eb | 2019-10-24 10:50:36 -0400 | [diff] [blame] | 938 | ImageDrawMode mode = optimize_sample_area(producer->dimensions(), srcRect, dstRect, nullptr, |
| 939 | &src, &dst, &srcToDst); |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 940 | if (mode == ImageDrawMode::kSkip) { |
| 941 | return; |
| 942 | } |
| 943 | // There's no dstClip to worry about and the producer is already made so we wouldn't be able |
| 944 | // to tell it to use decals if we had to |
| 945 | SkASSERT(mode != ImageDrawMode::kDecal); |
| 946 | |
| 947 | draw_texture_producer(fContext.get(), fRenderTargetContext.get(), this->clip(), viewMatrix, |
| 948 | paint, producer, src, dst, /* clip */ nullptr, srcToDst, |
| 949 | GrAA(paint.isAntiAlias()), |
| 950 | paint.isAntiAlias() ? GrQuadAAFlags::kAll : GrQuadAAFlags::kNone, |
Brian Salomon | 777e146 | 2020-02-28 21:10:31 -0500 | [diff] [blame] | 951 | constraint, GrSamplerState::WrapMode::kClamp); |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 952 | } |