diff options
author | vandebo@chromium.org <vandebo@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2010-10-15 18:58:19 +0000 |
---|---|---|
committer | vandebo@chromium.org <vandebo@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2010-10-15 18:58:19 +0000 |
commit | b70ae310bbdaa1b26786773aabce5548c1f48563 (patch) | |
tree | 917b6924a21ae5c541347da5d8fbd71ebb2000a1 | |
parent | 8d84fac294682647694b0d2d8a87ac2bd19b6aab (diff) |
Fix a memory leak in the new Canvas/Device workflow.
The previous change made it difficult to inherit from SkCanvas without leaking memory. By making SkDeviceFactory not reference counted, the right thing happens more naturally, just NewCanvas : public SkCanvas(new NewDeviceFactory()) {...}
Review URL: http://codereview.appspot.com/2530042
git-svn-id: http://skia.googlecode.com/svn/trunk@605 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | include/core/SkCanvas.h | 4 | ||||
-rw-r--r-- | include/core/SkDevice.h | 2 | ||||
-rw-r--r-- | src/core/SkCanvas.cpp | 5 |
3 files changed, 5 insertions, 6 deletions
diff --git a/include/core/SkCanvas.h b/include/core/SkCanvas.h index 6d995b8b55..b9753c8226 100644 --- a/include/core/SkCanvas.h +++ b/include/core/SkCanvas.h @@ -54,8 +54,8 @@ class SkCanvas : public SkRefCnt { public: /** Construct a canvas with the given device factory. @param factory Specify the factory for generating additional devices. - The factory may be null, in which case SkDeviceFactory - will be used. + The factory may be null, in which case + SkRasterDeviceFactory will be used. */ explicit SkCanvas(SkDeviceFactory* factory = NULL); diff --git a/include/core/SkDevice.h b/include/core/SkDevice.h index b7a9cbcb3a..c223a157a6 100644 --- a/include/core/SkDevice.h +++ b/include/core/SkDevice.h @@ -34,7 +34,7 @@ class SkRegion; to pass into SkCanvas. Doing so will eliminate the need to extend SkCanvas as well. */ -class SkDeviceFactory : public SkRefCnt { +class SkDeviceFactory { public: virtual SkDevice* newDevice(SkBitmap::Config config, int width, int height, bool isOpaque, bool isForLayer) = 0; diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp index 7cda41e7d9..baf5d84016 100644 --- a/src/core/SkCanvas.cpp +++ b/src/core/SkCanvas.cpp @@ -409,7 +409,6 @@ SkCanvas::SkCanvas(SkDeviceFactory* factory) fDeviceFactory(factory) { inc_canvas(); - SkSafeRef(factory); if (!factory) fDeviceFactory = SkNEW(SkRasterDeviceFactory); @@ -439,8 +438,8 @@ SkCanvas::~SkCanvas() { this->internalRestore(); // restore the last, since we're going away SkSafeUnref(fBounder); - SkSafeUnref(fDeviceFactory); - + SkDELETE(fDeviceFactory); + dec_canvas(); } |