From 00c2af8b731085a7fe456e689b70f019a34ef7dd Mon Sep 17 00:00:00 2001 From: mtklein Date: Mon, 27 Apr 2015 08:54:23 -0700 Subject: [PATCH] Reduce ref counting in SkPictureRecorder. This may be a small help to slimming paint: picture_overhead_draw 1.25us -> 1.22us 0.98x picture_overhead_nodraw 318ns -> 276ns 0.87x It certainly cannot hurt performance. BUG=chromium:470553 TBR=reed@google.com No public API changes. Review URL: https://codereview.chromium.org/1098183003 --- include/core/SkPicture.h | 3 ++- src/core/SkPicture.cpp | 4 ++-- src/core/SkPictureRecorder.cpp | 14 ++++++-------- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/include/core/SkPicture.h b/include/core/SkPicture.h index fba0a35..6445986 100644 --- a/include/core/SkPicture.h +++ b/include/core/SkPicture.h @@ -259,7 +259,8 @@ private: void createHeader(SkPictInfo* info) const; static bool IsValidPictInfo(const SkPictInfo& info); - // Takes ownership of the SkRecord and (optional) SnapshotArray, refs the (optional) BBH. + // Takes ownership of the (optional) SnapshotArray. + // For performance, we take ownership of the caller's refs on the SkRecord and BBH. SkPicture(const SkRect& cullRect, SkRecord*, SnapshotArray*, diff --git a/src/core/SkPicture.cpp b/src/core/SkPicture.cpp index 4d4364a..619be8b 100644 --- a/src/core/SkPicture.cpp +++ b/src/core/SkPicture.cpp @@ -456,8 +456,8 @@ SkPicture::SkPicture(const SkRect& cullRect, SkRecord* record, SnapshotArray* dr SkBBoxHierarchy* bbh, size_t approxBytesUsedBySubPictures) : fUniqueID(0) , fCullRect(cullRect) - , fRecord(SkRef(record)) - , fBBH(SkSafeRef(bbh)) + , fRecord(record) // For performance, we take ownership of the caller's ref. + , fBBH(bbh) // Ditto. , fDrawablePicts(drawablePicts) // take ownership , fApproxBytesUsedBySubPictures(approxBytesUsedBySubPictures) , fAnalysis(*fRecord) diff --git a/src/core/SkPictureRecorder.cpp b/src/core/SkPictureRecorder.cpp index 22b1ee3..6639bfc 100644 --- a/src/core/SkPictureRecorder.cpp +++ b/src/core/SkPictureRecorder.cpp @@ -77,17 +77,13 @@ SkPicture* SkPictureRecorder::endRecordingAsPicture() { for (int i = 0; pictList && i < pictList->count(); i++) { subPictureBytes += SkPictureUtils::ApproximateBytesUsed(pictList->begin()[i]); } - SkPicture* pict = - SkNEW_ARGS(SkPicture, (fCullRect, fRecord, pictList, fBBH, subPictureBytes)); + SkPicture* pict = SkNEW_ARGS(SkPicture, + (fCullRect, fRecord.detach(), pictList, fBBH.detach(), subPictureBytes)); if (saveLayerData) { pict->EXPERIMENTAL_addAccelData(saveLayerData); } - // release our refs now, so only the picture will be the owner. - fRecord.reset(NULL); - fBBH.reset(NULL); - return pict; } @@ -163,8 +159,10 @@ protected: for (int i = 0; pictList && i < pictList->count(); i++) { subPictureBytes += SkPictureUtils::ApproximateBytesUsed(pictList->begin()[i]); } - SkPicture* pict = - SkNEW_ARGS(SkPicture, (fBounds, fRecord, pictList, fBBH, subPictureBytes)); + // SkPicture will take ownership of a ref on both fRecord and fBBH. + // We're not willing to give up our ownership, so we must ref them for SkPicture. + SkPicture* pict = SkNEW_ARGS(SkPicture, + (fBounds, SkRef(fRecord.get()), pictList, SkSafeRef(fBBH.get()), subPictureBytes)); if (saveLayerData) { pict->EXPERIMENTAL_addAccelData(saveLayerData); -- 2.7.4