SkLayerInfo.h revision c92c129ff85b05a714bd1bf921c02d5e14651f8b
1/*
2 * Copyright 2014 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 SkLayerInfo_DEFINED
9#define SkLayerInfo_DEFINED
10
11#include "SkBigPicture.h"
12#include "SkTArray.h"
13
14// This class stores information about the saveLayer/restore pairs found
15// within an SkPicture. It is used by Ganesh to perform layer hoisting.
16class SkLayerInfo : public SkBigPicture::AccelData {
17public:
18    // Information about a given saveLayer/restore block in an SkPicture
19    class BlockInfo {
20    public:
21        BlockInfo() : fPicture(NULL), fPaint(NULL), fKey(NULL), fKeySize(0) {}
22        ~BlockInfo() { SkSafeUnref(fPicture); SkDELETE(fPaint); SkDELETE_ARRAY(fKey); }
23
24        // The picture owning the layer. If the owning picture is the top-most
25        // one (i.e., the picture for which this SkLayerInfo was created) then
26        // this pointer is NULL. If it is a nested picture then the pointer
27        // is non-NULL and owns a ref on the picture.
28        const SkPicture* fPicture;
29        // The device space bounds of this layer.
30        SkRect fBounds;
31        // If not-empty, the optional bounds parameter passed in to the saveLayer
32        // call.
33        SkRect fSrcBounds;
34        // The pre-matrix begins as the identity and accumulates the transforms
35        // of the containing SkPictures (if any). This matrix state has to be
36        // part of the initial matrix during replay so that it will be
37        // preserved across setMatrix calls.
38        SkMatrix fPreMat;
39        // The matrix state (in the leaf picture) in which this layer's draws
40        // must occur. It will/can be overridden by setMatrix calls in the
41        // layer itself. It does not include the translation needed to map the
42        // layer's top-left point to the origin (which must be part of the
43        // initial matrix).
44        SkMatrix fLocalMat;
45        // The paint to use on restore. Can be NULL since it is optional.
46        const SkPaint* fPaint;
47        // The index of this saveLayer in the picture.
48        size_t  fSaveLayerOpID;
49        // The index of the matching restore in the picture.
50        size_t  fRestoreOpID;
51        // True if this saveLayer has at least one other saveLayer nested within it.
52        // False otherwise.
53        bool    fHasNestedLayers;
54        // True if this saveLayer is nested within another. False otherwise.
55        bool    fIsNested;
56        // The variable length key for this saveLayer block. It stores the
57        // thread of drawPicture and saveLayer operation indices that lead to this
58        // saveLayer (including its own op index). The BlockInfo owns this memory.
59        unsigned* fKey;
60        int     fKeySize;  // # of ints
61    };
62
63    SkLayerInfo() {}
64
65    BlockInfo& addBlock() { return fBlocks.push_back(); }
66
67    int numBlocks() const { return fBlocks.count(); }
68
69    const BlockInfo& block(int index) const {
70        SkASSERT(index < fBlocks.count());
71
72        return fBlocks[index];
73    }
74
75private:
76    SkTArray<BlockInfo, true> fBlocks;
77
78    typedef SkBigPicture::AccelData INHERITED;
79};
80
81#endif // SkLayerInfo_DEFINED
82