2026-02-13 11:04:08 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2023, Andreas Kling <andreas@ladybird.org>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <LibGC/Heap.h>
|
2026-05-05 19:34:52 -03:00
|
|
|
#include <LibGfx/Bitmap.h>
|
|
|
|
|
#include <LibJS/Runtime/ExternalMemory.h>
|
2026-02-13 11:04:08 -03:00
|
|
|
#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);
|
|
|
|
|
|
2026-06-11 22:39:40 -03:00
|
|
|
GC::Ref<BitmapDecodedImageData> BitmapDecodedImageData::create(JS::Realm& realm, Gfx::DecodedImageFrame&& frame)
|
2026-02-13 11:04:08 -03:00
|
|
|
{
|
2026-06-11 22:39:40 -03:00
|
|
|
return realm.create<BitmapDecodedImageData>(move(frame));
|
2026-02-13 11:04:08 -03:00
|
|
|
}
|
|
|
|
|
|
2026-06-11 22:39:40 -03:00
|
|
|
BitmapDecodedImageData::BitmapDecodedImageData(Gfx::DecodedImageFrame&& frame)
|
|
|
|
|
: m_frame(move(frame))
|
2026-02-13 11:04:08 -03:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BitmapDecodedImageData::~BitmapDecodedImageData() = default;
|
|
|
|
|
|
2026-05-05 19:34:52 -03:00
|
|
|
size_t BitmapDecodedImageData::external_memory_size() const
|
|
|
|
|
{
|
2026-06-11 22:39:40 -03:00
|
|
|
return m_frame.bitmap().data_size();
|
2026-05-05 19:34:52 -03:00
|
|
|
}
|
|
|
|
|
|
2026-06-11 22:39:40 -03:00
|
|
|
Optional<Gfx::DecodedImageFrame> BitmapDecodedImageData::frame(size_t, Gfx::IntSize) const
|
2026-02-13 11:04:08 -03:00
|
|
|
{
|
2026-06-11 22:39:40 -03:00
|
|
|
return m_frame;
|
2026-02-13 11:04:08 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Optional<CSSPixels> BitmapDecodedImageData::intrinsic_width() const
|
|
|
|
|
{
|
2026-06-11 22:39:40 -03:00
|
|
|
return m_frame.width();
|
2026-02-13 11:04:08 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Optional<CSSPixels> BitmapDecodedImageData::intrinsic_height() const
|
|
|
|
|
{
|
2026-06-11 22:39:40 -03:00
|
|
|
return m_frame.height();
|
2026-02-13 11:04:08 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Optional<CSSPixelFraction> BitmapDecodedImageData::intrinsic_aspect_ratio() const
|
|
|
|
|
{
|
2026-06-11 22:39:40 -03:00
|
|
|
return CSSPixels(m_frame.width()) / CSSPixels(m_frame.height());
|
2026-02-13 11:04:08 -03:00
|
|
|
}
|
|
|
|
|
|
2026-06-11 22:39:40 -03:00
|
|
|
Optional<Gfx::IntRect> BitmapDecodedImageData::frame_rect(size_t) const
|
2026-02-13 11:04:08 -03:00
|
|
|
{
|
2026-06-11 22:39:40 -03:00
|
|
|
return m_frame.rect();
|
2026-02-13 11:04:08 -03:00
|
|
|
}
|
|
|
|
|
|
2026-06-11 22:39:40 -03:00
|
|
|
void BitmapDecodedImageData::paint(DisplayListRecordingContext& context, size_t, Gfx::IntRect dst_rect, Gfx::ScalingMode scaling_mode) const
|
2026-02-13 11:04:08 -03:00
|
|
|
{
|
2026-06-11 22:39:40 -03:00
|
|
|
context.display_list_recorder().draw_scaled_decoded_image_frame(dst_rect, m_frame, scaling_mode);
|
2026-02-13 11:04:08 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|