From 33cdbdea3ddcec9323b65eace86e10557312ae9b Mon Sep 17 00:00:00 2001 From: "bsalomon@google.com" Date: Fri, 11 Jan 2013 20:54:44 +0000 Subject: [PATCH] Fix leaks in blurrect benchs and gm. Review URL: https://codereview.appspot.com/7071060 git-svn-id: http://skia.googlecode.com/svn/trunk@7142 2bbb7eff-a529-9590-31e7-b0007b416f81 --- bench/BlurRectBench.cpp | 10 +++++++++- gm/blurrect.cpp | 28 +++++++++++++++------------- src/effects/SkBlurMask.cpp | 7 +++---- 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/bench/BlurRectBench.cpp b/bench/BlurRectBench.cpp index e9234a8ec..b0b06e65e 100644 --- a/bench/BlurRectBench.cpp +++ b/bench/BlurRectBench.cpp @@ -91,6 +91,7 @@ protected: SkMask mask; SkBlurMask::BlurRect(&mask, r, radius(), SkBlurMask::kNormal_Style, SkBlurMask::kHigh_Quality); + SkMask::FreeImage(mask.fImage); } }; @@ -104,12 +105,18 @@ public: } else { name.printf("blurrect_separable_%d", SkScalarRound(rad)); } - setName(name); + fSrcMask.fImage = NULL; + } + + ~BlurRectSeparableBench() { + SkMask::FreeImage(fSrcMask.fImage); } protected: virtual void preBenchSetup(const SkRect& r) SK_OVERRIDE { + SkMask::FreeImage(fSrcMask.fImage); + r.roundOut(&fSrcMask.fBounds); fSrcMask.fFormat = SkMask::kA8_Format; fSrcMask.fRowBytes = fSrcMask.fBounds.width(); @@ -123,6 +130,7 @@ protected: SkBlurMask::BlurSeparable(&mask, fSrcMask, radius(), SkBlurMask::kNormal_Style, SkBlurMask::kHigh_Quality); + SkMask::FreeImage(mask.fImage); } }; diff --git a/gm/blurrect.cpp b/gm/blurrect.cpp index 88863e604..a06f62aa3 100644 --- a/gm/blurrect.cpp +++ b/gm/blurrect.cpp @@ -140,11 +140,11 @@ class BlurRectCompareGM : public skiagm::GM { unsigned int fRectWidth, fRectHeight; SkScalar fRadius; public: - BlurRectCompareGM(const char name[], unsigned int rectWidth, unsigned int rectHeight, float radius) : - fName(name) - , fRectWidth( rectWidth ) - , fRectHeight( rectHeight ) - , fRadius( radius ) + BlurRectCompareGM(const char name[], unsigned int rectWidth, unsigned int rectHeight, float radius) + : fName(name) + , fRectWidth(rectWidth) + , fRectHeight(rectHeight) + , fRadius(radius) {} int width() const { return fRectWidth; } @@ -160,7 +160,7 @@ protected: return SkISize::Make(640, 480); } - virtual void makeMask( SkMask *m, const SkRect& ) = 0; + virtual void makeMask(SkMask *m, const SkRect&) = 0; virtual void onDraw(SkCanvas* canvas) { SkRect r; @@ -168,7 +168,8 @@ protected: SkMask mask; - makeMask(&mask, r); + this->makeMask(&mask, r); + SkAutoMaskFreeImage amfi(mask.fImage); SkBitmap bm; bm.setConfig(SkBitmap::kA8_Config, mask.fBounds.width(), mask.fBounds.height()); @@ -186,10 +187,10 @@ class BlurRectFastGM: public BlurRectCompareGM { public: BlurRectFastGM(const char name[], unsigned int rect_width, unsigned int rect_height, float blur_radius) : - BlurRectCompareGM( name, rect_width, rect_height, blur_radius ) {} + BlurRectCompareGM(name, rect_width, rect_height, blur_radius) {} protected: - virtual void makeMask( SkMask *m, const SkRect& r) SK_OVERRIDE { - SkBlurMask::BlurRect( m, r, radius(), SkBlurMask::kNormal_Style, + virtual void makeMask(SkMask *m, const SkRect& r) SK_OVERRIDE { + SkBlurMask::BlurRect(m, r, radius(), SkBlurMask::kNormal_Style, SkBlurMask::kHigh_Quality ); } }; @@ -199,17 +200,18 @@ public: BlurRectSlowGM(const char name[], unsigned int rect_width, unsigned int rect_height, float blur_radius) : BlurRectCompareGM( name, rect_width, rect_height, blur_radius ) {} protected: - virtual void makeMask( SkMask *m, const SkRect& r) SK_OVERRIDE { + virtual void makeMask(SkMask *m, const SkRect& r) SK_OVERRIDE { SkMask src; r.roundOut(&src.fBounds); src.fBounds.offset(-src.fBounds.fLeft, -src.fBounds.fTop); // move to origin src.fFormat = SkMask::kA8_Format; src.fRowBytes = src.fBounds.width(); src.fImage = SkMask::AllocImage( src.computeTotalImageSize() ); + SkAutoMaskFreeImage amfi(src.fImage); - memset( src.fImage, 0xff, src.computeTotalImageSize() ); + memset(src.fImage, 0xff, src.computeTotalImageSize()); - SkBlurMask::BlurSeparable( m, src, radius()/2, SkBlurMask::kNormal_Style, SkBlurMask::kHigh_Quality ); + SkBlurMask::BlurSeparable(m, src, radius()/2, SkBlurMask::kNormal_Style, SkBlurMask::kHigh_Quality); } }; diff --git a/src/effects/SkBlurMask.cpp b/src/effects/SkBlurMask.cpp index a44f439e6..99bf2d500 100644 --- a/src/effects/SkBlurMask.cpp +++ b/src/effects/SkBlurMask.cpp @@ -852,7 +852,7 @@ static void clamp_with_orig(uint8_t dst[], int dstRowBytes, /////////////////////////////////////////////////////////////////////////////// -// we use a local funciton to wrap the class static method to work around +// we use a local function to wrap the class static method to work around // a bug in gcc98 void SkMask_FreeImage(uint8_t* image); void SkMask_FreeImage(uint8_t* image) { @@ -1086,7 +1086,7 @@ static int compute_profile( SkScalar radius, unsigned int **profile_out ) { int size = SkScalarFloorToInt(radius * 3 + 1); int center = size >> 1; - unsigned int *profile = new unsigned int [size]; + unsigned int *profile = SkNEW_ARRAY(unsigned int, size); float invr = 1.0f/radius; @@ -1118,6 +1118,7 @@ bool SkBlurMask::BlurRect(SkMask *dst, const SkRect &src, float radius = SkScalarToFloat( SkScalarMul( provided_radius, kBlurRadiusFudgeFactor ) ); profile_size = compute_profile( radius, &profile ); + SkAutoTDeleteArray ada(profile); int pad = (int) (radius * 1.5f + 1); if (margin) { @@ -1142,8 +1143,6 @@ bool SkBlurMask::BlurRect(SkMask *dst, const SkRect &src, dst->fImage = dp; - SkAutoTCallVProc autoCall(dp); - int dst_height = dst->fBounds.height(); int dst_width = dst->fBounds.width();