reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame^] | 1 | /* |
| 2 | Copyright 2010 Google Inc. |
| 3 | |
| 4 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | you may not use this file except in compliance with the License. |
| 6 | You may obtain a copy of the License at |
| 7 | |
| 8 | http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | Unless required by applicable law or agreed to in writing, software |
| 11 | distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | See the License for the specific language governing permissions and |
| 14 | limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | |
| 18 | #ifndef GrAtlas_DEFINED |
| 19 | #define GrAtlas_DEFINED |
| 20 | |
| 21 | #include "GrPoint.h" |
| 22 | #include "GrTexture.h" |
| 23 | #include "GrTDArray.h" |
| 24 | |
| 25 | class GrGpu; |
| 26 | class GrRectanizer; |
| 27 | class GrAtlasMgr; |
| 28 | |
| 29 | class GrAtlas { |
| 30 | public: |
| 31 | GrAtlas(GrAtlasMgr*, int plotX, int plotY); |
| 32 | |
| 33 | int getPlotX() const { return fPlot.fX; } |
| 34 | int getPlotY() const { return fPlot.fY; } |
| 35 | |
| 36 | GrTexture* texture() const { return fTexture; } |
| 37 | |
| 38 | bool addSubImage(int width, int height, const void*, GrIPoint16*); |
| 39 | |
| 40 | static void FreeLList(GrAtlas* atlas) { |
| 41 | while (atlas) { |
| 42 | GrAtlas* next = atlas->fNext; |
| 43 | delete atlas; |
| 44 | atlas = next; |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | // testing |
| 49 | GrAtlas* nextAtlas() const { return fNext; } |
| 50 | |
| 51 | private: |
| 52 | ~GrAtlas(); // does not try to delete the fNext field |
| 53 | |
| 54 | GrAtlas* fNext; |
| 55 | GrTexture* fTexture; |
| 56 | GrRectanizer* fRects; |
| 57 | GrAtlasMgr* fAtlasMgr; |
| 58 | GrIPoint16 fPlot; |
| 59 | |
| 60 | friend class GrAtlasMgr; |
| 61 | }; |
| 62 | |
| 63 | class GrPlotMgr; |
| 64 | |
| 65 | class GrAtlasMgr { |
| 66 | public: |
| 67 | GrAtlasMgr(GrGpu*); |
| 68 | ~GrAtlasMgr(); |
| 69 | |
| 70 | GrAtlas* addToAtlas(GrAtlas*, int width, int height, const void*, |
| 71 | GrIPoint16*); |
| 72 | |
| 73 | GrTexture* getTexture() const { return fTexture; } |
| 74 | |
| 75 | // to be called by ~GrAtlas() |
| 76 | void freePlot(int x, int y); |
| 77 | |
| 78 | void abandonAll(); |
| 79 | |
| 80 | private: |
| 81 | GrGpu* fGpu; |
| 82 | GrTexture* fTexture; |
| 83 | GrPlotMgr* fPlotMgr; |
| 84 | }; |
| 85 | |
| 86 | #endif |
| 87 | |
| 88 | |