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

Side by Side Diff: src/pipe/SkGPipeWrite.cpp

Issue 1145893007: Fixing leaky handling of SkImage in SkDeferredCanvas. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: reed feedback Created 5 years, 6 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 | « src/pipe/SkGPipePriv.h ('k') | src/utils/SkDeferredCanvas.cpp » ('j') | 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 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 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 "SkAnnotation.h" 9 #include "SkAnnotation.h"
10 #include "SkBitmapDevice.h" 10 #include "SkBitmapDevice.h"
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 // Break them all by destroying the final link to this SkGPipeCanvas . 221 // Break them all by destroying the final link to this SkGPipeCanvas .
222 fBitmapShuttle->removeCanvas(); 222 fBitmapShuttle->removeCanvas();
223 } 223 }
224 fDone = true; 224 fDone = true;
225 } 225 }
226 226
227 void flushRecording(bool detachCurrentBlock); 227 void flushRecording(bool detachCurrentBlock);
228 size_t freeMemoryIfPossible(size_t bytesToFree); 228 size_t freeMemoryIfPossible(size_t bytesToFree);
229 229
230 size_t storageAllocatedForRecording() { 230 size_t storageAllocatedForRecording() {
231 return (NULL == fBitmapHeap) ? 0 : fBitmapHeap->bytesAllocated(); 231 size_t bytesAllocated = 0;
232 if (NULL != fBitmapHeap) {
233 bytesAllocated += fBitmapHeap->bytesAllocated();
234 }
235 if (NULL != fImageHeap) {
236 bytesAllocated += fImageHeap->bytesInCache();
237 }
238 return bytesAllocated;
232 } 239 }
233 240
234 void beginCommentGroup(const char* description) override; 241 void beginCommentGroup(const char* description) override;
235 void addComment(const char* kywd, const char* value) override; 242 void addComment(const char* kywd, const char* value) override;
236 void endCommentGroup() override; 243 void endCommentGroup() override;
237 244
238 /** 245 /**
239 * Flatten an SkBitmap to send to the reader, where it will be referenced 246 * Flatten an SkBitmap to send to the reader, where it will be referenced
240 * according to slot. 247 * according to slot.
241 */ 248 */
242 bool shuttleBitmap(const SkBitmap&, int32_t slot); 249 bool shuttleBitmap(const SkBitmap&, int32_t slot);
243 250
251 void resetImageHeap();
252
244 protected: 253 protected:
245 void willSave() override; 254 void willSave() override;
246 SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveFlags) ov erride; 255 SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveFlags) ov erride;
247 void willRestore() override; 256 void willRestore() override;
248 257
249 void didConcat(const SkMatrix&) override; 258 void didConcat(const SkMatrix&) override;
250 void didSetMatrix(const SkMatrix&) override; 259 void didSetMatrix(const SkMatrix&) override;
251 260
252 void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override; 261 void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override;
253 void onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y, 262 void onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
(...skipping 896 matching lines...) Expand 10 before | Expand all | Expand 10 after
1150 } 1159 }
1151 1160
1152 void SkGPipeCanvas::flushRecording(bool detachCurrentBlock) { 1161 void SkGPipeCanvas::flushRecording(bool detachCurrentBlock) {
1153 this->doNotify(); 1162 this->doNotify();
1154 if (detachCurrentBlock) { 1163 if (detachCurrentBlock) {
1155 // force a new block to be requested for the next recorded command 1164 // force a new block to be requested for the next recorded command
1156 fBlockSize = 0; 1165 fBlockSize = 0;
1157 } 1166 }
1158 } 1167 }
1159 1168
1169 void SkGPipeCanvas::resetImageHeap() {
1170 if (fImageHeap) {
1171 fImageHeap->reset();
1172 }
1173 }
1174
1160 size_t SkGPipeCanvas::freeMemoryIfPossible(size_t bytesToFree) { 1175 size_t SkGPipeCanvas::freeMemoryIfPossible(size_t bytesToFree) {
1161 return (NULL == fBitmapHeap) ? 0 : fBitmapHeap->freeMemoryIfPossible(bytesTo Free); 1176 return (NULL == fBitmapHeap) ? 0 : fBitmapHeap->freeMemoryIfPossible(bytesTo Free);
1162 } 1177 }
1163 1178
1164 /////////////////////////////////////////////////////////////////////////////// 1179 ///////////////////////////////////////////////////////////////////////////////
1165 1180
1166 template <typename T> uint32_t castToU32(T value) { 1181 template <typename T> uint32_t castToU32(T value) {
1167 union { 1182 union {
1168 T fSrc; 1183 T fSrc;
1169 uint32_t fDst; 1184 uint32_t fDst;
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1313 #include "SkGPipe.h" 1328 #include "SkGPipe.h"
1314 1329
1315 SkGPipeController::~SkGPipeController() { 1330 SkGPipeController::~SkGPipeController() {
1316 SkSafeUnref(fCanvas); 1331 SkSafeUnref(fCanvas);
1317 } 1332 }
1318 1333
1319 void SkGPipeController::setCanvas(SkGPipeCanvas* canvas) { 1334 void SkGPipeController::setCanvas(SkGPipeCanvas* canvas) {
1320 SkRefCnt_SafeAssign(fCanvas, canvas); 1335 SkRefCnt_SafeAssign(fCanvas, canvas);
1321 } 1336 }
1322 1337
1338 void SkGPipeController::purgeCaches()
1339 {
1340 fCanvas->resetImageHeap();
1341 // Other caches are self-purging with a small MRU pool
1342 // We could purge them as well, but it is not clear whether
1343 // that would be a win.
1344 }
1345
1323 /////////////////////////////////////////////////////////////////////////////// 1346 ///////////////////////////////////////////////////////////////////////////////
1324 1347
1325 SkGPipeWriter::SkGPipeWriter() 1348 SkGPipeWriter::SkGPipeWriter()
1326 : fWriter(0) { 1349 : fWriter(0) {
1327 fCanvas = NULL; 1350 fCanvas = NULL;
1328 } 1351 }
1329 1352
1330 SkGPipeWriter::~SkGPipeWriter() { 1353 SkGPipeWriter::~SkGPipeWriter() {
1331 this->endRecording(); 1354 this->endRecording();
1332 } 1355 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1386 void BitmapShuttle::removeCanvas() { 1409 void BitmapShuttle::removeCanvas() {
1387 if (NULL == fCanvas) { 1410 if (NULL == fCanvas) {
1388 return; 1411 return;
1389 } 1412 }
1390 fCanvas->unref(); 1413 fCanvas->unref();
1391 fCanvas = NULL; 1414 fCanvas = NULL;
1392 } 1415 }
1393 1416
1394 //////////////////////////////////////////////////////////////////////////////// /////////////////// 1417 //////////////////////////////////////////////////////////////////////////////// ///////////////////
1395 1418
1396 SkImageHeap::SkImageHeap() {} 1419 SkImageHeap::SkImageHeap() : fBytesInCache (0) {}
1397 1420
1398 SkImageHeap::~SkImageHeap() { 1421 SkImageHeap::~SkImageHeap() {
1399 fArray.unrefAll(); 1422 fArray.unrefAll();
1400 } 1423 }
1401 1424
1425 void SkImageHeap::reset() {
1426 fArray.unrefAll();
1427 fArray.rewind();
1428 fBytesInCache = 0;
1429 }
1430
1402 const SkImage* SkImageHeap::get(int32_t slot) const { 1431 const SkImage* SkImageHeap::get(int32_t slot) const {
1403 SkASSERT(slot > 0); 1432 SkASSERT(slot > 0);
1404 return fArray[slot - 1]; 1433 return fArray[slot - 1];
1405 } 1434 }
1406 1435
1407 int32_t SkImageHeap::find(const SkImage* img) const { 1436 int32_t SkImageHeap::find(const SkImage* img) const {
1408 int index = fArray.find(img); 1437 int index = fArray.find(img);
1409 if (index >= 0) { 1438 if (index >= 0) {
1410 return index + 1; // found 1439 return index + 1; // found
1411 } 1440 }
1412 return 0; // not found 1441 return 0; // not found
1413 } 1442 }
1414 1443
1415 int32_t SkImageHeap::insert(const SkImage* img) { 1444 int32_t SkImageHeap::insert(const SkImage* img) {
1416 int32_t slot = this->find(img); 1445 int32_t slot = this->find(img);
1417 if (slot) { 1446 if (slot) {
1418 return slot; 1447 return slot;
1419 } 1448 }
1449 // TODO: SkImage does not expose bytes per pixel, 4 is just a best guess.
1450 fBytesInCache += img->width() * img->height() * 4;
1420 *fArray.append() = SkRef(img); 1451 *fArray.append() = SkRef(img);
1452 printf("Images reff'ed: %d \n", fArray.count());
reed1 2015/06/04 13:20:39 EEEEK!
1421 return fArray.count(); // slot is always index+1 1453 return fArray.count(); // slot is always index+1
1422 } 1454 }
1423 1455
OLDNEW
« no previous file with comments | « src/pipe/SkGPipePriv.h ('k') | src/utils/SkDeferredCanvas.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698