00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
#include "precomp.h"
00024
#pragma hdrstop
00025
00026
NTSTATUS
00027 CreateConsoleBitmap(
00028 IN OUT PCONSOLE_GRAPHICS_BUFFER_INFO GraphicsInfo,
00029 IN OUT
PSCREEN_INFORMATION ScreenInfo,
00030 OUT PVOID *lpBitmap,
00031 OUT HANDLE *hMutex
00032 )
00033 {
00034
NTSTATUS Status;
00035 LARGE_INTEGER MaximumSize;
00036 SIZE_T ViewSize;
00037
00038
00039
00040
00041
00042
00043
if (GraphicsInfo->lpBitMapInfo->bmiHeader.biHeight > 0)
00044 {
00045
#if DBG
00046
DbgPrint(
"*************** Negating biHeight\n");
00047
#endif
00048
GraphicsInfo->lpBitMapInfo->bmiHeader.biHeight =
00049 -GraphicsInfo->lpBitMapInfo->bmiHeader.biHeight;
00050 }
00051
00052
if (GraphicsInfo->lpBitMapInfo->bmiHeader.biCompression != BI_RGB)
00053 {
00054
#if DBG
00055
DbgPrint(
"*************** setting Compression to BI_RGB)\n");
00056
#endif
00057
GraphicsInfo->lpBitMapInfo->bmiHeader.biCompression = BI_RGB;
00058 }
00059
00060
00061
00062
00063
00064 ScreenInfo->BufferInfo.GraphicsInfo.lpBitMapInfo = (LPBITMAPINFO)
ConsoleHeapAlloc(
MAKE_TAG(
BMP_TAG ),GraphicsInfo->dwBitMapInfoLength);
00065
if (ScreenInfo->BufferInfo.GraphicsInfo.lpBitMapInfo ==
NULL) {
00066
return STATUS_NO_MEMORY;
00067 }
00068 ScreenInfo->BufferInfo.GraphicsInfo.BitMapInfoLength = GraphicsInfo->dwBitMapInfoLength;
00069 RtlCopyMemory(ScreenInfo->BufferInfo.GraphicsInfo.lpBitMapInfo,
00070 GraphicsInfo->lpBitMapInfo,
00071 GraphicsInfo->dwBitMapInfoLength
00072 );
00073
ASSERT((GraphicsInfo->lpBitMapInfo->bmiHeader.biWidth *
00074 -GraphicsInfo->lpBitMapInfo->bmiHeader.biHeight / 8 *
00075 GraphicsInfo->lpBitMapInfo->bmiHeader.biBitCount) ==
00076 (LONG)GraphicsInfo->lpBitMapInfo->bmiHeader.biSizeImage);
00077
00078
00079
00080
00081
00082 MaximumSize.QuadPart = GraphicsInfo->lpBitMapInfo->bmiHeader.biSizeImage;
00083
Status =
NtCreateSection(&ScreenInfo->BufferInfo.GraphicsInfo.hSection,
00084 SECTION_ALL_ACCESS,
00085
NULL,
00086 &MaximumSize,
00087 PAGE_READWRITE,
00088 SEC_COMMIT,
00089
NULL
00090 );
00091
if (!
NT_SUCCESS(
Status)) {
00092
ConsoleHeapFree(ScreenInfo->BufferInfo.GraphicsInfo.lpBitMapInfo);
00093
return Status;
00094 }
00095
00096
00097
00098
00099
00100 ViewSize = GraphicsInfo->lpBitMapInfo->bmiHeader.biSizeImage;
00101 ScreenInfo->BufferInfo.GraphicsInfo.BitMap = 0;
00102
Status =
NtMapViewOfSection(ScreenInfo->BufferInfo.GraphicsInfo.hSection,
00103 NtCurrentProcess(),
00104 &ScreenInfo->BufferInfo.GraphicsInfo.BitMap,
00105 0
L,
00106 GraphicsInfo->lpBitMapInfo->bmiHeader.biSizeImage,
00107
NULL,
00108 &ViewSize,
00109 ViewUnmap,
00110 0
L,
00111 PAGE_READWRITE
00112 );
00113
if (!
NT_SUCCESS(
Status)) {
00114
ConsoleHeapFree(ScreenInfo->BufferInfo.GraphicsInfo.lpBitMapInfo);
00115
NtClose(ScreenInfo->BufferInfo.GraphicsInfo.hSection);
00116
return Status;
00117 }
00118
00119
00120
00121
00122
00123 ViewSize = GraphicsInfo->lpBitMapInfo->bmiHeader.biSizeImage;
00124 *lpBitmap = 0;
00125
Status =
NtMapViewOfSection(ScreenInfo->BufferInfo.GraphicsInfo.hSection,
00126
CONSOLE_CLIENTPROCESSHANDLE(),
00127 lpBitmap,
00128 0
L,
00129 GraphicsInfo->lpBitMapInfo->bmiHeader.biSizeImage,
00130
NULL,
00131 &ViewSize,
00132 ViewUnmap,
00133 0
L,
00134 PAGE_READWRITE
00135 );
00136
if (!
NT_SUCCESS(
Status)) {
00137
ConsoleHeapFree(ScreenInfo->BufferInfo.GraphicsInfo.lpBitMapInfo);
00138
NtUnmapViewOfSection(NtCurrentProcess(),ScreenInfo->BufferInfo.GraphicsInfo.BitMap);
00139
NtClose(ScreenInfo->BufferInfo.GraphicsInfo.hSection);
00140
return Status;
00141 }
00142 ScreenInfo->BufferInfo.GraphicsInfo.ClientProcess =
CONSOLE_CLIENTPROCESSHANDLE();
00143 ScreenInfo->BufferInfo.GraphicsInfo.ClientBitMap = *lpBitmap;
00144
00145
00146
00147
00148
00149
NtCreateMutant(&ScreenInfo->BufferInfo.GraphicsInfo.hMutex,
00150 MUTANT_ALL_ACCESS,
NULL,
FALSE);
00151
MapHandle(
CONSOLE_CLIENTPROCESSHANDLE(),
00152 ScreenInfo->BufferInfo.GraphicsInfo.hMutex,
00153 hMutex
00154 );
00155
00156 ScreenInfo->BufferInfo.GraphicsInfo.dwUsage = GraphicsInfo->dwUsage;
00157 ScreenInfo->ScreenBufferSize.X = (WORD)GraphicsInfo->lpBitMapInfo->bmiHeader.biWidth;
00158 ScreenInfo->ScreenBufferSize.Y = (WORD)-GraphicsInfo->lpBitMapInfo->bmiHeader.biHeight;
00159 ScreenInfo->Window.Left = 0;
00160 ScreenInfo->Window.Top = 0;
00161 ScreenInfo->Window.Right = (
SHORT)(ScreenInfo->Window.Left+ScreenInfo->ScreenBufferSize.X-1);
00162 ScreenInfo->Window.Bottom = (
SHORT)(ScreenInfo->Window.Top+ScreenInfo->ScreenBufferSize.Y-1);
00163
return STATUS_SUCCESS;
00164 }
00165
00166
00167 ULONG
00168 SrvInvalidateBitMapRect(
00169 IN OUT PCSR_API_MSG m,
00170 IN OUT PCSR_REPLY_STATUS ReplyStatus
00171 )
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190 {
00191
PCONSOLE_INVALIDATERECT_MSG a = (
PCONSOLE_INVALIDATERECT_MSG)&m->u.ApiMessageData;
00192
PCONSOLE_INFORMATION Console;
00193
PHANDLE_DATA HandleData;
00194
NTSTATUS Status;
00195
UINT Codepage;
00196
00197
Status =
ApiPreamble(a->
ConsoleHandle,
00198 &Console
00199 );
00200
if (!
NT_SUCCESS(
Status)) {
00201
return Status;
00202 }
00203
00204
Status =
DereferenceIoHandle(
CONSOLE_PERPROCESSDATA(),
00205 a->
OutputHandle,
00206
CONSOLE_OUTPUT_HANDLE |
CONSOLE_GRAPHICS_OUTPUT_HANDLE,
00207 GENERIC_WRITE,
00208 &HandleData
00209 );
00210
if (!
NT_SUCCESS(
Status)) {
00211
UnlockConsole(Console);
00212
return((ULONG)
Status);
00213 }
00214
if (HandleData->
HandleType &
CONSOLE_OUTPUT_HANDLE) {
00215
00216
00217
ASSERT(Console->
VDMBuffer !=
NULL);
00218
if (Console->
VDMBuffer !=
NULL) {
00219
00220
00221
if (HandleData->
Buffer.ScreenBuffer->ScreenBufferSize.X <= Console->
VDMBufferSize.X &&
00222 HandleData->
Buffer.ScreenBuffer->ScreenBufferSize.Y <= Console->
VDMBufferSize.Y) {
00223 COORD TargetPoint;
00224
00225 TargetPoint.X = a->
Rect.Left;
00226 TargetPoint.Y = a->
Rect.Top;
00227
00228
00229
00230
00231
00232
00233
00234
if ((a->
Rect.Left >= 0) &&
00235 (a->
Rect.Top >= 0) &&
00236 (a->
Rect.Right < HandleData->
Buffer.ScreenBuffer->ScreenBufferSize.X) &&
00237 (a->
Rect.Bottom < HandleData->
Buffer.ScreenBuffer->ScreenBufferSize.Y) &&
00238 (a->
Rect.Left <= a->
Rect.Right) &&
00239 (a->
Rect.Top <= a->
Rect.Bottom) ) {
00240
00241
if ((Console->
CurrentScreenBuffer->
Flags &
CONSOLE_OEMFONT_DISPLAY) && ((Console->
FullScreenFlags & CONSOLE_FULLSCREEN) == 0)) {
00242
#if defined(FE_SB)
00243
if (
CONSOLE_IS_DBCS_ENABLED() &&
00244 Console->
OutputCP !=
WINDOWSCP )
00245 {
00246 Codepage =
USACP;
00247 }
00248
else
00249
00250
#endif
00251
00252 Codepage =
WINDOWSCP;
00253 }
else {
00254
#if defined(FE_SB)
00255
if (
CONSOLE_IS_DBCS_ENABLED()) {
00256 Codepage = Console->
OutputCP;
00257 }
00258
else
00259
#endif
00260
00261 Codepage = Console->
CP;
00262 }
00263
00264
WriteRectToScreenBuffer((
PBYTE)Console->
VDMBuffer,
00265 Console->
VDMBufferSize, &a->
Rect,
00266 HandleData->
Buffer.ScreenBuffer, TargetPoint,
00267 Codepage);
00268
WriteToScreen(HandleData->
Buffer.ScreenBuffer,&a->
Rect);
00269 }
else {
00270
Status = STATUS_INVALID_PARAMETER;
00271 }
00272 }
else {
00273
Status = STATUS_INVALID_PARAMETER;
00274 }
00275 }
else {
00276
Status = STATUS_INVALID_PARAMETER;
00277 }
00278 }
else {
00279
00280
00281
00282
00283
00284
WriteToScreen(HandleData->
Buffer.ScreenBuffer,&a->
Rect);
00285 }
00286
00287
UnlockConsole(Console);
00288
return Status;
00289 UNREFERENCED_PARAMETER(ReplyStatus);
00290 }
00291
00292
NTSTATUS
00293 WriteRegionToScreenBitMap(
00294 IN
PSCREEN_INFORMATION ScreenInfo,
00295 IN PSMALL_RECT Region
00296 )
00297 {
00298
DWORD NumScanLines;
00299
int Height;
00300
00301
00302
00303
00304
InvertSelection(ScreenInfo->Console,
TRUE);
00305
00306
NtWaitForSingleObject(ScreenInfo->BufferInfo.GraphicsInfo.hMutex,
00307
FALSE,
NULL);
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319 Height = ScreenInfo->BufferInfo.GraphicsInfo.lpBitMapInfo->bmiHeader.biHeight;
00320
00321 NumScanLines = SetDIBitsToDevice(ScreenInfo->Console->hDC,
00322 Region->Left - ScreenInfo->Window.Left,
00323 Region->Top - ScreenInfo->Window.Top,
00324 Region->Right - Region->Left + 1,
00325 Region->Bottom - Region->Top + 1,
00326 Region->Left,
00327 Height < 0 ? -Height - Region->Bottom - 1 : Region->Bottom,
00328 0,
00329 ScreenInfo->ScreenBufferSize.Y,
00330 ScreenInfo->BufferInfo.GraphicsInfo.BitMap,
00331 ScreenInfo->BufferInfo.GraphicsInfo.lpBitMapInfo,
00332 ScreenInfo->BufferInfo.GraphicsInfo.dwUsage
00333 );
00334
00335
NtReleaseMutant(ScreenInfo->BufferInfo.GraphicsInfo.hMutex,
NULL);
00336
00337
00338
00339
00340
00341
InvertSelection(ScreenInfo->Console,
FALSE);
00342
00343
if (NumScanLines == 0) {
00344
return STATUS_UNSUCCESSFUL;
00345 }
00346
return STATUS_SUCCESS;
00347 }
00348
00349
00350
00351
00352
VOID
00353 FreeConsoleBitmap(
00354 IN
PSCREEN_INFORMATION ScreenInfo
00355 )
00356 {
00357
NtUnmapViewOfSection(NtCurrentProcess(),
00358 ScreenInfo->BufferInfo.GraphicsInfo.BitMap);
00359
NtUnmapViewOfSection(ScreenInfo->BufferInfo.GraphicsInfo.ClientProcess,
00360 ScreenInfo->BufferInfo.GraphicsInfo.ClientBitMap);
00361
NtClose(ScreenInfo->BufferInfo.GraphicsInfo.hSection);
00362
NtClose(ScreenInfo->BufferInfo.GraphicsInfo.hMutex);
00363
ConsoleHeapFree(ScreenInfo->BufferInfo.GraphicsInfo.lpBitMapInfo);
00364 }