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

Public Member Functions

 DisplacementMapGM ()
 
- 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
 
void onOnceBeforeDraw () override
 
SkISize getISize () override
 
void drawClippedBitmap (SkCanvas *canvas, int x, int y, const SkPaint &paint) const
 
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 28 of file displacement.cpp.

Constructor & Destructor Documentation

◆ DisplacementMapGM()

skiagm::DisplacementMapGM::DisplacementMapGM ( )
inline

Definition at line 30 of file displacement.cpp.

30 {
31 this->setBGColor(0xFF000000);
32 }
void setBGColor(SkColor)
Definition: gm.cpp:159

Member Function Documentation

◆ drawClippedBitmap()

void skiagm::DisplacementMapGM::drawClippedBitmap ( SkCanvas canvas,
int  x,
int  y,
const SkPaint paint 
) const
inlineprotected

Definition at line 52 of file displacement.cpp.

52 {
53 canvas->save();
55 canvas->clipIRect(fImage->bounds());
56 canvas->drawImage(fImage, 0, 0, SkSamplingOptions(), &paint);
57 canvas->restore();
58 }
#define SkIntToScalar(x)
Definition: SkScalar.h:57
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void clipIRect(const SkIRect &irect, SkClipOp op=SkClipOp::kIntersect)
Definition: SkCanvas.h:991
int save()
Definition: SkCanvas.cpp:447
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition: SkCanvas.h:1528
SkIRect bounds() const
Definition: SkImage.h:303
const Paint & paint
Definition: color_source.cc:38
double y
double x
SkSamplingOptions(SkFilterMode::kLinear))

◆ getISize()

SkISize skiagm::DisplacementMapGM::getISize ( )
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 50 of file displacement.cpp.

50{ return SkISize::Make(600, 500); }
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20

◆ getName()

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

Implements skiagm::GM.

Definition at line 35 of file displacement.cpp.

35{ return SkString("displacement"); }

◆ onDraw()

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

Reimplemented from skiagm::GM.

Definition at line 60 of file displacement.cpp.

60 {
61 canvas->clear(SK_ColorBLACK);
65 SkColorChannel::kR, SkColorChannel::kG, 0.0f, displ, nullptr));
66 this->drawClippedBitmap(canvas, 0, 0, paint);
68 SkColorChannel::kB, SkColorChannel::kA, 16.0f, displ, nullptr));
69 this->drawClippedBitmap(canvas, 100, 0, paint);
71 SkColorChannel::kR, SkColorChannel::kB, 32.0f, displ, nullptr));
72 this->drawClippedBitmap(canvas, 200, 0, paint);
74 SkColorChannel::kG, SkColorChannel::kA, 48.0f, displ, nullptr));
75 this->drawClippedBitmap(canvas, 300, 0, paint);
77 SkColorChannel::kR, SkColorChannel::kA, 64.0f, displ, nullptr));
78 this->drawClippedBitmap(canvas, 400, 0, paint);
79
81 SkColorChannel::kR, SkColorChannel::kG, 40.0f, displ, nullptr));
82 this->drawClippedBitmap(canvas, 0, 100, paint);
84 SkColorChannel::kB, SkColorChannel::kA, 40.0f, displ, nullptr));
85 this->drawClippedBitmap(canvas, 100, 100, paint);
87 SkColorChannel::kR, SkColorChannel::kB, 40.0f, displ, nullptr));
88 this->drawClippedBitmap(canvas, 200, 100, paint);
90 SkColorChannel::kG, SkColorChannel::kA, 40.0f, displ, nullptr));
91 this->drawClippedBitmap(canvas, 300, 100, paint);
93 SkColorChannel::kR, SkColorChannel::kA, 40.0f, displ, nullptr));
94 this->drawClippedBitmap(canvas, 400, 100, paint);
95
96 SkIRect cropRect = SkIRect::MakeXYWH(30, 30, 40, 40);
98 SkColorChannel::kR, SkColorChannel::kG, 0.0f, displ, nullptr, &cropRect));
99 this->drawClippedBitmap(canvas, 0, 200, paint);
101 SkColorChannel::kB, SkColorChannel::kA, 16.0f, displ, nullptr, &cropRect));
102 this->drawClippedBitmap(canvas, 100, 200, paint);
104 SkColorChannel::kR, SkColorChannel::kB, 32.0f, displ, nullptr, &cropRect));
105 this->drawClippedBitmap(canvas, 200, 200, paint);
107 SkColorChannel::kG, SkColorChannel::kA, 48.0f, displ, nullptr, &cropRect));
108 this->drawClippedBitmap(canvas, 300, 200, paint);
110 SkColorChannel::kR, SkColorChannel::kA, 64.0f, displ, nullptr, &cropRect));
111 this->drawClippedBitmap(canvas, 400, 200, paint);
112
114 SkColorChannel::kR, SkColorChannel::kG, 40.0f, displ, nullptr, &cropRect));
115 this->drawClippedBitmap(canvas, 0, 300, paint);
117 SkColorChannel::kB, SkColorChannel::kA, 40.0f, displ, nullptr, &cropRect));
118 this->drawClippedBitmap(canvas, 100, 300, paint);
120 SkColorChannel::kR, SkColorChannel::kB, 40.0f, displ, nullptr, &cropRect));
121 this->drawClippedBitmap(canvas, 200, 300, paint);
123 SkColorChannel::kG, SkColorChannel::kA, 40.0f, displ, nullptr, &cropRect));
124 this->drawClippedBitmap(canvas, 300, 300, paint);
126 SkColorChannel::kR, SkColorChannel::kA, 40.0f, displ, nullptr, &cropRect));
127 this->drawClippedBitmap(canvas, 400, 300, paint);
128
129 // Test for negative scale.
131 SkColorChannel::kG, SkColorChannel::kA, -40.0f, displ, nullptr));
132 this->drawClippedBitmap(canvas, 500, 0, paint);
133
134 // Tests for images of different sizes
137 SkColorChannel::kR, SkColorChannel::kG, 40.0f, std::move(displ), nullptr));
138 this->drawClippedBitmap(canvas, 0, 400, paint);
141 SkColorChannel::kB, SkColorChannel::kA, 40.0f, std::move(displ), nullptr));
142 this->drawClippedBitmap(canvas, 100, 400, paint);
145 SkColorChannel::kR, SkColorChannel::kB, 40.0f, std::move(displ), nullptr));
146 this->drawClippedBitmap(canvas, 200, 400, paint);
149 SkColorChannel::kG, SkColorChannel::kA, 40.0f, std::move(displ), nullptr));
150 this->drawClippedBitmap(canvas, 300, 400, paint);
151
152 // Test for no given displacement input. In this case, both displacement
153 // and color should use the same bitmap, given to SkCanvas::drawBitmap()
154 // as an input argument.
156 SkColorChannel::kG, SkColorChannel::kA, 40.0f, nullptr, nullptr));
157 this->drawClippedBitmap(canvas, 400, 400, paint);
158 }
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
void clear(SkColor color)
Definition: SkCanvas.h:1199
static sk_sp< SkImageFilter > DisplacementMap(SkColorChannel xChannelSelector, SkColorChannel yChannelSelector, SkScalar scale, sk_sp< SkImageFilter > displacement, sk_sp< SkImageFilter > color, const CropRect &cropRect={})
static sk_sp< SkImageFilter > Image(sk_sp< SkImage > image, const SkRect &srcRect, const SkRect &dstRect, const SkSamplingOptions &sampling)
void drawClippedBitmap(SkCanvas *canvas, int x, int y, const SkPaint &paint) const
Definition: SkRect.h:32
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
Definition: SkRect.h:104

◆ onOnceBeforeDraw()

void skiagm::DisplacementMapGM::onOnceBeforeDraw ( )
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 37 of file displacement.cpp.

37 {
38 fImage = ToolUtils::CreateStringImage(80, 80, 0xFF884422, 15, 55, 96, "g");
39
40 SkColor c1 = ToolUtils::color_to_565(0xFF244484);
41 SkColor c2 = ToolUtils::color_to_565(0xFF804020);
42
43 fCheckerboard = ToolUtils::create_checkerboard_image(80, 80, c1, c2, 8);
44 fSmall = ToolUtils::create_checkerboard_image(64, 64, c1, c2, 8);
45 fLarge = ToolUtils::create_checkerboard_image(96, 96, c1, c2, 8);
46 fLargeW = ToolUtils::create_checkerboard_image(96, 64, c1, c2, 8);
47 fLargeH = ToolUtils::create_checkerboard_image(64, 96, c1, c2, 8);
48 }
uint32_t SkColor
Definition: SkColor.h:37
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)
SkColor color_to_565(SkColor color)
Definition: ToolUtils.cpp:139

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