1 /* 2 * Copyright 2023 Google LLC 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef skgpu_TiledTextureUtils_DEFINED 9 #define skgpu_TiledTextureUtils_DEFINED 10 11 #include "include/core/SkCanvas.h" 12 #include "include/core/SkTileMode.h" 13 14 #include <tuple> 15 16 class GrClip; 17 class GrRecordingContext; 18 class SkBitmap; 19 struct SkIRect; 20 struct SkISize; 21 class SkMatrix; 22 class SkPaint; 23 struct SkRect; 24 struct SkSamplingOptions; 25 26 namespace skgpu { 27 28 class TiledTextureUtils { 29 public: 30 static bool ShouldTileImage(SkIRect conservativeClipBounds, 31 const SkISize& imageSize, 32 const SkMatrix& ctm, 33 const SkMatrix& srcToDst, 34 const SkRect* src, 35 int maxTileSize, 36 size_t cacheSize, 37 int* tileSize, 38 SkIRect* clippedSubset); 39 40 enum class ImageDrawMode { 41 // Src and dst have been restricted to the image content. May need to clamp, no need to 42 // decal. 43 kOptimized, 44 // Src and dst are their original sizes, requires use of a decal instead of plain clamping. 45 // This is used when a dst clip is provided and extends outside of the optimized dst rect. 46 kDecal, 47 // Src or dst are empty, or do not intersect the image content so don't draw anything. 48 kSkip 49 }; 50 51 static ImageDrawMode OptimizeSampleArea(const SkISize& imageSize, 52 const SkRect& origSrcRect, 53 const SkRect& origDstRect, 54 const SkPoint dstClip[4], 55 SkRect* outSrcRect, 56 SkRect* outDstRect, 57 SkMatrix* outSrcToDst); 58 59 static bool CanDisableMipmap(const SkMatrix& viewM, 60 const SkMatrix& localM, 61 bool sharpenMipmappedTextures); 62 63 static void ClampedOutsetWithOffset(SkIRect* iRect, int outset, SkPoint* offset, 64 const SkIRect& clamp); 65 66 static std::tuple<bool, size_t> DrawAsTiledImageRect(SkCanvas*, 67 const SkImage*, 68 const SkRect& srcRect, 69 const SkRect& dstRect, 70 SkCanvas::QuadAAFlags, 71 const SkSamplingOptions&, 72 const SkPaint*, 73 SkCanvas::SrcRectConstraint, 74 bool sharpenMM, 75 size_t cacheSize, 76 size_t maxTextureSize); 77 }; 78 79 } // namespace skgpu 80 81 #endif // skgpu_TiledTextureUtils_DEFINED 82