epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 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. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 10 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 11 | #ifndef GrAtlas_DEFINED |
| 12 | #define GrAtlas_DEFINED |
| 13 | |
| 14 | #include "GrPoint.h" |
| 15 | #include "GrTexture.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 16 | |
| 17 | class GrGpu; |
| 18 | class GrRectanizer; |
| 19 | class GrAtlasMgr; |
| 20 | |
| 21 | class GrAtlas { |
| 22 | public: |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 23 | int getPlotX() const { return fPlot.fX; } |
| 24 | int getPlotY() const { return fPlot.fY; } |
reed@google.com | 98539c6 | 2011-03-15 15:40:16 +0000 | [diff] [blame] | 25 | GrMaskFormat getMaskFormat() const { return fMaskFormat; } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 26 | |
| 27 | GrTexture* texture() const { return fTexture; } |
| 28 | |
| 29 | bool addSubImage(int width, int height, const void*, GrIPoint16*); |
| 30 | |
| 31 | static void FreeLList(GrAtlas* atlas) { |
commit-bot@chromium.org | 67ed64e | 2013-08-05 19:42:56 +0000 | [diff] [blame^] | 32 | while (NULL != atlas) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 33 | GrAtlas* next = atlas->fNext; |
| 34 | delete atlas; |
| 35 | atlas = next; |
| 36 | } |
| 37 | } |
| 38 | |
commit-bot@chromium.org | 67ed64e | 2013-08-05 19:42:56 +0000 | [diff] [blame^] | 39 | static void MarkAllUnused(GrAtlas* atlas) { |
| 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; } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 50 | |
| 51 | private: |
commit-bot@chromium.org | 67ed64e | 2013-08-05 19:42:56 +0000 | [diff] [blame^] | 52 | GrAtlas(GrAtlasMgr*, int plotX, int plotY, GrMaskFormat format); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 53 | ~GrAtlas(); // does not try to delete the fNext field |
| 54 | |
| 55 | GrAtlas* fNext; |
commit-bot@chromium.org | 67ed64e | 2013-08-05 19:42:56 +0000 | [diff] [blame^] | 56 | |
| 57 | // for recycling |
| 58 | bool fUsed; |
| 59 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 60 | GrTexture* fTexture; |
| 61 | GrRectanizer* fRects; |
| 62 | GrAtlasMgr* fAtlasMgr; |
| 63 | GrIPoint16 fPlot; |
reed@google.com | 98539c6 | 2011-03-15 15:40:16 +0000 | [diff] [blame] | 64 | GrMaskFormat fMaskFormat; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 65 | |
| 66 | friend class GrAtlasMgr; |
| 67 | }; |
| 68 | |
| 69 | class GrPlotMgr; |
| 70 | |
| 71 | class GrAtlasMgr { |
| 72 | public: |
| 73 | GrAtlasMgr(GrGpu*); |
| 74 | ~GrAtlasMgr(); |
| 75 | |
commit-bot@chromium.org | 67ed64e | 2013-08-05 19:42:56 +0000 | [diff] [blame^] | 76 | GrAtlas* addToAtlas(GrAtlas**, int width, int height, const void*, |
reed@google.com | 98539c6 | 2011-03-15 15:40:16 +0000 | [diff] [blame] | 77 | GrMaskFormat, GrIPoint16*); |
commit-bot@chromium.org | 67ed64e | 2013-08-05 19:42:56 +0000 | [diff] [blame^] | 78 | void deleteAtlas(GrAtlas* atlas) { delete atlas; } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 79 | |
reed@google.com | 759c16e | 2011-03-15 19:15:15 +0000 | [diff] [blame] | 80 | GrTexture* getTexture(GrMaskFormat format) const { |
| 81 | GrAssert((unsigned)format < kCount_GrMaskFormats); |
| 82 | return fTexture[format]; |
| 83 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 84 | |
| 85 | // to be called by ~GrAtlas() |
commit-bot@chromium.org | 67ed64e | 2013-08-05 19:42:56 +0000 | [diff] [blame^] | 86 | void freePlot(GrMaskFormat format, int x, int y); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 87 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 88 | private: |
| 89 | GrGpu* fGpu; |
reed@google.com | 759c16e | 2011-03-15 19:15:15 +0000 | [diff] [blame] | 90 | GrTexture* fTexture[kCount_GrMaskFormats]; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 91 | GrPlotMgr* fPlotMgr; |
| 92 | }; |
| 93 | |
| 94 | #endif |