| 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 dataPtr += fBytesPerPixel*plotWidth; | 85 dataPtr += fBytesPerPixel*plotWidth; |
| 86 imagePtr += fBytesPerPixel*width; | 86 imagePtr += fBytesPerPixel*width; |
| 87 } | 87 } |
| 88 | 88 |
| 89 fDirtyRect.join(loc->fX, loc->fY, loc->fX + width, loc->fY + height); | 89 fDirtyRect.join(loc->fX, loc->fY, loc->fX + width, loc->fY + height); |
| 90 adjust_for_offset(loc, fOffset); | 90 adjust_for_offset(loc, fOffset); |
| 91 fDirty = true; | 91 fDirty = true; |
| 92 // otherwise, just upload the image directly | 92 // otherwise, just upload the image directly |
| 93 } else if (image) { | 93 } else if (image) { |
| 94 adjust_for_offset(loc, fOffset); | 94 adjust_for_offset(loc, fOffset); |
| 95 GrContext* context = fTexture->getContext(); | |
| 96 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("skia.gpu"), "GrPlot::uploadToTex
ture"); | 95 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("skia.gpu"), "GrPlot::uploadToTex
ture"); |
| 97 context->writeTexturePixels(fTexture, | 96 fTexture->writePixels(loc->fX, loc->fY, width, height, fTexture->config(
), image, 0, |
| 98 loc->fX, loc->fY, width, height, | 97 GrContext::kDontFlush_PixelOpsFlag); |
| 99 fTexture->config(), image, 0, | |
| 100 GrContext::kDontFlush_PixelOpsFlag); | |
| 101 } else { | 98 } else { |
| 102 adjust_for_offset(loc, fOffset); | 99 adjust_for_offset(loc, fOffset); |
| 103 } | 100 } |
| 104 | 101 |
| 105 #if FONT_CACHE_STATS | 102 #if FONT_CACHE_STATS |
| 106 ++g_UploadCount; | 103 ++g_UploadCount; |
| 107 #endif | 104 #endif |
| 108 | 105 |
| 109 return true; | 106 return true; |
| 110 } | 107 } |
| 111 | 108 |
| 112 void GrPlot::uploadToTexture() { | 109 void GrPlot::uploadToTexture() { |
| 113 static const float kNearlyFullTolerance = 0.85f; | 110 static const float kNearlyFullTolerance = 0.85f; |
| 114 | 111 |
| 115 // should only do this if batching is enabled | 112 // should only do this if batching is enabled |
| 116 SkASSERT(fBatchUploads); | 113 SkASSERT(fBatchUploads); |
| 117 | 114 |
| 118 if (fDirty) { | 115 if (fDirty) { |
| 119 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("skia.gpu"), "GrPlot::uploadToTex
ture"); | 116 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("skia.gpu"), "GrPlot::uploadToTex
ture"); |
| 120 SkASSERT(fTexture); | 117 SkASSERT(fTexture); |
| 121 GrContext* context = fTexture->getContext(); | |
| 122 // We pass the flag that does not force a flush. We assume our caller is | 118 // We pass the flag that does not force a flush. We assume our caller is |
| 123 // smart and hasn't referenced the part of the texture we're about to up
date | 119 // smart and hasn't referenced the part of the texture we're about to up
date |
| 124 // since the last flush. | 120 // since the last flush. |
| 125 size_t rowBytes = fBytesPerPixel*fRects->width(); | 121 size_t rowBytes = fBytesPerPixel*fRects->width(); |
| 126 const unsigned char* dataPtr = fPlotData; | 122 const unsigned char* dataPtr = fPlotData; |
| 127 dataPtr += rowBytes*fDirtyRect.fTop; | 123 dataPtr += rowBytes*fDirtyRect.fTop; |
| 128 dataPtr += fBytesPerPixel*fDirtyRect.fLeft; | 124 dataPtr += fBytesPerPixel*fDirtyRect.fLeft; |
| 129 context->writeTexturePixels(fTexture, | 125 fTexture->writePixels(fOffset.fX + fDirtyRect.fLeft, fOffset.fY + fDirty
Rect.fTop, |
| 130 fOffset.fX + fDirtyRect.fLeft, fOffset.fY +
fDirtyRect.fTop, | 126 fDirtyRect.width(), fDirtyRect.height(), fTexture-
>config(), dataPtr, |
| 131 fDirtyRect.width(), fDirtyRect.height(), | 127 rowBytes, GrContext::kDontFlush_PixelOpsFlag); |
| 132 fTexture->config(), dataPtr, | |
| 133 rowBytes, | |
| 134 GrContext::kDontFlush_PixelOpsFlag); | |
| 135 fDirtyRect.setEmpty(); | 128 fDirtyRect.setEmpty(); |
| 136 fDirty = false; | 129 fDirty = false; |
| 137 // If the Plot is nearly full, anything else we add will probably be sma
ll and one | 130 // If the Plot is nearly full, anything else we add will probably be sma
ll and one |
| 138 // at a time, so free up the memory and after this upload any new images
directly. | 131 // at a time, so free up the memory and after this upload any new images
directly. |
| 139 if (fRects->percentFull() > kNearlyFullTolerance) { | 132 if (fRects->percentFull() > kNearlyFullTolerance) { |
| 140 SkDELETE_ARRAY(fPlotData); | 133 SkDELETE_ARRAY(fPlotData); |
| 141 fPlotData = NULL; | 134 fPlotData = NULL; |
| 142 } | 135 } |
| 143 } | 136 } |
| 144 } | 137 } |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 if (fBatchUploads) { | 278 if (fBatchUploads) { |
| 286 GrPlotList::Iter plotIter; | 279 GrPlotList::Iter plotIter; |
| 287 plotIter.init(fPlotList, GrPlotList::Iter::kHead_IterStart); | 280 plotIter.init(fPlotList, GrPlotList::Iter::kHead_IterStart); |
| 288 GrPlot* plot; | 281 GrPlot* plot; |
| 289 while ((plot = plotIter.get())) { | 282 while ((plot = plotIter.get())) { |
| 290 plot->uploadToTexture(); | 283 plot->uploadToTexture(); |
| 291 plotIter.next(); | 284 plotIter.next(); |
| 292 } | 285 } |
| 293 } | 286 } |
| 294 } | 287 } |
| OLD | NEW |