Title: [111143] trunk/Source/WebCore
Revision
111143
Author
[email protected]
Date
2012-03-18 17:39:44 -0700 (Sun, 18 Mar 2012)

Log Message

WebCore::BitmapImage::getCGImageRef should not be used off the main thread.
https://bugs.webkit.org/show_bug.cgi?id=81441

Reviewed by Anders Carlsson.

Covered by existing tests.

* loader/cache/MemoryCache.cpp:
(WebCore::memoryCache):
(WebCore::MemoryCache::add):
(WebCore::MemoryCache::revalidationFailed):
(WebCore::MemoryCache::resourceForURL):
(WebCore::MemoryCache::evict):
Add back main thread assertions.

* platform/graphics/cg/PatternCG.cpp:
(PatternCallbackData):
(WebCore::patternCallback):
(WebCore::patternReleaseOnMainThreadCallback):
(WebCore::Pattern::createPlatformPattern):
Instead of pulling out the CGImageRef in the pattern callback, do it upfront.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (111142 => 111143)


--- trunk/Source/WebCore/ChangeLog	2012-03-19 00:23:00 UTC (rev 111142)
+++ trunk/Source/WebCore/ChangeLog	2012-03-19 00:39:44 UTC (rev 111143)
@@ -1,3 +1,27 @@
+2012-03-18  Sam Weinig  <[email protected]>
+
+        WebCore::BitmapImage::getCGImageRef should not be used off the main thread.
+        https://bugs.webkit.org/show_bug.cgi?id=81441
+
+        Reviewed by Anders Carlsson.
+
+        Covered by existing tests.
+
+        * loader/cache/MemoryCache.cpp:
+        (WebCore::memoryCache):
+        (WebCore::MemoryCache::add):
+        (WebCore::MemoryCache::revalidationFailed):
+        (WebCore::MemoryCache::resourceForURL):
+        (WebCore::MemoryCache::evict):
+        Add back main thread assertions.
+
+        * platform/graphics/cg/PatternCG.cpp:
+        (PatternCallbackData):
+        (WebCore::patternCallback):
+        (WebCore::patternReleaseOnMainThreadCallback):
+        (WebCore::Pattern::createPlatformPattern):
+        Instead of pulling out the CGImageRef in the pattern callback, do it upfront.
+
 2012-03-18  Alexander Færøy  <[email protected]>
 
         [Qt] Don't prepare SQL statements when the database is not open

Modified: trunk/Source/WebCore/loader/cache/MemoryCache.cpp (111142 => 111143)


--- trunk/Source/WebCore/loader/cache/MemoryCache.cpp	2012-03-19 00:23:00 UTC (rev 111142)
+++ trunk/Source/WebCore/loader/cache/MemoryCache.cpp	2012-03-19 00:39:44 UTC (rev 111143)
@@ -58,9 +58,8 @@
 MemoryCache* memoryCache()
 {
     static MemoryCache* staticCache = new MemoryCache;
-#if PLATFORM(CHROMIUM)
     ASSERT(WTF::isMainThread());
-#endif
+
     return staticCache;
 }
 
@@ -95,10 +94,9 @@
 {
     if (disabled())
         return false;
-#if PLATFORM(CHROMIUM)
+
     ASSERT(WTF::isMainThread());
-#endif
-    
+
     m_resources.set(resource->url(), resource);
     resource->setInCache(true);
     
@@ -142,9 +140,7 @@
 
 void MemoryCache::revalidationFailed(CachedResource* revalidatingResource)
 {
-#if PLATFORM(CHROMIUM)
     ASSERT(WTF::isMainThread());
-#endif
     LOG(ResourceLoading, "Revalidation failed for %p", revalidatingResource);
     ASSERT(revalidatingResource->resourceToRevalidate());
     revalidatingResource->clearResourceToRevalidate();
@@ -152,9 +148,7 @@
 
 CachedResource* MemoryCache::resourceForURL(const KURL& resourceURL)
 {
-#if PLATFORM(CHROMIUM)
     ASSERT(WTF::isMainThread());
-#endif
     KURL url = ""
     CachedResource* resource = m_resources.get(url);
     bool wasPurgeable = MemoryCache::shouldMakeResourcePurgeableOnEviction() && resource && resource->isPurgeable();
@@ -385,9 +379,7 @@
 
 void MemoryCache::evict(CachedResource* resource)
 {
-#if PLATFORM(CHROMIUM)
     ASSERT(WTF::isMainThread());
-#endif
     LOG(ResourceLoading, "Evicting resource %p for '%s' from cache", resource, resource->url().string().latin1().data());
     // The resource may have already been removed by someone other than our caller,
     // who needed a fresh copy for a reload. See <http://bugs.webkit.org/show_bug.cgi?id=12479#c6>.

Modified: trunk/Source/WebCore/platform/graphics/cg/PatternCG.cpp (111142 => 111143)


--- trunk/Source/WebCore/platform/graphics/cg/PatternCG.cpp	2012-03-19 00:23:00 UTC (rev 111142)
+++ trunk/Source/WebCore/platform/graphics/cg/PatternCG.cpp	2012-03-19 00:39:44 UTC (rev 111143)
@@ -44,7 +44,7 @@
 
 static void patternCallback(void* info, CGContextRef context)
 {
-    CGImageRef platformImage = static_cast<Image*>(info)->getCGImageRef();
+    CGImageRef platformImage = static_cast<CGImageRef>(info);
     if (!platformImage)
         return;
 
@@ -55,7 +55,7 @@
 
 static void patternReleaseOnMainThreadCallback(void* info)
 {
-    static_cast<Image*>(info)->deref();
+    CGImageRelease(static_cast<CGImageRef>(info));
 }
 
 static void patternReleaseCallback(void* info)
@@ -84,12 +84,11 @@
     CGFloat xStep = m_repeatX ? tileRect.width() : (1 << 22);
     CGFloat yStep = m_repeatY ? tileRect.height() : (1 << 22);
 
-    // The pattern will release the tile when it's done rendering in patternReleaseCallback
-    tileImage()->ref();
+    // The pattern will release the CGImageRef when it's done rendering in patternReleaseCallback
+    CGImageRef platformImage = CGImageRetain(tileImage()->getCGImageRef());
 
     const CGPatternCallbacks patternCallbacks = { 0, patternCallback, patternReleaseCallback };
-    return CGPatternCreate(tileImage(), tileRect, patternTransform, xStep, yStep,
-        kCGPatternTilingConstantSpacing, TRUE, &patternCallbacks);
+    return CGPatternCreate(platformImage, tileRect, patternTransform, xStep, yStep, kCGPatternTilingConstantSpacing, TRUE, &patternCallbacks);
 }
 
 }
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to