Flutter Engine
The Flutter Engine
Public Member Functions | Protected Member Functions | List of all members
ChartBench Class Reference
Inheritance diagram for ChartBench:
Benchmark SkRefCnt SkRefCntBase

Public Member Functions

 ChartBench (bool aa)
 
- Public Member Functions inherited from Benchmark
 Benchmark ()
 
const char * getName ()
 
const char * getUniqueName ()
 
SkISize getSize ()
 
virtual bool isSuitableFor (Backend backend)
 
virtual void modifyGrContextOptions (GrContextOptions *)
 
virtual bool shouldLoop () const
 
void delayedSetup ()
 
void perCanvasPreDraw (SkCanvas *)
 
void perCanvasPostDraw (SkCanvas *)
 
void preDraw (SkCanvas *)
 
void postDraw (SkCanvas *)
 
void draw (int loops, SkCanvas *)
 
virtual void getGpuStats (SkCanvas *, skia_private::TArray< SkString > *keys, skia_private::TArray< double > *values)
 
virtual bool getDMSAAStats (GrRecordingContext *)
 
int getUnits () const
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 
virtual ~SkRefCntBase ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Protected Member Functions

const char * onGetName () override
 
void onDraw (int loops, SkCanvas *canvas) override
 
- Protected Member Functions inherited from Benchmark
void setUnits (int units)
 
virtual void setupPaint (SkPaint *paint)
 
virtual const char * onGetName ()=0
 
virtual const char * onGetUniqueName ()
 
virtual void onDelayedSetup ()
 
virtual void onPerCanvasPreDraw (SkCanvas *)
 
virtual void onPerCanvasPostDraw (SkCanvas *)
 
virtual void onPreDraw (SkCanvas *)
 
virtual void onPostDraw (SkCanvas *)
 
virtual void onDraw (int loops, SkCanvas *)=0
 
virtual SkISize onGetSize ()
 

Additional Inherited Members

- Public Types inherited from Benchmark
enum class  Backend {
  kNonRendering , kRaster , kGanesh , kGraphite ,
  kPDF , kHWUI
}
 

Detailed Description

Definition at line 89 of file ChartBench.cpp.

Constructor & Destructor Documentation

◆ ChartBench()

ChartBench::ChartBench ( bool  aa)
inline

Definition at line 91 of file ChartBench.cpp.

91 {
92 fShift = 0;
93 fAA = aa;
94 fSize.fWidth = -1;
95 fSize.fHeight = -1;
96 }
int32_t fHeight
Definition: SkSize.h:18
int32_t fWidth
Definition: SkSize.h:17

Member Function Documentation

◆ onDraw()

void ChartBench::onDraw ( int  loops,
SkCanvas canvas 
)
inlineoverrideprotectedvirtual

Implements Benchmark.

Definition at line 107 of file ChartBench.cpp.

107 {
108 bool sizeChanged = false;
109 if (canvas->getBaseLayerSize() != fSize) {
110 fSize = canvas->getBaseLayerSize();
111 sizeChanged = true;
112 }
113
114 SkScalar ySpread = SkIntToScalar(fSize.fHeight / 20);
115
117 if (sizeChanged) {
118 int dataPointCount = std::max(fSize.fWidth / kPixelsPerTick + 1, 2);
119
120 SkRandom random;
121 for (int i = 0; i < kNumGraphs; ++i) {
122 SkScalar y = (kNumGraphs - i) * (height - ySpread) / (kNumGraphs + 1);
123 fData[i].reset();
124 gen_data(y, ySpread, dataPointCount, &random, fData + i);
125 }
126 }
127
128 SkRandom colorRand;
129 SkColor colors[kNumGraphs];
130 for (int i = 0; i < kNumGraphs; ++i) {
131 colors[i] = colorRand.nextU() | 0xff000000;
132 }
133
134 for (int frame = 0; frame < loops; ++frame) {
135 SkPath plotPath;
136 SkPath fillPath;
137
138 static const SkScalar kStrokeWidth = SkIntToScalar(2);
139 SkPaint plotPaint;
140 SkPaint fillPaint;
141 plotPaint.setAntiAlias(fAA);
143 plotPaint.setStrokeWidth(kStrokeWidth);
146 fillPaint.setAntiAlias(fAA);
148
149 SkTDArray<SkScalar>* prevData = nullptr;
150 for (int i = 0; i < kNumGraphs; ++i) {
151 gen_paths(fData[i],
152 prevData,
153 height,
154 0,
155 SkIntToScalar(kPixelsPerTick),
156 fShift,
157 &plotPath,
158 &fillPath);
159
160 // Make the fills partially transparent
161 fillPaint.setColor((colors[i] & 0x00ffffff) | 0x80000000);
162 canvas->drawPath(fillPath, fillPaint);
163
164 plotPaint.setColor(colors[i]);
165 canvas->drawPath(plotPath, plotPaint);
166
167 prevData = fData + i;
168 }
169
170 fShift += kShiftPerFrame;
171 }
172 }
static void gen_paths(const SkTDArray< SkScalar > &topData, const SkTDArray< SkScalar > *bottomData, SkScalar yBase, SkScalar xLeft, SkScalar xDelta, int leftShift, SkPath *plot, SkPath *fill)
Definition: ChartBench.cpp:34
static void gen_data(SkScalar yAvg, SkScalar ySpread, int count, SkRandom *random, SkTDArray< SkScalar > *dataPts)
Definition: ChartBench.cpp:21
uint32_t SkColor
Definition: SkColor.h:37
#define SkIntToScalar(x)
Definition: SkScalar.h:57
virtual SkISize getBaseLayerSize() const
Definition: SkCanvas.cpp:369
void drawPath(const SkPath &path, const SkPaint &paint)
Definition: SkCanvas.cpp:1747
@ kRound_Cap
adds circle
Definition: SkPaint.h:335
void setStyle(Style style)
Definition: SkPaint.cpp:105
void setColor(SkColor color)
Definition: SkPaint.cpp:119
void setAntiAlias(bool aa)
Definition: SkPaint.h:170
void setStrokeCap(Cap cap)
Definition: SkPaint.cpp:179
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
@ kFill_Style
set to fill geometry
Definition: SkPaint.h:193
void setStrokeJoin(Join join)
Definition: SkPaint.cpp:189
@ kRound_Join
adds circle
Definition: SkPaint.h:360
void setStrokeWidth(SkScalar width)
Definition: SkPaint.cpp:159
Definition: SkPath.h:59
uint32_t nextU()
Definition: SkRandom.h:42
void reset()
Definition: SkTDArray.h:171
double frame
Definition: examples.cpp:31
float SkScalar
Definition: extension.cpp:12
static float max(float r, float g, float b)
Definition: hsl.cpp:49
double y
PODArray< SkColor > colors
Definition: SkRecords.h:276
int32_t height

◆ onGetName()

const char * ChartBench::onGetName ( )
inlineoverrideprotectedvirtual

Implements Benchmark.

Definition at line 99 of file ChartBench.cpp.

99 {
100 if (fAA) {
101 return "chart_aa";
102 } else {
103 return "chart_bw";
104 }
105 }

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