ReactOS 0.4.15-dev-7934-g1dc8d80
video.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

VOID ScreenEventHandler (PWINDOW_BUFFER_SIZE_RECORD ScreenEvent)
 
BOOLEAN VgaGetDoubleVisionState (PBOOLEAN Horizontal, PBOOLEAN Vertical)
 
BOOL VgaAttachToConsole (VOID)
 
VOID VgaDetachFromConsole (VOID)
 
VOID VgaConsoleUpdateTextCursor (BOOL CursorVisible, BYTE CursorStart, BYTE CursorEnd, BYTE TextSize, DWORD ScanlineSize, WORD Location)
 
BOOL VgaConsoleCreateGraphicsScreen (IN PCOORD Resolution, IN HANDLE PaletteHandle)
 
VOID VgaConsoleDestroyGraphicsScreen (VOID)
 
BOOL VgaConsoleCreateTextScreen (IN PCOORD Resolution, IN HANDLE PaletteHandle)
 
VOID VgaConsoleDestroyTextScreen (VOID)
 
VOID VgaConsoleRepaintScreen (PSMALL_RECT Rect)
 
BOOLEAN VgaConsoleInitialize (HANDLE TextHandle)
 
VOID VgaConsoleCleanup (VOID)
 

Function Documentation

◆ ScreenEventHandler()

VOID ScreenEventHandler ( PWINDOW_BUFFER_SIZE_RECORD  ScreenEvent)

Definition at line 448 of file video.c.

449{
450 /*
451 * This function monitors and allows console resizings only if they are triggered by us.
452 * User-driven resizings via the console properties, or programmatical console resizings
453 * made by explicit calls to SetConsoleScreenBufferSize by external applications, are forbidden.
454 * In that case only a console window resize is done in case the size is reduced.
455 * This protection is enabled in CONSRV side when NTVDM registers as a VDM to CONSRV,
456 * but we also implement it there in case we are running in STANDALONE mode without
457 * CONSRV registration.
458 *
459 * The only potential problem we have is that, when this handler is called,
460 * the console is already resized. In case this corresponds to a forbidden resize,
461 * we resize the console back to its original size from inside the handler.
462 * This will trigger a recursive call to the handler, that should be detected.
463 */
464
465 if (CurrResolution.X == ScreenEvent->dwSize.X &&
466 CurrResolution.Y == ScreenEvent->dwSize.Y)
467 {
468 /* Allowed resize, we are OK */
469 return;
470 }
471
472 DPRINT1("ScreenEventHandler - Detected forbidden resize! Reset console screenbuffer size back to (X = %d ; Y = %d)\n", CurrResolution.X, CurrResolution.Y);
473
474 // FIXME: If we're detaching, then stop monitoring for changes!!
475
476 /* Restore the original console size */
478
479 /* Force refresh of all the screen */
486}
#define DPRINT1
Definition: precomp.h:8
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
ULONG Y
Definition: bl.h:1340
ULONG X
Definition: bl.h:1339
SHORT Top
Definition: tui.c:25
SHORT Right
Definition: tui.c:26
SHORT Left
Definition: tui.c:24
SHORT Bottom
Definition: tui.c:27
static VOID ResizeTextConsole(PCOORD Resolution, PSMALL_RECT WindowSize OPTIONAL)
Definition: video.c:203
static COORD CurrResolution
Definition: svga.c:296
VOID VgaRefreshDisplay(VOID)
Definition: svga.c:1783
static BOOLEAN NeedsUpdate
Definition: svga.c:281
static SMALL_RECT UpdateRectangle
Definition: svga.c:298

Referenced by ConsoleEventThread().

◆ VgaAttachToConsole()

BOOL VgaAttachToConsole ( VOID  )

Definition at line 496 of file video.c.

497{
498 if (TextResolution.X == 0 || TextResolution.Y == 0)
499 DPRINT1("VgaAttachToConsole -- TextResolution uninitialized\n");
500
501 if (TextResolution.X == 0) TextResolution.X = 80;
502 if (TextResolution.Y == 0) TextResolution.Y = 25;
503
504 // DetachFromConsoleInternal();
505
506 /*
507 * AttachToConsoleInternal sets TextResolution
508 * to the new resolution and updates ConsoleInfo.
509 */
511 {
512 DisplayMessage(L"An unexpected error occurred!\n");
514 return FALSE;
515 }
516
517 /* Restore the original screen buffer */
520
521 /* Restore the screen state */
522 if (ScreenMode == TEXT_MODE)
523 {
524 /* The text mode framebuffer was recreated */
526 }
527 else
528 {
529 /* The graphics mode framebuffer is unchanged */
531 }
533
534 return TRUE;
535}
#define FALSE
Definition: types.h:117
VOID EmulatorTerminate(VOID)
Definition: emulator.c:503
#define L(x)
Definition: ntvdm.h:50
void DisplayMessage(BOOL bConsole, BOOL bSilent, LPCTSTR lpMessage, LPCTSTR lpTitle, UINT uType)
Definition: regsvr32.c:239
static PVOID OldConsoleFramebuffer
Definition: video.c:36
static BOOL AttachToConsoleInternal(PCOORD Resolution)
Definition: video.c:304
static VOID SetActiveScreenBuffer(HANDLE ScreenBuffer)
Definition: video.c:439
static HANDLE ScreenBufferHandle
Definition: video.c:35
static COORD TextResolution
Definition: video.c:48
@ TEXT_MODE
Definition: svga.c:291
static PCHAR_CELL TextFramebuffer
Definition: svga.c:224
static SCREEN_MODE ScreenMode
Definition: svga.c:295
static PVOID ActiveFramebuffer
ConsoleFramebuffer.
Definition: svga.c:211

Referenced by VidBiosAttachToConsole().

◆ VgaConsoleCleanup()

VOID VgaConsoleCleanup ( VOID  )

Definition at line 807 of file video.c.

808{
809 /* If the console video was not initialized, just return */
811 return;
812
814
815 // TODO: We need to initialize those events before using them!
819}
#define CloseHandle
Definition: compat.h:739
static HANDLE TextConsoleBuffer
Definition: video.c:46
static HANDLE EndEvent
Definition: video.c:70
static HANDLE StartEvent
Definition: video.c:69
static HANDLE AnotherEvent
Definition: video.c:71
VOID VgaDetachFromConsole(VOID)
Definition: video.c:537

Referenced by VgaCleanup().

◆ VgaConsoleCreateGraphicsScreen()

BOOL VgaConsoleCreateGraphicsScreen ( IN PCOORD  Resolution,
IN HANDLE  PaletteHandle 
)

Definition at line 610 of file video.c.

613{
614 DWORD i;
615 CONSOLE_GRAPHICS_BUFFER_INFO GraphicsBufferInfo;
616 BYTE BitmapInfoBuffer[VGA_BITMAP_INFO_SIZE];
617 LPBITMAPINFO BitmapInfo = (LPBITMAPINFO)BitmapInfoBuffer;
618 LPWORD PaletteIndex = (LPWORD)(BitmapInfo->bmiColors);
619
620 LONG Width = Resolution->X;
622
623 /* Use DoubleVision mode if the resolution is too small */
625 if (DoubleWidth) Width *= 2;
627 if (DoubleHeight) Height *= 2;
628
629 /* Fill the bitmap info header */
630 RtlZeroMemory(&BitmapInfo->bmiHeader, sizeof(BitmapInfo->bmiHeader));
631 BitmapInfo->bmiHeader.biSize = sizeof(BitmapInfo->bmiHeader);
632 BitmapInfo->bmiHeader.biWidth = Width;
633 BitmapInfo->bmiHeader.biHeight = Height;
634 BitmapInfo->bmiHeader.biBitCount = 8;
635 BitmapInfo->bmiHeader.biPlanes = 1;
636 BitmapInfo->bmiHeader.biCompression = BI_RGB;
637 BitmapInfo->bmiHeader.biSizeImage = Width * Height /* * 1 == biBitCount / 8 */;
638
639 /* Fill the palette data */
640 for (i = 0; i < (VGA_PALETTE_SIZE / 3); i++) PaletteIndex[i] = (WORD)i;
641
642 /* Fill the console graphics buffer info */
643 GraphicsBufferInfo.dwBitMapInfoLength = VGA_BITMAP_INFO_SIZE;
644 GraphicsBufferInfo.lpBitMapInfo = BitmapInfo;
645 GraphicsBufferInfo.dwUsage = DIB_PAL_COLORS;
646
647 /* Create the buffer */
650 NULL,
652 &GraphicsBufferInfo);
654
655 /* Save the framebuffer address and mutex */
656 // *GraphicsFramebuffer = GraphicsBufferInfo.lpBitMap;
657 GraphicsFramebuffer = GraphicsBufferInfo.lpBitMap;
658 ConsoleMutex = GraphicsBufferInfo.hMutex;
659
660 /* Clear the framebuffer */
661 // RtlZeroMemory(*GraphicsFramebuffer, BitmapInfo->bmiHeader.biSizeImage);
663
664 /* Set the graphics mode palette */
668
669 /* Set the active buffer */
671
672 return TRUE;
673}
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define GENERIC_READ
Definition: compat.h:135
#define FILE_SHARE_READ
Definition: compat.h:136
HANDLE WINAPI CreateConsoleScreenBuffer(DWORD dwDesiredAccess, DWORD dwShareMode, CONST SECURITY_ATTRIBUTES *lpSecurityAttributes, DWORD dwFlags, LPVOID lpScreenBufferData)
Definition: console.c:2313
BOOL WINAPI DECLSPEC_HOTPATCH SetConsolePalette(HANDLE hConsoleOutput, HPALETTE hPalette, UINT dwUsage)
Definition: console.c:1041
#define BI_RGB
Definition: precomp.h:56
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned short WORD
Definition: ntddk_ex.h:93
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define GENERIC_WRITE
Definition: nt_native.h:90
long LONG
Definition: pedump.c:60
LPBITMAPINFO lpBitMapInfo
Definition: wincon.h:230
USHORT biBitCount
Definition: precomp.h:46
ULONG biCompression
Definition: precomp.h:47
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1476
RGBQUAD bmiColors[1]
Definition: wingdi.h:1477
static HANDLE GraphicsConsoleBuffer
static PCHAR_CELL TextFramebuffer = NULL;
Definition: video.c:54
static BOOLEAN DoubleHeight
Definition: video.c:59
static HANDLE ConsoleMutex
static PVOID GraphicsFramebuffer = NULL;
Definition: video.c:56
static BOOLEAN DoubleWidth
Definition: video.c:58
static BYTE Resolution
Definition: mouse.c:35
static HPALETTE PaletteHandle
Definition: svga.c:215
static PBYTE GraphicsFramebuffer
Definition: svga.c:229
#define VGA_MINIMUM_WIDTH
Definition: svga.h:19
#define VGA_PALETTE_SIZE
Definition: svga.h:17
#define VGA_MINIMUM_HEIGHT
Definition: svga.h:20
#define VGA_BITMAP_INFO_SIZE
Definition: svga.h:18
uint16_t * LPWORD
Definition: typedefs.h:56
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
_In_ HFONT _Out_ PUINT _Out_ PUINT Width
Definition: font.h:89
_In_ HFONT _Out_ PUINT Height
Definition: font.h:88
#define CONSOLE_GRAPHICS_BUFFER
Definition: wincon.h:63
struct tagBITMAPINFO * LPBITMAPINFO
#define DIB_PAL_COLORS
Definition: wingdi.h:366
#define SYSPAL_NOSTATIC256
Definition: wingdi.h:21
unsigned char BYTE
Definition: xxhash.c:193

Referenced by VgaEnterNewMode().

◆ VgaConsoleCreateTextScreen()

BOOL VgaConsoleCreateTextScreen ( IN PCOORD  Resolution,
IN HANDLE  PaletteHandle 
)

Definition at line 698 of file video.c.

701{
702 /* Switch to the text buffer */
703 // FIXME: Wouldn't it be preferrable to switch to it AFTER we reset everything??
705
706 /* Adjust the text framebuffer if we changed the resolution */
707 if (TextResolution.X != Resolution->X ||
709 {
711
712 /*
713 * AttachToConsoleInternal sets TextResolution
714 * to the new resolution and updates ConsoleInfo.
715 */
717 {
718 DisplayMessage(L"An unexpected error occurred!\n");
720 return FALSE;
721 }
722 }
723 else
724 {
726 }
727
728 /*
729 * Set the text mode palette.
730 *
731 * INFORMATION: This call should fail on Windows (and therefore
732 * we get the default palette and our external behaviour is
733 * just like Windows' one), but it should success on ReactOS
734 * (so that we get console palette changes even for text-mode
735 * screen buffers, which is a new feature on ReactOS).
736 */
740
741 return TRUE;
742}
static VOID DetachFromConsoleInternal(VOID)
Definition: video.c:417
static VOID UpdateCursorPosition(VOID)
Definition: video.c:290

Referenced by VgaEnterNewMode().

◆ VgaConsoleDestroyGraphicsScreen()

VOID VgaConsoleDestroyGraphicsScreen ( VOID  )

Definition at line 675 of file video.c.

676{
677 /* Release the console framebuffer mutex */
679
680 /* Switch back to the default console text buffer */
681 // SetActiveScreenBuffer(TextConsoleBuffer);
682
683 /* Cleanup the video data */
686 // GraphicsFramebuffer = NULL;
689
690 // /* Reset the active framebuffer */
691 // ActiveFramebuffer = NULL;
692
695}
BOOL WINAPI DECLSPEC_HOTPATCH ReleaseMutex(IN HANDLE hMutex)
Definition: synch.c:618

Referenced by VgaLeaveCurrentMode().

◆ VgaConsoleDestroyTextScreen()

VOID VgaConsoleDestroyTextScreen ( VOID  )

Definition at line 744 of file video.c.

745{
746}

Referenced by VgaLeaveCurrentMode().

◆ VgaConsoleInitialize()

BOOLEAN VgaConsoleInitialize ( HANDLE  TextHandle)

Definition at line 783 of file video.c.

784{
785 /*
786 * Initialize the console video by saving the default
787 * text-mode console output handle, if it is valid.
788 */
789 if (!IsConsoleHandle(TextHandle)) return FALSE;
790 TextConsoleBuffer = TextHandle;
791
792 /* Save the original cursor and console screen buffer information */
795 {
797 return FALSE;
798 }
800
801 /* Switch to the text buffer, but do not enter into a text mode */
803
804 return TRUE;
805}
BOOL WINAPI GetConsoleScreenBufferInfo(IN HANDLE hConsoleOutput, OUT PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo)
Definition: console.c:595
BOOL WINAPI GetConsoleCursorInfo(HANDLE hConsoleOutput, PCONSOLE_CURSOR_INFO lpConsoleCursorInfo)
Definition: console.c:1702
#define IsConsoleHandle(h)
Definition: console.h:14
static CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo
Definition: video.c:47
static CONSOLE_SCREEN_BUFFER_INFO OrgConsoleBufferInfo
Definition: video.c:32
static CONSOLE_CURSOR_INFO OrgConsoleCursorInfo
Definition: video.c:31

Referenced by VgaInitialize().

◆ VgaConsoleRepaintScreen()

VOID VgaConsoleRepaintScreen ( PSMALL_RECT  Rect)

Definition at line 750 of file video.c.

751{
752 HANDLE ConsoleBufferHandle = NULL;
754
755 /* Check if we are in text or graphics mode */
757 {
758 /* Graphics mode */
759 ConsoleBufferHandle = GraphicsConsoleBuffer;
760
761 /* In DoubleVision mode, scale the update rectangle */
762 if (DoubleWidth)
763 {
766 }
767 if (DoubleHeight)
768 {
769 UpdateRectangle.Top *= 2;
771 }
772 }
773 else
774 {
775 /* Text mode */
776 ConsoleBufferHandle = TextConsoleBuffer;
777 }
778
779 /* Redraw the screen */
780 __InvalidateConsoleDIBits(ConsoleBufferHandle, &UpdateRectangle);
781}
BOOL __InvalidateConsoleDIBits(IN HANDLE hConsoleOutput, IN PSMALL_RECT lpRect)
Definition: video.c:158
@ GRAPHICS_MODE
Definition: svga.c:292

Referenced by VgaVerticalRetrace().

◆ VgaConsoleUpdateTextCursor()

VOID VgaConsoleUpdateTextCursor ( BOOL  CursorVisible,
BYTE  CursorStart,
BYTE  CursorEnd,
BYTE  TextSize,
DWORD  ScanlineSize,
WORD  Location 
)

Definition at line 575 of file video.c.

581{
583 CONSOLE_CURSOR_INFO CursorInfo;
584
585 if (CursorStart < CursorEnd)
586 {
587 /* Visible cursor */
588 CursorInfo.bVisible = CursorVisible;
589 CursorInfo.dwSize = (100 * (CursorEnd - CursorStart)) / TextSize;
590 }
591 else
592 {
593 /* Hidden cursor */
594 CursorInfo.bVisible = FALSE;
595 CursorInfo.dwSize = 1; // The size needs to be non-zero for SetConsoleCursorInfo to succeed.
596 }
597
598 /* Find the coordinates of the new position */
599 Position.X = (SHORT)(Location % ScanlineSize);
600 Position.Y = (SHORT)(Location / ScanlineSize);
601
602 DPRINT("VgaConsoleUpdateTextCursor: (X = %d ; Y = %d)\n", Position.X, Position.Y);
603
604 /* Update the physical cursor */
607}
BOOL WINAPI SetConsoleCursorPosition(IN HANDLE hConsoleOutput, IN COORD dwCursorPosition)
Definition: console.c:641
BOOL WINAPI SetConsoleCursorInfo(IN HANDLE hConsoleOutput, IN const CONSOLE_CURSOR_INFO *lpConsoleCursorInfo)
Definition: console.c:618
short SHORT
Definition: pedump.c:59
#define DPRINT
Definition: sndvol32.h:71
Definition: bl.h:1338
static COORD Position
Definition: mouse.c:34

Referenced by VgaUpdateTextCursor().

◆ VgaDetachFromConsole()

VOID VgaDetachFromConsole ( VOID  )
  • Update the physical cursor *‍/

Definition at line 537 of file video.c.

538{
540
541 /* Save the screen state */
542 if (ScreenMode == TEXT_MODE)
544 else
546
547 /* Reset the active framebuffer */
550
551 /* Restore the original console size */
553
554 /* Restore the original cursor shape */
556
557 // FIXME: Should we copy back the screen data to the screen buffer??
558 // WriteConsoleOutputA(...);
559
560 // FIXME: Should we change cursor POSITION??
561 // VgaUpdateTextCursor();
562
564 //SetConsoleCursorInfo(TextConsoleBuffer, &CursorInfo);
565 //SetConsoleCursorPosition(TextConsoleBuffer, Position /*OrgConsoleBufferInfo.dwCursorPosition*/);
566
567 /* Restore the old text-mode screen buffer */
569}

Referenced by VgaConsoleCleanup(), and VidBiosDetachFromConsole().

◆ VgaGetDoubleVisionState()

BOOLEAN VgaGetDoubleVisionState ( PBOOLEAN  Horizontal,
PBOOLEAN  Vertical 
)

Definition at line 488 of file video.c.

489{
490 if (GraphicsConsoleBuffer == NULL) return FALSE;
491 if (Horizontal) *Horizontal = DoubleWidth;
492 if (Vertical) *Vertical = DoubleHeight;
493 return TRUE;
494}

Referenced by DosMouseService(), DosUpdatePosition(), FromMouseCoordinates(), MouseEventHandler(), and ToMouseCoordinates().