ReactOS  0.4.14-dev-98-gb0d4763
conoutput.c File Reference
#include "consrv.h"
#include "console.h"
#include "include/conio.h"
#include "include/conio2.h"
#include "conoutput.h"
#include "handle.h"
#include <debug.h>
Include dependency graph for conoutput.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

NTSTATUS TEXTMODE_BUFFER_Initialize (OUT PCONSOLE_SCREEN_BUFFER *Buffer, IN OUT PCONSOLE Console, IN PTEXTMODE_BUFFER_INFO TextModeInfo)
 
NTSTATUS GRAPHICS_BUFFER_Initialize (OUT PCONSOLE_SCREEN_BUFFER *Buffer, IN OUT PCONSOLE Console, IN PGRAPHICS_BUFFER_INFO GraphicsInfo)
 
VOID TEXTMODE_BUFFER_Destroy (IN OUT PCONSOLE_SCREEN_BUFFER Buffer)
 
VOID GRAPHICS_BUFFER_Destroy (IN OUT PCONSOLE_SCREEN_BUFFER Buffer)
 
NTSTATUS CONSOLE_SCREEN_BUFFER_Initialize (OUT PCONSOLE_SCREEN_BUFFER *Buffer, IN OUT PCONSOLE Console, IN SIZE_T Size)
 
VOID CONSOLE_SCREEN_BUFFER_Destroy (IN OUT PCONSOLE_SCREEN_BUFFER Buffer)
 
NTSTATUS FASTCALL ConDrvCreateScreenBuffer (OUT PCONSOLE_SCREEN_BUFFER *Buffer, IN OUT PCONSOLE Console, IN ULONG BufferType, IN PVOID ScreenBufferInfo)
 
static VOID ConioSetActiveScreenBuffer (PCONSOLE_SCREEN_BUFFER Buffer)
 
VOID WINAPI ConioDeleteScreenBuffer (PCONSOLE_SCREEN_BUFFER Buffer)
 
VOID FASTCALL ConioDrawConsole (PCONSOLE Console)
 
NTSTATUS NTAPI ConDrvSetConsoleActiveScreenBuffer (IN PCONSOLE Console, IN PCONSOLE_SCREEN_BUFFER Buffer)
 
PCONSOLE_SCREEN_BUFFER ConDrvGetActiveScreenBuffer (IN PCONSOLE Console)
 
NTSTATUS NTAPI ConDrvInvalidateBitMapRect (IN PCONSOLE Console, IN PCONSOLE_SCREEN_BUFFER Buffer, IN PSMALL_RECT Region)
 
NTSTATUS NTAPI ConDrvGetConsoleCursorInfo (IN PCONSOLE Console, IN PTEXTMODE_SCREEN_BUFFER Buffer, OUT PCONSOLE_CURSOR_INFO CursorInfo)
 
NTSTATUS NTAPI ConDrvSetConsoleCursorInfo (IN PCONSOLE Console, IN PTEXTMODE_SCREEN_BUFFER Buffer, IN PCONSOLE_CURSOR_INFO CursorInfo)
 
NTSTATUS NTAPI ConDrvSetConsoleCursorPosition (IN PCONSOLE Console, IN PTEXTMODE_SCREEN_BUFFER Buffer, IN PCOORD Position)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 19 of file conoutput.c.

Function Documentation

◆ ConDrvCreateScreenBuffer()

NTSTATUS FASTCALL ConDrvCreateScreenBuffer ( OUT PCONSOLE_SCREEN_BUFFER Buffer,
IN OUT PCONSOLE  Console,
IN ULONG  BufferType,
IN PVOID  ScreenBufferInfo 
)

Definition at line 72 of file conoutput.c.

76 {
78 
79  if ( Console == NULL || Buffer == NULL ||
80  (BufferType != CONSOLE_TEXTMODE_BUFFER && BufferType != CONSOLE_GRAPHICS_BUFFER) )
81  {
83  }
84 
85  if (BufferType == CONSOLE_TEXTMODE_BUFFER)
86  {
88  Console,
90  }
91  else if (BufferType == CONSOLE_GRAPHICS_BUFFER)
92  {
94  Console,
96  }
97  else
98  {
99  /* Never ever go there!! */
100  ASSERT(FALSE);
101  }
102 
103  /* Insert the newly created screen buffer into the list, if succeeded */
104  if (NT_SUCCESS(Status)) InsertHeadList(&Console->BufferList, &(*Buffer)->ListEntry);
105 
106  return Status;
107 }
CONSOLE_SCREEN_BUFFER_INFO ScreenBufferInfo
Definition: notevil.c:38
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
Definition: rtlfuncs.h:201
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS TEXTMODE_BUFFER_Initialize(OUT PCONSOLE_SCREEN_BUFFER *Buffer, IN PCONSOLE Console, IN HANDLE ProcessHandle, IN PTEXTMODE_BUFFER_INFO TextModeInfo)
Definition: text.c:62
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS GRAPHICS_BUFFER_Initialize(OUT PCONSOLE_SCREEN_BUFFER *Buffer, IN PCONSOLE Console, IN HANDLE ProcessHandle, IN PGRAPHICS_BUFFER_INFO GraphicsInfo)
Definition: graphics.c:44
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
#define CONSOLE_TEXTMODE_BUFFER
Definition: wincon.h:59
#define CONSOLE_GRAPHICS_BUFFER
Definition: wincon.h:60
CConsole Console
return STATUS_SUCCESS
Definition: btrfs.c:2966

◆ ConDrvGetActiveScreenBuffer()

PCONSOLE_SCREEN_BUFFER ConDrvGetActiveScreenBuffer ( IN PCONSOLE  Console)

Definition at line 182 of file conoutput.c.

183 {
184  return (Console ? Console->ActiveBuffer : NULL);
185 }
smooth NULL
Definition: ftsmooth.c:416
CConsole Console

◆ ConDrvGetConsoleCursorInfo()

NTSTATUS NTAPI ConDrvGetConsoleCursorInfo ( IN PCONSOLE  Console,
IN PTEXTMODE_SCREEN_BUFFER  Buffer,
OUT PCONSOLE_CURSOR_INFO  CursorInfo 
)

Definition at line 207 of file conoutput.c.

210 {
211  if (Console == NULL || Buffer == NULL || CursorInfo == NULL)
213 
214  /* Validity check */
215  ASSERT(Console == Buffer->Header.Console);
216 
217  *CursorInfo = Buffer->CursorInfo;
218  // CursorInfo->bVisible = Buffer->CursorInfo.bVisible;
219  // CursorInfo->dwSize = Buffer->CursorInfo.dwSize;
220 
221  return STATUS_SUCCESS;
222 }
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
CConsole Console
return STATUS_SUCCESS
Definition: btrfs.c:2966

◆ ConDrvInvalidateBitMapRect()

NTSTATUS NTAPI ConDrvInvalidateBitMapRect ( IN PCONSOLE  Console,
IN PCONSOLE_SCREEN_BUFFER  Buffer,
IN PSMALL_RECT  Region 
)

Definition at line 190 of file conoutput.c.

193 {
194  if (Console == NULL || Buffer == NULL || Region == NULL)
196 
197  /* Validity check */
198  ASSERT(Console == Buffer->Header.Console);
199 
200  /* If the output buffer is the current one, redraw the correct portion of the screen */
201  if (Buffer == Console->ActiveBuffer) ConioDrawRegion(Console, Region);
202 
203  return STATUS_SUCCESS;
204 }
#define ConioDrawRegion(Console, Region)
Definition: conio2.h:13
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
CConsole Console
return STATUS_SUCCESS
Definition: btrfs.c:2966

◆ ConDrvSetConsoleActiveScreenBuffer()

NTSTATUS NTAPI ConDrvSetConsoleActiveScreenBuffer ( IN PCONSOLE  Console,
IN PCONSOLE_SCREEN_BUFFER  Buffer 
)

Definition at line 158 of file conoutput.c.

160 {
161  if (Console == NULL || Buffer == NULL)
163 
164  /* Validity check */
165  ASSERT(Console == Buffer->Header.Console);
166 
167  if (Buffer == Console->ActiveBuffer) return STATUS_SUCCESS;
168 
169  /* If old buffer has no handles, it's now unreferenced */
170  if (Console->ActiveBuffer->Header.HandleCount == 0)
171  {
172  ConioDeleteScreenBuffer(Console->ActiveBuffer);
173  }
174 
175  /* Tie console to new buffer */
177 
178  return STATUS_SUCCESS;
179 }
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
static VOID ConioSetActiveScreenBuffer(PCONSOLE_SCREEN_BUFFER Buffer)
Definition: conoutput.c:149
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
VOID WINAPI ConioDeleteScreenBuffer(PCONSOLE_SCREEN_BUFFER Buffer)
Definition: conoutput.c:113
CConsole Console
return STATUS_SUCCESS
Definition: btrfs.c:2966

◆ ConDrvSetConsoleCursorInfo()

NTSTATUS NTAPI ConDrvSetConsoleCursorInfo ( IN PCONSOLE  Console,
IN PTEXTMODE_SCREEN_BUFFER  Buffer,
IN PCONSOLE_CURSOR_INFO  CursorInfo 
)

Definition at line 225 of file conoutput.c.

228 {
229  ULONG Size;
230  BOOLEAN Visible, Success = TRUE;
231 
232  if (Console == NULL || Buffer == NULL || CursorInfo == NULL)
234 
235  /* Validity check */
236  ASSERT(Console == Buffer->Header.Console);
237 
238  Size = min(max(CursorInfo->dwSize, 1), 100);
239  Visible = CursorInfo->bVisible;
240 
241  if ( (Size != Buffer->CursorInfo.dwSize) ||
242  (Visible && !Buffer->CursorInfo.bVisible) ||
243  (!Visible && Buffer->CursorInfo.bVisible) )
244  {
245  Buffer->CursorInfo.dwSize = Size;
246  Buffer->CursorInfo.bVisible = Visible;
247 
249  }
250 
252 }
#define max(a, b)
Definition: svc.c:63
#define TRUE
Definition: types.h:120
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define ConioSetCursorInfo(Console, Buff)
Definition: conio2.h:18
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
#define min(a, b)
Definition: monoChain.cc:55
CConsole Console
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2966

◆ ConDrvSetConsoleCursorPosition()

NTSTATUS NTAPI ConDrvSetConsoleCursorPosition ( IN PCONSOLE  Console,
IN PTEXTMODE_SCREEN_BUFFER  Buffer,
IN PCOORD  Position 
)

Definition at line 255 of file conoutput.c.

258 {
259  SHORT OldCursorX, OldCursorY;
260 
261  if (Console == NULL || Buffer == NULL || Position == NULL)
263 
264  /* Validity check */
265  ASSERT(Console == Buffer->Header.Console);
266 
267  if ( Position->X < 0 || Position->X >= Buffer->ScreenBufferSize.X ||
268  Position->Y < 0 || Position->Y >= Buffer->ScreenBufferSize.Y )
269  {
271  }
272 
273  OldCursorX = Buffer->CursorPosition.X;
274  OldCursorY = Buffer->CursorPosition.Y;
275  Buffer->CursorPosition = *Position;
276  // Buffer->CursorPosition.X = Position->X;
277  // Buffer->CursorPosition.Y = Position->Y;
278  if ( ((PCONSOLE_SCREEN_BUFFER)Buffer == Console->ActiveBuffer) &&
279  (!ConioSetScreenInfo(Console, (PCONSOLE_SCREEN_BUFFER)Buffer, OldCursorX, OldCursorY)) )
280  {
281  return STATUS_UNSUCCESSFUL;
282  }
283 
284  return STATUS_SUCCESS;
285 }
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
static COORD Position
Definition: mouse.c:34
short SHORT
Definition: pedump.c:59
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
ULONG X
Definition: bl.h:1340
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define ConioSetScreenInfo(Console, Buff, OldCursorX, OldCursorY)
Definition: conio2.h:20
CConsole Console
return STATUS_SUCCESS
Definition: btrfs.c:2966
ULONG Y
Definition: bl.h:1341

◆ ConioDeleteScreenBuffer()

VOID WINAPI ConioDeleteScreenBuffer ( PCONSOLE_SCREEN_BUFFER  Buffer)

Definition at line 113 of file conoutput.c.

114 {
115  PCONSOLE Console = Buffer->Header.Console;
116  PCONSOLE_SCREEN_BUFFER NewBuffer;
117 
118  RemoveEntryList(&Buffer->ListEntry);
119  if (Buffer == Console->ActiveBuffer)
120  {
121  /* Delete active buffer; switch to most recently created */
122  Console->ActiveBuffer = NULL;
123  if (!IsListEmpty(&Console->BufferList))
124  {
125  NewBuffer = CONTAINING_RECORD(Console->BufferList.Flink,
127  ListEntry);
128  ConioSetActiveScreenBuffer(NewBuffer);
129  }
130  }
131 
133 }
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
static VOID ConioSetActiveScreenBuffer(PCONSOLE_SCREEN_BUFFER Buffer)
Definition: conoutput.c:149
CConsole Console
VOID CONSOLE_SCREEN_BUFFER_Destroy(IN OUT PCONSOLE_SCREEN_BUFFER Buffer)
Definition: conoutput.c:55

Referenced by ConDrvDeleteConsole(), ConDrvSetConsoleActiveScreenBuffer(), and ConSrvCloseHandleEntry().

◆ ConioDrawConsole()

VOID FASTCALL ConioDrawConsole ( PCONSOLE  Console)

Definition at line 136 of file conoutput.c.

137 {
139  PCONSOLE_SCREEN_BUFFER ActiveBuffer = Console->ActiveBuffer;
140 
141  if (ActiveBuffer)
142  {
143  ConioInitRect(&Region, 0, 0, ActiveBuffer->ViewSize.Y - 1, ActiveBuffer->ViewSize.X - 1);
145  }
146 }
#define ConioDrawRegion(Console, Region)
Definition: conio2.h:13
ULONG X
Definition: bl.h:1340
#define ConioInitRect(Rect, top, left, bottom, right)
Definition: rect.h:20
CConsole Console
ULONG Y
Definition: bl.h:1341

◆ ConioSetActiveScreenBuffer()

static VOID ConioSetActiveScreenBuffer ( PCONSOLE_SCREEN_BUFFER  Buffer)
static

Definition at line 149 of file conoutput.c.

150 {
151  PCONSOLE Console = Buffer->Header.Console;
152  Console->ActiveBuffer = Buffer;
154  // ConioDrawConsole(Console);
155 }
Definition: bufpool.h:45
CConsole Console
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
#define ConioResizeTerminal(Console)
Definition: conio2.h:22

Referenced by ConDrvSetConsoleActiveScreenBuffer(), and ConioDeleteScreenBuffer().

◆ CONSOLE_SCREEN_BUFFER_Destroy()

VOID CONSOLE_SCREEN_BUFFER_Destroy ( IN OUT PCONSOLE_SCREEN_BUFFER  Buffer)

Definition at line 58 of file conoutput.c.

59 {
60  if (Buffer->Header.Type == TEXTMODE_BUFFER)
62  else if (Buffer->Header.Type == GRAPHICS_BUFFER)
64  else if (Buffer->Header.Type == SCREEN_BUFFER)
66  // else
67  // do_nothing;
68 }
#define TEXTMODE_BUFFER
Definition: pccons.c:21
VOID TEXTMODE_BUFFER_Destroy(IN OUT PCONSOLE_SCREEN_BUFFER Buffer)
Definition: text.c:123
Definition: bufpool.h:45
#define ConsoleFreeHeap(HeapBase)
Definition: heap.h:15
VOID GRAPHICS_BUFFER_Destroy(IN OUT PCONSOLE_SCREEN_BUFFER Buffer)
Definition: graphics.c:249

Referenced by GRAPHICS_BUFFER_Destroy(), GRAPHICS_BUFFER_Initialize(), TEXTMODE_BUFFER_Destroy(), and TEXTMODE_BUFFER_Initialize().

◆ CONSOLE_SCREEN_BUFFER_Initialize()

NTSTATUS CONSOLE_SCREEN_BUFFER_Initialize ( OUT PCONSOLE_SCREEN_BUFFER Buffer,
IN OUT PCONSOLE  Console,
IN SIZE_T  Size 
)

Definition at line 41 of file conoutput.c.

44 {
45  if (Buffer == NULL || Console == NULL)
47 
50 
51  /* Initialize the header with the default type */
52  ConSrvInitObject(&(*Buffer)->Header, SCREEN_BUFFER, Console);
53  (*Buffer)->Vtbl = NULL;
54  return STATUS_SUCCESS;
55 }
#define max(a, b)
Definition: svc.c:63
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define ConsoleAllocHeap(Flags, Size)
Definition: heap.h:14
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
VOID ConSrvInitObject(IN OUT PCONSOLE_IO_OBJECT Object, IN CONSOLE_IO_OBJECT_TYPE Type, IN PCONSOLE Console)
Definition: handle.c:294
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
CConsole Console
return STATUS_SUCCESS
Definition: btrfs.c:2966

◆ GRAPHICS_BUFFER_Destroy()

VOID GRAPHICS_BUFFER_Destroy ( IN OUT PCONSOLE_SCREEN_BUFFER  Buffer)

Definition at line 249 of file graphics.c.

250 {
252 
253  /*
254  * IMPORTANT !! Reinitialize the type so that we don't enter a recursive
255  * infinite loop when calling CONSOLE_SCREEN_BUFFER_Destroy.
256  */
257  Buffer->Header.Type = SCREEN_BUFFER;
258 
259  /*
260  * Uninitialize the graphics screen buffer
261  * in the reverse way we initialized it.
262  */
265  NtClose(Buff->hSection);
268  NtClose(Buff->Mutex);
270 
272 }
#define DUPLICATE_CLOSE_SOURCE
NTSTATUS NTAPI NtUnmapViewOfSection(IN HANDLE ProcessHandle, IN PVOID BaseAddress)
Definition: section.c:3782
LPBITMAPINFO BitMapInfo
Definition: conio.h:175
VOID CONSOLE_SCREEN_BUFFER_Destroy(IN OUT PCONSOLE_SCREEN_BUFFER Buffer)
Definition: conoutput.c:55
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
#define NtCurrentProcess()
Definition: nt_native.h:1657
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
struct _GRAPHICS_SCREEN_BUFFER * PGRAPHICS_SCREEN_BUFFER
#define ConsoleFreeHeap(HeapBase)
Definition: heap.h:15
NTSTATUS NTAPI NtDuplicateObject(IN HANDLE SourceProcessHandle, IN HANDLE SourceHandle, IN HANDLE TargetProcessHandle OPTIONAL, OUT PHANDLE TargetHandle OPTIONAL, IN ACCESS_MASK DesiredAccess, IN ULONG HandleAttributes, IN ULONG Options)
Definition: obhandle.c:3407

◆ GRAPHICS_BUFFER_Initialize()

NTSTATUS GRAPHICS_BUFFER_Initialize ( OUT PCONSOLE_SCREEN_BUFFER Buffer,
IN OUT PCONSOLE  Console,
IN PGRAPHICS_BUFFER_INFO  GraphicsInfo 
)

Definition at line 48 of file graphics.c.

51 {
53  PGRAPHICS_SCREEN_BUFFER NewBuffer = NULL;
54 
55  LARGE_INTEGER SectionSize;
56  ULONG ViewSize = 0;
58 
59  if (Buffer == NULL || Console == NULL || GraphicsInfo == NULL)
61 
62  *Buffer = NULL;
63 
65  Console,
66  sizeof(GRAPHICS_SCREEN_BUFFER));
67  if (!NT_SUCCESS(Status)) return Status;
68  NewBuffer->Header.Type = GRAPHICS_BUFFER;
69  NewBuffer->Vtbl = &GraphicsVtbl;
70 
71  /*
72  * Remember the handle to the process so that we can close or unmap
73  * correctly the allocated resources when the client releases the
74  * screen buffer.
75  */
76  ProcessHandle = CsrGetClientThread()->Process->ProcessHandle;
77  NewBuffer->ClientProcess = ProcessHandle;
78 
79  /* Get infos from the graphics buffer information structure */
80  NewBuffer->BitMapInfoLength = GraphicsInfo->Info.dwBitMapInfoLength;
81 
82  NewBuffer->BitMapInfo = ConsoleAllocHeap(HEAP_ZERO_MEMORY, NewBuffer->BitMapInfoLength);
83  if (NewBuffer->BitMapInfo == NULL)
84  {
87  }
88 
89  /* Adjust the bitmap height if needed (bottom-top vs. top-bottom). Use always bottom-up. */
90  if (GraphicsInfo->Info.lpBitMapInfo->bmiHeader.biHeight > 0)
91  GraphicsInfo->Info.lpBitMapInfo->bmiHeader.biHeight = -GraphicsInfo->Info.lpBitMapInfo->bmiHeader.biHeight;
92 
93  /* We do not use anything else than uncompressed bitmaps */
94  if (GraphicsInfo->Info.lpBitMapInfo->bmiHeader.biCompression != BI_RGB)
95  {
96  DPRINT1("biCompression == %d != BI_RGB, correct that!\n", GraphicsInfo->Info.lpBitMapInfo->bmiHeader.biCompression);
97  GraphicsInfo->Info.lpBitMapInfo->bmiHeader.biCompression = BI_RGB;
98  }
99 
100  RtlCopyMemory(NewBuffer->BitMapInfo,
101  GraphicsInfo->Info.lpBitMapInfo,
102  GraphicsInfo->Info.dwBitMapInfoLength);
103 
104  NewBuffer->BitMapUsage = GraphicsInfo->Info.dwUsage;
105 
106  /* Set the screen buffer size. Fight against overflows. */
107  if ( GraphicsInfo->Info.lpBitMapInfo->bmiHeader.biWidth <= 0xFFFF &&
108  -GraphicsInfo->Info.lpBitMapInfo->bmiHeader.biHeight <= 0xFFFF )
109  {
110  /* Be careful about the sign of biHeight */
111  NewBuffer->ScreenBufferSize.X = (SHORT)GraphicsInfo->Info.lpBitMapInfo->bmiHeader.biWidth ;
112  NewBuffer->ScreenBufferSize.Y = (SHORT)-GraphicsInfo->Info.lpBitMapInfo->bmiHeader.biHeight;
113 
114  NewBuffer->OldViewSize = NewBuffer->ViewSize =
115  NewBuffer->OldScreenBufferSize = NewBuffer->ScreenBufferSize;
116  }
117  else
118  {
120  ConsoleFreeHeap(NewBuffer->BitMapInfo);
122  goto Quit;
123  }
124 
125  /*
126  * Create a mutex to synchronize bitmap memory access
127  * between ourselves and the client.
128  */
129  Status = NtCreateMutant(&NewBuffer->Mutex, MUTANT_ALL_ACCESS, NULL, FALSE);
130  if (!NT_SUCCESS(Status))
131  {
132  DPRINT1("NtCreateMutant() failed: %lu\n", Status);
133  ConsoleFreeHeap(NewBuffer->BitMapInfo);
135  goto Quit;
136  }
137 
138  /*
139  * Duplicate the Mutex for the client. We must keep a trace of it
140  * so that we can close it when the client releases the screen buffer.
141  */
143  NewBuffer->Mutex,
145  &NewBuffer->ClientMutex,
146  0, 0, DUPLICATE_SAME_ACCESS);
147  if (!NT_SUCCESS(Status))
148  {
149  DPRINT1("NtDuplicateObject() failed: %lu\n", Status);
150  NtClose(NewBuffer->Mutex);
151  ConsoleFreeHeap(NewBuffer->BitMapInfo);
153  goto Quit;
154  }
155 
156  /*
157  * Create a memory section for the bitmap area, to share with the client.
158  */
159  SectionSize.QuadPart = NewBuffer->BitMapInfo->bmiHeader.biSizeImage;
160  Status = NtCreateSection(&NewBuffer->hSection,
162  NULL,
163  &SectionSize,
165  SEC_COMMIT,
166  NULL);
167  if (!NT_SUCCESS(Status))
168  {
169  DPRINT1("Error: Impossible to create a shared section ; Status = %lu\n", Status);
170  NtClose(NewBuffer->ClientMutex);
171  NtClose(NewBuffer->Mutex);
172  ConsoleFreeHeap(NewBuffer->BitMapInfo);
174  goto Quit;
175  }
176 
177  /*
178  * Create a view for our needs.
179  */
180  ViewSize = 0;
181  NewBuffer->BitMap = NULL;
182  Status = NtMapViewOfSection(NewBuffer->hSection,
184  (PVOID*)&NewBuffer->BitMap,
185  0,
186  0,
187  NULL,
188  &ViewSize,
189  ViewUnmap,
190  0,
192  if (!NT_SUCCESS(Status))
193  {
194  DPRINT1("Error: Impossible to map the shared section ; Status = %lu\n", Status);
195  NtClose(NewBuffer->hSection);
196  NtClose(NewBuffer->ClientMutex);
197  NtClose(NewBuffer->Mutex);
198  ConsoleFreeHeap(NewBuffer->BitMapInfo);
200  goto Quit;
201  }
202 
203  /*
204  * Create a view for the client. We must keep a trace of it so that
205  * we can unmap it when the client releases the screen buffer.
206  */
207  ViewSize = 0;
208  NewBuffer->ClientBitMap = NULL;
209  Status = NtMapViewOfSection(NewBuffer->hSection,
211  (PVOID*)&NewBuffer->ClientBitMap,
212  0,
213  0,
214  NULL,
215  &ViewSize,
216  ViewUnmap,
217  0,
219  if (!NT_SUCCESS(Status))
220  {
221  DPRINT1("Error: Impossible to map the shared section ; Status = %lu\n", Status);
222  NtUnmapViewOfSection(NtCurrentProcess(), NewBuffer->BitMap);
223  NtClose(NewBuffer->hSection);
224  NtClose(NewBuffer->ClientMutex);
225  NtClose(NewBuffer->Mutex);
226  ConsoleFreeHeap(NewBuffer->BitMapInfo);
228  goto Quit;
229  }
230 
231  NewBuffer->ViewOrigin.X = NewBuffer->ViewOrigin.Y = 0;
232  NewBuffer->VirtualY = 0;
233 
234  NewBuffer->CursorBlinkOn = FALSE;
235  NewBuffer->ForceCursorOff = TRUE;
236  NewBuffer->CursorInfo.bVisible = FALSE;
237  NewBuffer->CursorInfo.dwSize = 0;
238  NewBuffer->CursorPosition.X = NewBuffer->CursorPosition.Y = 0;
239 
240  NewBuffer->Mode = 0;
241 
242  *Buffer = (PCONSOLE_SCREEN_BUFFER)NewBuffer;
244 
245 Quit:
246  return Status;
247 }
#define CsrGetClientThread()
Definition: csrsrv.h:77
NTSTATUS NTAPI NtUnmapViewOfSection(IN HANDLE ProcessHandle, IN PVOID BaseAddress)
Definition: section.c:3782
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
NTSTATUS NTAPI NtCreateSection(OUT PHANDLE SectionHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN PLARGE_INTEGER MaximumSize OPTIONAL, IN ULONG SectionPageProtection OPTIONAL, IN ULONG AllocationAttributes, IN HANDLE FileHandle OPTIONAL)
Definition: section.c:3373
BOOLEAN CursorBlinkOn
Definition: conio.h:99
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
COORD CursorPosition
Definition: conio.h:98
#define ConsoleAllocHeap(Flags, Size)
Definition: heap.h:14
COORD OldScreenBufferSize
Definition: conio.h:90
CONSOLE_IO_OBJECT Header
Definition: conio.h:82
#define SECTION_ALL_ACCESS
Definition: nt_native.h:1293
#define DUPLICATE_SAME_ACCESS
#define SEC_COMMIT
Definition: mmtypes.h:99
COORD ScreenBufferSize
Definition: conio.h:87
#define MUTANT_ALL_ACCESS
Definition: extypes.h:110
short SHORT
Definition: pedump.c:59
NTSTATUS NTAPI NtMapViewOfSection(IN HANDLE SectionHandle, IN HANDLE ProcessHandle, IN OUT PVOID *BaseAddress, IN ULONG_PTR ZeroBits, IN SIZE_T CommitSize, IN OUT PLARGE_INTEGER SectionOffset OPTIONAL, IN OUT PSIZE_T ViewSize, IN SECTION_INHERIT InheritDisposition, IN ULONG AllocationType, IN ULONG Protect)
Definition: section.c:3554
VOID CONSOLE_SCREEN_BUFFER_Destroy(IN OUT PCONSOLE_SCREEN_BUFFER Buffer)
Definition: conoutput.c:55
struct _CONSOLE_SCREEN_BUFFER * PCONSOLE_SCREEN_BUFFER
Definition: conio.h:70
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
#define NtCurrentProcess()
Definition: nt_native.h:1657
ULONG X
Definition: bl.h:1340
BOOLEAN bVisible
Definition: blue.h:41
NTSTATUS CONSOLE_SCREEN_BUFFER_Initialize(OUT PCONSOLE_SCREEN_BUFFER *Buffer, IN PCONSOLE Console, IN PCONSOLE_SCREEN_BUFFER_VTBL Vtbl, IN SIZE_T Size)
Definition: conoutput.c:37
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static CONSOLE_SCREEN_BUFFER_VTBL GraphicsVtbl
Definition: graphics.c:33
NTSTATUS NTAPI NtCreateMutant(OUT PHANDLE MutantHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN BOOLEAN InitialOwner)
Definition: mutant.c:83
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
BOOLEAN ForceCursorOff
Definition: conio.h:100
Status
Definition: gdiplustypes.h:24
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
CConsole Console
#define DPRINT1
Definition: precomp.h:8
#define ConsoleFreeHeap(HeapBase)
Definition: heap.h:15
NTSTATUS NTAPI NtDuplicateObject(IN HANDLE SourceProcessHandle, IN HANDLE SourceHandle, IN HANDLE TargetProcessHandle OPTIONAL, OUT PHANDLE TargetHandle OPTIONAL, IN ACCESS_MASK DesiredAccess, IN ULONG HandleAttributes, IN ULONG Options)
Definition: obhandle.c:3407
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER _Inout_ PSIZE_T ViewSize
Definition: mmfuncs.h:404
CONSOLE_IO_OBJECT_TYPE Type
Definition: conio.h:50
unsigned int ULONG
Definition: retypes.h:1
PCONSOLE_SCREEN_BUFFER_VTBL Vtbl
Definition: conio.h:83
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:403
return STATUS_SUCCESS
Definition: btrfs.c:2966
CONSOLE_CURSOR_INFO CursorInfo
Definition: conio.h:102
ULONG Y
Definition: bl.h:1341
#define BI_RGB
Definition: precomp.h:34
LONGLONG QuadPart
Definition: typedefs.h:112
#define PAGE_READWRITE
Definition: nt_native.h:1304

◆ TEXTMODE_BUFFER_Destroy()

VOID TEXTMODE_BUFFER_Destroy ( IN OUT PCONSOLE_SCREEN_BUFFER  Buffer)

Definition at line 123 of file text.c.

124 {
126 
127  /*
128  * IMPORTANT !! Reinitialize the type so that we don't enter a recursive
129  * infinite loop when calling CONSOLE_SCREEN_BUFFER_Destroy.
130  */
131  Buffer->Header.Type = SCREEN_BUFFER;
132 
133  ConsoleFreeHeap(Buff->Buffer);
134 
136 }
Definition: bufpool.h:45
VOID CONSOLE_SCREEN_BUFFER_Destroy(IN OUT PCONSOLE_SCREEN_BUFFER Buffer)
Definition: conoutput.c:55
#define ConsoleFreeHeap(HeapBase)
Definition: heap.h:15
PCHAR_INFO Buffer
Definition: conio.h:154
struct _TEXTMODE_SCREEN_BUFFER * PTEXTMODE_SCREEN_BUFFER

◆ TEXTMODE_BUFFER_Initialize()

NTSTATUS TEXTMODE_BUFFER_Initialize ( OUT PCONSOLE_SCREEN_BUFFER Buffer,
IN OUT PCONSOLE  Console,
IN PTEXTMODE_BUFFER_INFO  TextModeInfo 
)

Definition at line 55 of file text.c.

58 {
60  PTEXTMODE_SCREEN_BUFFER NewBuffer = NULL;
61 
62  if (Console == NULL || Buffer == NULL || TextModeInfo == NULL)
64 
65  *Buffer = NULL;
66 
68  Console,
69  sizeof(TEXTMODE_SCREEN_BUFFER));
70  if (!NT_SUCCESS(Status)) return Status;
71  NewBuffer->Header.Type = TEXTMODE_BUFFER;
72  NewBuffer->Vtbl = &TextVtbl;
73 
74  NewBuffer->Buffer = ConsoleAllocHeap(HEAP_ZERO_MEMORY,
75  TextModeInfo->ScreenBufferSize.X *
76  TextModeInfo->ScreenBufferSize.Y *
77  sizeof(CHAR_INFO));
78  if (NewBuffer->Buffer == NULL)
79  {
82  }
83 
84  NewBuffer->ScreenBufferSize = NewBuffer->OldScreenBufferSize
85  = TextModeInfo->ScreenBufferSize;
86  NewBuffer->ViewSize = NewBuffer->OldViewSize
87  = Console->ConsoleSize;
88 
89  NewBuffer->ViewOrigin.X = NewBuffer->ViewOrigin.Y = 0;
90  NewBuffer->VirtualY = 0;
91 
92  NewBuffer->CursorBlinkOn = NewBuffer->ForceCursorOff = FALSE;
93  NewBuffer->CursorInfo.bVisible = (TextModeInfo->IsCursorVisible && (TextModeInfo->CursorSize != 0));
94  NewBuffer->CursorInfo.dwSize = min(max(TextModeInfo->CursorSize, 0), 100);
95 
96  NewBuffer->ScreenDefaultAttrib = TextModeInfo->ScreenAttrib;
97  NewBuffer->PopupDefaultAttrib = TextModeInfo->PopupAttrib;
98 
99  /* Initialize buffer to be empty with default attributes */
100  for (NewBuffer->CursorPosition.Y = 0 ; NewBuffer->CursorPosition.Y < NewBuffer->ScreenBufferSize.Y; NewBuffer->CursorPosition.Y++)
101  {
102  ClearLineBuffer(NewBuffer);
103  }
104  NewBuffer->CursorPosition.X = NewBuffer->CursorPosition.Y = 0;
105 
107 
108  *Buffer = (PCONSOLE_SCREEN_BUFFER)NewBuffer;
109  return STATUS_SUCCESS;
110 }
#define max(a, b)
Definition: svc.c:63
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
BOOLEAN CursorBlinkOn
Definition: conio.h:99
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
static CONSOLE_SCREEN_BUFFER_VTBL TextVtbl
Definition: text.c:36
LONG NTSTATUS
Definition: precomp.h:26
COORD CursorPosition
Definition: conio.h:98
#define ConsoleAllocHeap(Flags, Size)
Definition: heap.h:14
#define TEXTMODE_BUFFER
Definition: pccons.c:21
COORD OldScreenBufferSize
Definition: conio.h:90
CONSOLE_IO_OBJECT Header
Definition: conio.h:82
#define ENABLE_WRAP_AT_EOL_OUTPUT
Definition: blue.h:45
COORD ScreenBufferSize
Definition: conio.h:87
struct _CONSOLE_SCREEN_BUFFER * PCONSOLE_SCREEN_BUFFER
Definition: conio.h:70
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
VOID CONSOLE_SCREEN_BUFFER_Destroy(IN OUT PCONSOLE_SCREEN_BUFFER Buffer)
Definition: conoutput.c:55
ULONG X
Definition: bl.h:1340
NTSTATUS CONSOLE_SCREEN_BUFFER_Initialize(OUT PCONSOLE_SCREEN_BUFFER *Buffer, IN PCONSOLE Console, IN PCONSOLE_SCREEN_BUFFER_VTBL Vtbl, IN SIZE_T Size)
Definition: conoutput.c:37
BOOLEAN bVisible
Definition: blue.h:41
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
BOOLEAN ForceCursorOff
Definition: conio.h:100
Status
Definition: gdiplustypes.h:24
#define ENABLE_PROCESSED_OUTPUT
Definition: blue.h:44
#define min(a, b)
Definition: monoChain.cc:55
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
CConsole Console
CONSOLE_IO_OBJECT_TYPE Type
Definition: conio.h:50
PCONSOLE_SCREEN_BUFFER_VTBL Vtbl
Definition: conio.h:83
VOID ClearLineBuffer(PTEXTMODE_SCREEN_BUFFER Buff)
Definition: text.c:146
return STATUS_SUCCESS
Definition: btrfs.c:2966
CONSOLE_CURSOR_INFO CursorInfo
Definition: conio.h:102
ULONG Y
Definition: bl.h:1341