Chromium Code Reviews| Index: src/core/SkRTree.cpp |
| diff --git a/src/core/SkRTree.cpp b/src/core/SkRTree.cpp |
| index d7a15d59578e5aa13b90717c6611138a4e9dae3e..e555c955661425323479ad3b96820c6580d928af 100644 |
| --- a/src/core/SkRTree.cpp |
| +++ b/src/core/SkRTree.cpp |
| @@ -21,21 +21,24 @@ static inline void join_no_empty_check(const SkIRect& joinWith, SkIRect* out); |
| SK_DEFINE_INST_COUNT(SkRTree) |
| -SkRTree* SkRTree::Create(int minChildren, int maxChildren, SkScalar aspectRatio) { |
| +SkRTree* SkRTree::Create(int minChildren, int maxChildren, SkScalar aspectRatio, |
| + bool orderWhenBulkLoading) { |
| if (minChildren < maxChildren && (maxChildren + 1) / 2 >= minChildren && |
| minChildren > 0 && maxChildren < static_cast<int>(SK_MaxU16)) { |
| - return new SkRTree(minChildren, maxChildren, aspectRatio); |
| + return new SkRTree(minChildren, maxChildren, aspectRatio, orderWhenBulkLoading); |
| } |
| return NULL; |
| } |
| -SkRTree::SkRTree(int minChildren, int maxChildren, SkScalar aspectRatio) |
| +SkRTree::SkRTree(int minChildren, int maxChildren, SkScalar aspectRatio, |
| + bool orderWhenBulkLoading) |
| : fMinChildren(minChildren) |
| , fMaxChildren(maxChildren) |
| , fNodeSize(sizeof(Node) + sizeof(Branch) * maxChildren) |
| , fCount(0) |
| , fNodes(fNodeSize * 256) |
| - , fAspectRatio(aspectRatio) { |
| + , fAspectRatio(aspectRatio) |
| + , fOrderWhenBulkLoading(orderWhenBulkLoading) { |
| SkASSERT(minChildren < maxChildren && minChildren > 0 && maxChildren < |
| static_cast<int>(SK_MaxU16)); |
| SkASSERT((maxChildren + 1) / 2 >= minChildren); |
| @@ -323,8 +326,14 @@ SkRTree::Branch SkRTree::bulkLoad(SkTDArray<Branch>* branches, int level) { |
| branches->rewind(); |
| return out; |
| } else { |
| - // First we sort the whole list by y coordinates |
| - SkTQSort(branches->begin(), branches->end() - 1, RectLessY()); |
| + // We sort the whole list by y coordinates, if we are told to do so. |
| + // |
| + // We expect Webkit / Bink to give us a reasonable x,y order. |
|
caryclark
2013/08/27 11:54:18
s/Bink/Blink
|
| + // Avoiding this call is a very big performance win for recording with |
|
caryclark
2013/08/27 11:54:18
s/is a very big/resulted in a 17%/
|
| + // negligible difference in playback speed. |
| + if (fOrderWhenBulkLoading) { |
| + SkTQSort(branches->begin(), branches->end() - 1, RectLessY()); |
| + } |
| int numBranches = branches->count() / fMaxChildren; |
| int remainder = branches->count() % fMaxChildren; |
| @@ -348,15 +357,18 @@ SkRTree::Branch SkRTree::bulkLoad(SkTDArray<Branch>* branches, int level) { |
| int currentBranch = 0; |
| for (int i = 0; i < numStrips; ++i) { |
| - int begin = currentBranch; |
| - int end = currentBranch + numTiles * fMaxChildren - SkMin32(remainder, |
| - (fMaxChildren - fMinChildren) * numTiles); |
| - if (end > branches->count()) { |
| - end = branches->count(); |
| - } |
| + // Once again, if we are told to do so, we sort by x. |
| + if (fOrderWhenBulkLoading) { |
| + int begin = currentBranch; |
| + int end = currentBranch + numTiles * fMaxChildren - SkMin32(remainder, |
| + (fMaxChildren - fMinChildren) * numTiles); |
| + if (end > branches->count()) { |
| + end = branches->count(); |
| + } |
| - // Now we sort horizontal strips of rectangles by their x coords |
| - SkTQSort(branches->begin() + begin, branches->begin() + end - 1, RectLessX()); |
| + // Now we sort horizontal strips of rectangles by their x coords |
| + SkTQSort(branches->begin() + begin, branches->begin() + end - 1, RectLessX()); |
| + } |
| for (int j = 0; j < numTiles && currentBranch < branches->count(); ++j) { |
| int incrementBy = fMaxChildren; |