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

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: 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
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->bytesAllocated();
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::resetImageHeap()
1339 {
1340 fCanvas->resetImageHeap();
1341 }
1342
1323 /////////////////////////////////////////////////////////////////////////////// 1343 ///////////////////////////////////////////////////////////////////////////////
1324 1344
1325 SkGPipeWriter::SkGPipeWriter() 1345 SkGPipeWriter::SkGPipeWriter()
1326 : fWriter(0) { 1346 : fWriter(0) {
1327 fCanvas = NULL; 1347 fCanvas = NULL;
1328 } 1348 }
1329 1349
1330 SkGPipeWriter::~SkGPipeWriter() { 1350 SkGPipeWriter::~SkGPipeWriter() {
1331 this->endRecording(); 1351 this->endRecording();
1332 } 1352 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1386 void BitmapShuttle::removeCanvas() { 1406 void BitmapShuttle::removeCanvas() {
1387 if (NULL == fCanvas) { 1407 if (NULL == fCanvas) {
1388 return; 1408 return;
1389 } 1409 }
1390 fCanvas->unref(); 1410 fCanvas->unref();
1391 fCanvas = NULL; 1411 fCanvas = NULL;
1392 } 1412 }
1393 1413
1394 //////////////////////////////////////////////////////////////////////////////// /////////////////// 1414 //////////////////////////////////////////////////////////////////////////////// ///////////////////
1395 1415
1396 SkImageHeap::SkImageHeap() {} 1416 SkImageHeap::SkImageHeap() : fBytesAllocated (0) {}
1397 1417
1398 SkImageHeap::~SkImageHeap() { 1418 SkImageHeap::~SkImageHeap() {
1399 fArray.unrefAll(); 1419 fArray.unrefAll();
1400 } 1420 }
1401 1421
1422 void SkImageHeap::reset() {
1423 fArray.unrefAll();
1424 fArray.rewind();
1425 fBytesAllocated = 0;
1426 }
1427
1402 const SkImage* SkImageHeap::get(int32_t slot) const { 1428 const SkImage* SkImageHeap::get(int32_t slot) const {
1403 SkASSERT(slot > 0); 1429 SkASSERT(slot > 0);
1404 return fArray[slot - 1]; 1430 return fArray[slot - 1];
1405 } 1431 }
1406 1432
1407 int32_t SkImageHeap::find(const SkImage* img) const { 1433 int32_t SkImageHeap::find(const SkImage* img) const {
1408 int index = fArray.find(img); 1434 int index = fArray.find(img);
1409 if (index >= 0) { 1435 if (index >= 0) {
1410 return index + 1; // found 1436 return index + 1; // found
1411 } 1437 }
1412 return 0; // not found 1438 return 0; // not found
1413 } 1439 }
1414 1440
1415 int32_t SkImageHeap::insert(const SkImage* img) { 1441 int32_t SkImageHeap::insert(const SkImage* img) {
1416 int32_t slot = this->find(img); 1442 int32_t slot = this->find(img);
1417 if (slot) { 1443 if (slot) {
1418 return slot; 1444 return slot;
1419 } 1445 }
1446 // TODO: SkImage does not expose bytes per pixel, 4 is just a best guess.
1447 fBytesAllocated += img->width() * img->height() * 4;
1420 *fArray.append() = SkRef(img); 1448 *fArray.append() = SkRef(img);
1449 printf("Images reff'ed: %d \n", fArray.count());
1421 return fArray.count(); // slot is always index+1 1450 return fArray.count(); // slot is always index+1
1422 } 1451 }
1423 1452
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698