Make BBH::search() const.
I'd like to have SkRecordDraw() work with a const SkBBoxHierarchy*, but can't quite today. The only interesting change here is no longer flushing if needed in RTree; instead we assert we've been flushed already. BUG=skia: R=robertphillips@google.com, mtklein@google.com Author: mtklein@chromium.org Review URL: https://codereview.chromium.org/452233002
This commit is contained in:
parent
6d42d9c7ff
commit
8875a04136
@ -59,7 +59,7 @@ public:
|
||||
/**
|
||||
* Populate 'results' with data pointers corresponding to bounding boxes that intersect 'query'
|
||||
*/
|
||||
virtual void search(const SkIRect& query, SkTDArray<void*>* results) = 0;
|
||||
virtual void search(const SkIRect& query, SkTDArray<void*>* results) const = 0;
|
||||
|
||||
virtual void clear() = 0;
|
||||
|
||||
|
@ -168,7 +168,7 @@ void SkQuadTree::insert(void* data, const SkIRect& bounds, bool) {
|
||||
}
|
||||
}
|
||||
|
||||
void SkQuadTree::search(const SkIRect& query, SkTDArray<void*>* results) {
|
||||
void SkQuadTree::search(const SkIRect& query, SkTDArray<void*>* results) const {
|
||||
SkASSERT(NULL != fRoot);
|
||||
SkASSERT(NULL != results);
|
||||
if (SkIRect::Intersects(fRootBounds, query)) {
|
||||
|
@ -54,7 +54,7 @@ public:
|
||||
/**
|
||||
* Given a query rectangle, populates the passed-in array with the elements it intersects
|
||||
*/
|
||||
virtual void search(const SkIRect& query, SkTDArray<void*>* results) SK_OVERRIDE;
|
||||
virtual void search(const SkIRect& query, SkTDArray<void*>* results) const SK_OVERRIDE;
|
||||
|
||||
virtual void clear() SK_OVERRIDE;
|
||||
|
||||
|
@ -102,11 +102,9 @@ void SkRTree::flushDeferredInserts() {
|
||||
this->validate();
|
||||
}
|
||||
|
||||
void SkRTree::search(const SkIRect& query, SkTDArray<void*>* results) {
|
||||
void SkRTree::search(const SkIRect& query, SkTDArray<void*>* results) const {
|
||||
this->validate();
|
||||
if (0 != fDeferredInserts.count()) {
|
||||
this->flushDeferredInserts();
|
||||
}
|
||||
SkASSERT(0 == fDeferredInserts.count()); // If this fails, you should have flushed.
|
||||
if (!this->isEmpty() && SkIRect::IntersectsNoEmptyCheck(fRoot.fBounds, query)) {
|
||||
this->search(fRoot.fChild.subtree, query, results);
|
||||
}
|
||||
@ -399,7 +397,7 @@ SkRTree::Branch SkRTree::bulkLoad(SkTDArray<Branch>* branches, int level) {
|
||||
}
|
||||
}
|
||||
|
||||
void SkRTree::validate() {
|
||||
void SkRTree::validate() const {
|
||||
#ifdef SK_DEBUG
|
||||
if (this->isEmpty()) {
|
||||
return;
|
||||
@ -408,7 +406,7 @@ void SkRTree::validate() {
|
||||
#endif
|
||||
}
|
||||
|
||||
int SkRTree::validateSubtree(Node* root, SkIRect bounds, bool isRoot) {
|
||||
int SkRTree::validateSubtree(Node* root, SkIRect bounds, bool isRoot) const {
|
||||
// make sure the pointer is pointing to a valid place
|
||||
SkASSERT(fNodes.contains(static_cast<void*>(root)));
|
||||
|
||||
|
@ -77,7 +77,7 @@ public:
|
||||
/**
|
||||
* Given a query rectangle, populates the passed-in array with the elements it intersects
|
||||
*/
|
||||
virtual void search(const SkIRect& query, SkTDArray<void*>* results) SK_OVERRIDE;
|
||||
virtual void search(const SkIRect& query, SkTDArray<void*>* results) const SK_OVERRIDE;
|
||||
|
||||
virtual void clear() SK_OVERRIDE;
|
||||
bool isEmpty() const { return 0 == fCount; }
|
||||
@ -177,8 +177,8 @@ private:
|
||||
*/
|
||||
Branch bulkLoad(SkTDArray<Branch>* branches, int level = 0);
|
||||
|
||||
void validate();
|
||||
int validateSubtree(Node* root, SkIRect bounds, bool isRoot = false);
|
||||
void validate() const;
|
||||
int validateSubtree(Node* root, SkIRect bounds, bool isRoot = false) const;
|
||||
|
||||
const int fMinChildren;
|
||||
const int fMaxChildren;
|
||||
|
@ -33,6 +33,10 @@ int SkTileGrid::tileCount(int x, int y) {
|
||||
return this->tile(x, y).count();
|
||||
}
|
||||
|
||||
const SkTDArray<void *>& SkTileGrid::tile(int x, int y) const {
|
||||
return fTileData[y * fXTileCount + x];
|
||||
}
|
||||
|
||||
SkTDArray<void *>& SkTileGrid::tile(int x, int y) {
|
||||
return fTileData[y * fXTileCount + x];
|
||||
}
|
||||
@ -65,7 +69,7 @@ void SkTileGrid::insert(void* data, const SkIRect& bounds, bool) {
|
||||
fInsertionCount++;
|
||||
}
|
||||
|
||||
void SkTileGrid::search(const SkIRect& query, SkTDArray<void*>* results) {
|
||||
void SkTileGrid::search(const SkIRect& query, SkTDArray<void*>* results) const {
|
||||
SkIRect adjustedQuery = query;
|
||||
// The inset is to counteract the outset that was applied in 'insert'
|
||||
// The outset/inset is to optimize for lookups of size
|
||||
@ -96,7 +100,7 @@ void SkTileGrid::search(const SkIRect& query, SkTDArray<void*>* results) {
|
||||
results->reset();
|
||||
SkAutoSTArray<kStackAllocationTileCount, int> curPositions(queryTileCount);
|
||||
SkAutoSTArray<kStackAllocationTileCount, SkTDArray<void *>*> storage(queryTileCount);
|
||||
SkTDArray<void *>** tileRange = storage.get();
|
||||
const SkTDArray<void *>** tileRange = const_cast<const SkTDArray<void*>**>(storage.get());
|
||||
int tile = 0;
|
||||
for (int x = tileStartX; x < tileEndX; ++x) {
|
||||
for (int y = tileStartY; y < tileEndY; ++y) {
|
||||
|
@ -33,7 +33,9 @@ public:
|
||||
kStackAllocationTileCount = 1024
|
||||
};
|
||||
|
||||
typedef void* (*SkTileGridNextDatumFunctionPtr)(SkTDArray<void*>** tileData, SkAutoSTArray<kStackAllocationTileCount, int>& tileIndices);
|
||||
typedef void* (*SkTileGridNextDatumFunctionPtr)(
|
||||
const SkTDArray<void*>** tileData,
|
||||
SkAutoSTArray<kStackAllocationTileCount, int>& tileIndices);
|
||||
|
||||
SkTileGrid(int xTileCount, int yTileCount, const SkTileGridFactory::TileGridInfo& info,
|
||||
SkTileGridNextDatumFunctionPtr nextDatumFunction);
|
||||
@ -54,7 +56,7 @@ public:
|
||||
* Populate 'results' with data pointers corresponding to bounding boxes that intersect 'query'
|
||||
* The query argument is expected to be an exact match to a tile of the grid
|
||||
*/
|
||||
virtual void search(const SkIRect& query, SkTDArray<void*>* results) SK_OVERRIDE;
|
||||
virtual void search(const SkIRect& query, SkTDArray<void*>* results) const SK_OVERRIDE;
|
||||
|
||||
virtual void clear() SK_OVERRIDE;
|
||||
|
||||
@ -75,6 +77,7 @@ public:
|
||||
int tileCount(int x, int y); // For testing only.
|
||||
|
||||
private:
|
||||
const SkTDArray<void*>& tile(int x, int y) const;
|
||||
SkTDArray<void*>& tile(int x, int y);
|
||||
|
||||
int fXTileCount, fYTileCount, fTileCount;
|
||||
@ -103,7 +106,8 @@ private:
|
||||
* such that 'a < b' is true if 'a' was inserted into the tile grid before 'b'.
|
||||
*/
|
||||
template <typename T>
|
||||
void* SkTileGridNextDatum(SkTDArray<void*>** tileData, SkAutoSTArray<SkTileGrid::kStackAllocationTileCount, int>& tileIndices) {
|
||||
void* SkTileGridNextDatum(const SkTDArray<void*>** tileData,
|
||||
SkAutoSTArray<SkTileGrid::kStackAllocationTileCount, int>& tileIndices) {
|
||||
T* minVal = NULL;
|
||||
int tileCount = tileIndices.count();
|
||||
int minIndex = tileCount;
|
||||
|
Loading…
Reference in New Issue
Block a user