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 |
14 #include "GrPoint.h" | 12 #include "GrPoint.h" |
15 #include "GrTexture.h" | 13 #include "GrTexture.h" |
16 #include "GrDrawTarget.h" | 14 #include "GrDrawTarget.h" |
17 | 15 |
18 class GrGpu; | 16 class GrGpu; |
19 class GrRectanizer; | 17 class GrRectanizer; |
20 class GrAtlasMgr; | 18 class GrAtlasMgr; |
19 class GrAtlas; | |
21 | 20 |
22 class GrAtlas { | 21 class GrPlot { |
23 public: | 22 public: |
24 int getPlotX() const { return fPlot.fX; } | 23 int getOffsetX() const { return fOffset.fX; } |
25 int getPlotY() const { return fPlot.fY; } | 24 int getOffsetY() const { return fOffset.fY; } |
26 | 25 |
27 GrTexture* texture() const { return fTexture; } | 26 GrTexture* texture() const { return fTexture; } |
28 | 27 |
29 bool addSubImage(int width, int height, const void*, GrIPoint16*); | 28 bool addSubImage(int width, int height, const void*, GrIPoint16*); |
30 | 29 |
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; } | 30 GrDrawTarget::DrawToken drawToken() const { return fDrawToken; } |
42 void setDrawToken(GrDrawTarget::DrawToken draw) { fDrawToken = draw; } | 31 void setDrawToken(GrDrawTarget::DrawToken draw) { fDrawToken = draw; } |
43 | 32 |
44 private: | 33 private: |
45 GrAtlas(GrAtlasMgr*, int plotX, int plotY, int bpp); | 34 GrPlot(); |
46 ~GrAtlas(); // does not try to delete the fNext field | 35 ~GrPlot(); // does not try to delete the fNext field |
47 | 36 |
48 // for recycling | 37 // for recycling |
49 GrDrawTarget::DrawToken fDrawToken; | 38 GrDrawTarget::DrawToken fDrawToken; |
50 | 39 |
51 GrAtlas* fNext; | 40 GrPlot* fNext; |
52 | 41 |
53 GrTexture* fTexture; | 42 GrTexture* fTexture; |
54 GrRectanizer* fRects; | 43 GrRectanizer* fRects; |
55 GrAtlasMgr* fAtlasMgr; | 44 GrAtlasMgr* fAtlasMgr; |
56 GrIPoint16 fPlot; | 45 GrIPoint16 fOffset; |
57 int fBytesPerPixel; | 46 int fBytesPerPixel; |
58 | 47 |
59 friend class GrAtlasMgr; | 48 friend class GrAtlasMgr; |
60 }; | 49 }; |
61 | 50 |
62 class GrPlotMgr; | |
63 | |
64 class GrAtlasMgr { | 51 class GrAtlasMgr { |
65 public: | 52 public: |
66 GrAtlasMgr(GrGpu*, GrPixelConfig); | 53 GrAtlasMgr(GrGpu*, GrPixelConfig); |
67 ~GrAtlasMgr(); | 54 ~GrAtlasMgr(); |
68 | 55 |
69 GrAtlas* addToAtlas(GrAtlas**, int width, int height, const void*, GrIPoint1 6*); | 56 GrPlot* addToAtlas(GrAtlas*, int width, int height, const void*, GrIPoint16* ); |
bsalomon
2013/09/27 18:42:55
This guy could really use a comment describing wha
jvanverth1
2013/09/27 19:12:54
Done.
| |
70 void deleteAtlas(GrAtlas* atlas) { delete atlas; } | 57 bool removeUnusedPlots(GrAtlas* atlas); |
71 | 58 |
59 // to be called by ~GrAtlas() | |
60 void deletePlotList(GrPlot* plot); | |
61 | |
72 GrTexture* getTexture() const { | 62 GrTexture* getTexture() const { |
73 return fTexture; | 63 return fTexture; |
74 } | 64 } |
75 | 65 |
76 // to be called by ~GrAtlas() | |
77 void freePlot(int x, int y); | |
78 | |
79 private: | 66 private: |
67 GrPlot* allocPlot(); | |
68 void freePlot(GrPlot* plot); | |
69 | |
80 GrGpu* fGpu; | 70 GrGpu* fGpu; |
81 GrPixelConfig fPixelConfig; | 71 GrPixelConfig fPixelConfig; |
82 GrTexture* fTexture; | 72 GrTexture* fTexture; |
83 GrPlotMgr* fPlotMgr; | 73 |
74 // allocated array of GrPlots | |
75 GrPlot* fPlots; | |
76 // linked list of free GrPlots | |
77 GrPlot* fFreePlots; | |
78 }; | |
79 | |
80 class GrAtlas { | |
81 public: | |
82 GrAtlas(GrAtlasMgr* mgr) : fPlots(NULL), fAtlasMgr(mgr) { } | |
83 ~GrAtlas() { fAtlasMgr->deletePlotList(fPlots); } | |
84 | |
85 bool isEmpty() { return NULL == fPlots; } | |
86 | |
87 private: | |
88 GrPlot* fPlots; | |
89 GrAtlasMgr* fAtlasMgr; | |
90 | |
91 friend class GrAtlasMgr; | |
84 }; | 92 }; |
85 | 93 |
86 #endif | 94 #endif |
OLD | NEW |