The Pedigree Project 0.1
Framebuffer.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 _MACHINE_FRAMEBUFFER_H
21#define _MACHINE_FRAMEBUFFER_H
22
23#include "pedigree/kernel/compiler.h"
24#include "pedigree/kernel/graphics/Graphics.h"
25#include "pedigree/kernel/processor/types.h"
26
35class EXPORTED_PUBLIC Framebuffer {
36 public:
38 virtual ~Framebuffer();
39
40 size_t getWidth() const;
41 size_t getHeight() const;
42
43 Graphics::PixelFormat getFormat() const;
44
45 bool getActive() const;
46
47 void setActive(bool b);
48
51 void setPalette(uint32_t* palette, size_t nEntries);
52
53 uint32_t* getPalette() const;
54
58 virtual void* getRawBuffer() const;
59
63 virtual physical_uintptr_t getPhysicalPage(size_t offset) const;
64
65 size_t getMappingFlags() const {
66 return m_MappingFlags;
67 }
68 void setMappingFlags(size_t flags) {
69 m_MappingFlags = flags;
70 }
71
86 virtual Graphics::Buffer* createBuffer(const void* srcData, Graphics::PixelFormat srcFormat,
87 size_t width, size_t height, uint32_t* pPalette = 0);
88
91 virtual void destroyBuffer(Graphics::Buffer* pBuffer);
92
107 void redraw(size_t x = ~0UL, size_t y = ~0UL, size_t w = ~0UL, size_t h = ~0UL,
108 bool bChild = false);
109
115 virtual void blit(Graphics::Buffer* pBuffer, size_t srcx, size_t srcy, size_t destx, size_t desty,
116 size_t width, size_t height, bool bLowestCall = true);
117
121 virtual void draw(void* pBuffer, size_t srcx, size_t srcy, size_t destx, size_t desty,
122 size_t width, size_t height,
123 Graphics::PixelFormat format = Graphics::Bits32_Argb, bool bLowestCall = true);
124
126 virtual void rect(size_t x, size_t y, size_t width, size_t height, uint32_t colour,
127 Graphics::PixelFormat format = Graphics::Bits32_Argb, bool bLowestCall = true);
128
130 virtual void copy(size_t srcx, size_t srcy, size_t destx, size_t desty, size_t w, size_t h,
131 bool bLowestCall = true);
132
134 virtual void line(size_t x1, size_t y1, size_t x2, size_t y2, uint32_t colour,
135 Graphics::PixelFormat format = Graphics::Bits32_Argb, bool bLowestCall = true);
136
138 void setPixel(size_t x, size_t y, uint32_t colour,
139 Graphics::PixelFormat format = Graphics::Bits32_Argb, bool bLowestCall = true);
140
146 size_t m_XPos;
147 void setXPos(size_t x);
148
150 size_t m_YPos;
151 void setYPos(size_t y);
152
154 size_t m_nWidth;
155 void setWidth(size_t w);
156
158 size_t m_nHeight;
159 void setHeight(size_t h);
160
162 Graphics::PixelFormat m_PixelFormat;
163 void setFormat(Graphics::PixelFormat pf);
164
167 void setBytesPerPixel(size_t b);
168 uint32_t getBytesPerPixel() const;
169
172 void setBytesPerLine(size_t b);
173 uint32_t getBytesPerLine() const;
174
177 void setParent(Framebuffer* p);
178 Framebuffer* getParent() const;
179
180 virtual void setFramebuffer(uintptr_t p);
181
182 private:
184 void swSetPixel(size_t x, size_t y, uint32_t colour,
185 Graphics::PixelFormat format = Graphics::Bits32_Argb);
186
187 protected:
188 // Base address of this framebuffer, set by whatever code inherits this
189 // class, ideally in the constructor.
190 uintptr_t m_FramebufferBase;
191
193 uint32_t* m_Palette;
194
197
198 Graphics::Buffer bufferFromSelf();
199
202 virtual void draw(Graphics::Buffer* pBuffer, size_t srcx, size_t srcy, size_t destx, size_t desty,
203 size_t width, size_t height, bool bLowestCall = true);
204
205 void swBlit(Graphics::Buffer* pBuffer, size_t srcx, size_t srcy, size_t destx, size_t desty,
206 size_t width, size_t height);
207
208 void swRect(size_t x, size_t y, size_t width, size_t height, uint32_t colour,
209 Graphics::PixelFormat format);
210
211 void swCopy(size_t srcx, size_t srcy, size_t destx, size_t desty, size_t w, size_t h);
212
213 void swLine(size_t x1, size_t y1, size_t x2, size_t y2, uint32_t colour,
214 Graphics::PixelFormat format);
215
216 void swDraw(void* pBuffer, size_t srcx, size_t srcy, size_t destx, size_t desty, size_t width,
217 size_t height, Graphics::PixelFormat format = Graphics::Bits32_Argb,
218 bool bLowestCall = true);
219
220 void swDraw(Graphics::Buffer* pBuffer, size_t srcx, size_t srcy, size_t destx, size_t desty,
221 size_t width, size_t height, bool bLowestCall = true);
222
223 Graphics::Buffer* swCreateBuffer(const void* srcData, Graphics::PixelFormat srcFormat,
224 size_t width, size_t height, uint32_t* pPalette);
225
226 void swDestroyBuffer(Graphics::Buffer* pBuffer);
227
229 virtual void hwRedraw(size_t x = ~0UL, size_t y = ~0UL, size_t w = ~0UL, size_t h = ~0UL);
230
231 private:
232 size_t m_MappingFlags = 0;
233};
234
235#endif
uint32_t * m_Palette
Current graphics palette - an array of 256 32-bit RGBA entries.
Graphics::PixelFormat m_PixelFormat
Framebuffer pixel format.
size_t m_nBytesPerPixel
Bytes per pixel in this framebuffer.
bool m_bActive
Whether this framebuffer is active or not.
size_t m_XPos
X position on our parent's framebuffer.
size_t m_nWidth
Width of the framebuffer in pixels.
size_t m_nHeight
Height of the framebuffer in pixels.
size_t m_YPos
Y position on our parent's framebuffer.
size_t m_nBytesPerLine
Bytes per line in this framebuffer.
Framebuffer * m_pParent
Parent of this framebuffer.