Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(494)

Side by Side Diff: src/gpu/GrBatchAtlas.cpp

Issue 1105913002: fix for using too much memory in GrBatchAtlas (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: feedback inc Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "GrBatchAtlas.h" 8 #include "GrBatchAtlas.h"
9 #include "GrBatchTarget.h" 9 #include "GrBatchTarget.h"
10 #include "GrGpu.h" 10 #include "GrGpu.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 int genID() const { return fGenID; } 43 int genID() const { return fGenID; }
44 GrBatchAtlas::AtlasID id() { return fID; } 44 GrBatchAtlas::AtlasID id() { return fID; }
45 45
46 GrTexture* texture() const { return fTexture; } 46 GrTexture* texture() const { return fTexture; }
47 47
48 bool addSubImage(int width, int height, const void* image, SkIPoint16* loc, size_t rowBytes) { 48 bool addSubImage(int width, int height, const void* image, SkIPoint16* loc, size_t rowBytes) {
49 if (!fRects->addRect(width, height, loc)) { 49 if (!fRects->addRect(width, height, loc)) {
50 return false; 50 return false;
51 } 51 }
52 52
53 SkASSERT(fData); 53 if (!fData) {
54 fData = reinterpret_cast<unsigned char*>(sk_calloc_throw(fBytesPerPi xel * fWidth *
55 fHeight));
56 }
54 const unsigned char* imagePtr = (const unsigned char*)image; 57 const unsigned char* imagePtr = (const unsigned char*)image;
55 // point ourselves at the right starting spot 58 // point ourselves at the right starting spot
56 unsigned char* dataPtr = fData; 59 unsigned char* dataPtr = fData;
57 dataPtr += fBytesPerPixel * fWidth * loc->fY; 60 dataPtr += fBytesPerPixel * fWidth * loc->fY;
58 dataPtr += fBytesPerPixel * loc->fX; 61 dataPtr += fBytesPerPixel * loc->fX;
59 // copy into the data buffer 62 // copy into the data buffer
60 for (int i = 0; i < height; ++i) { 63 for (int i = 0; i < height; ++i) {
61 memcpy(dataPtr, imagePtr, rowBytes); 64 memcpy(dataPtr, imagePtr, rowBytes);
62 dataPtr += fBytesPerPixel * fWidth; 65 dataPtr += fBytesPerPixel * fWidth;
63 imagePtr += rowBytes; 66 imagePtr += rowBytes;
(...skipping 17 matching lines...) Expand all
81 SkASSERT(batchToken >= fLastUpload); 84 SkASSERT(batchToken >= fLastUpload);
82 fLastUpload = batchToken; 85 fLastUpload = batchToken;
83 } 86 }
84 void setLastUseToken(BatchToken batchToken) { 87 void setLastUseToken(BatchToken batchToken) {
85 SkASSERT(batchToken >= fLastUse); 88 SkASSERT(batchToken >= fLastUse);
86 fLastUse = batchToken; 89 fLastUse = batchToken;
87 } 90 }
88 91
89 void uploadToTexture(GrBatchTarget::TextureUploader uploader) { 92 void uploadToTexture(GrBatchTarget::TextureUploader uploader) {
90 // We should only be issuing uploads if we are in fact dirty 93 // We should only be issuing uploads if we are in fact dirty
91 SkASSERT(fDirty); 94 SkASSERT(fDirty && fData && fTexture);
92 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("skia.gpu"), "GrBatchPlot::upload ToTexture"); 95 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("skia.gpu"), "GrBatchPlot::upload ToTexture");
93 SkASSERT(fTexture);
94 size_t rowBytes = fBytesPerPixel * fRects->width(); 96 size_t rowBytes = fBytesPerPixel * fRects->width();
95 const unsigned char* dataPtr = fData; 97 const unsigned char* dataPtr = fData;
96 dataPtr += rowBytes * fDirtyRect.fTop; 98 dataPtr += rowBytes * fDirtyRect.fTop;
97 dataPtr += fBytesPerPixel * fDirtyRect.fLeft; 99 dataPtr += fBytesPerPixel * fDirtyRect.fLeft;
98 uploader.writeTexturePixels(fTexture, 100 uploader.writeTexturePixels(fTexture,
99 fOffset.fX + fDirtyRect.fLeft, fOffset.fY + fDirtyRect.fTop, 101 fOffset.fX + fDirtyRect.fLeft, fOffset.fY + fDirtyRect.fTop,
100 fDirtyRect.width(), fDirtyRect.height(), 102 fDirtyRect.width(), fDirtyRect.height(),
101 fTexture->config(), dataPtr, rowBytes); 103 fTexture->config(), dataPtr, rowBytes);
102 fDirtyRect.setEmpty(); 104 fDirtyRect.setEmpty();
103 SkDEBUGCODE(fDirty = false;) 105 SkDEBUGCODE(fDirty = false;)
104 } 106 }
105 107
106 void resetRects() { 108 void resetRects() {
107 SkASSERT(fRects); 109 SkASSERT(fRects);
108 fRects->reset(); 110 fRects->reset();
109 fGenID++; 111 fGenID++;
110 fID = create_id(fIndex, fGenID); 112 fID = create_id(fIndex, fGenID);
111 113
112 // zero out the plot 114 // zero out the plot
113 SkASSERT(fData); 115 if (fData) {
114 memset(fData, 0, fBytesPerPixel * fWidth * fHeight); 116 sk_bzero(fData, fBytesPerPixel * fWidth * fHeight);
117 }
115 118
116 fDirtyRect.setEmpty(); 119 fDirtyRect.setEmpty();
117 SkDEBUGCODE(fDirty = false;) 120 SkDEBUGCODE(fDirty = false;)
118 } 121 }
119 122
120 int x() const { return fX; } 123 int x() const { return fX; }
121 int y() const { return fY; } 124 int y() const { return fY; }
122 125
123 private: 126 private:
124 BatchPlot() 127 BatchPlot()
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 fX = offX; 162 fX = offX;
160 fY = offY; 163 fY = offY;
161 fRects = GrRectanizer::Factory(width, height); 164 fRects = GrRectanizer::Factory(width, height);
162 fAtlas = atlas; 165 fAtlas = atlas;
163 fOffset.set(offX * width, offY * height); 166 fOffset.set(offX * width, offY * height);
164 fBytesPerPixel = bpp; 167 fBytesPerPixel = bpp;
165 fData = NULL; 168 fData = NULL;
166 fDirtyRect.setEmpty(); 169 fDirtyRect.setEmpty();
167 SkDEBUGCODE(fDirty = false;) 170 SkDEBUGCODE(fDirty = false;)
168 fTexture = texture; 171 fTexture = texture;
169
170 // allocate backing store
171 fData = SkNEW_ARRAY(unsigned char, fBytesPerPixel * width * height);
172 memset(fData, 0, fBytesPerPixel * width * height);
173 } 172 }
174 173
175 BatchToken fLastUpload; 174 BatchToken fLastUpload;
176 BatchToken fLastUse; 175 BatchToken fLastUse;
177 176
178 uint32_t fIndex; 177 uint32_t fIndex;
179 uint32_t fGenID; 178 uint32_t fGenID;
180 GrBatchAtlas::AtlasID fID; 179 GrBatchAtlas::AtlasID fID;
181 unsigned char* fData; 180 unsigned char* fData;
182 int fWidth; 181 int fWidth;
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 } 365 }
367 366
368 void GrBatchAtlas::setLastUseTokenBulk(const BulkUseTokenUpdater& updater, Batch Token batchToken) { 367 void GrBatchAtlas::setLastUseTokenBulk(const BulkUseTokenUpdater& updater, Batch Token batchToken) {
369 int count = updater.fPlotsToUpdate.count(); 368 int count = updater.fPlotsToUpdate.count();
370 for (int i = 0; i < count; i++) { 369 for (int i = 0; i < count; i++) {
371 BatchPlot* plot = fPlotArray[updater.fPlotsToUpdate[i]]; 370 BatchPlot* plot = fPlotArray[updater.fPlotsToUpdate[i]];
372 this->makeMRU(plot); 371 this->makeMRU(plot);
373 plot->setLastUseToken(batchToken); 372 plot->setLastUseToken(batchToken);
374 } 373 }
375 } 374 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698