Flutter Engine
The Flutter Engine
Public Member Functions | Protected Member Functions | List of all members
skiagm::TileImageFilterGM Class Reference
Inheritance diagram for skiagm::TileImageFilterGM:
skiagm::GM

Public Member Functions

 TileImageFilterGM ()
 
- Public Member Functions inherited from skiagm::GM
 GM (SkColor backgroundColor=SK_ColorWHITE)
 
virtual ~GM ()
 
void setMode (Mode mode)
 
Mode getMode () const
 
DrawResult gpuSetup (SkCanvas *, SkString *errorMsg, GraphiteTestContext *=nullptr)
 
void gpuTeardown ()
 
void onceBeforeDraw ()
 
DrawResult draw (SkCanvas *canvas)
 
DrawResult draw (SkCanvas *, SkString *errorMsg)
 
void drawBackground (SkCanvas *)
 
DrawResult drawContent (SkCanvas *canvas)
 
DrawResult drawContent (SkCanvas *, SkString *errorMsg)
 
virtual SkISize getISize ()=0
 
virtual SkString getName () const =0
 
virtual bool runAsBench () const
 
SkScalar width ()
 
SkScalar height ()
 
SkColor getBGColor () const
 
void setBGColor (SkColor)
 
void drawSizeBounds (SkCanvas *, SkColor)
 
bool animate (double)
 
virtual bool onChar (SkUnichar)
 
bool getControls (SkMetaData *controls)
 
void setControls (const SkMetaData &controls)
 
virtual void modifyGrContextOptions (GrContextOptions *)
 
virtual void modifyGraphiteContextOptions (skgpu::graphite::ContextOptions *) const
 
virtual bool isBazelOnly () const
 
virtual std::map< std::string, std::string > getGoldKeys () const
 

Protected Member Functions

SkString getName () const override
 
SkISize getISize () override
 
void onOnceBeforeDraw () override
 
void onDraw (SkCanvas *canvas) override
 
- Protected Member Functions inherited from skiagm::GM
virtual DrawResult onGpuSetup (SkCanvas *, SkString *, GraphiteTestContext *)
 
virtual void onGpuTeardown ()
 
virtual void onOnceBeforeDraw ()
 
virtual DrawResult onDraw (SkCanvas *, SkString *errorMsg)
 
virtual void onDraw (SkCanvas *)
 
virtual bool onAnimate (double)
 
virtual bool onGetControls (SkMetaData *)
 
virtual void onSetControls (const SkMetaData &)
 
GraphiteTestContextgraphiteTestContext () const
 

Additional Inherited Members

- Public Types inherited from skiagm::GM
enum  Mode { kGM_Mode , kSample_Mode , kBench_Mode }
 
using DrawResult = skiagm::DrawResult
 
using GraphiteTestContext = skiatest::graphite::GraphiteTestContext
 
- Static Public Attributes inherited from skiagm::GM
static constexpr char kErrorMsg_DrawSkippedGpuOnly []
 

Detailed Description

Definition at line 35 of file tileimagefilter.cpp.

Constructor & Destructor Documentation

◆ TileImageFilterGM()

skiagm::TileImageFilterGM::TileImageFilterGM ( )
inline

Definition at line 37 of file tileimagefilter.cpp.

37 {
38 this->setBGColor(0xFF000000);
39 }
void setBGColor(SkColor)
Definition: gm.cpp:159

Member Function Documentation

◆ getISize()

SkISize skiagm::TileImageFilterGM::getISize ( )
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 44 of file tileimagefilter.cpp.

44{ return SkISize::Make(WIDTH, HEIGHT); }
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20
#define WIDTH
#define HEIGHT

◆ getName()

SkString skiagm::TileImageFilterGM::getName ( ) const
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 42 of file tileimagefilter.cpp.

42{ return SkString("tileimagefilter"); }

◆ onDraw()

void skiagm::TileImageFilterGM::onDraw ( SkCanvas canvas)
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 52 of file tileimagefilter.cpp.

52 {
53 canvas->clear(SK_ColorBLACK);
54 SkPaint red;
57 SkPaint blue;
60
61 int x = 0, y = 0;
62
63 {
64 for (size_t i = 0; i < 4; i++) {
65 sk_sp<SkImage> image = (i & 0x01) ? fCheckerboard : fBitmap;
68 SkIntToScalar(image->width()/(i+1)),
69 SkIntToScalar(image->height()/(i+1)));
71 SkIntToScalar(i * 4),
72 SkIntToScalar(image->width() - i * 12),
73 SkIntToScalar(image->height()) - i * 12);
75 sk_sp<SkImageFilter> filter(SkImageFilters::Tile(srcRect, dstRect,
76 std::move(tileInput)));
77 canvas->save();
80 paint.setImageFilter(std::move(filter));
81 canvas->drawImage(fBitmap.get(), 0, 0, SkSamplingOptions(), &paint);
82 canvas->drawRect(srcRect, red);
83 canvas->drawRect(dstRect, blue);
84 canvas->restore();
85 x += image->width() + MARGIN;
86 if (x + image->width() > WIDTH) {
87 x = 0;
88 y += image->height() + MARGIN;
89 }
90 }
91 }
92
93 {
94 float matrix[20] = { 1, 0, 0, 0, 0,
95 0, 1, 0, 0, 0,
96 0, 0, 1, 0, 0,
97 0, 0, 0, 1, 0 };
98
99 SkRect srcRect = SkRect::MakeWH(SkIntToScalar(fBitmap->width()),
100 SkIntToScalar(fBitmap->height()));
101 SkRect dstRect = SkRect::MakeWH(SkIntToScalar(fBitmap->width() * 2),
102 SkIntToScalar(fBitmap->height() * 2));
103 sk_sp<SkImageFilter> tile(SkImageFilters::Tile(srcRect, dstRect, nullptr));
105
107 paint.setImageFilter(SkImageFilters::ColorFilter(std::move(cf), std::move(tile)));
108 canvas->save();
110 canvas->clipRect(dstRect);
111 canvas->saveLayer(&dstRect, &paint);
112 canvas->drawImage(fBitmap.get(), 0, 0);
113 canvas->restore();
114 canvas->drawRect(srcRect, red);
115 canvas->drawRect(dstRect, blue);
116 canvas->restore();
117 }
118
119 // test that the crop rect properly applies to the tile image filter
120 {
121 canvas->translate(0, SkIntToScalar(100));
122
123 SkRect srcRect = SkRect::MakeXYWH(0, 0, 50, 50);
124 SkRect dstRect = SkRect::MakeXYWH(0, 0, 100, 100);
125 SkIRect cropRect = SkIRect::MakeXYWH(5, 5, 40, 40);
127 sk_sp<SkImageFilter> green(SkImageFilters::ColorFilter(std::move(greenCF),
128 nullptr,
129 &cropRect));
131 paint.setColor(SK_ColorRED);
132 paint.setImageFilter(SkImageFilters::Tile(srcRect, dstRect, std::move(green)));
133 canvas->drawRect(dstRect, paint);
134 }
135 }
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
#define SkIntToScalar(x)
Definition: SkScalar.h:57
int saveLayer(const SkRect *bounds, const SkPaint *paint)
Definition: SkCanvas.cpp:496
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1361
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void clear(SkColor color)
Definition: SkCanvas.h:1199
int save()
Definition: SkCanvas.cpp:447
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition: SkCanvas.h:1528
static sk_sp< SkColorFilter > Blend(const SkColor4f &c, sk_sp< SkColorSpace >, SkBlendMode mode)
static sk_sp< SkColorFilter > Matrix(const SkColorMatrix &)
static sk_sp< SkImageFilter > ColorFilter(sk_sp< SkColorFilter > cf, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
static sk_sp< SkImageFilter > Image(sk_sp< SkImage > image, const SkRect &srcRect, const SkRect &dstRect, const SkSamplingOptions &sampling)
static sk_sp< SkImageFilter > Tile(const SkRect &src, const SkRect &dst, sk_sp< SkImageFilter > input)
int width() const
Definition: SkImage.h:285
int height() const
Definition: SkImage.h:291
void setStyle(Style style)
Definition: SkPaint.cpp:105
void setColor(SkColor color)
Definition: SkPaint.cpp:119
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
T * get() const
Definition: SkRefCnt.h:303
const Paint & paint
Definition: color_source.cc:38
double y
double x
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
sk_sp< const SkImage > image
Definition: SkRecords.h:269
Definition: SkRect.h:32
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
Definition: SkRect.h:104
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609
#define MARGIN

◆ onOnceBeforeDraw()

void skiagm::TileImageFilterGM::onOnceBeforeDraw ( )
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 46 of file tileimagefilter.cpp.

46 {
47 fBitmap = ToolUtils::CreateStringImage(50, 50, 0xD000D000, 10, 45, 50, "e");
48
49 fCheckerboard = ToolUtils::create_checkerboard_image(80, 80, 0xFFA0A0A0, 0xFF404040, 8);
50 }
sk_sp< SkImage > create_checkerboard_image(int w, int h, SkColor c1, SkColor c2, int checkSize)
Definition: ToolUtils.cpp:168
sk_sp< SkImage > CreateStringImage(int w, int h, SkColor c, int x, int y, int textSize, const char *str)

The documentation for this class was generated from the following file: