ReactOS  0.4.15-dev-1197-g8081ba9
graphics.c File Reference
#include <consrv.h>
#include <debug.h>
Include dependency graph for graphics.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

NTSTATUS CONSOLE_SCREEN_BUFFER_Initialize (OUT PCONSOLE_SCREEN_BUFFER *Buffer, IN PCONSOLE Console, IN CONSOLE_IO_OBJECT_TYPE Type, IN SIZE_T Size)
 
VOID CONSOLE_SCREEN_BUFFER_Destroy (IN OUT PCONSOLE_SCREEN_BUFFER Buffer)
 
NTSTATUS GRAPHICS_BUFFER_Initialize (OUT PCONSOLE_SCREEN_BUFFER *Buffer, IN PCONSOLE Console, IN HANDLE ProcessHandle, IN PGRAPHICS_BUFFER_INFO GraphicsInfo)
 
VOID GRAPHICS_BUFFER_Destroy (IN OUT PCONSOLE_SCREEN_BUFFER Buffer)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 16 of file graphics.c.

Function Documentation

◆ CONSOLE_SCREEN_BUFFER_Destroy()

VOID CONSOLE_SCREEN_BUFFER_Destroy ( IN OUT PCONSOLE_SCREEN_BUFFER  Buffer)

Definition at line 55 of file conoutput.c.

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 }
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
VOID TEXTMODE_BUFFER_Destroy(IN OUT PCONSOLE_SCREEN_BUFFER Buffer)
Definition: text.c:126
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
#define ConsoleFreeHeap(HeapBase)
Definition: heap.h:15
VOID GRAPHICS_BUFFER_Destroy(IN OUT PCONSOLE_SCREEN_BUFFER Buffer)
Definition: graphics.c:236

Referenced by GRAPHICS_BUFFER_Destroy(), and GRAPHICS_BUFFER_Initialize().

◆ CONSOLE_SCREEN_BUFFER_Initialize()

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

Definition at line 37 of file conoutput.c.

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 }
#define max(a, b)
Definition: svc.c:63
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
Type
Definition: Type.h:6
#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:211
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
CConsole Console
return STATUS_SUCCESS
Definition: btrfs.c:3014

Referenced by GRAPHICS_BUFFER_Initialize().

◆ GRAPHICS_BUFFER_Destroy()

VOID GRAPHICS_BUFFER_Destroy ( IN OUT PCONSOLE_SCREEN_BUFFER  Buffer)

Definition at line 236 of file graphics.c.

237 {
239 
240  /*
241  * IMPORTANT !! Reinitialize the type so that we don't enter a recursive
242  * infinite loop when calling CONSOLE_SCREEN_BUFFER_Destroy.
243  */
244  Buffer->Header.Type = SCREEN_BUFFER;
245 
246  /*
247  * Uninitialize the graphics screen buffer
248  * in the reverse way we initialized it.
249  */
252  NtClose(Buff->hSection);
255  NtClose(Buff->Mutex);
257 
259 }
#define DUPLICATE_CLOSE_SOURCE
NTSTATUS NTAPI NtUnmapViewOfSection(IN HANDLE ProcessHandle, IN PVOID BaseAddress)
Definition: section.c:3782
LPBITMAPINFO BitMapInfo
Definition: conio.h:150
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

Referenced by CONSOLE_SCREEN_BUFFER_Destroy().

◆ GRAPHICS_BUFFER_Initialize()

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

Definition at line 33 of file graphics.c.

37 {
39  PGRAPHICS_SCREEN_BUFFER NewBuffer = NULL;
40 
41  LARGE_INTEGER SectionSize;
42  SIZE_T ViewSize = 0;
43 
44  if (Buffer == NULL || Console == NULL || GraphicsInfo == NULL)
46 
47  *Buffer = NULL;
48 
50  Console,
52  sizeof(GRAPHICS_SCREEN_BUFFER));
53  if (!NT_SUCCESS(Status)) return Status;
54 
55  /*
56  * Remember the handle to the process so that we can close or unmap
57  * correctly the allocated resources when the client releases the
58  * screen buffer.
59  */
60  NewBuffer->ClientProcess = ProcessHandle;
61 
62  /* Get information from the graphics buffer information structure */
63  NewBuffer->BitMapInfoLength = GraphicsInfo->Info.dwBitMapInfoLength;
64 
65  NewBuffer->BitMapInfo = ConsoleAllocHeap(HEAP_ZERO_MEMORY, NewBuffer->BitMapInfoLength);
66  if (NewBuffer->BitMapInfo == NULL)
67  {
70  }
71 
72  /* Adjust the bitmap height if needed (bottom-top vs. top-bottom). Use always bottom-up. */
73  if (GraphicsInfo->Info.lpBitMapInfo->bmiHeader.biHeight > 0)
74  GraphicsInfo->Info.lpBitMapInfo->bmiHeader.biHeight = -GraphicsInfo->Info.lpBitMapInfo->bmiHeader.biHeight;
75 
76  /* We do not use anything else than uncompressed bitmaps */
77  if (GraphicsInfo->Info.lpBitMapInfo->bmiHeader.biCompression != BI_RGB)
78  {
79  DPRINT1("biCompression == %d != BI_RGB, fix that!\n",
80  GraphicsInfo->Info.lpBitMapInfo->bmiHeader.biCompression);
81  GraphicsInfo->Info.lpBitMapInfo->bmiHeader.biCompression = BI_RGB;
82  }
83 
84  RtlCopyMemory(NewBuffer->BitMapInfo,
85  GraphicsInfo->Info.lpBitMapInfo,
86  GraphicsInfo->Info.dwBitMapInfoLength);
87 
88  NewBuffer->BitMapUsage = GraphicsInfo->Info.dwUsage;
89 
90  /* Set the screen buffer size. Fight against overflows. */
91  if ( GraphicsInfo->Info.lpBitMapInfo->bmiHeader.biWidth <= 0xFFFF &&
92  -GraphicsInfo->Info.lpBitMapInfo->bmiHeader.biHeight <= 0xFFFF )
93  {
94  /* Be careful about the sign of biHeight */
95  NewBuffer->ScreenBufferSize.X = (SHORT)GraphicsInfo->Info.lpBitMapInfo->bmiHeader.biWidth ;
96  NewBuffer->ScreenBufferSize.Y = (SHORT)-GraphicsInfo->Info.lpBitMapInfo->bmiHeader.biHeight;
97 
98  NewBuffer->OldViewSize = NewBuffer->ViewSize =
99  NewBuffer->OldScreenBufferSize = NewBuffer->ScreenBufferSize;
100  }
101  else
102  {
104  ConsoleFreeHeap(NewBuffer->BitMapInfo);
106  goto Quit;
107  }
108 
109  /*
110  * Create a mutex to synchronize bitmap memory access
111  * between ourselves and the client.
112  */
113  Status = NtCreateMutant(&NewBuffer->Mutex, MUTANT_ALL_ACCESS, NULL, FALSE);
114  if (!NT_SUCCESS(Status))
115  {
116  DPRINT1("NtCreateMutant() failed: %lu\n", Status);
117  ConsoleFreeHeap(NewBuffer->BitMapInfo);
119  goto Quit;
120  }
121 
122  /*
123  * Duplicate the Mutex for the client. We must keep a trace of it
124  * so that we can close it when the client releases the screen buffer.
125  */
127  NewBuffer->Mutex,
129  &NewBuffer->ClientMutex,
130  0, 0, DUPLICATE_SAME_ACCESS);
131  if (!NT_SUCCESS(Status))
132  {
133  DPRINT1("NtDuplicateObject() failed: %lu\n", Status);
134  NtClose(NewBuffer->Mutex);
135  ConsoleFreeHeap(NewBuffer->BitMapInfo);
137  goto Quit;
138  }
139 
140  /*
141  * Create a memory section for the bitmap area, to share with the client.
142  */
143  SectionSize.QuadPart = NewBuffer->BitMapInfo->bmiHeader.biSizeImage;
144  Status = NtCreateSection(&NewBuffer->hSection,
146  NULL,
147  &SectionSize,
149  SEC_COMMIT,
150  NULL);
151  if (!NT_SUCCESS(Status))
152  {
153  DPRINT1("Error: Impossible to create a shared section, Status = 0x%08lx\n", Status);
154  NtDuplicateObject(ProcessHandle, NewBuffer->ClientMutex,
156  NtClose(NewBuffer->Mutex);
157  ConsoleFreeHeap(NewBuffer->BitMapInfo);
159  goto Quit;
160  }
161 
162  /*
163  * Create a view for our needs.
164  */
165  ViewSize = 0;
166  NewBuffer->BitMap = NULL;
167  Status = NtMapViewOfSection(NewBuffer->hSection,
169  (PVOID*)&NewBuffer->BitMap,
170  0,
171  0,
172  NULL,
173  &ViewSize,
174  ViewUnmap,
175  0,
177  if (!NT_SUCCESS(Status))
178  {
179  DPRINT1("Error: Impossible to map the shared section, Status = 0x%08lx\n", Status);
180  NtClose(NewBuffer->hSection);
181  NtDuplicateObject(ProcessHandle, NewBuffer->ClientMutex,
183  NtClose(NewBuffer->Mutex);
184  ConsoleFreeHeap(NewBuffer->BitMapInfo);
186  goto Quit;
187  }
188 
189  /*
190  * Create a view for the client. We must keep a trace of it so that
191  * we can unmap it when the client releases the screen buffer.
192  */
193  ViewSize = 0;
194  NewBuffer->ClientBitMap = NULL;
195  Status = NtMapViewOfSection(NewBuffer->hSection,
197  (PVOID*)&NewBuffer->ClientBitMap,
198  0,
199  0,
200  NULL,
201  &ViewSize,
202  ViewUnmap,
203  0,
205  if (!NT_SUCCESS(Status))
206  {
207  DPRINT1("Error: Impossible to map the shared section, Status = 0x%08lx\n", Status);
208  NtUnmapViewOfSection(NtCurrentProcess(), NewBuffer->BitMap);
209  NtClose(NewBuffer->hSection);
210  NtDuplicateObject(ProcessHandle, NewBuffer->ClientMutex,
212  NtClose(NewBuffer->Mutex);
213  ConsoleFreeHeap(NewBuffer->BitMapInfo);
215  goto Quit;
216  }
217 
218  NewBuffer->ViewOrigin.X = NewBuffer->ViewOrigin.Y = 0;
219 
220  NewBuffer->CursorBlinkOn = FALSE;
221  NewBuffer->ForceCursorOff = TRUE;
222  NewBuffer->CursorInfo.bVisible = FALSE;
223  NewBuffer->CursorInfo.dwSize = 0;
224  NewBuffer->CursorPosition.X = NewBuffer->CursorPosition.Y = 0;
225 
226  NewBuffer->Mode = 0;
227 
228  *Buffer = (PCONSOLE_SCREEN_BUFFER)NewBuffer;
230 
231 Quit:
232  return Status;
233 }
#define DUPLICATE_CLOSE_SOURCE
NTSTATUS NTAPI NtUnmapViewOfSection(IN HANDLE ProcessHandle, IN PVOID BaseAddress)
Definition: section.c:3782
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:72
#define TRUE
Definition: types.h:120
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
COORD CursorPosition
Definition: conio.h:71
#define ConsoleAllocHeap(Flags, Size)
Definition: heap.h:14
COORD OldScreenBufferSize
Definition: conio.h:65
#define SECTION_ALL_ACCESS
Definition: nt_native.h:1293
#define DUPLICATE_SAME_ACCESS
#define SEC_COMMIT
Definition: mmtypes.h:99
#define FALSE
Definition: types.h:117
COORD ScreenBufferSize
Definition: conio.h:62
#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
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
#define NtCurrentProcess()
Definition: nt_native.h:1657
ULONG X
Definition: bl.h:1340
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
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
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
Status
Definition: gdiplustypes.h:24
BOOLEAN ForceCursorOff
Definition: conio.h:73
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
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
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:403
return STATUS_SUCCESS
Definition: btrfs.c:3014
CONSOLE_CURSOR_INFO CursorInfo
Definition: conio.h:75
ULONG Y
Definition: bl.h:1341
#define BI_RGB
Definition: precomp.h:47
LONGLONG QuadPart
Definition: typedefs.h:114
#define PAGE_READWRITE
Definition: nt_native.h:1304

Referenced by ConDrvCreateScreenBuffer().