Flutter Engine
The Flutter Engine
Classes | Public Member Functions | List of all members
DDLTileHelper Class Reference

#include <DDLTileHelper.h>

Classes

class  TileData
 

Public Member Functions

 DDLTileHelper (GrDirectContext *, const GrSurfaceCharacterization &dstChar, const SkIRect &viewport, int numXDivisions, int numYDivisions, bool addRandomPaddingToDst)
 
void kickOffThreadedWork (SkTaskGroup *recordingTaskGroup, SkTaskGroup *gpuTaskGroup, GrDirectContext *, SkPicture *)
 
void createDDLsInParallel (SkPicture *)
 
void createComposeDDL ()
 
const sk_sp< GrDeferredDisplayList > & composeDDL () const
 
void interleaveDDLCreationAndDraw (GrDirectContext *, SkPicture *)
 
void drawAllTilesDirectly (GrDirectContext *, SkPicture *)
 
void dropCallbackContexts ()
 
void resetAllTiles ()
 
int numTiles () const
 
void createBackendTextures (SkTaskGroup *, GrDirectContext *)
 
void deleteBackendTextures (SkTaskGroup *, GrDirectContext *)
 

Detailed Description

Definition at line 29 of file DDLTileHelper.h.

Constructor & Destructor Documentation

◆ DDLTileHelper()

DDLTileHelper::DDLTileHelper ( GrDirectContext direct,
const GrSurfaceCharacterization dstChar,
const SkIRect viewport,
int  numXDivisions,
int  numYDivisions,
bool  addRandomPaddingToDst 
)

Definition at line 233 of file DDLTileHelper.cpp.

238 : fNumXDivisions(numXDivisions)
239 , fNumYDivisions(numYDivisions)
240 , fTiles(numXDivisions * numYDivisions)
241 , fDstCharacterization(dstChar) {
242 SkASSERT(fNumXDivisions > 0 && fNumYDivisions > 0);
243
244 int xTileSize = viewport.width()/fNumXDivisions;
245 int yTileSize = viewport.height()/fNumYDivisions;
246
247 SkRandom rand;
248
249 // Create the destination tiles
250 for (int y = 0, yOff = 0; y < fNumYDivisions; ++y, yOff += yTileSize) {
251 int ySize = (y < fNumYDivisions-1) ? yTileSize : viewport.height()-yOff;
252
253 for (int x = 0, xOff = 0; x < fNumXDivisions; ++x, xOff += xTileSize) {
254 int xSize = (x < fNumXDivisions-1) ? xTileSize : viewport.width()-xOff;
255
256 SkIRect clip = SkIRect::MakeXYWH(xOff, yOff, xSize, ySize);
257
258 SkASSERT(viewport.contains(clip));
259
260 static const uint32_t kMaxPad = 64;
261 int32_t lPad = addRandomPaddingToDst ? rand.nextRangeU(0, kMaxPad) : 0;
262 int32_t tPad = addRandomPaddingToDst ? rand.nextRangeU(0, kMaxPad) : 0;
263 int32_t rPad = addRandomPaddingToDst ? rand.nextRangeU(0, kMaxPad) : 0;
264 int32_t bPad = addRandomPaddingToDst ? rand.nextRangeU(0, kMaxPad) : 0;
265
266 fTiles[y*fNumXDivisions+x].init(y*fNumXDivisions+x, direct, dstChar, clip,
267 {lPad, tPad, rPad, bPad});
268 }
269 }
270}
#define SkASSERT(cond)
Definition: SkAssert.h:116
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
Definition: SkPath.cpp:3892
uint32_t nextRangeU(uint32_t min, uint32_t max)
Definition: SkRandom.h:80
double y
double x
Definition: SkRect.h:32
constexpr int32_t height() const
Definition: SkRect.h:165
constexpr int32_t width() const
Definition: SkRect.h:158
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
Definition: SkRect.h:104
bool contains(int32_t x, int32_t y) const
Definition: SkRect.h:463

Member Function Documentation

◆ composeDDL()

const sk_sp< GrDeferredDisplayList > & DDLTileHelper::composeDDL ( ) const
inline

Definition at line 118 of file DDLTileHelper.h.

118{ return fComposeDDL; }

◆ createBackendTextures()

void DDLTileHelper::createBackendTextures ( SkTaskGroup taskGroup,
GrDirectContext direct 
)

Definition at line 360 of file DDLTileHelper.cpp.

360 {
361
362 if (taskGroup) {
363 for (int i = 0; i < this->numTiles(); ++i) {
364 TileData* tile = &fTiles[i];
365 if (!tile->initialized()) {
366 continue;
367 }
368
369 taskGroup->add([direct, tile]() { TileData::CreateBackendTexture(direct, tile); });
370 }
371 } else {
372 for (int i = 0; i < this->numTiles(); ++i) {
373 TileData::CreateBackendTexture(direct, &fTiles[i]);
374 }
375 }
376}
static void CreateBackendTexture(GrDirectContext *, TileData *)
int numTiles() const
void add(std::function< void(void)> fn)
Definition: SkTaskGroup.cpp:16

◆ createComposeDDL()

void DDLTileHelper::createComposeDDL ( )

Definition at line 74 of file DDLTileHelper.cpp.

74 {
75 SkASSERT(!fComposeDDL);
76
77 GrDeferredDisplayListRecorder recorder(fDstCharacterization);
78
79 SkCanvas* recordingCanvas = recorder.getCanvas();
80
81 for (int i = 0; i < this->numTiles(); ++i) {
82 TileData* tile = &fTiles[i];
83 if (!tile->initialized()) {
84 continue;
85 }
86
87 sk_sp<SkImage> promiseImage = tile->makePromiseImageForDst(
88 recordingCanvas->recordingContext()->threadSafeProxy());
89
90 SkRect dstRect = SkRect::Make(tile->clipRect());
91 SkIRect srcRect = tile->clipRect();
92 srcRect.offsetTo(tile->padOffset().x(), tile->padOffset().y());
93
94 SkASSERT(promiseImage->bounds().contains(srcRect));
95
96 recordingCanvas->drawImageRect(promiseImage.get(), SkRect::Make(srcRect), dstRect,
97 SkSamplingOptions(), nullptr,
99 }
100
101 fComposeDDL = recorder.detach();
102 SkASSERT(fComposeDDL);
103}
sk_sp< GrContextThreadSafeProxy > threadSafeProxy()
virtual GrRecordingContext * recordingContext() const
Definition: SkCanvas.cpp:1637
@ kStrict_SrcRectConstraint
sample only inside bounds; slower
Definition: SkCanvas.h:1542
void drawImageRect(const SkImage *, const SkRect &src, const SkRect &dst, const SkSamplingOptions &, const SkPaint *, SrcRectConstraint)
Definition: SkCanvas.cpp:2333
SkIRect bounds() const
Definition: SkImage.h:303
T * get() const
Definition: SkRefCnt.h:303
void offsetTo(int32_t newX, int32_t newY)
Definition: SkRect.h:394
static SkRect Make(const SkISize &size)
Definition: SkRect.h:669

◆ createDDLsInParallel()

void DDLTileHelper::createDDLsInParallel ( SkPicture picture)

Definition at line 272 of file DDLTileHelper.cpp.

272 {
273#if 1
274 SkTaskGroup().batch(this->numTiles(), [&](int i) {
275 fTiles[i].createDDL(picture);
276 });
277 SkTaskGroup().add([this]{ this->createComposeDDL(); });
278 SkTaskGroup().wait();
279#else
280 // Use this code path to debug w/o threads
281 for (int i = 0; i < this->numTiles(); ++i) {
282 fTiles[i].createDDL(picture);
283 }
284 this->createComposeDDL();
285#endif
286}
void createComposeDDL()
void batch(int N, std::function< void(int)> fn)
Definition: SkTaskGroup.cpp:24
sk_sp< const SkPicture > picture
Definition: SkRecords.h:299

◆ deleteBackendTextures()

void DDLTileHelper::deleteBackendTextures ( SkTaskGroup taskGroup,
GrDirectContext direct 
)

Definition at line 378 of file DDLTileHelper.cpp.

378 {
379 if (taskGroup) {
380 for (int i = 0; i < this->numTiles(); ++i) {
381 TileData* tile = &fTiles[i];
382
383 taskGroup->add([direct, tile]() { TileData::DeleteBackendTexture(direct, tile); });
384 }
385 } else {
386 for (int i = 0; i < this->numTiles(); ++i) {
387 TileData::DeleteBackendTexture(direct, &fTiles[i]);
388 }
389 }
390}
static void DeleteBackendTexture(GrDirectContext *, TileData *)

◆ drawAllTilesDirectly()

void DDLTileHelper::drawAllTilesDirectly ( GrDirectContext dContext,
SkPicture picture 
)

Definition at line 341 of file DDLTileHelper.cpp.

341 {
342 for (int i = 0; i < this->numTiles(); ++i) {
343 fTiles[i].drawSKPDirectly(dContext, picture);
344 }
345}

◆ dropCallbackContexts()

void DDLTileHelper::dropCallbackContexts ( )

Definition at line 347 of file DDLTileHelper.cpp.

347 {
348 for (int i = 0; i < this->numTiles(); ++i) {
349 fTiles[i].dropCallbackContext();
350 }
351}

◆ interleaveDDLCreationAndDraw()

void DDLTileHelper::interleaveDDLCreationAndDraw ( GrDirectContext dContext,
SkPicture picture 
)

Definition at line 333 of file DDLTileHelper.cpp.

333 {
334 for (int i = 0; i < this->numTiles(); ++i) {
335 fTiles[i].createDDL(picture);
336 fTiles[i].draw(dContext);
337 }
338}

◆ kickOffThreadedWork()

void DDLTileHelper::kickOffThreadedWork ( SkTaskGroup recordingTaskGroup,
SkTaskGroup gpuTaskGroup,
GrDirectContext dContext,
SkPicture picture 
)

Definition at line 303 of file DDLTileHelper.cpp.

306 {
307 SkASSERT(recordingTaskGroup && gpuTaskGroup && dContext);
308
309 for (int i = 0; i < this->numTiles(); ++i) {
310 TileData* tile = &fTiles[i];
311 if (!tile->initialized()) {
312 continue;
313 }
314
315 // On a recording thread:
316 // generate the tile's DDL
317 // schedule gpu-thread processing of the DDL
318 // Note: a finer grained approach would be add a scheduling task which would evaluate
319 // which DDLs were ready to be rendered based on their prerequisites
320 recordingTaskGroup->add([tile, gpuTaskGroup, dContext, picture]() {
321 tile->createDDL(picture);
322
323 gpuTaskGroup->add([dContext, tile]() {
324 do_gpu_stuff(dContext, tile);
325 });
326 });
327 }
328
329 recordingTaskGroup->add([this] { this->createComposeDDL(); });
330}
static void do_gpu_stuff(GrDirectContext *direct, DDLTileHelper::TileData *tile)

◆ numTiles()

int DDLTileHelper::numTiles ( ) const
inline

Definition at line 134 of file DDLTileHelper.h.

134{ return fNumXDivisions * fNumYDivisions; }

◆ resetAllTiles()

void DDLTileHelper::resetAllTiles ( )

Definition at line 353 of file DDLTileHelper.cpp.

353 {
354 for (int i = 0; i < this->numTiles(); ++i) {
355 fTiles[i].reset();
356 }
357 fComposeDDL.reset();
358}
void reset(T *ptr=nullptr)
Definition: SkRefCnt.h:310

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