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