mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:48:10 +00:00
LibWeb: Start building a new Resource class to share more resources
A Resource represents a resource that we're loading, have loaded or will soon load. Basically, it's a downloadable resource that can be shared by multiple clients. A typical usecase is multiple <img> elements with the same src. In a future patch, we will try to make sure that those <img> elements get the same Resource if possible. This will reduce network usage, memory usage, and CPU usage. :^) For now, this first patch simply introduces the mechanism. You get a Resource by calling ResourceLoader::load_resource(). To get notified about changes to a Resource's load status, you inherit from ResourceClient and implement the callbacks you're interested in. This patch turns HTMLImageElement into a ResourceClient.
This commit is contained in:
parent
7be9cf8d36
commit
5ed66cb8d9
8 changed files with 274 additions and 23 deletions
|
@ -30,12 +30,15 @@
|
|||
#include <LibCore/Forward.h>
|
||||
#include <LibGfx/Forward.h>
|
||||
#include <LibWeb/DOM/HTMLElement.h>
|
||||
#include <LibWeb/Loader/Resource.h>
|
||||
|
||||
namespace Web {
|
||||
|
||||
class LayoutDocument;
|
||||
|
||||
class HTMLImageElement : public HTMLElement {
|
||||
class HTMLImageElement final
|
||||
: public HTMLElement
|
||||
, public ResourceClient {
|
||||
public:
|
||||
using WrapperType = Bindings::HTMLImageElementWrapper;
|
||||
|
||||
|
@ -55,6 +58,9 @@ public:
|
|||
void set_volatile(Badge<LayoutDocument>, bool);
|
||||
|
||||
private:
|
||||
virtual void resource_did_load() override;
|
||||
virtual void resource_did_fail() override;
|
||||
|
||||
void load_image(const String& src);
|
||||
|
||||
void animate();
|
||||
|
@ -62,7 +68,6 @@ private:
|
|||
virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) const override;
|
||||
|
||||
RefPtr<Gfx::ImageDecoder> m_image_decoder;
|
||||
ByteBuffer m_encoded_data;
|
||||
|
||||
size_t m_current_frame_index { 0 };
|
||||
size_t m_loops_completed { 0 };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue