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
79 virtual Graphics::Buffer* createBuffer(const void* srcData, Graphics::PixelFormat srcFormat,
80 size_t width, size_t height, uint32_t* pPalette = 0);
81
84 virtual void destroyBuffer(Graphics::Buffer* pBuffer);
85
100 void redraw(size_t x = ~0UL, size_t y = ~0UL, size_t w = ~0UL, size_t h = ~0UL,
101 bool bChild = false);
102
108 virtual void blit(Graphics::Buffer* pBuffer, size_t srcx, size_t srcy, size_t destx, size_t desty,
109 size_t width, size_t height, bool bLowestCall = true);
110
114 virtual void draw(void* pBuffer, size_t srcx, size_t srcy, size_t destx, size_t desty,
115 size_t width, size_t height,
116 Graphics::PixelFormat format = Graphics::Bits32_Argb, bool bLowestCall = true);
117
119 virtual void rect(size_t x, size_t y, size_t width, size_t height, uint32_t colour,
120 Graphics::PixelFormat format = Graphics::Bits32_Argb, bool bLowestCall = true);
121
123 virtual void copy(size_t srcx, size_t srcy, size_t destx, size_t desty, size_t w, size_t h,
124 bool bLowestCall = true);
125
127 virtual void line(size_t x1, size_t y1, size_t x2, size_t y2, uint32_t colour,
128 Graphics::PixelFormat format = Graphics::Bits32_Argb, bool bLowestCall = true);
129
131 void setPixel(size_t x, size_t y, uint32_t colour,
132 Graphics::PixelFormat format = Graphics::Bits32_Argb, bool bLowestCall = true);
133
139 size_t m_XPos;
140 void setXPos(size_t x);
141
143 size_t m_YPos;
144 void setYPos(size_t y);
145
147 size_t m_nWidth;
148 void setWidth(size_t w);
149
151 size_t m_nHeight;
152 void setHeight(size_t h);
153
155 Graphics::PixelFormat m_PixelFormat;
156 void setFormat(Graphics::PixelFormat pf);
157
160 void setBytesPerPixel(size_t b);
161 uint32_t getBytesPerPixel() const;
162
165 void setBytesPerLine(size_t b);
166 uint32_t getBytesPerLine() const;
167
170 void setParent(Framebuffer* p);
171 Framebuffer* getParent() const;
172
173 virtual void setFramebuffer(uintptr_t p);
174
175 private:
177 void swSetPixel(size_t x, size_t y, uint32_t colour,
178 Graphics::PixelFormat format = Graphics::Bits32_Argb);
179
180 protected:
181 // Base address of this framebuffer, set by whatever code inherits this
182 // class, ideally in the constructor.
183 uintptr_t m_FramebufferBase;
184
186 uint32_t* m_Palette;
187
190
191 Graphics::Buffer bufferFromSelf();
192
195 virtual void draw(Graphics::Buffer* pBuffer, size_t srcx, size_t srcy, size_t destx, size_t desty,
196 size_t width, size_t height, bool bLowestCall = true);
197
198 void swBlit(Graphics::Buffer* pBuffer, size_t srcx, size_t srcy, size_t destx, size_t desty,
199 size_t width, size_t height);
200
201 void swRect(size_t x, size_t y, size_t width, size_t height, uint32_t colour,
202 Graphics::PixelFormat format);
203
204 void swCopy(size_t srcx, size_t srcy, size_t destx, size_t desty, size_t w, size_t h);
205
206 void swLine(size_t x1, size_t y1, size_t x2, size_t y2, uint32_t colour,
207 Graphics::PixelFormat format);
208
209 void swDraw(void* pBuffer, size_t srcx, size_t srcy, size_t destx, size_t desty, size_t width,
210 size_t height, Graphics::PixelFormat format = Graphics::Bits32_Argb,
211 bool bLowestCall = true);
212
213 void swDraw(Graphics::Buffer* pBuffer, size_t srcx, size_t srcy, size_t destx, size_t desty,
214 size_t width, size_t height, bool bLowestCall = true);
215
216 Graphics::Buffer* swCreateBuffer(const void* srcData, Graphics::PixelFormat srcFormat,
217 size_t width, size_t height, uint32_t* pPalette);
218
219 void swDestroyBuffer(Graphics::Buffer* pBuffer);
220
222 virtual void hwRedraw(size_t x = ~0UL, size_t y = ~0UL, size_t w = ~0UL, size_t h = ~0UL);
223};
224
225#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.