blob: e8a0d96a65811184f5602982712f385f25162329 [file] [log] [blame]
junov@chromium.org7b537062012-11-06 18:58:43 +00001/*
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.com770963f2014-04-18 18:04:41 +000011#include "SkBBHFactory.h"
junov@chromium.org7b537062012-11-06 18:58:43 +000012#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.org7b537062012-11-06 18:58:43 +000018 */
19class SkTileGrid : public SkBBoxHierarchy {
20public:
mtklein03bde3e2014-08-12 07:01:25 -070021 SkTileGrid(int xTiles, int yTiles, const SkTileGridFactory::TileGridInfo& info);
junov@chromium.org7b537062012-11-06 18:58:43 +000022
23 virtual ~SkTileGrid();
24
25 /**
mtklein6bd41962014-10-02 07:41:56 -070026 * Insert a opIndex value and corresponding bounding box
27 * @param opIndex
mtkleina7f7b162014-08-11 12:05:59 -070028 * @param bounds The bounding box, should not be empty.
29 * @param defer Ignored; SkTileGrid does not defer insertions.
junov@chromium.org7b537062012-11-06 18:58:43 +000030 */
mtklein6bd41962014-10-02 07:41:56 -070031 virtual void insert(unsigned opIndex, const SkRect& bounds, bool) SK_OVERRIDE;
junov@chromium.org7b537062012-11-06 18:58:43 +000032
junov@chromium.org7b537062012-11-06 18:58:43 +000033 /**
mtklein6bd41962014-10-02 07:41:56 -070034 * Populate 'results' with opIndexes corresponding to bounding boxes that intersect 'query'.
mtkleina7f7b162014-08-11 12:05:59 -070035 * This will be fastest if the query is an exact match to a single grid tile.
junov@chromium.org7b537062012-11-06 18:58:43 +000036 */
mtklein6bd41962014-10-02 07:41:56 -070037 virtual void search(const SkRect& query, SkTDArray<unsigned>* results) const SK_OVERRIDE;
junov@chromium.org7b537062012-11-06 18:58:43 +000038
mtklein03bde3e2014-08-12 07:01:25 -070039 // For testing.
40 int tileCount(int x, int y) { return fTiles[y * fXTiles + x].count(); }
tfarina@chromium.org9f9d5822013-12-18 22:15:12 +000041
junov@chromium.org7b537062012-11-06 18:58:43 +000042private:
mtklein65be97d2014-10-07 11:46:39 -070043 void commonAdjust(SkRect*) const;
44 void userToGrid(const SkRect&, SkIRect* grid) const;
45
mtklein03bde3e2014-08-12 07:01:25 -070046 const int fXTiles, fYTiles;
mtklein65be97d2014-10-07 11:46:39 -070047 const SkScalar fInvWidth, fInvHeight;
48 const SkScalar fMarginWidth, fMarginHeight;
49 const SkPoint fOffset;
50 const SkRect fGridBounds;
mtklein03bde3e2014-08-12 07:01:25 -070051
mtklein6bd41962014-10-02 07:41:56 -070052 // (fXTiles * fYTiles) SkTDArrays, each listing ops overlapping that tile in order.
53 SkTDArray<unsigned>* fTiles;
junov@chromium.org7b537062012-11-06 18:58:43 +000054
junov@chromium.org7b537062012-11-06 18:58:43 +000055 typedef SkBBoxHierarchy INHERITED;
56};
57
skia.committer@gmail.com61b05dc2012-12-14 02:02:06 +000058#endif