⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 284772 in webkit


Ignore:
Timestamp:
Oct 24, 2021, 11:47:50 PM (5 years ago)
Author:
commit-queue@webkit.org
Message:

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

Patch by Kimmo Kinnunen <kkinnunen@apple.com> 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:
Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r284771 r284772  
     12021-10-24  Kimmo Kinnunen  <kkinnunen@apple.com>
     2
     3        ImageBitmap should report its memory cost
     4        https://bugs.webkit.org/show_bug.cgi?id=187964
     5
     6        Reviewed by Simon Fraser.
     7
     8        Add memory cost reporting for ImageBitmap. In order to avoid storing a lock, computing the
     9        memory cost many times and querying the thread-unsafe image buffer, compute it only when the
     10        image buffer updates and cache the value.
     11
     12        It is unclear how to test this with current infrastructure.
     13
     14        * html/ImageBitmap.cpp:
     15        (WebCore::ImageBitmap::ImageBitmap):
     16        (WebCore::ImageBitmap::takeImageBitmapBacking):
     17        (WebCore::ImageBitmap::updateMemoryCost):
     18        (WebCore::ImageBitmap::memoryCost const):
     19        * html/ImageBitmap.h:
     20        * html/ImageBitmap.idl:
     21
    1222021-10-24  Lauro Moura  <lmoura@igalia.com>
    223
  • trunk/Source/WebCore/html/ImageBitmap.cpp

    r284522 r284772  
    847847{
    848848    ASSERT_IMPLIES(m_backingStore, m_backingStore->buffer());
     849    updateMemoryCost();
    849850}
    850851
     
    859860std::optional<ImageBitmapBacking> ImageBitmap::takeImageBitmapBacking()
    860861{
    861     return std::exchange(m_backingStore, std::nullopt);
     862    auto result = std::exchange(m_backingStore, std::nullopt);
     863    if (result)
     864        updateMemoryCost();
     865    return result;
    862866}
    863867
     
    870874}
    871875
     876void ImageBitmap::updateMemoryCost()
     877{
     878    if (m_backingStore) {
     879        if (auto imageBuffer = m_backingStore->buffer()) {
     880            m_memoryCost = imageBuffer->memoryCost();
     881            return;
     882        }
     883    }
     884    m_memoryCost = 0;
     885}
     886
     887size_t ImageBitmap::memoryCost() const
     888{
     889    return m_memoryCost;
     890}
     891
    872892} // namespace WebCore
  • trunk/Source/WebCore/html/ImageBitmap.h

    r284075 r284772  
    2929#include "ImageBitmapBacking.h"
    3030#include "ScriptWrappable.h"
     31#include <atomic>
    3132#include <wtf/RefCounted.h>
    3233
     
    109110    static Vector<std::optional<ImageBitmapBacking>> detachBitmaps(Vector<RefPtr<ImageBitmap>>&&);
    110111
     112    size_t memoryCost() const;
    111113private:
    112114    friend class ImageBitmapImageObserver;
     
    131133    static void createPromise(ScriptExecutionContext&, RefPtr<CSSStyleImageValue>&, ImageBitmapOptions&&, std::optional<IntRect>, Promise&&);
    132134    static void createFromBuffer(ScriptExecutionContext&, Ref<ArrayBuffer>&&, String mimeType, long long expectedContentLength, const URL&, ImageBitmapOptions&&, std::optional<IntRect>, Promise&&);
     135    void updateMemoryCost();
    133136
    134137    std::optional<ImageBitmapBacking> m_backingStore;
     138    std::atomic<size_t> m_memoryCost { 0 };
    135139};
    136140
  • trunk/Source/WebCore/html/ImageBitmap.idl

    r283463 r284772  
    2727    EnabledAtRuntime=ImageBitmapEnabled,
    2828    Exposed=(Window,Worker),
    29     ImplementationLacksVTable
     29    ImplementationLacksVTable,
     30    ReportExtraMemoryCost
    3031] interface ImageBitmap {
    3132    readonly attribute unsigned long width;
Note: See TracChangeset for help on using the changeset viewer.