mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:07:45 +00:00
LibAccelGfx: Remove ability to change target canvas in painter
It is easier to build painter assuming target canvas won't change and we don't use this api anyway :)
This commit is contained in:
parent
161082e282
commit
4a2a37275e
3 changed files with 13 additions and 23 deletions
|
@ -170,13 +170,14 @@ void main() {
|
||||||
|
|
||||||
HashMap<u32, GL::Texture> s_immutable_bitmap_texture_cache;
|
HashMap<u32, GL::Texture> s_immutable_bitmap_texture_cache;
|
||||||
|
|
||||||
NonnullOwnPtr<Painter> Painter::create(Context& context)
|
NonnullOwnPtr<Painter> Painter::create(Context& context, NonnullRefPtr<Canvas> canvas)
|
||||||
{
|
{
|
||||||
return make<Painter>(context);
|
return make<Painter>(context, canvas);
|
||||||
}
|
}
|
||||||
|
|
||||||
Painter::Painter(Context& context)
|
Painter::Painter(Context& context, NonnullRefPtr<Canvas> canvas)
|
||||||
: m_context(context)
|
: m_context(context)
|
||||||
|
, m_target_canvas(canvas)
|
||||||
, m_rectangle_program(Program::create(Program::Name::RectangleProgram, vertex_shader_source, solid_color_fragment_shader_source))
|
, m_rectangle_program(Program::create(Program::Name::RectangleProgram, vertex_shader_source, solid_color_fragment_shader_source))
|
||||||
, m_rounded_rectangle_program(Program::create(Program::Name::RoundedRectangleProgram, vertex_shader_source, rect_with_rounded_corners_fragment_shader_source))
|
, m_rounded_rectangle_program(Program::create(Program::Name::RoundedRectangleProgram, vertex_shader_source, rect_with_rounded_corners_fragment_shader_source))
|
||||||
, m_blit_program(Program::create(Program::Name::BlitProgram, blit_vertex_shader_source, blit_fragment_shader_source))
|
, m_blit_program(Program::create(Program::Name::BlitProgram, blit_vertex_shader_source, blit_fragment_shader_source))
|
||||||
|
@ -184,6 +185,8 @@ Painter::Painter(Context& context)
|
||||||
, m_blur_program(Program::create(Program::Name::BlurProgram, blit_vertex_shader_source, blur_fragment_shader_source))
|
, m_blur_program(Program::create(Program::Name::BlurProgram, blit_vertex_shader_source, blur_fragment_shader_source))
|
||||||
{
|
{
|
||||||
m_state_stack.empend(State());
|
m_state_stack.empend(State());
|
||||||
|
state().clip_rect = { { 0, 0 }, m_target_canvas->size() };
|
||||||
|
bind_target_canvas();
|
||||||
}
|
}
|
||||||
|
|
||||||
Painter::~Painter()
|
Painter::~Painter()
|
||||||
|
@ -607,14 +610,6 @@ void Painter::bind_target_canvas()
|
||||||
GL::enable_scissor_test(state().clip_rect);
|
GL::enable_scissor_test(state().clip_rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Painter::set_target_canvas(NonnullRefPtr<Canvas> canvas)
|
|
||||||
{
|
|
||||||
m_target_canvas = canvas;
|
|
||||||
canvas->bind();
|
|
||||||
GL::set_viewport({ 0, 0, canvas->size().width(), canvas->size().height() });
|
|
||||||
state().clip_rect = { { 0, 0 }, m_target_canvas->size() };
|
|
||||||
}
|
|
||||||
|
|
||||||
void Painter::flush(Gfx::Bitmap& bitmap)
|
void Painter::flush(Gfx::Bitmap& bitmap)
|
||||||
{
|
{
|
||||||
m_target_canvas->bind();
|
m_target_canvas->bind();
|
||||||
|
|
|
@ -29,9 +29,9 @@ class Painter {
|
||||||
AK_MAKE_NONMOVABLE(Painter);
|
AK_MAKE_NONMOVABLE(Painter);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static NonnullOwnPtr<Painter> create(Context&);
|
static NonnullOwnPtr<Painter> create(Context&, NonnullRefPtr<Canvas>);
|
||||||
|
|
||||||
Painter(Context&);
|
Painter(Context&, NonnullRefPtr<Canvas>);
|
||||||
~Painter();
|
~Painter();
|
||||||
|
|
||||||
void clear(Gfx::Color);
|
void clear(Gfx::Color);
|
||||||
|
@ -67,7 +67,6 @@ public:
|
||||||
void set_clip_rect(Gfx::IntRect);
|
void set_clip_rect(Gfx::IntRect);
|
||||||
void clear_clip_rect();
|
void clear_clip_rect();
|
||||||
|
|
||||||
void set_target_canvas(NonnullRefPtr<Canvas>);
|
|
||||||
void flush(Gfx::Bitmap&);
|
void flush(Gfx::Bitmap&);
|
||||||
|
|
||||||
void fill_rect_with_linear_gradient(Gfx::IntRect const&, ReadonlySpan<Gfx::ColorStop>, float angle, Optional<float> repeat_length = {});
|
void fill_rect_with_linear_gradient(Gfx::IntRect const&, ReadonlySpan<Gfx::ColorStop>, float angle, Optional<float> repeat_length = {});
|
||||||
|
@ -110,7 +109,7 @@ private:
|
||||||
|
|
||||||
Vector<State, 1> m_state_stack;
|
Vector<State, 1> m_state_stack;
|
||||||
|
|
||||||
RefPtr<Canvas> m_target_canvas;
|
NonnullRefPtr<Canvas> m_target_canvas;
|
||||||
|
|
||||||
Program m_rectangle_program;
|
Program m_rectangle_program;
|
||||||
Program m_rounded_rectangle_program;
|
Program m_rounded_rectangle_program;
|
||||||
|
|
|
@ -13,9 +13,8 @@ PaintingCommandExecutorGPU::PaintingCommandExecutorGPU(AccelGfx::Context& contex
|
||||||
: m_target_bitmap(bitmap)
|
: m_target_bitmap(bitmap)
|
||||||
, m_context(context)
|
, m_context(context)
|
||||||
{
|
{
|
||||||
auto painter = AccelGfx::Painter::create(m_context);
|
|
||||||
auto canvas = AccelGfx::Canvas::create(bitmap.size());
|
auto canvas = AccelGfx::Canvas::create(bitmap.size());
|
||||||
painter->set_target_canvas(canvas);
|
auto painter = AccelGfx::Painter::create(m_context, canvas);
|
||||||
m_stacking_contexts.append({ .canvas = canvas,
|
m_stacking_contexts.append({ .canvas = canvas,
|
||||||
.painter = move(painter),
|
.painter = move(painter),
|
||||||
.opacity = 1.0f,
|
.opacity = 1.0f,
|
||||||
|
@ -115,9 +114,8 @@ CommandResult PaintingCommandExecutorGPU::push_stacking_context(float opacity, b
|
||||||
final_transform.multiply(stacking_context_transform);
|
final_transform.multiply(stacking_context_transform);
|
||||||
final_transform.multiply(inverse_origin_translation);
|
final_transform.multiply(inverse_origin_translation);
|
||||||
if (opacity < 1 || !stacking_context_transform.is_identity_or_translation()) {
|
if (opacity < 1 || !stacking_context_transform.is_identity_or_translation()) {
|
||||||
auto painter = AccelGfx::Painter::create(m_context);
|
|
||||||
auto canvas = AccelGfx::Canvas::create(source_paintable_rect.size());
|
auto canvas = AccelGfx::Canvas::create(source_paintable_rect.size());
|
||||||
painter->set_target_canvas(canvas);
|
auto painter = AccelGfx::Painter::create(m_context, canvas);
|
||||||
painter->translate(-source_paintable_rect.location().to_type<float>());
|
painter->translate(-source_paintable_rect.location().to_type<float>());
|
||||||
painter->clear(Color::Transparent);
|
painter->clear(Color::Transparent);
|
||||||
m_stacking_contexts.append({ .canvas = canvas,
|
m_stacking_contexts.append({ .canvas = canvas,
|
||||||
|
@ -169,8 +167,7 @@ CommandResult PaintingCommandExecutorGPU::paint_inner_box_shadow(PaintOuterBoxSh
|
||||||
CommandResult PaintingCommandExecutorGPU::paint_text_shadow(int blur_radius, Gfx::IntRect const& shadow_bounding_rect, Gfx::IntRect const& text_rect, Span<Gfx::DrawGlyphOrEmoji const> glyph_run, Color const& color, int fragment_baseline, Gfx::IntPoint const& draw_location)
|
CommandResult PaintingCommandExecutorGPU::paint_text_shadow(int blur_radius, Gfx::IntRect const& shadow_bounding_rect, Gfx::IntRect const& text_rect, Span<Gfx::DrawGlyphOrEmoji const> glyph_run, Color const& color, int fragment_baseline, Gfx::IntPoint const& draw_location)
|
||||||
{
|
{
|
||||||
auto text_shadow_canvas = AccelGfx::Canvas::create(shadow_bounding_rect.size());
|
auto text_shadow_canvas = AccelGfx::Canvas::create(shadow_bounding_rect.size());
|
||||||
auto text_shadow_painter = AccelGfx::Painter::create(m_context);
|
auto text_shadow_painter = AccelGfx::Painter::create(m_context, text_shadow_canvas);
|
||||||
text_shadow_painter->set_target_canvas(text_shadow_canvas);
|
|
||||||
text_shadow_painter->clear(color.with_alpha(0));
|
text_shadow_painter->clear(color.with_alpha(0));
|
||||||
|
|
||||||
Gfx::FloatRect const shadow_location { draw_location, shadow_bounding_rect.size() };
|
Gfx::FloatRect const shadow_location { draw_location, shadow_bounding_rect.size() };
|
||||||
|
@ -183,8 +180,7 @@ CommandResult PaintingCommandExecutorGPU::paint_text_shadow(int blur_radius, Gfx
|
||||||
}
|
}
|
||||||
|
|
||||||
auto horizontal_blur_canvas = AccelGfx::Canvas::create(shadow_bounding_rect.size());
|
auto horizontal_blur_canvas = AccelGfx::Canvas::create(shadow_bounding_rect.size());
|
||||||
auto horizontal_blur_painter = AccelGfx::Painter::create(m_context);
|
auto horizontal_blur_painter = AccelGfx::Painter::create(m_context, horizontal_blur_canvas);
|
||||||
horizontal_blur_painter->set_target_canvas(horizontal_blur_canvas);
|
|
||||||
horizontal_blur_painter->clear(color.with_alpha(0));
|
horizontal_blur_painter->clear(color.with_alpha(0));
|
||||||
horizontal_blur_painter->blit_blurred_canvas(shadow_bounding_rect.to_type<float>(), *text_shadow_canvas, blur_radius, AccelGfx::Painter::BlurDirection::Horizontal);
|
horizontal_blur_painter->blit_blurred_canvas(shadow_bounding_rect.to_type<float>(), *text_shadow_canvas, blur_radius, AccelGfx::Painter::BlurDirection::Horizontal);
|
||||||
painter().blit_blurred_canvas(shadow_location, *horizontal_blur_canvas, blur_radius, AccelGfx::Painter::BlurDirection::Vertical);
|
painter().blit_blurred_canvas(shadow_location, *horizontal_blur_canvas, blur_radius, AccelGfx::Painter::BlurDirection::Vertical);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue