junov@chromium.org | 7b53706 | 2012-11-06 18:58:43 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef SkTileGrid_DEFINED |
| 9 | #define SkTileGrid_DEFINED |
| 10 | |
robertphillips@google.com | 770963f | 2014-04-18 18:04:41 +0000 | [diff] [blame] | 11 | #include "SkBBHFactory.h" |
junov@chromium.org | 7b53706 | 2012-11-06 18:58:43 +0000 | [diff] [blame] | 12 | #include "SkBBoxHierarchy.h" |
| 13 | |
| 14 | /** |
| 15 | * Subclass of SkBBoxHierarchy that stores elements in buckets that correspond |
| 16 | * to tile regions, disposed in a regular grid. This is useful when the tile |
| 17 | * structure that will be use in search() calls is known prior to insertion. |
junov@chromium.org | 7b53706 | 2012-11-06 18:58:43 +0000 | [diff] [blame] | 18 | */ |
| 19 | class SkTileGrid : public SkBBoxHierarchy { |
| 20 | public: |
mtklein | 03bde3e | 2014-08-12 07:01:25 -0700 | [diff] [blame] | 21 | SkTileGrid(int xTiles, int yTiles, const SkTileGridFactory::TileGridInfo& info); |
junov@chromium.org | 7b53706 | 2012-11-06 18:58:43 +0000 | [diff] [blame] | 22 | |
| 23 | virtual ~SkTileGrid(); |
| 24 | |
| 25 | /** |
mtklein | 6bd4196 | 2014-10-02 07:41:56 -0700 | [diff] [blame] | 26 | * Insert a opIndex value and corresponding bounding box |
| 27 | * @param opIndex |
mtklein | a7f7b16 | 2014-08-11 12:05:59 -0700 | [diff] [blame] | 28 | * @param bounds The bounding box, should not be empty. |
| 29 | * @param defer Ignored; SkTileGrid does not defer insertions. |
junov@chromium.org | 7b53706 | 2012-11-06 18:58:43 +0000 | [diff] [blame] | 30 | */ |
mtklein | 6bd4196 | 2014-10-02 07:41:56 -0700 | [diff] [blame] | 31 | virtual void insert(unsigned opIndex, const SkRect& bounds, bool) SK_OVERRIDE; |
junov@chromium.org | 7b53706 | 2012-11-06 18:58:43 +0000 | [diff] [blame] | 32 | |
junov@chromium.org | 7b53706 | 2012-11-06 18:58:43 +0000 | [diff] [blame] | 33 | /** |
mtklein | 6bd4196 | 2014-10-02 07:41:56 -0700 | [diff] [blame] | 34 | * Populate 'results' with opIndexes corresponding to bounding boxes that intersect 'query'. |
mtklein | a7f7b16 | 2014-08-11 12:05:59 -0700 | [diff] [blame] | 35 | * This will be fastest if the query is an exact match to a single grid tile. |
junov@chromium.org | 7b53706 | 2012-11-06 18:58:43 +0000 | [diff] [blame] | 36 | */ |
mtklein | 6bd4196 | 2014-10-02 07:41:56 -0700 | [diff] [blame] | 37 | virtual void search(const SkRect& query, SkTDArray<unsigned>* results) const SK_OVERRIDE; |
junov@chromium.org | 7b53706 | 2012-11-06 18:58:43 +0000 | [diff] [blame] | 38 | |
mtklein | 03bde3e | 2014-08-12 07:01:25 -0700 | [diff] [blame] | 39 | // For testing. |
| 40 | int tileCount(int x, int y) { return fTiles[y * fXTiles + x].count(); } |
tfarina@chromium.org | 9f9d582 | 2013-12-18 22:15:12 +0000 | [diff] [blame] | 41 | |
junov@chromium.org | 7b53706 | 2012-11-06 18:58:43 +0000 | [diff] [blame] | 42 | private: |
mtklein | 65be97d | 2014-10-07 11:46:39 -0700 | [diff] [blame] | 43 | void commonAdjust(SkRect*) const; |
| 44 | void userToGrid(const SkRect&, SkIRect* grid) const; |
| 45 | |
mtklein | 03bde3e | 2014-08-12 07:01:25 -0700 | [diff] [blame] | 46 | const int fXTiles, fYTiles; |
mtklein | 65be97d | 2014-10-07 11:46:39 -0700 | [diff] [blame] | 47 | const SkScalar fInvWidth, fInvHeight; |
| 48 | const SkScalar fMarginWidth, fMarginHeight; |
| 49 | const SkPoint fOffset; |
| 50 | const SkRect fGridBounds; |
mtklein | 03bde3e | 2014-08-12 07:01:25 -0700 | [diff] [blame] | 51 | |
mtklein | 6bd4196 | 2014-10-02 07:41:56 -0700 | [diff] [blame] | 52 | // (fXTiles * fYTiles) SkTDArrays, each listing ops overlapping that tile in order. |
| 53 | SkTDArray<unsigned>* fTiles; |
junov@chromium.org | 7b53706 | 2012-11-06 18:58:43 +0000 | [diff] [blame] | 54 | |
junov@chromium.org | 7b53706 | 2012-11-06 18:58:43 +0000 | [diff] [blame] | 55 | typedef SkBBoxHierarchy INHERITED; |
| 56 | }; |
| 57 | |
skia.committer@gmail.com | 61b05dc | 2012-12-14 02:02:06 +0000 | [diff] [blame] | 58 | #endif |