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

Classes

struct  GradientStop
 

Public Member Functions

 FillrectGradientGM ()
 
- 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 drawGradient (SkCanvas *canvas, std::initializer_list< GradientStop > stops)
 
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 34 of file fillrect_gradient.cpp.

Constructor & Destructor Documentation

◆ FillrectGradientGM()

FillrectGradientGM::FillrectGradientGM ( )
inline

Definition at line 36 of file fillrect_gradient.cpp.

36{}

Member Function Documentation

◆ drawGradient()

void FillrectGradientGM::drawGradient ( SkCanvas canvas,
std::initializer_list< GradientStop stops 
)
inlineprotected

Definition at line 51 of file fillrect_gradient.cpp.

51 {
52 std::vector<SkColor> colors;
53 std::vector<SkScalar> positions;
54 colors.reserve(stops.size());
55 positions.reserve(stops.size());
56
57 for (const GradientStop& stop : stops) {
58 colors.push_back(stop.color);
59 positions.push_back(stop.pos);
60 }
61
62 static constexpr SkPoint points[] = {
65 };
66
67 // Draw the gradient linearly.
69 colors.data(),
70 positions.data(),
71 colors.size(),
74 paint.setShader(shader);
76
77 canvas->save();
78 canvas->translate(kCellSize + kPadSize, 0);
79
80 // Draw the gradient radially.
82 kCellSize / 2,
83 colors.data(),
84 positions.data(),
85 colors.size(),
87 paint.setShader(shader);
89
90 canvas->restore();
91 canvas->translate(0, kCellSize + kPadSize);
92 }
static const int points[]
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
int save()
Definition: SkCanvas.cpp:447
static sk_sp< SkShader > MakeRadial(const SkPoint &center, SkScalar radius, const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)
static sk_sp< SkShader > MakeLinear(const SkPoint pts[2], const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)
const Paint & paint
Definition: color_source.cc:38
const int kPadSize
const int kCellSize
PODArray< SkColor > colors
Definition: SkRecords.h:276
static constexpr SkPoint Make(float x, float y)
Definition: SkPoint_impl.h:173
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659

◆ getISize()

SkISize FillrectGradientGM::getISize ( )
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 46 of file fillrect_gradient.cpp.

46 {
49 }
const int kNumRows
const int kNumColumns
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20

◆ getName()

SkString FillrectGradientGM::getName ( ) const
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 44 of file fillrect_gradient.cpp.

44{ return SkString("fillrect_gradient"); }

◆ onDraw()

void FillrectGradientGM::onDraw ( SkCanvas canvas)
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 94 of file fillrect_gradient.cpp.

94 {
95 // Simple gradient: Green to white
96 this->drawGradient(canvas, {{0.0f, SK_ColorGREEN}, {1.0f, SK_ColorWHITE}});
97
98 // Multiple sections: Green to white to red
99 this->drawGradient(canvas,
100 {{0.0f, SK_ColorGREEN}, {0.5f, SK_ColorWHITE}, {1.0f, SK_ColorRED}});
101
102 // No stops at 0.0 or 1.0: Larger green to white to larger red
103 this->drawGradient(canvas,
104 {{0.4f, SK_ColorGREEN}, {0.5f, SK_ColorWHITE}, {0.6f, SK_ColorRED}});
105
106 // Only one stop, at zero: Solid red
107 this->drawGradient(canvas, {{0.0f, SK_ColorRED}});
108
109 // Only one stop, at 1.0: Solid red
110 this->drawGradient(canvas, {{1.0f, SK_ColorRED}});
111
112 // Only one stop, in the middle: Solid red
113 this->drawGradient(canvas, {{0.5f, SK_ColorRED}});
114
115 // Disjoint gradients (multiple stops at the same offset)
116 // Blue to white in the top (inner) half, red to yellow in the bottom (outer) half
117 this->drawGradient(canvas,
118 {{0.0f, SK_ColorBLUE},
119 {0.5f, SK_ColorWHITE},
120 {0.5f, SK_ColorRED},
121 {1.0f, SK_ColorYELLOW}});
122
123 // Ignored stops: Blue to white, red to yellow (same as previous)
124 this->drawGradient(canvas,
125 {{0.0f, SK_ColorBLUE},
126 {0.5f, SK_ColorWHITE},
127 {0.5f, SK_ColorGRAY},
128 {0.5f, SK_ColorCYAN},
129 {0.5f, SK_ColorRED},
130 {1.0f, SK_ColorYELLOW}});
131
132 // Unsorted stops: Blue to white, red to yellow
133 // Unlike Chrome, we don't sort the stops, so this renders differently than the prior cell.
134 this->drawGradient(canvas,
135 {{0.5f, SK_ColorWHITE},
136 {0.5f, SK_ColorGRAY},
137 {1.0f, SK_ColorYELLOW},
138 {0.5f, SK_ColorCYAN},
139 {0.5f, SK_ColorRED},
140 {0.0f, SK_ColorBLUE}});
141 }
constexpr SkColor SK_ColorYELLOW
Definition: SkColor.h:139
constexpr SkColor SK_ColorCYAN
Definition: SkColor.h:143
constexpr SkColor SK_ColorGRAY
Definition: SkColor.h:113
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
void drawGradient(SkCanvas *canvas, std::initializer_list< GradientStop > stops)

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