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

Side by Side Diff: src/core/SkRTree.cpp

Issue 670213002: Cut down SkBBH API more. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: update tilegrid test Created 6 years, 1 month 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkRTree.h" 8 #include "SkRTree.h"
9 #include "SkTSort.h" 9 #include "SkTSort.h"
10 10
(...skipping 26 matching lines...) Expand all
37 SkASSERT(minChildren < maxChildren && minChildren > 0 && maxChildren < 37 SkASSERT(minChildren < maxChildren && minChildren > 0 && maxChildren <
38 static_cast<int>(SK_MaxU16)); 38 static_cast<int>(SK_MaxU16));
39 SkASSERT((maxChildren + 1) / 2 >= minChildren); 39 SkASSERT((maxChildren + 1) / 2 >= minChildren);
40 this->validate(); 40 this->validate();
41 } 41 }
42 42
43 SkRTree::~SkRTree() { 43 SkRTree::~SkRTree() {
44 this->clear(); 44 this->clear();
45 } 45 }
46 46
47 void SkRTree::insert(unsigned opIndex, const SkRect& fbounds, bool defer) { 47 void SkRTree::insert(SkAutoTMalloc<SkRect>* boundsArray, int N) {
48 SkIRect bounds; 48 this->validate();
49 if (fbounds.isLargest()) {
50 bounds.setLargest();
51 } else {
52 fbounds.roundOut(&bounds);
53 }
54 49
55 this->validate(); 50 // Since a bulk-load into an existing tree is as of yet unimplemented (and a rguably not
56 if (bounds.isEmpty()) { 51 // of vital importance right now), we only batch up inserts if the tree is e mpty.
57 SkASSERT(false); 52 const bool bulkLoad = this->isEmpty();
58 return; 53 SkTDArray<Branch> deferred;
59 } 54 deferred.setReserve(bulkLoad ? N : 0);
60 Branch newBranch; 55
61 newBranch.fBounds = bounds; 56 for (int i = 0; i < N; i++) {
62 newBranch.fChild.opIndex = opIndex; 57 SkIRect bounds;
63 if (this->isEmpty()) { 58 (*boundsArray)[i].roundOut(&bounds);
64 // since a bulk-load into an existing tree is as of yet unimplemented (a nd arguably not 59 if (bounds.isEmpty()) {
65 // of vital importance right now), we only batch up inserts if the tree is empty. 60 continue;
66 if (defer) { 61 }
67 fDeferredInserts.push(newBranch); 62 fCount++;
68 return; 63
69 } else { 64 Branch newBranch;
70 fRoot.fChild.subtree = allocateNode(0); 65 newBranch.fBounds = bounds;
71 fRoot.fChild.subtree->fNumChildren = 0; 66 newBranch.fChild.opIndex = i;
67
68 if (bulkLoad) {
69 deferred.push(newBranch);
70 continue;
71 }
72
robertphillips 2014/10/24 18:52:45 In this case the tree isn't empty. So I think this
mtklein 2014/10/24 19:05:48 I've just asserted this->isEmpty() and deleted the
73 fRoot.fChild.subtree = allocateNode(0);
74 fRoot.fChild.subtree->fNumChildren = 0;
75
robertphillips 2014/10/24 18:52:45 this-> ?
76 Branch* newSibling = insert(fRoot.fChild.subtree, &newBranch);
77 fRoot.fBounds = this->computeBounds(fRoot.fChild.subtree);
78 if (newSibling) {
79 Node* oldRoot = fRoot.fChild.subtree;
80 Node* newRoot = this->allocateNode(oldRoot->fLevel + 1);
81 newRoot->fNumChildren = 2;
82 *newRoot->child(0) = fRoot;
83 *newRoot->child(1) = *newSibling;
84 fRoot.fChild.subtree = newRoot;
85 fRoot.fBounds = this->computeBounds(fRoot.fChild.subtree);
72 } 86 }
73 } 87 }
74 88
75 Branch* newSibling = insert(fRoot.fChild.subtree, &newBranch); 89 if (bulkLoad && fCount > 0) {
76 fRoot.fBounds = this->computeBounds(fRoot.fChild.subtree); 90 SkASSERT(fCount == deferred.count());
77 91 if (1 == fCount) {
robertphillips 2014/10/24 18:52:45 this-> ?
mtklein 2014/10/24 19:05:48 Done.
78 if (newSibling) { 92 fRoot.fChild.subtree = allocateNode(0);
79 Node* oldRoot = fRoot.fChild.subtree; 93 fRoot.fChild.subtree->fNumChildren = 0;
80 Node* newRoot = this->allocateNode(oldRoot->fLevel + 1); 94 this->insert(fRoot.fChild.subtree, &deferred[0]);
81 newRoot->fNumChildren = 2; 95 fRoot.fBounds = deferred[0].fBounds;
82 *newRoot->child(0) = fRoot; 96 } else {
83 *newRoot->child(1) = *newSibling; 97 fRoot = this->bulkLoad(&deferred);
84 fRoot.fChild.subtree = newRoot; 98 }
85 fRoot.fBounds = this->computeBounds(fRoot.fChild.subtree);
86 } 99 }
87
88 ++fCount;
89 this->validate(); 100 this->validate();
90 } 101 }
91 102
92 void SkRTree::flushDeferredInserts() {
93 this->validate();
94 if (this->isEmpty() && fDeferredInserts.count() > 0) {
95 fCount = fDeferredInserts.count();
96 if (1 == fCount) {
97 fRoot.fChild.subtree = allocateNode(0);
98 fRoot.fChild.subtree->fNumChildren = 0;
99 this->insert(fRoot.fChild.subtree, &fDeferredInserts[0]);
100 fRoot.fBounds = fDeferredInserts[0].fBounds;
101 } else {
102 fRoot = this->bulkLoad(&fDeferredInserts);
103 }
104 } else {
105 // TODO: some algorithm for bulk loading into an already populated tree
106 SkASSERT(0 == fDeferredInserts.count());
107 }
108 fDeferredInserts.rewind();
109 this->validate();
110 }
111
112 void SkRTree::search(const SkRect& fquery, SkTDArray<unsigned>* results) const { 103 void SkRTree::search(const SkRect& fquery, SkTDArray<unsigned>* results) const {
113 SkIRect query; 104 SkIRect query;
114 fquery.roundOut(&query); 105 fquery.roundOut(&query);
115 this->validate(); 106 this->validate();
116 SkASSERT(0 == fDeferredInserts.count()); // If this fails, you should have flushed.
117 if (!this->isEmpty() && SkIRect::IntersectsNoEmptyCheck(fRoot.fBounds, query )) { 107 if (!this->isEmpty() && SkIRect::IntersectsNoEmptyCheck(fRoot.fBounds, query )) {
118 this->search(fRoot.fChild.subtree, query, results); 108 this->search(fRoot.fChild.subtree, query, results);
119 } 109 }
120 this->validate(); 110 this->validate();
121 } 111 }
122 112
123 void SkRTree::clear() { 113 void SkRTree::clear() {
124 this->validate(); 114 this->validate();
125 fNodes.reset(); 115 fNodes.reset();
126 fDeferredInserts.rewind();
127 fCount = 0; 116 fCount = 0;
128 this->validate(); 117 this->validate();
129 } 118 }
130 119
131 SkRTree::Node* SkRTree::allocateNode(uint16_t level) { 120 SkRTree::Node* SkRTree::allocateNode(uint16_t level) {
132 Node* out = static_cast<Node*>(fNodes.allocThrow(fNodeSize)); 121 Node* out = static_cast<Node*>(fNodes.allocThrow(fNodeSize));
133 out->fNumChildren = 0; 122 out->fNumChildren = 0;
134 out->fLevel = level; 123 out->fLevel = level;
135 return out; 124 return out;
136 } 125 }
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 461
473 // Expand 'out' to include 'joinWith' 462 // Expand 'out' to include 'joinWith'
474 static inline void join_no_empty_check(const SkIRect& joinWith, SkIRect* out) { 463 static inline void join_no_empty_check(const SkIRect& joinWith, SkIRect* out) {
475 // since we check for empty bounds on insert, we know we'll never have empty rects 464 // since we check for empty bounds on insert, we know we'll never have empty rects
476 // and we can save the empty check that SkIRect::join requires 465 // and we can save the empty check that SkIRect::join requires
477 if (joinWith.fLeft < out->fLeft) { out->fLeft = joinWith.fLeft; } 466 if (joinWith.fLeft < out->fLeft) { out->fLeft = joinWith.fLeft; }
478 if (joinWith.fTop < out->fTop) { out->fTop = joinWith.fTop; } 467 if (joinWith.fTop < out->fTop) { out->fTop = joinWith.fTop; }
479 if (joinWith.fRight > out->fRight) { out->fRight = joinWith.fRight; } 468 if (joinWith.fRight > out->fRight) { out->fRight = joinWith.fRight; }
480 if (joinWith.fBottom > out->fBottom) { out->fBottom = joinWith.fBottom; } 469 if (joinWith.fBottom > out->fBottom) { out->fBottom = joinWith.fBottom; }
481 } 470 }
OLDNEW
« no previous file with comments | « src/core/SkRTree.h ('k') | src/core/SkRecordDraw.cpp » ('j') | tests/PictureTest.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698