The Pedigree Project  0.1
system/include/pedigree/kernel/machine/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 
33 {
34  public:
35  Framebuffer();
36  virtual ~Framebuffer();
37 
38  size_t getWidth() const;
39  size_t getHeight() const;
40 
41  Graphics::PixelFormat getFormat() const;
42 
43  bool getActive() const;
44 
45  void setActive(bool b);
46 
49  void setPalette(uint32_t *palette, size_t nEntries);
50 
51  uint32_t *getPalette() const;
52 
56  virtual void *getRawBuffer() const;
57 
72  virtual Graphics::Buffer *createBuffer(
73  const void *srcData, Graphics::PixelFormat srcFormat, size_t width,
74  size_t height, uint32_t *pPalette = 0);
75 
78  virtual void destroyBuffer(Graphics::Buffer *pBuffer);
79 
94  void redraw(
95  size_t x = ~0UL, size_t y = ~0UL, size_t w = ~0UL, size_t h = ~0UL,
96  bool bChild = false);
97 
103  virtual void blit(
104  Graphics::Buffer *pBuffer, size_t srcx, size_t srcy, size_t destx,
105  size_t desty, size_t width, size_t height, bool bLowestCall = true);
106 
110  virtual void draw(
111  void *pBuffer, size_t srcx, size_t srcy, size_t destx, size_t desty,
112  size_t width, size_t height,
113  Graphics::PixelFormat format = Graphics::Bits32_Argb,
114  bool bLowestCall = true);
115 
117  virtual void rect(
118  size_t x, size_t y, size_t width, size_t height, uint32_t colour,
119  Graphics::PixelFormat format = Graphics::Bits32_Argb,
120  bool bLowestCall = true);
121 
123  virtual void copy(
124  size_t srcx, size_t srcy, size_t destx, size_t desty, size_t w,
125  size_t h, bool bLowestCall = true);
126 
128  virtual void line(
129  size_t x1, size_t y1, size_t x2, size_t y2, uint32_t colour,
130  Graphics::PixelFormat format = Graphics::Bits32_Argb,
131  bool bLowestCall = true);
132 
134  void setPixel(
135  size_t x, size_t y, uint32_t colour,
136  Graphics::PixelFormat format = Graphics::Bits32_Argb,
137  bool bLowestCall = true);
138 
143  size_t m_XPos;
145  void setXPos(size_t x);
146 
148  size_t m_YPos;
149  void setYPos(size_t y);
150 
152  size_t m_nWidth;
153  void setWidth(size_t w);
154 
156  size_t m_nHeight;
157  void setHeight(size_t h);
158 
160  Graphics::PixelFormat m_PixelFormat;
161  void setFormat(Graphics::PixelFormat pf);
162 
165  void setBytesPerPixel(size_t b);
166  uint32_t getBytesPerPixel() const;
167 
170  void setBytesPerLine(size_t b);
171  uint32_t getBytesPerLine() const;
172 
175  void setParent(Framebuffer *p);
176  Framebuffer *getParent() const;
177 
178  virtual void setFramebuffer(uintptr_t p);
179 
180  private:
182  void swSetPixel(
183  size_t x, size_t y, uint32_t colour,
184  Graphics::PixelFormat format = Graphics::Bits32_Argb);
185 
186  protected:
187  // Base address of this framebuffer, set by whatever code inherits this
188  // class, ideally in the constructor.
189  uintptr_t m_FramebufferBase;
190 
192  uint32_t *m_Palette;
193 
195  bool m_bActive;
196 
197  Graphics::Buffer bufferFromSelf();
198 
201  virtual void draw(
202  Graphics::Buffer *pBuffer, size_t srcx, size_t srcy, size_t destx,
203  size_t desty, size_t width, size_t height, bool bLowestCall = true);
204 
205  void swBlit(
206  Graphics::Buffer *pBuffer, size_t srcx, size_t srcy, size_t destx,
207  size_t desty, size_t width, size_t height);
208 
209  void swRect(
210  size_t x, size_t y, size_t width, size_t height, uint32_t colour,
211  Graphics::PixelFormat format);
212 
213  void swCopy(
214  size_t srcx, size_t srcy, size_t destx, size_t desty, size_t w,
215  size_t h);
216 
217  void swLine(
218  size_t x1, size_t y1, size_t x2, size_t y2, uint32_t colour,
219  Graphics::PixelFormat format);
220 
221  void swDraw(
222  void *pBuffer, size_t srcx, size_t srcy, size_t destx, size_t desty,
223  size_t width, size_t height,
224  Graphics::PixelFormat format = Graphics::Bits32_Argb,
225  bool bLowestCall = true);
226 
227  void swDraw(
228  Graphics::Buffer *pBuffer, size_t srcx, size_t srcy, size_t destx,
229  size_t desty, size_t width, size_t height, bool bLowestCall = true);
230 
231  Graphics::Buffer *swCreateBuffer(
232  const void *srcData, Graphics::PixelFormat srcFormat, size_t width,
233  size_t height, uint32_t *pPalette);
234 
235  void swDestroyBuffer(Graphics::Buffer *pBuffer);
236 
238  virtual void hwRedraw(
239  size_t x = ~0UL, size_t y = ~0UL, size_t w = ~0UL, size_t h = ~0UL);
240 };
241 
242 #endif
bool m_bActive
Whether this framebuffer is active or not.
size_t m_nWidth
Width of the framebuffer in pixels.
uint32_t * m_Palette
Current graphics palette - an array of 256 32-bit RGBA entries.
size_t m_YPos
Y position on our parent's framebuffer.
size_t m_nBytesPerPixel
Bytes per pixel in this framebuffer.
Framebuffer * m_pParent
Parent of this framebuffer.
Abstracts the system's framebuffer offering.
Graphics::PixelFormat m_PixelFormat
Framebuffer pixel format.
size_t m_nBytesPerLine
Bytes per line in this framebuffer.
size_t m_nHeight
Height of the framebuffer in pixels.