| 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 #ifndef GrAtlas_DEFINED | 9 #ifndef GrAtlas_DEFINED |
| 10 #define GrAtlas_DEFINED | 10 #define GrAtlas_DEFINED |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 // or more GrPlots. The GrPlots keep track of subimage placement via their GrRec
tanizer. Once a | 24 // or more GrPlots. The GrPlots keep track of subimage placement via their GrRec
tanizer. Once a |
| 25 // GrPlot is "full" (i.e. there is no room for the new subimage according to the
GrRectanizer), the | 25 // GrPlot is "full" (i.e. there is no room for the new subimage according to the
GrRectanizer), the |
| 26 // GrAtlas can request a new GrPlot via GrAtlasMgr::addToAtlas(). | 26 // GrAtlas can request a new GrPlot via GrAtlasMgr::addToAtlas(). |
| 27 // | 27 // |
| 28 // If all GrPlots are allocated, the replacement strategy is up to the client. T
he drawToken is | 28 // If all GrPlots are allocated, the replacement strategy is up to the client. T
he drawToken is |
| 29 // available to ensure that all draw calls are finished for that particular GrPl
ot. | 29 // available to ensure that all draw calls are finished for that particular GrPl
ot. |
| 30 // GrAtlasMgr::removeUnusedPlots() will free up any finished plots for a given G
rAtlas. | 30 // GrAtlasMgr::removeUnusedPlots() will free up any finished plots for a given G
rAtlas. |
| 31 | 31 |
| 32 class GrPlot { | 32 class GrPlot { |
| 33 public: | 33 public: |
| 34 SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrPlot); |
| 35 |
| 34 int getOffsetX() const { return fOffset.fX; } | 36 int getOffsetX() const { return fOffset.fX; } |
| 35 int getOffsetY() const { return fOffset.fY; } | 37 int getOffsetY() const { return fOffset.fY; } |
| 36 | 38 |
| 37 GrTexture* texture() const { return fTexture; } | 39 GrTexture* texture() const { return fTexture; } |
| 38 | 40 |
| 39 bool addSubImage(int width, int height, const void*, GrIPoint16*); | 41 bool addSubImage(int width, int height, const void*, GrIPoint16*); |
| 40 | 42 |
| 41 GrDrawTarget::DrawToken drawToken() const { return fDrawToken; } | 43 GrDrawTarget::DrawToken drawToken() const { return fDrawToken; } |
| 42 void setDrawToken(GrDrawTarget::DrawToken draw) { fDrawToken = draw; } | 44 void setDrawToken(GrDrawTarget::DrawToken draw) { fDrawToken = draw; } |
| 43 | 45 |
| 46 void resetRects(); |
| 47 |
| 44 private: | 48 private: |
| 45 GrPlot(); | 49 GrPlot(); |
| 46 ~GrPlot(); // does not try to delete the fNext field | 50 ~GrPlot(); // does not try to delete the fNext field |
| 47 | 51 |
| 48 // for recycling | 52 // for recycling |
| 49 GrDrawTarget::DrawToken fDrawToken; | 53 GrDrawTarget::DrawToken fDrawToken; |
| 50 | 54 |
| 51 GrPlot* fNext; | |
| 52 | |
| 53 GrTexture* fTexture; | 55 GrTexture* fTexture; |
| 54 GrRectanizer* fRects; | 56 GrRectanizer* fRects; |
| 55 GrAtlasMgr* fAtlasMgr; | 57 GrAtlasMgr* fAtlasMgr; |
| 56 GrIPoint16 fOffset; | 58 GrIPoint16 fOffset; |
| 57 size_t fBytesPerPixel; | 59 size_t fBytesPerPixel; |
| 58 | 60 |
| 59 friend class GrAtlasMgr; | 61 friend class GrAtlasMgr; |
| 60 }; | 62 }; |
| 61 | 63 |
| 64 typedef SkTInternalLList<GrPlot> GrPlotList; |
| 65 |
| 62 class GrAtlasMgr { | 66 class GrAtlasMgr { |
| 63 public: | 67 public: |
| 64 GrAtlasMgr(GrGpu*, GrPixelConfig); | 68 GrAtlasMgr(GrGpu*, GrPixelConfig); |
| 65 ~GrAtlasMgr(); | 69 ~GrAtlasMgr(); |
| 66 | 70 |
| 67 // add subimage of width, height dimensions to atlas | 71 // add subimage of width, height dimensions to atlas |
| 68 // returns the containing GrPlot and location relative to the backing textur
e | 72 // returns the containing GrPlot and location relative to the backing textur
e |
| 69 GrPlot* addToAtlas(GrAtlas*, int width, int height, const void*, GrIPoint16*
); | 73 GrPlot* addToAtlas(GrAtlas*, int width, int height, const void*, GrIPoint16*
); |
| 70 | 74 |
| 71 // free up any plots that are not waiting on a draw call | 75 // remove reference to this plot |
| 72 bool removeUnusedPlots(GrAtlas* atlas); | 76 bool removePlot(GrAtlas* atlas, const GrPlot* plot); |
| 73 | 77 |
| 74 // to be called by ~GrAtlas() | 78 // get a plot that's not being used by the current draw |
| 75 void deletePlotList(GrPlot* plot); | 79 // this allows us to overwrite this plot without flushing |
| 80 GrPlot* getUnusedPlot(); |
| 76 | 81 |
| 77 GrTexture* getTexture() const { | 82 GrTexture* getTexture() const { |
| 78 return fTexture; | 83 return fTexture; |
| 79 } | 84 } |
| 80 | 85 |
| 81 private: | 86 private: |
| 82 GrPlot* allocPlot(); | 87 void moveToHead(GrPlot* plot); |
| 83 void freePlot(GrPlot* plot); | |
| 84 | 88 |
| 85 GrGpu* fGpu; | 89 GrGpu* fGpu; |
| 86 GrPixelConfig fPixelConfig; | 90 GrPixelConfig fPixelConfig; |
| 87 GrTexture* fTexture; | 91 GrTexture* fTexture; |
| 88 | 92 |
| 89 // allocated array of GrPlots | 93 // allocated array of GrPlots |
| 90 GrPlot* fPlots; | 94 GrPlot* fPlotArray; |
| 91 // linked list of free GrPlots | 95 // LRU list of GrPlots |
| 92 GrPlot* fFreePlots; | 96 GrPlotList fPlotList; |
| 93 }; | 97 }; |
| 94 | 98 |
| 95 class GrAtlas { | 99 class GrAtlas { |
| 96 public: | 100 public: |
| 97 GrAtlas(GrAtlasMgr* mgr) : fPlots(NULL), fAtlasMgr(mgr) { } | 101 GrAtlas() { } |
| 98 ~GrAtlas() { fAtlasMgr->deletePlotList(fPlots); } | 102 ~GrAtlas() { } |
| 99 | 103 |
| 100 bool isEmpty() { return NULL == fPlots; } | 104 bool isEmpty() { return 0 == fPlots.count(); } |
| 101 | 105 |
| 102 SkISize getSize() const; | 106 SkISize getSize() const; |
| 103 | 107 |
| 104 private: | 108 private: |
| 105 GrPlot* fPlots; | 109 SkTDArray<GrPlot*> fPlots; |
| 106 GrAtlasMgr* fAtlasMgr; | |
| 107 | 110 |
| 108 friend class GrAtlasMgr; | 111 friend class GrAtlasMgr; |
| 109 }; | 112 }; |
| 110 | 113 |
| 111 #endif | 114 #endif |
| OLD | NEW |