ReactOS  0.4.15-dev-1033-gd7d716a
conoutput.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS Console Driver DLL
4  * FILE: win32ss/user/winsrv/consrv/condrv/conoutput.c
5  * PURPOSE: General Console Output Functions
6  * PROGRAMMERS: Jeffrey Morlan
7  * Hermes Belusca-Maito (hermes.belusca@sfr.fr)
8  */
9 
10 /* INCLUDES *******************************************************************/
11 
12 #include <consrv.h>
13 
14 #define NDEBUG
15 #include <debug.h>
16 
17 /* PRIVATE FUNCTIONS **********************************************************/
18 
23  IN PTEXTMODE_BUFFER_INFO TextModeInfo);
28  IN PGRAPHICS_BUFFER_INFO GraphicsInfo);
29 
30 VOID
32 VOID
34 
35 
41  IN SIZE_T Size)
42 {
43  if (Buffer == NULL || Console == NULL)
45 
48 
49  /* Initialize the header with the default type */
50  ConSrvInitObject(&(*Buffer)->Header, Type /* SCREEN_BUFFER */, Console);
51  return STATUS_SUCCESS;
52 }
53 
54 VOID
56 {
57  switch (Buffer->Header.Type)
58  {
59  case TEXTMODE_BUFFER:
61  break;
62 
63  case GRAPHICS_BUFFER:
65  break;
66 
67  case SCREEN_BUFFER:
68  {
69  /* Free the palette handle */
70  if (Buffer->PaletteHandle != NULL)
71  DeleteObject(Buffer->PaletteHandle);
72 
73  /* Free the screen buffer memory */
75  break;
76  }
77 
78  default:
79  break;
80  }
81 }
82 
83 // ConDrvCreateConsoleScreenBuffer
88  IN ULONG BufferType,
90 {
92 
93  if ( Console == NULL || Buffer == NULL ||
94  (BufferType != CONSOLE_TEXTMODE_BUFFER && BufferType != CONSOLE_GRAPHICS_BUFFER) )
95  {
97  }
98 
99  /* Use the current process if ProcessHandle is NULL */
100  if (ProcessHandle == NULL)
102 
103  switch (BufferType)
104  {
108  break;
109 
113  break;
114 
115  default:
116  /* Never ever go there!! */
117  ASSERT(FALSE);
118  }
119 
120  /* Insert the newly created screen buffer into the list, if succeeded */
121  if (NT_SUCCESS(Status)) InsertHeadList(&Console->BufferList, &(*Buffer)->ListEntry);
122 
123  return Status;
124 }
125 
126 static VOID
128 
129 VOID NTAPI
131 {
132  PCONSOLE Console = Buffer->Header.Console;
133  PCONSOLE_SCREEN_BUFFER NewBuffer;
134 
135  /*
136  * We should notify temporarily the frontend because we are susceptible
137  * to delete the screen buffer it is using (which may be different from
138  * the active screen buffer in some cases), and because, if it actually
139  * uses the active screen buffer, we are going to nullify its pointer to
140  * change it.
141  */
143 
144  RemoveEntryList(&Buffer->ListEntry);
145  if (Buffer == Console->ActiveBuffer)
146  {
147  /* Delete active buffer; switch to most recently created */
148  if (!IsListEmpty(&Console->BufferList))
149  {
150  NewBuffer = CONTAINING_RECORD(Console->BufferList.Flink,
152  ListEntry);
153 
154  /* Tie console to new buffer and signal the change to the frontend */
155  ConioSetActiveScreenBuffer(NewBuffer);
156  }
157  else
158  {
159  Console->ActiveBuffer = NULL;
160  // InterlockedExchangePointer(&Console->ActiveBuffer, NULL);
161  }
162  }
163 
165 }
166 
167 static VOID
169 {
170  PCONSOLE Console = Buffer->Header.Console;
171  Console->ActiveBuffer = Buffer;
172  // InterlockedExchangePointer(&Console->ActiveBuffer, Buffer);
174 }
175 
179 {
180  if (Console == NULL || Buffer == NULL)
182 
183  /* Validity check */
184  ASSERT(Console == Buffer->Header.Console);
185 
186  if (Buffer == Console->ActiveBuffer) return STATUS_SUCCESS;
187 
188  /* If old buffer has no handles, it's now unreferenced */
189  if (Console->ActiveBuffer->Header.ReferenceCount == 0)
190  {
191  ConDrvDeleteScreenBuffer(Console->ActiveBuffer);
192  }
193 
194  /* Tie console to new buffer and signal the change to the frontend */
196 
197  return STATUS_SUCCESS;
198 }
199 
202 {
203  return (Console ? Console->ActiveBuffer : NULL);
204 }
205 
206 /* PUBLIC DRIVER APIS *********************************************************/
207 
212 {
213  if (Console == NULL || Buffer == NULL || Region == NULL)
215 
216  /* Validity check */
217  ASSERT(Console == Buffer->Header.Console);
218 
219  /* If the output buffer is the current one, redraw the correct portion of the screen */
220  if (Buffer == Console->ActiveBuffer) TermDrawRegion(Console, Region);
221 
222  return STATUS_SUCCESS;
223 }
224 
227  // IN PGRAPHICS_SCREEN_BUFFER Buffer,
229  IN HPALETTE PaletteHandle,
230  IN UINT PaletteUsage)
231 {
232  BOOL Success;
233 
234  /*
235  * Parameters validation
236  */
237  if (Console == NULL || Buffer == NULL)
239 
240  if ( PaletteUsage != SYSPAL_STATIC &&
241  PaletteUsage != SYSPAL_NOSTATIC &&
242  PaletteUsage != SYSPAL_NOSTATIC256 )
243  {
245  }
246 
247  /* Validity check */
248  ASSERT(Console == Buffer->Header.Console);
249 
250  /* Change the palette */
251  Success = TermSetPalette(Console, PaletteHandle, PaletteUsage);
252  if (Success)
253  {
254  /* Free the old palette handle if there was already one set */
255  if ( Buffer->PaletteHandle != NULL &&
256  Buffer->PaletteHandle != PaletteHandle )
257  {
258  DeleteObject(Buffer->PaletteHandle);
259  }
260 
261  /* Save the new palette in the screen buffer */
262  Buffer->PaletteHandle = PaletteHandle;
263  Buffer->PaletteUsage = PaletteUsage;
264  }
265 
267 }
268 
272  OUT PCONSOLE_CURSOR_INFO CursorInfo)
273 {
274  if (Console == NULL || Buffer == NULL || CursorInfo == NULL)
276 
277  /* Validity check */
278  ASSERT(Console == Buffer->Header.Console);
279 
280  *CursorInfo = Buffer->CursorInfo;
281  // CursorInfo->bVisible = Buffer->CursorInfo.bVisible;
282  // CursorInfo->dwSize = Buffer->CursorInfo.dwSize;
283 
284  return STATUS_SUCCESS;
285 }
286 
290  IN PCONSOLE_CURSOR_INFO CursorInfo)
291 {
292  ULONG Size;
293  BOOLEAN Visible, Success = TRUE;
294 
295  if (Console == NULL || Buffer == NULL || CursorInfo == NULL)
297 
298  /* Validity check */
299  ASSERT(Console == Buffer->Header.Console);
300 
301  Size = min(max(CursorInfo->dwSize, 1), 100);
302  Visible = CursorInfo->bVisible;
303 
304  if ( (Size != Buffer->CursorInfo.dwSize) ||
305  (Visible && !Buffer->CursorInfo.bVisible) ||
306  (!Visible && Buffer->CursorInfo.bVisible) )
307  {
308  Buffer->CursorInfo.dwSize = Size;
309  Buffer->CursorInfo.bVisible = Visible;
310 
312  }
313 
315 }
316 
321 {
322  SHORT OldCursorX, OldCursorY;
323 
324  if (Console == NULL || Buffer == NULL || Position == NULL)
326 
327  /* Validity check */
328  ASSERT(Console == Buffer->Header.Console);
329 
330  if ( Position->X < 0 || Position->X >= Buffer->ScreenBufferSize.X ||
331  Position->Y < 0 || Position->Y >= Buffer->ScreenBufferSize.Y )
332  {
334  }
335 
336  OldCursorX = Buffer->CursorPosition.X;
337  OldCursorY = Buffer->CursorPosition.Y;
338  Buffer->CursorPosition = *Position;
339 
340  if ( ((PCONSOLE_SCREEN_BUFFER)Buffer == Console->ActiveBuffer) &&
341  (!TermSetScreenInfo(Console, (PCONSOLE_SCREEN_BUFFER)Buffer, OldCursorX, OldCursorY)) )
342  {
343  return STATUS_UNSUCCESSFUL;
344  }
345 
346  return STATUS_SUCCESS;
347 }
348 
349 /* EOF */
#define IN
Definition: typedefs.h:39
NTSTATUS NTAPI ConDrvSetConsoleActiveScreenBuffer(IN PCONSOLE Console, IN PCONSOLE_SCREEN_BUFFER Buffer)
Definition: conoutput.c:177
#define max(a, b)
Definition: svc.c:63
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
VOID NTAPI ConDrvDeleteScreenBuffer(PCONSOLE_SCREEN_BUFFER Buffer)
Definition: conoutput.c:130
PCONSOLE_SCREEN_BUFFER ConDrvGetActiveScreenBuffer(IN PCONSOLE Console)
Definition: conoutput.c:201
Type
Definition: Type.h:6
CONSOLE_SCREEN_BUFFER_INFO ScreenBufferInfo
Definition: notevil.c:38
#define TRUE
Definition: types.h:120
#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
static COORD Position
Definition: mouse.c:34
LONG NTSTATUS
Definition: precomp.h:26
#define ConsoleAllocHeap(Flags, Size)
Definition: heap.h:14
#define TermDrawRegion(Console, Region)
Definition: term.h:22
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
NTSTATUS TEXTMODE_BUFFER_Initialize(OUT PCONSOLE_SCREEN_BUFFER *Buffer, IN PCONSOLE Console, IN HANDLE ProcessHandle, IN PTEXTMODE_BUFFER_INFO TextModeInfo)
Definition: text.c:54
NTSTATUS ConDrvCreateScreenBuffer(OUT PCONSOLE_SCREEN_BUFFER *Buffer, IN PCONSOLE Console, IN HANDLE ProcessHandle OPTIONAL, IN ULONG BufferType, IN PVOID ScreenBufferInfo)
Definition: conoutput.c:85
static HPALETTE PaletteHandle
Definition: svga.c:215
NTSTATUS NTAPI ConDrvGetConsoleCursorInfo(IN PCONSOLE Console, IN PTEXTMODE_SCREEN_BUFFER Buffer, OUT PCONSOLE_CURSOR_INFO CursorInfo)
Definition: conoutput.c:270
_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
VOID TEXTMODE_BUFFER_Destroy(IN OUT PCONSOLE_SCREEN_BUFFER Buffer)
Definition: text.c:126
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
#define TermSetScreenInfo(Console, ScreenBuffer, OldCursorX, OldCursorY)
Definition: term.h:26
short SHORT
Definition: pedump.c:59
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define TermSetActiveScreenBuffer(Console)
Definition: term.h:30
Definition: bufpool.h:45
NTSTATUS CONSOLE_SCREEN_BUFFER_Initialize(OUT PCONSOLE_SCREEN_BUFFER *Buffer, IN PCONSOLE Console, IN CONSOLE_IO_OBJECT_TYPE Type, IN SIZE_T Size)
Definition: conoutput.c:37
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
#define NtCurrentProcess()
Definition: nt_native.h:1657
ULONG X
Definition: bl.h:1340
NTSTATUS NTAPI ConDrvSetConsolePalette(IN PCONSOLE Console, IN PCONSOLE_SCREEN_BUFFER Buffer, IN HPALETTE PaletteHandle, IN UINT PaletteUsage)
Definition: conoutput.c:226
#define SYSPAL_NOSTATIC256
Definition: wingdi.h:21
#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:33
NTSTATUS NTAPI ConDrvSetConsoleCursorPosition(IN PCONSOLE Console, IN PTEXTMODE_SCREEN_BUFFER Buffer, IN PCOORD Position)
Definition: conoutput.c:318
static VOID ConioSetActiveScreenBuffer(PCONSOLE_SCREEN_BUFFER Buffer)
Definition: conoutput.c:168
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
Status
Definition: gdiplustypes.h:24
#define SYSPAL_STATIC
Definition: wingdi.h:925
NTSTATUS NTAPI ConDrvSetConsoleCursorInfo(IN PCONSOLE Console, IN PTEXTMODE_SCREEN_BUFFER Buffer, IN PCONSOLE_CURSOR_INFO CursorInfo)
Definition: conoutput.c:288
#define TermSetPalette(Console, PaletteHandle, PaletteUsage)
Definition: term.h:36
VOID ConSrvInitObject(IN OUT PCONSOLE_IO_OBJECT Object, IN CONSOLE_IO_OBJECT_TYPE Type, IN PCONSOLE Console)
Definition: handle.c:211
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
Definition: bl.h:1338
#define SYSPAL_NOSTATIC
Definition: wingdi.h:924
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define TermSetCursorInfo(Console, ScreenBuffer)
Definition: term.h:24
#define CONSOLE_TEXTMODE_BUFFER
Definition: wincon.h:62
#define CONSOLE_GRAPHICS_BUFFER
Definition: wincon.h:63
#define min(a, b)
Definition: monoChain.cc:55
unsigned int UINT
Definition: ndis.h:50
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
NTSTATUS NTAPI ConDrvInvalidateBitMapRect(IN PCONSOLE Console, IN PCONSOLE_SCREEN_BUFFER Buffer, IN PSMALL_RECT Region)
Definition: conoutput.c:209
CConsole Console
#define ConsoleFreeHeap(HeapBase)
Definition: heap.h:15
VOID GRAPHICS_BUFFER_Destroy(IN OUT PCONSOLE_SCREEN_BUFFER Buffer)
Definition: graphics.c:236
#define OUT
Definition: typedefs.h:40
unsigned int ULONG
Definition: retypes.h:1
VOID CONSOLE_SCREEN_BUFFER_Destroy(IN OUT PCONSOLE_SCREEN_BUFFER Buffer)
Definition: conoutput.c:55
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:403
return STATUS_SUCCESS
Definition: btrfs.c:3014
ULONG Y
Definition: bl.h:1341
enum _CONSOLE_IO_OBJECT_TYPE CONSOLE_IO_OBJECT_TYPE
#define TermReleaseScreenBuffer(Console, ScreenBuffer)
Definition: term.h:32
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68