| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef GrRectanizer_pow2_DEFINED | 8 #ifndef GrRectanizer_pow2_DEFINED |
| 9 #define GrRectanizer_pow2_DEFINED | 9 #define GrRectanizer_pow2_DEFINED |
| 10 | 10 |
| 11 #include "GrRectanizer.h" | 11 #include "GrRectanizer.h" |
| 12 #include "SkPoint.h" |
| 12 | 13 |
| 13 class GrRectanizerPow2 : public GrRectanizer { | 14 class GrRectanizerPow2 : public GrRectanizer { |
| 14 public: | 15 public: |
| 15 GrRectanizerPow2(int w, int h) : INHERITED(w, h) { | 16 GrRectanizerPow2(int w, int h) : INHERITED(w, h) { |
| 16 this->reset(); | 17 this->reset(); |
| 17 } | 18 } |
| 18 | 19 |
| 19 virtual ~GrRectanizerPow2() { } | 20 virtual ~GrRectanizerPow2() { } |
| 20 | 21 |
| 21 virtual void reset() SK_OVERRIDE { | 22 virtual void reset() SK_OVERRIDE { |
| 22 fNextStripY = 0; | 23 fNextStripY = 0; |
| 23 fAreaSoFar = 0; | 24 fAreaSoFar = 0; |
| 24 sk_bzero(fRows, sizeof(fRows)); | 25 sk_bzero(fRows, sizeof(fRows)); |
| 25 } | 26 } |
| 26 | 27 |
| 27 virtual bool addRect(int w, int h, GrIPoint16* loc) SK_OVERRIDE; | 28 virtual bool addRect(int w, int h, SkIPoint16* loc) SK_OVERRIDE; |
| 28 | 29 |
| 29 virtual float percentFull() const SK_OVERRIDE { | 30 virtual float percentFull() const SK_OVERRIDE { |
| 30 return fAreaSoFar / ((float)this->width() * this->height()); | 31 return fAreaSoFar / ((float)this->width() * this->height()); |
| 31 } | 32 } |
| 32 | 33 |
| 33 private: | 34 private: |
| 34 static const int kMIN_HEIGHT_POW2 = 2; | 35 static const int kMIN_HEIGHT_POW2 = 2; |
| 35 | 36 |
| 36 struct Row { | 37 struct Row { |
| 37 GrIPoint16 fLoc; | 38 SkIPoint16 fLoc; |
| 38 int fRowHeight; | 39 int fRowHeight; |
| 39 | 40 |
| 40 bool canAddWidth(int width, int containerWidth) const { | 41 bool canAddWidth(int width, int containerWidth) const { |
| 41 return fLoc.fX + width <= containerWidth; | 42 return fLoc.fX + width <= containerWidth; |
| 42 } | 43 } |
| 43 }; | 44 }; |
| 44 | 45 |
| 45 Row fRows[16]; | 46 Row fRows[16]; |
| 46 | 47 |
| 47 int fNextStripY; | 48 int fNextStripY; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 59 void initRow(Row* row, int rowHeight) { | 60 void initRow(Row* row, int rowHeight) { |
| 60 row->fLoc.set(0, fNextStripY); | 61 row->fLoc.set(0, fNextStripY); |
| 61 row->fRowHeight = rowHeight; | 62 row->fRowHeight = rowHeight; |
| 62 fNextStripY += rowHeight; | 63 fNextStripY += rowHeight; |
| 63 } | 64 } |
| 64 | 65 |
| 65 typedef GrRectanizer INHERITED; | 66 typedef GrRectanizer INHERITED; |
| 66 }; | 67 }; |
| 67 | 68 |
| 68 #endif | 69 #endif |
| OLD | NEW |