ladybird/Libraries/LibGfx/ColorSpace.h
Aliaksandr Kalenik b86eec4a27 LibGfx: Keep ImmutableBitmap source data context-neutral
With the SkImage cache extracted, ImmutableBitmap no longer needs to
hold a SkiaBackendContext, an SkImage, or an SkBitmap. Reduce it to just
the source pixels (a Bitmap or YUVData) and a color space, so the sam
ImmutableBitmap can be consumed by any Skia context without
coordination.

Per-context locking and ensure_sk_image() are no longer needed and go
away with this change; the cache rebuilds an SkImage from the source
data the first time each bitmap is drawn against a context.
2026-05-04 20:12:21 +02:00

64 lines
1.5 KiB
C++

/*
* Copyright (c) 2024, Lucas Chollet <lucas.chollet@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Error.h>
#include <AK/Noncopyable.h>
#include <AK/NonnullOwnPtr.h>
#include <LibIPC/Forward.h>
#include <LibMedia/Color/CodingIndependentCodePoints.h>
namespace Gfx {
namespace Details {
struct ColorSpaceImpl;
}
class ColorSpace {
public:
ColorSpace();
ColorSpace(ColorSpace const&);
ColorSpace(ColorSpace&&);
ColorSpace& operator=(ColorSpace const&);
ColorSpace& operator=(ColorSpace&&);
~ColorSpace();
static ErrorOr<ColorSpace> from_cicp(Media::CodingIndependentCodePoints);
static ErrorOr<ColorSpace> load_from_icc_bytes(ReadonlyBytes);
// In order to keep this file free of Skia types, this function can't return
// a sk_sp<ColorSpace>. To work around that issue, we define a template here
// and only provide a specialization for sk_sp<SkColorSpace>.
template<typename T>
T& color_space();
template<typename T>
T const& color_space() const;
private:
template<typename T>
friend ErrorOr<void> IPC::encode(IPC::Encoder&, T const&);
template<typename T>
friend ErrorOr<T> IPC::decode(IPC::Decoder&);
explicit ColorSpace(NonnullOwnPtr<Details::ColorSpaceImpl>&&);
NonnullOwnPtr<Details::ColorSpaceImpl> m_color_space;
};
}
namespace IPC {
template<>
ErrorOr<void> encode(Encoder&, Gfx::ColorSpace const&);
template<>
ErrorOr<Gfx::ColorSpace> decode(Decoder&);
}