28static const int kBmpSmallTileSize = 1 << 10;
30size_t get_tile_count(
const SkIRect& srcRect,
int tileSize) {
31 int tilesX = (srcRect.
fRight / tileSize) - (srcRect.
fLeft / tileSize) + 1;
32 int tilesY = (srcRect.
fBottom / tileSize) - (srcRect.
fTop / tileSize) + 1;
40int determine_tile_size(
const SkIRect&
src,
int maxTileSize) {
41 if (maxTileSize <= kBmpSmallTileSize) {
45 size_t maxTileTotalTileSize = get_tile_count(
src, maxTileSize);
46 size_t smallTotalTileSize = get_tile_count(
src, kBmpSmallTileSize);
48 maxTileTotalTileSize *= maxTileSize * maxTileSize;
49 smallTotalTileSize *= kBmpSmallTileSize * kBmpSmallTileSize;
51 if (maxTileTotalTileSize > 2 * smallTotalTileSize) {
52 return kBmpSmallTileSize;
64 const SkRect* srcRectPtr) {
70 inv.mapRect(&clippedSrcRect);
72 if (!clippedSrcRect.
intersect(*srcRectPtr)) {
76 clippedSrcRect.
roundOut(&clippedSrcIRect);
78 if (!clippedSrcIRect.
intersect(bmpBounds)) {
82 return clippedSrcIRect;
85int draw_tiled_bitmap(
SkCanvas* canvas,
100 int nx =
bitmap.width() / tileSize;
101 int ny =
bitmap.height() / tileSize;
103 int numTilesDrawn = 0;
107 for (
int x = 0;
x <= nx;
x++) {
108 for (
int y = 0;
y <= ny;
y++) {
113 if (!SkRect::Intersects(tileR, clippedSrcRect)) {
125 SkRect rectToDraw = tileR;
126 if (!srcToDst.
mapRect(&rectToDraw)) {
151 if (
SkBitmap subsetBmp;
bitmap.extractSubset(&subsetBmp, iTileR)) {
197 return numTilesDrawn;
215 if (imageSize.
width() > maxTileSize || imageSize.
height() > maxTileSize) {
216 *clippedSubset = determine_clipped_src_rect(conservativeClipBounds, ctm,
217 srcToDst, imageSize,
src);
218 *tileSize = determine_tile_size(*clippedSubset, maxTileSize);
223 const size_t area = imageSize.
width() * imageSize.
height();
224 if (area < 4 * kBmpSmallTileSize * kBmpSmallTileSize) {
238 size_t bmpSize = area *
sizeof(
SkPMColor);
239 if (bmpSize < cacheSize / 2) {
245 *clippedSubset = determine_clipped_src_rect(conservativeClipBounds, ctm,
246 srcToDst, imageSize,
src);
247 *tileSize = kBmpSmallTileSize;
248 size_t usedTileBytes = get_tile_count(*clippedSubset, kBmpSmallTileSize) *
249 kBmpSmallTileSize * kBmpSmallTileSize *
252 return usedTileBytes * 2 < bmpSize;
264 const SkRect& origSrcRect,
265 const SkRect& origDstRect,
282 if (!
src.intersect(srcBounds)) {
290 for (
int i = 0;
i < 4; ++
i) {
291 if (!
dst.contains(dstClip[
i].
fX, dstClip[
i].
fY)) {
295 *outDstRect = origDstRect;
311 matrix.setConcat(viewM, localM);
332 int leftClampDelta =
clamp.fLeft - iRect->
fLeft;
333 if (leftClampDelta > 0) {
340 int topClampDelta =
clamp.fTop - iRect->
fTop;
341 if (topClampDelta > 0) {
366 size_t maxTextureSize) {
376 srcRect, dstRect,
nullptr,
408 int maxTileSize = maxTextureSize - 2 * tileFilterPad;
423 size_t tiles = draw_tiled_bitmap(canvas,
433 return {
true,
tiles};
static SkM44 inv(const SkM44 &m)
static unsigned clamp(SkFixed fx, int max)
SK_SPI sk_sp< SkImage > SkMakeImageFromRasterBitmap(const SkBitmap &, SkCopyPixelsMode)
@ kNever_SkCopyPixelsMode
never copy src pixels (even if they are marked mutable)
static SkImage_Base * as_IB(SkImage *image)
static constexpr int kBicubicFilterTexelPad
#define SK_ScalarRoot2Over2
static SkDevice * TopDevice(const SkCanvas *canvas)
virtual bool isClipEmpty() const
@ kFast_SrcRectConstraint
sample outside bounds; faster
void experimental_DrawEdgeAAImageSet(const ImageSetEntry imageSet[], int cnt, const SkPoint dstClips[], const SkMatrix preViewMatrices[], const SkSamplingOptions &, const SkPaint *paint=nullptr, SrcRectConstraint constraint=kStrict_SrcRectConstraint)
virtual bool getROPixels(GrDirectContext *, SkBitmap *, CachingHint=kAllow_CachingHint) const =0
SkISize dimensions() const
virtual bool isTextureBacked() const =0
bool invert(SkM44 *inverse) const
static SkMatrix RectToRect(const SkRect &src, const SkRect &dst, ScaleToFit mode=kFill_ScaleToFit)
static SkMatrix Concat(const SkMatrix &a, const SkMatrix &b)
bool mapRect(SkRect *dst, const SkRect &src, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
static size_t Mul(size_t x, size_t y)
static SkSamplingOptions AnisoFallback(bool imageIsMipped)
static void ClampedOutsetWithOffset(SkIRect *iRect, int outset, SkPoint *offset, const SkIRect &clamp)
static ImageDrawMode OptimizeSampleArea(const SkISize &imageSize, const SkRect &origSrcRect, const SkRect &origDstRect, const SkPoint dstClip[4], SkRect *outSrcRect, SkRect *outDstRect, SkMatrix *outSrcToDst)
static bool ShouldTileImage(SkIRect conservativeClipBounds, const SkISize &imageSize, const SkMatrix &ctm, const SkMatrix &srcToDst, const SkRect *src, int maxTileSize, size_t cacheSize, int *tileSize, SkIRect *clippedSubset)
static std::tuple< bool, size_t > DrawAsTiledImageRect(SkCanvas *, const SkImage *, const SkRect &srcRect, const SkRect &dstRect, SkCanvas::QuadAAFlags, const SkSamplingOptions &, const SkPaint *, SkCanvas::SrcRectConstraint, size_t cacheSize, size_t maxTextureSize)
static bool CanDisableMipmap(const SkMatrix &viewM, const SkMatrix &localM)
unsigned useCenter Optional< SkMatrix > matrix
clipRect(r.rect, r.opAA.op(), r.opAA.aa())) template<> void Draw
sk_sp< const SkImage > image
SkSamplingOptions sampling
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
SkSamplingOptions(SkFilterMode::kLinear))
constexpr struct @263 tiles[]
bool intersect(const SkIRect &r)
int32_t fBottom
larger y-axis bounds
int32_t fTop
smaller y-axis bounds
static constexpr SkIRect MakeSize(const SkISize &size)
static constexpr SkIRect MakeEmpty()
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
int32_t fLeft
smaller x-axis bounds
void outset(int32_t dx, int32_t dy)
int32_t fRight
larger x-axis bounds
static constexpr SkISize Make(int32_t w, int32_t h)
constexpr int32_t width() const
constexpr int32_t height() const
static constexpr SkPoint Make(float x, float y)
static SkRect Make(const SkISize &size)
SkScalar fBottom
larger y-axis bounds
bool intersect(const SkRect &r)
SkScalar fLeft
smaller x-axis bounds
SkScalar fRight
larger x-axis bounds
bool contains(SkScalar x, SkScalar y) const
void roundOut(SkIRect *dst) const
void offset(float dx, float dy)
void setLTRB(float left, float top, float right, float bottom)
SkScalar fTop
smaller y-axis bounds
const SkFilterMode filter
const SkMipmapMode mipmap