xref: /reactos/boot/environ/lib/io/display/guicons.c (revision 9393fc32)
1*c2c66affSColin Finck /*
2*c2c66affSColin Finck  * COPYRIGHT:       See COPYING.ARM in the top level directory
3*c2c66affSColin Finck  * PROJECT:         ReactOS UEFI Boot Library
4*c2c66affSColin Finck  * FILE:            boot/environ/lib/io/display/guicons.c
5*c2c66affSColin Finck  * PURPOSE:         Boot Library GUI Console Routines
6*c2c66affSColin Finck  * PROGRAMMER:      Alex Ionescu (alex.ionescu@reactos.org)
7*c2c66affSColin Finck  */
8*c2c66affSColin Finck 
9*c2c66affSColin Finck /* INCLUDES ******************************************************************/
10*c2c66affSColin Finck 
11*c2c66affSColin Finck #include "bl.h"
12*c2c66affSColin Finck 
13*c2c66affSColin Finck /* DATA VARIABLES ************************************************************/
14*c2c66affSColin Finck 
15*c2c66affSColin Finck BL_GRAPHICS_CONSOLE_VTABLE ConsoleGraphicalVtbl =
16*c2c66affSColin Finck {
17*c2c66affSColin Finck     {
18*c2c66affSColin Finck         (PCONSOLE_DESTRUCT)ConsoleGraphicalDestruct,
19*c2c66affSColin Finck         (PCONSOLE_REINITIALIZE)ConsoleGraphicalReinitialize,
20*c2c66affSColin Finck         ConsoleTextBaseGetTextState,
21*c2c66affSColin Finck         (PCONSOLE_SET_TEXT_STATE)ConsoleGraphicalSetTextState,
22*c2c66affSColin Finck         NULL, // GetTextResolution
23*c2c66affSColin Finck         NULL, // SetTextResolution
24*c2c66affSColin Finck         (PCONSOLE_CLEAR_TEXT)ConsoleGraphicalClearText
25*c2c66affSColin Finck     },
26*c2c66affSColin Finck     ConsoleGraphicalIsEnabled,
27*c2c66affSColin Finck     ConsoleGraphicalEnable,
28*c2c66affSColin Finck     NULL,
29*c2c66affSColin Finck     ConsoleGraphicalGetGraphicalResolution,
30*c2c66affSColin Finck     ConsoleGraphicalGetOriginalResolution,
31*c2c66affSColin Finck     NULL,
32*c2c66affSColin Finck };
33*c2c66affSColin Finck 
34*c2c66affSColin Finck /* FUNCTIONS *****************************************************************/
35*c2c66affSColin Finck 
36*c2c66affSColin Finck NTSTATUS
ConsoleGraphicalSetTextState(_In_ PBL_GRAPHICS_CONSOLE Console,_In_ ULONG Mask,_In_ PBL_DISPLAY_STATE TextState)37*c2c66affSColin Finck ConsoleGraphicalSetTextState (
38*c2c66affSColin Finck     _In_ PBL_GRAPHICS_CONSOLE Console,
39*c2c66affSColin Finck     _In_ ULONG Mask,
40*c2c66affSColin Finck     _In_ PBL_DISPLAY_STATE TextState
41*c2c66affSColin Finck     )
42*c2c66affSColin Finck {
43*c2c66affSColin Finck     /* Is the text console active? */
44*c2c66affSColin Finck     if (Console->TextConsole.Active)
45*c2c66affSColin Finck     {
46*c2c66affSColin Finck         /* Let it handle that */
47*c2c66affSColin Finck         return ConsoleFirmwareTextSetState(&Console->TextConsole,
48*c2c66affSColin Finck                                            Mask,
49*c2c66affSColin Finck                                            TextState);
50*c2c66affSColin Finck     }
51*c2c66affSColin Finck 
52*c2c66affSColin Finck     /* Not yet */
53*c2c66affSColin Finck     EfiPrintf(L"FFX set not implemented\r\n");
54*c2c66affSColin Finck     return STATUS_NOT_IMPLEMENTED;
55*c2c66affSColin Finck }
56*c2c66affSColin Finck 
57*c2c66affSColin Finck NTSTATUS
ConsoleGraphicalConstruct(_In_ PBL_GRAPHICS_CONSOLE GraphicsConsole)58*c2c66affSColin Finck ConsoleGraphicalConstruct (
59*c2c66affSColin Finck     _In_ PBL_GRAPHICS_CONSOLE GraphicsConsole
60*c2c66affSColin Finck     )
61*c2c66affSColin Finck {
62*c2c66affSColin Finck     NTSTATUS Status;
63*c2c66affSColin Finck 
64*c2c66affSColin Finck     /* Create a text console */
65*c2c66affSColin Finck     Status = ConsoleTextLocalConstruct(&GraphicsConsole->TextConsole, FALSE);
66*c2c66affSColin Finck     if (!NT_SUCCESS(Status))
67*c2c66affSColin Finck     {
68*c2c66affSColin Finck         EfiPrintf(L"Text failed: %lx\r\n", Status);
69*c2c66affSColin Finck         return Status;
70*c2c66affSColin Finck     }
71*c2c66affSColin Finck 
72*c2c66affSColin Finck     /* But overwrite its callbacks with ours */
73*c2c66affSColin Finck     GraphicsConsole->TextConsole.Callbacks = &ConsoleGraphicalVtbl.Text;
74*c2c66affSColin Finck 
75*c2c66affSColin Finck     /* Try to create a GOP console */
76*c2c66affSColin Finck     Status = ConsoleEfiGraphicalOpenProtocol(GraphicsConsole, BlGopConsole);
77*c2c66affSColin Finck     if (!NT_SUCCESS(Status))
78*c2c66affSColin Finck     {
79*c2c66affSColin Finck         /* That failed, try an older EFI 1.02 UGA console */
80*c2c66affSColin Finck         EfiPrintf(L"GOP open failed!\r\n", Status);
81*c2c66affSColin Finck         Status = ConsoleEfiGraphicalOpenProtocol(GraphicsConsole, BlUgaConsole);
82*c2c66affSColin Finck         if (!NT_SUCCESS(Status))
83*c2c66affSColin Finck         {
84*c2c66affSColin Finck             /* That failed too, give up */
85*c2c66affSColin Finck             EfiPrintf(L"UGA failed!\r\n", Status);
86*c2c66affSColin Finck             ConsoleTextLocalDestruct(&GraphicsConsole->TextConsole);
87*c2c66affSColin Finck             return STATUS_UNSUCCESSFUL;
88*c2c66affSColin Finck         }
89*c2c66affSColin Finck     }
90*c2c66affSColin Finck 
91*c2c66affSColin Finck     /* Enable the console */
92*c2c66affSColin Finck     Status = ConsoleFirmwareGraphicalEnable(GraphicsConsole);
93*c2c66affSColin Finck     if (!NT_SUCCESS(Status))
94*c2c66affSColin Finck     {
95*c2c66affSColin Finck         /* Failed to enable it, undo everything */
96*c2c66affSColin Finck         EfiPrintf(L"Enable failed\r\n");
97*c2c66affSColin Finck         ConsoleFirmwareGraphicalClose(GraphicsConsole);
98*c2c66affSColin Finck         ConsoleTextLocalDestruct(&GraphicsConsole->TextConsole);
99*c2c66affSColin Finck         return STATUS_UNSUCCESSFUL;
100*c2c66affSColin Finck     }
101*c2c66affSColin Finck 
102*c2c66affSColin Finck     /* Save the graphics text color from the text mode text color */
103*c2c66affSColin Finck     GraphicsConsole->FgColor = GraphicsConsole->TextConsole.State.FgColor;
104*c2c66affSColin Finck     GraphicsConsole->BgColor = GraphicsConsole->TextConsole.State.BgColor;
105*c2c66affSColin Finck     return STATUS_SUCCESS;
106*c2c66affSColin Finck }
107*c2c66affSColin Finck 
108*c2c66affSColin Finck VOID
ConsolepClearBuffer(_In_ PUCHAR FrameBuffer,_In_ ULONG Width,_In_ PUCHAR FillColor,_In_ ULONG Height,_In_ ULONG ScanlineWidth,_In_ ULONG PixelDepth)109*c2c66affSColin Finck ConsolepClearBuffer (
110*c2c66affSColin Finck     _In_ PUCHAR FrameBuffer,
111*c2c66affSColin Finck     _In_ ULONG Width,
112*c2c66affSColin Finck     _In_ PUCHAR FillColor,
113*c2c66affSColin Finck     _In_ ULONG Height,
114*c2c66affSColin Finck     _In_ ULONG ScanlineWidth,
115*c2c66affSColin Finck     _In_ ULONG PixelDepth
116*c2c66affSColin Finck     )
117*c2c66affSColin Finck {
118*c2c66affSColin Finck     PUCHAR Scanline, Current, FrameBufferEnd, LineEnd;
119*c2c66affSColin Finck     ULONG LineBytes, WidthBytes, BytesPerPixel;
120*c2c66affSColin Finck 
121*c2c66affSColin Finck     /* Get the BPP */
122*c2c66affSColin Finck     BytesPerPixel = PixelDepth / 8;
123*c2c66affSColin Finck 
124*c2c66affSColin Finck     /* Using that, calculate the size of a scan line */
125*c2c66affSColin Finck     LineBytes = ScanlineWidth * BytesPerPixel;
126*c2c66affSColin Finck 
127*c2c66affSColin Finck     /* And the size of line we'll have to clear */
128*c2c66affSColin Finck     WidthBytes = Width * BytesPerPixel;
129*c2c66affSColin Finck 
130*c2c66affSColin Finck     /* Allocate a scanline */
131*c2c66affSColin Finck     Scanline = BlMmAllocateHeap(WidthBytes);
132*c2c66affSColin Finck     if (Scanline)
133*c2c66affSColin Finck     {
134*c2c66affSColin Finck         /* For each remaining pixel on the scanline */
135*c2c66affSColin Finck         Current = Scanline;
136*c2c66affSColin Finck         while (Width--)
137*c2c66affSColin Finck         {
138*c2c66affSColin Finck             /* Copy in the fill color */
139*c2c66affSColin Finck             RtlCopyMemory(Current, FillColor, BytesPerPixel);
140*c2c66affSColin Finck             Current += BytesPerPixel;
141*c2c66affSColin Finck         }
142*c2c66affSColin Finck 
143*c2c66affSColin Finck         /* For each scanline in the frame buffer */
144*c2c66affSColin Finck         while (Height--)
145*c2c66affSColin Finck         {
146*c2c66affSColin Finck             /* Copy our constructed scanline */
147*c2c66affSColin Finck             RtlCopyMemory(FrameBuffer, Scanline, WidthBytes);
148*c2c66affSColin Finck             FrameBuffer += LineBytes;
149*c2c66affSColin Finck         }
150*c2c66affSColin Finck     }
151*c2c66affSColin Finck     else
152*c2c66affSColin Finck     {
153*c2c66affSColin Finck         FrameBufferEnd = FrameBuffer + Height * LineBytes;
154*c2c66affSColin Finck         ScanlineWidth = BytesPerPixel * (ScanlineWidth - Width);
155*c2c66affSColin Finck         while (FrameBuffer != FrameBufferEnd)
156*c2c66affSColin Finck         {
157*c2c66affSColin Finck             if (FrameBuffer != (FrameBuffer + WidthBytes))
158*c2c66affSColin Finck             {
159*c2c66affSColin Finck                 LineEnd = FrameBuffer + WidthBytes;
160*c2c66affSColin Finck                 do
161*c2c66affSColin Finck                 {
162*c2c66affSColin Finck                     RtlCopyMemory(FrameBuffer, FillColor, BytesPerPixel);
163*c2c66affSColin Finck                     FrameBuffer += BytesPerPixel;
164*c2c66affSColin Finck                 }
165*c2c66affSColin Finck                 while (FrameBuffer != LineEnd);
166*c2c66affSColin Finck             }
167*c2c66affSColin Finck 
168*c2c66affSColin Finck             FrameBuffer += ScanlineWidth;
169*c2c66affSColin Finck         }
170*c2c66affSColin Finck     }
171*c2c66affSColin Finck }
172*c2c66affSColin Finck 
173*c2c66affSColin Finck NTSTATUS
ConsolepConvertColorToPixel(_In_ BL_COLOR Color,_Out_ PUCHAR Pixel)174*c2c66affSColin Finck ConsolepConvertColorToPixel (
175*c2c66affSColin Finck     _In_ BL_COLOR Color,
176*c2c66affSColin Finck     _Out_ PUCHAR Pixel
177*c2c66affSColin Finck     )
178*c2c66affSColin Finck {
179*c2c66affSColin Finck     NTSTATUS Status;
180*c2c66affSColin Finck 
181*c2c66affSColin Finck     /* Assume success */
182*c2c66affSColin Finck     Status = STATUS_SUCCESS;
183*c2c66affSColin Finck 
184*c2c66affSColin Finck     /* Convert the color to a pixel value */
185*c2c66affSColin Finck     switch (Color)
186*c2c66affSColin Finck     {
187*c2c66affSColin Finck     case Black:
188*c2c66affSColin Finck         Pixel[1] = 0;
189*c2c66affSColin Finck         Pixel[2] = 0;
190*c2c66affSColin Finck         Pixel[0] = 0;
191*c2c66affSColin Finck         break;
192*c2c66affSColin Finck     case Blue:
193*c2c66affSColin Finck         Pixel[1] = 0;
194*c2c66affSColin Finck         Pixel[2] = 0;
195*c2c66affSColin Finck         Pixel[0] = 0x7F;
196*c2c66affSColin Finck         break;
197*c2c66affSColin Finck     case Green:
198*c2c66affSColin Finck         Pixel[1] = 0x7F;
199*c2c66affSColin Finck         Pixel[2] = 0;
200*c2c66affSColin Finck         Pixel[0] = 0;
201*c2c66affSColin Finck         break;
202*c2c66affSColin Finck     case Cyan:
203*c2c66affSColin Finck         Pixel[1] = 0x7F;
204*c2c66affSColin Finck         Pixel[2] = 0;
205*c2c66affSColin Finck         Pixel[0] = 0x7F;
206*c2c66affSColin Finck         break;
207*c2c66affSColin Finck     case Red:
208*c2c66affSColin Finck         Pixel[1] = 0;
209*c2c66affSColin Finck         Pixel[2] = 0x7F;
210*c2c66affSColin Finck         Pixel[0] = 0x7F;
211*c2c66affSColin Finck         break;
212*c2c66affSColin Finck     case Magenta:
213*c2c66affSColin Finck         Pixel[1] = 0;
214*c2c66affSColin Finck         Pixel[2] = 0x7F;
215*c2c66affSColin Finck         Pixel[0] = 0x7F;
216*c2c66affSColin Finck         break;
217*c2c66affSColin Finck     case Brown:
218*c2c66affSColin Finck         Pixel[1] = 0x3F;
219*c2c66affSColin Finck         Pixel[2] = 0x7F;
220*c2c66affSColin Finck         Pixel[0] = 0;
221*c2c66affSColin Finck         break;
222*c2c66affSColin Finck     case LtGray:
223*c2c66affSColin Finck         Pixel[1] = 0xBFu;
224*c2c66affSColin Finck         Pixel[2] = 0xBFu;
225*c2c66affSColin Finck         *Pixel = 0xBFu;
226*c2c66affSColin Finck         break;
227*c2c66affSColin Finck     case Gray:
228*c2c66affSColin Finck         Pixel[1] = 0x7F;
229*c2c66affSColin Finck         Pixel[2] = 0x7F;
230*c2c66affSColin Finck         Pixel[0] = 0x7F;
231*c2c66affSColin Finck         break;
232*c2c66affSColin Finck     case LtBlue:
233*c2c66affSColin Finck         Pixel[1] = 0;
234*c2c66affSColin Finck         Pixel[2] = 0;
235*c2c66affSColin Finck         Pixel[0] = 0xFF;
236*c2c66affSColin Finck         break;
237*c2c66affSColin Finck     case LtGreen:
238*c2c66affSColin Finck         Pixel[1] = 0xFF;
239*c2c66affSColin Finck         Pixel[2] = 0;
240*c2c66affSColin Finck         Pixel[0] = 0;
241*c2c66affSColin Finck         break;
242*c2c66affSColin Finck     case LtCyan:
243*c2c66affSColin Finck         Pixel[1] = 0xFF;
244*c2c66affSColin Finck         Pixel[2] = 0;
245*c2c66affSColin Finck         Pixel[0] = 0xFF;
246*c2c66affSColin Finck         break;
247*c2c66affSColin Finck     case LtRed:
248*c2c66affSColin Finck         Pixel[1] = 0;
249*c2c66affSColin Finck         Pixel[2] = 0xFF;
250*c2c66affSColin Finck         Pixel[0] = 0;
251*c2c66affSColin Finck         break;
252*c2c66affSColin Finck     case LtMagenta:
253*c2c66affSColin Finck         Pixel[1] = 0;
254*c2c66affSColin Finck         Pixel[2] = 0xFF;
255*c2c66affSColin Finck         Pixel[0] = 0xFF;
256*c2c66affSColin Finck         break;
257*c2c66affSColin Finck     case Yellow:
258*c2c66affSColin Finck         Pixel[1] = 0xFF;
259*c2c66affSColin Finck         Pixel[2] = 0xFF;
260*c2c66affSColin Finck         Pixel[0] = 0;
261*c2c66affSColin Finck         break;
262*c2c66affSColin Finck     case White:
263*c2c66affSColin Finck         Pixel[1] = 0xFF;
264*c2c66affSColin Finck         Pixel[2] = 0xFF;
265*c2c66affSColin Finck         Pixel[0] = 0xFF;
266*c2c66affSColin Finck         break;
267*c2c66affSColin Finck     default:
268*c2c66affSColin Finck         Status = STATUS_INVALID_PARAMETER;
269*c2c66affSColin Finck         break;
270*c2c66affSColin Finck     }
271*c2c66affSColin Finck     return Status;
272*c2c66affSColin Finck }
273*c2c66affSColin Finck 
274*c2c66affSColin Finck NTSTATUS
ConsoleGraphicalClearPixels(_In_ PBL_GRAPHICS_CONSOLE Console,_In_ ULONG Color)275*c2c66affSColin Finck ConsoleGraphicalClearPixels  (
276*c2c66affSColin Finck     _In_ PBL_GRAPHICS_CONSOLE Console,
277*c2c66affSColin Finck     _In_ ULONG Color
278*c2c66affSColin Finck     )
279*c2c66affSColin Finck {
280*c2c66affSColin Finck     NTSTATUS Status;
281*c2c66affSColin Finck 
282*c2c66affSColin Finck     /* Check if the text console is active */
283*c2c66affSColin Finck     if (Console->TextConsole.Active)
284*c2c66affSColin Finck     {
285*c2c66affSColin Finck         /* We shouldn't be here */
286*c2c66affSColin Finck         Status = STATUS_UNSUCCESSFUL;
287*c2c66affSColin Finck     }
288*c2c66affSColin Finck     else
289*c2c66affSColin Finck     {
290*c2c66affSColin Finck         /* Clear it in graphics mode */
291*c2c66affSColin Finck         Status = ConsoleFirmwareGraphicalClear(Console, Color);
292*c2c66affSColin Finck     }
293*c2c66affSColin Finck 
294*c2c66affSColin Finck     /* All good */
295*c2c66affSColin Finck     return Status;
296*c2c66affSColin Finck }
297*c2c66affSColin Finck 
298*c2c66affSColin Finck NTSTATUS
ConsoleGraphicalClearText(_In_ PBL_GRAPHICS_CONSOLE Console,_In_ BOOLEAN LineOnly)299*c2c66affSColin Finck ConsoleGraphicalClearText (
300*c2c66affSColin Finck     _In_ PBL_GRAPHICS_CONSOLE Console,
301*c2c66affSColin Finck     _In_ BOOLEAN LineOnly
302*c2c66affSColin Finck     )
303*c2c66affSColin Finck {
304*c2c66affSColin Finck     /* Is the text console active? */
305*c2c66affSColin Finck     if (Console->TextConsole.Active)
306*c2c66affSColin Finck     {
307*c2c66affSColin Finck         /* Let firmware clear do it */
308*c2c66affSColin Finck         return ConsoleFirmwareTextClear(&Console->TextConsole, LineOnly);
309*c2c66affSColin Finck     }
310*c2c66affSColin Finck 
311*c2c66affSColin Finck     /* Are we clearing a line only? */
312*c2c66affSColin Finck     if (LineOnly)
313*c2c66affSColin Finck     {
314*c2c66affSColin Finck         return BfClearToEndOfLine(Console);
315*c2c66affSColin Finck     }
316*c2c66affSColin Finck 
317*c2c66affSColin Finck     /* Nope -- the whole screen */
318*c2c66affSColin Finck     return BfClearScreen(Console);
319*c2c66affSColin Finck }
320*c2c66affSColin Finck 
321*c2c66affSColin Finck BOOLEAN
ConsoleGraphicalIsEnabled(_In_ PBL_GRAPHICS_CONSOLE Console)322*c2c66affSColin Finck ConsoleGraphicalIsEnabled  (
323*c2c66affSColin Finck     _In_ PBL_GRAPHICS_CONSOLE Console
324*c2c66affSColin Finck     )
325*c2c66affSColin Finck {
326*c2c66affSColin Finck     /* Is the text console active? If so, the graphics console isn't */
327*c2c66affSColin Finck     return !Console->TextConsole.Active;
328*c2c66affSColin Finck }
329*c2c66affSColin Finck 
330*c2c66affSColin Finck VOID
ConsoleGraphicalDestruct(_In_ PBL_GRAPHICS_CONSOLE Console)331*c2c66affSColin Finck ConsoleGraphicalDestruct (
332*c2c66affSColin Finck     _In_ PBL_GRAPHICS_CONSOLE Console
333*c2c66affSColin Finck     )
334*c2c66affSColin Finck {
335*c2c66affSColin Finck     /* Is the text console active? */
336*c2c66affSColin Finck     if (Console->TextConsole.Active)
337*c2c66affSColin Finck     {
338*c2c66affSColin Finck         /* Disable it */
339*c2c66affSColin Finck         ConsoleFirmwareGraphicalDisable(Console);
340*c2c66affSColin Finck     }
341*c2c66affSColin Finck 
342*c2c66affSColin Finck     /* Close the firmware protocols */
343*c2c66affSColin Finck     ConsoleFirmwareGraphicalClose(Console);
344*c2c66affSColin Finck 
345*c2c66affSColin Finck     /* Destroy the console object */
346*c2c66affSColin Finck     ConsoleTextLocalDestruct(&Console->TextConsole);
347*c2c66affSColin Finck }
348*c2c66affSColin Finck 
349*c2c66affSColin Finck NTSTATUS
ConsoleGraphicalReinitialize(_In_ PBL_GRAPHICS_CONSOLE Console)350*c2c66affSColin Finck ConsoleGraphicalReinitialize (
351*c2c66affSColin Finck     _In_ PBL_GRAPHICS_CONSOLE Console
352*c2c66affSColin Finck     )
353*c2c66affSColin Finck {
354*c2c66affSColin Finck     /* Is the text console active? */
355*c2c66affSColin Finck     if (Console->TextConsole.Active)
356*c2c66affSColin Finck     {
357*c2c66affSColin Finck         /* Reinitialize it */
358*c2c66affSColin Finck         ConsoleTextLocalReinitialize(&Console->TextConsole);
359*c2c66affSColin Finck     }
360*c2c66affSColin Finck 
361*c2c66affSColin Finck     /* Disable the graphics console */
362*c2c66affSColin Finck     ConsoleFirmwareGraphicalDisable(Console);
363*c2c66affSColin Finck 
364*c2c66affSColin Finck     /* Then bring it back again */
365*c2c66affSColin Finck     return ConsoleFirmwareGraphicalEnable(Console);
366*c2c66affSColin Finck }
367*c2c66affSColin Finck 
368*c2c66affSColin Finck NTSTATUS
ConsoleGraphicalEnable(_In_ PBL_GRAPHICS_CONSOLE Console,_In_ BOOLEAN Enable)369*c2c66affSColin Finck ConsoleGraphicalEnable (
370*c2c66affSColin Finck     _In_ PBL_GRAPHICS_CONSOLE Console,
371*c2c66affSColin Finck     _In_ BOOLEAN Enable
372*c2c66affSColin Finck     )
373*c2c66affSColin Finck {
374*c2c66affSColin Finck     BOOLEAN Active;
375*c2c66affSColin Finck     NTSTATUS Status;
376*c2c66affSColin Finck 
377*c2c66affSColin Finck     /* The text mode console state should be the opposite of what we want to do */
378*c2c66affSColin Finck     Active = Console->TextConsole.Active;
379*c2c66affSColin Finck     if (Active == Enable)
380*c2c66affSColin Finck     {
381*c2c66affSColin Finck         /* Are we trying to enable graphics? */
382*c2c66affSColin Finck         if (Enable)
383*c2c66affSColin Finck         {
384*c2c66affSColin Finck             /* Enable the console */
385*c2c66affSColin Finck             Status = ConsoleFirmwareGraphicalEnable(Console);
386*c2c66affSColin Finck             if (NT_SUCCESS(Status))
387*c2c66affSColin Finck             {
388*c2c66affSColin Finck                 return Status;
389*c2c66affSColin Finck             }
390*c2c66affSColin Finck 
391*c2c66affSColin Finck             /* Is the text console active? */
392*c2c66affSColin Finck             if (Console->TextConsole.Active)
393*c2c66affSColin Finck             {
394*c2c66affSColin Finck                 /* Turn it off */
395*c2c66affSColin Finck                 ConsoleFirmwareTextClose(&Console->TextConsole);
396*c2c66affSColin Finck                 Console->TextConsole.Active = FALSE;
397*c2c66affSColin Finck             }
398*c2c66affSColin Finck 
399*c2c66affSColin Finck             /* Preserve the text colors */
400*c2c66affSColin Finck             Console->FgColor = Console->TextConsole.State.FgColor;
401*c2c66affSColin Finck             Console->BgColor = Console->TextConsole.State.BgColor;
402*c2c66affSColin Finck         }
403*c2c66affSColin Finck         else
404*c2c66affSColin Finck         {
405*c2c66affSColin Finck             /* We are turning off graphics -- is the text console active? */
406*c2c66affSColin Finck             if (Active != TRUE)
407*c2c66affSColin Finck             {
408*c2c66affSColin Finck                 /* It isn't, so let's turn it on */
409*c2c66affSColin Finck                 Status = ConsoleFirmwareTextOpen(&Console->TextConsole);
410*c2c66affSColin Finck                 if (!NT_SUCCESS(Status))
411*c2c66affSColin Finck                 {
412*c2c66affSColin Finck                     return Status;
413*c2c66affSColin Finck                 }
414*c2c66affSColin Finck 
415*c2c66affSColin Finck                 /* Remember that it's on */
416*c2c66affSColin Finck                 Console->TextConsole.Active = TRUE;
417*c2c66affSColin Finck             }
418*c2c66affSColin Finck 
419*c2c66affSColin Finck             /* Disable the graphics console */
420*c2c66affSColin Finck             ConsoleFirmwareGraphicalDisable(Console);
421*c2c66affSColin Finck         }
422*c2c66affSColin Finck     }
423*c2c66affSColin Finck 
424*c2c66affSColin Finck     /* All good */
425*c2c66affSColin Finck     return STATUS_SUCCESS;
426*c2c66affSColin Finck }
427*c2c66affSColin Finck 
428*c2c66affSColin Finck NTSTATUS
ConsoleGraphicalGetGraphicalResolution(_In_ PBL_GRAPHICS_CONSOLE Console,_In_ PBL_DISPLAY_MODE DisplayMode)429*c2c66affSColin Finck ConsoleGraphicalGetGraphicalResolution (
430*c2c66affSColin Finck     _In_ PBL_GRAPHICS_CONSOLE Console,
431*c2c66affSColin Finck     _In_ PBL_DISPLAY_MODE DisplayMode
432*c2c66affSColin Finck     )
433*c2c66affSColin Finck {
434*c2c66affSColin Finck     /* Is the text console active? */
435*c2c66affSColin Finck     if (Console->TextConsole.Active)
436*c2c66affSColin Finck     {
437*c2c66affSColin Finck         /* There's no graphics resolution then */
438*c2c66affSColin Finck         return STATUS_UNSUCCESSFUL;
439*c2c66affSColin Finck     }
440*c2c66affSColin Finck 
441*c2c66affSColin Finck     /* Return the current display mode */
442*c2c66affSColin Finck     *DisplayMode = Console->DisplayMode;
443*c2c66affSColin Finck     return STATUS_SUCCESS;
444*c2c66affSColin Finck }
445*c2c66affSColin Finck 
446*c2c66affSColin Finck NTSTATUS
ConsoleGraphicalGetOriginalResolution(_In_ PBL_GRAPHICS_CONSOLE Console,_In_ PBL_DISPLAY_MODE DisplayMode)447*c2c66affSColin Finck ConsoleGraphicalGetOriginalResolution (
448*c2c66affSColin Finck     _In_ PBL_GRAPHICS_CONSOLE Console,
449*c2c66affSColin Finck     _In_ PBL_DISPLAY_MODE DisplayMode
450*c2c66affSColin Finck     )
451*c2c66affSColin Finck {
452*c2c66affSColin Finck     /* Is the text console active? */
453*c2c66affSColin Finck     if (Console->TextConsole.Active)
454*c2c66affSColin Finck     {
455*c2c66affSColin Finck         /* There's no graphics resolution then */
456*c2c66affSColin Finck         return STATUS_UNSUCCESSFUL;
457*c2c66affSColin Finck     }
458*c2c66affSColin Finck 
459*c2c66affSColin Finck     /* Return the current display mode */
460*c2c66affSColin Finck     *DisplayMode = Console->OldDisplayMode;
461*c2c66affSColin Finck     return STATUS_SUCCESS;
462*c2c66affSColin Finck }
463