| commit-bot@chromium.org | ad854bf | 2014-05-29 18:46:38 +0000 | [diff] [blame] | 1 | /* |
| robertphillips | 901e96d | 2014-06-02 07:15:18 -0700 | [diff] [blame] | 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 | */ |
| commit-bot@chromium.org | ad854bf | 2014-05-29 18:46:38 +0000 | [diff] [blame] | 7 | |
| Herb Derby | 73c7587 | 2020-01-22 18:09:16 -0500 | [diff] [blame] | 8 | #ifndef GrRectanizerSkyline_DEFINED |
| 9 | #define GrRectanizerSkyline_DEFINED |
| commit-bot@chromium.org | ad854bf | 2014-05-29 18:46:38 +0000 | [diff] [blame] | 10 | |
| Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/private/SkTDArray.h" |
| Herb Derby | 73c7587 | 2020-01-22 18:09:16 -0500 | [diff] [blame] | 12 | #include "src/core/SkIPoint16.h" |
| commit-bot@chromium.org | ad854bf | 2014-05-29 18:46:38 +0000 | [diff] [blame] | 13 | |
| 14 | // Pack rectangles and track the current silhouette |
| robertphillips | 901e96d | 2014-06-02 07:15:18 -0700 | [diff] [blame] | 15 | // Based, in part, on Jukka Jylanki's work at http://clb.demon.fi |
| Herb Derby | 73c7587 | 2020-01-22 18:09:16 -0500 | [diff] [blame] | 16 | class GrRectanizerSkyline { |
| commit-bot@chromium.org | ad854bf | 2014-05-29 18:46:38 +0000 | [diff] [blame] | 17 | public: |
| Herb Derby | 73c7587 | 2020-01-22 18:09:16 -0500 | [diff] [blame] | 18 | GrRectanizerSkyline(int w, int h) : fWidth{w}, fHeight{h} { |
| commit-bot@chromium.org | ad854bf | 2014-05-29 18:46:38 +0000 | [diff] [blame] | 19 | this->reset(); |
| 20 | } |
| 21 | |
| Herb Derby | 73c7587 | 2020-01-22 18:09:16 -0500 | [diff] [blame] | 22 | void reset() { |
| commit-bot@chromium.org | ad854bf | 2014-05-29 18:46:38 +0000 | [diff] [blame] | 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 | |
| Herb Derby | 73c7587 | 2020-01-22 18:09:16 -0500 | [diff] [blame] | 31 | bool addRect(int w, int h, SkIPoint16* loc); |
| commit-bot@chromium.org | ad854bf | 2014-05-29 18:46:38 +0000 | [diff] [blame] | 32 | |
| Herb Derby | 73c7587 | 2020-01-22 18:09:16 -0500 | [diff] [blame] | 33 | int width() const { return fWidth; } |
| 34 | int height() const { return fHeight; } |
| commit-bot@chromium.org | ad854bf | 2014-05-29 18:46:38 +0000 | [diff] [blame] | 35 | |
| 36 | private: |
| 37 | struct SkylineSegment { |
| 38 | int fX; |
| 39 | int fY; |
| 40 | int fWidth; |
| 41 | }; |
| 42 | |
| robertphillips | 4cbf8e3 | 2014-06-09 07:59:25 -0700 | [diff] [blame] | 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 |
| halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 45 | // 'y' with the y-location at which it fits (the x location is pulled from |
| robertphillips | 4cbf8e3 | 2014-06-09 07:59:25 -0700 | [diff] [blame] | 46 | // 'skylineIndex's segment. |
| commit-bot@chromium.org | ad854bf | 2014-05-29 18:46:38 +0000 | [diff] [blame] | 47 | bool rectangleFits(int skylineIndex, int width, int height, int* y) const; |
| robertphillips | 4cbf8e3 | 2014-06-09 07:59:25 -0700 | [diff] [blame] | 48 | // Update the skyline structure to include a width x height rect located |
| 49 | // at x,y. |
| commit-bot@chromium.org | ad854bf | 2014-05-29 18:46:38 +0000 | [diff] [blame] | 50 | void addSkylineLevel(int skylineIndex, int x, int y, int width, int height); |
| 51 | |
| Chris Dalton | a550cf2 | 2020-02-07 13:35:31 -0700 | [diff] [blame] | 52 | const int fWidth; |
| 53 | const int fHeight; |
| Herb Derby | 73c7587 | 2020-01-22 18:09:16 -0500 | [diff] [blame] | 54 | SkTDArray<SkylineSegment> fSkyline; |
| 55 | int32_t fAreaSoFar; |
| commit-bot@chromium.org | ad854bf | 2014-05-29 18:46:38 +0000 | [diff] [blame] | 56 | }; |
| 57 | |
| Herb Derby | 73c7587 | 2020-01-22 18:09:16 -0500 | [diff] [blame] | 58 | #endif // GrRectanizerSkyline_DEFINED |