mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 09:45:06 +02:00
Two related problems exist in the current display list architecture: 1. DrawPaintingSurface thread safety: CanvasPaintable::paint() records the *same* PaintingSurface that the canvas rendering context draws to. The rendering thread later reads from it, but the main thread may be concurrently drawing — a data race. 2. Video frames force display list rebuilds: each new video frame triggers set_needs_display() → full display list rebuild. Both stem from display list commands holding direct references to content (surface/bitmap) rather than going through an indirection layer. ExternalContentSource is a thread-safe, atomically-refcounted container that holds an ImmutableBitmap snapshot. The accompanying DrawExternalContent display list command reads from it during replay, so producers can swap in new content without rebuilding the list. Subsequent commits migrate canvas, video, and SVG painting to ExternalContentSource and then remove DrawPaintingSurface.
32 lines
694 B
C++
32 lines
694 B
C++
/*
|
|
* Copyright (c) 2026, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/AtomicRefCounted.h>
|
|
#include <AK/RefPtr.h>
|
|
#include <LibGfx/Forward.h>
|
|
#include <LibThreading/Mutex.h>
|
|
|
|
namespace Web::Painting {
|
|
|
|
class ExternalContentSource final : public AtomicRefCounted<ExternalContentSource> {
|
|
public:
|
|
static NonnullRefPtr<ExternalContentSource> create();
|
|
|
|
void update(RefPtr<Gfx::ImmutableBitmap>);
|
|
void clear();
|
|
RefPtr<Gfx::ImmutableBitmap> current_bitmap() const;
|
|
|
|
private:
|
|
ExternalContentSource() = default;
|
|
|
|
mutable Threading::Mutex m_mutex;
|
|
RefPtr<Gfx::ImmutableBitmap> m_bitmap;
|
|
};
|
|
|
|
}
|