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