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
diff --git a/src/core/SkBBoxHierarchy.h b/src/core/SkBBoxHierarchy.h
index 36047b9..b42f708 100644
--- a/src/core/SkBBoxHierarchy.h
+++ b/src/core/SkBBoxHierarchy.h
@@ -59,7 +59,7 @@
/**
* 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;
diff --git a/src/core/SkQuadTree.cpp b/src/core/SkQuadTree.cpp
index a11613d..1fc3cd0 100644
--- a/src/core/SkQuadTree.cpp
+++ b/src/core/SkQuadTree.cpp
@@ -168,7 +168,7 @@
}
}
-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)) {
diff --git a/src/core/SkQuadTree.h b/src/core/SkQuadTree.h
index bf1bc8e..faa33fc 100644
--- a/src/core/SkQuadTree.h
+++ b/src/core/SkQuadTree.h
@@ -54,7 +54,7 @@
/**
* 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;
diff --git a/src/core/SkRTree.cpp b/src/core/SkRTree.cpp
index fe08437..3985fb1 100644
--- a/src/core/SkRTree.cpp
+++ b/src/core/SkRTree.cpp
@@ -102,11 +102,9 @@
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 @@
}
}
-void SkRTree::validate() {
+void SkRTree::validate() const {
#ifdef SK_DEBUG
if (this->isEmpty()) {
return;
@@ -408,7 +406,7 @@
#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)));
diff --git a/src/core/SkRTree.h b/src/core/SkRTree.h
index d21b5f8..6487b32 100644
--- a/src/core/SkRTree.h
+++ b/src/core/SkRTree.h
@@ -77,7 +77,7 @@
/**
* 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 @@
*/
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;
diff --git a/src/core/SkTileGrid.cpp b/src/core/SkTileGrid.cpp
index 35f85d2..c86e789 100644
--- a/src/core/SkTileGrid.cpp
+++ b/src/core/SkTileGrid.cpp
@@ -33,6 +33,10 @@
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 @@
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 @@
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) {
diff --git a/src/core/SkTileGrid.h b/src/core/SkTileGrid.h
index 0ec5c2c..ea473fb 100644
--- a/src/core/SkTileGrid.h
+++ b/src/core/SkTileGrid.h
@@ -33,7 +33,9 @@
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 @@
* 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 @@
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 @@
* 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;