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 | |
| 8 | #ifndef GrRectanizer_skyline_DEFINED |
| 9 | #define GrRectanizer_skyline_DEFINED |
| 10 | |
| 11 | #include "GrRectanizer.h" |
| 12 | #include "SkTDArray.h" |
| 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 |
commit-bot@chromium.org | ad854bf | 2014-05-29 18:46:38 +0000 | [diff] [blame] | 16 | class GrRectanizerSkyline : public GrRectanizer { |
| 17 | public: |
| 18 | GrRectanizerSkyline(int w, int h) : INHERITED(w, h) { |
| 19 | this->reset(); |
| 20 | } |
| 21 | |
robertphillips | 60029a5 | 2015-11-09 13:51:06 -0800 | [diff] [blame] | 22 | ~GrRectanizerSkyline() override { } |
commit-bot@chromium.org | ad854bf | 2014-05-29 18:46:38 +0000 | [diff] [blame] | 23 | |
robertphillips | 60029a5 | 2015-11-09 13:51:06 -0800 | [diff] [blame] | 24 | void reset() override { |
commit-bot@chromium.org | ad854bf | 2014-05-29 18:46:38 +0000 | [diff] [blame] | 25 | fAreaSoFar = 0; |
| 26 | fSkyline.reset(); |
| 27 | SkylineSegment* seg = fSkyline.append(1); |
| 28 | seg->fX = 0; |
| 29 | seg->fY = 0; |
| 30 | seg->fWidth = this->width(); |
| 31 | } |
| 32 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 33 | bool addRect(int w, int h, SkIPoint16* loc) override; |
commit-bot@chromium.org | ad854bf | 2014-05-29 18:46:38 +0000 | [diff] [blame] | 34 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 35 | float percentFull() const override { |
commit-bot@chromium.org | ad854bf | 2014-05-29 18:46:38 +0000 | [diff] [blame] | 36 | return fAreaSoFar / ((float)this->width() * this->height()); |
| 37 | } |
| 38 | |
| 39 | private: |
| 40 | struct SkylineSegment { |
| 41 | int fX; |
| 42 | int fY; |
| 43 | int fWidth; |
| 44 | }; |
| 45 | |
| 46 | SkTDArray<SkylineSegment> fSkyline; |
| 47 | |
| 48 | int32_t fAreaSoFar; |
| 49 | |
robertphillips | 4cbf8e3 | 2014-06-09 07:59:25 -0700 | [diff] [blame] | 50 | // Can a width x height rectangle fit in the free space represented by |
| 51 | // the skyline segments >= 'skylineIndex'? If so, return true and fill in |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 52 | // '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] | 53 | // 'skylineIndex's segment. |
commit-bot@chromium.org | ad854bf | 2014-05-29 18:46:38 +0000 | [diff] [blame] | 54 | bool rectangleFits(int skylineIndex, int width, int height, int* y) const; |
robertphillips | 4cbf8e3 | 2014-06-09 07:59:25 -0700 | [diff] [blame] | 55 | // Update the skyline structure to include a width x height rect located |
| 56 | // at x,y. |
commit-bot@chromium.org | ad854bf | 2014-05-29 18:46:38 +0000 | [diff] [blame] | 57 | void addSkylineLevel(int skylineIndex, int x, int y, int width, int height); |
| 58 | |
| 59 | typedef GrRectanizer INHERITED; |
| 60 | }; |
| 61 | |
| 62 | #endif |