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