Files
ladybird/Libraries/LibWeb/CSS/StyleValues/ImageStyleValue.h
Aliaksandr Kalenik 76c79ee522 LibGfx: Remove ImmutableBitmap
DecodedImageFrame now owns decoded bitmap pixels directly, so the
separate ImmutableBitmap wrapper no longer carries useful semantics.
Remove the class and pass decoded image frames or bitmaps at the
boundaries where pixels are actually required.

The Skia image cache now keys off DecodedImageFrame, matching the
display-list commands that paint decoded images. Video frames stay
owned by LibMedia, with the explicit YUV-to-bitmap conversion living
at HTMLVideoElement's decoded-frame entry point for canvas and WebGL
callers.
2026-05-05 14:39:17 -05:00

95 lines
2.9 KiB
C++

/*
* Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
* Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
* Copyright (c) 2021-2025, Sam Atkins <sam@ladybird.org>
* Copyright (c) 2022-2023, MacDue <macdue@dueutil.tech>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibGC/Weak.h>
#include <LibGfx/Forward.h>
#include <LibJS/Heap/Cell.h>
#include <LibWeb/CSS/StyleValues/AbstractImageStyleValue.h>
#include <LibWeb/CSS/URL.h>
#include <LibWeb/Forward.h>
namespace Web::CSS {
class ImageStyleValue final
: public AbstractImageStyleValue
, public Weakable<ImageStyleValue> {
using Base = AbstractImageStyleValue;
public:
class Client {
public:
Client(ImageStyleValue const&);
virtual ~Client();
virtual void image_style_value_did_update(ImageStyleValue&) = 0;
protected:
void image_style_value_finalize();
ImageStyleValue const& m_image_style_value;
};
static ValueComparingNonnullRefPtr<ImageStyleValue const> create(URL const&);
static ValueComparingNonnullRefPtr<ImageStyleValue const> create(::URL::URL const&);
virtual ~ImageStyleValue() override;
virtual void visit_edges(JS::Cell::Visitor& visitor) const override;
virtual void serialize(StringBuilder&, SerializationMode) const override;
virtual bool equals(StyleValue const& other) const override;
virtual bool is_computationally_independent() const override { return true; }
virtual void load_any_resources(DOM::Document&) override;
Optional<CSSPixels> natural_width() const override;
Optional<CSSPixels> natural_height() const override;
Optional<CSSPixelFraction> natural_aspect_ratio() const override;
virtual bool is_paintable() const override;
void paint(DisplayListRecordingContext& context, DevicePixelRect const& dest_rect, CSS::ImageRendering image_rendering) const override;
virtual Optional<Gfx::Color> color_if_single_pixel_bitmap() const override;
RefPtr<Gfx::DecodedImageFrame> current_frame(DevicePixelRect const& dest_rect) const;
mutable Function<void()> on_animate;
GC::Ptr<HTML::DecodedImageData> image_data() const;
private:
friend class Client;
ImageStyleValue(URL const&);
void register_client(Client&) const;
void unregister_client(Client&) const;
virtual void set_style_sheet(GC::Ptr<CSSStyleSheet>) override;
virtual ValueComparingNonnullRefPtr<StyleValue const> absolutized(ComputationContext const&) const override;
void animate();
RefPtr<Gfx::DecodedImageFrame> frame(size_t frame_index, Gfx::IntSize = {}) const;
GC::Ptr<HTML::SharedResourceRequest> m_resource_request;
GC::Ptr<CSSStyleSheet> m_style_sheet;
URL m_url;
GC::Weak<DOM::Document> m_document;
size_t m_current_frame_index { 0 };
size_t m_loops_completed { 0 };
GC::Ptr<Platform::Timer> m_timer;
mutable HashTable<Client*> m_clients;
};
}