mirror of
https://github.com/RGBCube/serenity
synced 2025-05-25 04:45:06 +00:00

This change introduces a new 2D graphics library that uses OpenGL to perform painting operations. For now, it has extremely limited functionality and supports only rectangle painting, but we have to start somewhere. Since this library is intended to be used by LibWeb, where the WebContent process does not have an associated window, painting occurs in an offscreen buffer created using EGL. For now it is only possible to compile this library on linux. Offscreen context creation on SerenityOS and MacOS will have to be implemented separately in the future. Co-Authored-By: Andreas Kling <awesomekling@gmail.com>
53 lines
1.1 KiB
C++
53 lines
1.1 KiB
C++
/*
|
|
* Copyright (c) 2023, Andreas Kling <kling@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/Noncopyable.h>
|
|
#include <AK/Vector.h>
|
|
#include <LibAccelGfx/Forward.h>
|
|
#include <LibGfx/AffineTransform.h>
|
|
#include <LibGfx/Forward.h>
|
|
|
|
namespace AccelGfx {
|
|
|
|
class Painter {
|
|
AK_MAKE_NONCOPYABLE(Painter);
|
|
AK_MAKE_NONMOVABLE(Painter);
|
|
|
|
public:
|
|
Painter(Canvas&);
|
|
~Painter();
|
|
|
|
void clear(Gfx::Color);
|
|
|
|
void save();
|
|
void restore();
|
|
|
|
[[nodiscard]] Gfx::AffineTransform const& transform() const { return state().transform; }
|
|
void set_transform(Gfx::AffineTransform const& transform) { state().transform = transform; }
|
|
|
|
void fill_rect(Gfx::FloatRect, Gfx::Color);
|
|
void fill_rect(Gfx::IntRect, Gfx::Color);
|
|
|
|
private:
|
|
void flush();
|
|
|
|
Canvas& m_canvas;
|
|
|
|
struct State {
|
|
Gfx::AffineTransform transform;
|
|
};
|
|
|
|
[[nodiscard]] State& state() { return m_state_stack.last(); }
|
|
[[nodiscard]] State const& state() const { return m_state_stack.last(); }
|
|
|
|
[[nodiscard]] Gfx::FloatRect to_clip_space(Gfx::FloatRect const& screen_rect) const;
|
|
|
|
Vector<State, 1> m_state_stack;
|
|
};
|
|
|
|
}
|