Stop refcounting SkDeferredCanvas::NotificationClient
authorjunov@chromium.org <junov@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 20 Aug 2012 14:25:04 +0000 (14:25 +0000)
committerjunov@chromium.org <junov@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 20 Aug 2012 14:25:04 +0000 (14:25 +0000)
User code (i.e. WebKit) is now responsible for the lifetime scope of the notification client.
With http://trac.webkit.org/changeset/125804 skia-side ref counting has become unnecessary and undesirable.
Review URL: https://codereview.appspot.com/6443146

git-svn-id: http://skia.googlecode.com/svn/trunk@5169 2bbb7eff-a529-9590-31e7-b0007b416f81

bench/DeferredCanvasBench.cpp
include/utils/SkDeferredCanvas.h
src/utils/SkDeferredCanvas.cpp

index 60873887a5ebd1d24fd9aa3b99a82f00d49b77fb..99c07bfe573ea3458c6a95977647f40210fd47d7 100644 (file)
@@ -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;
 };
 
 
index f5313713eccb06c27f08abba191ce8c93d3ea911..ff3235136d2013f2765a5778d84c4362f688f445 100644 (file)
@@ -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.
index bb33e2217d07bf22745717b2b78220de8a29cf16..661e017bfa96b4c465eeecc0c2b07968bf98a013 100644 (file)
@@ -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() {