ReactOS 0.4.15-dev-7889-g76290a6
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
30VOID
32VOID
34
35
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
54VOID
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
126static VOID
128
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 */
156 }
157 else
158 {
159 Console->ActiveBuffer = NULL;
160 // InterlockedExchangePointer(&Console->ActiveBuffer, NULL);
161 }
162 }
163
165}
166
167static 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{
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 */
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 */
unsigned char BOOLEAN
CConsole Console
Type
Definition: Type.h:7
LONG NTSTATUS
Definition: precomp.h:26
Definition: bufpool.h:45
NTSTATUS NTAPI ConDrvGetConsoleCursorInfo(IN PCONSOLE Console, IN PTEXTMODE_SCREEN_BUFFER Buffer, OUT PCONSOLE_CURSOR_INFO CursorInfo)
Definition: conoutput.c:270
NTSTATUS TEXTMODE_BUFFER_Initialize(OUT PCONSOLE_SCREEN_BUFFER *Buffer, IN PCONSOLE Console, IN HANDLE ProcessHandle, IN PTEXTMODE_BUFFER_INFO TextModeInfo)
Definition: text.c:54
static VOID ConioSetActiveScreenBuffer(PCONSOLE_SCREEN_BUFFER Buffer)
Definition: conoutput.c:168
NTSTATUS NTAPI ConDrvSetConsoleCursorPosition(IN PCONSOLE Console, IN PTEXTMODE_SCREEN_BUFFER Buffer, IN PCOORD Position)
Definition: conoutput.c:318
VOID GRAPHICS_BUFFER_Destroy(IN OUT PCONSOLE_SCREEN_BUFFER Buffer)
Definition: graphics.c:236
NTSTATUS GRAPHICS_BUFFER_Initialize(OUT PCONSOLE_SCREEN_BUFFER *Buffer, IN PCONSOLE Console, IN HANDLE ProcessHandle, IN PGRAPHICS_BUFFER_INFO GraphicsInfo)
Definition: graphics.c:33
VOID NTAPI ConDrvDeleteScreenBuffer(PCONSOLE_SCREEN_BUFFER Buffer)
Definition: conoutput.c:130
NTSTATUS NTAPI ConDrvSetConsoleCursorInfo(IN PCONSOLE Console, IN PTEXTMODE_SCREEN_BUFFER Buffer, IN PCONSOLE_CURSOR_INFO CursorInfo)
Definition: conoutput.c:288
NTSTATUS NTAPI ConDrvSetConsolePalette(IN PCONSOLE Console, IN PCONSOLE_SCREEN_BUFFER Buffer, IN HPALETTE PaletteHandle, IN UINT PaletteUsage)
Definition: conoutput.c:226
VOID CONSOLE_SCREEN_BUFFER_Destroy(IN OUT PCONSOLE_SCREEN_BUFFER Buffer)
Definition: conoutput.c:55
PCONSOLE_SCREEN_BUFFER ConDrvGetActiveScreenBuffer(IN PCONSOLE Console)
Definition: conoutput.c:201
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
NTSTATUS NTAPI ConDrvSetConsoleActiveScreenBuffer(IN PCONSOLE Console, IN PCONSOLE_SCREEN_BUFFER Buffer)
Definition: conoutput.c:177
NTSTATUS ConDrvCreateScreenBuffer(OUT PCONSOLE_SCREEN_BUFFER *Buffer, IN PCONSOLE Console, IN HANDLE ProcessHandle OPTIONAL, IN ULONG BufferType, IN PVOID ScreenBufferInfo)
Definition: conoutput.c:85
VOID TEXTMODE_BUFFER_Destroy(IN OUT PCONSOLE_SCREEN_BUFFER Buffer)
Definition: text.c:126
NTSTATUS NTAPI ConDrvInvalidateBitMapRect(IN PCONSOLE Console, IN PCONSOLE_SCREEN_BUFFER Buffer, IN PSMALL_RECT Region)
Definition: conoutput.c:209
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
#define InsertHeadList(ListHead, Entry)
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
@ Success
Definition: eventcreate.c:712
unsigned int BOOL
Definition: ntddk_ex.h:94
pKey DeleteObject()
Status
Definition: gdiplustypes.h:25
#define ASSERT(a)
Definition: mode.c:44
#define min(a, b)
Definition: monoChain.cc:55
unsigned int UINT
Definition: ndis.h:50
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:403
CONSOLE_SCREEN_BUFFER_INFO ScreenBufferInfo
Definition: notevil.c:38
#define NtCurrentProcess()
Definition: nt_native.h:1657
#define TEXTMODE_BUFFER
Definition: pccons.c:21
short SHORT
Definition: pedump.c:59
#define STATUS_SUCCESS
Definition: shellext.h:65
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68
Definition: bl.h:1338
ULONG Y
Definition: bl.h:1340
ULONG X
Definition: bl.h:1339
static COORD Position
Definition: mouse.c:34
#define max(a, b)
Definition: svc.c:63
static HPALETTE PaletteHandle
Definition: svga.c:215
#define TermSetPalette(Console, PaletteHandle, PaletteUsage)
Definition: term.h:36
#define TermReleaseScreenBuffer(Console, ScreenBuffer)
Definition: term.h:32
#define TermSetActiveScreenBuffer(Console)
Definition: term.h:30
#define TermDrawRegion(Console, Region)
Definition: term.h:22
#define TermSetScreenInfo(Console, ScreenBuffer, OldCursorX, OldCursorY)
Definition: term.h:26
#define TermSetCursorInfo(Console, ScreenBuffer)
Definition: term.h:24
#define NTAPI
Definition: typedefs.h:36
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define IN
Definition: typedefs.h:39
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
VOID ConSrvInitObject(IN OUT PCONSOLE_IO_OBJECT Object, IN CONSOLE_IO_OBJECT_TYPE Type, IN PCONSOLE Console)
Definition: handle.c:211
#define ConsoleAllocHeap(Flags, Size)
Definition: heap.h:14
#define ConsoleFreeHeap(HeapBase)
Definition: heap.h:15
enum _CONSOLE_IO_OBJECT_TYPE CONSOLE_IO_OBJECT_TYPE
@ SCREEN_BUFFER
Definition: conio.h:27
@ GRAPHICS_BUFFER
Definition: conio.h:26
#define CONSOLE_TEXTMODE_BUFFER
Definition: wincon.h:62
#define CONSOLE_GRAPHICS_BUFFER
Definition: wincon.h:63
#define SYSPAL_STATIC
Definition: wingdi.h:926
#define SYSPAL_NOSTATIC
Definition: wingdi.h:925
#define SYSPAL_NOSTATIC256
Definition: wingdi.h:21