ReactOS 0.4.16-dev-2232-gc2aaa52
vidfb.c File Reference
#include <freeldr.h>
#include "vidfb.h"
#include "vgafont.h"
#include <debug.h>
Include dependency graph for vidfb.c:

Go to the source code of this file.

Classes

struct  _FRAMEBUFFER_INFO
 

Macros

#define TOP_BOTTOM_LINES   0
 
#define VGA_CHAR_SIZE   2
 
#define FBCONS_WIDTH   (framebufInfo.ScreenWidth / CHAR_WIDTH)
 
#define FBCONS_HEIGHT   ((framebufInfo.ScreenHeight - 2 * TOP_BOTTOM_LINES) / CHAR_HEIGHT)
 

Typedefs

typedef struct _FRAMEBUFFER_INFO FRAMEBUFFER_INFO
 
typedef struct _FRAMEBUFFER_INFOPFRAMEBUFFER_INFO
 

Functions

 DBG_DEFAULT_CHANNEL (UI)
 
BOOLEAN VidFbInitializeVideo (_Out_opt_ PCM_FRAMEBUF_DEVICE_DATA *pFbData, _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)
 
static UINT32 FbConsAttrToSingleColor (_In_ UCHAR Attr)
 
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.
 
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)
 

Variables

static FRAMEBUFFER_INFO framebufInfo = {0}
 
static CM_FRAMEBUF_DEVICE_DATA FrameBufferData = {0}
 

Macro Definition Documentation

◆ FBCONS_HEIGHT

Definition at line 381 of file vidfb.c.

◆ FBCONS_WIDTH

#define FBCONS_WIDTH   (framebufInfo.ScreenWidth / CHAR_WIDTH)

Definition at line 380 of file vidfb.c.

◆ TOP_BOTTOM_LINES

#define TOP_BOTTOM_LINES   0

Definition at line 17 of file vidfb.c.

◆ VGA_CHAR_SIZE

#define VGA_CHAR_SIZE   2

Definition at line 378 of file vidfb.c.

Typedef Documentation

◆ FRAMEBUFFER_INFO

◆ PFRAMEBUFFER_INFO

Function Documentation

◆ DBG_DEFAULT_CHANNEL()

DBG_DEFAULT_CHANNEL ( UI  )

◆ FbConsAttrToColors()

static VOID FbConsAttrToColors ( _In_ UCHAR  Attr,
_Out_ PUINT32  FgColor,
_Out_ PUINT32  BgColor 
)
static

Maps a text-mode CGA-style character attribute to separate foreground and background ARGB colors.

Definition at line 403 of file vidfb.c.

407{
408 *FgColor = FbConsAttrToSingleColor(Attr & 0x0F);
409 *BgColor = FbConsAttrToSingleColor((Attr >> 4) & 0x0F);
410}
static UINT32 FbConsAttrToSingleColor(_In_ UCHAR Attr)
Definition: vidfb.c:385

Referenced by FbConsClearScreen(), FbConsPutChar(), and FbConsScrollUp().

◆ FbConsAttrToSingleColor()

static UINT32 FbConsAttrToSingleColor ( _In_ UCHAR  Attr)
inlinestatic

Definition at line 385 of file vidfb.c.

387{
389 Intensity = (0 == (Attr & 0x08) ? 127 : 255);
390
391 return 0xff000000 |
392 (0 == (Attr & 0x04) ? 0 : (Intensity << 16)) |
393 (0 == (Attr & 0x02) ? 0 : (Intensity << 8)) |
394 (0 == (Attr & 0x01) ? 0 : Intensity);
395}
static WORD Intensity(RGBQUAD clr)
Definition: msrle32.c:44
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by FbConsAttrToColors().

◆ FbConsClearScreen()

VOID FbConsClearScreen ( _In_ UCHAR  Attr)

Definition at line 413 of file vidfb.c.

415{
416 UINT32 FgColor, BgColor;
417 FbConsAttrToColors(Attr, &FgColor, &BgColor);
419}
unsigned int UINT32
#define FALSE
Definition: types.h:117
VOID VidFbClearScreenColor(_In_ UINT32 Color, _In_ BOOLEAN FullScreen)
Definition: vidfb.c:230
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:403

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 492 of file vidfb.c.

494{
495 PUCHAR OffScreenBuffer = (PUCHAR)Buffer;
496 ULONG Row, Col;
497
498 // ULONG Width, Height, Depth;
499 // FbConsGetDisplaySize(&Width, &Height, &Depth);
501
502 for (Row = 0; Row < Height; ++Row)
503 {
504 for (Col = 0; Col < Width; ++Col)
505 {
506 FbConsPutChar(OffScreenBuffer[0], OffScreenBuffer[1], Col, Row);
507 OffScreenBuffer += VGA_CHAR_SIZE;
508 }
509 }
510}
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:380
#define VGA_CHAR_SIZE
Definition: vidfb.c:378
#define FBCONS_HEIGHT
Definition: vidfb.c:381
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:445

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 481 of file vidfb.c.

482{
484}

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 462 of file vidfb.c.

466{
467 // VidFbGetDisplaySize(Width, Height, Depth);
468 // *Width /= CHAR_WIDTH;
469 // *Height /= CHAR_HEIGHT;
473}
ULONG BitsPerPixel
Definition: vidfb.c:33
static FRAMEBUFFER_INFO framebufInfo
Definition: vidfb.c:44
_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 427 of file vidfb.c.

433{
434 /* Don't display outside of the screen */
435 if ((Column >= FBCONS_WIDTH) || (Row >= FBCONS_HEIGHT))
436 return;
437 VidFbOutputChar(Char, Column * CHAR_WIDTH, Row * CHAR_HEIGHT, FgColor, BgColor);
438}
#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:253

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 445 of file vidfb.c.

450{
451 UINT32 FgColor, BgColor;
452 FbConsAttrToColors(Attr, &FgColor, &BgColor);
453 FbConsOutputChar(Char, Column, Row, FgColor, BgColor);
454}
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:427

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

◆ FbConsScrollUp()

VOID FbConsScrollUp ( _In_ UCHAR  Attr)

Definition at line 513 of file vidfb.c.

515{
516 UINT32 BgColor, Dummy;
517 FbConsAttrToColors(Attr, &Dummy, &BgColor);
518 VidFbScrollUp(BgColor, CHAR_HEIGHT);
519}
VOID VidFbScrollUp(_In_ UINT32 Color, _In_ ULONG Scroll)
Definition: vidfb.c:317

Referenced by UefiConsPutChar(), and XboxConsPutChar().

◆ VidFbClearScreenColor()

VOID VidFbClearScreenColor ( _In_ UINT32  Color,
_In_ BOOLEAN  FullScreen 
)

Definition at line 230 of file vidfb.c.

233{
234 ULONG Line, Col;
235 PUINT32 p;
236
237 for (Line = 0; Line < framebufInfo.ScreenHeight - (FullScreen ? 0 : 2 * TOP_BOTTOM_LINES); Line++)
238 {
240 for (Col = 0; Col < framebufInfo.ScreenWidth; Col++)
241 {
242 *p++ = Color;
243 }
244 }
245}
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:41
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 310 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 294 of file vidfb.c.

◆ VidFbInitializeVideo()

BOOLEAN VidFbInitializeVideo ( _Out_opt_ PCM_FRAMEBUF_DEVICE_DATA pFbData,
_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 99 of file vidfb.c.

108{
110
111 if (pFbData)
112 *pFbData = NULL;
113
115
116 /* Verify framebuffer dimensions */
117 if ((ScreenWidth < 1) || (ScreenHeight < 1))
118 {
119 ERR("Invalid framebuffer dimensions\n");
120 return FALSE;
121 }
122
127 framebufInfo.PixelsPerScanLine = PixelsPerScanLine;
128 framebufInfo.BitsPerPixel = BitsPerPixel;
129
130 framebufInfo.BytesPerPixel = (BitsPerPixel + 7) / 8; // Round up to nearest byte.
131 framebufInfo.Delta = (PixelsPerScanLine * framebufInfo.BytesPerPixel + 3) & ~3;
132
133 /* Verify that the framebuffer fits inside the video RAM */
135 {
136 ERR("Framebuffer doesn't fit inside the video RAM (FB size: %lu, VRAM size: %lu)\n",
138 return FALSE;
139 }
140
141 /* We currently only support 32bpp */
142 if (BitsPerPixel != 32)
143 {
144 /* Unsupported BPP */
145 ERR("Unsupported %lu bits per pixel format\n", BitsPerPixel);
146 return FALSE;
147 }
148
149 //ASSERT((BitsPerPixel <= 8 && !PixelMasks) || (BitsPerPixel > 8));
150 if (BitsPerPixel > 8)
151 {
152 if (!PixelMasks ||
153 (PixelMasks->RedMask == 0 &&
154 PixelMasks->GreenMask == 0 &&
155 PixelMasks->BlueMask == 0 /* &&
156 PixelMasks->ReservedMask == 0 */))
157 {
158 /* Determine pixel mask given color depth and color channel */
159 switch (BitsPerPixel)
160 {
161 case 32:
162 case 24: /* 8:8:8 */
163 BitMasks->RedMask = 0x00FF0000; // 0x00FF0000;
164 BitMasks->GreenMask = 0x0000FF00; // 0x00FF0000 >> 8;
165 BitMasks->BlueMask = 0x000000FF; // 0x00FF0000 >> 16;
166 BitMasks->ReservedMask = ((1 << (BitsPerPixel - 24)) - 1) << 24;
167 break;
168 case 16: /* 5:6:5 */
169 BitMasks->RedMask = 0xF800; // 0xF800;
170 BitMasks->GreenMask = 0x07E0; // (0xF800 >> 5) | 0x20;
171 BitMasks->BlueMask = 0x001F; // 0xF800 >> 11;
172 BitMasks->ReservedMask = 0;
173 break;
174 case 15: /* 5:5:5 */
175 BitMasks->RedMask = 0x7C00; // 0x7C00;
176 BitMasks->GreenMask = 0x03E0; // 0x7C00 >> 5;
177 BitMasks->BlueMask = 0x001F; // 0x7C00 >> 10;
178 BitMasks->ReservedMask = 0x8000;
179 break;
180 default:
181 /* Unsupported BPP */
183 RtlZeroMemory(BitMasks, sizeof(*BitMasks));
184 }
185 }
186 else
187 {
188 /* Copy the pixel masks */
189 RtlCopyMemory(BitMasks, PixelMasks, sizeof(*BitMasks));
190 }
191 }
192 else
193 {
194 /* Palettized modes don't use masks */
195 RtlZeroMemory(BitMasks, sizeof(*BitMasks));
196 }
197
198#if DBG
199 VidFbPrintFramebufferInfo();
200 {
201 ULONG BppFromMasks =
202 PixelBitmasksToBpp(BitMasks->RedMask,
203 BitMasks->GreenMask,
204 BitMasks->BlueMask,
205 BitMasks->ReservedMask);
206 TRACE("BitsPerPixel = %lu , BppFromMasks = %lu\n", BitsPerPixel, BppFromMasks);
207 //ASSERT(BitsPerPixel == BppFromMasks);
208 }
209#endif
210
211 /* Initialize the hardware device configuration data if specified */
212 if (pFbData)
213 {
219
222
223 *pFbData = &FrameBufferData;
224 }
225
226 return TRUE;
227}
#define ERR(fmt,...)
Definition: precomp.h:57
#define UNIMPLEMENTED
Definition: ntoskrnl.c:15
#define BufferSize
Definition: mmc.h:75
#define NULL
Definition: types.h:112
#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 BitsPerPixel
Pixel depth.
Definition: framebuf.h:51
struct _CM_FRAMEBUF_DEVICE_DATA::@3616 PixelMasks
ULONG PixelsPerScanLine
Pitch/stride in pixels.
Definition: framebuf.h:50
ULONG BufferSize
Definition: vidfb.c:25
ULONG PixelsPerScanLine
Definition: vidfb.c:32
PIXEL_BITMASK PixelMasks
Definition: vidfb.c:36
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
static CM_FRAMEBUF_DEVICE_DATA FrameBufferData
Definition: vidfb.c:45
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
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254

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 253 of file vidfb.c.

259{
260 const UCHAR* FontPtr;
261 PUINT32 Pixel;
262 UCHAR Mask;
263 ULONG Line, Col;
264
265 /* Don't display outside of the screen, nor partial characters */
266 if ((X + CHAR_WIDTH - 1 >= framebufInfo.ScreenWidth) ||
268 {
269 return;
270 }
271
272 FontPtr = BitmapFont8x16 + Char * CHAR_HEIGHT;
274 (Y + TOP_BOTTOM_LINES) * framebufInfo.Delta + X * sizeof(UINT32));
275
276 for (Line = 0; Line < CHAR_HEIGHT; Line++)
277 {
278 Mask = 0x80;
279 for (Col = 0; Col < CHAR_WIDTH; Col++)
280 {
281 Pixel[Col] = (0 != (FontPtr[Line] & Mask) ? FgColor : BgColor);
282 Mask = Mask >> 1;
283 }
284 Pixel = (PUINT32)((PUCHAR)Pixel + framebufInfo.Delta);
285 }
286}
#define Y(I)
unsigned int Mask
Definition: fpcontrol.c:82
const UCHAR BitmapFont8x16[256 *CHAR_HEIGHT]
Definition: vgafont.c:13

Referenced by FbConsOutputChar().

◆ VidFbScrollUp()

VOID VidFbScrollUp ( _In_ UINT32  Color,
_In_ ULONG  Scroll 
)

Definition at line 317 of file vidfb.c.

320{
324
325 while (PixelCount--)
326 *Dst++ = *Src++;
327
328 for (PixelCount = 0; PixelCount < framebufInfo.ScreenWidth * Scroll; PixelCount++)
329 *Dst++ = Color;
330}
#define Dst
Definition: mesh.h:153

Referenced by FbConsScrollUp().

Variable Documentation

◆ FrameBufferData

CM_FRAMEBUF_DEVICE_DATA FrameBufferData = {0}
static

Definition at line 45 of file vidfb.c.

Referenced by VidFbInitializeVideo().

◆ framebufInfo