ReactOS 0.4.16-dev-2122-g1628f5e
vidfb.h File Reference
#include "twidbits.h"
Include dependency graph for vidfb.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _PIXEL_BITMASK
 Physical format of an RGB pixel, specified with per-component bit-masks. A bit being set defines those used for the given color component, such as Red, Green, Blue, or Reserved. More...
 

Typedefs

typedef struct _PIXEL_BITMASK PIXEL_BITMASK
 Physical format of an RGB pixel, specified with per-component bit-masks. A bit being set defines those used for the given color component, such as Red, Green, Blue, or Reserved.
 
typedef struct _PIXEL_BITMASKPPIXEL_BITMASK
 

Functions

FORCEINLINE ULONG PixelBitmasksToBpp (_In_ ULONG RedMask, _In_ ULONG GreenMask, _In_ ULONG BlueMask, _In_ ULONG ReservedMask)
 Calculates the number of bits per pixel ("PixelDepth") for the given pixel format, given by the pixel color masks.
 
BOOLEAN VidFbInitializeVideo (_In_ ULONG_PTR BaseAddress, _In_ ULONG BufferSize, _In_ UINT32 ScreenWidth, _In_ UINT32 ScreenHeight, _In_ UINT32 PixelsPerScanLine, _In_ UINT32 BitsPerPixel, _In_opt_ PPIXEL_BITMASK PixelMasks)
 Initializes internal framebuffer information based on the given parameters.
 
VOID VidFbClearScreenColor (_In_ UINT32 Color, _In_ BOOLEAN FullScreen)
 
VOID VidFbOutputChar (_In_ UCHAR Char, _In_ ULONG X, _In_ ULONG Y, _In_ UINT32 FgColor, _In_ UINT32 BgColor)
 Displays a character at a given pixel position with specific foreground and background colors.
 
VOID VidFbGetDisplaySize (_Out_ PULONG Width, _Out_ PULONG Height, _Out_ PULONG Depth)
 Returns the width and height in pixels, of the whole visible area of the graphics framebuffer.
 
ULONG VidFbGetBufferSize (VOID)
 Returns the size in bytes, of a full graphics pixel buffer rectangle that can fill the whole visible area of the graphics framebuffer.
 
VOID VidFbScrollUp (_In_ UINT32 Color, _In_ ULONG Scroll)
 
VOID FbConsClearScreen (_In_ UCHAR Attr)
 
VOID FbConsOutputChar (_In_ UCHAR Char, _In_ ULONG Column, _In_ ULONG Row, _In_ UINT32 FgColor, _In_ UINT32 BgColor)
 Displays a character at a given position with specific foreground and background colors.
 
VOID FbConsPutChar (_In_ UCHAR Char, _In_ UCHAR Attr, _In_ ULONG Column, _In_ ULONG Row)
 Displays a character with specific text attributes at a given position.
 
VOID FbConsGetDisplaySize (_Out_ PULONG Width, _Out_ PULONG Height, _Out_ PULONG Depth)
 Returns the width and height in number of CGA characters/attributes, of a full text-mode CGA-style character buffer rectangle that can fill the whole console.
 
ULONG FbConsGetBufferSize (VOID)
 Returns the size in bytes, of a full text-mode CGA-style character buffer rectangle that can fill the whole console.
 
VOID FbConsCopyOffScreenBufferToVRAM (_In_ PVOID Buffer)
 Copies a full text-mode CGA-style character buffer rectangle to the console.
 
VOID FbConsScrollUp (_In_ UCHAR Attr)
 

Typedef Documentation

◆ PIXEL_BITMASK

Physical format of an RGB pixel, specified with per-component bit-masks. A bit being set defines those used for the given color component, such as Red, Green, Blue, or Reserved.

Note
Supports up to 32 bits-per-pixel deep pixels.

◆ PPIXEL_BITMASK

Function Documentation

◆ FbConsClearScreen()

VOID FbConsClearScreen ( _In_ UCHAR  Attr)

Definition at line 377 of file vidfb.c.

379{
380 UINT32 FgColor, BgColor;
381 FbConsAttrToColors(Attr, &FgColor, &BgColor);
383}
unsigned int UINT32
#define FALSE
Definition: types.h:117
VOID VidFbClearScreenColor(_In_ UINT32 Color, _In_ BOOLEAN FullScreen)
Definition: vidfb.c:194
static VOID FbConsAttrToColors(_In_ UCHAR Attr, _Out_ PUINT32 FgColor, _Out_ PUINT32 BgColor)
Maps a text-mode CGA-style character attribute to separate foreground and background ARGB colors.
Definition: vidfb.c:367

Referenced by UefiVideoClearScreen(), and XboxVideoClearScreen().

◆ FbConsCopyOffScreenBufferToVRAM()

VOID FbConsCopyOffScreenBufferToVRAM ( _In_ PVOID  Buffer)

Copies a full text-mode CGA-style character buffer rectangle to the console.

Definition at line 456 of file vidfb.c.

458{
459 PUCHAR OffScreenBuffer = (PUCHAR)Buffer;
460 ULONG Row, Col;
461
462 // ULONG Width, Height, Depth;
463 // FbConsGetDisplaySize(&Width, &Height, &Depth);
465
466 for (Row = 0; Row < Height; ++Row)
467 {
468 for (Col = 0; Col < Width; ++Col)
469 {
470 FbConsPutChar(OffScreenBuffer[0], OffScreenBuffer[1], Col, Row);
471 OffScreenBuffer += VGA_CHAR_SIZE;
472 }
473 }
474}
Definition: bufpool.h:45
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
_In_ HFONT _Out_ PUINT _Out_ PUINT Width
Definition: font.h:89
_In_ HFONT _Out_ PUINT Height
Definition: font.h:88
#define FBCONS_WIDTH
Definition: vidfb.c:344
#define VGA_CHAR_SIZE
Definition: vidfb.c:342
#define FBCONS_HEIGHT
Definition: vidfb.c:345
VOID FbConsPutChar(_In_ UCHAR Char, _In_ UCHAR Attr, _In_ ULONG Column, _In_ ULONG Row)
Displays a character with specific text attributes at a given position.
Definition: vidfb.c:409

Referenced by UefiVideoCopyOffScreenBufferToVRAM(), and XboxVideoCopyOffScreenBufferToVRAM().

◆ FbConsGetBufferSize()

ULONG FbConsGetBufferSize ( VOID  )

Returns the size in bytes, of a full text-mode CGA-style character buffer rectangle that can fill the whole console.

Definition at line 445 of file vidfb.c.

446{
448}

Referenced by UefiVideoGetBufferSize(), and XboxVideoGetBufferSize().

◆ FbConsGetDisplaySize()

VOID FbConsGetDisplaySize ( _Out_ PULONG  Width,
_Out_ PULONG  Height,
_Out_ PULONG  Depth 
)

Returns the width and height in number of CGA characters/attributes, of a full text-mode CGA-style character buffer rectangle that can fill the whole console.

Definition at line 426 of file vidfb.c.

430{
431 // VidFbGetDisplaySize(Width, Height, Depth);
432 // *Width /= CHAR_WIDTH;
433 // *Height /= CHAR_HEIGHT;
437}
ULONG BitsPerPixel
Definition: vidfb.c:32
FRAMEBUFFER_INFO framebufInfo
Definition: vidfb.c:43
_In_opt_ PALLOCATE_FUNCTION _In_opt_ PFREE_FUNCTION _In_ ULONG _In_ SIZE_T _In_ ULONG _In_ USHORT Depth
Definition: exfuncs.h:819

Referenced by UefiVideoGetDisplaySize(), and XboxVideoGetDisplaySize().

◆ FbConsOutputChar()

VOID FbConsOutputChar ( _In_ UCHAR  Char,
_In_ ULONG  Column,
_In_ ULONG  Row,
_In_ UINT32  FgColor,
_In_ UINT32  BgColor 
)

Displays a character at a given position with specific foreground and background colors.

Definition at line 391 of file vidfb.c.

397{
398 /* Don't display outside of the screen */
399 if ((Column >= FBCONS_WIDTH) || (Row >= FBCONS_HEIGHT))
400 return;
401 VidFbOutputChar(Char, Column * CHAR_WIDTH, Row * CHAR_HEIGHT, FgColor, BgColor);
402}
#define CHAR_WIDTH
Definition: vgafont.h:10
#define CHAR_HEIGHT
Definition: vgafont.h:11
VOID VidFbOutputChar(_In_ UCHAR Char, _In_ ULONG X, _In_ ULONG Y, _In_ UINT32 FgColor, _In_ UINT32 BgColor)
Displays a character at a given pixel position with specific foreground and background colors.
Definition: vidfb.c:217

Referenced by FbConsPutChar().

◆ FbConsPutChar()

VOID FbConsPutChar ( _In_ UCHAR  Char,
_In_ UCHAR  Attr,
_In_ ULONG  Column,
_In_ ULONG  Row 
)

Displays a character with specific text attributes at a given position.

Definition at line 409 of file vidfb.c.

414{
415 UINT32 FgColor, BgColor;
416 FbConsAttrToColors(Attr, &FgColor, &BgColor);
417 FbConsOutputChar(Char, Column, Row, FgColor, BgColor);
418}
VOID FbConsOutputChar(_In_ UCHAR Char, _In_ ULONG Column, _In_ ULONG Row, _In_ UINT32 FgColor, _In_ UINT32 BgColor)
Displays a character at a given position with specific foreground and background colors.
Definition: vidfb.c:391

Referenced by FbConsCopyOffScreenBufferToVRAM(), UefiVideoPutChar(), and XboxVideoPutChar().

◆ FbConsScrollUp()

VOID FbConsScrollUp ( _In_ UCHAR  Attr)

Definition at line 477 of file vidfb.c.

479{
480 UINT32 BgColor, Dummy;
481 FbConsAttrToColors(Attr, &Dummy, &BgColor);
482 VidFbScrollUp(BgColor, CHAR_HEIGHT);
483}
VOID VidFbScrollUp(_In_ UINT32 Color, _In_ ULONG Scroll)
Definition: vidfb.c:281

Referenced by UefiConsPutChar(), and XboxConsPutChar().

◆ PixelBitmasksToBpp()

FORCEINLINE ULONG PixelBitmasksToBpp ( _In_ ULONG  RedMask,
_In_ ULONG  GreenMask,
_In_ ULONG  BlueMask,
_In_ ULONG  ReservedMask 
)

Calculates the number of bits per pixel ("PixelDepth") for the given pixel format, given by the pixel color masks.

Remarks
See UEFI Spec Rev.2.10 Section 12.9 "Graphics Output Protocol": example code "GetPixelElementSize()" function.

Definition at line 41 of file vidfb.h.

46{
47 ULONG CompoundMask = (RedMask | GreenMask | BlueMask | ReservedMask);
48 /* Alternatively, the calculation could be done by finding the highest
49 * bit set in the combined pixel color masks, if they are packed together. */
50 return CountNumberOfBits(CompoundMask); // FindHighestSetBit(CompoundMask);
51}
FORCEINLINE ULONG CountNumberOfBits(_In_ UINT32 n)
Return the number of bits set in a 32-bit integer.
Definition: twidbits.h:22

Referenced by UefiInitializeVideo(), and VidFbInitializeVideo().

◆ VidFbClearScreenColor()

VOID VidFbClearScreenColor ( _In_ UINT32  Color,
_In_ BOOLEAN  FullScreen 
)

Definition at line 194 of file vidfb.c.

197{
198 ULONG Line, Col;
199 PUINT32 p;
200
201 for (Line = 0; Line < framebufInfo.ScreenHeight - (FullScreen ? 0 : 2 * TOP_BOTTOM_LINES); Line++)
202 {
204 for (Col = 0; Col < framebufInfo.ScreenWidth; Col++)
205 {
206 *p++ = Color;
207 }
208 }
209}
unsigned int * PUINT32
Definition: basetsd.h:119
GLfloat GLfloat p
Definition: glext.h:8902
Definition: ncftp.h:79
ULONG_PTR BaseAddress
Definition: vidfb.c:24
ULONG ScreenHeight
Definition: vidfb.c:29
ULONG Delta
Definition: vidfb.c:40
ULONG ScreenWidth
Definition: vidfb.c:28
#define TOP_BOTTOM_LINES
Definition: vidfb.c:17

Referenced by FbConsClearScreen(), XboxVideoInit(), and XboxVideoPrepareForReactOS().

◆ VidFbGetBufferSize()

ULONG VidFbGetBufferSize ( VOID  )

Returns the size in bytes, of a full graphics pixel buffer rectangle that can fill the whole visible area of the graphics framebuffer.

Definition at line 274 of file vidfb.c.

◆ VidFbGetDisplaySize()

VOID VidFbGetDisplaySize ( _Out_ PULONG  Width,
_Out_ PULONG  Height,
_Out_ PULONG  Depth 
)

Returns the width and height in pixels, of the whole visible area of the graphics framebuffer.

Definition at line 258 of file vidfb.c.

◆ VidFbInitializeVideo()

BOOLEAN VidFbInitializeVideo ( _In_ ULONG_PTR  BaseAddress,
_In_ ULONG  BufferSize,
_In_ UINT32  ScreenWidth,
_In_ UINT32  ScreenHeight,
_In_ UINT32  PixelsPerScanLine,
_In_ UINT32  BitsPerPixel,
_In_opt_ PPIXEL_BITMASK  PixelMasks 
)

Initializes internal framebuffer information based on the given parameters.

Parameters
[in]BaseAddressThe framebuffer physical base address.
[in]BufferSizeThe framebuffer size, in bytes.
[in]ScreenWidth
[in]ScreenHeightThe width and height of the visible framebuffer area, in pixels.
[in]PixelsPerScanLineThe size in number of pixels of a whole horizontal video memory scanline.
[in]BitsPerPixelThe number of usable bits (not counting the reserved ones) per pixel.
[in]PixelMasksOptional pointer to a PIXEL_BITMASK structure describing the pixel format used by the framebuffer.
Returns
TRUE if initialization is successful; FALSE if not.

Definition at line 97 of file vidfb.c.

105{
107
109
114 framebufInfo.PixelsPerScanLine = PixelsPerScanLine;
115 framebufInfo.BitsPerPixel = BitsPerPixel;
116
117 framebufInfo.BytesPerPixel = ((BitsPerPixel + 7) & ~7) / 8; // Round up to nearest byte.
118 framebufInfo.Delta = (PixelsPerScanLine * framebufInfo.BytesPerPixel + 3) & ~3;
119
120 /* We currently only support 32bpp */
121 if (BitsPerPixel != 32)
122 {
123 /* Unsupported BPP */
124 ERR("Unsupported %lu bits per pixel format\n", BitsPerPixel);
125 return FALSE;
126 }
127
128 //ASSERT((BitsPerPixel <= 8 && !PixelMasks) || (BitsPerPixel > 8));
129 if (BitsPerPixel > 8)
130 {
131 if (!PixelMasks ||
132 (PixelMasks->RedMask == 0 &&
133 PixelMasks->GreenMask == 0 &&
134 PixelMasks->BlueMask == 0 /* &&
135 PixelMasks->ReservedMask == 0 */))
136 {
137 /* Determine pixel mask given color depth and color channel */
138 switch (BitsPerPixel)
139 {
140 case 32:
141 case 24: /* 8:8:8 */
142 BitMasks->RedMask = 0x00FF0000; // 0x00FF0000;
143 BitMasks->GreenMask = 0x0000FF00; // 0x00FF0000 >> 8;
144 BitMasks->BlueMask = 0x000000FF; // 0x00FF0000 >> 16;
145 BitMasks->ReservedMask = ((1 << (BitsPerPixel - 24)) - 1) << 24;
146 break;
147 case 16: /* 5:6:5 */
148 BitMasks->RedMask = 0xF800; // 0xF800;
149 BitMasks->GreenMask = 0x07E0; // (0xF800 >> 5) | 0x20;
150 BitMasks->BlueMask = 0x001F; // 0xF800 >> 11;
151 BitMasks->ReservedMask = 0;
152 break;
153 case 15: /* 5:5:5 */
154 BitMasks->RedMask = 0x7C00; // 0x7C00;
155 BitMasks->GreenMask = 0x03E0; // 0x7C00 >> 5;
156 BitMasks->BlueMask = 0x001F; // 0x7C00 >> 10;
157 BitMasks->ReservedMask = 0x8000;
158 break;
159 default:
160 /* Unsupported BPP */
162 RtlZeroMemory(BitMasks, sizeof(*BitMasks));
163 }
164 }
165 else
166 {
167 /* Copy the pixel masks */
168 RtlCopyMemory(BitMasks, PixelMasks, sizeof(*BitMasks));
169 }
170 }
171 else
172 {
173 /* Palettized modes don't use masks */
174 RtlZeroMemory(BitMasks, sizeof(*BitMasks));
175 }
176
177#if DBG
178 VidFbPrintFramebufferInfo();
179 {
180 ULONG BppFromMasks =
181 PixelBitmasksToBpp(BitMasks->RedMask,
182 BitMasks->GreenMask,
183 BitMasks->BlueMask,
184 BitMasks->ReservedMask);
185 TRACE("BitsPerPixel = %lu , BppFromMasks = %lu\n", BitsPerPixel, BppFromMasks);
186 //ASSERT(BitsPerPixel == BppFromMasks);
187 }
188#endif
189
190 return TRUE;
191}
#define ERR(fmt,...)
Definition: precomp.h:57
#define UNIMPLEMENTED
Definition: ntoskrnl.c:15
#define BufferSize
Definition: mmc.h:75
#define TRUE
Definition: types.h:120
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
static ULONG ScreenWidth
Definition: pcvideo.c:116
static ULONG ScreenHeight
Definition: pcvideo.c:117
#define TRACE(s)
Definition: solgame.cpp:4
ULONG BufferSize
Definition: vidfb.c:25
ULONG PixelsPerScanLine
Definition: vidfb.c:31
PIXEL_BITMASK PixelMasks
Definition: vidfb.c:35
Physical format of an RGB pixel, specified with per-component bit-masks. A bit being set defines thos...
Definition: vidfb.h:22
ULONG RedMask
Definition: vidfb.h:23
ULONG BlueMask
Definition: vidfb.h:25
ULONG GreenMask
Definition: vidfb.h:24
ULONG ReservedMask
Definition: vidfb.h:26
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
FORCEINLINE ULONG PixelBitmasksToBpp(_In_ ULONG RedMask, _In_ ULONG GreenMask, _In_ ULONG BlueMask, _In_ ULONG ReservedMask)
Calculates the number of bits per pixel ("PixelDepth") for the given pixel format,...
Definition: vidfb.h:41

Referenced by UefiInitializeVideo(), and XboxVideoInit().

◆ VidFbOutputChar()

VOID VidFbOutputChar ( _In_ UCHAR  Char,
_In_ ULONG  X,
_In_ ULONG  Y,
_In_ UINT32  FgColor,
_In_ UINT32  BgColor 
)

Displays a character at a given pixel position with specific foreground and background colors.

Definition at line 217 of file vidfb.c.

223{
224 const UCHAR* FontPtr;
225 PUINT32 Pixel;
226 UCHAR Mask;
227 ULONG Line, Col;
228
229 /* Don't display outside of the screen, nor partial characters */
232 {
233 return;
234 }
235
236 FontPtr = BitmapFont8x16 + Char * CHAR_HEIGHT;
238 (Y + TOP_BOTTOM_LINES) * framebufInfo.Delta + X * sizeof(UINT32));
239
240 for (Line = 0; Line < CHAR_HEIGHT; Line++)
241 {
242 Mask = 0x80;
243 for (Col = 0; Col < CHAR_WIDTH; Col++)
244 {
245 Pixel[Col] = (0 != (FontPtr[Line] & Mask) ? FgColor : BgColor);
246 Mask = Mask >> 1;
247 }
248 Pixel = (PUINT32)((PUCHAR)Pixel + framebufInfo.Delta);
249 }
250}
#define Y(I)
unsigned int Mask
Definition: fpcontrol.c:82
const UCHAR BitmapFont8x16[256 *CHAR_HEIGHT]
Definition: vgafont.c:13
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by FbConsOutputChar().

◆ VidFbScrollUp()

VOID VidFbScrollUp ( _In_ UINT32  Color,
_In_ ULONG  Scroll 
)

Definition at line 281 of file vidfb.c.

284{
288
289 while (PixelCount--)
290 *Dst++ = *Src++;
291
292 for (PixelCount = 0; PixelCount < framebufInfo.ScreenWidth * Scroll; PixelCount++)
293 *Dst++ = Color;
294}
#define Dst
Definition: mesh.h:153

Referenced by FbConsScrollUp().