Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 1 | /* |
| 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 Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "tools/DDLTileHelper.h" |
Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #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" |
| 15 | #include "src/core/SkDeferredDisplayListPriv.h" |
| 16 | #include "src/core/SkTaskGroup.h" |
Robert Phillips | 7b0ed55 | 2020-02-20 12:45:19 -0500 | [diff] [blame] | 17 | #include "src/gpu/GrContextPriv.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 18 | #include "src/image/SkImage_Gpu.h" |
| 19 | #include "tools/DDLPromiseImageHelper.h" |
Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 20 | |
Robert Phillips | 19f466d | 2020-02-26 10:27:07 -0500 | [diff] [blame] | 21 | void DDLTileHelper::TileData::init(int id, |
| 22 | sk_sp<SkSurface> dstSurface, |
| 23 | const SkSurfaceCharacterization& dstSurfaceCharacterization, |
| 24 | const SkIRect& clip) { |
Robert Phillips | a865a3a | 2020-02-14 10:49:39 -0500 | [diff] [blame] | 25 | fID = id; |
| 26 | fDstSurface = dstSurface; |
| 27 | fClip = clip; |
| 28 | |
Robert Phillips | 19f466d | 2020-02-26 10:27:07 -0500 | [diff] [blame] | 29 | fCharacterization = dstSurfaceCharacterization.createResized(clip.width(), clip.height()); |
Robert Phillips | a865a3a | 2020-02-14 10:49:39 -0500 | [diff] [blame] | 30 | SkASSERT(fCharacterization.isValid()); |
Robert Phillips | 8472a3d | 2020-04-16 16:27:45 -0400 | [diff] [blame^] | 31 | SkASSERT(!fBackendTexture.isValid()); |
Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 32 | } |
| 33 | |
Robert Phillips | a865a3a | 2020-02-14 10:49:39 -0500 | [diff] [blame] | 34 | DDLTileHelper::TileData::~TileData() {} |
| 35 | |
Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 36 | void DDLTileHelper::TileData::createTileSpecificSKP(SkData* compressedPictureData, |
| 37 | const DDLPromiseImageHelper& helper) { |
Robert Phillips | 7a3197b | 2018-09-26 21:18:23 +0000 | [diff] [blame] | 38 | SkASSERT(!fReconstitutedPicture); |
Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 39 | |
Robert Phillips | 7a3197b | 2018-09-26 21:18:23 +0000 | [diff] [blame] | 40 | // This is bending the DDLRecorder contract! The promise images in the SKP should be |
| 41 | // created by the same recorder used to create the matching DDL. |
| 42 | SkDeferredDisplayListRecorder recorder(fCharacterization); |
Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 43 | |
Robert Phillips | 7a3197b | 2018-09-26 21:18:23 +0000 | [diff] [blame] | 44 | fReconstitutedPicture = helper.reinflateSKP(&recorder, compressedPictureData, &fPromiseImages); |
Robert Phillips | e8e2bb1 | 2018-09-27 14:26:47 -0400 | [diff] [blame] | 45 | |
| 46 | std::unique_ptr<SkDeferredDisplayList> ddl = recorder.detach(); |
Chris Dalton | 6b49810 | 2019-08-01 14:14:52 -0600 | [diff] [blame] | 47 | if (ddl->priv().numRenderTasks()) { |
Robert Phillips | e8e2bb1 | 2018-09-27 14:26:47 -0400 | [diff] [blame] | 48 | // TODO: remove this once skbug.com/8424 is fixed. If the DDL resulting from the |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 49 | // reinflation of the SKPs contains opsTasks that means some image subset operation |
Robert Phillips | e8e2bb1 | 2018-09-27 14:26:47 -0400 | [diff] [blame] | 50 | // created a draw. |
| 51 | fReconstitutedPicture.reset(); |
| 52 | } |
Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | void DDLTileHelper::TileData::createDDL() { |
Robert Phillips | 24a8e9e | 2020-03-06 20:26:28 +0000 | [diff] [blame] | 56 | SkASSERT(!fDisplayList && fReconstitutedPicture); |
Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 57 | |
Robert Phillips | 7a3197b | 2018-09-26 21:18:23 +0000 | [diff] [blame] | 58 | SkDeferredDisplayListRecorder recorder(fCharacterization); |
| 59 | |
| 60 | // DDL TODO: the DDLRecorder's GrContext isn't initialized until getCanvas is called. |
| 61 | // Maybe set it up in the ctor? |
Robert Phillips | 24a8e9e | 2020-03-06 20:26:28 +0000 | [diff] [blame] | 62 | SkCanvas* recordingCanvas = recorder.getCanvas(); |
Robert Phillips | 7a3197b | 2018-09-26 21:18:23 +0000 | [diff] [blame] | 63 | |
| 64 | // Because we cheated in createTileSpecificSKP and used the wrong DDLRecorder, the GrContext's |
| 65 | // stored in fReconstitutedPicture's promise images are incorrect. Patch them with the correct |
| 66 | // one now. |
| 67 | for (int i = 0; i < fPromiseImages.count(); ++i) { |
Robert Phillips | 24a8e9e | 2020-03-06 20:26:28 +0000 | [diff] [blame] | 68 | GrContext* newContext = recordingCanvas->getGrContext(); |
Robert Phillips | 7a3197b | 2018-09-26 21:18:23 +0000 | [diff] [blame] | 69 | |
| 70 | if (fPromiseImages[i]->isTextureBacked()) { |
Jim Van Verth | 21bd60d | 2018-10-12 15:00:20 -0400 | [diff] [blame] | 71 | SkImage_GpuBase* gpuImage = (SkImage_GpuBase*) fPromiseImages[i].get(); |
Robert Phillips | 7a3197b | 2018-09-26 21:18:23 +0000 | [diff] [blame] | 72 | gpuImage->resetContext(sk_ref_sp(newContext)); |
| 73 | } |
| 74 | } |
Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 75 | |
Robert Phillips | 24a8e9e | 2020-03-06 20:26:28 +0000 | [diff] [blame] | 76 | recordingCanvas->clipRect(SkRect::MakeWH(fClip.width(), fClip.height())); |
| 77 | recordingCanvas->translate(-fClip.fLeft, -fClip.fTop); |
Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 78 | |
| 79 | // Note: in this use case we only render a picture to the deferred canvas |
| 80 | // but, more generally, clients will use arbitrary draw calls. |
Robert Phillips | 24a8e9e | 2020-03-06 20:26:28 +0000 | [diff] [blame] | 81 | recordingCanvas->drawPicture(fReconstitutedPicture); |
Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 82 | |
Robert Phillips | 7a3197b | 2018-09-26 21:18:23 +0000 | [diff] [blame] | 83 | fDisplayList = recorder.detach(); |
Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 84 | } |
| 85 | |
Robert Phillips | 6eb5cb9 | 2020-03-05 12:52:45 -0500 | [diff] [blame] | 86 | void DDLTileHelper::TileData::precompile(GrContext* context) { |
| 87 | SkASSERT(fDisplayList); |
| 88 | |
| 89 | SkDeferredDisplayList::ProgramIterator iter(context, fDisplayList.get()); |
| 90 | for (; !iter.done(); iter.next()) { |
| 91 | iter.compile(); |
| 92 | } |
| 93 | } |
| 94 | |
Robert Phillips | 8472a3d | 2020-04-16 16:27:45 -0400 | [diff] [blame^] | 95 | sk_sp<SkSurface> DDLTileHelper::TileData::makeWrappedTileDest(GrContext* context) { |
| 96 | if (!fBackendTexture.isValid()) { |
| 97 | return nullptr; |
| 98 | } |
Robert Phillips | 7ae9d2f | 2020-04-15 10:58:15 -0400 | [diff] [blame] | 99 | |
Robert Phillips | 8472a3d | 2020-04-16 16:27:45 -0400 | [diff] [blame^] | 100 | return SkSurface::MakeFromBackendTexture(context, |
| 101 | fBackendTexture, |
| 102 | fCharacterization.origin(), |
| 103 | fCharacterization.sampleCount(), |
| 104 | fCharacterization.colorType(), |
| 105 | fCharacterization.refColorSpace(), |
| 106 | &fCharacterization.surfaceProps()); |
| 107 | } |
| 108 | |
| 109 | void DDLTileHelper::TileData::drawSKPDirectly(GrContext* context) { |
| 110 | SkASSERT(!fDisplayList && !fTileSurface && fReconstitutedPicture); |
| 111 | |
| 112 | fTileSurface = this->makeWrappedTileDest(context); |
| 113 | if (fTileSurface) { |
| 114 | SkCanvas* tileCanvas = fTileSurface->getCanvas(); |
Robert Phillips | 24a8e9e | 2020-03-06 20:26:28 +0000 | [diff] [blame] | 115 | |
| 116 | tileCanvas->clipRect(SkRect::MakeWH(fClip.width(), fClip.height())); |
| 117 | tileCanvas->translate(-fClip.fLeft, -fClip.fTop); |
| 118 | |
| 119 | tileCanvas->drawPicture(fReconstitutedPicture); |
| 120 | |
Robert Phillips | 8472a3d | 2020-04-16 16:27:45 -0400 | [diff] [blame^] | 121 | // We can't snap an image here bc, since we're using wrapped backend textures for the |
| 122 | // surfaces, that would incur a copy. |
Robert Phillips | 24a8e9e | 2020-03-06 20:26:28 +0000 | [diff] [blame] | 123 | } |
| 124 | } |
| 125 | |
Robert Phillips | a865a3a | 2020-02-14 10:49:39 -0500 | [diff] [blame] | 126 | void DDLTileHelper::TileData::draw(GrContext* context) { |
Robert Phillips | 8472a3d | 2020-04-16 16:27:45 -0400 | [diff] [blame^] | 127 | SkASSERT(fDisplayList && !fTileSurface); |
Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 128 | |
Robert Phillips | 8472a3d | 2020-04-16 16:27:45 -0400 | [diff] [blame^] | 129 | // The tile's surface needs to be held until after the DDL is flushed |
| 130 | fTileSurface = this->makeWrappedTileDest(context); |
| 131 | if (fTileSurface) { |
| 132 | fTileSurface->draw(fDisplayList.get()); |
Robert Phillips | a865a3a | 2020-02-14 10:49:39 -0500 | [diff] [blame] | 133 | |
Robert Phillips | 8472a3d | 2020-04-16 16:27:45 -0400 | [diff] [blame^] | 134 | // We can't snap an image here bc, since we're using wrapped backend textures for the |
| 135 | // surfaces, that would incur a copy. |
Robert Phillips | a865a3a | 2020-02-14 10:49:39 -0500 | [diff] [blame] | 136 | } |
Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 137 | } |
| 138 | |
Robert Phillips | a865a3a | 2020-02-14 10:49:39 -0500 | [diff] [blame] | 139 | // TODO: We should create a single DDL for the composition step and just add replaying it |
| 140 | // as the last GPU task |
Robert Phillips | 8472a3d | 2020-04-16 16:27:45 -0400 | [diff] [blame^] | 141 | void DDLTileHelper::TileData::compose(GrContext* context) { |
| 142 | SkASSERT(context->priv().asDirectContext()); |
| 143 | SkASSERT(fDstSurface); |
| 144 | |
| 145 | if (!fBackendTexture.isValid()) { |
| 146 | return; |
| 147 | } |
| 148 | |
| 149 | // Here we are, unfortunately, aliasing 'fBackendTexture'. It is backing both 'fTileSurface' |
| 150 | // and 'tmp'. |
| 151 | sk_sp<SkImage> tmp = SkImage::MakeFromTexture(context, |
| 152 | fBackendTexture, |
| 153 | fCharacterization.origin(), |
| 154 | fCharacterization.colorType(), |
| 155 | kPremul_SkAlphaType, |
| 156 | fCharacterization.refColorSpace()); |
Robert Phillips | a865a3a | 2020-02-14 10:49:39 -0500 | [diff] [blame] | 157 | |
| 158 | SkCanvas* canvas = fDstSurface->getCanvas(); |
| 159 | canvas->save(); |
| 160 | canvas->clipRect(SkRect::Make(fClip)); |
Robert Phillips | 8472a3d | 2020-04-16 16:27:45 -0400 | [diff] [blame^] | 161 | canvas->drawImage(tmp, fClip.fLeft, fClip.fTop); |
Robert Phillips | a865a3a | 2020-02-14 10:49:39 -0500 | [diff] [blame] | 162 | canvas->restore(); |
Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | void DDLTileHelper::TileData::reset() { |
| 166 | // TODO: when DDLs are re-renderable we don't need to do this |
| 167 | fDisplayList = nullptr; |
Robert Phillips | 8472a3d | 2020-04-16 16:27:45 -0400 | [diff] [blame^] | 168 | fTileSurface = nullptr; |
| 169 | } |
| 170 | |
| 171 | void DDLTileHelper::TileData::CreateBackendTexture(GrContext* context, TileData* tile) { |
| 172 | SkASSERT(context->priv().asDirectContext()); |
| 173 | SkASSERT(!tile->fBackendTexture.isValid()); |
| 174 | |
| 175 | tile->fBackendTexture = context->createBackendTexture(tile->fCharacterization); |
| 176 | // TODO: it seems that, on the Linux bots, backend texture creation is failing |
| 177 | // a lot (skbug.com/10142) |
| 178 | //SkASSERT(tile->fBackendTexture.isValid()); |
| 179 | } |
| 180 | |
| 181 | void DDLTileHelper::TileData::DeleteBackendTexture(GrContext* context, TileData* tile) { |
| 182 | SkASSERT(context->priv().asDirectContext()); |
| 183 | // TODO: it seems that, on the Linux bots, backend texture creation is failing |
| 184 | // a lot (skbug.com/10142) |
| 185 | //SkASSERT(tile->fBackendTexture.isValid()); |
| 186 | |
| 187 | tile->fTileSurface = nullptr; |
| 188 | context->deleteBackendTexture(tile->fBackendTexture); |
Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 192 | |
Robert Phillips | a865a3a | 2020-02-14 10:49:39 -0500 | [diff] [blame] | 193 | DDLTileHelper::DDLTileHelper(sk_sp<SkSurface> dstSurface, |
Robert Phillips | 19f466d | 2020-02-26 10:27:07 -0500 | [diff] [blame] | 194 | const SkSurfaceCharacterization& dstChar, |
Robert Phillips | a865a3a | 2020-02-14 10:49:39 -0500 | [diff] [blame] | 195 | const SkIRect& viewport, |
| 196 | int numDivisions) |
Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 197 | : fNumDivisions(numDivisions) { |
| 198 | SkASSERT(fNumDivisions > 0); |
Robert Phillips | a865a3a | 2020-02-14 10:49:39 -0500 | [diff] [blame] | 199 | fTiles = new TileData[this->numTiles()]; |
Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 200 | |
| 201 | int xTileSize = viewport.width()/fNumDivisions; |
| 202 | int yTileSize = viewport.height()/fNumDivisions; |
| 203 | |
| 204 | // Create the destination tiles |
| 205 | for (int y = 0, yOff = 0; y < fNumDivisions; ++y, yOff += yTileSize) { |
| 206 | int ySize = (y < fNumDivisions-1) ? yTileSize : viewport.height()-yOff; |
| 207 | |
| 208 | for (int x = 0, xOff = 0; x < fNumDivisions; ++x, xOff += xTileSize) { |
| 209 | int xSize = (x < fNumDivisions-1) ? xTileSize : viewport.width()-xOff; |
| 210 | |
| 211 | SkIRect clip = SkIRect::MakeXYWH(xOff, yOff, xSize, ySize); |
| 212 | |
| 213 | SkASSERT(viewport.contains(clip)); |
| 214 | |
Robert Phillips | 19f466d | 2020-02-26 10:27:07 -0500 | [diff] [blame] | 215 | fTiles[y*fNumDivisions+x].init(y*fNumDivisions+x, dstSurface, dstChar, clip); |
Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 216 | } |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | void DDLTileHelper::createSKPPerTile(SkData* compressedPictureData, |
| 221 | const DDLPromiseImageHelper& helper) { |
Robert Phillips | a865a3a | 2020-02-14 10:49:39 -0500 | [diff] [blame] | 222 | for (int i = 0; i < this->numTiles(); ++i) { |
Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 223 | fTiles[i].createTileSpecificSKP(compressedPictureData, helper); |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | void DDLTileHelper::createDDLsInParallel() { |
| 228 | #if 1 |
Robert Phillips | a865a3a | 2020-02-14 10:49:39 -0500 | [diff] [blame] | 229 | SkTaskGroup().batch(this->numTiles(), [&](int i) { fTiles[i].createDDL(); }); |
Robert Phillips | f18c756 | 2018-06-13 09:01:36 -0400 | [diff] [blame] | 230 | SkTaskGroup().wait(); |
Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 231 | #else |
| 232 | // Use this code path to debug w/o threads |
Robert Phillips | 24a8e9e | 2020-03-06 20:26:28 +0000 | [diff] [blame] | 233 | for (int i = 0; i < this->numTiles(); ++i) { |
Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 234 | fTiles[i].createDDL(); |
| 235 | } |
| 236 | #endif |
Robert Phillips | a865a3a | 2020-02-14 10:49:39 -0500 | [diff] [blame] | 237 | } |
Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 238 | |
Robert Phillips | 7b0ed55 | 2020-02-20 12:45:19 -0500 | [diff] [blame] | 239 | // On the gpu thread: |
| 240 | // precompile any programs |
| 241 | // replay the DDL into a surface to make the tile image |
| 242 | // compose the tile image into the main canvas |
| 243 | static void do_gpu_stuff(GrContext* context, DDLTileHelper::TileData* tile) { |
Robert Phillips | 7b0ed55 | 2020-02-20 12:45:19 -0500 | [diff] [blame] | 244 | |
| 245 | // TODO: schedule program compilation as their own tasks |
Robert Phillips | 6eb5cb9 | 2020-03-05 12:52:45 -0500 | [diff] [blame] | 246 | tile->precompile(context); |
Robert Phillips | 7b0ed55 | 2020-02-20 12:45:19 -0500 | [diff] [blame] | 247 | |
| 248 | tile->draw(context); |
| 249 | |
| 250 | // TODO: we should actually have a separate DDL that does |
| 251 | // the final composition draw |
Robert Phillips | 8472a3d | 2020-04-16 16:27:45 -0400 | [diff] [blame^] | 252 | tile->compose(context); |
Robert Phillips | 7b0ed55 | 2020-02-20 12:45:19 -0500 | [diff] [blame] | 253 | } |
| 254 | |
Robert Phillips | a865a3a | 2020-02-14 10:49:39 -0500 | [diff] [blame] | 255 | // We expect to have more than one recording thread but just one gpu thread |
| 256 | void DDLTileHelper::kickOffThreadedWork(SkTaskGroup* recordingTaskGroup, |
| 257 | SkTaskGroup* gpuTaskGroup, |
| 258 | GrContext* gpuThreadContext) { |
| 259 | SkASSERT(recordingTaskGroup && gpuTaskGroup && gpuThreadContext); |
| 260 | |
| 261 | for (int i = 0; i < this->numTiles(); ++i) { |
| 262 | TileData* tile = &fTiles[i]; |
| 263 | |
| 264 | // On a recording thread: |
| 265 | // generate the tile's DDL |
| 266 | // schedule gpu-thread processing of the DDL |
| 267 | // Note: a finer grained approach would be add a scheduling task which would evaluate |
| 268 | // which DDLs were ready to be rendered based on their prerequisites |
| 269 | recordingTaskGroup->add([tile, gpuTaskGroup, gpuThreadContext]() { |
| 270 | tile->createDDL(); |
| 271 | |
| 272 | gpuTaskGroup->add([gpuThreadContext, tile]() { |
Robert Phillips | 7b0ed55 | 2020-02-20 12:45:19 -0500 | [diff] [blame] | 273 | do_gpu_stuff(gpuThreadContext, tile); |
Robert Phillips | a865a3a | 2020-02-14 10:49:39 -0500 | [diff] [blame] | 274 | }); |
| 275 | }); |
| 276 | } |
Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 277 | } |
| 278 | |
Robert Phillips | 6eb5cb9 | 2020-03-05 12:52:45 -0500 | [diff] [blame] | 279 | void DDLTileHelper::precompileAndDrawAllTiles(GrContext* context) { |
Robert Phillips | a865a3a | 2020-02-14 10:49:39 -0500 | [diff] [blame] | 280 | for (int i = 0; i < this->numTiles(); ++i) { |
Robert Phillips | 6eb5cb9 | 2020-03-05 12:52:45 -0500 | [diff] [blame] | 281 | fTiles[i].precompile(context); |
Robert Phillips | a865a3a | 2020-02-14 10:49:39 -0500 | [diff] [blame] | 282 | fTiles[i].draw(context); |
Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 283 | } |
Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 284 | } |
| 285 | |
Robert Phillips | 24a8e9e | 2020-03-06 20:26:28 +0000 | [diff] [blame] | 286 | void DDLTileHelper::interleaveDDLCreationAndDraw(GrContext* context) { |
| 287 | for (int i = 0; i < this->numTiles(); ++i) { |
| 288 | fTiles[i].createDDL(); |
| 289 | fTiles[i].draw(context); |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | void DDLTileHelper::drawAllTilesDirectly(GrContext* context) { |
| 294 | for (int i = 0; i < this->numTiles(); ++i) { |
| 295 | fTiles[i].drawSKPDirectly(context); |
| 296 | } |
| 297 | } |
| 298 | |
Robert Phillips | 8472a3d | 2020-04-16 16:27:45 -0400 | [diff] [blame^] | 299 | void DDLTileHelper::composeAllTiles(GrContext* context) { |
Robert Phillips | a865a3a | 2020-02-14 10:49:39 -0500 | [diff] [blame] | 300 | for (int i = 0; i < this->numTiles(); ++i) { |
Robert Phillips | 8472a3d | 2020-04-16 16:27:45 -0400 | [diff] [blame^] | 301 | fTiles[i].compose(context); |
Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 302 | } |
| 303 | } |
| 304 | |
| 305 | void DDLTileHelper::resetAllTiles() { |
Robert Phillips | a865a3a | 2020-02-14 10:49:39 -0500 | [diff] [blame] | 306 | for (int i = 0; i < this->numTiles(); ++i) { |
Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 307 | fTiles[i].reset(); |
| 308 | } |
| 309 | } |
Robert Phillips | 8472a3d | 2020-04-16 16:27:45 -0400 | [diff] [blame^] | 310 | |
| 311 | void DDLTileHelper::createBackendTextures(SkTaskGroup* taskGroup, GrContext* context) { |
| 312 | SkASSERT(context->priv().asDirectContext()); |
| 313 | |
| 314 | if (taskGroup) { |
| 315 | for (int i = 0; i < this->numTiles(); ++i) { |
| 316 | TileData* tile = &fTiles[i]; |
| 317 | |
| 318 | taskGroup->add([context, tile]() { TileData::CreateBackendTexture(context, tile); }); |
| 319 | } |
| 320 | } else { |
| 321 | for (int i = 0; i < this->numTiles(); ++i) { |
| 322 | TileData::CreateBackendTexture(context, &fTiles[i]); |
| 323 | } |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | void DDLTileHelper::deleteBackendTextures(SkTaskGroup* taskGroup, GrContext* context) { |
| 328 | SkASSERT(context->priv().asDirectContext()); |
| 329 | |
| 330 | if (taskGroup) { |
| 331 | for (int i = 0; i < this->numTiles(); ++i) { |
| 332 | TileData* tile = &fTiles[i]; |
| 333 | |
| 334 | taskGroup->add([context, tile]() { TileData::DeleteBackendTexture(context, tile); }); |
| 335 | } |
| 336 | } else { |
| 337 | for (int i = 0; i < this->numTiles(); ++i) { |
| 338 | TileData::DeleteBackendTexture(context, &fTiles[i]); |
| 339 | } |
| 340 | } |
| 341 | } |