1.11
screen.h
1/*
2 * Copyright (C) 2018 Microchip Technology Inc. All rights reserved.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6#ifndef EGT_SCREEN_H
7#define EGT_SCREEN_H
8
14#include <egt/detail/meta.h>
15#include <egt/geometry.h>
16#include <egt/painter.h>
17#include <egt/surface.h>
18#include <egt/types.h>
19#include <iosfwd>
20#include <memory>
21#include <vector>
22
23namespace egt
24{
25inline namespace v1
26{
27namespace detail
28{
29class FrameBufferInfo;
30}
31
38class EGT_API Screen
39{
40public:
41
45 using DamageArray = std::vector<Rect>;
46
47 Screen() noexcept;
48 Screen(const Screen&) = default;
49 Screen& operator=(const Screen&) = default;
50 Screen(Screen&&) noexcept = default;
51 Screen& operator=(Screen&&) noexcept = default;
52
61 virtual void flip(const DamageArray& damage);
62
69 virtual void schedule_flip() = 0;
70
75 virtual uint32_t index() { return 0; }
76
80 EGT_NODISCARD Size size() const { return m_size; }
81
85 EGT_NODISCARD Rect box() const { return Rect(Point(), m_size); }
86
90 EGT_NODISCARD Painter& painter() { return *m_painter; }
91
101 static void damage_algorithm(Screen::DamageArray& damage, Rect rect);
102
106 void async_flip(bool async)
107 {
108 m_async = async;
109 }
110
116 EGT_NODISCARD virtual size_t max_brightness() const;
117
123 EGT_NODISCARD virtual size_t brightness() const;
124
132 virtual void brightness(size_t brightness);
133
140 virtual void low_fidelity();
141
148 virtual void high_fidelity();
149
153 EGT_NODISCARD PixelFormat format() const { return m_format; };
154
158 EGT_NODISCARD virtual bool have_planes() const { return false; }
159
164 EGT_NODISCARD virtual bool is_composer() const { return false; }
165
166 virtual ~Screen() noexcept = default;
167
168protected:
169
176 void init(const detail::FrameBufferInfo* info, uint32_t count, const Size& size,
177 PixelFormat format = PixelFormat::argb8888);
178
180 void init(const Size& size, PixelFormat format = PixelFormat::argb8888)
181 {
182 init(nullptr, 0, size, format);
183 }
184
186 struct ScreenBuffer
187 {
188 explicit ScreenBuffer(Surface&& s) noexcept
189 : surface(std::move(s))
190 {
191 damage.reserve(10);
192 }
193
194 Surface surface;
195
199 DamageArray damage;
200
201 void add_damage(const Rect& rect)
202 {
203 Screen::damage_algorithm(damage, rect);
204 }
205 };
206
208 virtual void copy_to_buffer(ScreenBuffer& buffer);
209
211 void copy_to_buffer_software(ScreenBuffer& buffer);
212
215
217 std::unique_ptr<Painter> m_painter;
218
220 using BufferArray = std::vector<ScreenBuffer>;
221
224
227
229 bool m_async{false};
230
232 PixelFormat m_format{};
233};
234
235}
236}
237
238#endif
Drawing interface for 2D graphics.
Definition painter.h:54
Manages one of more buffers that make up a Screen.
Definition screen.h:39
void copy_to_buffer_software(ScreenBuffer &buffer)
Copy the framebuffer to the current composition buffer.
virtual ~Screen() noexcept=default
EGT_NODISCARD Rect box() const
Bounding box for the screen.
Definition screen.h:85
void async_flip(bool async)
Set if asynchronous buffer flips are used.
Definition screen.h:106
virtual void low_fidelity()
Configure low fidelity options.
std::unique_ptr< Painter > m_painter
Composition painter.
Definition screen.h:217
virtual void brightness(size_t brightness)
Set the brightness of the screen.
virtual EGT_NODISCARD bool is_composer() const
Returns true if this is a screen used with the Microchip Graphic Composer.
Definition screen.h:164
virtual void high_fidelity()
Configure high fidelity options.
Screen() noexcept
virtual EGT_NODISCARD size_t brightness() const
Get the current brightness of the screen.
std::vector< Rect > DamageArray
Type used for damage arrays.
Definition screen.h:45
BufferArray m_buffers
Screen buffer array.
Definition screen.h:223
virtual void copy_to_buffer(ScreenBuffer &buffer)
Copy the framebuffer to the current composition buffer.
virtual EGT_NODISCARD size_t max_brightness() const
Get the max brightness of the screen.
EGT_NODISCARD Size size() const
Size of the screen.
Definition screen.h:80
virtual EGT_NODISCARD bool have_planes() const
Returns true if the screen supports planes.
Definition screen.h:158
Size m_size
Size of the screen.
Definition screen.h:226
EGT_NODISCARD PixelFormat format() const
Get the format of the screen.
Definition screen.h:153
static void damage_algorithm(Screen::DamageArray &damage, Rect rect)
This function implements the algorithm for adding damage rectangles to a list.
std::vector< ScreenBuffer > BufferArray
Type used for an array of ScreenBuffer objects.
Definition screen.h:220
Surface m_surface
Composition surface.
Definition screen.h:214
EGT_NODISCARD Painter & painter()
Get the painter for the screen.
Definition screen.h:90
Definition surface.h:34
PixelFormat
Supported pixel formats.
Definition types.h:30
EGT framework namespace.
Definition animation.h:24