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 | |
| 8 | #ifndef DDLTileHelper_DEFINED |
| 9 | #define DDLTileHelper_DEFINED |
| 10 | |
| 11 | #include "SkRect.h" |
| 12 | #include "SkRefCnt.h" |
| 13 | #include "SkSurfaceCharacterization.h" |
| 14 | |
Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 15 | class DDLPromiseImageHelper; |
| 16 | class SkCanvas; |
| 17 | class SkData; |
| 18 | class SkDeferredDisplayList; |
| 19 | class SkPicture; |
| 20 | class SkSurface; |
| 21 | class SkSurfaceCharacterization; |
| 22 | |
| 23 | class DDLTileHelper { |
| 24 | public: |
| 25 | // TileData class encapsulates the information and behavior for a single tile/thread in |
| 26 | // a DDL rendering. |
| 27 | class TileData { |
| 28 | public: |
| 29 | TileData(sk_sp<SkSurface>, const SkIRect& clip); |
| 30 | |
| 31 | // This method can be invoked in parallel |
| 32 | // In each thread we will reconvert the compressedPictureData into an SkPicture |
| 33 | // replacing each image-index with a promise image. |
| 34 | void createTileSpecificSKP(SkData* compressedPictureData, |
| 35 | const DDLPromiseImageHelper& helper); |
| 36 | |
| 37 | // This method can be invoked in parallel |
| 38 | // Create the per-tile DDL from the per-tile SKP |
| 39 | void createDDL(); |
| 40 | |
| 41 | // This method operates serially and replays the recorded DDL into the tile surface. |
| 42 | void draw(); |
| 43 | |
| 44 | // This method also operates serially and composes the results of replaying the DDL into |
| 45 | // the final destination surface. |
| 46 | void compose(SkCanvas* dst); |
| 47 | |
| 48 | void reset(); |
| 49 | |
| 50 | private: |
Robert Phillips | 7a3197b | 2018-09-26 21:18:23 +0000 | [diff] [blame] | 51 | sk_sp<SkSurface> fSurface; |
| 52 | SkSurfaceCharacterization fCharacterization; |
| 53 | SkIRect fClip; // in the device space of the dest canvas |
| 54 | sk_sp<SkPicture> fReconstitutedPicture; |
| 55 | SkTArray<sk_sp<SkImage>> fPromiseImages; // All the promise images in the |
| 56 | // reconstituted picture |
Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 57 | std::unique_ptr<SkDeferredDisplayList> fDisplayList; |
| 58 | }; |
| 59 | |
| 60 | DDLTileHelper(SkCanvas* canvas, const SkIRect& viewport, int numDivisions); |
| 61 | |
| 62 | void createSKPPerTile(SkData* compressedPictureData, const DDLPromiseImageHelper& helper); |
| 63 | |
| 64 | void createDDLsInParallel(); |
| 65 | |
| 66 | void drawAllTilesAndFlush(GrContext*, bool flush); |
| 67 | |
| 68 | void composeAllTiles(SkCanvas* dstCanvas); |
| 69 | |
| 70 | void resetAllTiles(); |
| 71 | |
| 72 | private: |
| 73 | int fNumDivisions; // number of tiles along a side |
| 74 | SkTArray<TileData> fTiles; |
| 75 | }; |
| 76 | |
| 77 | #endif |