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

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

Issue 466503002: SkTileGrid: store insertion order, return results sorted by that. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: comments 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/SkRecordDraw.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
2 /* 1 /*
3 * Copyright 2012 Google Inc. 2 * Copyright 2012 Google Inc.
4 * 3 *
5 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 5 * found in the LICENSE file.
7 */ 6 */
8 7
9 #ifndef SkTileGrid_DEFINED 8 #ifndef SkTileGrid_DEFINED
10 #define SkTileGrid_DEFINED 9 #define SkTileGrid_DEFINED
11 10
12 #include "SkBBHFactory.h" 11 #include "SkBBHFactory.h"
13 #include "SkBBoxHierarchy.h" 12 #include "SkBBoxHierarchy.h"
14 #include "SkPictureStateTree.h"
15 13
16 /** 14 /**
17 * Subclass of SkBBoxHierarchy that stores elements in buckets that correspond 15 * Subclass of SkBBoxHierarchy that stores elements in buckets that correspond
18 * to tile regions, disposed in a regular grid. This is useful when the tile 16 * to tile regions, disposed in a regular grid. This is useful when the tile
19 * structure that will be use in search() calls is known prior to insertion. 17 * structure that will be use in search() calls is known prior to insertion.
20 * Calls to search will return in constant time.
21 *
22 * Note: Current implementation of search() only supports looking-up regions
23 * that are an exact match to a single tile. Implementation could be augmented
24 * to support arbitrary rectangles, but performance would be sub-optimal.
25 */ 18 */
26 class SkTileGrid : public SkBBoxHierarchy { 19 class SkTileGrid : public SkBBoxHierarchy {
27 public: 20 public:
28 SkTileGrid(int xTileCount, int yTileCount, const SkTileGridFactory::TileGrid Info& info); 21 SkTileGrid(int xTiles, int yTiles, const SkTileGridFactory::TileGridInfo& in fo);
29 22
30 virtual ~SkTileGrid(); 23 virtual ~SkTileGrid();
31 24
32 /** 25 /**
33 * Insert a data pointer and corresponding bounding box 26 * Insert a data pointer and corresponding bounding box
34 * @param data The data pointer, may _NOT_ be NULL. 27 * @param data An arbitrary data pointer, may be NULL.
35 * @param bounds The bounding box, should not be empty. 28 * @param bounds The bounding box, should not be empty.
36 * @param defer Ignored; SkTileGrid does not defer insertions. 29 * @param defer Ignored; SkTileGrid does not defer insertions.
37 */ 30 */
38 virtual void insert(void* data, const SkIRect& bounds, bool) SK_OVERRIDE; 31 virtual void insert(void* data, const SkIRect& bounds, bool) SK_OVERRIDE;
39 32
40 virtual void flushDeferredInserts() SK_OVERRIDE {}; 33 virtual void flushDeferredInserts() SK_OVERRIDE {};
41 34
42 /** 35 /**
43 * Populate 'results' with data pointers corresponding to bounding boxes tha t intersect 'query'. 36 * Populate 'results' with data pointers corresponding to bounding boxes tha t intersect 'query'.
44 * This will be fastest if the query is an exact match to a single grid tile . 37 * This will be fastest if the query is an exact match to a single grid tile .
45 */ 38 */
46 virtual void search(const SkIRect& query, SkTDArray<void*>* results) const S K_OVERRIDE; 39 virtual void search(const SkIRect& query, SkTDArray<void*>* results) const S K_OVERRIDE;
47 40
48 virtual void clear() SK_OVERRIDE; 41 virtual void clear() SK_OVERRIDE;
49 42
50 /** 43 virtual int getCount() const SK_OVERRIDE { return fCount; }
51 * Gets the number of insertions
52 */
53 virtual int getCount() const SK_OVERRIDE;
54 44
55 virtual int getDepth() const SK_OVERRIDE { return -1; } 45 virtual int getDepth() const SK_OVERRIDE { return -1; }
56 46
57 virtual void rewindInserts() SK_OVERRIDE; 47 virtual void rewindInserts() SK_OVERRIDE;
58 48
59 int tileCount(int x, int y); // For testing only. 49 // For testing.
50 int tileCount(int x, int y) { return fTiles[y * fXTiles + x].count(); }
60 51
61 private: 52 private:
62 const SkTDArray<void*>& tile(int x, int y) const; 53 struct Entry {
63 SkTDArray<void*>& tile(int x, int y); 54 size_t order; // Insertion order. Used to preserve order when merging multiple tiles.
55 void* data;
56 };
64 57
65 int fXTileCount, fYTileCount, fTileCount; 58 const int fXTiles, fYTiles;
66 SkTileGridFactory::TileGridInfo fInfo; 59 SkTileGridFactory::TileGridInfo fInfo;
67 SkTDArray<void*>* fTileData; 60 size_t fCount;
68 int fInsertionCount; 61
69 SkIRect fGridBounds; 62 // (fXTiles * fYTiles) SkTDArrays, each listing data overlapping that tile i n insertion order.
63 SkTDArray<Entry>* fTiles;
70 64
71 typedef SkBBoxHierarchy INHERITED; 65 typedef SkBBoxHierarchy INHERITED;
72 }; 66 };
73 67
74 #endif 68 #endif
OLDNEW
« no previous file with comments | « src/core/SkRecordDraw.cpp ('k') | src/core/SkTileGrid.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698