Title: [284772] trunk/Source/WebCore
Revision
284772
Author
[email protected]
Date
2021-10-24 23:47:50 -0700 (Sun, 24 Oct 2021)

Log Message

ImageBitmap should report its memory cost
https://bugs.webkit.org/show_bug.cgi?id=187964

Patch by Kimmo Kinnunen <[email protected]> on 2021-10-24
Reviewed by Simon Fraser.

Add memory cost reporting for ImageBitmap. In order to avoid storing a lock, computing the
memory cost many times and querying the thread-unsafe image buffer, compute it only when the
image buffer updates and cache the value.

It is unclear how to test this with current infrastructure.

* html/ImageBitmap.cpp:
(WebCore::ImageBitmap::ImageBitmap):
(WebCore::ImageBitmap::takeImageBitmapBacking):
(WebCore::ImageBitmap::updateMemoryCost):
(WebCore::ImageBitmap::memoryCost const):
* html/ImageBitmap.h:
* html/ImageBitmap.idl:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (284771 => 284772)


--- trunk/Source/WebCore/ChangeLog	2021-10-25 02:48:49 UTC (rev 284771)
+++ trunk/Source/WebCore/ChangeLog	2021-10-25 06:47:50 UTC (rev 284772)
@@ -1,3 +1,24 @@
+2021-10-24  Kimmo Kinnunen  <[email protected]>
+
+        ImageBitmap should report its memory cost
+        https://bugs.webkit.org/show_bug.cgi?id=187964
+
+        Reviewed by Simon Fraser.
+
+        Add memory cost reporting for ImageBitmap. In order to avoid storing a lock, computing the
+        memory cost many times and querying the thread-unsafe image buffer, compute it only when the
+        image buffer updates and cache the value.
+
+        It is unclear how to test this with current infrastructure.
+
+        * html/ImageBitmap.cpp:
+        (WebCore::ImageBitmap::ImageBitmap):
+        (WebCore::ImageBitmap::takeImageBitmapBacking):
+        (WebCore::ImageBitmap::updateMemoryCost):
+        (WebCore::ImageBitmap::memoryCost const):
+        * html/ImageBitmap.h:
+        * html/ImageBitmap.idl:
+
 2021-10-24  Lauro Moura  <[email protected]>
 
         [GLIB] REGRESSION(r284670): Tentative LTS build fix

Modified: trunk/Source/WebCore/html/ImageBitmap.cpp (284771 => 284772)


--- trunk/Source/WebCore/html/ImageBitmap.cpp	2021-10-25 02:48:49 UTC (rev 284771)
+++ trunk/Source/WebCore/html/ImageBitmap.cpp	2021-10-25 06:47:50 UTC (rev 284772)
@@ -846,6 +846,7 @@
     : m_backingStore(WTFMove(backingStore))
 {
     ASSERT_IMPLIES(m_backingStore, m_backingStore->buffer());
+    updateMemoryCost();
 }
 
 ImageBitmap::~ImageBitmap()
@@ -858,7 +859,10 @@
 
 std::optional<ImageBitmapBacking> ImageBitmap::takeImageBitmapBacking()
 {
-    return std::exchange(m_backingStore, std::nullopt);
+    auto result = std::exchange(m_backingStore, std::nullopt);
+    if (result)
+        updateMemoryCost();
+    return result;
 }
 
 RefPtr<ImageBuffer> ImageBitmap::takeImageBuffer()
@@ -869,4 +873,20 @@
     return nullptr;
 }
 
+void ImageBitmap::updateMemoryCost()
+{
+    if (m_backingStore) {
+        if (auto imageBuffer = m_backingStore->buffer()) {
+            m_memoryCost = imageBuffer->memoryCost();
+            return;
+        }
+    }
+    m_memoryCost = 0;
+}
+
+size_t ImageBitmap::memoryCost() const
+{
+    return m_memoryCost;
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/html/ImageBitmap.h (284771 => 284772)


--- trunk/Source/WebCore/html/ImageBitmap.h	2021-10-25 02:48:49 UTC (rev 284771)
+++ trunk/Source/WebCore/html/ImageBitmap.h	2021-10-25 06:47:50 UTC (rev 284772)
@@ -28,6 +28,7 @@
 #include "IDLTypes.h"
 #include "ImageBitmapBacking.h"
 #include "ScriptWrappable.h"
+#include <atomic>
 #include <wtf/RefCounted.h>
 
 namespace JSC {
@@ -108,6 +109,7 @@
 
     static Vector<std::optional<ImageBitmapBacking>> detachBitmaps(Vector<RefPtr<ImageBitmap>>&&);
 
+    size_t memoryCost() const;
 private:
     friend class ImageBitmapImageObserver;
     friend class PendingImageBitmap;
@@ -130,8 +132,10 @@
     static void createPromise(ScriptExecutionContext&, RefPtr<ImageData>&, ImageBitmapOptions&&, std::optional<IntRect>, Promise&&);
     static void createPromise(ScriptExecutionContext&, RefPtr<CSSStyleImageValue>&, ImageBitmapOptions&&, std::optional<IntRect>, Promise&&);
     static void createFromBuffer(ScriptExecutionContext&, Ref<ArrayBuffer>&&, String mimeType, long long expectedContentLength, const URL&, ImageBitmapOptions&&, std::optional<IntRect>, Promise&&);
+    void updateMemoryCost();
 
     std::optional<ImageBitmapBacking> m_backingStore;
+    std::atomic<size_t> m_memoryCost { 0 };
 };
 
 }

Modified: trunk/Source/WebCore/html/ImageBitmap.idl (284771 => 284772)


--- trunk/Source/WebCore/html/ImageBitmap.idl	2021-10-25 02:48:49 UTC (rev 284771)
+++ trunk/Source/WebCore/html/ImageBitmap.idl	2021-10-25 06:47:50 UTC (rev 284772)
@@ -26,7 +26,8 @@
 [
     EnabledAtRuntime=ImageBitmapEnabled,
     Exposed=(Window,Worker),
-    ImplementationLacksVTable
+    ImplementationLacksVTable,
+    ReportExtraMemoryCost
 ] interface ImageBitmap {
     readonly attribute unsigned long width;
     readonly attribute unsigned long height;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to