The TileCache object should be deallocated on the main thread
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 16 Feb 2012 00:01:55 +0000 (00:01 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 16 Feb 2012 00:01:55 +0000 (00:01 +0000)
https://bugs.webkit.org/show_bug.cgi?id=78757
<rdar://problem/10866161>

Reviewed by Sam Weinig.

Since the WebTileCacheLayer can be deleted on the scrolling thread, we need to make sure that the underlying
TileCache object is actually destroyed on the main thread.

* platform/graphics/ca/mac/TileCache.h:
* platform/graphics/ca/mac/TileCache.mm:
(WebCore::TileCache::~TileCache):
Assert that this object is being destroyed on the main thread.

* platform/graphics/ca/mac/WebTileCacheLayer.mm:
(-[WebTileCacheLayer dealloc]):
If dealloc is being called from a non-main thread, make sure to delete the tile cache object on the main thread.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@107852 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/ca/mac/TileCache.h
Source/WebCore/platform/graphics/ca/mac/TileCache.mm
Source/WebCore/platform/graphics/ca/mac/WebTileCacheLayer.mm

index dc63af6..fbf33c2 100644 (file)
@@ -1,5 +1,25 @@
 2012-02-15  Anders Carlsson  <andersca@apple.com>
 
+        The TileCache object should be deallocated on the main thread
+        https://bugs.webkit.org/show_bug.cgi?id=78757
+        <rdar://problem/10866161>
+
+        Reviewed by Sam Weinig.
+
+        Since the WebTileCacheLayer can be deleted on the scrolling thread, we need to make sure that the underlying
+        TileCache object is actually destroyed on the main thread.
+
+        * platform/graphics/ca/mac/TileCache.h:
+        * platform/graphics/ca/mac/TileCache.mm:
+        (WebCore::TileCache::~TileCache):
+        Assert that this object is being destroyed on the main thread.
+
+        * platform/graphics/ca/mac/WebTileCacheLayer.mm:
+        (-[WebTileCacheLayer dealloc]):
+        If dealloc is being called from a non-main thread, make sure to delete the tile cache object on the main thread.
+
+2012-02-15  Anders Carlsson  <andersca@apple.com>
+
         Scrolling Coordinator must be deleted on the main thread
         https://bugs.webkit.org/show_bug.cgi?id=78756
         <rdar://problem/10866167>
index 77a8800..768b2aa 100644 (file)
@@ -49,6 +49,7 @@ class TileCache {
 
 public:
     static PassOwnPtr<TileCache> create(WebTileCacheLayer*, const IntSize& tileSize);
+    ~TileCache();
 
     void tileCacheLayerBoundsChanged();
 
index cdd8183..dda076b 100644 (file)
@@ -31,6 +31,7 @@
 #import "WebLayer.h"
 #import "WebTileCacheLayer.h"
 #import "WebTileLayer.h"
+#import <wtf/MainThread.h>
 #import <utility>
 
 using namespace std;
@@ -62,6 +63,11 @@ TileCache::TileCache(WebTileCacheLayer* tileCacheLayer, const IntSize& tileSize)
     [CATransaction commit];
 }
 
+TileCache::~TileCache()
+{
+    ASSERT(isMainThread());
+}
+
 void TileCache::tileCacheLayerBoundsChanged()
 {
     if (m_tiles.isEmpty()) {
index c07b5df..d7dc8c9 100644 (file)
@@ -28,6 +28,7 @@
 
 #import "IntRect.h"
 #import "TileCache.h"
+#import <wtf/MainThread.h>
 
 using namespace WebCore;
 
@@ -45,6 +46,18 @@ using namespace WebCore;
     return self;
 }
 
+- (void)dealloc
+{
+    if (!isMainThread()) {
+        TileCache* tileCache = _tileCache.leakPtr();
+        dispatch_async(dispatch_get_main_queue(), ^{
+            delete tileCache;
+        });
+    }
+
+    [super dealloc];
+}
+
 - (void)setBounds:(CGRect)bounds
 {
     [super setBounds:bounds];