Flutter Engine
The Flutter Engine
Classes | Functions | Variables
ImageCacheBudgetBench.cpp File Reference
#include "bench/Benchmark.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkImage.h"
#include "include/core/SkSurface.h"
#include "include/gpu/GrDirectContext.h"
#include "src/gpu/ganesh/GrDirectContextPriv.h"
#include "src/gpu/ganesh/GrResourceCache.h"
#include "tools/ToolUtils.h"
#include <utility>

Go to the source code of this file.

Classes

class  ImageCacheBudgetBench
 
class  ImageCacheBudgetDynamicBench
 

Functions

static void make_images (sk_sp< SkImage > imgs[], int cnt)
 
static void draw_image (SkCanvas *canvas, SkImage *img)
 
void set_cache_budget (SkCanvas *canvas, int approxImagesInBudget)
 

Variables

static constexpr int kS = 25
 

Function Documentation

◆ draw_image()

static void draw_image ( SkCanvas canvas,
SkImage img 
)
static

Definition at line 35 of file ImageCacheBudgetBench.cpp.

35 {
36 // Make the paint transparent to avoid any issues of deferred tiler blending
37 // optmizations
39 paint.setAlpha(0x10);
40 canvas->drawImage(img, 0, 0, SkSamplingOptions(), &paint);
41}
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition: SkCanvas.h:1528
const Paint & paint
Definition: color_source.cc:38
SkSamplingOptions(SkFilterMode::kLinear))

◆ make_images()

static void make_images ( sk_sp< SkImage imgs[],
int  cnt 
)
static

Definition at line 29 of file ImageCacheBudgetBench.cpp.

29 {
30 for (int i = 0; i < cnt; ++i) {
32 }
33}
static constexpr int kS
constexpr SkColor SK_ColorCYAN
Definition: SkColor.h:143
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
sk_sp< SkImage > create_checkerboard_image(int w, int h, SkColor c1, SkColor c2, int checkSize)
Definition: ToolUtils.cpp:168

◆ set_cache_budget()

void set_cache_budget ( SkCanvas canvas,
int  approxImagesInBudget 
)

Definition at line 43 of file ImageCacheBudgetBench.cpp.

43 {
44 // This is inexact but we attempt to figure out a baseline number of resources GrContext needs
45 // to render an SkImage and add one additional resource for each image we'd like to fit.
46 auto context = canvas->recordingContext()->asDirectContext();
47 SkASSERT(context);
48 context->flushAndSubmit();
49 context->priv().getResourceCache()->purgeUnlockedResources(
52 make_images(&image, 1);
53 draw_image(canvas, image.get());
54 context->flushAndSubmit();
55 int baselineCount;
56 context->getResourceCacheUsage(&baselineCount, nullptr);
57 baselineCount -= 1; // for the image's textures.
58 context->setResourceCacheLimits(baselineCount + approxImagesInBudget, 1 << 30);
59 context->priv().getResourceCache()->purgeUnlockedResources(
61}
static void make_images(sk_sp< SkImage > imgs[], int cnt)
static void draw_image(SkCanvas *canvas, SkImage *img)
#define SkASSERT(cond)
Definition: SkAssert.h:116
virtual GrDirectContext * asDirectContext()
virtual GrRecordingContext * recordingContext() const
Definition: SkCanvas.cpp:1637
T * get() const
Definition: SkRefCnt.h:303
sk_sp< const SkImage > image
Definition: SkRecords.h:269

Variable Documentation

◆ kS

constexpr int kS = 25
staticconstexpr

These benchmarks were designed to measure changes to GrResourceCache's replacement policy

Definition at line 27 of file ImageCacheBudgetBench.cpp.