ladybird/Libraries/LibGfx/PaintingSurface.h
Aliaksandr Kalenik 24e2c402f5 LibWeb+WebContent: Move display list rasterization off the main thread
The display list is an immutable data structure, so once it's created,
rasterization can be moved to a separate thread. This allows more room
for performing other tasks between processing HTML rendering tasks.

This change makes PaintingSurface, ImmutableBitmap, and GlyphRun atomic
ref-counted, as they are shared between the main and rendering threads
by being included in the display list.
2025-03-31 15:58:15 +01:00

68 lines
1.5 KiB
C++

/*
* Copyright (c) 2024-2025, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/AtomicRefCounted.h>
#include <AK/Function.h>
#include <AK/NonnullOwnPtr.h>
#include <AK/RefPtr.h>
#include <LibGfx/Color.h>
#include <LibGfx/Size.h>
#include <LibGfx/SkiaBackendContext.h>
#ifdef AK_OS_MACOS
# include <LibGfx/MetalContext.h>
#endif
class SkCanvas;
class SkSurface;
namespace Gfx {
class PaintingSurface : public AtomicRefCounted<PaintingSurface> {
public:
enum class Origin {
TopLeft,
BottomLeft,
};
Function<void(PaintingSurface&)> on_flush;
static NonnullRefPtr<PaintingSurface> create_with_size(RefPtr<SkiaBackendContext> context, IntSize size, BitmapFormat color_type, AlphaType alpha_type);
static NonnullRefPtr<PaintingSurface> wrap_bitmap(Bitmap&);
#ifdef AK_OS_MACOS
static NonnullRefPtr<PaintingSurface> wrap_iosurface(Core::IOSurfaceHandle const&, RefPtr<SkiaBackendContext>, Origin = Origin::TopLeft);
#endif
void read_into_bitmap(Bitmap&);
void write_from_bitmap(Bitmap const&);
void notify_content_will_change();
IntSize size() const;
IntRect rect() const;
SkCanvas& canvas() const;
SkSurface& sk_surface() const;
template<typename T>
T sk_image_snapshot() const;
void flush();
~PaintingSurface();
private:
struct Impl;
PaintingSurface(NonnullOwnPtr<Impl>&&);
NonnullOwnPtr<Impl> m_impl;
};
}