The Pedigree Project 0.1
pedigree_fb.h
1/*
2 * Copyright (c) 2008-2014, Pedigree Developers
3 *
4 * Please see the CONTRIB file in the root of the source tree for a full
5 * list of contributors.
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
20#ifndef PEDIGREE_FB_FRAMEBUFFER_H
21#define PEDIGREE_FB_FRAMEBUFFER_H
22
23#include <signal.h>
24
25#include <cairo/cairo.h>
26#include <pedigree/fb.h>
27#include <sys/vt.h>
28
30class Framebuffer {
31 public:
33 virtual ~Framebuffer();
34
36 bool initialise();
37
39 bool claimTerminal();
40
42 class FrameGuard {
43 public:
44 explicit FrameGuard(const Framebuffer& framebuffer);
46 explicit operator bool() const {
47 return m_Active;
48 }
49
50 private:
51 FrameGuard(const FrameGuard&) = delete;
52 FrameGuard& operator=(const FrameGuard&) = delete;
53 sigset_t m_PreviousMask;
54 bool m_Masked;
55 bool m_Active;
56 };
57
59 bool takeRedraw();
60
62 void storeMode();
63
65 void restoreMode();
66
68 int enterMode(size_t desiredW, size_t desiredH, size_t desiredBpp);
69
71 int useCurrentMode();
72
74 void* getFramebuffer() const {
75 return m_pFramebuffer;
76 }
77
79 void flush(size_t x, size_t y, size_t w, size_t h);
80
82 cairo_format_t getFormat() const {
83 return m_Format;
84 }
85
87 size_t getWidth() const {
88 return m_Width;
89 }
90 size_t getHeight() const {
91 return m_Height;
92 }
93 size_t getBytesPerLine() const {
94 return m_BytesPerLine;
95 }
96
97 private:
98 int mapMode(const pedigree_fb_mode& mode);
99 static void terminalSignal(int signal);
100 void releaseTerminal();
101
102 void* m_pFramebuffer;
103 size_t m_FramebufferSize;
104
105 cairo_format_t m_Format;
106
107 size_t m_Width;
108 size_t m_Height;
109 size_t m_BytesPerLine;
110
111 int m_Fb;
112
113 bool m_bStoredMode;
114 pedigree_fb_mode m_StoredMode;
115
116 int m_Terminal = -1;
117 volatile sig_atomic_t m_TerminalActive = 1;
118 volatile sig_atomic_t m_TerminalRedraw = 0;
119 int m_PreviousDisplayMode = 0;
120 vt_mode m_PreviousTerminalMode = {};
121 struct sigaction m_PreviousReleaseAction = {};
122 struct sigaction m_PreviousAcquireAction = {};
123 sigset_t m_PreviousTerminalMask;
124};
125
126#endif
bool initialise()
Definition fb.cc:211
void flush(size_t x, size_t y, size_t w, size_t h)
Definition fb.cc:350
bool takeRedraw()
Definition fb.cc:172
void * getFramebuffer() const
Definition pedigree_fb.h:74
void restoreMode()
Definition fb.cc:236
cairo_format_t getFormat() const
Definition pedigree_fb.h:82
void storeMode()
Definition fb.cc:223
bool claimTerminal()
Definition fb.cc:88
int enterMode(size_t desiredW, size_t desiredH, size_t desiredBpp)
Definition fb.cc:316
size_t getWidth() const
Definition pedigree_fb.h:87
int useCurrentMode()
Definition fb.cc:303