OLD | NEW |
(Empty) | |
| 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 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 |
| 15 // Based in part on Jukka Jylänki's work at http://clb.demon.fi |
| 16 class GrRectanizerSkyline : public GrRectanizer { |
| 17 public: |
| 18 GrRectanizerSkyline(int w, int h) : INHERITED(w, h) { |
| 19 this->reset(); |
| 20 } |
| 21 |
| 22 virtual ~GrRectanizerSkyline() { } |
| 23 |
| 24 virtual void reset() SK_OVERRIDE{ |
| 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 |
| 33 virtual bool addRect(int w, int h, GrIPoint16* loc) SK_OVERRIDE; |
| 34 |
| 35 virtual float percentFull() const SK_OVERRIDE{ |
| 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 |
| 50 bool rectangleFits(int skylineIndex, int width, int height, int* y) const; |
| 51 void addSkylineLevel(int skylineIndex, int x, int y, int width, int height); |
| 52 |
| 53 typedef GrRectanizer INHERITED; |
| 54 }; |
| 55 |
| 56 #endif |
OLD | NEW |