Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(166)

Unified Diff: src/core/SkRTree.cpp

Issue 23480002: R-Tree -- Don't sort draw commands unless specified. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/core/SkRTree.h ('k') | tests/RTreeTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkRTree.cpp
diff --git a/src/core/SkRTree.cpp b/src/core/SkRTree.cpp
index d7a15d59578e5aa13b90717c6611138a4e9dae3e..95e4336ac779d4f438a49201d26276294f0ccccf 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 sortWhenBulkLoading) {
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, sortWhenBulkLoading);
}
return NULL;
}
-SkRTree::SkRTree(int minChildren, int maxChildren, SkScalar aspectRatio)
+SkRTree::SkRTree(int minChildren, int maxChildren, SkScalar aspectRatio,
+ bool sortWhenBulkLoading)
: fMinChildren(minChildren)
, fMaxChildren(maxChildren)
, fNodeSize(sizeof(Node) + sizeof(Branch) * maxChildren)
, fCount(0)
, fNodes(fNodeSize * 256)
- , fAspectRatio(aspectRatio) {
+ , fAspectRatio(aspectRatio)
+ , fSortWhenBulkLoading(sortWhenBulkLoading) {
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 / Blink to give us a reasonable x,y order.
+ // Avoiding this call resulted in a 17% win for recording with
+ // negligible difference in playback speed.
+ if (fSortWhenBulkLoading) {
+ 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 (fSortWhenBulkLoading) {
+ 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;
« no previous file with comments | « src/core/SkRTree.h ('k') | tests/RTreeTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698