Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(516)

Side by Side Diff: src/core/SkTileGrid.h

Issue 452233002: Make BBH::search() const. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: More const for tile() Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkRTree.cpp ('k') | src/core/SkTileGrid.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2012 Google Inc. 3 * Copyright 2012 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #ifndef SkTileGrid_DEFINED 9 #ifndef SkTileGrid_DEFINED
10 #define SkTileGrid_DEFINED 10 #define SkTileGrid_DEFINED
(...skipping 15 matching lines...) Expand all
26 class SkTileGrid : public SkBBoxHierarchy { 26 class SkTileGrid : public SkBBoxHierarchy {
27 public: 27 public:
28 enum { 28 enum {
29 // Number of tiles for which data is allocated on the stack in 29 // Number of tiles for which data is allocated on the stack in
30 // SkTileGrid::search. If malloc becomes a bottleneck, we may consider 30 // SkTileGrid::search. If malloc becomes a bottleneck, we may consider
31 // increasing this number. Typical large web page, say 2k x 16k, would 31 // increasing this number. Typical large web page, say 2k x 16k, would
32 // require 512 tiles of size 256 x 256 pixels. 32 // require 512 tiles of size 256 x 256 pixels.
33 kStackAllocationTileCount = 1024 33 kStackAllocationTileCount = 1024
34 }; 34 };
35 35
36 typedef void* (*SkTileGridNextDatumFunctionPtr)(SkTDArray<void*>** tileData, SkAutoSTArray<kStackAllocationTileCount, int>& tileIndices); 36 typedef void* (*SkTileGridNextDatumFunctionPtr)(
37 const SkTDArray<void*>** tileData,
38 SkAutoSTArray<kStackAllocationTileCount, int>& tileIndices);
37 39
38 SkTileGrid(int xTileCount, int yTileCount, const SkTileGridFactory::TileGrid Info& info, 40 SkTileGrid(int xTileCount, int yTileCount, const SkTileGridFactory::TileGrid Info& info,
39 SkTileGridNextDatumFunctionPtr nextDatumFunction); 41 SkTileGridNextDatumFunctionPtr nextDatumFunction);
40 42
41 virtual ~SkTileGrid(); 43 virtual ~SkTileGrid();
42 44
43 /** 45 /**
44 * Insert a data pointer and corresponding bounding box 46 * Insert a data pointer and corresponding bounding box
45 * @param data The data pointer, may be NULL 47 * @param data The data pointer, may be NULL
46 * @param bounds The bounding box, should not be empty 48 * @param bounds The bounding box, should not be empty
47 * @param defer Ignored, TileArray does not defer insertions 49 * @param defer Ignored, TileArray does not defer insertions
48 */ 50 */
49 virtual void insert(void* data, const SkIRect& bounds, bool) SK_OVERRIDE; 51 virtual void insert(void* data, const SkIRect& bounds, bool) SK_OVERRIDE;
50 52
51 virtual void flushDeferredInserts() SK_OVERRIDE {}; 53 virtual void flushDeferredInserts() SK_OVERRIDE {};
52 54
53 /** 55 /**
54 * Populate 'results' with data pointers corresponding to bounding boxes tha t intersect 'query' 56 * Populate 'results' with data pointers corresponding to bounding boxes tha t intersect 'query'
55 * The query argument is expected to be an exact match to a tile of the grid 57 * The query argument is expected to be an exact match to a tile of the grid
56 */ 58 */
57 virtual void search(const SkIRect& query, SkTDArray<void*>* results) SK_OVER RIDE; 59 virtual void search(const SkIRect& query, SkTDArray<void*>* results) const S K_OVERRIDE;
58 60
59 virtual void clear() SK_OVERRIDE; 61 virtual void clear() SK_OVERRIDE;
60 62
61 /** 63 /**
62 * Gets the number of insertions 64 * Gets the number of insertions
63 */ 65 */
64 virtual int getCount() const SK_OVERRIDE; 66 virtual int getCount() const SK_OVERRIDE;
65 67
66 virtual int getDepth() const SK_OVERRIDE { return -1; } 68 virtual int getDepth() const SK_OVERRIDE { return -1; }
67 69
68 virtual void rewindInserts() SK_OVERRIDE; 70 virtual void rewindInserts() SK_OVERRIDE;
69 71
70 // Used by search() and in SkTileGridHelper implementations 72 // Used by search() and in SkTileGridHelper implementations
71 enum { 73 enum {
72 kTileFinished = -1, 74 kTileFinished = -1,
73 }; 75 };
74 76
75 int tileCount(int x, int y); // For testing only. 77 int tileCount(int x, int y); // For testing only.
76 78
77 private: 79 private:
80 const SkTDArray<void*>& tile(int x, int y) const;
78 SkTDArray<void*>& tile(int x, int y); 81 SkTDArray<void*>& tile(int x, int y);
79 82
80 int fXTileCount, fYTileCount, fTileCount; 83 int fXTileCount, fYTileCount, fTileCount;
81 SkTileGridFactory::TileGridInfo fInfo; 84 SkTileGridFactory::TileGridInfo fInfo;
82 SkTDArray<void*>* fTileData; 85 SkTDArray<void*>* fTileData;
83 int fInsertionCount; 86 int fInsertionCount;
84 SkIRect fGridBounds; 87 SkIRect fGridBounds;
85 SkTileGridNextDatumFunctionPtr fNextDatumFunction; 88 SkTileGridNextDatumFunctionPtr fNextDatumFunction;
86 89
87 typedef SkBBoxHierarchy INHERITED; 90 typedef SkBBoxHierarchy INHERITED;
88 }; 91 };
89 92
90 /** 93 /**
91 * Generic implementation for SkTileGridNextDatumFunctionPtr. user code may inst antiate 94 * Generic implementation for SkTileGridNextDatumFunctionPtr. user code may inst antiate
92 * this template to get a valid SkTileGridNextDatumFunction implementation 95 * this template to get a valid SkTileGridNextDatumFunction implementation
93 * 96 *
94 * Returns the next element of tileData[i][tileIndices[i]] for all i and advance s 97 * Returns the next element of tileData[i][tileIndices[i]] for all i and advance s
95 * tileIndices[] past them. The order in which data are returned by successive 98 * tileIndices[] past them. The order in which data are returned by successive
96 * calls to this method must reflect the order in which the were originally 99 * calls to this method must reflect the order in which the were originally
97 * recorded into the tile grid. 100 * recorded into the tile grid.
98 * 101 *
99 * \param tileData array of pointers to arrays of tile data 102 * \param tileData array of pointers to arrays of tile data
100 * \param tileIndices per-tile data indices, indices are incremented for tiles t hat contain 103 * \param tileIndices per-tile data indices, indices are incremented for tiles t hat contain
101 * the next datum. 104 * the next datum.
102 * \tparam T a type to which it is safe to cast a datum and that has an operator < 105 * \tparam T a type to which it is safe to cast a datum and that has an operator <
103 * such that 'a < b' is true if 'a' was inserted into the tile grid before ' b'. 106 * such that 'a < b' is true if 'a' was inserted into the tile grid before ' b'.
104 */ 107 */
105 template <typename T> 108 template <typename T>
106 void* SkTileGridNextDatum(SkTDArray<void*>** tileData, SkAutoSTArray<SkTileGrid: :kStackAllocationTileCount, int>& tileIndices) { 109 void* SkTileGridNextDatum(const SkTDArray<void*>** tileData,
110 SkAutoSTArray<SkTileGrid::kStackAllocationTileCount, i nt>& tileIndices) {
107 T* minVal = NULL; 111 T* minVal = NULL;
108 int tileCount = tileIndices.count(); 112 int tileCount = tileIndices.count();
109 int minIndex = tileCount; 113 int minIndex = tileCount;
110 int maxIndex = 0; 114 int maxIndex = 0;
111 // Find the next Datum; track where it's found so we reduce the size of the second loop. 115 // Find the next Datum; track where it's found so we reduce the size of the second loop.
112 for (int tile = 0; tile < tileCount; ++tile) { 116 for (int tile = 0; tile < tileCount; ++tile) {
113 int pos = tileIndices[tile]; 117 int pos = tileIndices[tile];
114 if (pos != SkTileGrid::kTileFinished) { 118 if (pos != SkTileGrid::kTileFinished) {
115 T* candidate = (T*)(*tileData[tile])[pos]; 119 T* candidate = (T*)(*tileData[tile])[pos];
116 if (NULL == minVal || (*candidate) < (*minVal)) { 120 if (NULL == minVal || (*candidate) < (*minVal)) {
(...skipping 16 matching lines...) Expand all
133 tileIndices[tile] = SkTileGrid::kTileFinished; 137 tileIndices[tile] = SkTileGrid::kTileFinished;
134 } 138 }
135 } 139 }
136 } 140 }
137 return minVal; 141 return minVal;
138 } 142 }
139 return NULL; 143 return NULL;
140 } 144 }
141 145
142 #endif 146 #endif
OLDNEW
« no previous file with comments | « src/core/SkRTree.cpp ('k') | src/core/SkTileGrid.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698