Flutter Engine
The Flutter Engine
Functions
Canvas_SrcRectConstraint.cpp File Reference
#include "tools/fiddle/examples.h"

Go to the source code of this file.

Functions

 REG_FIDDLE (Canvas_SrcRectConstraint, 256, 64, false, 0)
 

Function Documentation

◆ REG_FIDDLE()

REG_FIDDLE ( Canvas_SrcRectConstraint  ,
256  ,
64  ,
false  ,
 
)

Definition at line 4 of file Canvas_SrcRectConstraint.cpp.

4 {
5void draw(SkCanvas* canvas) {
6 SkBitmap redBorder;
8 SkCanvas checkRed(redBorder);
9 checkRed.clear(SK_ColorRED);
10 uint32_t checkers[][2] = { { SK_ColorBLACK, SK_ColorWHITE },
12 checkRed.writePixels(
13 SkImageInfo::MakeN32Premul(2, 2), (void*) checkers, sizeof(checkers[0]), 1, 1);
14 canvas->scale(16, 16);
15 canvas->drawImage(redBorder.asImage(), 0, 0);
16 canvas->resetMatrix();
17 sk_sp<SkImage> image = redBorder.asImage();
18 for (auto constraint : { SkCanvas::kStrict_SrcRectConstraint,
20 canvas->translate(80, 0);
21 canvas->drawImageRect(image.get(), SkRect::MakeLTRB(1, 1, 3, 3),
22 SkRect::MakeLTRB(16, 16, 48, 48),
23 SkSamplingOptions(SkFilterMode::kLinear), nullptr, constraint);
24 }
25}
26} // END FIDDLE
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition: aaclip.cpp:27
void allocPixels(const SkImageInfo &info, size_t rowBytes)
Definition: SkBitmap.cpp:258
sk_sp< SkImage > asImage() const
Definition: SkBitmap.cpp:645
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
@ kStrict_SrcRectConstraint
sample only inside bounds; slower
Definition: SkCanvas.h:1542
@ kFast_SrcRectConstraint
sample outside bounds; faster
Definition: SkCanvas.h:1543
void resetMatrix()
Definition: SkCanvas.cpp:1355
void drawImageRect(const SkImage *, const SkRect &src, const SkRect &dst, const SkSamplingOptions &, const SkPaint *, SrcRectConstraint)
Definition: SkCanvas.cpp:2333
void scale(SkScalar sx, SkScalar sy)
Definition: SkCanvas.cpp:1289
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition: SkCanvas.h:1528
T * get() const
Definition: SkRefCnt.h:303
sk_sp< const SkImage > image
Definition: SkRecords.h:269
static SkImageInfo MakeN32Premul(int width, int height)
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition: SkRect.h:646