ladybird/Libraries/LibGfx/CanvasCommandPlayer.h
Aliaksandr Kalenik be9ee28afc LibGfx: Stop caching Skia images during canvas playback
The decoded-frame Skia image cache is useful for display-list
rasterization because decoded image resources can be replayed over many
frames. The cache lets that path reuse SkImage wrappers and GPU-backed
copies instead of rebuilding them whenever the same resource is painted.

For canvas, commands are consumed into one backing surface and decoded
frames are already held by the command or paint style for the draw. A
per-painter cache does not match that usage model, and can keep decoded
frames and Skia images alive after the draw has consumed them.

This removes the cache from PainterSkia and drops the now-unused pruning
hook from CanvasCommandPlayer. With the cache gone, PainterSkia can hold
its painting surface directly instead of allocating a private Impl.
DisplayListPlayerSkia keeps owning the cache, so display-list
rasterization keeps the SkImage reuse behavior.
2026-06-16 00:38:30 +02:00

50 lines
1.4 KiB
C++

/*
* Copyright (c) 2026, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Noncopyable.h>
#include <AK/NonnullOwnPtr.h>
#include <AK/NonnullRefPtr.h>
#include <AK/RefPtr.h>
#include <LibGfx/CanvasCommandList.h>
#include <LibGfx/Forward.h>
namespace Gfx {
class CanvasCommandPlayer {
AK_MAKE_NONCOPYABLE(CanvasCommandPlayer);
AK_MAKE_NONMOVABLE(CanvasCommandPlayer);
public:
CanvasCommandPlayer(RefPtr<SkiaBackendContext>, IntSize, BitmapFormat, AlphaType);
~CanvasCommandPlayer();
NonnullRefPtr<PaintingSurface> surface() const;
void clear(Color);
void play(CanvasCommandList const&);
private:
void play_command(CanvasCommands::ClearRect const&);
void play_command(CanvasCommands::FillRect const&);
void play_command(CanvasCommands::DrawBitmap const&);
void play_command(CanvasCommands::FillPath const&);
void play_command(CanvasCommands::StrokePath const&);
void play_command(CanvasCommands::SetTransform const&);
void play_command(CanvasCommands::Save const&);
void play_command(CanvasCommands::Restore const&);
void play_command(CanvasCommands::ClipPath const&);
void play_command(CanvasCommands::Reset const&);
NonnullRefPtr<PaintStyle> resolve_paint_style(CanvasPaintStyle const&) const;
NonnullRefPtr<PaintingSurface> m_surface;
NonnullOwnPtr<PainterSkia> m_painter;
};
}