Xyris  0.5
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
Graphics Namespace Reference

Namespaces

 Font
 

Data Structures

class  Framebuffer
 

Enumerations

enum  FramebufferMemoryModel { Undefined_FBMM = 0, RGB_FBMM = 1 }
 

Functions

FramebuffergetFramebuffer ()
 
void init (Framebuffer *fb)
 
void pixel (uint32_t x, uint32_t y, uint32_t color)
 
void putrect (uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint32_t color)
 
void resetDoubleBuffer ()
 
void swap ()
 

Enumeration Type Documentation

◆ FramebufferMemoryModel

Enumerator
Undefined_FBMM 
RGB_FBMM 

Definition at line 16 of file framebuffer.hpp.

16  {
17  Undefined_FBMM = 0,
18  RGB_FBMM = 1,
19 };

Function Documentation

◆ getFramebuffer()

Framebuffer * Graphics::getFramebuffer ( )

Get a pointer to the active framebuffer.

Returns
Framebuffer* Pointer to active framebuffer

Definition at line 81 of file framebuffer.cpp.

82 {
83  return framebuffer;
84 }

◆ init()

void Graphics::init ( Framebuffer fb)

Initializes the framebuffer (if available)

Definition at line 32 of file graphics.cpp.

33 {
34  // Get the framebuffer info
35  if (!(info = fb))
36  return;
37  // Ensure valid info is provided
38  if (!info->getAddress())
39  return;
40  // Map in the framebuffer
41  Logger::Debug(__func__, "==== MAP FRAMEBUFFER ====");
43  (uintptr_t)info->getAddress(),
44  (uintptr_t)info->getAddress() + (info->getPitch() * info->getHeight())
45  ));
46  // Alloc the backbuffer
47  backbuffer = malloc(info->getPitch() * info->getHeight());
48  memcpy(backbuffer, info->getAddress(), info->getPitch() * info->getHeight());
49 
50  initialized = true;
51 }
+ Here is the call graph for this function:

◆ pixel()

void Graphics::pixel ( uint32_t  x,
uint32_t  y,
uint32_t  color 
)

Draws a pixel at a given coordinate.

Parameters
xX-axis coordinate
yY-axis coordinate
colorHex color

Definition at line 53 of file graphics.cpp.

54 {
55  // Ensure framebuffer information exists
56  if (!initialized)
57  return;
58  if ((x <= info->getWidth()) && (y <= info->getHeight())) {
59  // Special thanks to the SkiftOS contributors.
60  uint8_t* pixel = (uint8_t*)backbuffer + (y * info->getPitch()) + (x * info->getPixelWidth());
61  // Pixel information
62  pixel[0] = (color >> info->getBlueMaskShift()) & 0xff; // B
63  pixel[1] = (color >> info->getGreenMaskShift()) & 0xff; // G
64  pixel[2] = (color >> info->getRedMaskShift()) & 0xff; // R
65  // Additional pixel information
66  if (info->getPixelWidth() == 4)
67  pixel[3] = 0x00;
68  }
69 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ putrect()

void Graphics::putrect ( uint32_t  x,
uint32_t  y,
uint32_t  w,
uint32_t  h,
uint32_t  color 
)

Draws and fills a rectangle of a given width and height, and color at the provided coordinates.

Parameters
xX-axis coordinate
yY-axis coordinate
wWidth
hHeight
colorHex color

Definition at line 71 of file graphics.cpp.

72 {
73  // Ensure framebuffer information exists
74  if (!initialized)
75  return;
76  for (uint32_t curr_x = x; curr_x <= x + w; curr_x++) {
77  for (uint32_t curr_y = y; curr_y <= y + h; curr_y++) {
78  // Extremely slow but good for debugging
79  pixel(curr_x, curr_y, color);
80  }
81  }
82  // Swap after doing a large operation
83  swap();
84 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ resetDoubleBuffer()

void Graphics::resetDoubleBuffer ( )

Fill the backbuffer with '0'.

Definition at line 86 of file graphics.cpp.

87 {
88  if (!initialized)
89  return;
90  memset(backbuffer, 0, (info->getPitch() * info->getHeight()));
91 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ swap()

void Graphics::swap ( )

Swap the data on backbuffer to memory video buffer and show in the screen.

Definition at line 93 of file graphics.cpp.

94 {
95  if (!initialized)
96  return;
97  memcpy(info->getAddress(), backbuffer, (info->getPitch() * info->getHeight()));
98 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:
Graphics::Framebuffer::getGreenMaskShift
uint8_t getGreenMaskShift()
Definition: framebuffer.hpp:41
Graphics::Framebuffer::getPitch
uint32_t getPitch()
Definition: framebuffer.hpp:37
Graphics::Framebuffer::getAddress
void * getAddress()
Definition: framebuffer.hpp:33
Graphics::Undefined_FBMM
@ Undefined_FBMM
Definition: framebuffer.hpp:17
Graphics::pixel
void pixel(uint32_t x, uint32_t y, uint32_t color)
Draws a pixel at a given coordinate.
Definition: graphics.cpp:53
Graphics::Framebuffer::getPixelWidth
uint8_t getPixelWidth()
Definition: framebuffer.hpp:44
Graphics::swap
void swap()
Swap the data on backbuffer to memory video buffer and show in the screen.
Definition: graphics.cpp:93
Graphics::Framebuffer::getBlueMaskShift
uint8_t getBlueMaskShift()
Definition: framebuffer.hpp:43
Graphics::RGB_FBMM
@ RGB_FBMM
Definition: framebuffer.hpp:18
Memory::Section
Definition: MemorySection.hpp:29
Graphics::Framebuffer::getRedMaskShift
uint8_t getRedMaskShift()
Definition: framebuffer.hpp:39
memcpy
void * memcpy(void *dstptr, const void *srcptr, size_t size)
Definition: string.cpp:141
Logger::Debug
static void Debug(const char *tag, const char *fmt,...)
Definition: Logger.cpp:71
malloc
void * malloc(size_t)
Graphics::Framebuffer::getHeight
uint32_t getHeight()
Definition: framebuffer.hpp:35
Memory::mapKernelRangeVirtual
void mapKernelRangeVirtual(Section sect)
Map an address range into the kernel virtual address space.
Definition: paging.cpp:192
memset
void * memset(void *bufptr, int value, size_t size)
Sets the number of bytes in memory at ptr to the value.
Definition: string.cpp:106