diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-12-18 20:57:18 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-12-18 21:19:04 +0100 |
commit | 54bd322881a3ce316596ec535e59ce0b0dcf2da0 (patch) | |
tree | e7e43d573ef4b1010192e6b014a1b327836c9bf3 /Libraries/LibHTML/DOM | |
parent | 7e068565bc836b7df01ce3512f96d75671e027f6 (diff) | |
download | serenity-54bd322881a3ce316596ec535e59ce0b0dcf2da0.zip |
LibHTML: Mark image bitmaps outside the visible viewport as volatile
When the visible viewport rect changes, we walk the layout tree and
check where each LayoutImage is in relation to the viewport rect.
Images outside have their bitmaps marked as volatile.
Note that the bitmaps are managed by ImageDecoder objects. If a bitmap
is purged by the kernel while volatile, we construct a new ImageDecoder
next time we need pixels for the image.
Diffstat (limited to 'Libraries/LibHTML/DOM')
-rw-r--r-- | Libraries/LibHTML/DOM/HTMLImageElement.cpp | 14 | ||||
-rw-r--r-- | Libraries/LibHTML/DOM/HTMLImageElement.h | 5 |
2 files changed, 18 insertions, 1 deletions
diff --git a/Libraries/LibHTML/DOM/HTMLImageElement.cpp b/Libraries/LibHTML/DOM/HTMLImageElement.cpp index da4afde084..7bb8f8cd38 100644 --- a/Libraries/LibHTML/DOM/HTMLImageElement.cpp +++ b/Libraries/LibHTML/DOM/HTMLImageElement.cpp @@ -80,3 +80,17 @@ const GraphicsBitmap* HTMLImageElement::bitmap() const return nullptr; return m_image_decoder->bitmap(); } + +void HTMLImageElement::set_volatile(Badge<LayoutDocument>, bool v) +{ + if (!m_image_decoder) + return; + if (v) { + m_image_decoder->set_volatile(); + return; + } + bool has_image = m_image_decoder->set_nonvolatile(); + if (has_image) + return; + m_image_decoder = ImageDecoder::create(m_encoded_data.data(), m_encoded_data.size()); +} diff --git a/Libraries/LibHTML/DOM/HTMLImageElement.h b/Libraries/LibHTML/DOM/HTMLImageElement.h index 2cc8587c30..e2677e9651 100644 --- a/Libraries/LibHTML/DOM/HTMLImageElement.h +++ b/Libraries/LibHTML/DOM/HTMLImageElement.h @@ -4,6 +4,8 @@ #include <LibDraw/ImageDecoder.h> #include <LibHTML/DOM/HTMLElement.h> +class LayoutDocument; + class HTMLImageElement : public HTMLElement { public: HTMLImageElement(Document&, const String& tag_name); @@ -19,12 +21,13 @@ public: const GraphicsBitmap* bitmap() const; const ImageDecoder* image_decoder() const { return m_image_decoder; } + void set_volatile(Badge<LayoutDocument>, bool); + private: void load_image(const String& src); virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) const override; RefPtr<ImageDecoder> m_image_decoder; - mutable RefPtr<GraphicsBitmap> m_bitmap; ByteBuffer m_encoded_data; }; |