Title: [281661] trunk/Source/WebKit
Revision
281661
Author
[email protected]
Date
2021-08-26 15:07:30 -0700 (Thu, 26 Aug 2021)

Log Message

Manually release SharedBitmap if CGBitmapContextCreateWithData fails and doesn't do it
https://bugs.webkit.org/show_bug.cgi?id=229428
<rdar://problem/82264138>

Reviewed by Darin Adler.

* Shared/ShareableBitmap.h:
* Shared/cg/ShareableBitmapCG.cpp:
(WebKit::ShareableBitmap::createGraphicsContext):
(WebKit::ShareableBitmap::releaseBitmapContextData):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (281660 => 281661)


--- trunk/Source/WebKit/ChangeLog	2021-08-26 22:07:13 UTC (rev 281660)
+++ trunk/Source/WebKit/ChangeLog	2021-08-26 22:07:30 UTC (rev 281661)
@@ -1,3 +1,16 @@
+2021-08-26  Cameron McCormack  <[email protected]>
+
+        Manually release SharedBitmap if CGBitmapContextCreateWithData fails and doesn't do it
+        https://bugs.webkit.org/show_bug.cgi?id=229428
+        <rdar://problem/82264138>
+
+        Reviewed by Darin Adler.
+
+        * Shared/ShareableBitmap.h:
+        * Shared/cg/ShareableBitmapCG.cpp:
+        (WebKit::ShareableBitmap::createGraphicsContext):
+        (WebKit::ShareableBitmap::releaseBitmapContextData):
+
 2021-08-26  Aditya Keerthi  <[email protected]>
 
         [iOS] Photo picker appears at incorrect locations when opened using a trackpad

Modified: trunk/Source/WebKit/Shared/ShareableBitmap.h (281660 => 281661)


--- trunk/Source/WebKit/Shared/ShareableBitmap.h	2021-08-26 22:07:13 UTC (rev 281660)
+++ trunk/Source/WebKit/Shared/ShareableBitmap.h	2021-08-26 22:07:30 UTC (rev 281661)
@@ -176,6 +176,10 @@
     COMPtr<ID2D1Bitmap> m_bitmap;
 #endif
 
+#if USE(CG)
+    bool m_releaseBitmapContextDataCalled { false };
+#endif
+
     // If the shareable bitmap is backed by shared memory, this points to the shared memory object.
     RefPtr<SharedMemory> m_sharedMemory;
 

Modified: trunk/Source/WebKit/Shared/cg/ShareableBitmapCG.cpp (281660 => 281661)


--- trunk/Source/WebKit/Shared/cg/ShareableBitmapCG.cpp	2021-08-26 22:07:13 UTC (rev 281660)
+++ trunk/Source/WebKit/Shared/cg/ShareableBitmapCG.cpp	2021-08-26 22:07:30 UTC (rev 281661)
@@ -97,12 +97,21 @@
     if (bytesPerRow.hasOverflowed())
         return nullptr;
 
+    ref(); // Balanced by deref in releaseBitmapContextData.
+
+    m_releaseBitmapContextDataCalled = false;
     RetainPtr<CGContextRef> bitmapContext = adoptCF(CGBitmapContextCreateWithData(data(), m_size.width(), m_size.height(), bitsPerComponent, bytesPerRow, colorSpace(m_configuration), bitmapInfo(m_configuration), releaseBitmapContextData, this));
-    if (!bitmapContext)
+    if (!bitmapContext) {
+        // When CGBitmapContextCreateWithData fails and returns null, it will only
+        // call the release callback in some circumstances <rdar://82228446>. We
+        // work around this by recording whether it was called, and calling it
+        // ourselves if needed.
+        if (!m_releaseBitmapContextDataCalled)
+            releaseBitmapContextData(this, this->data());
         return nullptr;
+    }
+    ASSERT(!m_releaseBitmapContextDataCalled);
 
-    ref(); // Balanced by deref in releaseBitmapContextData.
-
     // We want the origin to be in the top left corner so we flip the backing store context.
     CGContextTranslateCTM(bitmapContext.get(), 0, m_size.height());
     CGContextScaleCTM(bitmapContext.get(), 1, -1);
@@ -171,6 +180,7 @@
 {
     ShareableBitmap* bitmap = static_cast<ShareableBitmap*>(typelessBitmap);
     ASSERT_UNUSED(typelessData, bitmap->data() == typelessData);
+    bitmap->m_releaseBitmapContextDataCalled = true;
     bitmap->deref(); // Balanced by ref in createGraphicsContext.
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to