blob: c825194a2f490887b0e0f147984f3d993757926f [file] [log] [blame]
Robert Phillips96601082018-05-29 16:13:26 -04001/*
2 * Copyright 2018 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "tools/DDLTileHelper.h"
Robert Phillips96601082018-05-29 16:13:26 -04009
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "include/core/SkCanvas.h"
11#include "include/core/SkDeferredDisplayListRecorder.h"
12#include "include/core/SkPicture.h"
13#include "include/core/SkSurface.h"
14#include "include/core/SkSurfaceCharacterization.h"
Robert Phillipsd5f3c982020-07-07 13:18:47 -040015#include "include/gpu/GrDirectContext.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050016#include "src/core/SkDeferredDisplayListPriv.h"
17#include "src/core/SkTaskGroup.h"
Adlai Hollera0693042020-10-14 11:23:11 -040018#include "src/gpu/GrDirectContextPriv.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050019#include "src/image/SkImage_Gpu.h"
20#include "tools/DDLPromiseImageHelper.h"
Robert Phillips96601082018-05-29 16:13:26 -040021
Robert Phillips19f466d2020-02-26 10:27:07 -050022void DDLTileHelper::TileData::init(int id,
Robert Phillipsd5f3c982020-07-07 13:18:47 -040023 GrDirectContext* direct,
Robert Phillips19f466d2020-02-26 10:27:07 -050024 const SkSurfaceCharacterization& dstSurfaceCharacterization,
Robert Phillips0c088492020-11-10 08:30:50 -050025 const SkIRect& clip,
26 const SkIRect& paddingOutsets) {
Robert Phillipsa865a3a2020-02-14 10:49:39 -050027 fID = id;
Robert Phillipsa865a3a2020-02-14 10:49:39 -050028 fClip = clip;
Robert Phillips0c088492020-11-10 08:30:50 -050029 fPaddingOutsets = paddingOutsets;
Robert Phillipsa865a3a2020-02-14 10:49:39 -050030
Robert Phillipsbc688322020-12-14 11:38:59 -050031 fPlaybackChar = dstSurfaceCharacterization.createResized(this->paddedRectSize().width(),
32 this->paddedRectSize().height());
33 SkASSERT(fPlaybackChar.isValid());
Robert Phillips11c67672020-04-23 15:10:03 -040034
Robert Phillipsd5f3c982020-07-07 13:18:47 -040035 SkDEBUGCODE(const GrCaps* caps = direct->priv().caps());
Greg Daniel0e9d34d2021-08-13 16:20:18 -040036 SkASSERT(caps->isFormatTexturable(fPlaybackChar.backendFormat(),
37 fPlaybackChar.backendFormat().textureType()));
Robert Phillips11c67672020-04-23 15:10:03 -040038
Greg Daniel0e9d34d2021-08-13 16:20:18 -040039 fCallbackContext.reset(new PromiseImageCallbackContext(direct, fPlaybackChar.backendFormat()));
Robert Phillips96601082018-05-29 16:13:26 -040040}
41
Robert Phillipscd1e3972021-02-22 17:24:22 -050042DDLTileHelper::TileData::TileData() {}
Robert Phillipsa865a3a2020-02-14 10:49:39 -050043DDLTileHelper::TileData::~TileData() {}
44
Adlai Holler55aaefe2021-03-03 16:12:56 -070045void DDLTileHelper::TileData::createDDL(const SkPicture* picture) {
46 SkASSERT(!fDisplayList && picture);
Robert Phillips96601082018-05-29 16:13:26 -040047
Robert Phillipsbc688322020-12-14 11:38:59 -050048 auto recordingChar = fPlaybackChar.createResized(fClip.width(), fClip.height());
49 SkASSERT(recordingChar.isValid());
50
51 SkDeferredDisplayListRecorder recorder(recordingChar);
Robert Phillips7a3197b2018-09-26 21:18:23 +000052
Adlai Holler55aaefe2021-03-03 16:12:56 -070053 // DDL TODO: the DDLRecorder's rContext isn't initialized until getCanvas is called.
Robert Phillips7a3197b2018-09-26 21:18:23 +000054 // Maybe set it up in the ctor?
Robert Phillips24a8e9e2020-03-06 20:26:28 +000055 SkCanvas* recordingCanvas = recorder.getCanvas();
Robert Phillips7a3197b2018-09-26 21:18:23 +000056
Robert Phillips0c088492020-11-10 08:30:50 -050057 // We always record the DDL in the (0,0) .. (clipWidth, clipHeight) coordinates
Robert Phillips24a8e9e2020-03-06 20:26:28 +000058 recordingCanvas->clipRect(SkRect::MakeWH(fClip.width(), fClip.height()));
59 recordingCanvas->translate(-fClip.fLeft, -fClip.fTop);
Robert Phillips96601082018-05-29 16:13:26 -040060
61 // Note: in this use case we only render a picture to the deferred canvas
62 // but, more generally, clients will use arbitrary draw calls.
Adlai Holler55aaefe2021-03-03 16:12:56 -070063 recordingCanvas->drawPicture(picture);
Robert Phillips96601082018-05-29 16:13:26 -040064
Robert Phillips7a3197b2018-09-26 21:18:23 +000065 fDisplayList = recorder.detach();
Robert Phillips96601082018-05-29 16:13:26 -040066}
67
Robert Phillips11c67672020-04-23 15:10:03 -040068void DDLTileHelper::createComposeDDL() {
69 SkASSERT(!fComposeDDL);
70
71 SkDeferredDisplayListRecorder recorder(fDstCharacterization);
72
73 SkCanvas* recordingCanvas = recorder.getCanvas();
74
75 for (int i = 0; i < this->numTiles(); ++i) {
76 TileData* tile = &fTiles[i];
Robert Phillips559f9c12021-01-11 12:29:20 -050077 if (!tile->initialized()) {
78 continue;
79 }
Robert Phillips11c67672020-04-23 15:10:03 -040080
Adlai Holler55aaefe2021-03-03 16:12:56 -070081 sk_sp<SkImage> promiseImage = tile->makePromiseImageForDst(
82 recordingCanvas->recordingContext()->threadSafeProxy());
Robert Phillips11c67672020-04-23 15:10:03 -040083
Robert Phillips0c088492020-11-10 08:30:50 -050084 SkRect dstRect = SkRect::Make(tile->clipRect());
85 SkIRect srcRect = tile->clipRect();
86 srcRect.offsetTo(tile->padOffset().x(), tile->padOffset().y());
Robert Phillips11c67672020-04-23 15:10:03 -040087
Robert Phillips0c088492020-11-10 08:30:50 -050088 SkASSERT(promiseImage->bounds().contains(srcRect));
Robert Phillips11c67672020-04-23 15:10:03 -040089
Mike Reede02d7f82021-01-21 22:25:21 -050090 recordingCanvas->drawImageRect(promiseImage.get(), SkRect::Make(srcRect), dstRect,
91 SkSamplingOptions(), nullptr,
92 SkCanvas::kStrict_SrcRectConstraint);
Robert Phillips11c67672020-04-23 15:10:03 -040093 }
94
95 fComposeDDL = recorder.detach();
Robert Phillips889d6132020-06-16 11:11:33 -040096 SkASSERT(fComposeDDL);
Robert Phillips11c67672020-04-23 15:10:03 -040097}
98
Robert Phillipsd5f3c982020-07-07 13:18:47 -040099void DDLTileHelper::TileData::precompile(GrDirectContext* direct) {
Robert Phillips559f9c12021-01-11 12:29:20 -0500100 if (!this->initialized()) {
101 return;
102 }
103
Robert Phillips6eb5cb92020-03-05 12:52:45 -0500104 SkASSERT(fDisplayList);
105
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400106 SkDeferredDisplayList::ProgramIterator iter(direct, fDisplayList.get());
Robert Phillips6eb5cb92020-03-05 12:52:45 -0500107 for (; !iter.done(); iter.next()) {
108 iter.compile();
109 }
110}
111
Adlai Holler55aaefe2021-03-03 16:12:56 -0700112sk_sp<SkSurface> DDLTileHelper::TileData::makeWrappedTileDest(GrRecordingContext* rContext) {
Robert Phillips11c67672020-04-23 15:10:03 -0400113 SkASSERT(fCallbackContext && fCallbackContext->promiseImageTexture());
114
115 auto promiseImageTexture = fCallbackContext->promiseImageTexture();
116 if (!promiseImageTexture->backendTexture().isValid()) {
Robert Phillips8472a3d2020-04-16 16:27:45 -0400117 return nullptr;
118 }
Robert Phillips7ae9d2f2020-04-15 10:58:15 -0400119
Robert Phillips11c67672020-04-23 15:10:03 -0400120 // Here we are, unfortunately, aliasing the backend texture held by the SkPromiseImageTexture.
121 // Both the tile's destination surface and the promise image used to draw the tile will be
122 // backed by the same backendTexture - unbeknownst to Ganesh.
Adlai Holler55aaefe2021-03-03 16:12:56 -0700123 return SkSurface::MakeFromBackendTexture(rContext,
Robert Phillips11c67672020-04-23 15:10:03 -0400124 promiseImageTexture->backendTexture(),
Robert Phillipsbc688322020-12-14 11:38:59 -0500125 fPlaybackChar.origin(),
126 fPlaybackChar.sampleCount(),
127 fPlaybackChar.colorType(),
128 fPlaybackChar.refColorSpace(),
129 &fPlaybackChar.surfaceProps());
Robert Phillips8472a3d2020-04-16 16:27:45 -0400130}
131
Adlai Holler55aaefe2021-03-03 16:12:56 -0700132void DDLTileHelper::TileData::drawSKPDirectly(GrDirectContext* dContext,
133 const SkPicture* picture) {
134 SkASSERT(!fDisplayList && !fTileSurface && picture);
Robert Phillips8472a3d2020-04-16 16:27:45 -0400135
Adlai Holler55aaefe2021-03-03 16:12:56 -0700136 fTileSurface = this->makeWrappedTileDest(dContext);
Robert Phillips8472a3d2020-04-16 16:27:45 -0400137 if (fTileSurface) {
138 SkCanvas* tileCanvas = fTileSurface->getCanvas();
Robert Phillips24a8e9e2020-03-06 20:26:28 +0000139
Robert Phillips0c088492020-11-10 08:30:50 -0500140 SkASSERT(this->padOffset().isZero() && this->paddedRectSize() == fClip.size());
Robert Phillips24a8e9e2020-03-06 20:26:28 +0000141 tileCanvas->clipRect(SkRect::MakeWH(fClip.width(), fClip.height()));
142 tileCanvas->translate(-fClip.fLeft, -fClip.fTop);
143
Adlai Holler55aaefe2021-03-03 16:12:56 -0700144 tileCanvas->drawPicture(picture);
Robert Phillips24a8e9e2020-03-06 20:26:28 +0000145
Robert Phillips8472a3d2020-04-16 16:27:45 -0400146 // We can't snap an image here bc, since we're using wrapped backend textures for the
147 // surfaces, that would incur a copy.
Robert Phillips24a8e9e2020-03-06 20:26:28 +0000148 }
149}
150
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400151void DDLTileHelper::TileData::draw(GrDirectContext* direct) {
Robert Phillips8472a3d2020-04-16 16:27:45 -0400152 SkASSERT(fDisplayList && !fTileSurface);
Robert Phillips96601082018-05-29 16:13:26 -0400153
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400154 fTileSurface = this->makeWrappedTileDest(direct);
Robert Phillips8472a3d2020-04-16 16:27:45 -0400155 if (fTileSurface) {
Robert Phillips0c088492020-11-10 08:30:50 -0500156 fTileSurface->draw(fDisplayList, this->padOffset().x(), this->padOffset().y());
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500157
Robert Phillips8472a3d2020-04-16 16:27:45 -0400158 // We can't snap an image here bc, since we're using wrapped backend textures for the
159 // surfaces, that would incur a copy.
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500160 }
Robert Phillips96601082018-05-29 16:13:26 -0400161}
162
Robert Phillips96601082018-05-29 16:13:26 -0400163void DDLTileHelper::TileData::reset() {
164 // TODO: when DDLs are re-renderable we don't need to do this
165 fDisplayList = nullptr;
Robert Phillips11c67672020-04-23 15:10:03 -0400166
Robert Phillips8472a3d2020-04-16 16:27:45 -0400167 fTileSurface = nullptr;
168}
169
Robert Phillips0c088492020-11-10 08:30:50 -0500170sk_sp<SkImage> DDLTileHelper::TileData::makePromiseImageForDst(
Adlai Holler55aaefe2021-03-03 16:12:56 -0700171 sk_sp<GrContextThreadSafeProxy> threadSafeProxy) {
Robert Phillips11c67672020-04-23 15:10:03 -0400172 SkASSERT(fCallbackContext);
173
174 // The promise image gets a ref on the promise callback context
Brian Salomonf1432742020-11-09 15:40:27 -0500175 sk_sp<SkImage> promiseImage =
Adlai Holler55aaefe2021-03-03 16:12:56 -0700176 SkImage::MakePromiseTexture(std::move(threadSafeProxy),
177 fCallbackContext->backendFormat(),
178 this->paddedRectSize(),
179 GrMipmapped::kNo,
180 GrSurfaceOrigin::kBottomLeft_GrSurfaceOrigin,
181 fPlaybackChar.colorType(),
182 kPremul_SkAlphaType,
183 fPlaybackChar.refColorSpace(),
184 PromiseImageCallbackContext::PromiseImageFulfillProc,
185 PromiseImageCallbackContext::PromiseImageReleaseProc,
186 (void*)this->refCallbackContext().release());
Robert Phillips11c67672020-04-23 15:10:03 -0400187 fCallbackContext->wasAddedToImage();
188
189 return promiseImage;
190}
191
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400192void DDLTileHelper::TileData::CreateBackendTexture(GrDirectContext* direct, TileData* tile) {
Robert Phillips11c67672020-04-23 15:10:03 -0400193 SkASSERT(tile->fCallbackContext && !tile->fCallbackContext->promiseImageTexture());
Robert Phillipsbc688322020-12-14 11:38:59 -0500194
195 const SkSurfaceCharacterization& c = tile->fPlaybackChar;
Greg Daniel398ecf12020-08-26 16:33:54 -0400196 GrBackendTexture beTex = direct->createBackendTexture(c.width(), c.height(), c.colorType(),
197 GrMipMapped(c.isMipMapped()),
198 GrRenderable::kYes);
Robert Phillips11c67672020-04-23 15:10:03 -0400199 tile->fCallbackContext->setBackendTexture(beTex);
Robert Phillips8472a3d2020-04-16 16:27:45 -0400200}
201
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400202void DDLTileHelper::TileData::DeleteBackendTexture(GrDirectContext*, TileData* tile) {
Robert Phillips559f9c12021-01-11 12:29:20 -0500203 if (!tile->initialized()) {
204 return;
205 }
206
Robert Phillips11c67672020-04-23 15:10:03 -0400207 SkASSERT(tile->fCallbackContext);
208
Robert Phillips8472a3d2020-04-16 16:27:45 -0400209 // TODO: it seems that, on the Linux bots, backend texture creation is failing
210 // a lot (skbug.com/10142)
Robert Phillips11c67672020-04-23 15:10:03 -0400211 SkASSERT(!tile->fCallbackContext->promiseImageTexture() ||
212 tile->fCallbackContext->promiseImageTexture()->backendTexture().isValid());
Robert Phillips8472a3d2020-04-16 16:27:45 -0400213
214 tile->fTileSurface = nullptr;
Robert Phillips11c67672020-04-23 15:10:03 -0400215
216 SkASSERT(tile->fCallbackContext->unique());
217 tile->fCallbackContext.reset();
Robert Phillips96601082018-05-29 16:13:26 -0400218}
219
220///////////////////////////////////////////////////////////////////////////////////////////////////
221
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400222DDLTileHelper::DDLTileHelper(GrDirectContext* direct,
Robert Phillips19f466d2020-02-26 10:27:07 -0500223 const SkSurfaceCharacterization& dstChar,
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500224 const SkIRect& viewport,
Robert Phillips96f6d9a2021-02-26 10:41:06 -0500225 int numXDivisions, int numYDivisions,
Robert Phillips0c088492020-11-10 08:30:50 -0500226 bool addRandomPaddingToDst)
Robert Phillips96f6d9a2021-02-26 10:41:06 -0500227 : fNumXDivisions(numXDivisions)
228 , fNumYDivisions(numYDivisions)
229 , fTiles(numXDivisions * numYDivisions)
Robert Phillips11c67672020-04-23 15:10:03 -0400230 , fDstCharacterization(dstChar) {
Robert Phillips96f6d9a2021-02-26 10:41:06 -0500231 SkASSERT(fNumXDivisions > 0 && fNumYDivisions > 0);
Robert Phillips96601082018-05-29 16:13:26 -0400232
Robert Phillips96f6d9a2021-02-26 10:41:06 -0500233 int xTileSize = viewport.width()/fNumXDivisions;
234 int yTileSize = viewport.height()/fNumYDivisions;
Robert Phillips96601082018-05-29 16:13:26 -0400235
Robert Phillips0c088492020-11-10 08:30:50 -0500236 SkRandom rand;
237
Robert Phillips96601082018-05-29 16:13:26 -0400238 // Create the destination tiles
Robert Phillips96f6d9a2021-02-26 10:41:06 -0500239 for (int y = 0, yOff = 0; y < fNumYDivisions; ++y, yOff += yTileSize) {
240 int ySize = (y < fNumYDivisions-1) ? yTileSize : viewport.height()-yOff;
Robert Phillips96601082018-05-29 16:13:26 -0400241
Robert Phillips96f6d9a2021-02-26 10:41:06 -0500242 for (int x = 0, xOff = 0; x < fNumXDivisions; ++x, xOff += xTileSize) {
243 int xSize = (x < fNumXDivisions-1) ? xTileSize : viewport.width()-xOff;
Robert Phillips96601082018-05-29 16:13:26 -0400244
245 SkIRect clip = SkIRect::MakeXYWH(xOff, yOff, xSize, ySize);
246
247 SkASSERT(viewport.contains(clip));
248
Robert Phillips0c088492020-11-10 08:30:50 -0500249 static const uint32_t kMaxPad = 64;
250 int32_t lPad = addRandomPaddingToDst ? rand.nextRangeU(0, kMaxPad) : 0;
251 int32_t tPad = addRandomPaddingToDst ? rand.nextRangeU(0, kMaxPad) : 0;
252 int32_t rPad = addRandomPaddingToDst ? rand.nextRangeU(0, kMaxPad) : 0;
253 int32_t bPad = addRandomPaddingToDst ? rand.nextRangeU(0, kMaxPad) : 0;
254
Robert Phillips96f6d9a2021-02-26 10:41:06 -0500255 fTiles[y*fNumXDivisions+x].init(y*fNumXDivisions+x, direct, dstChar, clip,
Robert Phillips0c088492020-11-10 08:30:50 -0500256 {lPad, tPad, rPad, bPad});
Robert Phillips96601082018-05-29 16:13:26 -0400257 }
258 }
259}
260
Robert Phillips0d8722c2021-03-29 13:29:40 -0400261void DDLTileHelper::createDDLsInParallel(SkPicture* picture) {
Robert Phillips96601082018-05-29 16:13:26 -0400262#if 1
Adlai Holler55aaefe2021-03-03 16:12:56 -0700263 SkTaskGroup().batch(this->numTiles(), [&](int i) {
Robert Phillips0d8722c2021-03-29 13:29:40 -0400264 fTiles[i].createDDL(picture);
Adlai Holler55aaefe2021-03-03 16:12:56 -0700265 });
Robert Phillips11c67672020-04-23 15:10:03 -0400266 SkTaskGroup().add([this]{ this->createComposeDDL(); });
Robert Phillipsf18c7562018-06-13 09:01:36 -0400267 SkTaskGroup().wait();
Robert Phillips96601082018-05-29 16:13:26 -0400268#else
269 // Use this code path to debug w/o threads
Robert Phillips24a8e9e2020-03-06 20:26:28 +0000270 for (int i = 0; i < this->numTiles(); ++i) {
Robert Phillips0d8722c2021-03-29 13:29:40 -0400271 fTiles[i].createDDL(picture);
Robert Phillips96601082018-05-29 16:13:26 -0400272 }
Robert Phillips11c67672020-04-23 15:10:03 -0400273 this->createComposeDDL();
Robert Phillips96601082018-05-29 16:13:26 -0400274#endif
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500275}
Robert Phillips96601082018-05-29 16:13:26 -0400276
Robert Phillips7b0ed552020-02-20 12:45:19 -0500277// On the gpu thread:
278// precompile any programs
279// replay the DDL into a surface to make the tile image
280// compose the tile image into the main canvas
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400281static void do_gpu_stuff(GrDirectContext* direct, DDLTileHelper::TileData* tile) {
Robert Phillips7b0ed552020-02-20 12:45:19 -0500282
283 // TODO: schedule program compilation as their own tasks
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400284 tile->precompile(direct);
Robert Phillips7b0ed552020-02-20 12:45:19 -0500285
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400286 tile->draw(direct);
Robert Phillips5dbcca52020-05-29 10:41:33 -0400287
Robert Phillips5dbcca52020-05-29 10:41:33 -0400288 tile->dropDDL();
Robert Phillips7b0ed552020-02-20 12:45:19 -0500289}
290
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500291// We expect to have more than one recording thread but just one gpu thread
292void DDLTileHelper::kickOffThreadedWork(SkTaskGroup* recordingTaskGroup,
293 SkTaskGroup* gpuTaskGroup,
Robert Phillips0d8722c2021-03-29 13:29:40 -0400294 GrDirectContext* dContext,
295 SkPicture* picture) {
Robert Phillipscd1e3972021-02-22 17:24:22 -0500296 SkASSERT(recordingTaskGroup && gpuTaskGroup && dContext);
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500297
298 for (int i = 0; i < this->numTiles(); ++i) {
299 TileData* tile = &fTiles[i];
Robert Phillips559f9c12021-01-11 12:29:20 -0500300 if (!tile->initialized()) {
301 continue;
302 }
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500303
304 // On a recording thread:
305 // generate the tile's DDL
306 // schedule gpu-thread processing of the DDL
307 // Note: a finer grained approach would be add a scheduling task which would evaluate
308 // which DDLs were ready to be rendered based on their prerequisites
Robert Phillips0d8722c2021-03-29 13:29:40 -0400309 recordingTaskGroup->add([tile, gpuTaskGroup, dContext, picture]() {
310 tile->createDDL(picture);
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500311
Robert Phillipscd1e3972021-02-22 17:24:22 -0500312 gpuTaskGroup->add([dContext, tile]() {
313 do_gpu_stuff(dContext, tile);
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500314 });
315 });
316 }
Robert Phillips11c67672020-04-23 15:10:03 -0400317
318 recordingTaskGroup->add([this] { this->createComposeDDL(); });
Robert Phillips96601082018-05-29 16:13:26 -0400319}
320
Robert Phillips5dbcca52020-05-29 10:41:33 -0400321// Only called from skpbench
Robert Phillips0d8722c2021-03-29 13:29:40 -0400322void DDLTileHelper::interleaveDDLCreationAndDraw(GrDirectContext* dContext, SkPicture* picture) {
Robert Phillips24a8e9e2020-03-06 20:26:28 +0000323 for (int i = 0; i < this->numTiles(); ++i) {
Robert Phillips0d8722c2021-03-29 13:29:40 -0400324 fTiles[i].createDDL(picture);
325 fTiles[i].draw(dContext);
Robert Phillips24a8e9e2020-03-06 20:26:28 +0000326 }
327}
328
Robert Phillips5dbcca52020-05-29 10:41:33 -0400329// Only called from skpbench
Robert Phillips0d8722c2021-03-29 13:29:40 -0400330void DDLTileHelper::drawAllTilesDirectly(GrDirectContext* dContext, SkPicture* picture) {
Robert Phillips24a8e9e2020-03-06 20:26:28 +0000331 for (int i = 0; i < this->numTiles(); ++i) {
Robert Phillips0d8722c2021-03-29 13:29:40 -0400332 fTiles[i].drawSKPDirectly(dContext, picture);
Robert Phillips24a8e9e2020-03-06 20:26:28 +0000333 }
334}
335
Robert Phillips11c67672020-04-23 15:10:03 -0400336void DDLTileHelper::dropCallbackContexts() {
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500337 for (int i = 0; i < this->numTiles(); ++i) {
Robert Phillips11c67672020-04-23 15:10:03 -0400338 fTiles[i].dropCallbackContext();
Robert Phillips96601082018-05-29 16:13:26 -0400339 }
340}
341
342void DDLTileHelper::resetAllTiles() {
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500343 for (int i = 0; i < this->numTiles(); ++i) {
Robert Phillips96601082018-05-29 16:13:26 -0400344 fTiles[i].reset();
345 }
Robert Phillips11c67672020-04-23 15:10:03 -0400346 fComposeDDL.reset();
Robert Phillips96601082018-05-29 16:13:26 -0400347}
Robert Phillips8472a3d2020-04-16 16:27:45 -0400348
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400349void DDLTileHelper::createBackendTextures(SkTaskGroup* taskGroup, GrDirectContext* direct) {
Robert Phillips8472a3d2020-04-16 16:27:45 -0400350
351 if (taskGroup) {
352 for (int i = 0; i < this->numTiles(); ++i) {
353 TileData* tile = &fTiles[i];
Robert Phillips559f9c12021-01-11 12:29:20 -0500354 if (!tile->initialized()) {
355 continue;
356 }
Robert Phillips8472a3d2020-04-16 16:27:45 -0400357
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400358 taskGroup->add([direct, tile]() { TileData::CreateBackendTexture(direct, tile); });
Robert Phillips8472a3d2020-04-16 16:27:45 -0400359 }
360 } else {
361 for (int i = 0; i < this->numTiles(); ++i) {
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400362 TileData::CreateBackendTexture(direct, &fTiles[i]);
Robert Phillips8472a3d2020-04-16 16:27:45 -0400363 }
364 }
365}
366
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400367void DDLTileHelper::deleteBackendTextures(SkTaskGroup* taskGroup, GrDirectContext* direct) {
Robert Phillips8472a3d2020-04-16 16:27:45 -0400368 if (taskGroup) {
369 for (int i = 0; i < this->numTiles(); ++i) {
370 TileData* tile = &fTiles[i];
371
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400372 taskGroup->add([direct, tile]() { TileData::DeleteBackendTexture(direct, tile); });
Robert Phillips8472a3d2020-04-16 16:27:45 -0400373 }
374 } else {
375 for (int i = 0; i < this->numTiles(); ++i) {
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400376 TileData::DeleteBackendTexture(direct, &fTiles[i]);
Robert Phillips8472a3d2020-04-16 16:27:45 -0400377 }
378 }
379}