OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "SkPictureStateTree.h" | 9 #include "SkPictureStateTree.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
11 | 11 |
12 SkPictureStateTree::SkPictureStateTree() | 12 SkPictureStateTree::SkPictureStateTree() |
13 : fAlloc(2048) | 13 : fAlloc(2048) |
14 , fRoot(NULL) | |
15 , fLastRestoredNode(NULL) | 14 , fLastRestoredNode(NULL) |
16 , fStateStack(sizeof(Draw), 16) { | 15 , fStateStack(sizeof(Draw), 16) { |
17 SkMatrix* identity = static_cast<SkMatrix*>(fAlloc.allocThrow(sizeof(SkMatri
x))); | 16 fRootMatrix.reset(); |
18 identity->reset(); | 17 fRoot.fParent = NULL; |
19 fRoot = static_cast<Node*>(fAlloc.allocThrow(sizeof(Node))); | 18 fRoot.fMatrix = &fRootMatrix; |
20 fRoot->fParent = NULL; | 19 fRoot.fFlags = Node::kSave_Flag; |
21 fRoot->fMatrix = identity; | 20 fRoot.fOffset = 0; |
22 fRoot->fFlags = Node::kSave_Flag; | 21 fRoot.fLevel = 0; |
23 fRoot->fOffset = 0; | 22 fCurrentState.fNode = &fRoot; |
24 fRoot->fLevel = 0; | 23 fCurrentState.fMatrix = &fRootMatrix; |
25 fCurrentState.fNode = fRoot; | |
26 fCurrentState.fMatrix = identity; | |
27 *static_cast<Draw*>(fStateStack.push_back()) = fCurrentState; | 24 *static_cast<Draw*>(fStateStack.push_back()) = fCurrentState; |
28 } | 25 } |
29 | 26 |
30 SkPictureStateTree::~SkPictureStateTree() { | 27 SkPictureStateTree::~SkPictureStateTree() { |
31 } | 28 } |
32 | 29 |
33 SkPictureStateTree::Draw* SkPictureStateTree::appendDraw(uint32_t offset) { | 30 SkPictureStateTree::Draw* SkPictureStateTree::appendDraw(uint32_t offset) { |
34 Draw* draw = static_cast<Draw*>(fAlloc.allocThrow(sizeof(Draw))); | 31 Draw* draw = static_cast<Draw*>(fAlloc.allocThrow(sizeof(Draw))); |
35 *draw = fCurrentState; | 32 *draw = fCurrentState; |
36 draw->fOffset = offset; | 33 draw->fOffset = offset; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 *m = trans; | 68 *m = trans; |
72 fCurrentState.fMatrix = m; | 69 fCurrentState.fMatrix = m; |
73 } | 70 } |
74 | 71 |
75 void SkPictureStateTree::appendClip(uint32_t offset) { | 72 void SkPictureStateTree::appendClip(uint32_t offset) { |
76 this->appendNode(offset); | 73 this->appendNode(offset); |
77 } | 74 } |
78 | 75 |
79 SkPictureStateTree::Iterator SkPictureStateTree::getIterator(const SkTDArray<voi
d*>& draws, | 76 SkPictureStateTree::Iterator SkPictureStateTree::getIterator(const SkTDArray<voi
d*>& draws, |
80 SkCanvas* canvas) { | 77 SkCanvas* canvas) { |
81 return Iterator(draws, canvas, fRoot); | 78 return Iterator(draws, canvas, &fRoot); |
82 } | 79 } |
83 | 80 |
84 void SkPictureStateTree::appendNode(uint32_t offset) { | 81 void SkPictureStateTree::appendNode(uint32_t offset) { |
85 Node* n = static_cast<Node*>(fAlloc.allocThrow(sizeof(Node))); | 82 Node* n = static_cast<Node*>(fAlloc.allocThrow(sizeof(Node))); |
86 n->fOffset = offset; | 83 n->fOffset = offset; |
87 n->fFlags = 0; | 84 n->fFlags = 0; |
88 n->fParent = fCurrentState.fNode; | 85 n->fParent = fCurrentState.fNode; |
89 n->fLevel = fCurrentState.fNode->fLevel + 1; | 86 n->fLevel = fCurrentState.fNode->fLevel + 1; |
90 n->fMatrix = fCurrentState.fMatrix; | 87 n->fMatrix = fCurrentState.fMatrix; |
91 fCurrentState.fNode = n; | 88 fCurrentState.fNode = n; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 if (fCurrentMatrix != draw->fMatrix) { | 177 if (fCurrentMatrix != draw->fMatrix) { |
181 SkMatrix tmp = *draw->fMatrix; | 178 SkMatrix tmp = *draw->fMatrix; |
182 tmp.postConcat(fPlaybackMatrix); | 179 tmp.postConcat(fPlaybackMatrix); |
183 fCanvas->setMatrix(tmp); | 180 fCanvas->setMatrix(tmp); |
184 fCurrentMatrix = draw->fMatrix; | 181 fCurrentMatrix = draw->fMatrix; |
185 } | 182 } |
186 | 183 |
187 ++fPlaybackIndex; | 184 ++fPlaybackIndex; |
188 return draw->fOffset; | 185 return draw->fOffset; |
189 } | 186 } |
OLD | NEW |