aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/pipe
diff options
context:
space:
mode:
authorGravatar junov <junov@chromium.org>2015-06-02 11:47:45 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-06-02 11:47:45 -0700
commitd26c9fa66c45b5a050580772acfbcc1b5271543e (patch)
tree8704bc7f574c6300f57819e21613856c1bc75396 /src/pipe
parenta66cc7e1e01bab8590fdcfafb269e21bfe8782fa (diff)
Fixing leaky handling of SkImage in SkDeferredCanvas.
Long lived SkImageHeap objects currently accumulate refs indefinitely. This leads to massive memory leaks in the gpu-accelerated 2D canvas code path. This CL does not implement a general fix for SkGPipe, but it resolves the leak in SkDeferredCanvas (currently the only user of SkGPipe) by resetting the image heap when the deferral queue is flushed. This change also fixes the accounting of bytes allocated by referenced images in order to trigger flushing heuristics appropriately. BUG=crbug.com/494148 Review URL: https://codereview.chromium.org/1145893007
Diffstat (limited to 'src/pipe')
-rw-r--r--src/pipe/SkGPipePriv.h3
-rw-r--r--src/pipe/SkGPipeWrite.cpp36
2 files changed, 37 insertions, 2 deletions
diff --git a/src/pipe/SkGPipePriv.h b/src/pipe/SkGPipePriv.h
index c3919f635b..5f6e45b158 100644
--- a/src/pipe/SkGPipePriv.h
+++ b/src/pipe/SkGPipePriv.h
@@ -222,6 +222,8 @@ public:
SkImageHeap();
virtual ~SkImageHeap();
+ size_t bytesInCache() const { return fBytesInCache; }
+ void reset();
// slot must be "valid" -- 0 is never valid
const SkImage* get(int32_t slot) const;
// returns 0 if not found, else returns slot
@@ -231,6 +233,7 @@ public:
private:
SkTDArray<const SkImage*> fArray;
+ size_t fBytesInCache;
};
///////////////////////////////////////////////////////////////////////////////
diff --git a/src/pipe/SkGPipeWrite.cpp b/src/pipe/SkGPipeWrite.cpp
index 2e73be83f1..a8a21141ac 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->bytesInCache();
+ }
+ 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,14 @@ void SkGPipeController::setCanvas(SkGPipeCanvas* canvas) {
SkRefCnt_SafeAssign(fCanvas, canvas);
}
+void SkGPipeController::purgeCaches()
+{
+ fCanvas->resetImageHeap();
+ // Other caches are self-purging with a small MRU pool
+ // We could purge them as well, but it is not clear whether
+ // that would be a win.
+}
+
///////////////////////////////////////////////////////////////////////////////
SkGPipeWriter::SkGPipeWriter()
@@ -1393,12 +1416,18 @@ void BitmapShuttle::removeCanvas() {
///////////////////////////////////////////////////////////////////////////////////////////////////
-SkImageHeap::SkImageHeap() {}
+SkImageHeap::SkImageHeap() : fBytesInCache (0) {}
SkImageHeap::~SkImageHeap() {
fArray.unrefAll();
}
+void SkImageHeap::reset() {
+ fArray.unrefAll();
+ fArray.rewind();
+ fBytesInCache = 0;
+}
+
const SkImage* SkImageHeap::get(int32_t slot) const {
SkASSERT(slot > 0);
return fArray[slot - 1];
@@ -1417,7 +1446,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.
+ fBytesInCache += 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
}