| Differences between
and this patch
- a/Source/WebCore/ChangeLog +21 lines
Lines 1-3 a/Source/WebCore/ChangeLog_sec1
1
2021-10-22  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 NOBODY (OOPS!).
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
1
2021-10-19  Kimmo Kinnunen  <kkinnunen@apple.com>
22
2021-10-19  Kimmo Kinnunen  <kkinnunen@apple.com>
2
23
3
        WebGL low-power and high-performance contexts should use different ANGLE Metal EGLDisplays
24
        WebGL low-power and high-performance contexts should use different ANGLE Metal EGLDisplays
- a/Source/WebCore/html/ImageBitmap.cpp -1 / +21 lines
Lines 846-851 ImageBitmap::ImageBitmap(std::optional<ImageBitmapBacking>&& backingStore) a/Source/WebCore/html/ImageBitmap.cpp_sec1
846
    : m_backingStore(WTFMove(backingStore))
846
    : m_backingStore(WTFMove(backingStore))
847
{
847
{
848
    ASSERT_IMPLIES(m_backingStore, m_backingStore->buffer());
848
    ASSERT_IMPLIES(m_backingStore, m_backingStore->buffer());
849
    updateMemoryCost();
849
}
850
}
850
851
851
ImageBitmap::~ImageBitmap()
852
ImageBitmap::~ImageBitmap()
Lines 858-864 ImageBitmap::~ImageBitmap() a/Source/WebCore/html/ImageBitmap.cpp_sec2
858
859
859
std::optional<ImageBitmapBacking> ImageBitmap::takeImageBitmapBacking()
860
std::optional<ImageBitmapBacking> ImageBitmap::takeImageBitmapBacking()
860
{
861
{
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;
862
}
866
}
863
867
864
RefPtr<ImageBuffer> ImageBitmap::takeImageBuffer()
868
RefPtr<ImageBuffer> ImageBitmap::takeImageBuffer()
Lines 869-872 RefPtr<ImageBuffer> ImageBitmap::takeImageBuffer() a/Source/WebCore/html/ImageBitmap.cpp_sec3
869
    return nullptr;
873
    return nullptr;
870
}
874
}
871
875
876
void 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
887
size_t ImageBitmap::memoryCost() const
888
{
889
    return m_memoryCost;
890
}
891
872
} // namespace WebCore
892
} // namespace WebCore
- a/Source/WebCore/html/ImageBitmap.h +4 lines
Lines 28-33 a/Source/WebCore/html/ImageBitmap.h_sec1
28
#include "IDLTypes.h"
28
#include "IDLTypes.h"
29
#include "ImageBitmapBacking.h"
29
#include "ImageBitmapBacking.h"
30
#include "ScriptWrappable.h"
30
#include "ScriptWrappable.h"
31
#include <atomic>
31
#include <wtf/RefCounted.h>
32
#include <wtf/RefCounted.h>
32
33
33
namespace JSC {
34
namespace JSC {
Lines 108-113 public: a/Source/WebCore/html/ImageBitmap.h_sec2
108
109
109
    static Vector<std::optional<ImageBitmapBacking>> detachBitmaps(Vector<RefPtr<ImageBitmap>>&&);
110
    static Vector<std::optional<ImageBitmapBacking>> detachBitmaps(Vector<RefPtr<ImageBitmap>>&&);
110
111
112
    size_t memoryCost() const;
111
private:
113
private:
112
    friend class ImageBitmapImageObserver;
114
    friend class ImageBitmapImageObserver;
113
    friend class PendingImageBitmap;
115
    friend class PendingImageBitmap;
Lines 130-137 private: a/Source/WebCore/html/ImageBitmap.h_sec3
130
    static void createPromise(ScriptExecutionContext&, RefPtr<ImageData>&, ImageBitmapOptions&&, std::optional<IntRect>, Promise&&);
132
    static void createPromise(ScriptExecutionContext&, RefPtr<ImageData>&, ImageBitmapOptions&&, std::optional<IntRect>, Promise&&);
131
    static void createPromise(ScriptExecutionContext&, RefPtr<CSSStyleImageValue>&, ImageBitmapOptions&&, std::optional<IntRect>, Promise&&);
133
    static void createPromise(ScriptExecutionContext&, RefPtr<CSSStyleImageValue>&, ImageBitmapOptions&&, std::optional<IntRect>, Promise&&);
132
    static void createFromBuffer(ScriptExecutionContext&, Ref<ArrayBuffer>&&, String mimeType, long long expectedContentLength, const URL&, ImageBitmapOptions&&, std::optional<IntRect>, Promise&&);
134
    static void createFromBuffer(ScriptExecutionContext&, Ref<ArrayBuffer>&&, String mimeType, long long expectedContentLength, const URL&, ImageBitmapOptions&&, std::optional<IntRect>, Promise&&);
135
    void updateMemoryCost();
133
136
134
    std::optional<ImageBitmapBacking> m_backingStore;
137
    std::optional<ImageBitmapBacking> m_backingStore;
138
    std::atomic<size_t> m_memoryCost { 0 };
135
};
139
};
136
140
137
}
141
}
- a/Source/WebCore/html/ImageBitmap.idl -1 / +2 lines
Lines 26-32 a/Source/WebCore/html/ImageBitmap.idl_sec1
26
[
26
[
27
    EnabledAtRuntime=ImageBitmapEnabled,
27
    EnabledAtRuntime=ImageBitmapEnabled,
28
    Exposed=(Window,Worker),
28
    Exposed=(Window,Worker),
29
    ImplementationLacksVTable
29
    ImplementationLacksVTable,
30
    ReportExtraMemoryCost
30
] interface ImageBitmap {
31
] interface ImageBitmap {
31
    readonly attribute unsigned long width;
32
    readonly attribute unsigned long width;
32
    readonly attribute unsigned long height;
33
    readonly attribute unsigned long height;

Return to Bug 187964