| 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 GrLayerAtlas_DEFINED | 9 #ifndef GrLayerAtlas_DEFINED |
| 10 #define GrLayerAtlas_DEFINED | 10 #define GrLayerAtlas_DEFINED |
| 11 | 11 |
| 12 #include "GrTypes.h" | 12 #include "GrTexture.h" |
| 13 | 13 |
| 14 #include "SkPoint.h" | 14 #include "SkPoint.h" |
| 15 #include "SkSize.h" | |
| 16 #include "SkTDArray.h" | 15 #include "SkTDArray.h" |
| 17 #include "SkTInternalLList.h" | 16 #include "SkTInternalLList.h" |
| 18 | 17 |
| 19 class GrLayerAtlas; | 18 class GrLayerAtlas; |
| 20 class GrTexture; | |
| 21 class GrTextureProvider; | 19 class GrTextureProvider; |
| 22 class GrRectanizer; | 20 class GrRectanizer; |
| 23 | 21 |
| 24 // The backing GrTexture for a GrLayerAtlas is broken into a spatial grid of Plo
ts. When | 22 // The backing GrTexture for a GrLayerAtlas is broken into a spatial grid of Plo
ts. When |
| 25 // the atlas needs space on the texture (i.e., in response to an addToAtlas call
), it | 23 // the atlas needs space on the texture (i.e., in response to an addToAtlas call
), it |
| 26 // iterates through the plots in use by the requesting client looking for space
and, | 24 // iterates through the plots in use by the requesting client looking for space
and, |
| 27 // if no space is found, opens up a new Plot for that client. The Plots keep tra
ck of | 25 // if no space is found, opens up a new Plot for that client. The Plots keep tra
ck of |
| 28 // subimage placement via their GrRectanizer. | 26 // subimage placement via their GrRectanizer. |
| 29 // | 27 // |
| 30 // If all Plots are full, the replacement strategy is up to the client. The Plot
::reset | 28 // If all Plots are full, the replacement strategy is up to the client. The Plot
::reset |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 GrLayerAtlas(GrTextureProvider*, GrPixelConfig, GrSurfaceFlags flags, | 100 GrLayerAtlas(GrTextureProvider*, GrPixelConfig, GrSurfaceFlags flags, |
| 103 const SkISize& backingTextureSize, | 101 const SkISize& backingTextureSize, |
| 104 int numPlotsX, int numPlotsY); | 102 int numPlotsX, int numPlotsY); |
| 105 ~GrLayerAtlas(); | 103 ~GrLayerAtlas(); |
| 106 | 104 |
| 107 // Requests a width x height block in the atlas. Upon success it returns | 105 // Requests a width x height block in the atlas. Upon success it returns |
| 108 // the containing Plot and absolute location in the backing texture. | 106 // the containing Plot and absolute location in the backing texture. |
| 109 // nullptr is returned if there is no more space in the atlas. | 107 // nullptr is returned if there is no more space in the atlas. |
| 110 Plot* addToAtlas(ClientPlotUsage*, int width, int height, SkIPoint16* loc); | 108 Plot* addToAtlas(ClientPlotUsage*, int width, int height, SkIPoint16* loc); |
| 111 | 109 |
| 112 GrTexture* getTexture() const { | 110 GrTexture* getTextureOrNull() const { |
| 113 return fTexture; | 111 return fTexture; |
| 114 } | 112 } |
| 115 | 113 |
| 114 GrTexture* getTexture() const { |
| 115 SkASSERT(fTexture); |
| 116 return fTexture; |
| 117 } |
| 118 |
| 119 bool reattachBackingTexture(); |
| 120 |
| 121 void detachBackingTexture() { |
| 122 fTexture.reset(nullptr); |
| 123 } |
| 124 |
| 125 void resetPlots(); |
| 126 |
| 116 enum IterOrder { | 127 enum IterOrder { |
| 117 kLRUFirst_IterOrder, | 128 kLRUFirst_IterOrder, |
| 118 kMRUFirst_IterOrder | 129 kMRUFirst_IterOrder |
| 119 }; | 130 }; |
| 120 | 131 |
| 121 typedef SkTInternalLList<Plot> PlotList; | 132 typedef SkTInternalLList<Plot> PlotList; |
| 122 typedef PlotList::Iter PlotIter; | 133 typedef PlotList::Iter PlotIter; |
| 123 Plot* iterInit(PlotIter* iter, IterOrder order) { | 134 Plot* iterInit(PlotIter* iter, IterOrder order) { |
| 124 return iter->init(fPlotList, kLRUFirst_IterOrder == order | 135 return iter->init(fPlotList, kLRUFirst_IterOrder == order |
| 125 ? PlotList::Iter::kTail_I
terStart | 136 ? PlotList::Iter::kTail_I
terStart |
| 126 : PlotList::Iter::kHead_I
terStart); | 137 : PlotList::Iter::kHead_I
terStart); |
| 127 } | 138 } |
| 128 | 139 |
| 129 private: | 140 private: |
| 141 void createBackingTexture(); |
| 142 |
| 130 void makeMRU(Plot* plot); | 143 void makeMRU(Plot* plot); |
| 131 | 144 |
| 132 GrTextureProvider* fTexProvider; | 145 GrTextureProvider* fTexProvider; |
| 133 GrPixelConfig fPixelConfig; | 146 GrPixelConfig fPixelConfig; |
| 134 GrSurfaceFlags fFlags; | 147 GrSurfaceFlags fFlags; |
| 135 GrTexture* fTexture; | 148 SkAutoTUnref<GrTexture> fTexture; |
| 136 | 149 |
| 137 SkISize fBackingTextureSize; | 150 SkISize fBackingTextureSize; |
| 138 | 151 |
| 139 // allocated array of Plots | 152 // allocated array of Plots |
| 140 Plot* fPlotArray; | 153 Plot* fPlotArray; |
| 141 // LRU list of Plots (MRU at head - LRU at tail) | 154 // LRU list of Plots (MRU at head - LRU at tail) |
| 142 PlotList fPlotList; | 155 PlotList fPlotList; |
| 143 }; | 156 }; |
| 144 | 157 |
| 145 #endif | 158 #endif |
| OLD | NEW |