From fff3a40767df6d3a913c146d96b2b4284dffb4c5 Mon Sep 17 00:00:00 2001 From: Florin Malita Date: Wed, 19 Jul 2017 10:32:28 -0400 Subject: Singleton SRGB color filters Change-Id: I67e976e63bbb9ebb47616613e02adb97e6e2345c Reviewed-on: https://skia-review.googlesource.com/24303 Reviewed-by: Mike Klein Reviewed-by: Mike Reed Commit-Queue: Florin Malita --- src/core/SkColorFilter.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/core/SkColorFilter.cpp b/src/core/SkColorFilter.cpp index d8e68c8db5..454fdb267c 100644 --- a/src/core/SkColorFilter.cpp +++ b/src/core/SkColorFilter.cpp @@ -277,14 +277,18 @@ void SkSRGBGammaColorFilter::toString(SkString* str) const { } #endif +template +sk_sp MakeSRGBGammaCF() { + static SkColorFilter* gSingleton = new SkSRGBGammaColorFilter(dir); + return sk_ref_sp(gSingleton); +} + sk_sp SkColorFilter::MakeLinearToSRGBGamma() { - return sk_sp(new SkSRGBGammaColorFilter( - SkSRGBGammaColorFilter::Direction::kLinearToSRGB)); + return MakeSRGBGammaCF(); } sk_sp SkColorFilter::MakeSRGBToLinearGamma() { - return sk_sp(new SkSRGBGammaColorFilter( - SkSRGBGammaColorFilter::Direction::kSRGBToLinear)); + return MakeSRGBGammaCF(); } /////////////////////////////////////////////////////////////////////////////////////////////////// -- cgit v1.2.3