1.11
surface.h
1/*
2 * Copyright (C) 2024 Microchip Technology Inc. All rights reserved.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6#ifndef EGT_SURFACE_H
7#define EGT_SURFACE_H
8
14#include <egt/color.h>
15#include <egt/detail/meta.h>
16#include <egt/geometry.h>
17#include <egt/types.h>
18#include <functional>
19#include <memory>
20#include <string>
21
22namespace egt
23{
24inline namespace v1
25{
26
27namespace detail
28{
29class FrameBuffer;
30class InternalSurface;
31}
32
33class EGT_API Surface
34{
35public:
36 using ReleaseFunction = std::function<void(void*)>;
37
38 Surface(const Size& size = {}, PixelFormat format = PixelFormat::argb8888);
39
40 Surface(void* data, const ReleaseFunction& release,
41 const Size& size, PixelFormat format, DefaultDim stride);
42
43 Surface(const detail::FrameBuffer& fb);
44
46
47 Surface(const Surface&) = delete;
49
50 Surface& operator=(const Surface&) = delete;
52
53 explicit operator bool() const noexcept { return !empty(); }
54
55 bool empty() const { return m_data == nullptr; }
56
57 void* data() { return m_data; }
58 const void* data() const { return m_data; }
59
60 const Size& size() const { return m_size; }
61 PixelFormat format() const { return m_format; }
62 DefaultDim width() const { return m_size.width(); }
63 DefaultDim height() const { return m_size.height(); }
64 DefaultDim stride() const { return m_stride; }
65
66 static DefaultDim stride(PixelFormat format, DefaultDim width);
67
68 void write_to_png(const std::string& name) const;
69
70 void flush(bool claimed_by_cpu = false) const;
71 void mark_dirty();
72
73 void zero();
74
75 void color_at(const Point& point, const Color& color);
76 EGT_NODISCARD Color color_at(const Point& point) const;
77
78 void flood(const Point& point, const Color& color);
79
80 EGT_NODISCARD const detail::InternalSurface& impl() const { return *m_impl; }
81
87 void sync_for_cpu() const;
88
89protected:
90 void* m_data{nullptr};
93 PixelFormat m_format{PixelFormat::invalid};
94 DefaultDim m_stride{0};
95 std::unique_ptr<detail::InternalSurface> m_impl;
96};
97
98}
99}
100
101#endif
32 bit RGBA color.
Definition color.h:41
Definition surface.h:34
void * data()
Definition surface.h:57
std::function< void(void *)> ReleaseFunction
Definition surface.h:36
EGT_NODISCARD const detail::InternalSurface & impl() const
Definition surface.h:80
DefaultDim width() const
Definition surface.h:62
const void * data() const
Definition surface.h:58
Surface(Surface &&rhs)
std::unique_ptr< detail::InternalSurface > m_impl
Definition surface.h:95
bool empty() const
Definition surface.h:55
Surface(const detail::FrameBuffer &fb)
void flood(const Point &point, const Color &color)
static DefaultDim stride(PixelFormat format, DefaultDim width)
EGT_NODISCARD Color color_at(const Point &point) const
ReleaseFunction m_release
Definition surface.h:91
Surface & operator=(const Surface &)=delete
PixelFormat format() const
Definition surface.h:61
void sync_for_cpu() const
Claim the surface for being used by the CPU.
Surface(void *data, const ReleaseFunction &release, const Size &size, PixelFormat format, DefaultDim stride)
DefaultDim stride() const
Definition surface.h:64
Surface(const Size &size={}, PixelFormat format=PixelFormat::argb8888)
Surface & operator=(Surface &&rhs)
void write_to_png(const std::string &name) const
const Size & size() const
Definition surface.h:60
Size m_size
Definition surface.h:92
void flush(bool claimed_by_cpu=false) const
Surface(const Surface &)=delete
void color_at(const Point &point, const Color &color)
DefaultDim height() const
Definition surface.h:63
PixelFormat
Supported pixel formats.
Definition types.h:30
int DefaultDim
Define the default dimension type used for geometry.
Definition geometry.h:34
EGT framework namespace.
Definition animation.h:24