Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Functions
ChartBench.cpp File Reference
#include "bench/Benchmark.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPath.h"
#include "include/private/base/SkTDArray.h"
#include "src/base/SkRandom.h"

Go to the source code of this file.

Classes

class  ChartBench
 

Functions

static void gen_data (SkScalar yAvg, SkScalar ySpread, int count, SkRandom *random, SkTDArray< SkScalar > *dataPts)
 
static void gen_paths (const SkTDArray< SkScalar > &topData, const SkTDArray< SkScalar > *bottomData, SkScalar yBase, SkScalar xLeft, SkScalar xDelta, int leftShift, SkPath *plot, SkPath *fill)
 

Function Documentation

◆ gen_data()

static void gen_data ( SkScalar  yAvg,
SkScalar  ySpread,
int  count,
SkRandom random,
SkTDArray< SkScalar > *  dataPts 
)
static

This is a conversion of samplecode/SampleChart.cpp into a bench. It sure would be nice to be able to write one subclass that can be a GM, bench, and/or Sample.

Definition at line 21 of file ChartBench.cpp.

22 {
23 dataPts->resize(count);
24 for (int i = 0; i < count; ++i) {
25 (*dataPts)[i] = random->nextRangeScalar(yAvg - SkScalarHalf(ySpread),
26 yAvg + SkScalarHalf(ySpread));
27 }
28}
int count
#define SkScalarHalf(a)
Definition SkScalar.h:75
SkScalar nextRangeScalar(SkScalar min, SkScalar max)
Definition SkRandom.h:106
void resize(int count)
Definition SkTDArray.h:183

◆ gen_paths()

static void gen_paths ( const SkTDArray< SkScalar > &  topData,
const SkTDArray< SkScalar > *  bottomData,
SkScalar  yBase,
SkScalar  xLeft,
SkScalar  xDelta,
int  leftShift,
SkPath plot,
SkPath fill 
)
static

Definition at line 34 of file ChartBench.cpp.

39 {
40 plot->rewind();
41 fill->rewind();
42 plot->incReserve(topData.size());
43 if (nullptr == bottomData) {
44 fill->incReserve(topData.size() + 2);
45 } else {
46 fill->incReserve(2 * topData.size());
47 }
48
49 leftShift %= topData.size();
50 SkScalar x = xLeft;
51
52 // Account for the leftShift using two loops
53 int shiftToEndCount = topData.size() - leftShift;
54 plot->moveTo(x, topData[leftShift]);
55 fill->moveTo(x, topData[leftShift]);
56
57 for (int i = 1; i < shiftToEndCount; ++i) {
58 plot->lineTo(x, topData[i + leftShift]);
59 fill->lineTo(x, topData[i + leftShift]);
60 x += xDelta;
61 }
62
63 for (int i = 0; i < leftShift; ++i) {
64 plot->lineTo(x, topData[i]);
65 fill->lineTo(x, topData[i]);
66 x += xDelta;
67 }
68
69 if (bottomData) {
70 SkASSERT(bottomData->size() == topData.size());
71 // iterate backwards over the previous graph's data to generate the bottom of the filled
72 // area (and account for leftShift).
73 for (int i = 0; i < leftShift; ++i) {
74 x -= xDelta;
75 fill->lineTo(x, (*bottomData)[leftShift - 1 - i]);
76 }
77 for (int i = 0; i < shiftToEndCount; ++i) {
78 x -= xDelta;
79 fill->lineTo(x, (*bottomData)[bottomData->size() - 1 - i]);
80 }
81 } else {
82 fill->lineTo(x - xDelta, yBase);
83 fill->lineTo(xLeft, yBase);
84 }
85}
#define SkASSERT(cond)
Definition SkAssert.h:116
SkPath & moveTo(SkScalar x, SkScalar y)
Definition SkPath.cpp:678
SkPath & lineTo(SkScalar x, SkScalar y)
Definition SkPath.cpp:718
SkPath & rewind()
Definition SkPath.cpp:372
void incReserve(int extraPtCount, int extraVerbCount=0, int extraConicCount=0)
Definition SkPath.cpp:668
int size() const
Definition SkTDArray.h:138
float SkScalar
Definition extension.cpp:12
double x
static void plot(SkCanvas *canvas, const char *fn, float xMin, float xMax, float yMin, float yMax, const char *label=nullptr, bool requireES3=false)