From a7d948523dce6044fc02db90726e5f971a93628b Mon Sep 17 00:00:00 2001 From: "reed@google.com" Date: Wed, 30 Mar 2011 21:23:07 +0000 Subject: [PATCH] replace SkRefDict with SkMetaData (much more general) git-svn-id: http://skia.googlecode.com/svn/trunk@1025 2bbb7eff-a529-9590-31e7-b0007b416f81 --- include/core/SkDevice.h | 7 ++++--- src/core/SkDevice.cpp | 18 ++++++++++++++++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/include/core/SkDevice.h b/include/core/SkDevice.h index 03855e8485..8889fb4b24 100644 --- a/include/core/SkDevice.h +++ b/include/core/SkDevice.h @@ -21,13 +21,13 @@ #include "SkBitmap.h" #include "SkCanvas.h" #include "SkColor.h" -#include "SkRefDict.h" class SkClipStack; class SkDevice; class SkDraw; struct SkIRect; class SkMatrix; +class SkMetaData; class SkRegion; /** \class SkDeviceFactory @@ -63,6 +63,7 @@ public: @param bitmap A copy of this bitmap is made and stored in the device */ SkDevice(SkCanvas*, const SkBitmap& bitmap, bool forOffscreen); + virtual ~SkDevice(); virtual SkDeviceFactory* getDeviceFactory() { return SkNEW(SkRasterDeviceFactory); @@ -223,7 +224,7 @@ public: /////////////////////////////////////////////////////////////////////////// - SkRefDict& getRefDict() { return fRefDict; } + SkMetaData& getMetaData(); struct TextFlags { uint32_t fFlags; // SkPaint::getFlags() @@ -261,8 +262,8 @@ private: SkCanvas* fCanvas; SkBitmap fBitmap; - SkRefDict fRefDict; SkIPoint fOrigin; + SkMetaData* fMetaData; }; #endif diff --git a/src/core/SkDevice.cpp b/src/core/SkDevice.cpp index 82318487cc..69d0c1cc34 100644 --- a/src/core/SkDevice.cpp +++ b/src/core/SkDevice.cpp @@ -1,15 +1,16 @@ #include "SkDevice.h" #include "SkDraw.h" +#include "SkMetaData.h" #include "SkRect.h" SkDeviceFactory::~SkDeviceFactory() {} -SkDevice::SkDevice(SkCanvas* canvas) : fCanvas(canvas) { +SkDevice::SkDevice(SkCanvas* canvas) : fCanvas(canvas), fMetaData(NULL) { fOrigin.setZero(); } SkDevice::SkDevice(SkCanvas* canvas, const SkBitmap& bitmap, bool isForLayer) - : fCanvas(canvas), fBitmap(bitmap) { + : fCanvas(canvas), fBitmap(bitmap), fMetaData(NULL) { fOrigin.setZero(); // auto-allocate if we're for offscreen drawing if (isForLayer) { @@ -22,6 +23,19 @@ SkDevice::SkDevice(SkCanvas* canvas, const SkBitmap& bitmap, bool isForLayer) } } +SkDevice::~SkDevice() { + delete fMetaData; +} + +SkMetaData& SkDevice::getMetaData() { + // metadata users are rare, so we lazily allocate it. If that changes we + // can decide to just make it a field in the device (rather than a ptr) + if (NULL == fMetaData) { + fMetaData = new SkMetaData; + } + return *fMetaData; +} + void SkDevice::lockPixels() { fBitmap.lockPixels(); }