Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Private Member Functions | List of all members
ImageCycle Class Reference
Inheritance diagram for ImageCycle:
Benchmark SkRefCnt SkRefCntBase

Public Member Functions

 ImageCycle (int imageCnt, int repeatCnt)
 
bool isSuitableFor (Backend backend) override
 
- Public Member Functions inherited from Benchmark
 Benchmark ()
 
const char * getName ()
 
const char * getUniqueName ()
 
SkISize getSize ()
 
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 *) 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 * onGetUniqueName ()
 
virtual void onDelayedSetup ()
 
virtual void onPreDraw (SkCanvas *)
 
virtual void onPostDraw (SkCanvas *)
 

Private Member Functions

SkISize onGetSize () override
 

Additional Inherited Members

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

Detailed Description

Draws a small set of small images multiple times each with no overlaps so that each image could be batched. This was originally added to detect regressions as TextureOp is refactored to use "dynamic state" for texture bindings. Everything is kept small as we're mostly interested in CPU overhead.

Definition at line 25 of file ImageCycleBench.cpp.

Constructor & Destructor Documentation

◆ ImageCycle()

ImageCycle::ImageCycle ( int  imageCnt,
int  repeatCnt 
)
inline

imageCnt is the number of images and repeat cnt is how many times each image is drawn per logical "frame."

Definition at line 31 of file ImageCycleBench.cpp.

31 : fImageCnt(imageCnt), fRepeatCnt(repeatCnt) {
32 fName.appendf("image_cycle_image_cnt_%d_repeat_cnt_%d", fImageCnt, fRepeatCnt);
33 }
void void void appendf(const char format[],...) SK_PRINTF_LIKE(2
Definition SkString.cpp:550

Member Function Documentation

◆ isSuitableFor()

bool ImageCycle::isSuitableFor ( Backend  backend)
inlineoverridevirtual

Reimplemented from Benchmark.

Definition at line 35 of file ImageCycleBench.cpp.

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

◆ onDraw()

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

Implements Benchmark.

Definition at line 60 of file ImageCycleBench.cpp.

60 {
62 paint.setAntiAlias(true);
63 static constexpr SkScalar kPad = 2;
64 // To avoid tripping up bounds tracking we position the draws such that all the
65 // draws of image 0 are above those of image 1, etc.
66 static const int imagesPerRow =
67 SkScalarFloorToInt(kDeviceSize.fWidth / (kImageSize.fWidth + kPad));
68 int rowsPerImage = SkScalarCeilToInt((SkScalar)fRepeatCnt / imagesPerRow);
69 for (int l = 0; l < loops; ++l) {
70 for (int r = 0; r < fRepeatCnt; ++r) {
71 for (int i = 0; i < fImageCnt; ++i) {
72 SkScalar imageYOffset = i * rowsPerImage * (kImageSize.fHeight + kPad);
73 SkScalar rowYOffset = (r / imagesPerRow) * (kImageSize.fHeight + kPad);
74 SkScalar x = (r % imagesPerRow) * (kImageSize.fWidth + kPad);
75 canvas->drawImage(fImages[i].get(), x, imageYOffset + rowYOffset,
77 }
78 }
79 // Prevent any batching between "frames".
81 }
82 }
#define SkScalarCeilToInt(x)
Definition SkScalar.h:36
#define SkScalarFloorToInt(x)
Definition SkScalar.h:35
constexpr int kPad
SkSurface * getSurface() const
Definition SkCanvas.cpp:369
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition SkCanvas.h:1528
const Paint & paint
float SkScalar
Definition extension.cpp:12
double x
const myers::Point & get(const myers::Segment &)
void FlushAndSubmit(SkSurface *surface)
Definition GpuTools.h:34
int32_t fHeight
Definition SkSize.h:18
int32_t fWidth
Definition SkSize.h:17

◆ onGetName()

const char * ImageCycle::onGetName ( )
inlineoverrideprotectedvirtual

Implements Benchmark.

Definition at line 38 of file ImageCycleBench.cpp.

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

◆ onGetSize()

SkISize ImageCycle::onGetSize ( )
inlineoverrideprivatevirtual

Reimplemented from Benchmark.

Definition at line 85 of file ImageCycleBench.cpp.

85{ return {kDeviceSize.fWidth, kDeviceSize.fHeight}; }

◆ onPerCanvasPostDraw()

void ImageCycle::onPerCanvasPostDraw ( SkCanvas )
inlineoverrideprotectedvirtual

Reimplemented from Benchmark.

Definition at line 58 of file ImageCycleBench.cpp.

58{ fImages.reset(); }

◆ onPerCanvasPreDraw()

void ImageCycle::onPerCanvasPreDraw ( SkCanvas canvas)
inlineoverrideprotectedvirtual

Reimplemented from Benchmark.

Definition at line 40 of file ImageCycleBench.cpp.

40 {
41 auto ii = SkImageInfo::Make(kImageSize.fWidth, kImageSize.fHeight, kRGBA_8888_SkColorType,
42 kPremul_SkAlphaType, nullptr);
43 SkRandom random;
44 fImages = std::make_unique<sk_sp<SkImage>[]>(fImageCnt);
45 for (int i = 0; i < fImageCnt; ++i) {
46 auto surf = canvas->makeSurface(ii);
47 SkColor color = random.nextU();
48 surf->getCanvas()->clear(color);
50 paint.setColor(~color);
51 paint.setBlendMode(SkBlendMode::kSrc);
52 surf->getCanvas()->drawRect(
53 SkRect::MakeLTRB(1, 1, kImageSize.fWidth - 1, kImageSize.fHeight - 1), paint);
54 fImages[i] = surf->makeImageSnapshot();
55 }
56 }
SkColor4f color
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition SkAlphaType.h:29
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition SkColorType.h:24
uint32_t SkColor
Definition SkColor.h:37
sk_sp< SkSurface > makeSurface(const SkImageInfo &info, const SkSurfaceProps *props=nullptr)
uint32_t nextU()
Definition SkRandom.h:42
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition SkRect.h:646

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