Title: [283773] branches/safari-612-branch/Source/WebKit
Revision
283773
Author
repst...@apple.com
Date
2021-10-07 19:01:42 -0700 (Thu, 07 Oct 2021)

Log Message

Cherry-pick r281661. rdar://problem/83955525

    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):

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

Modified Paths

Diff

Modified: branches/safari-612-branch/Source/WebKit/ChangeLog (283772 => 283773)


--- branches/safari-612-branch/Source/WebKit/ChangeLog	2021-10-08 02:01:40 UTC (rev 283772)
+++ branches/safari-612-branch/Source/WebKit/ChangeLog	2021-10-08 02:01:42 UTC (rev 283773)
@@ -1,5 +1,36 @@
 2021-10-07  Alan Coon  <alanc...@apple.com>
 
+        Cherry-pick r281661. rdar://problem/83955525
+
+    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):
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@281661 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2021-08-26  Cameron McCormack  <hey...@apple.com>
+
+            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-10-07  Alan Coon  <alanc...@apple.com>
+
         Cherry-pick r281480. rdar://problem/83957360
 
     PCM: Support ephemeral measurement with non-persistent WebCore::PrivateClickMeasurement

Modified: branches/safari-612-branch/Source/WebKit/Shared/ShareableBitmap.h (283772 => 283773)


--- branches/safari-612-branch/Source/WebKit/Shared/ShareableBitmap.h	2021-10-08 02:01:40 UTC (rev 283772)
+++ branches/safari-612-branch/Source/WebKit/Shared/ShareableBitmap.h	2021-10-08 02:01:42 UTC (rev 283773)
@@ -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: branches/safari-612-branch/Source/WebKit/Shared/cg/ShareableBitmapCG.cpp (283772 => 283773)


--- branches/safari-612-branch/Source/WebKit/Shared/cg/ShareableBitmapCG.cpp	2021-10-08 02:01:40 UTC (rev 283772)
+++ branches/safari-612-branch/Source/WebKit/Shared/cg/ShareableBitmapCG.cpp	2021-10-08 02:01:42 UTC (rev 283773)
@@ -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
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to