From 57fa241d6f43557e4243a46f8b5a4ed447ccb8d2 Mon Sep 17 00:00:00 2001 From: reed Date: Thu, 7 Jan 2016 17:56:33 -0800 Subject: [PATCH] don't leak test filters and shaders BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1568173002 TBR= Review URL: https://codereview.chromium.org/1568173002 --- gm/colorfilterimagefilter.cpp | 38 +++++++++++++++++------------------ 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/gm/colorfilterimagefilter.cpp b/gm/colorfilterimagefilter.cpp index 711a7e48c3..49e568b130 100644 --- a/gm/colorfilterimagefilter.cpp +++ b/gm/colorfilterimagefilter.cpp @@ -42,15 +42,10 @@ static SkColorFilter* cf_make_colorize(SkColor color) { return SkColorFilter::CreateModeFilter(color, SkXfermode::kSrc_Mode); } -static const SkTDArray& sk_gm_get_colorfilters() { - static SkTDArray gColorFilters; - - if (gColorFilters.count() == 0) { - *gColorFilters.append() = cf_make_brightness(0.5f); - *gColorFilters.append() = cf_make_grayscale(); - *gColorFilters.append() = cf_make_colorize(SK_ColorBLUE); - } - return gColorFilters; +static void sk_gm_get_colorfilters(SkTDArray* array) { + *array->append() = cf_make_brightness(0.5f); + *array->append() = cf_make_grayscale(); + *array->append() = cf_make_colorize(SK_ColorBLUE); } /////////////////////////////////////////////////////////////////////////////////////////////////// @@ -75,15 +70,10 @@ static SkShader* sh_make_image() { return image->newShader(SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode); } -static const SkTDArray& sk_gm_get_shaders() { - static SkTDArray gShaders; - - if (gShaders.count() == 0) { - *gShaders.append() = sh_make_lineargradient0(); - *gShaders.append() = sh_make_lineargradient1(); - *gShaders.append() = sh_make_image(); - } - return gShaders; +static void sk_gm_get_shaders(SkTDArray* array) { + *array->append() = sh_make_lineargradient0(); + *array->append() = sh_make_lineargradient1(); + *array->append() = sh_make_image(); } /////////////////////////////////////////////////////////////////////////////////////////////////// @@ -190,9 +180,17 @@ DEF_SIMPLE_GM(colorfilterimagefilter_layer, canvas, 32, 32) { /////////////////////////////////////////////////////////////////////////////////////////////////// +template class SkTRefArray : public SkTDArray { +public: + ~SkTRefArray() { this->unrefAll(); } +}; + DEF_SIMPLE_GM(colorfiltershader, canvas, 800, 800) { - const SkTDArray& filters = sk_gm_get_colorfilters(); - const SkTDArray& shaders = sk_gm_get_shaders(); + SkTRefArray filters; + sk_gm_get_colorfilters(&filters); + + SkTRefArray shaders; + sk_gm_get_shaders(&shaders); SkPaint paint; SkRect r = SkRect::MakeWH(120, 120);