diff --git a/src/core/SkBBoxHierarchy.h b/src/core/SkBBoxHierarchy.h index 36047b9706..b42f708bc7 100644 --- a/src/core/SkBBoxHierarchy.h +++ b/src/core/SkBBoxHierarchy.h @@ -59,7 +59,7 @@ public: /** * Populate 'results' with data pointers corresponding to bounding boxes that intersect 'query' */ - virtual void search(const SkIRect& query, SkTDArray* results) = 0; + virtual void search(const SkIRect& query, SkTDArray* results) const = 0; virtual void clear() = 0; diff --git a/src/core/SkQuadTree.cpp b/src/core/SkQuadTree.cpp index a11613d08b..1fc3cd0192 100644 --- a/src/core/SkQuadTree.cpp +++ b/src/core/SkQuadTree.cpp @@ -168,7 +168,7 @@ void SkQuadTree::insert(void* data, const SkIRect& bounds, bool) { } } -void SkQuadTree::search(const SkIRect& query, SkTDArray* results) { +void SkQuadTree::search(const SkIRect& query, SkTDArray* 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 bf1bc8ebba..faa33fca45 100644 --- a/src/core/SkQuadTree.h +++ b/src/core/SkQuadTree.h @@ -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* results) SK_OVERRIDE; + virtual void search(const SkIRect& query, SkTDArray* results) const SK_OVERRIDE; virtual void clear() SK_OVERRIDE; diff --git a/src/core/SkRTree.cpp b/src/core/SkRTree.cpp index fe08437da3..3985fb1285 100644 --- a/src/core/SkRTree.cpp +++ b/src/core/SkRTree.cpp @@ -102,11 +102,9 @@ void SkRTree::flushDeferredInserts() { this->validate(); } -void SkRTree::search(const SkIRect& query, SkTDArray* results) { +void SkRTree::search(const SkIRect& query, SkTDArray* 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* 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(root))); diff --git a/src/core/SkRTree.h b/src/core/SkRTree.h index d21b5f8d37..6487b324ef 100644 --- a/src/core/SkRTree.h +++ b/src/core/SkRTree.h @@ -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* results) SK_OVERRIDE; + virtual void search(const SkIRect& query, SkTDArray* results) const SK_OVERRIDE; virtual void clear() SK_OVERRIDE; bool isEmpty() const { return 0 == fCount; } @@ -177,8 +177,8 @@ private: */ Branch bulkLoad(SkTDArray* 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 35f85d26c9..c86e78928c 100644 --- a/src/core/SkTileGrid.cpp +++ b/src/core/SkTileGrid.cpp @@ -33,6 +33,10 @@ int SkTileGrid::tileCount(int x, int y) { return this->tile(x, y).count(); } +const SkTDArray& SkTileGrid::tile(int x, int y) const { + return fTileData[y * fXTileCount + x]; +} + SkTDArray& 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* results) { +void SkTileGrid::search(const SkIRect& query, SkTDArray* 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* results) { results->reset(); SkAutoSTArray curPositions(queryTileCount); SkAutoSTArray*> storage(queryTileCount); - SkTDArray** tileRange = storage.get(); + const SkTDArray** tileRange = const_cast**>(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 0ec5c2c393..ea473fb6d0 100644 --- a/src/core/SkTileGrid.h +++ b/src/core/SkTileGrid.h @@ -33,7 +33,9 @@ public: kStackAllocationTileCount = 1024 }; - typedef void* (*SkTileGridNextDatumFunctionPtr)(SkTDArray** tileData, SkAutoSTArray& tileIndices); + typedef void* (*SkTileGridNextDatumFunctionPtr)( + const SkTDArray** tileData, + SkAutoSTArray& 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* results) SK_OVERRIDE; + virtual void search(const SkIRect& query, SkTDArray* 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& tile(int x, int y) const; SkTDArray& 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 -void* SkTileGridNextDatum(SkTDArray** tileData, SkAutoSTArray& tileIndices) { +void* SkTileGridNextDatum(const SkTDArray** tileData, + SkAutoSTArray& tileIndices) { T* minVal = NULL; int tileCount = tileIndices.count(); int minIndex = tileCount;