mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-11 17:37:33 +02:00
Decoded image data should not continue to traffic in ImmutableBitmap now that the bitmap wrapper is being retired. Introduce DecodedImageFrame as the paintable decoded-image unit and store a Bitmap plus ColorSpace in it directly. Thread the new frame type through decoded image data, display-list image commands, filters, canvas drawImage, patterns, WebGL texture upload, and CSS/SVG image consumers. ImmutableBitmap remains only at the legacy boundaries that still need it, such as HTML video snapshots and callers that explicitly ask for a bitmap snapshot. This keeps color-space ownership with the decoded frame while making the expensive or legacy ImmutableBitmap path explicit at the few call sites that still need it.
71 lines
2.1 KiB
C++
71 lines
2.1 KiB
C++
/*
|
|
* Copyright (c) 2023, Andreas Kling <andreas@ladybird.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <LibGC/Heap.h>
|
|
#include <LibJS/Runtime/Realm.h>
|
|
#include <LibWeb/HTML/BitmapDecodedImageData.h>
|
|
#include <LibWeb/Painting/DisplayListRecorder.h>
|
|
#include <LibWeb/Painting/DisplayListRecordingContext.h>
|
|
|
|
namespace Web::HTML {
|
|
|
|
GC_DEFINE_ALLOCATOR(BitmapDecodedImageData);
|
|
|
|
ErrorOr<GC::Ref<BitmapDecodedImageData>> BitmapDecodedImageData::create(JS::Realm& realm, Vector<Frame>&& frames, size_t loop_count, bool animated)
|
|
{
|
|
return realm.create<BitmapDecodedImageData>(move(frames), loop_count, animated);
|
|
}
|
|
|
|
BitmapDecodedImageData::BitmapDecodedImageData(Vector<Frame>&& frames, size_t loop_count, bool animated)
|
|
: m_frames(move(frames))
|
|
, m_loop_count(loop_count)
|
|
, m_animated(animated)
|
|
{
|
|
}
|
|
|
|
BitmapDecodedImageData::~BitmapDecodedImageData() = default;
|
|
|
|
RefPtr<Gfx::DecodedImageFrame> BitmapDecodedImageData::frame(size_t frame_index, Gfx::IntSize) const
|
|
{
|
|
if (frame_index >= m_frames.size())
|
|
return nullptr;
|
|
return m_frames[frame_index].frame;
|
|
}
|
|
|
|
int BitmapDecodedImageData::frame_duration(size_t frame_index) const
|
|
{
|
|
if (frame_index >= m_frames.size())
|
|
return 0;
|
|
return m_frames[frame_index].duration;
|
|
}
|
|
|
|
Optional<CSSPixels> BitmapDecodedImageData::intrinsic_width() const
|
|
{
|
|
return m_frames.first().frame->width();
|
|
}
|
|
|
|
Optional<CSSPixels> BitmapDecodedImageData::intrinsic_height() const
|
|
{
|
|
return m_frames.first().frame->height();
|
|
}
|
|
|
|
Optional<CSSPixelFraction> BitmapDecodedImageData::intrinsic_aspect_ratio() const
|
|
{
|
|
return CSSPixels(m_frames.first().frame->width()) / CSSPixels(m_frames.first().frame->height());
|
|
}
|
|
|
|
Optional<Gfx::IntRect> BitmapDecodedImageData::frame_rect(size_t frame_index) const
|
|
{
|
|
return m_frames[frame_index].frame->rect();
|
|
}
|
|
|
|
void BitmapDecodedImageData::paint(DisplayListRecordingContext& context, size_t frame_index, Gfx::IntRect dst_rect, Gfx::IntRect clip_rect, Gfx::ScalingMode scaling_mode) const
|
|
{
|
|
context.display_list_recorder().draw_scaled_decoded_image_frame(dst_rect, clip_rect, *m_frames[frame_index].frame, scaling_mode);
|
|
}
|
|
|
|
}
|