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

Public Member Functions

 CompositingImages (SkISize imageSize, SkISize tileSize, SkISize tileGridSize, ClampingMode clampMode, TransformMode transformMode, int layerCnt)
 
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 *) 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

Simulates drawing layers images in a grid a la a tile based compositor.

Definition at line 48 of file CompositingImagesBench.cpp.

Constructor & Destructor Documentation

◆ CompositingImages()

CompositingImages::CompositingImages ( SkISize  imageSize,
SkISize  tileSize,
SkISize  tileGridSize,
ClampingMode  clampMode,
TransformMode  transformMode,
int  layerCnt 
)
inline

Definition at line 50 of file CompositingImagesBench.cpp.

52 : fImageSize(imageSize)
53 , fTileSize(tileSize)
54 , fTileGridSize(tileGridSize)
55 , fClampMode(clampMode)
56 , fTransformMode(transformMode)
57 , fLayerCnt(layerCnt) {
58 fName.appendf("compositing_images_tile_size_%dx%d_grid_%dx%d_layers_%d",
59 fTileSize.fWidth, fTileSize.fHeight, fTileGridSize.fWidth,
60 fTileGridSize.fHeight, fLayerCnt);
61 if (imageSize != tileSize) {
62 fName.appendf("_image_%dx%d", imageSize.fWidth, imageSize.fHeight);
63 }
64 switch(clampMode) {
66 fName.append("_fast");
67 break;
69 fName.append("_strict");
70 break;
72 fName.append("_chrome");
73 break;
75 fName.append("_chrome_optimal");
76 break;
77 }
78 switch(transformMode) {
80 break;
82 fName.append("_subpixel");
83 break;
85 fName.append("_rotated");
86 break;
88 fName.append("_persp");
89 break;
90 }
91 }
@ kChromeTiling_RowMajor
void append(const char text[])
Definition: SkString.h:203
void void void appendf(const char format[],...) SK_PRINTF_LIKE(2
Definition: SkString.cpp:550
int32_t fHeight
Definition: SkSize.h:18
int32_t fWidth
Definition: SkSize.h:17

Member Function Documentation

◆ isSuitableFor()

bool CompositingImages::isSuitableFor ( Backend  backend)
inlineoverridevirtual

Reimplemented from Benchmark.

Definition at line 93 of file CompositingImagesBench.cpp.

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

◆ onDraw()

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

Implements Benchmark.

Definition at line 123 of file CompositingImagesBench.cpp.

123 {
125 paint.setAntiAlias(true);
127
128 canvas->save();
129 canvas->concat(this->getTransform());
130
131 for (int loop = 0; loop < loops; ++loop) {
132 for (int l = 0; l < fLayerCnt; ++l) {
134 fTileGridSize.fWidth * fTileGridSize.fHeight);
135
136 if (fClampMode == ClampingMode::kAlwaysFast ||
137 fClampMode == ClampingMode::kAlwaysStrict) {
138 // Simple 2D for loop, submit everything as a single batch
139 int i = 0;
140 for (int y = 0; y < fTileGridSize.fHeight; ++y) {
141 for (int x = 0; x < fTileGridSize.fWidth; ++x) {
142 set[i++] = this->getEntry(x, y, l);
143 }
144 }
145
146 SkCanvas::SrcRectConstraint constraint =
147 fClampMode == ClampingMode::kAlwaysFast
150 canvas->experimental_DrawEdgeAAImageSet(set.get(), i, nullptr, nullptr,
151 sampling, &paint, constraint);
152 } else if (fClampMode == ClampingMode::kChromeTiling_RowMajor) {
153 // Same tile order, but break batching between fast and strict sections, and
154 // adjust bottom and right tiles to encode content area distinct from src rect.
155 int i = 0;
156 for (int y = 0; y < fTileGridSize.fHeight - 1; ++y) {
157 int rowStart = i;
158 for (int x = 0; x < fTileGridSize.fWidth - 1; ++x) {
159 set[i++] = this->getEntry(x, y, l);
160 }
161 // Flush "fast" horizontal row
162 canvas->experimental_DrawEdgeAAImageSet(set.get() + rowStart,
163 fTileGridSize.fWidth - 1, nullptr, nullptr, sampling, &paint,
165 // Then flush a single adjusted entry for the right edge
166 SkPoint dstQuad[4];
167 set[i++] = this->getAdjustedEntry(fTileGridSize.fWidth - 1, y, l, dstQuad);
169 set.get() + fTileGridSize.fWidth - 1, 1, dstQuad, nullptr, sampling,
171 }
172 // For last row, accumulate it as a single strict batch
173 int rowStart = i;
174 AutoTArray<SkPoint> dstQuads(4 * (fTileGridSize.fWidth - 1));
175 for (int x = 0; x < fTileGridSize.fWidth - 1; ++x) {
176 set[i++] = this->getAdjustedEntry(x, fTileGridSize.fHeight - 1, l,
177 dstQuads.get() + x * 4);
178 }
179 // The corner can use conventional strict mode without geometric adjustment
180 set[i++] = this->getEntry(
181 fTileGridSize.fWidth - 1, fTileGridSize.fHeight - 1, l);
182 canvas->experimental_DrawEdgeAAImageSet(set.get() + rowStart,
183 fTileGridSize.fWidth, dstQuads.get(), nullptr, sampling, &paint,
185 } else {
187 int i = 0;
188 // Interior fast tiles
189 for (int y = 0; y < fTileGridSize.fHeight - 1; ++y) {
190 for (int x = 0; x < fTileGridSize.fWidth - 1; ++x) {
191 set[i++] = this->getEntry(x, y, l);
192 }
193 }
194 canvas->experimental_DrawEdgeAAImageSet(set.get(), i, nullptr, nullptr,
195 sampling, &paint,
197
198 // Right edge
199 int strictStart = i;
200 AutoTArray<SkPoint> dstQuads(
201 4 * (fTileGridSize.fWidth + fTileGridSize.fHeight - 2));
202 for (int y = 0; y < fTileGridSize.fHeight - 1; ++y) {
203 set[i++] = this->getAdjustedEntry(fTileGridSize.fWidth - 1, y, l,
204 dstQuads.get() + y * 4);
205 }
206 canvas->experimental_DrawEdgeAAImageSet(set.get() + strictStart,
207 i - strictStart, dstQuads.get(), nullptr, sampling, &paint,
209 int quadStart = 4 * (fTileGridSize.fHeight - 1);
210 strictStart = i;
211 for (int x = 0; x < fTileGridSize.fWidth - 1; ++x) {
212 set[i++] = this->getAdjustedEntry(x, fTileGridSize.fHeight - 1, l,
213 dstQuads.get() + quadStart + x * 4);
214 }
215 set[i++] = this->getEntry(
216 fTileGridSize.fWidth - 1, fTileGridSize.fHeight - 1, l);
217 canvas->experimental_DrawEdgeAAImageSet(set.get() + strictStart,
218 i - strictStart, dstQuads.get() + quadStart, nullptr, sampling, &paint,
220 }
221 }
222 // Prevent any batching between composited "frames".
223 skgpu::Flush(canvas->getSurface());
224 }
225 canvas->restore();
226 }
#define SkASSERT(cond)
Definition: SkAssert.h:116
SkSurface * getSurface() const
Definition: SkCanvas.cpp:365
void restore()
Definition: SkCanvas.cpp:461
SrcRectConstraint
Definition: SkCanvas.h:1541
@ kStrict_SrcRectConstraint
sample only inside bounds; slower
Definition: SkCanvas.h:1542
@ 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)
Definition: SkCanvas.cpp:1853
int save()
Definition: SkCanvas.cpp:447
void concat(const SkMatrix &matrix)
Definition: SkCanvas.cpp:1318
const Paint & paint
Definition: color_source.cc:38
double y
double x
SkSamplingOptions sampling
Definition: SkRecords.h:337
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not set
Definition: switches.h:76
void Flush(SkSurface *surface)
Definition: GpuTools.h:25

◆ onGetName()

const char * CompositingImages::onGetName ( )
inlineoverrideprotectedvirtual

Implements Benchmark.

Definition at line 96 of file CompositingImagesBench.cpp.

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

◆ onPerCanvasPostDraw()

void CompositingImages::onPerCanvasPostDraw ( SkCanvas )
inlineoverrideprotectedvirtual

Reimplemented from Benchmark.

Definition at line 121 of file CompositingImagesBench.cpp.

121{ fImages.reset(); }

◆ onPerCanvasPreDraw()

void CompositingImages::onPerCanvasPreDraw ( SkCanvas canvas)
inlineoverrideprotectedvirtual

Reimplemented from Benchmark.

Definition at line 98 of file CompositingImagesBench.cpp.

98 {
99 // Use image size, which may be larger than the tile size (emulating how Chrome specifies
100 // their tiles).
101 auto ii = SkImageInfo::Make(fImageSize.fWidth, fImageSize.fHeight, kRGBA_8888_SkColorType,
102 kPremul_SkAlphaType, nullptr);
103 SkRandom random;
104 int numImages = fLayerCnt * fTileGridSize.fWidth * fTileGridSize.fHeight;
105 fImages = std::make_unique<sk_sp<SkImage>[]>(numImages);
106 for (int i = 0; i < numImages; ++i) {
107 auto surf = canvas->makeSurface(ii);
108 SkColor color = random.nextU();
109 surf->getCanvas()->clear(color);
111 paint.setColor(~color);
112 paint.setBlendMode(SkBlendMode::kSrc);
113 // While the image may be bigger than fTileSize, prepare its content as if fTileSize
114 // is what will be visible.
115 surf->getCanvas()->drawRect(
116 SkRect::MakeLTRB(3, 3, fTileSize.fWidth - 3, fTileSize.fHeight - 3), paint);
117 fImages[i] = surf->makeImageSnapshot();
118 }
119 }
@ 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)
Definition: SkCanvas.cpp:1195
uint32_t nextU()
Definition: SkRandom.h:42
DlColor color
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: