Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | Protected Types | Protected Member Functions | Protected Attributes | List of all members
BulkRectBench< kRectCount, kLayout, kImageMode, kDrawMode > Class Template Reference
Inheritance diagram for BulkRectBench< kRectCount, kLayout, kImageMode, kDrawMode >:
Benchmark SkRefCnt SkRefCntBase

Public Member Functions

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
 

Static Public Attributes

static constexpr int kWidth = 1024
 
static constexpr int kHeight = 1024
 
static constexpr int kImageCount
 

Protected Types

using INHERITED = Benchmark
 

Protected Member Functions

void computeName ()
 
void drawImagesBatch (SkCanvas *canvas) const
 
void drawImagesRef (SkCanvas *canvas) const
 
void drawSolidColorsBatch (SkCanvas *canvas) const
 
void drawSolidColorsRef (SkCanvas *canvas) const
 
const char * onGetName () override
 
void onDelayedSetup () override
 
void onPerCanvasPreDraw (SkCanvas *canvas) override
 
void onPerCanvasPostDraw (SkCanvas *canvas) override
 
void onDraw (int loops, SkCanvas *canvas) override
 
SkISize onGetSize () override
 
- Protected Member Functions inherited from Benchmark
void setUnits (int units)
 
virtual void setupPaint (SkPaint *paint)
 
virtual const char * onGetUniqueName ()
 
virtual void onPreDraw (SkCanvas *)
 
virtual void onPostDraw (SkCanvas *)
 

Protected Attributes

SkRect fRects [kRectCount]
 
sk_sp< SkImagefImages [kImageCount]
 
SkColor4f fColors [kRectCount]
 
SkString fName
 

Additional Inherited Members

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

Detailed Description

template<int kRectCount, RectangleLayout kLayout, ImageMode kImageMode, DrawMode kDrawMode>
class BulkRectBench< kRectCount, kLayout, kImageMode, kDrawMode >

Definition at line 42 of file BulkRectBench.cpp.

Member Typedef Documentation

◆ INHERITED

template<int kRectCount, RectangleLayout kLayout, ImageMode kImageMode, DrawMode kDrawMode>
using BulkRectBench< kRectCount, kLayout, kImageMode, kDrawMode >::INHERITED = Benchmark
protected

Definition at line 269 of file BulkRectBench.cpp.

Member Function Documentation

◆ computeName()

template<int kRectCount, RectangleLayout kLayout, ImageMode kImageMode, DrawMode kDrawMode>
void BulkRectBench< kRectCount, kLayout, kImageMode, kDrawMode >::computeName ( )
inlineprotected

Definition at line 70 of file BulkRectBench.cpp.

70 {
71 fName = "bulkrect";
72 fName.appendf("_%d", kRectCount);
73 if (kLayout == RectangleLayout::kRandom) {
74 fName.append("_random");
75 } else {
76 fName.append("_grid");
77 }
78 if (kImageMode == ImageMode::kShared) {
79 fName.append("_sharedimage");
80 } else if (kImageMode == ImageMode::kUnique) {
81 fName.append("_uniqueimages");
82 } else {
83 fName.append("_solidcolor");
84 }
85 if (kDrawMode == DrawMode::kBatch) {
86 fName.append("_batch");
87 } else if (kDrawMode == DrawMode::kRef) {
88 fName.append("_ref");
89 } else {
90 fName.append("_quad");
91 }
92 }
void append(const char text[])
Definition SkString.h:203
void void void appendf(const char format[],...) SK_PRINTF_LIKE(2
Definition SkString.cpp:550

◆ drawImagesBatch()

template<int kRectCount, RectangleLayout kLayout, ImageMode kImageMode, DrawMode kDrawMode>
void BulkRectBench< kRectCount, kLayout, kImageMode, kDrawMode >::drawImagesBatch ( SkCanvas canvas) const
inlineprotected

Definition at line 94 of file BulkRectBench.cpp.

94 {
95 SkASSERT(kImageMode != ImageMode::kNone);
96 SkASSERT(kDrawMode == DrawMode::kBatch);
97
98 SkCanvas::ImageSetEntry batch[kRectCount];
99 for (int i = 0; i < kRectCount; ++i) {
100 int imageIndex = kImageMode == ImageMode::kShared ? 0 : i;
101 batch[i].fImage = fImages[imageIndex];
102 batch[i].fSrcRect = SkRect::MakeIWH(fImages[imageIndex]->width(),
103 fImages[imageIndex]->height());
104 batch[i].fDstRect = fRects[i];
106 }
107
109 paint.setAntiAlias(true);
110
111 canvas->experimental_DrawEdgeAAImageSet(batch, kRectCount, nullptr, nullptr,
114 }
#define SkASSERT(cond)
Definition SkAssert.h:116
SkRect fRects[kRectCount]
sk_sp< SkImage > fImages[kImageCount]
@ kFast_SrcRectConstraint
sample outside bounds; faster
Definition SkCanvas.h:1543
void experimental_DrawEdgeAAImageSet(const ImageSetEntry imageSet[], int cnt, const SkPoint dstClips[], const SkMatrix preViewMatrices[], const SkSamplingOptions &, const SkPaint *paint=nullptr, SrcRectConstraint constraint=kStrict_SrcRectConstraint)
@ kAll_QuadAAFlags
Definition SkCanvas.h:1665
const Paint & paint
int32_t height
int32_t width
sk_sp< const SkImage > fImage
Definition SkCanvas.h:1681
static SkRect MakeIWH(int w, int h)
Definition SkRect.h:623

◆ drawImagesRef()

template<int kRectCount, RectangleLayout kLayout, ImageMode kImageMode, DrawMode kDrawMode>
void BulkRectBench< kRectCount, kLayout, kImageMode, kDrawMode >::drawImagesRef ( SkCanvas canvas) const
inlineprotected

Definition at line 116 of file BulkRectBench.cpp.

116 {
117 SkASSERT(kImageMode != ImageMode::kNone);
118 SkASSERT(kDrawMode == DrawMode::kRef);
119
121 paint.setAntiAlias(true);
122
123 for (int i = 0; i < kRectCount; ++i) {
124 int imageIndex = kImageMode == ImageMode::kShared ? 0 : i;
125 SkRect srcRect = SkRect::MakeIWH(fImages[imageIndex]->width(),
126 fImages[imageIndex]->height());
127 canvas->drawImageRect(fImages[imageIndex].get(), srcRect, fRects[i],
130 }
131 }
void drawImageRect(const SkImage *, const SkRect &src, const SkRect &dst, const SkSamplingOptions &, const SkPaint *, SrcRectConstraint)
const myers::Point & get(const myers::Segment &)

◆ drawSolidColorsBatch()

template<int kRectCount, RectangleLayout kLayout, ImageMode kImageMode, DrawMode kDrawMode>
void BulkRectBench< kRectCount, kLayout, kImageMode, kDrawMode >::drawSolidColorsBatch ( SkCanvas canvas) const
inlineprotected

Definition at line 133 of file BulkRectBench.cpp.

133 {
134 SkASSERT(kImageMode == ImageMode::kNone);
135 SkASSERT(kDrawMode == DrawMode::kBatch);
136
137 auto context = canvas->recordingContext();
138 SkASSERT(context);
139
140 GrQuadSetEntry batch[kRectCount];
141 for (int i = 0; i < kRectCount; ++i) {
142 batch[i].fRect = fRects[i];
143 batch[i].fColor = fColors[i].premul();
144 batch[i].fLocalMatrix = SkMatrix::I();
145 batch[i].fAAFlags = GrQuadAAFlags::kAll;
146 }
147
149 paint.setColor(SK_ColorWHITE);
150 paint.setAntiAlias(true);
151
153 SkMatrix view = canvas->getLocalToDeviceAs3x3();
154 SkSurfaceProps props;
155 GrPaint grPaint;
156 SkPaintToGrPaint(context, sdc->colorInfo(), paint, view, props, &grPaint);
157 sdc->drawQuadSet(nullptr, std::move(grPaint), view, batch, kRectCount);
158 }
constexpr SkColor SK_ColorWHITE
Definition SkColor.h:122
bool SkPaintToGrPaint(GrRecordingContext *context, const GrColorInfo &dstColorInfo, const SkPaint &skPaint, const SkMatrix &ctm, const SkSurfaceProps &surfaceProps, GrPaint *grPaint)
Definition SkGr.cpp:553
SkColor4f fColors[kRectCount]
SkMatrix getLocalToDeviceAs3x3() const
Definition SkCanvas.h:2222
virtual GrRecordingContext * recordingContext() const
static const SkMatrix & I()
SurfaceDrawContext * TopDeviceSurfaceDrawContext(const SkCanvas *canvas)
Definition GrCanvas.cpp:20
SkPMColor4f fColor
Definition GrOpsTypes.h:20
GrQuadAAFlags fAAFlags
Definition GrOpsTypes.h:22
SkMatrix fLocalMatrix
Definition GrOpsTypes.h:21

◆ drawSolidColorsRef()

template<int kRectCount, RectangleLayout kLayout, ImageMode kImageMode, DrawMode kDrawMode>
void BulkRectBench< kRectCount, kLayout, kImageMode, kDrawMode >::drawSolidColorsRef ( SkCanvas canvas) const
inlineprotected

Definition at line 160 of file BulkRectBench.cpp.

160 {
161 SkASSERT(kImageMode == ImageMode::kNone);
162 SkASSERT(kDrawMode == DrawMode::kRef || kDrawMode == DrawMode::kQuad);
163
165 paint.setAntiAlias(true);
166 for (int i = 0; i < kRectCount; ++i) {
167 if (kDrawMode == DrawMode::kRef) {
168 paint.setColor4f(fColors[i]);
169 canvas->drawRect(fRects[i], paint);
170 } else {
173 }
174 }
175 }
@ kSrcOver
r = s + (1-sa)*d
void drawRect(const SkRect &rect, const SkPaint &paint)
void experimental_DrawEdgeAAQuad(const SkRect &rect, const SkPoint clip[4], QuadAAFlags aaFlags, const SkColor4f &color, SkBlendMode mode)

◆ isSuitableFor()

template<int kRectCount, RectangleLayout kLayout, ImageMode kImageMode, DrawMode kDrawMode>
bool BulkRectBench< kRectCount, kLayout, kImageMode, kDrawMode >::isSuitableFor ( Backend  backend)
inlineoverridevirtual

Reimplemented from Benchmark.

Definition at line 54 of file BulkRectBench.cpp.

54 {
55 if (kDrawMode == DrawMode::kBatch && kImageMode == ImageMode::kNone) {
56 // Currently the bulk color quad API is only available on
57 // skgpu::ganesh::SurfaceDrawContext
58 return backend == Backend::kGanesh;
59 } else {
60 return this->INHERITED::isSuitableFor(backend);
61 }
62 }
const char * backend
virtual bool isSuitableFor(Backend backend)
Definition Benchmark.h:55

◆ onDelayedSetup()

template<int kRectCount, RectangleLayout kLayout, ImageMode kImageMode, DrawMode kDrawMode>
void BulkRectBench< kRectCount, kLayout, kImageMode, kDrawMode >::onDelayedSetup ( )
inlineoverrideprotectedvirtual

Reimplemented from Benchmark.

Definition at line 184 of file BulkRectBench.cpp.

184 {
185 static constexpr SkScalar kMinRectSize = 0.2f;
186 static constexpr SkScalar kMaxRectSize = 300.f;
187
188 SkRandom rand;
189 for (int i = 0; i < kRectCount; i++) {
190 if (kLayout == RectangleLayout::kRandom) {
191 SkScalar w = rand.nextF() * (kMaxRectSize - kMinRectSize) + kMinRectSize;
192 SkScalar h = rand.nextF() * (kMaxRectSize - kMinRectSize) + kMinRectSize;
193
194 SkScalar x = rand.nextF() * (kWidth - w);
195 SkScalar y = rand.nextF() * (kHeight - h);
196
197 fRects[i].setXYWH(x, y, w, h);
198 } else {
199 int gridSize = SkScalarCeilToInt(SkScalarSqrt(kRectCount));
200 SkASSERT(gridSize * gridSize >= kRectCount);
201
202 SkScalar w = (kWidth - 1.f) / gridSize;
203 SkScalar h = (kHeight - 1.f) / gridSize;
204
205 SkScalar x = (i % gridSize) * w + 0.5f; // Offset to ensure AA doesn't get disabled
206 SkScalar y = (i / gridSize) * h + 0.5f;
207
208 fRects[i].setXYWH(x, y, w, h);
209 }
210
211 // Make sure we don't extend outside the render target, don't want to include clipping
212 // in the benchmark.
214
215 fColors[i] = {rand.nextF(), rand.nextF(), rand.nextF(), 1.f};
216 }
217 }
static bool contains(const SkRect &r, SkPoint p)
#define SkScalarCeilToInt(x)
Definition SkScalar.h:36
#define SkScalarSqrt(x)
Definition SkScalar.h:42
static constexpr int kHeight
static constexpr int kWidth
float nextF()
Definition SkRandom.h:55
float SkScalar
Definition extension.cpp:12
double y
double x
SkScalar w
SkScalar h
void setXYWH(float x, float y, float width, float height)
Definition SkRect.h:931
static constexpr SkRect MakeWH(float w, float h)
Definition SkRect.h:609

◆ onDraw()

template<int kRectCount, RectangleLayout kLayout, ImageMode kImageMode, DrawMode kDrawMode>
void BulkRectBench< kRectCount, kLayout, kImageMode, kDrawMode >::onDraw ( int  loops,
SkCanvas canvas 
)
inlineoverrideprotectedvirtual

Implements Benchmark.

Definition at line 247 of file BulkRectBench.cpp.

247 {
248 for (int i = 0; i < loops; i++) {
249 if (kImageMode == ImageMode::kNone) {
250 if (kDrawMode == DrawMode::kBatch) {
251 this->drawSolidColorsBatch(canvas);
252 } else {
253 this->drawSolidColorsRef(canvas);
254 }
255 } else {
256 if (kDrawMode == DrawMode::kBatch) {
257 this->drawImagesBatch(canvas);
258 } else {
259 this->drawImagesRef(canvas);
260 }
261 }
262 }
263 }
void drawSolidColorsRef(SkCanvas *canvas) const
void drawSolidColorsBatch(SkCanvas *canvas) const
void drawImagesBatch(SkCanvas *canvas) const
void drawImagesRef(SkCanvas *canvas) const

◆ onGetName()

template<int kRectCount, RectangleLayout kLayout, ImageMode kImageMode, DrawMode kDrawMode>
const char * BulkRectBench< kRectCount, kLayout, kImageMode, kDrawMode >::onGetName ( )
inlineoverrideprotectedvirtual

Implements Benchmark.

Definition at line 177 of file BulkRectBench.cpp.

177 {
178 if (fName.isEmpty()) {
179 this->computeName();
180 }
181 return fName.c_str();
182 }
bool isEmpty() const
Definition SkString.h:130
const char * c_str() const
Definition SkString.h:133

◆ onGetSize()

template<int kRectCount, RectangleLayout kLayout, ImageMode kImageMode, DrawMode kDrawMode>
SkISize BulkRectBench< kRectCount, kLayout, kImageMode, kDrawMode >::onGetSize ( )
inlineoverrideprotectedvirtual

Reimplemented from Benchmark.

Definition at line 265 of file BulkRectBench.cpp.

265 {
266 return { kWidth, kHeight };
267 }

◆ onPerCanvasPostDraw()

template<int kRectCount, RectangleLayout kLayout, ImageMode kImageMode, DrawMode kDrawMode>
void BulkRectBench< kRectCount, kLayout, kImageMode, kDrawMode >::onPerCanvasPostDraw ( SkCanvas canvas)
inlineoverrideprotectedvirtual

Reimplemented from Benchmark.

Definition at line 238 of file BulkRectBench.cpp.

238 {
239 for (int i = 0; i < kImageCount; ++i) {
240 // For Vulkan we need to make sure the bench isn't holding onto any refs to the
241 // GrContext when we go to delete the vulkan context (which happens before the bench is
242 // deleted). So reset all the images here so they aren't holding GrContext refs.
243 fImages[i].reset();
244 }
245 }
static constexpr int kImageCount
void reset(T *ptr=nullptr)
Definition SkRefCnt.h:310

◆ onPerCanvasPreDraw()

template<int kRectCount, RectangleLayout kLayout, ImageMode kImageMode, DrawMode kDrawMode>
void BulkRectBench< kRectCount, kLayout, kImageMode, kDrawMode >::onPerCanvasPreDraw ( SkCanvas canvas)
inlineoverrideprotectedvirtual

Reimplemented from Benchmark.

Definition at line 219 of file BulkRectBench.cpp.

219 {
220 // Push the skimages to the GPU when using the GPU backend so that the texture creation is
221 // not part of the bench measurements. Always remake the images since they are so simple,
222 // and since they are context-specific, this works when the bench runs multiple GPU backends
223 auto direct = GrAsDirectContext(canvas->recordingContext());
224 for (int i = 0; i < kImageCount; ++i) {
225 SkBitmap bm;
226 bm.allocN32Pixels(256, 256);
227 bm.eraseColor(fColors[i].toSkColor());
228 auto image = bm.asImage();
229
230 if (direct) {
232 } else {
233 fImages[i] = std::move(image);
234 }
235 }
236 }
static GrDirectContext * GrAsDirectContext(GrContext_Base *base)
sk_sp< SkImage > asImage() const
Definition SkBitmap.cpp:645
void allocN32Pixels(int width, int height, bool isOpaque=false)
Definition SkBitmap.cpp:232
void eraseColor(SkColor4f) const
Definition SkBitmap.cpp:442
sk_sp< SkImage > image
Definition examples.cpp:29
SK_API sk_sp< SkImage > TextureFromImage(GrDirectContext *, const SkImage *, skgpu::Mipmapped=skgpu::Mipmapped::kNo, skgpu::Budgeted=skgpu::Budgeted::kYes)

Member Data Documentation

◆ fColors

template<int kRectCount, RectangleLayout kLayout, ImageMode kImageMode, DrawMode kDrawMode>
SkColor4f BulkRectBench< kRectCount, kLayout, kImageMode, kDrawMode >::fColors[kRectCount]
protected

Definition at line 67 of file BulkRectBench.cpp.

◆ fImages

template<int kRectCount, RectangleLayout kLayout, ImageMode kImageMode, DrawMode kDrawMode>
sk_sp<SkImage> BulkRectBench< kRectCount, kLayout, kImageMode, kDrawMode >::fImages[kImageCount]
protected

Definition at line 66 of file BulkRectBench.cpp.

◆ fName

template<int kRectCount, RectangleLayout kLayout, ImageMode kImageMode, DrawMode kDrawMode>
SkString BulkRectBench< kRectCount, kLayout, kImageMode, kDrawMode >::fName
protected

Definition at line 68 of file BulkRectBench.cpp.

◆ fRects

template<int kRectCount, RectangleLayout kLayout, ImageMode kImageMode, DrawMode kDrawMode>
SkRect BulkRectBench< kRectCount, kLayout, kImageMode, kDrawMode >::fRects[kRectCount]
protected

Definition at line 65 of file BulkRectBench.cpp.

◆ kHeight

template<int kRectCount, RectangleLayout kLayout, ImageMode kImageMode, DrawMode kDrawMode>
constexpr int BulkRectBench< kRectCount, kLayout, kImageMode, kDrawMode >::kHeight = 1024
inlinestaticconstexpr

Definition at line 48 of file BulkRectBench.cpp.

◆ kImageCount

template<int kRectCount, RectangleLayout kLayout, ImageMode kImageMode, DrawMode kDrawMode>
constexpr int BulkRectBench< kRectCount, kLayout, kImageMode, kDrawMode >::kImageCount
inlinestaticconstexpr
Initial value:
= kImageMode == ImageMode::kShared ?
1 : (kImageMode == ImageMode::kNone ? 0 : kRectCount)

Definition at line 51 of file BulkRectBench.cpp.

◆ kWidth

template<int kRectCount, RectangleLayout kLayout, ImageMode kImageMode, DrawMode kDrawMode>
constexpr int BulkRectBench< kRectCount, kLayout, kImageMode, kDrawMode >::kWidth = 1024
inlinestaticconstexpr

Definition at line 47 of file BulkRectBench.cpp.


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