2022-02-28 12:13:23 +01:00
|
|
|
/*
|
2024-10-04 13:19:50 +02:00
|
|
|
* Copyright (c) 2018-2022, Andreas Kling <andreas@ladybird.org>
|
2022-10-26 20:53:41 +01:00
|
|
|
* Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
|
2022-02-28 12:13:23 +01:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
2025-07-31 23:07:26 +02:00
|
|
|
#include <LibWeb/Painting/DisplayListRecordingContext.h>
|
2022-02-28 12:13:23 +01:00
|
|
|
|
|
|
|
|
namespace Web {
|
|
|
|
|
|
2024-04-29 17:33:50 +02:00
|
|
|
static u64 s_next_paint_generation_id = 0;
|
|
|
|
|
|
2025-07-31 23:07:26 +02:00
|
|
|
DisplayListRecordingContext::DisplayListRecordingContext(Painting::DisplayListRecorder& display_list_recorder, Palette const& palette, double device_pixels_per_css_pixel)
|
2024-06-23 18:40:10 +02:00
|
|
|
: m_display_list_recorder(display_list_recorder)
|
2022-02-28 12:13:23 +01:00
|
|
|
, m_palette(palette)
|
2025-07-13 03:54:55 +02:00
|
|
|
, m_device_pixel_converter(device_pixels_per_css_pixel)
|
2024-04-29 17:33:50 +02:00
|
|
|
, m_paint_generation_id(s_next_paint_generation_id++)
|
2022-02-28 12:13:23 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-31 23:07:26 +02:00
|
|
|
CSSPixelRect DisplayListRecordingContext::css_viewport_rect() const
|
2022-10-27 14:37:05 +01:00
|
|
|
{
|
|
|
|
|
return {
|
2025-07-13 03:54:55 +02:00
|
|
|
m_device_viewport_rect.x().value() / m_device_pixel_converter.device_pixels_per_css_pixel(),
|
|
|
|
|
m_device_viewport_rect.y().value() / m_device_pixel_converter.device_pixels_per_css_pixel(),
|
|
|
|
|
m_device_viewport_rect.width().value() / m_device_pixel_converter.device_pixels_per_css_pixel(),
|
|
|
|
|
m_device_viewport_rect.height().value() / m_device_pixel_converter.device_pixels_per_css_pixel()
|
2022-10-27 14:37:05 +01:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-31 23:07:26 +02:00
|
|
|
DevicePixels DisplayListRecordingContext::rounded_device_pixels(CSSPixels css_pixels) const
|
2022-10-26 20:53:41 +01:00
|
|
|
{
|
2025-07-13 03:54:55 +02:00
|
|
|
return m_device_pixel_converter.rounded_device_pixels(css_pixels);
|
2022-10-26 20:53:41 +01:00
|
|
|
}
|
|
|
|
|
|
2025-07-31 23:07:26 +02:00
|
|
|
DevicePixels DisplayListRecordingContext::enclosing_device_pixels(CSSPixels css_pixels) const
|
2022-10-26 20:53:41 +01:00
|
|
|
{
|
2025-07-13 03:54:55 +02:00
|
|
|
return m_device_pixel_converter.enclosing_device_pixels(css_pixels);
|
2022-10-26 20:53:41 +01:00
|
|
|
}
|
|
|
|
|
|
2025-07-31 23:07:26 +02:00
|
|
|
DevicePixels DisplayListRecordingContext::floored_device_pixels(CSSPixels css_pixels) const
|
2022-10-26 20:53:41 +01:00
|
|
|
{
|
2025-07-13 03:54:55 +02:00
|
|
|
return m_device_pixel_converter.floored_device_pixels(css_pixels);
|
2022-10-26 20:53:41 +01:00
|
|
|
}
|
|
|
|
|
|
2025-07-31 23:07:26 +02:00
|
|
|
DevicePixelPoint DisplayListRecordingContext::rounded_device_point(CSSPixelPoint point) const
|
2022-10-26 20:53:41 +01:00
|
|
|
{
|
2025-07-13 03:54:55 +02:00
|
|
|
return m_device_pixel_converter.rounded_device_point(point);
|
2022-10-26 20:53:41 +01:00
|
|
|
}
|
|
|
|
|
|
2025-07-31 23:07:26 +02:00
|
|
|
DevicePixelPoint DisplayListRecordingContext::floored_device_point(CSSPixelPoint point) const
|
2023-04-10 12:34:39 +01:00
|
|
|
{
|
2025-07-13 03:54:55 +02:00
|
|
|
return m_device_pixel_converter.floored_device_point(point);
|
2023-04-10 12:34:39 +01:00
|
|
|
}
|
|
|
|
|
|
2025-07-31 23:07:26 +02:00
|
|
|
DevicePixelRect DisplayListRecordingContext::enclosing_device_rect(CSSPixelRect rect) const
|
2022-10-26 20:53:41 +01:00
|
|
|
{
|
2025-07-13 03:54:55 +02:00
|
|
|
return m_device_pixel_converter.enclosing_device_rect(rect);
|
2022-10-26 20:53:41 +01:00
|
|
|
}
|
|
|
|
|
|
2025-07-31 23:07:26 +02:00
|
|
|
DevicePixelRect DisplayListRecordingContext::rounded_device_rect(CSSPixelRect rect) const
|
2022-10-26 20:53:41 +01:00
|
|
|
{
|
2025-07-13 03:54:55 +02:00
|
|
|
return m_device_pixel_converter.rounded_device_rect(rect);
|
2022-10-26 20:53:41 +01:00
|
|
|
}
|
|
|
|
|
|
2025-07-31 23:07:26 +02:00
|
|
|
DevicePixelSize DisplayListRecordingContext::enclosing_device_size(CSSPixelSize size) const
|
2022-10-26 20:53:41 +01:00
|
|
|
{
|
2025-07-13 03:54:55 +02:00
|
|
|
return m_device_pixel_converter.enclosing_device_size(size);
|
2022-10-26 20:53:41 +01:00
|
|
|
}
|
|
|
|
|
|
2025-07-31 23:07:26 +02:00
|
|
|
DevicePixelSize DisplayListRecordingContext::rounded_device_size(CSSPixelSize size) const
|
2022-10-26 20:53:41 +01:00
|
|
|
{
|
2025-07-13 03:54:55 +02:00
|
|
|
return m_device_pixel_converter.rounded_device_size(size);
|
2022-10-26 20:53:41 +01:00
|
|
|
}
|
|
|
|
|
|
2025-07-31 23:07:26 +02:00
|
|
|
CSSPixels DisplayListRecordingContext::scale_to_css_pixels(DevicePixels device_pixels) const
|
2022-10-26 20:53:41 +01:00
|
|
|
{
|
2025-07-13 03:54:55 +02:00
|
|
|
return CSSPixels::nearest_value_for(device_pixels.value() / m_device_pixel_converter.device_pixels_per_css_pixel());
|
2022-10-26 20:53:41 +01:00
|
|
|
}
|
|
|
|
|
|
2025-07-31 23:07:26 +02:00
|
|
|
CSSPixelPoint DisplayListRecordingContext::scale_to_css_point(DevicePixelPoint point) const
|
2022-10-26 20:53:41 +01:00
|
|
|
{
|
|
|
|
|
return {
|
|
|
|
|
scale_to_css_pixels(point.x()),
|
|
|
|
|
scale_to_css_pixels(point.y())
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-31 23:07:26 +02:00
|
|
|
CSSPixelSize DisplayListRecordingContext::scale_to_css_size(DevicePixelSize size) const
|
2023-04-11 19:01:49 -04:00
|
|
|
{
|
|
|
|
|
return {
|
|
|
|
|
scale_to_css_pixels(size.width()),
|
|
|
|
|
scale_to_css_pixels(size.height())
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-31 23:07:26 +02:00
|
|
|
CSSPixelRect DisplayListRecordingContext::scale_to_css_rect(DevicePixelRect rect) const
|
2023-04-11 19:01:49 -04:00
|
|
|
{
|
|
|
|
|
return {
|
|
|
|
|
scale_to_css_point(rect.location()),
|
|
|
|
|
scale_to_css_size(rect.size())
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-28 12:13:23 +01:00
|
|
|
}
|