| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2010 Google Inc. | 3 * Copyright 2010 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 | 9 |
| 10 | 10 |
| 11 #ifndef GrAtlas_DEFINED | 11 #ifndef GrAtlas_DEFINED |
| 12 #define GrAtlas_DEFINED | 12 #define GrAtlas_DEFINED |
| 13 | 13 |
| 14 #include "GrPoint.h" | 14 #include "GrPoint.h" |
| 15 #include "GrTexture.h" | 15 #include "GrTexture.h" |
| 16 | 16 |
| 17 class GrGpu; | 17 class GrGpu; |
| 18 class GrRectanizer; | 18 class GrRectanizer; |
| 19 class GrAtlasMgr; | 19 class GrAtlasMgr; |
| 20 | 20 |
| 21 class GrAtlas { | 21 class GrAtlas { |
| 22 public: | 22 public: |
| 23 GrAtlas(GrAtlasMgr*, int plotX, int plotY, GrMaskFormat); | |
| 24 | |
| 25 int getPlotX() const { return fPlot.fX; } | 23 int getPlotX() const { return fPlot.fX; } |
| 26 int getPlotY() const { return fPlot.fY; } | 24 int getPlotY() const { return fPlot.fY; } |
| 27 GrMaskFormat getMaskFormat() const { return fMaskFormat; } | 25 GrMaskFormat getMaskFormat() const { return fMaskFormat; } |
| 28 | 26 |
| 29 GrTexture* texture() const { return fTexture; } | 27 GrTexture* texture() const { return fTexture; } |
| 30 | 28 |
| 31 bool addSubImage(int width, int height, const void*, GrIPoint16*); | 29 bool addSubImage(int width, int height, const void*, GrIPoint16*); |
| 32 | 30 |
| 33 static void FreeLList(GrAtlas* atlas) { | 31 static void FreeLList(GrAtlas* atlas) { |
| 34 while (atlas) { | 32 while (NULL != atlas) { |
| 35 GrAtlas* next = atlas->fNext; | 33 GrAtlas* next = atlas->fNext; |
| 36 delete atlas; | 34 delete atlas; |
| 37 atlas = next; | 35 atlas = next; |
| 38 } | 36 } |
| 39 } | 37 } |
| 40 | 38 |
| 41 // testing | 39 static void MarkAllUnused(GrAtlas* atlas) { |
| 42 GrAtlas* nextAtlas() const { return fNext; } | 40 while (NULL != atlas) { |
| 41 atlas->fUsed = false; |
| 42 atlas = atlas->fNext; |
| 43 } |
| 44 } |
| 45 |
| 46 static bool RemoveUnusedAtlases(GrAtlasMgr* atlasMgr, GrAtlas** startAtlas); |
| 47 |
| 48 bool used() const { return fUsed; } |
| 49 void setUsed(bool used) { fUsed = used; } |
| 43 | 50 |
| 44 private: | 51 private: |
| 52 GrAtlas(GrAtlasMgr*, int plotX, int plotY, GrMaskFormat format); |
| 45 ~GrAtlas(); // does not try to delete the fNext field | 53 ~GrAtlas(); // does not try to delete the fNext field |
| 46 | 54 |
| 47 GrAtlas* fNext; | 55 GrAtlas* fNext; |
| 56 |
| 57 // for recycling |
| 58 bool fUsed; |
| 59 |
| 48 GrTexture* fTexture; | 60 GrTexture* fTexture; |
| 49 GrRectanizer* fRects; | 61 GrRectanizer* fRects; |
| 50 GrAtlasMgr* fAtlasMgr; | 62 GrAtlasMgr* fAtlasMgr; |
| 51 GrIPoint16 fPlot; | 63 GrIPoint16 fPlot; |
| 52 GrMaskFormat fMaskFormat; | 64 GrMaskFormat fMaskFormat; |
| 53 | 65 |
| 54 friend class GrAtlasMgr; | 66 friend class GrAtlasMgr; |
| 55 }; | 67 }; |
| 56 | 68 |
| 57 class GrPlotMgr; | 69 class GrPlotMgr; |
| 58 | 70 |
| 59 class GrAtlasMgr { | 71 class GrAtlasMgr { |
| 60 public: | 72 public: |
| 61 GrAtlasMgr(GrGpu*); | 73 GrAtlasMgr(GrGpu*); |
| 62 ~GrAtlasMgr(); | 74 ~GrAtlasMgr(); |
| 63 | 75 |
| 64 GrAtlas* addToAtlas(GrAtlas*, int width, int height, const void*, | 76 GrAtlas* addToAtlas(GrAtlas**, int width, int height, const void*, |
| 65 GrMaskFormat, GrIPoint16*); | 77 GrMaskFormat, GrIPoint16*); |
| 78 void deleteAtlas(GrAtlas* atlas) { delete atlas; } |
| 66 | 79 |
| 67 GrTexture* getTexture(GrMaskFormat format) const { | 80 GrTexture* getTexture(GrMaskFormat format) const { |
| 68 GrAssert((unsigned)format < kCount_GrMaskFormats); | 81 GrAssert((unsigned)format < kCount_GrMaskFormats); |
| 69 return fTexture[format]; | 82 return fTexture[format]; |
| 70 } | 83 } |
| 71 | 84 |
| 72 // to be called by ~GrAtlas() | 85 // to be called by ~GrAtlas() |
| 73 void freePlot(int x, int y); | 86 void freePlot(GrMaskFormat format, int x, int y); |
| 74 | 87 |
| 75 private: | 88 private: |
| 76 GrGpu* fGpu; | 89 GrGpu* fGpu; |
| 77 GrTexture* fTexture[kCount_GrMaskFormats]; | 90 GrTexture* fTexture[kCount_GrMaskFormats]; |
| 78 GrPlotMgr* fPlotMgr; | 91 GrPlotMgr* fPlotMgr; |
| 79 }; | 92 }; |
| 80 | 93 |
| 81 #endif | 94 #endif |
| OLD | NEW |