OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * 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 |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkBBHFactory.h" | 8 #include "SkBBHFactory.h" |
9 #include "SkRTree.h" | 9 #include "SkRTree.h" |
10 #include "SkTileGrid.h" | 10 #include "SkTileGrid.h" |
11 | 11 |
12 SkBBoxHierarchy* SkRTreeFactory::operator()(const SkRect& bounds) const { | 12 |
13 SkScalar aspectRatio = bounds.width() / bounds.height(); | 13 SkBBoxHierarchy* SkRTreeFactory::operator()(int width, int height) const { |
| 14 SkScalar aspectRatio = SkScalarDiv(SkIntToScalar(width), SkIntToScalar(heigh
t)); |
14 return SkNEW_ARGS(SkRTree, (aspectRatio)); | 15 return SkNEW_ARGS(SkRTree, (aspectRatio)); |
15 } | 16 } |
16 | 17 |
17 SkBBoxHierarchy* SkTileGridFactory::operator()(const SkRect& bounds) const { | 18 SkBBoxHierarchy* SkTileGridFactory::operator()(int width, int height) const { |
18 SkASSERT(fInfo.fMargin.width() >= 0); | 19 SkASSERT(fInfo.fMargin.width() >= 0); |
19 SkASSERT(fInfo.fMargin.height() >= 0); | 20 SkASSERT(fInfo.fMargin.height() >= 0); |
20 | |
21 // We want a conservative answer for the size... | |
22 const SkIRect ibounds = bounds.roundOut(); | |
23 const int width = ibounds.width(); | |
24 const int height = ibounds.height(); | |
25 | |
26 // Note: SkIRects are non-inclusive of the right() column and bottom() row. | 21 // Note: SkIRects are non-inclusive of the right() column and bottom() row. |
27 // For example, an SkIRect at 0,0 with a size of (1,1) will only have | 22 // For example, an SkIRect at 0,0 with a size of (1,1) will only have |
28 // content at pixel (0,0) and will report left=0 and right=1, hence the | 23 // content at pixel (0,0) and will report left=0 and right=1, hence the |
29 // "-1"s below. | 24 // "-1"s below. |
30 int xTileCount = (width + fInfo.fTileInterval.width() - 1) / fInfo.fTileInte
rval.width(); | 25 int xTileCount = (width + fInfo.fTileInterval.width() - 1) / fInfo.fTileInte
rval.width(); |
31 int yTileCount = (height + fInfo.fTileInterval.height() - 1) / fInfo.fTileIn
terval.height(); | 26 int yTileCount = (height + fInfo.fTileInterval.height() - 1) / fInfo.fTileIn
terval.height(); |
32 return SkNEW_ARGS(SkTileGrid, (xTileCount, yTileCount, fInfo)); | 27 return SkNEW_ARGS(SkTileGrid, (xTileCount, yTileCount, fInfo)); |
33 } | 28 } |
OLD | NEW |