This is a small prerequisite for moving decoded YUV frames from ImmutableBitmap into Media::VideoFrame. Once the frame owns the planes directly, CPU consumers and the Skia upload path will share the same YUVData object. Those consumers need different representations. Skia expects high bit depth YUVA pixmaps to be full-range 16-bit samples, while CPU conversion paths must see the decoder-native samples and the original bit depth. Keep YUVData in decoder-native form, and make the Skia expansion a temporary copy owned by SkYUVAPixmaps. Add a regression test that checks 10-bit pixmaps are expanded for Skia without mutating the source planes or changing YUVData::to_bitmap() output.
57 lines
1.3 KiB
C++
57 lines
1.3 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;
|
|
|
|
private:
|
|
explicit YUVData(NonnullOwnPtr<Details::YUVDataImpl>);
|
|
|
|
NonnullOwnPtr<Details::YUVDataImpl> m_impl;
|
|
};
|
|
|
|
}
|