blob: 3ff7699835940809e350b3642a7e03cee49f9f6d [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 Phillips0c088492020-11-10 08:30:50 -050031 fCharacterization = dstSurfaceCharacterization.createResized(this->paddedRectSize().width(),
32 this->paddedRectSize().height());
Robert Phillipsa865a3a2020-02-14 10:49:39 -050033 SkASSERT(fCharacterization.isValid());
Robert Phillips11c67672020-04-23 15:10:03 -040034
Robert Phillipsd5f3c982020-07-07 13:18:47 -040035 GrBackendFormat backendFormat = direct->defaultBackendFormat(fCharacterization.colorType(),
36 GrRenderable::kYes);
37 SkDEBUGCODE(const GrCaps* caps = direct->priv().caps());
Robert Phillips11c67672020-04-23 15:10:03 -040038 SkASSERT(caps->isFormatTexturable(backendFormat));
39
Robert Phillipsd5f3c982020-07-07 13:18:47 -040040 fCallbackContext.reset(new PromiseImageCallbackContext(direct, backendFormat));
Robert Phillips96601082018-05-29 16:13:26 -040041}
42
Robert Phillipsa865a3a2020-02-14 10:49:39 -050043DDLTileHelper::TileData::~TileData() {}
44
Robert Phillips96601082018-05-29 16:13:26 -040045void DDLTileHelper::TileData::createTileSpecificSKP(SkData* compressedPictureData,
46 const DDLPromiseImageHelper& helper) {
Robert Phillips7a3197b2018-09-26 21:18:23 +000047 SkASSERT(!fReconstitutedPicture);
Robert Phillips96601082018-05-29 16:13:26 -040048
Robert Phillips7a3197b2018-09-26 21:18:23 +000049 // This is bending the DDLRecorder contract! The promise images in the SKP should be
50 // created by the same recorder used to create the matching DDL.
51 SkDeferredDisplayListRecorder recorder(fCharacterization);
Robert Phillips96601082018-05-29 16:13:26 -040052
Robert Phillips7a3197b2018-09-26 21:18:23 +000053 fReconstitutedPicture = helper.reinflateSKP(&recorder, compressedPictureData, &fPromiseImages);
Robert Phillipse8e2bb12018-09-27 14:26:47 -040054
Adlai Holler7580ad42020-06-24 13:45:25 -040055 auto ddl = recorder.detach();
Robert Phillipsdc369702020-08-13 13:34:27 -040056 if (ddl && ddl->priv().numRenderTasks()) {
Robert Phillipse8e2bb12018-09-27 14:26:47 -040057 // TODO: remove this once skbug.com/8424 is fixed. If the DDL resulting from the
Greg Danielf41b2bd2019-08-22 16:19:24 -040058 // reinflation of the SKPs contains opsTasks that means some image subset operation
Robert Phillipse8e2bb12018-09-27 14:26:47 -040059 // created a draw.
60 fReconstitutedPicture.reset();
61 }
Robert Phillips96601082018-05-29 16:13:26 -040062}
63
64void DDLTileHelper::TileData::createDDL() {
Robert Phillips24a8e9e2020-03-06 20:26:28 +000065 SkASSERT(!fDisplayList && fReconstitutedPicture);
Robert Phillips96601082018-05-29 16:13:26 -040066
Robert Phillips7a3197b2018-09-26 21:18:23 +000067 SkDeferredDisplayListRecorder recorder(fCharacterization);
68
69 // DDL TODO: the DDLRecorder's GrContext isn't initialized until getCanvas is called.
70 // Maybe set it up in the ctor?
Robert Phillips24a8e9e2020-03-06 20:26:28 +000071 SkCanvas* recordingCanvas = recorder.getCanvas();
Robert Phillips7a3197b2018-09-26 21:18:23 +000072
73 // Because we cheated in createTileSpecificSKP and used the wrong DDLRecorder, the GrContext's
74 // stored in fReconstitutedPicture's promise images are incorrect. Patch them with the correct
75 // one now.
76 for (int i = 0; i < fPromiseImages.count(); ++i) {
Robert Phillips7a3197b2018-09-26 21:18:23 +000077 if (fPromiseImages[i]->isTextureBacked()) {
Adlai Holler302e8fb2020-09-14 11:58:06 -040078 auto rContext = recordingCanvas->recordingContext();
Jim Van Verth21bd60d2018-10-12 15:00:20 -040079 SkImage_GpuBase* gpuImage = (SkImage_GpuBase*) fPromiseImages[i].get();
Adlai Holler302e8fb2020-09-14 11:58:06 -040080 gpuImage->resetContext(sk_ref_sp(rContext));
Robert Phillips7a3197b2018-09-26 21:18:23 +000081 }
82 }
Robert Phillips96601082018-05-29 16:13:26 -040083
Robert Phillips0c088492020-11-10 08:30:50 -050084 // We always record the DDL in the (0,0) .. (clipWidth, clipHeight) coordinates
Robert Phillips24a8e9e2020-03-06 20:26:28 +000085 recordingCanvas->clipRect(SkRect::MakeWH(fClip.width(), fClip.height()));
86 recordingCanvas->translate(-fClip.fLeft, -fClip.fTop);
Robert Phillips96601082018-05-29 16:13:26 -040087
88 // Note: in this use case we only render a picture to the deferred canvas
89 // but, more generally, clients will use arbitrary draw calls.
Robert Phillips24a8e9e2020-03-06 20:26:28 +000090 recordingCanvas->drawPicture(fReconstitutedPicture);
Robert Phillips96601082018-05-29 16:13:26 -040091
Robert Phillips7a3197b2018-09-26 21:18:23 +000092 fDisplayList = recorder.detach();
Robert Phillips96601082018-05-29 16:13:26 -040093}
94
Robert Phillips11c67672020-04-23 15:10:03 -040095void DDLTileHelper::createComposeDDL() {
96 SkASSERT(!fComposeDDL);
97
98 SkDeferredDisplayListRecorder recorder(fDstCharacterization);
99
100 SkCanvas* recordingCanvas = recorder.getCanvas();
101
102 for (int i = 0; i < this->numTiles(); ++i) {
103 TileData* tile = &fTiles[i];
104
Robert Phillips0c088492020-11-10 08:30:50 -0500105 sk_sp<SkImage> promiseImage = tile->makePromiseImageForDst(&recorder);
Robert Phillips11c67672020-04-23 15:10:03 -0400106
Robert Phillips0c088492020-11-10 08:30:50 -0500107 SkRect dstRect = SkRect::Make(tile->clipRect());
108 SkIRect srcRect = tile->clipRect();
109 srcRect.offsetTo(tile->padOffset().x(), tile->padOffset().y());
Robert Phillips11c67672020-04-23 15:10:03 -0400110
Robert Phillips0c088492020-11-10 08:30:50 -0500111 SkASSERT(promiseImage->bounds().contains(srcRect));
Robert Phillips11c67672020-04-23 15:10:03 -0400112
Robert Phillips0c088492020-11-10 08:30:50 -0500113 recordingCanvas->drawImageRect(promiseImage.get(), srcRect, dstRect, nullptr);
Robert Phillips11c67672020-04-23 15:10:03 -0400114 }
115
116 fComposeDDL = recorder.detach();
Robert Phillips889d6132020-06-16 11:11:33 -0400117 SkASSERT(fComposeDDL);
Robert Phillips11c67672020-04-23 15:10:03 -0400118}
119
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400120void DDLTileHelper::TileData::precompile(GrDirectContext* direct) {
Robert Phillips6eb5cb92020-03-05 12:52:45 -0500121 SkASSERT(fDisplayList);
122
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400123 SkDeferredDisplayList::ProgramIterator iter(direct, fDisplayList.get());
Robert Phillips6eb5cb92020-03-05 12:52:45 -0500124 for (; !iter.done(); iter.next()) {
125 iter.compile();
126 }
127}
128
Adlai Hollerb2705682020-10-20 10:11:53 -0400129sk_sp<SkSurface> DDLTileHelper::TileData::makeWrappedTileDest(GrRecordingContext* context) {
Robert Phillips11c67672020-04-23 15:10:03 -0400130 SkASSERT(fCallbackContext && fCallbackContext->promiseImageTexture());
131
132 auto promiseImageTexture = fCallbackContext->promiseImageTexture();
133 if (!promiseImageTexture->backendTexture().isValid()) {
Robert Phillips8472a3d2020-04-16 16:27:45 -0400134 return nullptr;
135 }
Robert Phillips7ae9d2f2020-04-15 10:58:15 -0400136
Robert Phillips11c67672020-04-23 15:10:03 -0400137 // Here we are, unfortunately, aliasing the backend texture held by the SkPromiseImageTexture.
138 // Both the tile's destination surface and the promise image used to draw the tile will be
139 // backed by the same backendTexture - unbeknownst to Ganesh.
Robert Phillips8472a3d2020-04-16 16:27:45 -0400140 return SkSurface::MakeFromBackendTexture(context,
Robert Phillips11c67672020-04-23 15:10:03 -0400141 promiseImageTexture->backendTexture(),
Robert Phillips8472a3d2020-04-16 16:27:45 -0400142 fCharacterization.origin(),
143 fCharacterization.sampleCount(),
144 fCharacterization.colorType(),
145 fCharacterization.refColorSpace(),
146 &fCharacterization.surfaceProps());
147}
148
Adlai Hollerb2705682020-10-20 10:11:53 -0400149void DDLTileHelper::TileData::drawSKPDirectly(GrRecordingContext* context) {
Robert Phillips8472a3d2020-04-16 16:27:45 -0400150 SkASSERT(!fDisplayList && !fTileSurface && fReconstitutedPicture);
151
152 fTileSurface = this->makeWrappedTileDest(context);
153 if (fTileSurface) {
154 SkCanvas* tileCanvas = fTileSurface->getCanvas();
Robert Phillips24a8e9e2020-03-06 20:26:28 +0000155
Robert Phillips0c088492020-11-10 08:30:50 -0500156 SkASSERT(this->padOffset().isZero() && this->paddedRectSize() == fClip.size());
Robert Phillips24a8e9e2020-03-06 20:26:28 +0000157 tileCanvas->clipRect(SkRect::MakeWH(fClip.width(), fClip.height()));
158 tileCanvas->translate(-fClip.fLeft, -fClip.fTop);
159
160 tileCanvas->drawPicture(fReconstitutedPicture);
161
Robert Phillips8472a3d2020-04-16 16:27:45 -0400162 // We can't snap an image here bc, since we're using wrapped backend textures for the
163 // surfaces, that would incur a copy.
Robert Phillips24a8e9e2020-03-06 20:26:28 +0000164 }
165}
166
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400167void DDLTileHelper::TileData::draw(GrDirectContext* direct) {
Robert Phillips8472a3d2020-04-16 16:27:45 -0400168 SkASSERT(fDisplayList && !fTileSurface);
Robert Phillips96601082018-05-29 16:13:26 -0400169
Robert Phillips11c67672020-04-23 15:10:03 -0400170 // The tile's surface needs to be held until after the DDL is flushed bc the DDL doesn't take
171 // a ref on its destination proxy.
172 // TODO: make the DDL (or probably the drawing manager) take a ref on the destination proxy
173 // (maybe in GrDrawingManager::addDDLTarget).
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400174 fTileSurface = this->makeWrappedTileDest(direct);
Robert Phillips8472a3d2020-04-16 16:27:45 -0400175 if (fTileSurface) {
Robert Phillips0c088492020-11-10 08:30:50 -0500176 fTileSurface->draw(fDisplayList, this->padOffset().x(), this->padOffset().y());
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500177
Robert Phillips8472a3d2020-04-16 16:27:45 -0400178 // We can't snap an image here bc, since we're using wrapped backend textures for the
179 // surfaces, that would incur a copy.
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500180 }
Robert Phillips96601082018-05-29 16:13:26 -0400181}
182
Robert Phillips96601082018-05-29 16:13:26 -0400183void DDLTileHelper::TileData::reset() {
184 // TODO: when DDLs are re-renderable we don't need to do this
185 fDisplayList = nullptr;
Robert Phillips11c67672020-04-23 15:10:03 -0400186
Robert Phillips8472a3d2020-04-16 16:27:45 -0400187 fTileSurface = nullptr;
188}
189
Robert Phillips0c088492020-11-10 08:30:50 -0500190sk_sp<SkImage> DDLTileHelper::TileData::makePromiseImageForDst(
191 SkDeferredDisplayListRecorder* recorder) {
Robert Phillips11c67672020-04-23 15:10:03 -0400192 SkASSERT(fCallbackContext);
193
194 // The promise image gets a ref on the promise callback context
Brian Salomonf1432742020-11-09 15:40:27 -0500195 sk_sp<SkImage> promiseImage =
196 recorder->makePromiseTexture(fCallbackContext->backendFormat(),
Robert Phillips0c088492020-11-10 08:30:50 -0500197 this->paddedRectSize().width(),
198 this->paddedRectSize().height(),
Brian Salomonf1432742020-11-09 15:40:27 -0500199 GrMipmapped::kNo,
200 GrSurfaceOrigin::kBottomLeft_GrSurfaceOrigin,
201 fCharacterization.colorType(),
202 kPremul_SkAlphaType,
203 fCharacterization.refColorSpace(),
204 PromiseImageCallbackContext::PromiseImageFulfillProc,
205 PromiseImageCallbackContext::PromiseImageReleaseProc,
206 (void*)this->refCallbackContext().release());
Robert Phillips11c67672020-04-23 15:10:03 -0400207 fCallbackContext->wasAddedToImage();
208
209 return promiseImage;
210}
211
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400212void DDLTileHelper::TileData::CreateBackendTexture(GrDirectContext* direct, TileData* tile) {
Robert Phillips11c67672020-04-23 15:10:03 -0400213 SkASSERT(tile->fCallbackContext && !tile->fCallbackContext->promiseImageTexture());
Greg Daniel398ecf12020-08-26 16:33:54 -0400214 const SkSurfaceCharacterization& c = tile->fCharacterization;
215 GrBackendTexture beTex = direct->createBackendTexture(c.width(), c.height(), c.colorType(),
216 GrMipMapped(c.isMipMapped()),
217 GrRenderable::kYes);
Robert Phillips11c67672020-04-23 15:10:03 -0400218 tile->fCallbackContext->setBackendTexture(beTex);
Robert Phillips8472a3d2020-04-16 16:27:45 -0400219}
220
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400221void DDLTileHelper::TileData::DeleteBackendTexture(GrDirectContext*, TileData* tile) {
Robert Phillips11c67672020-04-23 15:10:03 -0400222 SkASSERT(tile->fCallbackContext);
223
Robert Phillips8472a3d2020-04-16 16:27:45 -0400224 // TODO: it seems that, on the Linux bots, backend texture creation is failing
225 // a lot (skbug.com/10142)
Robert Phillips11c67672020-04-23 15:10:03 -0400226 SkASSERT(!tile->fCallbackContext->promiseImageTexture() ||
227 tile->fCallbackContext->promiseImageTexture()->backendTexture().isValid());
Robert Phillips8472a3d2020-04-16 16:27:45 -0400228
229 tile->fTileSurface = nullptr;
Robert Phillips11c67672020-04-23 15:10:03 -0400230
231 SkASSERT(tile->fCallbackContext->unique());
232 tile->fCallbackContext.reset();
Robert Phillips96601082018-05-29 16:13:26 -0400233}
234
235///////////////////////////////////////////////////////////////////////////////////////////////////
236
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400237DDLTileHelper::DDLTileHelper(GrDirectContext* direct,
Robert Phillips19f466d2020-02-26 10:27:07 -0500238 const SkSurfaceCharacterization& dstChar,
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500239 const SkIRect& viewport,
Robert Phillips0c088492020-11-10 08:30:50 -0500240 int numDivisions,
241 bool addRandomPaddingToDst)
Robert Phillips11c67672020-04-23 15:10:03 -0400242 : fNumDivisions(numDivisions)
Adlai Holler8e821232020-05-11 13:33:59 -0400243 , fTiles(numDivisions * numDivisions)
Robert Phillips11c67672020-04-23 15:10:03 -0400244 , fDstCharacterization(dstChar) {
Robert Phillips96601082018-05-29 16:13:26 -0400245 SkASSERT(fNumDivisions > 0);
Robert Phillips96601082018-05-29 16:13:26 -0400246
247 int xTileSize = viewport.width()/fNumDivisions;
248 int yTileSize = viewport.height()/fNumDivisions;
249
Robert Phillips0c088492020-11-10 08:30:50 -0500250 SkRandom rand;
251
Robert Phillips96601082018-05-29 16:13:26 -0400252 // Create the destination tiles
253 for (int y = 0, yOff = 0; y < fNumDivisions; ++y, yOff += yTileSize) {
254 int ySize = (y < fNumDivisions-1) ? yTileSize : viewport.height()-yOff;
255
256 for (int x = 0, xOff = 0; x < fNumDivisions; ++x, xOff += xTileSize) {
257 int xSize = (x < fNumDivisions-1) ? xTileSize : viewport.width()-xOff;
258
259 SkIRect clip = SkIRect::MakeXYWH(xOff, yOff, xSize, ySize);
260
261 SkASSERT(viewport.contains(clip));
262
Robert Phillips0c088492020-11-10 08:30:50 -0500263 static const uint32_t kMaxPad = 64;
264 int32_t lPad = addRandomPaddingToDst ? rand.nextRangeU(0, kMaxPad) : 0;
265 int32_t tPad = addRandomPaddingToDst ? rand.nextRangeU(0, kMaxPad) : 0;
266 int32_t rPad = addRandomPaddingToDst ? rand.nextRangeU(0, kMaxPad) : 0;
267 int32_t bPad = addRandomPaddingToDst ? rand.nextRangeU(0, kMaxPad) : 0;
268
269 fTiles[y*fNumDivisions+x].init(y*fNumDivisions+x, direct, dstChar, clip,
270 {lPad, tPad, rPad, bPad});
Robert Phillips96601082018-05-29 16:13:26 -0400271 }
272 }
273}
274
275void DDLTileHelper::createSKPPerTile(SkData* compressedPictureData,
276 const DDLPromiseImageHelper& helper) {
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500277 for (int i = 0; i < this->numTiles(); ++i) {
Robert Phillips96601082018-05-29 16:13:26 -0400278 fTiles[i].createTileSpecificSKP(compressedPictureData, helper);
279 }
280}
281
282void DDLTileHelper::createDDLsInParallel() {
283#if 1
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500284 SkTaskGroup().batch(this->numTiles(), [&](int i) { fTiles[i].createDDL(); });
Robert Phillips11c67672020-04-23 15:10:03 -0400285 SkTaskGroup().add([this]{ this->createComposeDDL(); });
Robert Phillipsf18c7562018-06-13 09:01:36 -0400286 SkTaskGroup().wait();
Robert Phillips96601082018-05-29 16:13:26 -0400287#else
288 // Use this code path to debug w/o threads
Robert Phillips24a8e9e2020-03-06 20:26:28 +0000289 for (int i = 0; i < this->numTiles(); ++i) {
Robert Phillips96601082018-05-29 16:13:26 -0400290 fTiles[i].createDDL();
291 }
Robert Phillips11c67672020-04-23 15:10:03 -0400292 this->createComposeDDL();
Robert Phillips96601082018-05-29 16:13:26 -0400293#endif
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500294}
Robert Phillips96601082018-05-29 16:13:26 -0400295
Robert Phillips7b0ed552020-02-20 12:45:19 -0500296// On the gpu thread:
297// precompile any programs
298// replay the DDL into a surface to make the tile image
299// compose the tile image into the main canvas
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400300static void do_gpu_stuff(GrDirectContext* direct, DDLTileHelper::TileData* tile) {
Robert Phillips7b0ed552020-02-20 12:45:19 -0500301
302 // TODO: schedule program compilation as their own tasks
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400303 tile->precompile(direct);
Robert Phillips7b0ed552020-02-20 12:45:19 -0500304
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400305 tile->draw(direct);
Robert Phillips5dbcca52020-05-29 10:41:33 -0400306
Robert Phillips5dbcca52020-05-29 10:41:33 -0400307 tile->dropDDL();
Robert Phillips7b0ed552020-02-20 12:45:19 -0500308}
309
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500310// We expect to have more than one recording thread but just one gpu thread
311void DDLTileHelper::kickOffThreadedWork(SkTaskGroup* recordingTaskGroup,
312 SkTaskGroup* gpuTaskGroup,
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400313 GrDirectContext* direct) {
314 SkASSERT(recordingTaskGroup && gpuTaskGroup && direct);
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500315
316 for (int i = 0; i < this->numTiles(); ++i) {
317 TileData* tile = &fTiles[i];
318
319 // On a recording thread:
320 // generate the tile's DDL
321 // schedule gpu-thread processing of the DDL
322 // Note: a finer grained approach would be add a scheduling task which would evaluate
323 // which DDLs were ready to be rendered based on their prerequisites
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400324 recordingTaskGroup->add([tile, gpuTaskGroup, direct]() {
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500325 tile->createDDL();
326
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400327 gpuTaskGroup->add([direct, tile]() {
328 do_gpu_stuff(direct, tile);
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500329 });
330 });
331 }
Robert Phillips11c67672020-04-23 15:10:03 -0400332
333 recordingTaskGroup->add([this] { this->createComposeDDL(); });
Robert Phillips96601082018-05-29 16:13:26 -0400334}
335
Robert Phillips5dbcca52020-05-29 10:41:33 -0400336// Only called from ViaDDL
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400337void DDLTileHelper::precompileAndDrawAllTiles(GrDirectContext* direct) {
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500338 for (int i = 0; i < this->numTiles(); ++i) {
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400339 fTiles[i].precompile(direct);
340 fTiles[i].draw(direct);
Robert Phillips96601082018-05-29 16:13:26 -0400341 }
Robert Phillips96601082018-05-29 16:13:26 -0400342}
343
Robert Phillips5dbcca52020-05-29 10:41:33 -0400344// Only called from skpbench
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400345void DDLTileHelper::interleaveDDLCreationAndDraw(GrDirectContext* direct) {
Robert Phillips24a8e9e2020-03-06 20:26:28 +0000346 for (int i = 0; i < this->numTiles(); ++i) {
347 fTiles[i].createDDL();
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400348 fTiles[i].draw(direct);
Robert Phillips24a8e9e2020-03-06 20:26:28 +0000349 }
350}
351
Robert Phillips5dbcca52020-05-29 10:41:33 -0400352// Only called from skpbench
Adlai Hollerb2705682020-10-20 10:11:53 -0400353void DDLTileHelper::drawAllTilesDirectly(GrDirectContext* context) {
Robert Phillips24a8e9e2020-03-06 20:26:28 +0000354 for (int i = 0; i < this->numTiles(); ++i) {
355 fTiles[i].drawSKPDirectly(context);
356 }
357}
358
Robert Phillips11c67672020-04-23 15:10:03 -0400359void DDLTileHelper::dropCallbackContexts() {
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500360 for (int i = 0; i < this->numTiles(); ++i) {
Robert Phillips11c67672020-04-23 15:10:03 -0400361 fTiles[i].dropCallbackContext();
Robert Phillips96601082018-05-29 16:13:26 -0400362 }
363}
364
365void DDLTileHelper::resetAllTiles() {
Robert Phillipsa865a3a2020-02-14 10:49:39 -0500366 for (int i = 0; i < this->numTiles(); ++i) {
Robert Phillips96601082018-05-29 16:13:26 -0400367 fTiles[i].reset();
368 }
Robert Phillips11c67672020-04-23 15:10:03 -0400369 fComposeDDL.reset();
Robert Phillips96601082018-05-29 16:13:26 -0400370}
Robert Phillips8472a3d2020-04-16 16:27:45 -0400371
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400372void DDLTileHelper::createBackendTextures(SkTaskGroup* taskGroup, GrDirectContext* direct) {
Robert Phillips8472a3d2020-04-16 16:27:45 -0400373
374 if (taskGroup) {
375 for (int i = 0; i < this->numTiles(); ++i) {
376 TileData* tile = &fTiles[i];
377
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400378 taskGroup->add([direct, tile]() { TileData::CreateBackendTexture(direct, tile); });
Robert Phillips8472a3d2020-04-16 16:27:45 -0400379 }
380 } else {
381 for (int i = 0; i < this->numTiles(); ++i) {
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400382 TileData::CreateBackendTexture(direct, &fTiles[i]);
Robert Phillips8472a3d2020-04-16 16:27:45 -0400383 }
384 }
385}
386
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400387void DDLTileHelper::deleteBackendTextures(SkTaskGroup* taskGroup, GrDirectContext* direct) {
Robert Phillips8472a3d2020-04-16 16:27:45 -0400388 if (taskGroup) {
389 for (int i = 0; i < this->numTiles(); ++i) {
390 TileData* tile = &fTiles[i];
391
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400392 taskGroup->add([direct, tile]() { TileData::DeleteBackendTexture(direct, tile); });
Robert Phillips8472a3d2020-04-16 16:27:45 -0400393 }
394 } else {
395 for (int i = 0; i < this->numTiles(); ++i) {
Robert Phillipsd5f3c982020-07-07 13:18:47 -0400396 TileData::DeleteBackendTexture(direct, &fTiles[i]);
Robert Phillips8472a3d2020-04-16 16:27:45 -0400397 }
398 }
399}