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 | |
10 | |
11 #ifndef GrAtlas_DEFINED | 9 #ifndef GrAtlas_DEFINED |
12 #define GrAtlas_DEFINED | 10 #define GrAtlas_DEFINED |
13 | 11 |
| 12 |
14 #include "GrPoint.h" | 13 #include "GrPoint.h" |
15 #include "GrTexture.h" | 14 #include "GrTexture.h" |
16 #include "GrDrawTarget.h" | 15 #include "GrDrawTarget.h" |
17 | 16 |
18 class GrGpu; | 17 class GrGpu; |
19 class GrRectanizer; | 18 class GrRectanizer; |
20 class GrAtlasMgr; | 19 class GrAtlasMgr; |
| 20 class GrAtlas; |
21 | 21 |
22 class GrAtlas { | 22 // The backing GrTexture for a set of GrAtlases is broken into a spatial grid of
GrPlots. When |
| 23 // a GrAtlas needs space on the texture, it requests a GrPlot. Each GrAtlas can
claim one |
| 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 |
| 26 // GrAtlas can request a new GrPlot via GrAtlasMgr::addToAtlas(). |
| 27 // |
| 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. |
| 30 // GrAtlasMgr::removeUnusedPlots() will free up any finished plots for a given G
rAtlas. |
| 31 |
| 32 class GrPlot { |
23 public: | 33 public: |
24 int getPlotX() const { return fPlot.fX; } | 34 int getOffsetX() const { return fOffset.fX; } |
25 int getPlotY() const { return fPlot.fY; } | 35 int getOffsetY() const { return fOffset.fY; } |
26 | 36 |
27 GrTexture* texture() const { return fTexture; } | 37 GrTexture* texture() const { return fTexture; } |
28 | 38 |
29 bool addSubImage(int width, int height, const void*, GrIPoint16*); | 39 bool addSubImage(int width, int height, const void*, GrIPoint16*); |
30 | 40 |
31 static void FreeLList(GrAtlas* atlas) { | |
32 while (NULL != atlas) { | |
33 GrAtlas* next = atlas->fNext; | |
34 delete atlas; | |
35 atlas = next; | |
36 } | |
37 } | |
38 | |
39 static bool RemoveUnusedAtlases(GrAtlasMgr* atlasMgr, GrAtlas** startAtlas); | |
40 | |
41 GrDrawTarget::DrawToken drawToken() const { return fDrawToken; } | 41 GrDrawTarget::DrawToken drawToken() const { return fDrawToken; } |
42 void setDrawToken(GrDrawTarget::DrawToken draw) { fDrawToken = draw; } | 42 void setDrawToken(GrDrawTarget::DrawToken draw) { fDrawToken = draw; } |
43 | 43 |
44 private: | 44 private: |
45 GrAtlas(GrAtlasMgr*, int plotX, int plotY, int bpp); | 45 GrPlot(); |
46 ~GrAtlas(); // does not try to delete the fNext field | 46 ~GrPlot(); // does not try to delete the fNext field |
47 | 47 |
48 // for recycling | 48 // for recycling |
49 GrDrawTarget::DrawToken fDrawToken; | 49 GrDrawTarget::DrawToken fDrawToken; |
50 | 50 |
51 GrAtlas* fNext; | 51 GrPlot* fNext; |
52 | 52 |
53 GrTexture* fTexture; | 53 GrTexture* fTexture; |
54 GrRectanizer* fRects; | 54 GrRectanizer* fRects; |
55 GrAtlasMgr* fAtlasMgr; | 55 GrAtlasMgr* fAtlasMgr; |
56 GrIPoint16 fPlot; | 56 GrIPoint16 fOffset; |
57 int fBytesPerPixel; | 57 int fBytesPerPixel; |
58 | 58 |
59 friend class GrAtlasMgr; | 59 friend class GrAtlasMgr; |
60 }; | 60 }; |
61 | 61 |
62 class GrPlotMgr; | |
63 | |
64 class GrAtlasMgr { | 62 class GrAtlasMgr { |
65 public: | 63 public: |
66 GrAtlasMgr(GrGpu*, GrPixelConfig); | 64 GrAtlasMgr(GrGpu*, GrPixelConfig); |
67 ~GrAtlasMgr(); | 65 ~GrAtlasMgr(); |
68 | 66 |
69 GrAtlas* addToAtlas(GrAtlas**, int width, int height, const void*, GrIPoint1
6*); | 67 // add subimage of width, height dimensions to atlas |
70 void deleteAtlas(GrAtlas* atlas) { delete atlas; } | 68 // returns the containing GrPlot and location relative to the backing textur
e |
71 | 69 GrPlot* addToAtlas(GrAtlas*, int width, int height, const void*, GrIPoint16*
); |
| 70 |
| 71 // free up any plots that are not waiting on a draw call |
| 72 bool removeUnusedPlots(GrAtlas* atlas); |
| 73 |
| 74 // to be called by ~GrAtlas() |
| 75 void deletePlotList(GrPlot* plot); |
| 76 |
72 GrTexture* getTexture() const { | 77 GrTexture* getTexture() const { |
73 return fTexture; | 78 return fTexture; |
74 } | 79 } |
75 | 80 |
76 // to be called by ~GrAtlas() | |
77 void freePlot(int x, int y); | |
78 | |
79 private: | 81 private: |
| 82 GrPlot* allocPlot(); |
| 83 void freePlot(GrPlot* plot); |
| 84 |
80 GrGpu* fGpu; | 85 GrGpu* fGpu; |
81 GrPixelConfig fPixelConfig; | 86 GrPixelConfig fPixelConfig; |
82 GrTexture* fTexture; | 87 GrTexture* fTexture; |
83 GrPlotMgr* fPlotMgr; | 88 |
| 89 // allocated array of GrPlots |
| 90 GrPlot* fPlots; |
| 91 // linked list of free GrPlots |
| 92 GrPlot* fFreePlots; |
| 93 }; |
| 94 |
| 95 class GrAtlas { |
| 96 public: |
| 97 GrAtlas(GrAtlasMgr* mgr) : fPlots(NULL), fAtlasMgr(mgr) { } |
| 98 ~GrAtlas() { fAtlasMgr->deletePlotList(fPlots); } |
| 99 |
| 100 bool isEmpty() { return NULL == fPlots; } |
| 101 |
| 102 private: |
| 103 GrPlot* fPlots; |
| 104 GrAtlasMgr* fAtlasMgr; |
| 105 |
| 106 friend class GrAtlasMgr; |
84 }; | 107 }; |
85 | 108 |
86 #endif | 109 #endif |
OLD | NEW |