Index: src/core/SkPictureStateTree.cpp |
diff --git a/src/core/SkPictureStateTree.cpp b/src/core/SkPictureStateTree.cpp |
index 891d04ca21bc4ae7a9b11b679afb7b2434c2fba6..92717597d3973ff33275e20cad74ba016a737b72 100644 |
--- a/src/core/SkPictureStateTree.cpp |
+++ b/src/core/SkPictureStateTree.cpp |
@@ -99,24 +99,37 @@ SkPictureStateTree::Iterator::Iterator(const SkTDArray<void*>& draws, SkCanvas* |
, fValid(true) { |
} |
-uint32_t SkPictureStateTree::Iterator::draw() { |
+void SkPictureStateTree::Iterator::setCurrentMatrix(const SkMatrix* matrix) { |
+ SkASSERT(NULL != matrix); |
+ |
+ if (matrix == fCurrentMatrix) { |
+ return; |
+ } |
+ |
+ SkMatrix m = *matrix; |
+ m.postConcat(fPlaybackMatrix); |
Justin Novosad
2014/04/22 15:31:34
If I understand correctly, this is because 'matrix
f(malita)
2014/04/22 15:48:38
Exactly. Added comment.
|
+ fCanvas->setMatrix(m); |
+ fCurrentMatrix = matrix; |
+} |
+ |
+uint32_t SkPictureStateTree::Iterator::nextDraw() { |
Justin Novosad
2014/04/22 15:31:34
+1 for the name change.
|
SkASSERT(this->isValid()); |
if (fPlaybackIndex >= fDraws->count()) { |
- // restore back to where we started |
- fCanvas->setMatrix(fPlaybackMatrix); |
if (fCurrentNode->fFlags & Node::kSaveLayer_Flag) { |
fCanvas->restore(); |
} |
- fCurrentNode = fCurrentNode->fParent; |
- while (NULL != fCurrentNode) { |
Justin Novosad
2014/04/22 15:31:34
The changes to this loop look mostly like a cleane
f(malita)
2014/04/22 15:48:38
Yes, the loop change itself is just cleanup.
The
|
- if (fCurrentNode->fFlags & Node::kSave_Flag) { |
- fCanvas->restore(); |
- } |
- if (fCurrentNode->fFlags & Node::kSaveLayer_Flag) { |
+ |
+ for (fCurrentNode = fCurrentNode->fParent; fCurrentNode; |
+ fCurrentNode = fCurrentNode->fParent) { |
+ if (fCurrentNode->fFlags & (Node::kSave_Flag | Node::kSaveLayer_Flag)) { |
fCanvas->restore(); |
} |
- fCurrentNode = fCurrentNode->fParent; |
} |
+ |
+ // restore back to where we started |
+ fCanvas->setMatrix(fPlaybackMatrix); |
+ fCurrentMatrix = NULL; |
+ |
return kDrawComplete; |
} |
@@ -145,9 +158,13 @@ uint32_t SkPictureStateTree::Iterator::draw() { |
if (currentLevel >= targetLevel) { |
if (tmp != fCurrentNode && tmp->fFlags & Node::kSave_Flag) { |
fCanvas->restore(); |
+ // restore() may change the matrix, so we need to reapply. |
+ fCurrentMatrix = NULL; |
} |
if (tmp->fFlags & Node::kSaveLayer_Flag) { |
fCanvas->restore(); |
+ // restore() may change the matrix, so we need to reapply. |
+ fCurrentMatrix = NULL; |
} |
tmp = tmp->fParent; |
} |
@@ -155,17 +172,19 @@ uint32_t SkPictureStateTree::Iterator::draw() { |
fNodes.push(ancestor); |
ancestor = ancestor->fParent; |
} |
+ |
+ SkASSERT(NULL != tmp); |
+ SkASSERT(NULL != ancestor); |
} |
if (ancestor->fFlags & Node::kSave_Flag) { |
if (fCurrentNode != ancestor) { |
fCanvas->restore(); |
+ // restore() may change the matrix, so we need to reapply. |
+ fCurrentMatrix = NULL; |
} |
if (targetNode != ancestor) { |
- // FIXME: the save below depends on soon-to-be-deprecated |
- // SaveFlags behavior: it relies on matrix changes persisting |
- // after restore. |
- fCanvas->save(SkCanvas::kClip_SaveFlag); |
+ fCanvas->save(); |
} |
} |
fCurrentNode = ancestor; |
@@ -174,29 +193,18 @@ uint32_t SkPictureStateTree::Iterator::draw() { |
// If we're not at the target node yet, we'll need to return an offset to make the caller |
// apply the next clip or saveLayer. |
if (fCurrentNode != targetNode) { |
- if (fCurrentMatrix != fNodes.top()->fMatrix) { |
- fCurrentMatrix = fNodes.top()->fMatrix; |
- SkMatrix tmp = *fNodes.top()->fMatrix; |
- tmp.postConcat(fPlaybackMatrix); |
- fCanvas->setMatrix(tmp); |
- } |
uint32_t offset = fNodes.top()->fOffset; |
fCurrentNode = fNodes.top(); |
fSave = fCurrentNode != targetNode && fCurrentNode->fFlags & Node::kSave_Flag; |
fNodes.pop(); |
+ this->setCurrentMatrix(fCurrentNode->fMatrix); |
return offset; |
} |
} |
// If we got this far, the clip/saveLayer state is all set, so we can proceed to set the matrix |
// for the draw, and return its offset. |
- |
- if (fCurrentMatrix != draw->fMatrix) { |
- SkMatrix tmp = *draw->fMatrix; |
- tmp.postConcat(fPlaybackMatrix); |
- fCanvas->setMatrix(tmp); |
- fCurrentMatrix = draw->fMatrix; |
- } |
+ this->setCurrentMatrix(draw->fMatrix); |
++fPlaybackIndex; |
return draw->fOffset; |