From d7dbd423f2188eeecb6b18e9253c0335ca068e17 Mon Sep 17 00:00:00 2001 From: "scroggo@google.com" Date: Tue, 3 Jul 2012 15:16:30 +0000 Subject: [PATCH] Ensure that SkDeferredCanvas::onCreateCompatibleDevice unrefs its temp device. Also update my GM to use createCompatibleDevice. Review URL: https://codereview.appspot.com/6357061 git-svn-id: http://skia.googlecode.com/svn/trunk@4450 2bbb7eff-a529-9590-31e7-b0007b416f81 --- gm/extractbitmap.cpp | 8 +++----- src/utils/SkDeferredCanvas.cpp | 6 +++--- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/gm/extractbitmap.cpp b/gm/extractbitmap.cpp index 050d7e7834..68f6d44e24 100644 --- a/gm/extractbitmap.cpp +++ b/gm/extractbitmap.cpp @@ -72,13 +72,11 @@ protected: canvas->translate(0, SkIntToScalar(bitmap.height() + 20)); canvas->drawBitmap(subset, 0, 0); } -/* + // Now do the same but with a device bitmap as source image - SkRefPtr primaryDevice(canvas->getDevice()); - SkRefPtr secondDevice(canvas->createCompatibleDevice( + SkAutoTUnref secondDevice(canvas->createCompatibleDevice( SkBitmap::kARGB_8888_Config, bitmap.width(), bitmap.height(), true)); - secondDevice->unref(); SkCanvas secondCanvas(secondDevice.get()); secondCanvas.writePixels(bitmap, 0, 0); @@ -91,7 +89,7 @@ protected: canvas->drawBitmap(deviceBitmap, 0, 0); canvas->drawBitmap(deviceSubset, 0, 0); -*/ + } private: diff --git a/src/utils/SkDeferredCanvas.cpp b/src/utils/SkDeferredCanvas.cpp index 096120a962..9afd580b9f 100644 --- a/src/utils/SkDeferredCanvas.cpp +++ b/src/utils/SkDeferredCanvas.cpp @@ -589,9 +589,9 @@ SkDevice* SkDeferredCanvas::DeferredDevice::onCreateCompatibleDevice( // Save layer usage not supported, and not required by SkDeferredCanvas. SkASSERT(usage != kSaveLayer_Usage); // Create a compatible non-deferred device. - SkDevice* compatibleDevice = - fImmediateDevice->createCompatibleDevice(config, width, height, - isOpaque); + SkAutoTUnref compatibleDevice + (fImmediateDevice->createCompatibleDevice(config, width, height, + isOpaque)); return SkNEW_ARGS(DeferredDevice, (compatibleDevice, fDeviceContext)); }