aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar bungeman@google.com <bungeman@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-10-04 21:25:00 +0000
committerGravatar bungeman@google.com <bungeman@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-10-04 21:25:00 +0000
commit02f55841854ae32f21a13417e9ee711463e488cf (patch)
treefab3bae2934075a02cc8ddd801b7b1ff8e648f4e
parenta30bc82a2e7163235b01a6b2ecbd4e2c0906c0b8 (diff)
Change SkAutoMaskImage so that we're less likely to write leaky code.
-rw-r--r--include/core/SkMaskFilter.h11
-rw-r--r--src/core/SkBitmap.cpp7
-rw-r--r--src/core/SkDraw.cpp2
-rw-r--r--src/core/SkMaskFilter.cpp5
-rw-r--r--src/gpu/SkGpuDevice.cpp5
5 files changed, 12 insertions, 18 deletions
diff --git a/include/core/SkMaskFilter.h b/include/core/SkMaskFilter.h
index b32f4d3926..0f1321e086 100644
--- a/include/core/SkMaskFilter.h
+++ b/include/core/SkMaskFilter.h
@@ -97,16 +97,13 @@ protected:
Stack class used to manage the fImage buffer in a SkMask.
When this object loses scope, the buffer is freed with SkMask::FreeImage().
*/
-class SkAutoMaskImage {
+class SkAutoMaskFreeImage {
public:
- SkAutoMaskImage(SkMask* mask, bool alloc) {
- if (alloc) {
- mask->fImage = SkMask::AllocImage(mask->computeImageSize());
- }
- fImage = mask->fImage;
+ SkAutoMaskFreeImage(uint8_t* maskImage) {
+ fImage = maskImage;
}
- ~SkAutoMaskImage() {
+ ~SkAutoMaskFreeImage() {
SkMask::FreeImage(fImage);
}
private:
diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp
index 581047ee4a..6e4639f285 100644
--- a/src/core/SkBitmap.cpp
+++ b/src/core/SkBitmap.cpp
@@ -1326,15 +1326,14 @@ bool SkBitmap::extractAlpha(SkBitmap* dst, const SkPaint* paint,
tmpBitmap.swap(*dst);
return true;
}
-
- SkAutoMaskImage srcCleanup(&srcM, true);
+ srcM.fImage = SkMask::AllocImage(srcM.computeImageSize());
+ SkAutoMaskFreeImage srcCleanup(srcM.fImage);
GetBitmapAlpha(*this, srcM.fImage, srcM.fRowBytes);
if (!filter->filterMask(&dstM, srcM, identity, NULL)) {
goto NO_FILTER_CASE;
}
-
- SkAutoMaskImage dstCleanup(&dstM, false);
+ SkAutoMaskFreeImage dstCleanup(dstM.fImage);
tmpBitmap.setConfig(SkBitmap::kA8_Config, dstM.fBounds.width(),
dstM.fBounds.height(), dstM.fRowBytes);
diff --git a/src/core/SkDraw.cpp b/src/core/SkDraw.cpp
index 1bfac70283..ed21f65164 100644
--- a/src/core/SkDraw.cpp
+++ b/src/core/SkDraw.cpp
@@ -791,7 +791,7 @@ void SkDraw::drawDevMask(const SkMask& srcM, const SkPaint& paint) const {
} else {
dstM.fImage = NULL;
}
- SkAutoMaskImage ami(&dstM, false);
+ SkAutoMaskFreeImage ami(dstM.fImage);
if (fBounder && !fBounder->doIRect(mask->fBounds)) {
return;
diff --git a/src/core/SkMaskFilter.cpp b/src/core/SkMaskFilter.cpp
index 334de5e69a..980c3503b6 100644
--- a/src/core/SkMaskFilter.cpp
+++ b/src/core/SkMaskFilter.cpp
@@ -28,14 +28,13 @@ bool SkMaskFilter::filterPath(const SkPath& devPath, const SkMatrix& matrix,
SkMask::kComputeBoundsAndRenderImage_CreateMode)) {
return false;
}
-
- SkAutoMaskImage autoSrc(&srcM, false);
+ SkAutoMaskFreeImage autoSrc(srcM.fImage);
if (!this->filterMask(&dstM, srcM, matrix, NULL)) {
return false;
}
+ SkAutoMaskFreeImage autoDst(dstM.fImage);
- SkAutoMaskImage autoDst(&dstM, false);
SkRegion::Cliperator clipper(clip, dstM.fBounds);
if (!clipper.done() && (bounder == NULL || bounder->doIRect(dstM.fBounds))) {
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index 8dadc0b0bc..9923c8c7b4 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -926,14 +926,13 @@ static bool drawWithMaskFilter(GrContext* context, const SkPath& path,
SkMask::kComputeBoundsAndRenderImage_CreateMode)) {
return false;
}
-
- SkAutoMaskImage autoSrc(&srcM, false);
+ SkAutoMaskFreeImage autoSrc(srcM.fImage);
if (!filter->filterMask(&dstM, srcM, matrix, NULL)) {
return false;
}
// this will free-up dstM when we're done (allocated in filterMask())
- SkAutoMaskImage autoDst(&dstM, false);
+ SkAutoMaskFreeImage autoDst(dstM.fImage);
if (clip.quickReject(dstM.fBounds)) {
return false;