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 |
11 | 11 |
12 | 12 |
13 #include "SkPoint.h" | 13 #include "SkPoint.h" |
14 #include "GrTexture.h" | 14 #include "GrTexture.h" |
15 #include "GrDrawTarget.h" | 15 #include "GrDrawTarget.h" |
16 | 16 |
17 class GrGpu; | 17 class GrGpu; |
18 class GrRectanizer; | 18 class GrRectanizer; |
19 class GrAtlasMgr; | |
20 class GrAtlas; | 19 class GrAtlas; |
21 | 20 |
22 // The backing GrTexture for a set of GrAtlases is broken into a spatial grid of
GrPlots. When | 21 // 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 | 22 // 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 | 23 // 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 | 24 // 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(). | 25 // GrAtlas can request a new GrPlot via GrAtlas::addToAtlas(). |
27 // | 26 // |
28 // If all GrPlots are allocated, the replacement strategy is up to the client. T
he drawToken is | 27 // 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. | 28 // 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. | 29 // GrAtlas::removeUnusedPlots() will free up any finished plots for a given GrAt
las. |
31 | 30 |
32 class GrPlot { | 31 class GrPlot { |
33 public: | 32 public: |
34 SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrPlot); | 33 SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrPlot); |
35 | 34 |
36 GrTexture* texture() const { return fTexture; } | 35 GrTexture* texture() const { return fTexture; } |
37 | 36 |
38 bool addSubImage(int width, int height, const void*, SkIPoint16*); | 37 bool addSubImage(int width, int height, const void*, SkIPoint16*); |
39 | 38 |
40 GrDrawTarget::DrawToken drawToken() const { return fDrawToken; } | 39 GrDrawTarget::DrawToken drawToken() const { return fDrawToken; } |
41 void setDrawToken(GrDrawTarget::DrawToken draw) { fDrawToken = draw; } | 40 void setDrawToken(GrDrawTarget::DrawToken draw) { fDrawToken = draw; } |
42 | 41 |
43 void uploadToTexture(); | 42 void uploadToTexture(); |
44 | 43 |
45 void resetRects(); | 44 void resetRects(); |
46 | 45 |
47 private: | 46 private: |
48 GrPlot(); | 47 GrPlot(); |
49 ~GrPlot(); // does not try to delete the fNext field | 48 ~GrPlot(); // does not try to delete the fNext field |
50 void init(GrAtlasMgr* mgr, int offX, int offY, int width, int height, size_t
bpp, | 49 void init(GrAtlas* atlas, int offX, int offY, int width, int height, size_t
bpp, |
51 bool batchUploads); | 50 bool batchUploads); |
52 | 51 |
53 // for recycling | 52 // for recycling |
54 GrDrawTarget::DrawToken fDrawToken; | 53 GrDrawTarget::DrawToken fDrawToken; |
55 | 54 |
56 unsigned char* fPlotData; | 55 unsigned char* fPlotData; |
57 GrTexture* fTexture; | 56 GrTexture* fTexture; |
58 GrRectanizer* fRects; | 57 GrRectanizer* fRects; |
59 GrAtlasMgr* fAtlasMgr; | 58 GrAtlas* fAtlas; |
60 SkIPoint16 fOffset; // the offset of the plot in the bac
king texture | 59 SkIPoint16 fOffset; // the offset of the plot in the bac
king texture |
61 size_t fBytesPerPixel; | 60 size_t fBytesPerPixel; |
62 SkIRect fDirtyRect; | 61 SkIRect fDirtyRect; |
63 bool fDirty; | 62 bool fDirty; |
64 bool fBatchUploads; | 63 bool fBatchUploads; |
65 | 64 |
66 friend class GrAtlasMgr; | 65 friend class GrAtlas; |
67 }; | 66 }; |
68 | 67 |
69 typedef SkTInternalLList<GrPlot> GrPlotList; | 68 typedef SkTInternalLList<GrPlot> GrPlotList; |
70 | 69 |
71 class GrAtlasMgr { | 70 class GrAtlas { |
72 public: | 71 public: |
73 GrAtlasMgr(GrGpu*, GrPixelConfig, const SkISize& backingTextureSize, | 72 // This class allows each client to independently track the GrPlots in |
74 int numPlotsX, int numPlotsY, bool batchUploads); | 73 // which its data is stored. |
75 ~GrAtlasMgr(); | 74 class ClientPlotUsage { |
| 75 public: |
| 76 bool isEmpty() const { return 0 == fPlots.count(); } |
| 77 |
| 78 private: |
| 79 SkTDArray<GrPlot*> fPlots; |
| 80 |
| 81 friend class GrAtlas; |
| 82 }; |
| 83 |
| 84 GrAtlas(GrGpu*, GrPixelConfig, const SkISize& backingTextureSize, |
| 85 int numPlotsX, int numPlotsY, bool batchUploads); |
| 86 ~GrAtlas(); |
76 | 87 |
77 // add subimage of width, height dimensions to atlas | 88 // add subimage of width, height dimensions to atlas |
78 // returns the containing GrPlot and location relative to the backing textur
e | 89 // returns the containing GrPlot and location relative to the backing textur
e |
79 GrPlot* addToAtlas(GrAtlas*, int width, int height, const void*, SkIPoint16*
); | 90 GrPlot* addToAtlas(ClientPlotUsage*, int width, int height, const void*, SkI
Point16*); |
80 | 91 |
81 // remove reference to this plot | 92 // remove reference to this plot |
82 bool removePlot(GrAtlas* atlas, const GrPlot* plot); | 93 void removePlot(ClientPlotUsage* usage, const GrPlot* plot); |
83 | 94 |
84 // get a plot that's not being used by the current draw | 95 // get a plot that's not being used by the current draw |
85 // this allows us to overwrite this plot without flushing | 96 // this allows us to overwrite this plot without flushing |
86 GrPlot* getUnusedPlot(); | 97 GrPlot* getUnusedPlot(); |
87 | 98 |
88 GrTexture* getTexture() const { | 99 GrTexture* getTexture() const { |
89 return fTexture; | 100 return fTexture; |
90 } | 101 } |
91 | 102 |
92 void uploadPlotsToTexture(); | 103 void uploadPlotsToTexture(); |
93 | 104 |
94 private: | 105 private: |
95 void moveToHead(GrPlot* plot); | 106 void makeMRU(GrPlot* plot); |
96 | 107 |
97 GrGpu* fGpu; | 108 GrGpu* fGpu; |
98 GrPixelConfig fPixelConfig; | 109 GrPixelConfig fPixelConfig; |
99 GrTexture* fTexture; | 110 GrTexture* fTexture; |
100 SkISize fBackingTextureSize; | 111 SkISize fBackingTextureSize; |
101 int fNumPlotsX; | 112 int fNumPlotsX; |
102 int fNumPlotsY; | 113 int fNumPlotsY; |
103 bool fBatchUploads; | 114 bool fBatchUploads; |
104 | 115 |
105 // allocated array of GrPlots | 116 // allocated array of GrPlots |
106 GrPlot* fPlotArray; | 117 GrPlot* fPlotArray; |
107 // LRU list of GrPlots | 118 // LRU list of GrPlots (MRU at head - LRU at tail) |
108 GrPlotList fPlotList; | 119 GrPlotList fPlotList; |
109 }; | 120 }; |
110 | 121 |
111 class GrAtlas { | |
112 public: | |
113 GrAtlas() { } | |
114 ~GrAtlas() { } | |
115 | |
116 bool isEmpty() { return 0 == fPlots.count(); } | |
117 | |
118 private: | |
119 SkTDArray<GrPlot*> fPlots; | |
120 | |
121 friend class GrAtlasMgr; | |
122 }; | |
123 | |
124 #endif | 122 #endif |
OLD | NEW |