From 862a3876086a9367c584598038887b94d8065fd7 Mon Sep 17 00:00:00 2001 From: fmalita Date: Mon, 17 Oct 2016 07:16:05 -0700 Subject: Avoid SkImage ref churn in short lived SkBitmapProvider SkBitmapProvider is always stack-allocated and tightly-scoped. It should be safe to store a SkImage rawptr instead of a ref object. R=reed@google.com GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2424813002 Review-Url: https://codereview.chromium.org/2424813002 --- src/core/SkBitmapProvider.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/core') diff --git a/src/core/SkBitmapProvider.h b/src/core/SkBitmapProvider.h index 9901c0fc1a..2080104b87 100644 --- a/src/core/SkBitmapProvider.h +++ b/src/core/SkBitmapProvider.h @@ -15,10 +15,10 @@ class SkBitmapProvider { public: explicit SkBitmapProvider(const SkBitmap& bm) : fBitmap(bm) {} - explicit SkBitmapProvider(const SkImage* img) : fImage(SkSafeRef(img)) {} + explicit SkBitmapProvider(const SkImage* img) : fImage(img) {} SkBitmapProvider(const SkBitmapProvider& other) : fBitmap(other.fBitmap) - , fImage(SkSafeRef(other.fImage.get())) + , fImage(other.fImage) {} int width() const; @@ -38,8 +38,14 @@ public: bool asBitmap(SkBitmap*) const; private: - SkBitmap fBitmap; - SkAutoTUnref fImage; + // Stack-allocated only. + void* operator new(size_t) = delete; + void* operator new(size_t, void*) = delete; + + SkBitmap fBitmap; + // SkBitmapProvider is always short-lived/stack allocated, and the source image is guaranteed + // to outlive its scope => we can store a raw ptr to avoid ref churn. + const SkImage* fImage; }; #endif -- cgit v1.2.3