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