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 15 matching lines...) Expand all Loading... |
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); | 34 SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrPlot); |
35 | 35 |
36 int getOffsetX() const { return fOffset.fX; } | |
37 int getOffsetY() const { return fOffset.fY; } | |
38 | |
39 GrTexture* texture() const { return fTexture; } | 36 GrTexture* texture() const { return fTexture; } |
40 | 37 |
41 bool addSubImage(int width, int height, const void*, GrIPoint16*); | 38 bool addSubImage(int width, int height, const void*, GrIPoint16*); |
42 | 39 |
43 GrDrawTarget::DrawToken drawToken() const { return fDrawToken; } | 40 GrDrawTarget::DrawToken drawToken() const { return fDrawToken; } |
44 void setDrawToken(GrDrawTarget::DrawToken draw) { fDrawToken = draw; } | 41 void setDrawToken(GrDrawTarget::DrawToken draw) { fDrawToken = draw; } |
45 | 42 |
46 void resetRects(); | 43 void resetRects(); |
47 | 44 |
48 private: | 45 private: |
49 GrPlot(); | 46 GrPlot(); |
50 ~GrPlot(); // does not try to delete the fNext field | 47 ~GrPlot(); // does not try to delete the fNext field |
| 48 void init(GrAtlasMgr* mgr, int offX, int offY, int width, int height, size_t
bpp); |
51 | 49 |
52 // for recycling | 50 // for recycling |
53 GrDrawTarget::DrawToken fDrawToken; | 51 GrDrawTarget::DrawToken fDrawToken; |
54 | 52 |
55 GrTexture* fTexture; | 53 GrTexture* fTexture; |
56 GrRectanizer* fRects; | 54 GrRectanizer* fRects; |
57 GrAtlasMgr* fAtlasMgr; | 55 GrAtlasMgr* fAtlasMgr; |
58 GrIPoint16 fOffset; | 56 GrIPoint16 fOffset; // the offset of the plot in the bac
king texture |
59 size_t fBytesPerPixel; | 57 size_t fBytesPerPixel; |
60 | 58 |
61 friend class GrAtlasMgr; | 59 friend class GrAtlasMgr; |
62 }; | 60 }; |
63 | 61 |
64 typedef SkTInternalLList<GrPlot> GrPlotList; | 62 typedef SkTInternalLList<GrPlot> GrPlotList; |
65 | 63 |
66 class GrAtlasMgr { | 64 class GrAtlasMgr { |
67 public: | 65 public: |
68 GrAtlasMgr(GrGpu*, GrPixelConfig); | 66 GrAtlasMgr(GrGpu*, GrPixelConfig, |
| 67 int backingTextureWidth, int backingTextureHeight, |
| 68 int numPlotsX, int numPlotsY); |
69 ~GrAtlasMgr(); | 69 ~GrAtlasMgr(); |
70 | 70 |
71 // add subimage of width, height dimensions to atlas | 71 // add subimage of width, height dimensions to atlas |
72 // 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 |
73 GrPlot* addToAtlas(GrAtlas*, int width, int height, const void*, GrIPoint16*
); | 73 GrPlot* addToAtlas(GrAtlas*, int width, int height, const void*, GrIPoint16*
); |
74 | 74 |
75 // remove reference to this plot | 75 // remove reference to this plot |
76 bool removePlot(GrAtlas* atlas, const GrPlot* plot); | 76 bool removePlot(GrAtlas* atlas, const GrPlot* plot); |
77 | 77 |
78 // get a plot that's not being used by the current draw | 78 // get a plot that's not being used by the current draw |
79 // this allows us to overwrite this plot without flushing | 79 // this allows us to overwrite this plot without flushing |
80 GrPlot* getUnusedPlot(); | 80 GrPlot* getUnusedPlot(); |
81 | 81 |
82 GrTexture* getTexture() const { | 82 GrTexture* getTexture() const { |
83 return fTexture; | 83 return fTexture; |
84 } | 84 } |
85 | 85 |
86 private: | 86 private: |
87 void moveToHead(GrPlot* plot); | 87 void moveToHead(GrPlot* plot); |
88 | 88 |
89 GrGpu* fGpu; | 89 GrGpu* fGpu; |
90 GrPixelConfig fPixelConfig; | 90 GrPixelConfig fPixelConfig; |
91 GrTexture* fTexture; | 91 GrTexture* fTexture; |
| 92 int fBackingTextureWidth; |
| 93 int fBackingTextureHeight; |
| 94 int fNumPlotsX; |
| 95 int fNumPlotsY; |
92 | 96 |
93 // allocated array of GrPlots | 97 // allocated array of GrPlots |
94 GrPlot* fPlotArray; | 98 GrPlot* fPlotArray; |
95 // LRU list of GrPlots | 99 // LRU list of GrPlots |
96 GrPlotList fPlotList; | 100 GrPlotList fPlotList; |
97 }; | 101 }; |
98 | 102 |
99 class GrAtlas { | 103 class GrAtlas { |
100 public: | 104 public: |
101 GrAtlas() { } | 105 GrAtlas() { } |
102 ~GrAtlas() { } | 106 ~GrAtlas() { } |
103 | 107 |
104 bool isEmpty() { return 0 == fPlots.count(); } | 108 bool isEmpty() { return 0 == fPlots.count(); } |
105 | 109 |
106 private: | 110 private: |
107 SkTDArray<GrPlot*> fPlots; | 111 SkTDArray<GrPlot*> fPlots; |
108 | 112 |
109 friend class GrAtlasMgr; | 113 friend class GrAtlasMgr; |
110 }; | 114 }; |
111 | 115 |
112 #endif | 116 #endif |
OLD | NEW |