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