From: twiz@google.com Date: Tue, 10 May 2011 23:10:26 +0000 (+0000) Subject: git-svn-id: http://skia.googlecode.com/svn/trunk@1292 2bbb7eff-a529-9590-31e7-b0007b4... X-Git-Tag: submit/tizen/20180928.044319~18514 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=246bd0f2718fb17f18bd3fd4bc5e99fdd0560a82;p=platform%2Fupstream%2FlibSkiaSharp.git git-svn-id: skia.googlecode.com/svn/trunk@1292 2bbb7eff-a529-9590-31e7-b0007b416f81 --- diff --git a/include/core/SkDevice.h b/include/core/SkDevice.h index d9a4fde4c2..46bcf1a105 100644 --- a/include/core/SkDevice.h +++ b/include/core/SkDevice.h @@ -155,6 +155,31 @@ public: virtual void setMatrixClip(const SkMatrix&, const SkRegion&, const SkClipStack&); + /** + * Observer interface for listening to the calls to + * SkDevice::setMatrixClip(...). Users of SkDevice instances should + * implement matrixClipChanged(...) to receive notifications. + */ + class SkMatrixClipObserver : public SkRefCnt { + public: + virtual void matrixClipChanged(const SkMatrix&, const SkRegion&, + const SkClipStack&) = 0; + }; + + /** Assign the clip observer. Note that an extra reference is added to the + * observer, and removed at SkDevice construction, or re-assignment of a + * different observer. + */ + void setMatrixClipObserver(SkMatrixClipObserver* observer); + + /** Return the device's associated SkMatrixClipObserver, or NULL. + * If non-null is returned, the reference count of the object is not + * modified. + */ + SkMatrixClipObserver* getMatrixClipObserver() const { + return fMatrixClipObserver; + } + /** Called when this device gains focus (i.e becomes the current device for drawing). */ @@ -281,6 +306,8 @@ private: SkIPoint fOrigin; SkMetaData* fMetaData; + SkMatrixClipObserver* fMatrixClipObserver; + SkDeviceFactory* fCachedDeviceFactory; }; diff --git a/src/core/SkDevice.cpp b/src/core/SkDevice.cpp index 850a53fd16..4a7693673f 100644 --- a/src/core/SkDevice.cpp +++ b/src/core/SkDevice.cpp @@ -25,13 +25,13 @@ SkDeviceFactory::~SkDeviceFactory() { /////////////////////////////////////////////////////////////////////////////// -SkDevice::SkDevice(SkCanvas* canvas) : fCanvas(canvas), fMetaData(NULL) { +SkDevice::SkDevice(SkCanvas* canvas) : fCanvas(canvas), fMetaData(NULL), fMatrixClipObserver(NULL) { fOrigin.setZero(); fCachedDeviceFactory = NULL; } SkDevice::SkDevice(SkCanvas* canvas, const SkBitmap& bitmap, bool isForLayer) - : fCanvas(canvas), fBitmap(bitmap), fMetaData(NULL) { + : fCanvas(canvas), fBitmap(bitmap), fMetaData(NULL), fMatrixClipObserver(NULL) { fOrigin.setZero(); // auto-allocate if we're for offscreen drawing if (isForLayer) { @@ -48,6 +48,7 @@ SkDevice::SkDevice(SkCanvas* canvas, const SkBitmap& bitmap, bool isForLayer) SkDevice::~SkDevice() { delete fMetaData; SkSafeUnref(fCachedDeviceFactory); + SkSafeUnref(fMatrixClipObserver); } SkDeviceFactory* SkDevice::onNewDeviceFactory() { @@ -105,8 +106,16 @@ void SkDevice::clear(SkColor color) { void SkDevice::onAccessBitmap(SkBitmap* bitmap) {} -void SkDevice::setMatrixClip(const SkMatrix&, const SkRegion&, - const SkClipStack&) {} +void SkDevice::setMatrixClip(const SkMatrix& matrix, const SkRegion& region, + const SkClipStack& clipStack) { + if (fMatrixClipObserver) { + fMatrixClipObserver->matrixClipChanged(matrix, region, clipStack); + } +} + +void SkDevice::setMatrixClipObserver(SkMatrixClipObserver* observer) { + SkRefCnt_SafeAssign(fMatrixClipObserver, observer); +} ///////////////////////////////////////////////////////////////////////////////