Add SkBBoxHierarchy::reserve() as an optional size hint.
I want to play around with how SkTileGrid stores its tiles. Having a cap on the number of insert() calls can be pretty handy. While I'm at it, I gave flush() a default empty impl. Like reserve(), it's really an optional hook for subclasses. BUG=skia: Review URL: https://codereview.chromium.org/639933003
This commit is contained in:
parent
a9c56525f3
commit
208d1704c2
@ -24,9 +24,14 @@ public:
|
||||
SkBBoxHierarchy() {}
|
||||
|
||||
/**
|
||||
* Insert opIndex and corresponding bounding box
|
||||
* Hint that <= opCount calls to insert() will be made.
|
||||
*/
|
||||
virtual void reserve(unsigned opCount) {}
|
||||
|
||||
/**
|
||||
* Insert opIndex and corresponding bounding box.
|
||||
* @param opIndex Any value, will be returned in order.
|
||||
* @param bounds The bounding box, should not be empty
|
||||
* @param bounds The bounding box, should not be empty.
|
||||
* @param defer Whether or not it is acceptable to delay insertion of this element (building up
|
||||
* an entire spatial data structure at once is often faster and produces better
|
||||
* structures than repeated inserts) until flushDeferredInserts is called or the first
|
||||
@ -35,9 +40,9 @@ public:
|
||||
virtual void insert(unsigned opIndex, const SkRect& bounds, bool defer = false) = 0;
|
||||
|
||||
/**
|
||||
* If any insertions have been deferred, this forces them to be inserted
|
||||
* If any insertions have been deferred, force them to be inserted.
|
||||
*/
|
||||
virtual void flushDeferredInserts() = 0;
|
||||
virtual void flushDeferredInserts() {}
|
||||
|
||||
/**
|
||||
* Populate results with sorted opIndex corresponding to bounding boxes that intersect query.
|
||||
|
@ -162,6 +162,7 @@ public:
|
||||
|
||||
// Finally feed all stored bounds into the BBH. They'll be returned in this order.
|
||||
SkASSERT(bbh);
|
||||
bbh->reserve(record.count());
|
||||
for (unsigned i = 0; i < record.count(); i++) {
|
||||
if (!fBounds[i].isEmpty()) {
|
||||
bbh->insert(i, fBounds[i], true/*ok to defer*/);
|
||||
|
@ -30,8 +30,6 @@ public:
|
||||
*/
|
||||
virtual void insert(unsigned opIndex, const SkRect& bounds, bool) SK_OVERRIDE;
|
||||
|
||||
virtual void flushDeferredInserts() SK_OVERRIDE {};
|
||||
|
||||
/**
|
||||
* Populate 'results' with opIndexes corresponding to bounding boxes that intersect 'query'.
|
||||
* This will be fastest if the query is an exact match to a single grid tile.
|
||||
|
@ -1869,9 +1869,7 @@ struct CountingBBH : public SkBBoxHierarchy {
|
||||
this->searchCalls++;
|
||||
}
|
||||
|
||||
// All other methods unimplemented.
|
||||
virtual void insert(unsigned opIndex, const SkRect& bounds, bool defer) SK_OVERRIDE {}
|
||||
virtual void flushDeferredInserts() SK_OVERRIDE {}
|
||||
};
|
||||
|
||||
class SpoonFedBBHFactory : public SkBBHFactory {
|
||||
|
@ -103,7 +103,6 @@ struct TestBBH : public SkBBoxHierarchy {
|
||||
fEntries.push(e);
|
||||
}
|
||||
|
||||
virtual void flushDeferredInserts() SK_OVERRIDE {}
|
||||
virtual void search(const SkRect& query, SkTDArray<unsigned>* results) const SK_OVERRIDE {}
|
||||
|
||||
struct Entry {
|
||||
|
Loading…
Reference in New Issue
Block a user