| 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 #include "GrAtlas.h" | 9 #include "GrAtlas.h" |
| 10 #include "GrContext.h" | 10 #include "GrContext.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 fDirtyRect.setEmpty(); | 47 fDirtyRect.setEmpty(); |
| 48 fDirty = false; | 48 fDirty = false; |
| 49 fBatchUploads = batchUploads; | 49 fBatchUploads = batchUploads; |
| 50 } | 50 } |
| 51 | 51 |
| 52 static inline void adjust_for_offset(SkIPoint16* loc, const SkIPoint16& offset)
{ | 52 static inline void adjust_for_offset(SkIPoint16* loc, const SkIPoint16& offset)
{ |
| 53 loc->fX += offset.fX; | 53 loc->fX += offset.fX; |
| 54 loc->fY += offset.fY; | 54 loc->fY += offset.fY; |
| 55 } | 55 } |
| 56 | 56 |
| 57 bool GrPlot::addSubImage(int width, int height, const void* image, SkIPoint16* l
oc) { | 57 bool GrPlot::addSubImage(int width, int height, const void* image, |
| 58 SkIPoint16* loc) { |
| 58 float percentFull = fRects->percentFull(); | 59 float percentFull = fRects->percentFull(); |
| 59 if (!fRects->addRect(width, height, loc)) { | 60 if (!fRects->addRect(width, height, loc)) { |
| 60 return false; | 61 return false; |
| 61 } | 62 } |
| 62 | 63 |
| 63 // if batching uploads, create backing memory on first use | 64 // if batching uploads, create backing memory on first use |
| 64 // once the plot is nearly full we will revert to uploading each subimage in
dividually | 65 // once the plot is nearly full we will revert to uploading each subimage in
dividually |
| 65 int plotWidth = fRects->width(); | 66 int plotWidth = fRects->width(); |
| 66 int plotHeight = fRects->height(); | 67 int plotHeight = fRects->height(); |
| 67 if (fBatchUploads && NULL == fPlotData && 0.0f == percentFull) { | 68 if (fBatchUploads && NULL == fPlotData && 0.0f == percentFull) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 80 for (int i = 0; i < height; ++i) { | 81 for (int i = 0; i < height; ++i) { |
| 81 memcpy(dataPtr, imagePtr, fBytesPerPixel*width); | 82 memcpy(dataPtr, imagePtr, fBytesPerPixel*width); |
| 82 dataPtr += fBytesPerPixel*plotWidth; | 83 dataPtr += fBytesPerPixel*plotWidth; |
| 83 imagePtr += fBytesPerPixel*width; | 84 imagePtr += fBytesPerPixel*width; |
| 84 } | 85 } |
| 85 | 86 |
| 86 fDirtyRect.join(loc->fX, loc->fY, loc->fX + width, loc->fY + height); | 87 fDirtyRect.join(loc->fX, loc->fY, loc->fX + width, loc->fY + height); |
| 87 adjust_for_offset(loc, fOffset); | 88 adjust_for_offset(loc, fOffset); |
| 88 fDirty = true; | 89 fDirty = true; |
| 89 // otherwise, just upload the image directly | 90 // otherwise, just upload the image directly |
| 90 } else if (NULL != image) { | 91 } else { |
| 91 adjust_for_offset(loc, fOffset); | 92 adjust_for_offset(loc, fOffset); |
| 92 GrContext* context = fTexture->getContext(); | 93 GrContext* context = fTexture->getContext(); |
| 93 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("skia.gpu"), "GrPlot::uploadToTex
ture"); | 94 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("skia.gpu"), "GrPlot::uploadToTex
ture"); |
| 94 context->writeTexturePixels(fTexture, | 95 context->writeTexturePixels(fTexture, |
| 95 loc->fX, loc->fY, width, height, | 96 loc->fX, loc->fY, width, height, |
| 96 fTexture->config(), image, 0, | 97 fTexture->config(), image, 0, |
| 97 GrContext::kDontFlush_PixelOpsFlag); | 98 GrContext::kDontFlush_PixelOpsFlag); |
| 98 } else { | |
| 99 adjust_for_offset(loc, fOffset); | |
| 100 } | 99 } |
| 101 | 100 |
| 102 #if FONT_CACHE_STATS | 101 #if FONT_CACHE_STATS |
| 103 ++g_UploadCount; | 102 ++g_UploadCount; |
| 104 #endif | 103 #endif |
| 105 | 104 |
| 106 return true; | 105 return true; |
| 107 } | 106 } |
| 108 | 107 |
| 109 void GrPlot::uploadToTexture() { | 108 void GrPlot::uploadToTexture() { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 140 } | 139 } |
| 141 } | 140 } |
| 142 | 141 |
| 143 void GrPlot::resetRects() { | 142 void GrPlot::resetRects() { |
| 144 SkASSERT(NULL != fRects); | 143 SkASSERT(NULL != fRects); |
| 145 fRects->reset(); | 144 fRects->reset(); |
| 146 } | 145 } |
| 147 | 146 |
| 148 /////////////////////////////////////////////////////////////////////////////// | 147 /////////////////////////////////////////////////////////////////////////////// |
| 149 | 148 |
| 150 GrAtlas::GrAtlas(GrGpu* gpu, GrPixelConfig config, GrTextureFlags flags, | 149 GrAtlas::GrAtlas(GrGpu* gpu, GrPixelConfig config, |
| 151 const SkISize& backingTextureSize, | 150 const SkISize& backingTextureSize, |
| 152 int numPlotsX, int numPlotsY, bool batchUploads) { | 151 int numPlotsX, int numPlotsY, bool batchUploads) { |
| 153 fGpu = SkRef(gpu); | 152 fGpu = SkRef(gpu); |
| 154 fPixelConfig = config; | 153 fPixelConfig = config; |
| 155 fFlags = flags; | |
| 156 fBackingTextureSize = backingTextureSize; | 154 fBackingTextureSize = backingTextureSize; |
| 157 fNumPlotsX = numPlotsX; | 155 fNumPlotsX = numPlotsX; |
| 158 fNumPlotsY = numPlotsY; | 156 fNumPlotsY = numPlotsY; |
| 159 fBatchUploads = batchUploads; | 157 fBatchUploads = batchUploads; |
| 160 fTexture = NULL; | 158 fTexture = NULL; |
| 161 | 159 |
| 162 int textureWidth = fBackingTextureSize.width(); | 160 int textureWidth = fBackingTextureSize.width(); |
| 163 int textureHeight = fBackingTextureSize.height(); | 161 int textureHeight = fBackingTextureSize.height(); |
| 164 | 162 |
| 165 int plotWidth = textureWidth / fNumPlotsX; | 163 int plotWidth = textureWidth / fNumPlotsX; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 if (plot->addSubImage(width, height, image, loc)) { | 214 if (plot->addSubImage(width, height, image, loc)) { |
| 217 this->makeMRU(plot); | 215 this->makeMRU(plot); |
| 218 return plot; | 216 return plot; |
| 219 } | 217 } |
| 220 } | 218 } |
| 221 | 219 |
| 222 // before we get a new plot, make sure we have a backing texture | 220 // before we get a new plot, make sure we have a backing texture |
| 223 if (NULL == fTexture) { | 221 if (NULL == fTexture) { |
| 224 // TODO: Update this to use the cache rather than directly creating a te
xture. | 222 // TODO: Update this to use the cache rather than directly creating a te
xture. |
| 225 GrTextureDesc desc; | 223 GrTextureDesc desc; |
| 226 desc.fFlags = fFlags | kDynamicUpdate_GrTextureFlagBit; | 224 desc.fFlags = kDynamicUpdate_GrTextureFlagBit; |
| 227 desc.fWidth = fBackingTextureSize.width(); | 225 desc.fWidth = fBackingTextureSize.width(); |
| 228 desc.fHeight = fBackingTextureSize.height(); | 226 desc.fHeight = fBackingTextureSize.height(); |
| 229 desc.fConfig = fPixelConfig; | 227 desc.fConfig = fPixelConfig; |
| 230 | 228 |
| 231 fTexture = fGpu->createTexture(desc, NULL, 0); | 229 fTexture = fGpu->createTexture(desc, NULL, 0); |
| 232 if (NULL == fTexture) { | 230 if (NULL == fTexture) { |
| 233 return NULL; | 231 return NULL; |
| 234 } | 232 } |
| 235 } | 233 } |
| 236 | 234 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 if (fBatchUploads) { | 279 if (fBatchUploads) { |
| 282 GrPlotList::Iter plotIter; | 280 GrPlotList::Iter plotIter; |
| 283 plotIter.init(fPlotList, GrPlotList::Iter::kHead_IterStart); | 281 plotIter.init(fPlotList, GrPlotList::Iter::kHead_IterStart); |
| 284 GrPlot* plot; | 282 GrPlot* plot; |
| 285 while (NULL != (plot = plotIter.get())) { | 283 while (NULL != (plot = plotIter.get())) { |
| 286 plot->uploadToTexture(); | 284 plot->uploadToTexture(); |
| 287 plotIter.next(); | 285 plotIter.next(); |
| 288 } | 286 } |
| 289 } | 287 } |
| 290 } | 288 } |
| OLD | NEW |