| 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" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 , fPlaybackIndex(0) | 97 , fPlaybackIndex(0) |
| 98 , fSave(false) | 98 , fSave(false) |
| 99 , fValid(true) { | 99 , fValid(true) { |
| 100 } | 100 } |
| 101 | 101 |
| 102 uint32_t SkPictureStateTree::Iterator::draw() { | 102 uint32_t SkPictureStateTree::Iterator::draw() { |
| 103 SkASSERT(this->isValid()); | 103 SkASSERT(this->isValid()); |
| 104 if (fPlaybackIndex >= fDraws->count()) { | 104 if (fPlaybackIndex >= fDraws->count()) { |
| 105 // restore back to where we started | 105 // restore back to where we started |
| 106 fCanvas->setMatrix(fPlaybackMatrix); | 106 fCanvas->setMatrix(fPlaybackMatrix); |
| 107 if (fCurrentNode->fFlags & Node::kSaveLayer_Flag) { fCanvas->restore();
} | 107 if (fCurrentNode->fFlags & Node::kSaveLayer_Flag) { |
| 108 fCanvas->restore(); |
| 109 } |
| 108 fCurrentNode = fCurrentNode->fParent; | 110 fCurrentNode = fCurrentNode->fParent; |
| 109 while (NULL != fCurrentNode) { | 111 while (NULL != fCurrentNode) { |
| 110 if (fCurrentNode->fFlags & Node::kSave_Flag) { fCanvas->restore(); } | 112 if (fCurrentNode->fFlags & Node::kSave_Flag) { |
| 111 if (fCurrentNode->fFlags & Node::kSaveLayer_Flag) { fCanvas->restore
(); } | 113 fCanvas->restore(); |
| 114 } |
| 115 if (fCurrentNode->fFlags & Node::kSaveLayer_Flag) { |
| 116 fCanvas->restore(); |
| 117 } |
| 112 fCurrentNode = fCurrentNode->fParent; | 118 fCurrentNode = fCurrentNode->fParent; |
| 113 } | 119 } |
| 114 return kDrawComplete; | 120 return kDrawComplete; |
| 115 } | 121 } |
| 116 | 122 |
| 117 Draw* draw = static_cast<Draw*>((*fDraws)[fPlaybackIndex]); | 123 Draw* draw = static_cast<Draw*>((*fDraws)[fPlaybackIndex]); |
| 118 Node* targetNode = draw->fNode; | 124 Node* targetNode = draw->fNode; |
| 119 | 125 |
| 120 if (fSave) { | 126 if (fSave) { |
| 121 fCanvas->save(SkCanvas::kClip_SaveFlag); | 127 fCanvas->save(SkCanvas::kClip_SaveFlag); |
| 122 fSave = false; | 128 fSave = false; |
| 123 } | 129 } |
| 124 | 130 |
| 125 if (fCurrentNode != targetNode) { | 131 if (fCurrentNode != targetNode) { |
| 126 // If we're not at the target and we don't have a list of nodes to get t
here, we need to | 132 // If we're not at the target and we don't have a list of nodes to get t
here, we need to |
| 127 // figure out the path from our current node, to the target | 133 // figure out the path from our current node, to the target |
| 128 if (fNodes.count() == 0) { | 134 if (fNodes.count() == 0) { |
| 129 // Trace back up to a common ancestor, restoring to get our current
state to match that | 135 // Trace back up to a common ancestor, restoring to get our current
state to match that |
| 130 // of the ancestor, and saving a list of nodes whose state we need t
o apply to get to | 136 // of the ancestor, and saving a list of nodes whose state we need t
o apply to get to |
| 131 // the target (we can restore up to the ancestor immediately, but we
'll need to return | 137 // the target (we can restore up to the ancestor immediately, but we
'll need to return |
| 132 // an offset for each node on the way down to the target, to apply t
he desired clips and | 138 // an offset for each node on the way down to the target, to apply t
he desired clips and |
| 133 // saveLayers, so it may take several draw() calls before the next d
raw actually occurs) | 139 // saveLayers, so it may take several draw() calls before the next d
raw actually occurs) |
| 134 Node* tmp = fCurrentNode; | 140 Node* tmp = fCurrentNode; |
| 135 Node* ancestor = targetNode; | 141 Node* ancestor = targetNode; |
| 136 while (tmp != ancestor) { | 142 while (tmp != ancestor) { |
| 137 uint16_t currentLevel = tmp->fLevel; | 143 uint16_t currentLevel = tmp->fLevel; |
| 138 uint16_t targetLevel = ancestor->fLevel; | 144 uint16_t targetLevel = ancestor->fLevel; |
| 139 if (currentLevel >= targetLevel) { | 145 if (currentLevel >= targetLevel) { |
| 140 if (tmp != fCurrentNode && tmp->fFlags & Node::kSave_Flag) {
fCanvas->restore(); } | 146 if (tmp != fCurrentNode && tmp->fFlags & Node::kSave_Flag) {
|
| 141 if (tmp->fFlags & Node::kSaveLayer_Flag) { fCanvas->restore(
); } | 147 fCanvas->restore(); |
| 148 } |
| 149 if (tmp->fFlags & Node::kSaveLayer_Flag) { |
| 150 fCanvas->restore(); |
| 151 } |
| 142 tmp = tmp->fParent; | 152 tmp = tmp->fParent; |
| 143 } | 153 } |
| 144 if (currentLevel <= targetLevel) { | 154 if (currentLevel <= targetLevel) { |
| 145 fNodes.push(ancestor); | 155 fNodes.push(ancestor); |
| 146 ancestor = ancestor->fParent; | 156 ancestor = ancestor->fParent; |
| 147 } | 157 } |
| 148 } | 158 } |
| 149 | 159 |
| 150 if (ancestor->fFlags & Node::kSave_Flag) { | 160 if (ancestor->fFlags & Node::kSave_Flag) { |
| 151 if (fCurrentNode != ancestor) { fCanvas->restore(); } | 161 if (fCurrentNode != ancestor) { |
| 152 if (targetNode != ancestor) { fCanvas->save(SkCanvas::kClip_Save
Flag); } | 162 fCanvas->restore(); |
| 163 } |
| 164 if (targetNode != ancestor) { |
| 165 fCanvas->save(SkCanvas::kClip_SaveFlag); |
| 166 } |
| 153 } | 167 } |
| 154 fCurrentNode = ancestor; | 168 fCurrentNode = ancestor; |
| 155 } | 169 } |
| 156 | 170 |
| 157 // If we're not at the target node yet, we'll need to return an offset t
o make the caller | 171 // If we're not at the target node yet, we'll need to return an offset t
o make the caller |
| 158 // apply the next clip or saveLayer. | 172 // apply the next clip or saveLayer. |
| 159 if (fCurrentNode != targetNode) { | 173 if (fCurrentNode != targetNode) { |
| 160 if (fCurrentMatrix != fNodes.top()->fMatrix) { | 174 if (fCurrentMatrix != fNodes.top()->fMatrix) { |
| 161 fCurrentMatrix = fNodes.top()->fMatrix; | 175 fCurrentMatrix = fNodes.top()->fMatrix; |
| 162 SkMatrix tmp = *fNodes.top()->fMatrix; | 176 SkMatrix tmp = *fNodes.top()->fMatrix; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 177 if (fCurrentMatrix != draw->fMatrix) { | 191 if (fCurrentMatrix != draw->fMatrix) { |
| 178 SkMatrix tmp = *draw->fMatrix; | 192 SkMatrix tmp = *draw->fMatrix; |
| 179 tmp.postConcat(fPlaybackMatrix); | 193 tmp.postConcat(fPlaybackMatrix); |
| 180 fCanvas->setMatrix(tmp); | 194 fCanvas->setMatrix(tmp); |
| 181 fCurrentMatrix = draw->fMatrix; | 195 fCurrentMatrix = draw->fMatrix; |
| 182 } | 196 } |
| 183 | 197 |
| 184 ++fPlaybackIndex; | 198 ++fPlaybackIndex; |
| 185 return draw->fOffset; | 199 return draw->fOffset; |
| 186 } | 200 } |
| OLD | NEW |