diff --git a/Userland/Libraries/LibAccelGfx/Painter.cpp b/Userland/Libraries/LibAccelGfx/Painter.cpp index 21c3e23a8e..69745f1979 100644 --- a/Userland/Libraries/LibAccelGfx/Painter.cpp +++ b/Userland/Libraries/LibAccelGfx/Painter.cpp @@ -170,13 +170,14 @@ void main() { HashMap s_immutable_bitmap_texture_cache; -NonnullOwnPtr Painter::create(Context& context) +NonnullOwnPtr Painter::create(Context& context, NonnullRefPtr canvas) { - return make(context); + return make(context, canvas); } -Painter::Painter(Context& context) +Painter::Painter(Context& context, NonnullRefPtr canvas) : m_context(context) + , m_target_canvas(canvas) , 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_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_state_stack.empend(State()); + state().clip_rect = { { 0, 0 }, m_target_canvas->size() }; + bind_target_canvas(); } Painter::~Painter() @@ -607,14 +610,6 @@ void Painter::bind_target_canvas() GL::enable_scissor_test(state().clip_rect); } -void Painter::set_target_canvas(NonnullRefPtr 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) { m_target_canvas->bind(); diff --git a/Userland/Libraries/LibAccelGfx/Painter.h b/Userland/Libraries/LibAccelGfx/Painter.h index 55d3f15630..6c99937186 100644 --- a/Userland/Libraries/LibAccelGfx/Painter.h +++ b/Userland/Libraries/LibAccelGfx/Painter.h @@ -29,9 +29,9 @@ class Painter { AK_MAKE_NONMOVABLE(Painter); public: - static NonnullOwnPtr create(Context&); + static NonnullOwnPtr create(Context&, NonnullRefPtr); - Painter(Context&); + Painter(Context&, NonnullRefPtr); ~Painter(); void clear(Gfx::Color); @@ -67,7 +67,6 @@ public: void set_clip_rect(Gfx::IntRect); void clear_clip_rect(); - void set_target_canvas(NonnullRefPtr); void flush(Gfx::Bitmap&); void fill_rect_with_linear_gradient(Gfx::IntRect const&, ReadonlySpan, float angle, Optional repeat_length = {}); @@ -110,7 +109,7 @@ private: Vector m_state_stack; - RefPtr m_target_canvas; + NonnullRefPtr m_target_canvas; Program m_rectangle_program; Program m_rounded_rectangle_program; diff --git a/Userland/Libraries/LibWeb/Painting/PaintingCommandExecutorGPU.cpp b/Userland/Libraries/LibWeb/Painting/PaintingCommandExecutorGPU.cpp index 5088ec9990..e31465cc27 100644 --- a/Userland/Libraries/LibWeb/Painting/PaintingCommandExecutorGPU.cpp +++ b/Userland/Libraries/LibWeb/Painting/PaintingCommandExecutorGPU.cpp @@ -13,9 +13,8 @@ PaintingCommandExecutorGPU::PaintingCommandExecutorGPU(AccelGfx::Context& contex : m_target_bitmap(bitmap) , m_context(context) { - auto painter = AccelGfx::Painter::create(m_context); 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, .painter = move(painter), .opacity = 1.0f, @@ -115,9 +114,8 @@ CommandResult PaintingCommandExecutorGPU::push_stacking_context(float opacity, b final_transform.multiply(stacking_context_transform); final_transform.multiply(inverse_origin_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()); - painter->set_target_canvas(canvas); + auto painter = AccelGfx::Painter::create(m_context, canvas); painter->translate(-source_paintable_rect.location().to_type()); painter->clear(Color::Transparent); 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 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_painter = AccelGfx::Painter::create(m_context); - text_shadow_painter->set_target_canvas(text_shadow_canvas); + auto text_shadow_painter = AccelGfx::Painter::create(m_context, text_shadow_canvas); text_shadow_painter->clear(color.with_alpha(0)); 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_painter = AccelGfx::Painter::create(m_context); - horizontal_blur_painter->set_target_canvas(horizontal_blur_canvas); + auto horizontal_blur_painter = AccelGfx::Painter::create(m_context, horizontal_blur_canvas); horizontal_blur_painter->clear(color.with_alpha(0)); horizontal_blur_painter->blit_blurred_canvas(shadow_bounding_rect.to_type(), *text_shadow_canvas, blur_radius, AccelGfx::Painter::BlurDirection::Horizontal); painter().blit_blurred_canvas(shadow_location, *horizontal_blur_canvas, blur_radius, AccelGfx::Painter::BlurDirection::Vertical);