1.10
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 <cairo.h>
15#include <egt/detail/meta.h>
16#include <egt/geometry.h>
17#include <egt/types.h>
18#include <iosfwd>
19#include <memory>
20#include <vector>
21
22namespace egt
23{
24inline namespace v1
25{
26
33class EGT_API Screen
34{
35public:
36
40 using DamageArray = std::vector<Rect>;
41
42 Screen() noexcept;
43 Screen(const Screen&) = default;
44 Screen& operator=(const Screen&) = default;
45 Screen(Screen&&) noexcept = default;
46 Screen& operator=(Screen&&) noexcept = default;
47
56 virtual void flip(const DamageArray& damage);
57
64 virtual void schedule_flip() = 0;
65
70 virtual uint32_t index() { return 0; }
71
75 EGT_NODISCARD Size size() const { return m_size; }
76
80 EGT_NODISCARD Rect box() const { return Rect(Point(), m_size); }
81
87 EGT_NODISCARD shared_cairo_t context() const { return m_cr; }
88
98 static void damage_algorithm(Screen::DamageArray& damage, Rect rect);
99
103 void async_flip(bool async)
104 {
105 m_async = async;
106 }
107
113 EGT_NODISCARD virtual size_t max_brightness() const;
114
120 EGT_NODISCARD virtual size_t brightness() const;
121
129 virtual void brightness(size_t brightness);
130
137 virtual void low_fidelity();
138
145 virtual void high_fidelity();
146
150 EGT_NODISCARD PixelFormat format() const { return m_format; };
151
155 EGT_NODISCARD virtual bool have_planes() const { return false; }
156
161 EGT_NODISCARD virtual bool is_composer() const { return false; }
162
163 virtual ~Screen() noexcept = default;
164
165protected:
166
173 void init(void** ptr, uint32_t count, const Size& size,
174 PixelFormat format = PixelFormat::argb8888);
175
177 void init(const Size& size, PixelFormat format = PixelFormat::argb8888)
178 {
179 init(nullptr, 0, size, format);
180 }
181
183 struct ScreenBuffer
184 {
185 explicit ScreenBuffer(cairo_surface_t* s) noexcept
186 : surface(s)
187 {
188 damage.reserve(10);
189 }
190
192
196 DamageArray damage;
197
198 void add_damage(const Rect& rect)
199 {
200 Screen::damage_algorithm(damage, rect);
201 }
202 };
203
205 virtual void copy_to_buffer(ScreenBuffer& buffer);
206
208 void copy_to_buffer_software(ScreenBuffer& buffer);
209
212
215
217 using BufferArray = std::vector<ScreenBuffer>;
218
221
224
226 bool m_async{false};
227
229 PixelFormat m_format{};
230};
231
232}
233}
234
235#endif
Manages one of more buffers that make up a Screen.
Definition screen.h:34
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:80
void async_flip(bool async)
Set if asynchronous buffer flips are used.
Definition screen.h:103
virtual void low_fidelity()
Configure low fidelity options.
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:161
virtual void high_fidelity()
Configure high fidelity options.
Screen() noexcept
virtual EGT_NODISCARD size_t brightness() const
Get the current brightness of the screen.
shared_cairo_t m_cr
Composition surface context.
Definition screen.h:214
std::vector< Rect > DamageArray
Type used for damage arrays.
Definition screen.h:40
BufferArray m_buffers
Screen buffer array.
Definition screen.h:220
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:75
virtual EGT_NODISCARD bool have_planes() const
Returns true if the screen supports planes.
Definition screen.h:155
Size m_size
Size of the screen.
Definition screen.h:223
EGT_NODISCARD PixelFormat format() const
Get the format of the screen.
Definition screen.h:150
EGT_NODISCARD shared_cairo_t context() const
Get the context for the screen.
Definition screen.h:87
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:217
shared_cairo_surface_t m_surface
Composition surface.
Definition screen.h:211
std::shared_ptr< cairo_surface_t > shared_cairo_surface_t
Shared pointer for a cairo surface.
Definition types.h:29
std::shared_ptr< cairo_t > shared_cairo_t
Shared pointer for a cairo context.
Definition types.h:35
std::unique_ptr< cairo_surface_t, detail::cairo_surface_t_deleter > unique_cairo_surface_t
Unique pointer for a cairo surface.
Definition types.h:80
PixelFormat
Supported pixel formats.
Definition types.h:94
EGT framework namespace.
Definition animation.h:24