blob: fa6f8115bcdd48ef50fdd41a3adc5ee2e6fd64b4 [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
15#if SK_SUPPORT_GPU
16
17class DDLPromiseImageHelper;
18class SkCanvas;
19class SkData;
20class SkDeferredDisplayList;
21class SkPicture;
22class SkSurface;
23class SkSurfaceCharacterization;
24
25class DDLTileHelper {
26public:
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
74private:
75 int fNumDivisions; // number of tiles along a side
76 SkTArray<TileData> fTiles;
77};
78
79#endif
80#endif