| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2013 Google Inc. | 3 * Copyright 2013 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #include "GrRectanizer.h" | 9 #include "GrRectanizer_skyline.h" |
| 10 #include "SkTDArray.h" | |
| 11 | |
| 12 // Pack rectangles and track the current silhouette | |
| 13 // Based in part on Jukka Jylänki's work at http://clb.demon.fi | |
| 14 | |
| 15 class GrRectanizerSkyline : public GrRectanizer { | |
| 16 public: | |
| 17 GrRectanizerSkyline(int w, int h) : INHERITED(w, h) { | |
| 18 this->reset(); | |
| 19 } | |
| 20 | |
| 21 virtual ~GrRectanizerSkyline() { | |
| 22 } | |
| 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 virtual int stripToPurge(int height) const SK_OVERRIDE { return -1; } | |
| 40 virtual void purgeStripAtY(int yCoord) SK_OVERRIDE { } | |
| 41 | |
| 42 /////////////////////////////////////////////////////////////////////////// | |
| 43 | |
| 44 struct SkylineSegment { | |
| 45 int fX; | |
| 46 int fY; | |
| 47 int fWidth; | |
| 48 }; | |
| 49 | |
| 50 SkTDArray<SkylineSegment> fSkyline; | |
| 51 | |
| 52 int32_t fAreaSoFar; | |
| 53 | |
| 54 bool rectangleFits(int skylineIndex, int width, int height, int* y) const; | |
| 55 void addSkylineLevel(int skylineIndex, int x, int y, int width, int height); | |
| 56 | |
| 57 private: | |
| 58 typedef GrRectanizer INHERITED; | |
| 59 }; | |
| 60 | 10 |
| 61 bool GrRectanizerSkyline::addRect(int width, int height, GrIPoint16* loc) { | 11 bool GrRectanizerSkyline::addRect(int width, int height, GrIPoint16* loc) { |
| 62 if ((unsigned)width > (unsigned)this->width() || | 12 if ((unsigned)width > (unsigned)this->width() || |
| 63 (unsigned)height > (unsigned)this->height()) { | 13 (unsigned)height > (unsigned)this->height()) { |
| 64 return false; | 14 return false; |
| 65 } | 15 } |
| 66 | 16 |
| 67 // find position for new rectangle | 17 // find position for new rectangle |
| 68 int bestWidth = this->width() + 1; | 18 int bestWidth = this->width() + 1; |
| 69 int bestX; | 19 int bestX; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 --i; | 109 --i; |
| 160 } | 110 } |
| 161 } | 111 } |
| 162 } | 112 } |
| 163 | 113 |
| 164 /////////////////////////////////////////////////////////////////////////////// | 114 /////////////////////////////////////////////////////////////////////////////// |
| 165 | 115 |
| 166 GrRectanizer* GrRectanizer::Factory(int width, int height) { | 116 GrRectanizer* GrRectanizer::Factory(int width, int height) { |
| 167 return SkNEW_ARGS(GrRectanizerSkyline, (width, height)); | 117 return SkNEW_ARGS(GrRectanizerSkyline, (width, height)); |
| 168 } | 118 } |
| OLD | NEW |