Flutter Engine
The Flutter Engine
Functions | Variables
SkTiledImageUtils Namespace Reference

Functions

SK_API void DrawImageRect (SkCanvas *canvas, const SkImage *image, const SkRect &src, const SkRect &dst, const SkSamplingOptions &sampling={}, const SkPaint *paint=nullptr, SkCanvas::SrcRectConstraint constraint=SkCanvas::kFast_SrcRectConstraint)
 
void DrawImageRect (SkCanvas *canvas, const sk_sp< SkImage > &image, const SkRect &src, const SkRect &dst, const SkSamplingOptions &sampling={}, const SkPaint *paint=nullptr, SkCanvas::SrcRectConstraint constraint=SkCanvas::kFast_SrcRectConstraint)
 
void DrawImageRect (SkCanvas *canvas, const SkImage *image, const SkRect &dst, const SkSamplingOptions &sampling={}, const SkPaint *paint=nullptr, SkCanvas::SrcRectConstraint constraint=SkCanvas::kFast_SrcRectConstraint)
 
void DrawImageRect (SkCanvas *canvas, const sk_sp< SkImage > &image, const SkRect &dst, const SkSamplingOptions &sampling={}, const SkPaint *paint=nullptr, SkCanvas::SrcRectConstraint constraint=SkCanvas::kFast_SrcRectConstraint)
 
void DrawImage (SkCanvas *canvas, const SkImage *image, SkScalar x, SkScalar y, const SkSamplingOptions &sampling={}, const SkPaint *paint=nullptr, SkCanvas::SrcRectConstraint constraint=SkCanvas::kFast_SrcRectConstraint)
 
void DrawImage (SkCanvas *canvas, const sk_sp< SkImage > &image, SkScalar x, SkScalar y, const SkSamplingOptions &sampling={}, const SkPaint *paint=nullptr, SkCanvas::SrcRectConstraint constraint=SkCanvas::kFast_SrcRectConstraint)
 
SK_API void GetImageKeyValues (const SkImage *image, uint32_t keyValues[kNumImageKeyValues])
 

Variables

static constexpr int kNumImageKeyValues = 6
 

Detailed Description

SkTiledImageUtils' DrawImage/DrawImageRect methods are intended to be direct replacements for their SkCanvas equivalents. The SkTiledImageUtils calls will break SkBitmap-backed SkImages into smaller tiles and draw them if the original image is too large to be uploaded to the GPU. If the original image doesn't need tiling or is already gpu-backed the DrawImage/DrawImageRect calls will fall through to the matching SkCanvas call.

Function Documentation

◆ DrawImage() [1/2]

void SkTiledImageUtils::DrawImage ( SkCanvas canvas,
const sk_sp< SkImage > &  image,
SkScalar  x,
SkScalar  y,
const SkSamplingOptions sampling = {},
const SkPaint paint = nullptr,
SkCanvas::SrcRectConstraint  constraint = SkCanvas::kFast_SrcRectConstraint 
)
inline

Definition at line 95 of file SkTiledImageUtils.h.

98 {},
99 const SkPaint* paint = nullptr,
100 SkCanvas::SrcRectConstraint constraint =
102 DrawImage(canvas, image.get(), x, y, sampling, paint, constraint);
103}
SrcRectConstraint
Definition: SkCanvas.h:1541
@ kFast_SrcRectConstraint
sample outside bounds; faster
Definition: SkCanvas.h:1543
T * get() const
Definition: SkRefCnt.h:303
const Paint & paint
Definition: color_source.cc:38
double y
double x
sk_sp< const SkImage > image
Definition: SkRecords.h:269
SkSamplingOptions sampling
Definition: SkRecords.h:337
void DrawImage(SkCanvas *canvas, const sk_sp< SkImage > &image, SkScalar x, SkScalar y, const SkSamplingOptions &sampling={}, const SkPaint *paint=nullptr, SkCanvas::SrcRectConstraint constraint=SkCanvas::kFast_SrcRectConstraint)

◆ DrawImage() [2/2]

void SkTiledImageUtils::DrawImage ( SkCanvas canvas,
const SkImage image,
SkScalar  x,
SkScalar  y,
const SkSamplingOptions sampling = {},
const SkPaint paint = nullptr,
SkCanvas::SrcRectConstraint  constraint = SkCanvas::kFast_SrcRectConstraint 
)
inline

Definition at line 78 of file SkTiledImageUtils.h.

81 {},
82 const SkPaint* paint = nullptr,
85 if (!image) {
86 return;
87 }
88
91
92 DrawImageRect(canvas, image, src, dst, sampling, paint, constraint);
93}
int width() const
Definition: SkImage.h:285
int height() const
Definition: SkImage.h:291
void DrawImageRect(SkCanvas *canvas, const sk_sp< SkImage > &image, const SkRect &dst, const SkSamplingOptions &sampling={}, const SkPaint *paint=nullptr, SkCanvas::SrcRectConstraint constraint=SkCanvas::kFast_SrcRectConstraint)
dst
Definition: cp.py:12
static SkRect MakeIWH(int w, int h)
Definition: SkRect.h:623
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659

◆ DrawImageRect() [1/4]

void SkTiledImageUtils::DrawImageRect ( SkCanvas canvas,
const sk_sp< SkImage > &  image,
const SkRect dst,
const SkSamplingOptions sampling = {},
const SkPaint paint = nullptr,
SkCanvas::SrcRectConstraint  constraint = SkCanvas::kFast_SrcRectConstraint 
)
inline

Definition at line 68 of file SkTiledImageUtils.h.

71 {},
72 const SkPaint* paint = nullptr,
75 DrawImageRect(canvas, image.get(), dst, sampling, paint, constraint);
76}

◆ DrawImageRect() [2/4]

void SkTiledImageUtils::DrawImageRect ( SkCanvas canvas,
const sk_sp< SkImage > &  image,
const SkRect src,
const SkRect dst,
const SkSamplingOptions sampling = {},
const SkPaint paint = nullptr,
SkCanvas::SrcRectConstraint  constraint = SkCanvas::kFast_SrcRectConstraint 
)
inline

Definition at line 41 of file SkTiledImageUtils.h.

45 {},
46 const SkPaint* paint = nullptr,
49 DrawImageRect(canvas, image.get(), src, dst, sampling, paint, constraint);
50}

◆ DrawImageRect() [3/4]

void SkTiledImageUtils::DrawImageRect ( SkCanvas canvas,
const SkImage image,
const SkRect dst,
const SkSamplingOptions sampling = {},
const SkPaint paint = nullptr,
SkCanvas::SrcRectConstraint  constraint = SkCanvas::kFast_SrcRectConstraint 
)
inline

Definition at line 52 of file SkTiledImageUtils.h.

55 {},
56 const SkPaint* paint = nullptr,
59 if (!image) {
60 return;
61 }
62
64
65 DrawImageRect(canvas, image, src, dst, sampling, paint, constraint);
66}

◆ DrawImageRect() [4/4]

void SkTiledImageUtils::DrawImageRect ( SkCanvas canvas,
const SkImage image,
const SkRect src,
const SkRect dst,
const SkSamplingOptions sampling = {},
const SkPaint paint = nullptr,
SkCanvas::SrcRectConstraint  constraint = SkCanvas::kFast_SrcRectConstraint 
)

Definition at line 24 of file SkTiledImageUtils.cpp.

30 {
31 if (!image || !canvas) {
32 return;
33 }
34
35 SkPaint p;
36 if (paint) {
37 p = *paint;
38 }
39 if (!SkCanvasPriv::TopDevice(canvas)->drawAsTiledImageRect(
40 canvas, image, &src, dst, sampling, p, constraint)) {
41 // Either the image didn't require tiling or this is a raster-backed
42 // canvas. In either case fall back to a default draw.
43 canvas->drawImageRect(image, src, dst, sampling, paint, constraint);
44 }
45}
static SkDevice * TopDevice(const SkCanvas *canvas)
Definition: SkCanvasPriv.h:65
void drawImageRect(const SkImage *, const SkRect &src, const SkRect &dst, const SkSamplingOptions &, const SkPaint *, SrcRectConstraint)
Definition: SkCanvas.cpp:2333

◆ GetImageKeyValues()

void SkTiledImageUtils::GetImageKeyValues ( const SkImage image,
uint32_t  keyValues[kNumImageKeyValues] 
)

Retrieves a set of values that can be used as part of a cache key for the provided image.

Unfortunately, SkImage::uniqueID isn't sufficient as an SkImage cache key. In particular, SkBitmap-backed SkImages can share a single SkBitmap and refer to different subsets of it. In this situation the optimal key is based on the SkBitmap's generation ID and the subset rectangle. For Picture-backed images this method will attempt to generate a concise internally-based key (i.e., containing picture ID, matrix translation, width and height, etc.). For complicated Picture-backed images (i.e., those w/ a paint or a full matrix) it will fall back to using 'image's unique key.

Parameters
imageThe image for which key values are desired
keyValuesThe resulting key values

Definition at line 47 of file SkTiledImageUtils.cpp.

47 {
48 if (!image || !keyValues) {
49 if (keyValues) {
50 memset(keyValues, 0, kNumImageKeyValues * sizeof(uint32_t));
51 }
52 return;
53 }
54
55 const SkImage_Base* imageBase = as_IB(image);
56 if (const SkBitmap* bm = imageBase->onPeekBitmap()) {
57 keyValues[0] = bm->pixelRef()->getGenerationID();
58 SkIRect subset = image->bounds();
59 subset.offset(bm->pixelRefOrigin());
60
61 SkASSERT(SkTFitsIn<uint32_t>(subset.fLeft));
62 SkASSERT(SkTFitsIn<uint32_t>(subset.fTop));
63 SkASSERT(SkTFitsIn<uint32_t>(subset.fRight));
64 SkASSERT(SkTFitsIn<uint32_t>(subset.fBottom));
65
66 keyValues[1] = 0; // This empty slot is to disambiguate picture IDs
67 keyValues[2] = subset.fLeft;
68 keyValues[3] = subset.fTop;
69 keyValues[4] = subset.fRight;
70 keyValues[5] = subset.fBottom;
71 return;
72 }
73
74 if (imageBase->type() == SkImage_Base::Type::kLazyPicture) {
75 const SkImage_Picture* pictureImage = static_cast<const SkImage_Picture*>(imageBase);
76 if (pictureImage->getImageKeyValues(keyValues)) {
77 return;
78 }
79 }
80
81 keyValues[0] = image->uniqueID();
82 memset(&keyValues[1], 0, (kNumImageKeyValues-1) * sizeof(uint32_t));
83}
#define SkASSERT(cond)
Definition: SkAssert.h:116
static SkImage_Base * as_IB(SkImage *image)
Definition: SkImage_Base.h:201
virtual Type type() const =0
virtual const SkBitmap * onPeekBitmap() const
Definition: SkImage_Base.h:64
bool getImageKeyValues(uint32_t keyValues[SkTiledImageUtils::kNumImageKeyValues]) const
uint32_t uniqueID() const
Definition: SkImage.h:311
SkIRect bounds() const
Definition: SkImage.h:303
static constexpr int kNumImageKeyValues
Definition: SkRect.h:32
int32_t fBottom
larger y-axis bounds
Definition: SkRect.h:36
int32_t fTop
smaller y-axis bounds
Definition: SkRect.h:34
void offset(int32_t dx, int32_t dy)
Definition: SkRect.h:367
int32_t fLeft
smaller x-axis bounds
Definition: SkRect.h:33
int32_t fRight
larger x-axis bounds
Definition: SkRect.h:35

Variable Documentation

◆ kNumImageKeyValues

constexpr int SkTiledImageUtils::kNumImageKeyValues = 6
staticconstexpr

Definition at line 105 of file SkTiledImageUtils.h.