OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "SkQuadTree.h" | 8 #include "SkQuadTree.h" |
9 #include "SkTSort.h" | 9 #include "SkTSort.h" |
10 #include <stdio.h> | 10 #include <stdio.h> |
(...skipping 28 matching lines...) Expand all Loading... | |
39 intersect &= ~kMaskLeft; | 39 intersect &= ~kMaskLeft; |
40 } | 40 } |
41 if (query.fBottom < split.fY) { | 41 if (query.fBottom < split.fY) { |
42 intersect &= ~kMaskBottom; | 42 intersect &= ~kMaskBottom; |
43 } else if(query.fTop >= split.fY) { | 43 } else if(query.fTop >= split.fY) { |
44 intersect &= ~kMaskTop; | 44 intersect &= ~kMaskTop; |
45 } | 45 } |
46 return intersect; | 46 return intersect; |
47 } | 47 } |
48 | 48 |
49 SkQuadTree::SkQuadTree(const SkIRect& bounds) | 49 SkQuadTree::SkQuadTree(const SkIRect& bounds) : fRoot(NULL) { |
50 : fRoot(NULL) { | |
51 SkASSERT((bounds.width() * bounds.height()) > 0); | 50 SkASSERT((bounds.width() * bounds.height()) > 0); |
52 fRootBounds = bounds; | 51 fRootBounds = bounds; |
53 } | 52 } |
54 | 53 |
55 SkQuadTree::~SkQuadTree() { | 54 SkQuadTree::~SkQuadTree() { |
56 } | 55 } |
57 | 56 |
58 void SkQuadTree::insert(Node* node, Entry* entry) { | 57 void SkQuadTree::insert(Node* node, Entry* entry) { |
59 // does it belong in a child? | 58 // does it belong in a child? |
60 if (NULL != node->fChildren[0]) { | 59 if (NULL != node->fChildren[0]) { |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
171 | 170 |
172 void SkQuadTree::search(const SkIRect& query, SkTDArray<void*>* results) { | 171 void SkQuadTree::search(const SkIRect& query, SkTDArray<void*>* results) { |
173 SkASSERT(NULL != fRoot); | 172 SkASSERT(NULL != fRoot); |
174 SkASSERT(NULL != results); | 173 SkASSERT(NULL != results); |
175 if (SkIRect::Intersects(fRootBounds, query)) { | 174 if (SkIRect::Intersects(fRootBounds, query)) { |
176 this->search(fRoot, query, results); | 175 this->search(fRoot, query, results); |
177 } | 176 } |
178 } | 177 } |
179 | 178 |
180 void SkQuadTree::clear() { | 179 void SkQuadTree::clear() { |
180 this->flushDeferredInserts(); | |
181 if (NULL != fRoot) { | 181 if (NULL != fRoot) { |
182 this->clear(fRoot); | 182 this->clear(fRoot); |
183 fNodePool.release(fRoot); | 183 fNodePool.release(fRoot); |
184 fRoot = NULL; | 184 fRoot = NULL; |
185 } | 185 } |
186 SkASSERT(fEntryPool.allocated() == fEntryPool.available()); | |
djsollen
2014/05/09 14:23:08
should we add this here as well.
SkASSERT(0 == fD
| |
187 SkASSERT(fNodePool.allocated() == fNodePool.available()); | |
186 } | 188 } |
187 | 189 |
188 int SkQuadTree::getDepth() const { | 190 int SkQuadTree::getDepth() const { |
189 return this->getDepth(fRoot); | 191 return this->getDepth(fRoot); |
190 } | 192 } |
191 | 193 |
192 void SkQuadTree::rewindInserts() { | 194 void SkQuadTree::rewindInserts() { |
193 SkASSERT(fClient); | 195 SkASSERT(fClient); |
194 // Currently only supports deferred inserts | 196 // Currently only supports deferred inserts |
195 SkASSERT(NULL == fRoot); | 197 SkASSERT(NULL == fRoot); |
(...skipping 12 matching lines...) Expand all Loading... | |
208 | 210 |
209 void SkQuadTree::flushDeferredInserts() { | 211 void SkQuadTree::flushDeferredInserts() { |
210 if (NULL == fRoot) { | 212 if (NULL == fRoot) { |
211 fRoot = fNodePool.acquire(); | 213 fRoot = fNodePool.acquire(); |
212 fRoot->fBounds = fRootBounds; | 214 fRoot->fBounds = fRootBounds; |
213 } | 215 } |
214 while(!fDeferred.isEmpty()) { | 216 while(!fDeferred.isEmpty()) { |
215 this->insert(fRoot, fDeferred.pop()); | 217 this->insert(fRoot, fDeferred.pop()); |
216 } | 218 } |
217 } | 219 } |
OLD | NEW |