diff options
-rw-r--r-- | bench/DeferredCanvasBench.cpp | 4 | ||||
-rw-r--r-- | include/utils/SkDeferredCanvas.h | 11 | ||||
-rw-r--r-- | src/utils/SkDeferredCanvas.cpp | 6 |
3 files changed, 10 insertions, 11 deletions
diff --git a/bench/DeferredCanvasBench.cpp b/bench/DeferredCanvasBench.cpp index 60873887a5..99c07bfe57 100644 --- a/bench/DeferredCanvasBench.cpp +++ b/bench/DeferredCanvasBench.cpp @@ -76,7 +76,7 @@ public: protected: virtual void initDeferredCanvas(SkDeferredCanvas& canvas) SK_OVERRIDE { - canvas.setNotificationClient(SkNEW(SimpleNotificationClient))->unref(); + canvas.setNotificationClient(&fNotificationClient); } virtual void drawInDeferredCanvas(SkDeferredCanvas& canvas) SK_OVERRIDE { @@ -93,10 +93,12 @@ protected: virtual void finalizeDeferredCanvas(SkDeferredCanvas& canvas) SK_OVERRIDE { canvas.clear(0x0); + canvas.setNotificationClient(NULL); } private: typedef DeferredCanvasBench INHERITED; + SimpleNotificationClient fNotificationClient; }; diff --git a/include/utils/SkDeferredCanvas.h b/include/utils/SkDeferredCanvas.h index f5313713ec..ff3235136d 100644 --- a/include/utils/SkDeferredCanvas.h +++ b/include/utils/SkDeferredCanvas.h @@ -48,8 +48,11 @@ public: /** * Specify a NotificationClient to be used by this canvas. Calling * setNotificationClient will release the previously set - * NotificationClient, if any. Takes a reference on the notification - * client. + * NotificationClient, if any. SkDeferredCanvas does not take ownership + * of the notification client. Therefore user code is resposible + * for its destruction. The notification client must be unregistered + * by calling setNotificationClient(NULL) if it is destroyed before + * this canvas. * Note: Must be called after the device is set with setDevice. * * @param notificationClient interface for dispatching notifications @@ -167,10 +170,8 @@ public: virtual SkDrawFilter* setDrawFilter(SkDrawFilter* filter) SK_OVERRIDE; public: - class NotificationClient : public SkRefCnt { + class NotificationClient { public: - SK_DECLARE_INST_COUNT(NotificationClient) - /** * Called before executing one or several draw commands, which means * once per flush when deferred rendering is enabled. diff --git a/src/utils/SkDeferredCanvas.cpp b/src/utils/SkDeferredCanvas.cpp index bb33e2217d..661e017bfa 100644 --- a/src/utils/SkDeferredCanvas.cpp +++ b/src/utils/SkDeferredCanvas.cpp @@ -16,8 +16,6 @@ #include "SkPaint.h" #include "SkShader.h" -SK_DEFINE_INST_COUNT(SkDeferredCanvas::NotificationClient) - enum { // Deferred canvas will auto-flush when recording reaches this limit kDefaultMaxRecordingStorageBytes = 64*1024*1024, @@ -354,7 +352,6 @@ DeferredDevice::DeferredDevice( fMaxRecordingStorageBytes = kDefaultMaxRecordingStorageBytes; fNotificationClient = notificationClient; - SkSafeRef(fNotificationClient); fImmediateDevice = immediateDevice; // ref counted via fImmediateCanvas fImmediateCanvas = SkNEW_ARGS(SkCanvas, (fImmediateDevice)); fPipeController.setPlaybackCanvas(fImmediateCanvas); @@ -364,7 +361,6 @@ DeferredDevice::DeferredDevice( DeferredDevice::~DeferredDevice() { this->flushPending(); SkSafeUnref(fImmediateCanvas); - SkSafeUnref(fNotificationClient); } void DeferredDevice::setMaxRecordingStorage(size_t maxStorage) { @@ -386,7 +382,7 @@ void DeferredDevice::beginRecording() { void DeferredDevice::setNotificationClient( SkDeferredCanvas::NotificationClient* notificationClient) { - SkRefCnt_SafeAssign(fNotificationClient, notificationClient); + fNotificationClient = notificationClient; } void DeferredDevice::contentsCleared() { |