Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(41)

Unified Diff: gm/colorfilterimagefilter.cpp

Issue 1568173002: don't leak test filters and shaders (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/colorfilterimagefilter.cpp
diff --git a/gm/colorfilterimagefilter.cpp b/gm/colorfilterimagefilter.cpp
index 711a7e48c337e9cdd5bbd89af8981f9bfc844737..49e568b1305411d2410e9098407229829937b980 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<SkColorFilter*>& sk_gm_get_colorfilters() {
- static SkTDArray<SkColorFilter*> 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<SkColorFilter*>* 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<SkShader*>& sk_gm_get_shaders() {
- static SkTDArray<SkShader*> 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<SkShader*>* 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 <typename T> class SkTRefArray : public SkTDArray<T> {
+public:
+ ~SkTRefArray() { this->unrefAll(); }
+};
+
DEF_SIMPLE_GM(colorfiltershader, canvas, 800, 800) {
- const SkTDArray<SkColorFilter*>& filters = sk_gm_get_colorfilters();
- const SkTDArray<SkShader*>& shaders = sk_gm_get_shaders();
+ SkTRefArray<SkColorFilter*> filters;
+ sk_gm_get_colorfilters(&filters);
+
+ SkTRefArray<SkShader*> shaders;
+ sk_gm_get_shaders(&shaders);
SkPaint paint;
SkRect r = SkRect::MakeWH(120, 120);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698