1 /* 2 * Copyright 2010 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 skgpu_Rectanizer_DEFINED 9 #define skgpu_Rectanizer_DEFINED 10 11 #include "src/core/SkIPoint16.h" 12 13 namespace skgpu { 14 15 class Rectanizer { 16 public: Rectanizer(int width,int height)17 Rectanizer(int width, int height) : fWidth(width), fHeight(height) { 18 SkASSERT(width >= 0); 19 SkASSERT(height >= 0); 20 } 21 ~Rectanizer()22 virtual ~Rectanizer() {} 23 24 virtual void reset() = 0; 25 width()26 int width() const { return fWidth; } height()27 int height() const { return fHeight; } 28 29 // Attempt to add a rect. Return true on success; false on failure. If 30 // successful the position in the atlas is returned in 'loc'. 31 virtual bool addRect(int width, int height, SkIPoint16* loc) = 0; 32 virtual float percentFull() const = 0; 33 addPaddedRect(int width,int height,int16_t padding,SkIPoint16 * loc)34 bool addPaddedRect(int width, int height, int16_t padding, SkIPoint16* loc) { 35 if (this->addRect(width + 2*padding, height + 2*padding, loc)) { 36 loc->fX += padding; 37 loc->fY += padding; 38 return true; 39 } 40 return false; 41 } 42 43 /** 44 * Our factory, which returns the subclass du jour 45 */ 46 static Rectanizer* Factory(int width, int height); 47 48 private: 49 const int fWidth; 50 const int fHeight; 51 }; 52 53 } // End of namespace skgpu 54 55 #endif 56