/* * Copyright (c) 2023, MacDue * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include namespace Ladybird { class TVGIconEngine : public QIconEngine { public: TVGIconEngine(Gfx::TinyVGDecodedImageData const& image_data) : m_image_data(image_data) { } static TVGIconEngine* from_file(QString const& path); void paint(QPainter* painter, QRect const& rect, QIcon::Mode mode, QIcon::State state) override; QIconEngine* clone() const override; QPixmap pixmap(QSize const& size, QIcon::Mode mode, QIcon::State state) override; void add_filter(QIcon::Mode mode, Function filter); private: static unsigned next_cache_id() { static unsigned cache_id = 0; return cache_id++; } void invalidate_cache() { m_cache_id = next_cache_id(); } class Filter : public RefCounted { public: Filter(QIcon::Mode mode, Function function) : m_mode(mode) , m_function(move(function)) { } QIcon::Mode mode() const { return m_mode; } Function const& function() const { return m_function; } private: QIcon::Mode m_mode; Function m_function; }; QString pixmap_cache_key(QSize const& size, QIcon::Mode mode, QIcon::State state); Vector> m_filters; NonnullRefPtr m_image_data; unsigned m_cache_id { next_cache_id() }; }; }