| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef SkLayerInfo_DEFINED | 8 #ifndef SkLayerInfo_DEFINED |
| 9 #define SkLayerInfo_DEFINED | 9 #define SkLayerInfo_DEFINED |
| 10 | 10 |
| 11 #include "SkBigPicture.h" | 11 #include "SkPicture.h" |
| 12 #include "SkTArray.h" | 12 #include "SkTArray.h" |
| 13 | 13 |
| 14 // This class stores information about the saveLayer/restore pairs found | 14 // This class stores information about the saveLayer/restore pairs found |
| 15 // within an SkPicture. It is used by Ganesh to perform layer hoisting. | 15 // within an SkPicture. It is used by Ganesh to perform layer hoisting. |
| 16 class SkLayerInfo : public SkBigPicture::AccelData { | 16 class SkLayerInfo : public SkPicture::AccelData { |
| 17 public: | 17 public: |
| 18 // Information about a given saveLayer/restore block in an SkPicture | 18 // Information about a given saveLayer/restore block in an SkPicture |
| 19 class BlockInfo { | 19 class BlockInfo { |
| 20 public: | 20 public: |
| 21 BlockInfo() : fPicture(NULL), fPaint(NULL), fKey(NULL), fKeySize(0) {} | 21 BlockInfo() : fPicture(NULL), fPaint(NULL), fKey(NULL), fKeySize(0) {} |
| 22 ~BlockInfo() { SkSafeUnref(fPicture); SkDELETE(fPaint); SkDELETE_ARRAY(f
Key); } | 22 ~BlockInfo() { SkSafeUnref(fPicture); SkDELETE(fPaint); SkDELETE_ARRAY(f
Key); } |
| 23 | 23 |
| 24 // The picture owning the layer. If the owning picture is the top-most | 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 | 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 | 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. | 27 // is non-NULL and owns a ref on the picture. |
| 28 const SkPicture* fPicture; | 28 const SkPicture* fPicture; |
| 29 // The device space bounds of this layer. | 29 // The device space bounds of this layer. |
| 30 SkRect fBounds; | 30 SkRect fBounds; |
| 31 // If not-empty, the optional bounds parameter passed in to the saveLaye
r | 31 // If not-empty, the optional bounds parameter passed in to the saveLaye
r |
| 32 // call. | 32 // call. |
| 33 SkRect fSrcBounds; | 33 SkRect fSrcBounds; |
| 34 // The pre-matrix begins as the identity and accumulates the transforms | 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 | 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 | 36 // part of the initial matrix during replay so that it will be |
| 37 // preserved across setMatrix calls. | 37 // preserved across setMatrix calls. |
| 38 SkMatrix fPreMat; | 38 SkMatrix fPreMat; |
| 39 // The matrix state (in the leaf picture) in which this layer's draws | 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 | 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 | 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 | 42 // layer's top-left point to the origin (which must be part of the |
| 43 // initial matrix). | 43 // initial matrix). |
| 44 SkMatrix fLocalMat; | 44 SkMatrix fLocalMat; |
| 45 // The paint to use on restore. Can be NULL since it is optional. | 45 // The paint to use on restore. Can be NULL since it is optional. |
| 46 const SkPaint* fPaint; | 46 const SkPaint* fPaint; |
| 47 // The index of this saveLayer in the picture. | 47 // The index of this saveLayer in the picture. |
| 48 size_t fSaveLayerOpID; | 48 size_t fSaveLayerOpID; |
| 49 // The index of the matching restore in the picture. | 49 // The index of the matching restore in the picture. |
| 50 size_t fRestoreOpID; | 50 size_t fRestoreOpID; |
| 51 // True if this saveLayer has at least one other saveLayer nested within
it. | 51 // True if this saveLayer has at least one other saveLayer nested within
it. |
| 52 // False otherwise. | 52 // False otherwise. |
| 53 bool fHasNestedLayers; | 53 bool fHasNestedLayers; |
| 54 // True if this saveLayer is nested within another. False otherwise. | 54 // True if this saveLayer is nested within another. False otherwise. |
| 55 bool fIsNested; | 55 bool fIsNested; |
| 56 // The variable length key for this saveLayer block. It stores the | 56 // The variable length key for this saveLayer block. It stores the |
| 57 // thread of drawPicture and saveLayer operation indices that lead to th
is | 57 // thread of drawPicture and saveLayer operation indices that lead to th
is |
| 58 // saveLayer (including its own op index). The BlockInfo owns this memor
y. | 58 // saveLayer (including its own op index). The BlockInfo owns this memor
y. |
| 59 unsigned* fKey; | 59 unsigned* fKey; |
| 60 int fKeySize; // # of ints | 60 int fKeySize; // # of ints |
| 61 }; | 61 }; |
| 62 | 62 |
| 63 SkLayerInfo() {} | 63 SkLayerInfo(Key key) : INHERITED(key) { } |
| 64 | 64 |
| 65 BlockInfo& addBlock() { return fBlocks.push_back(); } | 65 BlockInfo& addBlock() { return fBlocks.push_back(); } |
| 66 | 66 |
| 67 int numBlocks() const { return fBlocks.count(); } | 67 int numBlocks() const { return fBlocks.count(); } |
| 68 | 68 |
| 69 const BlockInfo& block(int index) const { | 69 const BlockInfo& block(int index) const { |
| 70 SkASSERT(index < fBlocks.count()); | 70 SkASSERT(index < fBlocks.count()); |
| 71 | 71 |
| 72 return fBlocks[index]; | 72 return fBlocks[index]; |
| 73 } | 73 } |
| 74 | 74 |
| 75 // We may, in the future, need to pass in the GPUDevice in order to |
| 76 // incorporate the clip and matrix state into the key |
| 77 static SkPicture::AccelData::Key ComputeKey(); |
| 78 |
| 75 private: | 79 private: |
| 76 SkTArray<BlockInfo, true> fBlocks; | 80 SkTArray<BlockInfo, true> fBlocks; |
| 77 | 81 |
| 78 typedef SkBigPicture::AccelData INHERITED; | 82 typedef SkPicture::AccelData INHERITED; |
| 79 }; | 83 }; |
| 80 | 84 |
| 81 #endif // SkLayerInfo_DEFINED | 85 #endif // SkLayerInfo_DEFINED |
| OLD | NEW |