HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
gfx_surface.hpp
1// Copyright Take Vos 2021.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "gfx_surface_state.hpp"
8#include "draw_context.hpp"
9#include "subpixel_orientation.hpp"
10#include "gfx_system_globals.hpp"
11
12namespace tt {
13class gfx_device;
14class gfx_system;
15
17public:
18 gfx_system &system;
19
20 gfx_surface_state state = gfx_surface_state::no_device;
21
24
27 subpixel_orientation subpixel_orientation = subpixel_orientation::BlueRight;
28 // subpixel_orientation subpixel_orientation = subpixel_orientation::Unknown;
29
30 virtual ~gfx_surface() {}
31
32 gfx_surface(const gfx_surface &) = delete;
33 gfx_surface &operator=(const gfx_surface &) = delete;
34 gfx_surface(gfx_surface &&) = delete;
35 gfx_surface &operator=(gfx_surface &&) = delete;
36
37 virtual void init() {}
38
39 gfx_surface(gfx_system &system) : system(system) {}
40
46 virtual void set_device(gfx_device *device) noexcept;
47
48 [[nodiscard]] gfx_device *device() const noexcept
49 {
50 tt_axiom(gfx_system_mutex.recurse_lock_count());
51 return _device;
52 }
53
54 void set_closed() noexcept
55 {
56 ttlet lock = std::scoped_lock(gfx_system_mutex);
57 state = gfx_surface_state::window_lost;
58 }
59
60 [[nodiscard]] bool is_closed() const noexcept
61 {
62 ttlet lock = std::scoped_lock(gfx_system_mutex);
63 return state == gfx_surface_state::no_window;
64 }
65
73 [[nodiscard]] virtual extent2 update(extent2 minimum_size, extent2 maximum_size) noexcept = 0;
74
75 [[nodiscard]] virtual std::optional<draw_context> render_start(aarectangle redraw_rectangle) = 0;
76 virtual void render_finish(draw_context const &context, color background_color) = 0;
77
78protected:
79 gfx_device *_device = nullptr;
80
81 virtual void teardown() = 0;
82};
83
84}
This is a RGBA floating point color.
Definition color.hpp:36
Class which represents an axis-aligned rectangle.
Definition axis_aligned_rectangle.hpp:20
Draw context for drawing using the TTauri shaders.
Definition draw_context.hpp:29
Definition gfx_device.hpp:22
Definition gfx_surface.hpp:16
virtual void set_device(gfx_device *device) noexcept
virtual extent2 update(extent2 minimum_size, extent2 maximum_size) noexcept=0
Update the surface.
extent2 size
The current size of the surface.
Definition gfx_surface.hpp:23
Graphics system.
Definition gfx_system.hpp:21
int recurse_lock_count() const noexcept
This function should be used in tt_axiom() to check if the lock is held by current thread.
Definition unfair_recursive_mutex.hpp:60