1 2/* 3 * Copyright 2010 Google Inc. 4 * 5 * Use of this source code is governed by a BSD-style license that can be 6 * found in the LICENSE file. 7 */ 8 9 10 11#ifndef GrAtlas_DEFINED 12#define GrAtlas_DEFINED 13 14#include "GrPoint.h" 15#include "GrTexture.h" 16#include "GrTDArray.h" 17 18class GrGpu; 19class GrRectanizer; 20class GrAtlasMgr; 21 22class GrAtlas { 23public: 24 GrAtlas(GrAtlasMgr*, int plotX, int plotY, GrMaskFormat); 25 26 int getPlotX() const { return fPlot.fX; } 27 int getPlotY() const { return fPlot.fY; } 28 GrMaskFormat getMaskFormat() const { return fMaskFormat; } 29 30 GrTexture* texture() const { return fTexture; } 31 32 bool addSubImage(int width, int height, const void*, GrIPoint16*); 33 34 static void FreeLList(GrAtlas* atlas) { 35 while (atlas) { 36 GrAtlas* next = atlas->fNext; 37 delete atlas; 38 atlas = next; 39 } 40 } 41 42 // testing 43 GrAtlas* nextAtlas() const { return fNext; } 44 45private: 46 ~GrAtlas(); // does not try to delete the fNext field 47 48 GrAtlas* fNext; 49 GrTexture* fTexture; 50 GrRectanizer* fRects; 51 GrAtlasMgr* fAtlasMgr; 52 GrIPoint16 fPlot; 53 GrMaskFormat fMaskFormat; 54 55 friend class GrAtlasMgr; 56}; 57 58class GrPlotMgr; 59 60class GrAtlasMgr { 61public: 62 GrAtlasMgr(GrGpu*); 63 ~GrAtlasMgr(); 64 65 GrAtlas* addToAtlas(GrAtlas*, int width, int height, const void*, 66 GrMaskFormat, GrIPoint16*); 67 68 GrTexture* getTexture(GrMaskFormat format) const { 69 GrAssert((unsigned)format < kCount_GrMaskFormats); 70 return fTexture[format]; 71 } 72 73 // to be called by ~GrAtlas() 74 void freePlot(int x, int y); 75 76private: 77 GrGpu* fGpu; 78 GrTexture* fTexture[kCount_GrMaskFormats]; 79 GrPlotMgr* fPlotMgr; 80}; 81 82#endif 83 84 85