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

Public Member Functions

 ImageCacheBudgetBench (int budgetSize, bool shuffle)
 
bool isSuitableFor (Backend backend) override
 
- 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 onPerCanvasPreDraw (SkCanvas *canvas) override
 
void onPerCanvasPostDraw (SkCanvas *canvas) 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

Tests repeatedly drawing the same set of images in each frame. Different instances of the bench run with different cache sizes and either repeat the image order each frame or use a random order. Every variation of this bench draws the same image set, only the budget and order of images differs. Since the total fill is the same they can be cross-compared.

Definition at line 71 of file ImageCacheBudgetBench.cpp.

Constructor & Destructor Documentation

◆ ImageCacheBudgetBench()

ImageCacheBudgetBench::ImageCacheBudgetBench ( int  budgetSize,
bool  shuffle 
)
inline

budgetSize is the number of images that can fit in the cache. 100 images will be drawn.

Definition at line 74 of file ImageCacheBudgetBench.cpp.

75 : fBudgetSize(budgetSize)
76 , fShuffle(shuffle)
77 , fIndices(nullptr) {
78 float imagesOverBudget = float(kImagesToDraw) / budgetSize;
79 // Make the benchmark name contain the percentage of the budget that is used in each
80 // simulated frame.
81 fName.printf("image_cache_budget_%.0f%s", imagesOverBudget * 100,
82 (shuffle ? "_shuffle" : ""));
83 }
void printf(const char format[],...) SK_PRINTF_LIKE(2
Definition: SkString.cpp:534
SI Vec< sizeof...(Ix), T > shuffle(const Vec< N, T > &)
Definition: SkVx.h:667

Member Function Documentation

◆ isSuitableFor()

bool ImageCacheBudgetBench::isSuitableFor ( Backend  backend)
inlineoverridevirtual

Reimplemented from Benchmark.

Definition at line 85 of file ImageCacheBudgetBench.cpp.

85{ return Backend::kGanesh == backend; }
const char * backend

◆ onDraw()

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

Implements Benchmark.

Definition at line 125 of file ImageCacheBudgetBench.cpp.

125 {
126 auto dContext = GrAsDirectContext(canvas->recordingContext());
127
128 for (int i = 0; i < loops; ++i) {
129 for (int frame = 0; frame < kSimulatedFrames; ++frame) {
130 for (int j = 0; j < kImagesToDraw; ++j) {
131 int idx;
132 if (fShuffle) {
133 idx = fIndices[frame * kImagesToDraw + j];
134 } else {
135 idx = j;
136 }
137 draw_image(canvas, fImages[idx].get());
138 }
139 // Simulate a frame boundary by flushing. This should notify GrResourceCache.
140 if (dContext) {
141 dContext->flush();
142 }
143 }
144 }
145 }
static GrDirectContext * GrAsDirectContext(GrContext_Base *base)
static void draw_image(SkCanvas *canvas, SkImage *img)
virtual GrRecordingContext * recordingContext() const
Definition: SkCanvas.cpp:1637
double frame
Definition: examples.cpp:31
constexpr size_t kImagesToDraw
const myers::Point & get(const myers::Segment &)

◆ onGetName()

const char * ImageCacheBudgetBench::onGetName ( )
inlineoverrideprotectedvirtual

Implements Benchmark.

Definition at line 88 of file ImageCacheBudgetBench.cpp.

88 {
89 return fName.c_str();
90 }
const char * c_str() const
Definition: SkString.h:133

◆ onPerCanvasPostDraw()

void ImageCacheBudgetBench::onPerCanvasPostDraw ( SkCanvas canvas)
inlineoverrideprotectedvirtual

Reimplemented from Benchmark.

Definition at line 115 of file ImageCacheBudgetBench.cpp.

115 {
116 auto context = canvas->recordingContext()->asDirectContext();
117 SkASSERT(context);
118 context->setResourceCacheLimit(fOldBytes);
119 for (int i = 0; i < kImagesToDraw; ++i) {
120 fImages[i].reset();
121 }
122 fIndices.reset(nullptr);
123 }
#define SkASSERT(cond)
Definition: SkAssert.h:116
virtual GrDirectContext * asDirectContext()
void reset(T *ptr=nullptr)
Definition: SkRefCnt.h:310

◆ onPerCanvasPreDraw()

void ImageCacheBudgetBench::onPerCanvasPreDraw ( SkCanvas canvas)
inlineoverrideprotectedvirtual

Reimplemented from Benchmark.

Definition at line 92 of file ImageCacheBudgetBench.cpp.

92 {
93 auto context = canvas->recordingContext()->asDirectContext();
94 SkASSERT(context);
95 fOldBytes = context->getResourceCacheLimit();
96 set_cache_budget(canvas, fBudgetSize);
97 make_images(fImages, kImagesToDraw);
98 if (fShuffle) {
99 SkRandom random;
100 fIndices.reset(new int[kSimulatedFrames * kImagesToDraw]);
101 for (int frame = 0; frame < kSimulatedFrames; ++frame) {
102 int* base = fIndices.get() + frame * kImagesToDraw;
103 for (int i = 0; i < kImagesToDraw; ++i) {
104 base[i] = i;
105 }
106 for (int i = 0; i < kImagesToDraw - 1; ++i) {
107 int other = random.nextULessThan(kImagesToDraw - i) + i;
108 using std::swap;
109 swap(base[i], base[other]);
110 }
111 }
112 }
113 }
static void make_images(sk_sp< SkImage > imgs[], int cnt)
void set_cache_budget(SkCanvas *canvas, int approxImagesInBudget)
void swap(sk_sp< T > &a, sk_sp< T > &b)
Definition: SkRefCnt.h:341
uint32_t nextULessThan(uint32_t count)
Definition: SkRandom.h:93

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