mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 01:35:08 +02:00
Using the Rust yuv crate, eagerly convert from YUV to RGBA on the CPU when a GPU context is unavailable. Time spent converting an 8-bit YUV frame with this crate is better than libyuv on ARM by about 20%, and on x86 with AVX2, it achieves similar numbers to libyuv.
60 lines
1.4 KiB
C++
60 lines
1.4 KiB
C++
/*
|
|
* Copyright (c) 2026, Gregory Bertilson <gregory@ladybird.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/Error.h>
|
|
#include <AK/FixedArray.h>
|
|
#include <AK/NonnullOwnPtr.h>
|
|
#include <AK/NonnullRefPtr.h>
|
|
#include <LibGfx/Forward.h>
|
|
#include <LibGfx/Size.h>
|
|
#include <LibMedia/Color/CodingIndependentCodePoints.h>
|
|
#include <LibMedia/Subsampling.h>
|
|
|
|
class SkYUVAPixmaps;
|
|
|
|
namespace Gfx {
|
|
|
|
namespace Details {
|
|
|
|
struct YUVDataImpl;
|
|
|
|
}
|
|
|
|
// Holds planar YUV data with metadata needed for GPU conversion.
|
|
// Uses FixedArray for deterministic buffer sizing.
|
|
// Not ref-counted - owned directly by ImmutableBitmap via NonnullOwnPtr.
|
|
class YUVData final {
|
|
public:
|
|
static ErrorOr<NonnullOwnPtr<YUVData>> create(IntSize size, u8 bit_depth, Media::Subsampling, Media::CodingIndependentCodePoints);
|
|
|
|
~YUVData();
|
|
|
|
IntSize size() const;
|
|
u8 bit_depth() const;
|
|
Media::Subsampling subsampling() const;
|
|
Media::CodingIndependentCodePoints const& cicp() const;
|
|
|
|
// Writable access for decoder to fill buffers after creation
|
|
Bytes y_data();
|
|
Bytes u_data();
|
|
Bytes v_data();
|
|
|
|
ErrorOr<NonnullRefPtr<Bitmap>> to_bitmap() const;
|
|
|
|
SkYUVAPixmaps make_pixmaps() const;
|
|
|
|
void expand_samples_to_full_16_bit_range();
|
|
|
|
private:
|
|
explicit YUVData(NonnullOwnPtr<Details::YUVDataImpl>);
|
|
|
|
NonnullOwnPtr<Details::YUVDataImpl> m_impl;
|
|
};
|
|
|
|
}
|