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 "GrPoint.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; | 19 class GrAtlasMgr; |
20 class GrAtlas; | 20 class GrAtlas; |
21 | 21 |
22 // The backing GrTexture for a set of GrAtlases is broken into a spatial grid of
GrPlots. When | 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 | 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 | 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); | 34 SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrPlot); |
35 | 35 |
36 GrTexture* texture() const { return fTexture; } | 36 GrTexture* texture() const { return fTexture; } |
37 | 37 |
38 bool addSubImage(int width, int height, const void*, GrIPoint16*); | 38 bool addSubImage(int width, int height, const void*, SkIPoint16*); |
39 | 39 |
40 GrDrawTarget::DrawToken drawToken() const { return fDrawToken; } | 40 GrDrawTarget::DrawToken drawToken() const { return fDrawToken; } |
41 void setDrawToken(GrDrawTarget::DrawToken draw) { fDrawToken = draw; } | 41 void setDrawToken(GrDrawTarget::DrawToken draw) { fDrawToken = draw; } |
42 | 42 |
43 void uploadToTexture(); | 43 void uploadToTexture(); |
44 | 44 |
45 void resetRects(); | 45 void resetRects(); |
46 | 46 |
47 private: | 47 private: |
48 GrPlot(); | 48 GrPlot(); |
49 ~GrPlot(); // does not try to delete the fNext field | 49 ~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, | 50 void init(GrAtlasMgr* mgr, int offX, int offY, int width, int height, size_t
bpp, |
51 bool batchUploads); | 51 bool batchUploads); |
52 | 52 |
53 // for recycling | 53 // for recycling |
54 GrDrawTarget::DrawToken fDrawToken; | 54 GrDrawTarget::DrawToken fDrawToken; |
55 | 55 |
56 unsigned char* fPlotData; | 56 unsigned char* fPlotData; |
57 GrTexture* fTexture; | 57 GrTexture* fTexture; |
58 GrRectanizer* fRects; | 58 GrRectanizer* fRects; |
59 GrAtlasMgr* fAtlasMgr; | 59 GrAtlasMgr* fAtlasMgr; |
60 GrIPoint16 fOffset; // the offset of the plot in the bac
king texture | 60 SkIPoint16 fOffset; // the offset of the plot in the bac
king texture |
61 size_t fBytesPerPixel; | 61 size_t fBytesPerPixel; |
62 SkIRect fDirtyRect; | 62 SkIRect fDirtyRect; |
63 bool fDirty; | 63 bool fDirty; |
64 bool fBatchUploads; | 64 bool fBatchUploads; |
65 | 65 |
66 friend class GrAtlasMgr; | 66 friend class GrAtlasMgr; |
67 }; | 67 }; |
68 | 68 |
69 typedef SkTInternalLList<GrPlot> GrPlotList; | 69 typedef SkTInternalLList<GrPlot> GrPlotList; |
70 | 70 |
71 class GrAtlasMgr { | 71 class GrAtlasMgr { |
72 public: | 72 public: |
73 GrAtlasMgr(GrGpu*, GrPixelConfig, const SkISize& backingTextureSize, | 73 GrAtlasMgr(GrGpu*, GrPixelConfig, const SkISize& backingTextureSize, |
74 int numPlotsX, int numPlotsY, bool batchUploads); | 74 int numPlotsX, int numPlotsY, bool batchUploads); |
75 ~GrAtlasMgr(); | 75 ~GrAtlasMgr(); |
76 | 76 |
77 // add subimage of width, height dimensions to atlas | 77 // add subimage of width, height dimensions to atlas |
78 // returns the containing GrPlot and location relative to the backing textur
e | 78 // returns the containing GrPlot and location relative to the backing textur
e |
79 GrPlot* addToAtlas(GrAtlas*, int width, int height, const void*, GrIPoint16*
); | 79 GrPlot* addToAtlas(GrAtlas*, int width, int height, const void*, SkIPoint16*
); |
80 | 80 |
81 // remove reference to this plot | 81 // remove reference to this plot |
82 bool removePlot(GrAtlas* atlas, const GrPlot* plot); | 82 bool removePlot(GrAtlas* atlas, const GrPlot* plot); |
83 | 83 |
84 // get a plot that's not being used by the current draw | 84 // get a plot that's not being used by the current draw |
85 // this allows us to overwrite this plot without flushing | 85 // this allows us to overwrite this plot without flushing |
86 GrPlot* getUnusedPlot(); | 86 GrPlot* getUnusedPlot(); |
87 | 87 |
88 GrTexture* getTexture() const { | 88 GrTexture* getTexture() const { |
89 return fTexture; | 89 return fTexture; |
(...skipping 25 matching lines...) Expand all Loading... |
115 | 115 |
116 bool isEmpty() { return 0 == fPlots.count(); } | 116 bool isEmpty() { return 0 == fPlots.count(); } |
117 | 117 |
118 private: | 118 private: |
119 SkTDArray<GrPlot*> fPlots; | 119 SkTDArray<GrPlot*> fPlots; |
120 | 120 |
121 friend class GrAtlasMgr; | 121 friend class GrAtlasMgr; |
122 }; | 122 }; |
123 | 123 |
124 #endif | 124 #endif |
OLD | NEW |