blob: 669eded484212b437bb3c8fb5d82f610c80a4ba9 [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
8#ifndef DDLTileHelper_DEFINED
9#define DDLTileHelper_DEFINED
10
11#include "SkRect.h"
12#include "SkRefCnt.h"
13#include "SkSurfaceCharacterization.h"
14
Robert Phillips96601082018-05-29 16:13:26 -040015class DDLPromiseImageHelper;
16class SkCanvas;
17class SkData;
18class SkDeferredDisplayList;
19class SkPicture;
20class SkSurface;
21class SkSurfaceCharacterization;
22
23class DDLTileHelper {
24public:
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:
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
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
72private:
73 int fNumDivisions; // number of tiles along a side
74 SkTArray<TileData> fTiles;
75};
76
77#endif