OLD | NEW |
1 | |
2 /* | 1 /* |
3 * Copyright 2010 Google Inc. | 2 * Copyright 2010 Google Inc. |
4 * | 3 * |
5 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 5 * found in the LICENSE file. |
7 */ | 6 */ |
8 | 7 |
9 #ifndef GrLayerAtlas_DEFINED | 8 #ifndef GrLayerAtlas_DEFINED |
10 #define GrLayerAtlas_DEFINED | 9 #define GrLayerAtlas_DEFINED |
11 | 10 |
12 #include "GrTexture.h" | 11 #include "GrTexture.h" |
13 | 12 |
14 #include "SkPoint.h" | 13 #include "SkPoint.h" |
15 #include "SkTDArray.h" | 14 #include "SkTDArray.h" |
16 #include "SkTInternalLList.h" | 15 #include "SkTInternalLList.h" |
17 | 16 |
18 class GrLayerAtlas; | 17 class GrLayerAtlas; |
19 class GrTextureProvider; | 18 class GrTextureProvider; |
20 class GrRectanizer; | 19 class GrRectanizer; |
21 | 20 |
22 // The backing GrTexture for a GrLayerAtlas is broken into a spatial grid of Plo
ts. When | 21 // The backing GrTexture for a GrLayerAtlas is broken into a spatial grid of Plo
ts. When |
23 // the atlas needs space on the texture (i.e., in response to an addToAtlas call
), it | 22 // the atlas needs space on the texture (i.e., in response to an addToAtlas call
), it |
24 // iterates through the plots in use by the requesting client looking for space
and, | 23 // iterates through the plots in use by the requesting client looking for space
and, |
25 // if no space is found, opens up a new Plot for that client. The Plots keep tra
ck of | 24 // if no space is found, opens up a new Plot for that client. The Plots keep tra
ck of |
26 // subimage placement via their GrRectanizer. | 25 // subimage placement via their GrRectanizer. |
27 // | 26 // |
28 // If all Plots are full, the replacement strategy is up to the client. The Plot
::reset | 27 // If all Plots are full, the replacement strategy is up to the client. The Plot
::reset |
29 // call will remove a Plot's knowledge of any allocated rects - freeing its spac
e for reuse. | 28 // call will remove a Plot's knowledge of any allocated rects - freeing its spac
e for reuse. |
30 | 29 |
31 class GrLayerAtlas { | 30 class GrLayerAtlas { |
32 public: | 31 public: |
33 class Plot { | 32 class Plot { |
34 SK_DECLARE_INTERNAL_LLIST_INTERFACE(Plot); // In an MRU llist | 33 SK_DECLARE_INTERNAL_LLIST_INTERFACE(Plot); // In an MRU llist |
35 | 34 |
36 public: | 35 public: |
(...skipping 13 matching lines...) Expand all Loading... |
50 | 49 |
51 bool allocateRect(int width, int height, SkIPoint16*); | 50 bool allocateRect(int width, int height, SkIPoint16*); |
52 | 51 |
53 int fID; | 52 int fID; |
54 GrRectanizer* fRects; | 53 GrRectanizer* fRects; |
55 SkIPoint16 fOffset; // the offset of the plot in the
backing texture | 54 SkIPoint16 fOffset; // the offset of the plot in the
backing texture |
56 }; | 55 }; |
57 | 56 |
58 // This class allows each client to independently track the Plots in | 57 // This class allows each client to independently track the Plots in |
59 // which its data is stored. | 58 // which its data is stored. |
60 // For example, multiple pictures may simultaneously store their layers in t
he | 59 // For example, multiple pictures may simultaneously store their layers in t
he |
61 // layer atlas. When a picture goes away it can use the ClientPlotUsage to r
emove itself | 60 // layer atlas. When a picture goes away it can use the ClientPlotUsage to r
emove itself |
62 // from those plots. | 61 // from those plots. |
63 class ClientPlotUsage { | 62 class ClientPlotUsage { |
64 public: | 63 public: |
65 ClientPlotUsage(int maxPlots) | 64 ClientPlotUsage(int maxPlots) |
66 SkDEBUGCODE(: fMaxPlots(maxPlots)) { | 65 SkDEBUGCODE(: fMaxPlots(maxPlots)) { |
67 fPlots.setReserve(maxPlots); | 66 fPlots.setReserve(maxPlots); |
68 } | 67 } |
69 | 68 |
70 bool isEmpty() const { return 0 == fPlots.count(); } | 69 bool isEmpty() const { return 0 == fPlots.count(); } |
71 | 70 |
72 int numPlots() const { return fPlots.count(); } | 71 int numPlots() const { return fPlots.count(); } |
73 Plot* plot(int index) { return fPlots[index]; } | 72 Plot* plot(int index) { return fPlots[index]; } |
74 | 73 |
75 void appendPlot(Plot* plot) { | 74 void appendPlot(Plot* plot) { |
76 SkASSERT(fPlots.count() <= fMaxPlots); | 75 SkASSERT(fPlots.count() <= fMaxPlots); |
77 SkASSERT(!fPlots.contains(plot)); | 76 SkASSERT(!fPlots.contains(plot)); |
78 *fPlots.append() = plot; | 77 *fPlots.append() = plot; |
79 } | 78 } |
80 | 79 |
81 // remove reference to 'plot' | 80 // remove reference to 'plot' |
82 void removePlot(const Plot* plot) { | 81 void removePlot(const Plot* plot) { |
83 int index = fPlots.find(const_cast<Plot*>(plot)); | 82 int index = fPlots.find(const_cast<Plot*>(plot)); |
84 if (index >= 0) { | 83 if (index >= 0) { |
85 fPlots.remove(index); | 84 fPlots.remove(index); |
86 } | 85 } |
87 } | 86 } |
88 | 87 |
89 #ifdef SK_DEBUG | 88 #ifdef SK_DEBUG |
90 bool contains(const Plot* plot) const { | 89 bool contains(const Plot* plot) const { |
91 return fPlots.contains(const_cast<Plot*>(plot)); | 90 return fPlots.contains(const_cast<Plot*>(plot)); |
92 } | 91 } |
93 #endif | 92 #endif |
94 | 93 |
95 private: | 94 private: |
96 SkTDArray<Plot*> fPlots; | 95 SkTDArray<Plot*> fPlots; |
97 SkDEBUGCODE(int fMaxPlots;) | 96 SkDEBUGCODE(int fMaxPlots;) |
98 }; | 97 }; |
99 | 98 |
100 GrLayerAtlas(GrTextureProvider*, GrPixelConfig, GrSurfaceFlags flags, | 99 GrLayerAtlas(GrTextureProvider*, GrPixelConfig, GrSurfaceFlags flags, |
101 const SkISize& backingTextureSize, | 100 const SkISize& backingTextureSize, |
102 int numPlotsX, int numPlotsY); | 101 int numPlotsX, int numPlotsY); |
103 ~GrLayerAtlas(); | 102 ~GrLayerAtlas(); |
104 | 103 |
105 // Requests a width x height block in the atlas. Upon success it returns | 104 // Requests a width x height block in the atlas. Upon success it returns |
106 // the containing Plot and absolute location in the backing texture. | 105 // the containing Plot and absolute location in the backing texture. |
107 // nullptr is returned if there is no more space in the atlas. | 106 // nullptr is returned if there is no more space in the atlas. |
108 Plot* addToAtlas(ClientPlotUsage*, int width, int height, SkIPoint16* loc); | 107 Plot* addToAtlas(ClientPlotUsage*, int width, int height, SkIPoint16* loc); |
109 | 108 |
110 GrTexture* getTextureOrNull() const { | 109 GrTexture* getTextureOrNull() const { |
111 return fTexture; | 110 return fTexture; |
112 } | 111 } |
113 | 112 |
114 GrTexture* getTexture() const { | 113 GrTexture* getTexture() const { |
115 SkASSERT(fTexture); | 114 SkASSERT(fTexture); |
116 return fTexture; | 115 return fTexture; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 | 148 |
150 SkISize fBackingTextureSize; | 149 SkISize fBackingTextureSize; |
151 | 150 |
152 // allocated array of Plots | 151 // allocated array of Plots |
153 Plot* fPlotArray; | 152 Plot* fPlotArray; |
154 // LRU list of Plots (MRU at head - LRU at tail) | 153 // LRU list of Plots (MRU at head - LRU at tail) |
155 PlotList fPlotList; | 154 PlotList fPlotList; |
156 }; | 155 }; |
157 | 156 |
158 #endif | 157 #endif |
OLD | NEW |