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

Unified 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, 7 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 side-by-side diff with in-line comments
Download patch
Index: src/pipe/SkGPipeWrite.cpp
diff --git a/src/pipe/SkGPipeWrite.cpp b/src/pipe/SkGPipeWrite.cpp
index 2e73be83f11231d9602b0127c55be35ea48763be..1617c4eb2096f59edcfeae309a9d6ca43db2c515 100644
--- a/src/pipe/SkGPipeWrite.cpp
+++ b/src/pipe/SkGPipeWrite.cpp
@@ -228,7 +228,14 @@ public:
size_t freeMemoryIfPossible(size_t bytesToFree);
size_t storageAllocatedForRecording() {
- return (NULL == fBitmapHeap) ? 0 : fBitmapHeap->bytesAllocated();
+ size_t bytesAllocated = 0;
+ if (NULL != fBitmapHeap) {
+ bytesAllocated += fBitmapHeap->bytesAllocated();
+ }
+ if (NULL != fImageHeap) {
+ bytesAllocated += fImageHeap->bytesAllocated();
+ }
+ return bytesAllocated;
}
void beginCommentGroup(const char* description) override;
@@ -241,6 +248,8 @@ public:
*/
bool shuttleBitmap(const SkBitmap&, int32_t slot);
+ void resetImageHeap();
+
protected:
void willSave() override;
SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveFlags) override;
@@ -1157,6 +1166,12 @@ void SkGPipeCanvas::flushRecording(bool detachCurrentBlock) {
}
}
+void SkGPipeCanvas::resetImageHeap() {
+ if (fImageHeap) {
+ fImageHeap->reset();
+ }
+}
+
size_t SkGPipeCanvas::freeMemoryIfPossible(size_t bytesToFree) {
return (NULL == fBitmapHeap) ? 0 : fBitmapHeap->freeMemoryIfPossible(bytesToFree);
}
@@ -1320,6 +1335,11 @@ void SkGPipeController::setCanvas(SkGPipeCanvas* canvas) {
SkRefCnt_SafeAssign(fCanvas, canvas);
}
+void SkGPipeController::resetImageHeap()
+{
+ fCanvas->resetImageHeap();
+}
+
///////////////////////////////////////////////////////////////////////////////
SkGPipeWriter::SkGPipeWriter()
@@ -1393,12 +1413,18 @@ void BitmapShuttle::removeCanvas() {
///////////////////////////////////////////////////////////////////////////////////////////////////
-SkImageHeap::SkImageHeap() {}
+SkImageHeap::SkImageHeap() : fBytesAllocated (0) {}
SkImageHeap::~SkImageHeap() {
fArray.unrefAll();
}
+void SkImageHeap::reset() {
+ fArray.unrefAll();
+ fArray.rewind();
+ fBytesAllocated = 0;
+}
+
const SkImage* SkImageHeap::get(int32_t slot) const {
SkASSERT(slot > 0);
return fArray[slot - 1];
@@ -1417,7 +1443,10 @@ int32_t SkImageHeap::insert(const SkImage* img) {
if (slot) {
return slot;
}
+ // TODO: SkImage does not expose bytes per pixel, 4 is just a best guess.
+ fBytesAllocated += img->width() * img->height() * 4;
*fArray.append() = SkRef(img);
+ printf("Images reff'ed: %d \n", fArray.count());
return fArray.count(); // slot is always index+1
}

Powered by Google App Engine
This is Rietveld 408576698