1 | /* |
2 | * Copyright 2014 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 GrRectanizerSkyline_DEFINED |
9 | #define GrRectanizerSkyline_DEFINED |
10 | |
11 | #include "include/private/SkTDArray.h" |
12 | #include "src/core/SkIPoint16.h" |
13 | |
14 | // Pack rectangles and track the current silhouette |
15 | // Based, in part, on Jukka Jylanki's work at http://clb.demon.fi |
16 | class GrRectanizerSkyline { |
17 | public: |
18 | GrRectanizerSkyline(int w, int h) : fWidth{w}, fHeight{h} { |
19 | this->reset(); |
20 | } |
21 | |
22 | void reset() { |
23 | fAreaSoFar = 0; |
24 | fSkyline.reset(); |
25 | SkylineSegment* seg = fSkyline.append(1); |
26 | seg->fX = 0; |
27 | seg->fY = 0; |
28 | seg->fWidth = this->width(); |
29 | } |
30 | |
31 | bool addRect(int w, int h, SkIPoint16* loc); |
32 | |
33 | int width() const { return fWidth; } |
34 | int height() const { return fHeight; } |
35 | |
36 | private: |
37 | struct SkylineSegment { |
38 | int fX; |
39 | int fY; |
40 | int fWidth; |
41 | }; |
42 | |
43 | // Can a width x height rectangle fit in the free space represented by |
44 | // the skyline segments >= 'skylineIndex'? If so, return true and fill in |
45 | // 'y' with the y-location at which it fits (the x location is pulled from |
46 | // 'skylineIndex's segment. |
47 | bool rectangleFits(int skylineIndex, int width, int height, int* y) const; |
48 | // Update the skyline structure to include a width x height rect located |
49 | // at x,y. |
50 | void addSkylineLevel(int skylineIndex, int x, int y, int width, int height); |
51 | |
52 | const int fWidth; |
53 | const int fHeight; |
54 | SkTDArray<SkylineSegment> fSkyline; |
55 | int32_t fAreaSoFar; |
56 | }; |
57 | |
58 | #endif // GrRectanizerSkyline_DEFINED |
59 | |