Flutter Engine
The Flutter Engine
Public Member Functions | Protected Member Functions | List of all members
SKPBench Class Reference

#include <SKPBench.h>

Inheritance diagram for SKPBench:
Benchmark SkRefCnt SkRefCntBase SKPAnimationBench

Public Member Functions

 SKPBench (const char *name, const SkPicture *, const SkIRect &devClip, SkScalar scale, bool doLooping)
 
 ~SKPBench () override
 
bool shouldLoop () const override
 
void getGpuStats (SkCanvas *, skia_private::TArray< SkString > *keys, skia_private::TArray< double > *values) override
 
bool getDMSAAStats (GrRecordingContext *) 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
 
const char * onGetUniqueName () override
 
void onPerCanvasPreDraw (SkCanvas *) override
 
void onPerCanvasPostDraw (SkCanvas *) override
 
bool isSuitableFor (Backend backend) override
 
void onDraw (int loops, SkCanvas *canvas) override
 
SkISize onGetSize () override
 
virtual void drawMPDPicture ()
 
virtual void drawPicture ()
 
const SkPicturepicture () const
 
const skia_private::TArray< sk_sp< SkSurface > > & surfaces () const
 
const SkTDArray< SkIRect > & tileRects () const
 
- 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

Runs an SkPicture as a benchmark by repeatedly drawing it scaled inside a device clip.

Definition at line 21 of file SKPBench.h.

Constructor & Destructor Documentation

◆ SKPBench()

SKPBench::SKPBench ( const char *  name,
const SkPicture pic,
const SkIRect devClip,
SkScalar  scale,
bool  doLooping 
)

Definition at line 32 of file SKPBench.cpp.

34 : fPic(SkRef(pic))
35 , fClip(clip)
36 , fScale(scale)
37 , fName(name)
38 , fDoLooping(doLooping) {
39 fUniqueName.printf("%s_%.2g", name, scale); // Scale makes this unqiue for perf.skia.org traces.
40}
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
Definition: SkPath.cpp:3892
static T * SkRef(T *obj)
Definition: SkRefCnt.h:132
void printf(const char format[],...) SK_PRINTF_LIKE(2
Definition: SkString.cpp:534
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
const Scalar scale

◆ ~SKPBench()

SKPBench::~SKPBench ( )
override

Definition at line 42 of file SKPBench.cpp.

42 {
43 for (int i = 0; i < fSurfaces.size(); ++i) {
44 fSurfaces[i]->unref();
45 }
46}
int size() const
Definition: SkTArray.h:421

Member Function Documentation

◆ drawMPDPicture()

void SKPBench::drawMPDPicture ( )
protectedvirtual

Reimplemented in SKPAnimationBench.

Definition at line 153 of file SKPBench.cpp.

153 {
154 // TODO: remove me
155}

◆ drawPicture()

void SKPBench::drawPicture ( )
protectedvirtual

Reimplemented in SKPAnimationBench.

Definition at line 157 of file SKPBench.cpp.

157 {
158 for (int j = 0; j < fTileRects.size(); ++j) {
159 const SkMatrix trans = SkMatrix::Translate(-fTileRects[j].fLeft / fScale,
160 -fTileRects[j].fTop / fScale);
161 fSurfaces[j]->getCanvas()->drawPicture(fPic.get(), &trans, nullptr);
162 }
163
164 for (int j = 0; j < fTileRects.size(); ++j) {
165 skgpu::Flush(fSurfaces[j].get());
166 }
167}
static SkMatrix Translate(SkScalar dx, SkScalar dy)
Definition: SkMatrix.h:91
int size() const
Definition: SkTDArray.h:138
T * get() const
Definition: SkRefCnt.h:303
const myers::Point & get(const myers::Segment &)
void Flush(SkSurface *surface)
Definition: GpuTools.h:25

◆ getDMSAAStats()

bool SKPBench::getDMSAAStats ( GrRecordingContext rContext)
overridevirtual

Reimplemented from Benchmark.

Definition at line 200 of file SKPBench.cpp.

200 {
201 if (!rContext || !rContext->asDirectContext()) {
202 return false;
203 }
204 // Clear the current DMSAA stats then do a single tiled draw that resets them to the specific
205 // values for our SKP.
206 rContext->asDirectContext()->flushAndSubmit();
207 rContext->priv().dmsaaStats() = {};
208 this->drawPicture(); // Draw tiled for DMSAA stats.
209 rContext->asDirectContext()->flush();
210 return true;
211}
virtual GrDirectContext * asDirectContext()
void flushAndSubmit(GrSyncCpu sync=GrSyncCpu::kNo)
GrSemaphoresSubmitted flush(const GrFlushInfo &info)
GrRecordingContextPriv priv()
virtual void drawPicture()
Definition: SKPBench.cpp:157

◆ getGpuStats()

void SKPBench::getGpuStats ( SkCanvas canvas,
skia_private::TArray< SkString > *  keys,
skia_private::TArray< double > *  values 
)
overridevirtual

Reimplemented from Benchmark.

Definition at line 184 of file SKPBench.cpp.

184 {
185 // we do a special single draw and then dump the key / value pairs
186 auto direct = canvas->recordingContext() ? canvas->recordingContext()->asDirectContext()
187 : nullptr;
188 if (!direct) {
189 return;
190 }
191
192 // TODO refactor this out if we want to test other subclasses of skpbench
193 direct->flushAndSubmit();
194 direct->freeGpuResources();
195 direct->resetContext();
196 direct->priv().getGpu()->resetShaderCacheForTesting();
197 draw_pic_for_stats(canvas, direct, fPic.get(), keys, values);
198}
static void draw_pic_for_stats(SkCanvas *canvas, GrDirectContext *dContext, const SkPicture *picture, TArray< SkString > *keys, TArray< double > *values)
Definition: SKPBench.cpp:169
virtual GrRecordingContext * recordingContext() const
Definition: SkCanvas.cpp:1637

◆ isSuitableFor()

bool SKPBench::isSuitableFor ( Backend  backend)
overrideprotectedvirtual

Reimplemented from Benchmark.

Definition at line 112 of file SKPBench.cpp.

112 {
114}
const char * backend

◆ onDraw()

void SKPBench::onDraw ( int  loops,
SkCanvas canvas 
)
overrideprotectedvirtual

Implements Benchmark.

Definition at line 120 of file SKPBench.cpp.

120 {
121 SkASSERT(fDoLooping || 1 == loops);
122 while (1) {
123 this->drawPicture();
124 if (0 == --loops) {
125 break;
126 }
127
128 // Ensure the gpu backends don't combine ops/tasks across draw loops. Also submit each work
129 // to the gpu so we are measuring the cost of gpu submission and not amortizing one
130 // submission across all loops.
131 auto direct = canvas->recordingContext() ? canvas->recordingContext()->asDirectContext()
132 : nullptr;
133 if (direct) {
134 direct->flushAndSubmit();
135 }
136
137#if defined(SK_GRAPHITE)
138 skgpu::graphite::Recorder* recorder = canvas->recorder();
139 if (recorder) {
140 std::unique_ptr<skgpu::graphite::Recording> recording = recorder->snap();
141 if (recording) {
143 info.fRecording = recording.get();
144 skgpu::graphite::Context* context = recorder->priv().context();
145 context->insertRecording(info);
146 context->submit();
147 }
148 }
149#endif
150 }
151}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
#define SkASSERT(cond)
Definition: SkAssert.h:116
virtual skgpu::graphite::Recorder * recorder() const
Definition: SkCanvas.cpp:1641
bool submit(SyncToCpu=SyncToCpu::kNo)
Definition: Context.cpp:162
bool insertRecording(const InsertRecordingInfo &)
Definition: Context.cpp:156
std::unique_ptr< Recording > snap()
Definition: Recorder.cpp:159

◆ onGetName()

const char * SKPBench::onGetName ( )
overrideprotectedvirtual

Implements Benchmark.

Definition at line 48 of file SKPBench.cpp.

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

◆ onGetSize()

SkISize SKPBench::onGetSize ( )
overrideprotectedvirtual

Reimplemented from Benchmark.

Definition at line 116 of file SKPBench.cpp.

116 {
117 return SkISize::Make(fClip.width(), fClip.height());
118}
constexpr int32_t height() const
Definition: SkRect.h:165
constexpr int32_t width() const
Definition: SkRect.h:158
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20

◆ onGetUniqueName()

const char * SKPBench::onGetUniqueName ( )
overrideprotectedvirtual

Reimplemented from Benchmark.

Definition at line 52 of file SKPBench.cpp.

52 {
53 return fUniqueName.c_str();
54}

◆ onPerCanvasPostDraw()

void SKPBench::onPerCanvasPostDraw ( SkCanvas canvas)
overrideprotectedvirtual

Reimplemented from Benchmark.

Definition at line 99 of file SKPBench.cpp.

99 {
100 // Draw the last set of tiles into the main canvas in case we're
101 // saving the images
102 for (int i = 0; i < fTileRects.size(); ++i) {
103 sk_sp<SkImage> image(fSurfaces[i]->makeImageSnapshot());
104 canvas->drawImage(image,
105 SkIntToScalar(fTileRects[i].fLeft), SkIntToScalar(fTileRects[i].fTop));
106 }
107
108 fSurfaces.clear();
109 fTileRects.clear();
110}
#define SkIntToScalar(x)
Definition: SkScalar.h:57
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition: SkCanvas.h:1528
void clear()
Definition: SkTDArray.h:175
sk_sp< const SkImage > image
Definition: SkRecords.h:269

◆ onPerCanvasPreDraw()

void SKPBench::onPerCanvasPreDraw ( SkCanvas canvas)
overrideprotectedvirtual

Reimplemented from Benchmark.

Definition at line 56 of file SKPBench.cpp.

56 {
58 bounds.intersect(fClip);
59 bounds.intersect(fPic->cullRect().roundOut());
60 SkAssertResult(!bounds.isEmpty());
61
62#if defined(SK_GRAPHITE)
63 const bool gpu = canvas->recordingContext() != nullptr || canvas->recorder() != nullptr;
64#else
65 const bool gpu = canvas->recordingContext() != nullptr;
66#endif
67 int tileW = gpu ? FLAGS_GPUbenchTileW : FLAGS_CPUbenchTileW,
68 tileH = gpu ? FLAGS_GPUbenchTileH : FLAGS_CPUbenchTileH;
69
70 tileW = std::min(tileW, bounds.width());
71 tileH = std::min(tileH, bounds.height());
72
73 int xTiles = SkScalarCeilToInt(bounds.width() / SkIntToScalar(tileW));
74 int yTiles = SkScalarCeilToInt(bounds.height() / SkIntToScalar(tileH));
75
76 fSurfaces.reserve_exact(fSurfaces.size() + (xTiles * yTiles));
77 fTileRects.reserve(xTiles * yTiles);
78
79 SkImageInfo ii = canvas->imageInfo().makeWH(tileW, tileH);
80
81 for (int y = bounds.fTop; y < bounds.fBottom; y += tileH) {
82 for (int x = bounds.fLeft; x < bounds.fRight; x += tileW) {
83 const SkIRect tileRect = SkIRect::MakeXYWH(x, y, tileW, tileH);
84 *fTileRects.append() = tileRect;
85 fSurfaces.emplace_back(canvas->makeSurface(ii));
86
87 // Never want the contents of a tile to include stuff the parent
88 // canvas clips out
90 clip.offset(-SkIntToScalar(tileRect.fLeft), -SkIntToScalar(tileRect.fTop));
91 fSurfaces.back()->getCanvas()->clipRect(clip);
92
93 fSurfaces.back()->getCanvas()->setMatrix(canvas->getLocalToDevice());
94 fSurfaces.back()->getCanvas()->scale(fScale, fScale);
95 }
96 }
97}
SkAssertResult(font.textToGlyphs("Hello", 5, SkTextEncoding::kUTF8, glyphs, std::size(glyphs))==count)
#define SkScalarCeilToInt(x)
Definition: SkScalar.h:36
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1361
sk_sp< SkSurface > makeSurface(const SkImageInfo &info, const SkSurfaceProps *props=nullptr)
Definition: SkCanvas.cpp:1195
SkM44 getLocalToDevice() const
Definition: SkCanvas.cpp:1633
SkIRect getDeviceClipBounds() const
Definition: SkCanvas.cpp:1607
void setMatrix(const SkM44 &matrix)
Definition: SkCanvas.cpp:1349
void scale(SkScalar sx, SkScalar sy)
Definition: SkCanvas.cpp:1289
SkImageInfo imageInfo() const
Definition: SkCanvas.cpp:1206
void offset(SkScalar dx, SkScalar dy, SkPath *dst) const
Definition: SkPath.cpp:1691
virtual SkRect cullRect() const =0
SkCanvas * getCanvas()
Definition: SkSurface.cpp:82
void reserve(int n)
Definition: SkTDArray.h:187
T * append()
Definition: SkTDArray.h:191
void reserve_exact(int n)
Definition: SkTArray.h:181
T & emplace_back(Args &&... args)
Definition: SkTArray.h:248
static float min(float r, float g, float b)
Definition: hsl.cpp:48
double y
double x
Optional< SkRect > bounds
Definition: SkRecords.h:189
Definition: SkRect.h:32
int32_t fTop
smaller y-axis bounds
Definition: SkRect.h:34
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
Definition: SkRect.h:104
int32_t fLeft
smaller x-axis bounds
Definition: SkRect.h:33
SkImageInfo makeWH(int newWidth, int newHeight) const
Definition: SkImageInfo.h:444
static SkRect Make(const SkISize &size)
Definition: SkRect.h:669
void roundOut(SkIRect *dst) const
Definition: SkRect.h:1241

◆ picture()

const SkPicture * SKPBench::picture ( ) const
inlineprotected

Definition at line 48 of file SKPBench.h.

48{ return fPic.get(); }

◆ shouldLoop()

bool SKPBench::shouldLoop ( ) const
inlineoverridevirtual

Reimplemented from Benchmark.

Definition at line 27 of file SKPBench.h.

27 {
28 return fDoLooping;
29 }

◆ surfaces()

const skia_private::TArray< sk_sp< SkSurface > > & SKPBench::surfaces ( ) const
inlineprotected

Definition at line 49 of file SKPBench.h.

49{ return fSurfaces; }

◆ tileRects()

const SkTDArray< SkIRect > & SKPBench::tileRects ( ) const
inlineprotected

Definition at line 50 of file SKPBench.h.

50{ return fTileRects; }

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