1.12
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 void flush() {}
167
168 virtual ~Screen() noexcept = default;
169
170protected:
171
178 void init(const detail::FrameBufferInfo* info, uint32_t count, const Size& size,
179 PixelFormat format = PixelFormat::argb8888);
180
182 void init(const Size& size, PixelFormat format = PixelFormat::argb8888)
183 {
184 init(nullptr, 0, size, format);
185 }
186
188 struct ScreenBuffer
189 {
190 explicit ScreenBuffer(Surface&& s) noexcept
191 : surface(std::move(s))
192 {
193 damage.reserve(10);
194 }
195
196 Surface surface;
197
201 DamageArray damage;
202
203 void add_damage(const Rect& rect)
204 {
205 Screen::damage_algorithm(damage, rect);
206 }
207 };
208
210 virtual void copy_to_buffer(ScreenBuffer& buffer);
211
213 void copy_to_buffer_software(ScreenBuffer& buffer);
214
217
219 std::unique_ptr<Painter> m_painter;
220
222 using BufferArray = std::vector<ScreenBuffer>;
223
226
229
231 bool m_async{false};
232
234 PixelFormat m_format{};
235};
236
237}
238}
239
240#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:219
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:225
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:228
EGT_NODISCARD PixelFormat format() const
Get the format of the screen.
Definition screen.h:153
virtual void flush()
Definition screen.h:166
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:222
Surface m_surface
Composition surface.
Definition screen.h:216
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