35 IN EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput,
36 IN UINT32 Width OPTIONAL,
37 IN UINT32 Height OPTIONAL,
38 IN UINT32 Bpp OPTIONAL
47 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;
50 SetMax = Width == 0 && Height == 0;
54 "OCC: Requesting %ux%u@%u (max: %d) resolution, curr %u, total %u\n",
59 (UINT32)GraphicsOutput->Mode->Mode,
60 (UINT32)GraphicsOutput->Mode->MaxMode
65 "OCC: Current FB at 0x%LX (0x%X), format %d, res %ux%u scan %u\n",
66 GraphicsOutput->Mode->FrameBufferBase,
67 (UINT32)GraphicsOutput->Mode->FrameBufferSize,
68 GraphicsOutput->Mode->Info != NULL ? GraphicsOutput->Mode->Info->PixelFormat : -1,
69 GraphicsOutput->Mode->Info != NULL ? GraphicsOutput->Mode->Info->HorizontalResolution : 0,
70 GraphicsOutput->Mode->Info != NULL ? GraphicsOutput->Mode->Info->VerticalResolution : 0,
71 GraphicsOutput->Mode->Info != NULL ? GraphicsOutput->Mode->Info->PixelsPerScanLine : 0
78 MaxMode = GraphicsOutput->Mode->MaxMode;
79 for (ModeIndex = 0; ModeIndex < MaxMode; ++ModeIndex) {
80 Status = GraphicsOutput->QueryMode (
87 if (EFI_ERROR (Status)) {
88 DEBUG ((DEBUG_INFO,
"OCC: Mode %u failure - %r\n", ModeIndex, Status));
94 "OCC: Mode %u - %ux%u:%u\n",
96 Info->HorizontalResolution,
97 Info->VerticalResolution,
105 if ( (Info->HorizontalResolution == Width)
106 && (Info->VerticalResolution == Height)
107 && ((Bpp == 0) || (Bpp == 24) || (Bpp == 32))
108 && ( (Info->PixelFormat == PixelRedGreenBlueReserved8BitPerColor)
109 || (Info->PixelFormat == PixelBlueGreenRedReserved8BitPerColor)
110 || ( (Info->PixelFormat == PixelBitMask)
111 && ( (Info->PixelInformation.RedMask == 0xFF000000U)
112 || (Info->PixelInformation.RedMask == 0xFF0000U)
113 || (Info->PixelInformation.RedMask == 0xFF00U)
114 || (Info->PixelInformation.RedMask == 0xFFU)))
115 || (Info->PixelFormat == PixelBltOnly)))
117 ModeNumber = ModeIndex;
121 }
else if ( (Info->HorizontalResolution > Width)
122 || ((Info->HorizontalResolution == Width) && (Info->VerticalResolution > Height)))
124 Width = Info->HorizontalResolution;
125 Height = Info->VerticalResolution;
126 ModeNumber = ModeIndex;
132 if (ModeNumber < 0) {
133 DEBUG ((DEBUG_WARN,
"OCC: No compatible mode for %ux%u@%u (max: %u) resolution\n", Width, Height, Bpp, SetMax));
134 return EFI_NOT_FOUND;
137 if (ModeNumber == GraphicsOutput->Mode->Mode) {
138 DEBUG ((DEBUG_INFO,
"OCC: Current mode matches desired mode %u\n", (UINT32)ModeNumber));
139 return EFI_ALREADY_STARTED;
148 "OCC: Setting mode %u with %ux%u resolution\n",
154 Status = GraphicsOutput->SetMode (GraphicsOutput, (UINT32)ModeNumber);
155 if (EFI_ERROR (Status)) {
158 "OCC: Failed to set mode %u (prev %u) with %ux%u resolution\n",
160 (UINT32)GraphicsOutput->Mode->Mode,
167 DEBUG ((DEBUG_INFO,
"OCC: Changed resolution mode to %u\n", (UINT32)GraphicsOutput->Mode->Mode));
174 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut,
187 SetMax = Width == 0 && Height == 0;
191 "OCC: Requesting %ux%u (max: %d) console mode, curr %u, max %u\n",
195 (UINT32)TextOut->Mode->Mode,
196 (UINT32)TextOut->Mode->MaxMode
203 MaxMode = TextOut->Mode->MaxMode;
204 for (ModeIndex = 0; ModeIndex < MaxMode; ++ModeIndex) {
205 Status = TextOut->QueryMode (
212 if (EFI_ERROR (Status)) {
218 "OCC: Mode %u - %ux%u\n",
228 if ((Columns == Width) && (Rows == Height)) {
229 ModeNumber = ModeIndex;
232 }
else if ( ((UINT32)Columns > Width)
233 || (((UINT32)Columns == Width) && ((UINT32)Rows > Height)))
235 Width = (UINT32)Columns;
236 Height = (UINT32)Rows;
237 ModeNumber = ModeIndex;
241 if (ModeNumber < 0) {
242 DEBUG ((DEBUG_WARN,
"OCC: No compatible mode for %ux%u (max: %u) console mode\n", Width, Height, SetMax));
243 return EFI_NOT_FOUND;
246 if (ModeNumber == TextOut->Mode->Mode) {
253 "OCC: Current console mode matches desired mode %u, forcing update\n",
264 "OCC: Setting mode %u (prev %u) with %ux%u console mode\n",
266 (UINT32)TextOut->Mode->Mode,
271 Status = TextOut->SetMode (TextOut, (UINTN)ModeNumber);
272 if (EFI_ERROR (Status)) {
275 "OCC: Failed to set mode %u with %ux%u console mode\n",
283 DEBUG ((DEBUG_INFO,
"OCC: Changed console mode to %u\n", (UINT32)TextOut->Mode->Mode));
290 IN UINT32 Width OPTIONAL,
291 IN UINT32 Height OPTIONAL,
292 IN UINT32 Bpp OPTIONAL,
297 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
304 Result =
gBS->LocateProtocol (
307 (VOID **)&OcForceResolution
310 if (!EFI_ERROR (Result)) {
311 Result = OcForceResolution->SetResolution (OcForceResolution, Width, Height);
312 if (EFI_ERROR (Result)) {
313 DEBUG ((DEBUG_WARN,
"OCC: Failed to force resolution - %r\n", Result));
316 DEBUG ((DEBUG_INFO,
"OCC: Missing OcForceResolution protocol - %r\n", Result));
320 #ifdef OC_CONSOLE_CHANGE_ALL_RESOLUTIONS
323 EFI_HANDLE *HandleBuffer;
326 Result =
gBS->LocateHandleBuffer (
334 if (!EFI_ERROR (Result)) {
335 Result = EFI_NOT_FOUND;
337 DEBUG ((DEBUG_INFO,
"OCC: Found %u handles with GOP\n", (UINT32)HandleCount));
339 for (Index = 0; Index < HandleCount; ++Index) {
340 DEBUG ((DEBUG_INFO,
"OCC: Trying handle %u - %p\n", (UINT32)Index, HandleBuffer[Index]));
342 Status =
gBS->HandleProtocol (
345 (VOID **)&GraphicsOutput
348 if (EFI_ERROR (Status)) {
349 DEBUG ((DEBUG_WARN,
"OCC: Missing GOP on console - %r\n", Status));
356 FreePool (HandleBuffer);
358 DEBUG ((DEBUG_INFO,
"OCC: Failed to find handles with GOP - %r\n", Result));
362 Result =
gBS->HandleProtocol (
363 gST->ConsoleOutHandle,
365 (VOID **)&GraphicsOutput
368 if (EFI_ERROR (Result)) {
369 DEBUG ((DEBUG_WARN,
"OCC: Missing GOP on ConOut - %r\n", Result));
393 IN CONST CHAR8 *Font OPTIONAL,
394 IN BOOLEAN IgnoreTextOutput,
395 IN BOOLEAN SanitiseClearScreen,
396 IN BOOLEAN ClearScreenOnModeSwitch,
397 IN BOOLEAN ReplaceTabWithSpace,
416 ClearScreenOnModeSwitch,
VOID OcSetupConsole(IN EFI_CONSOLE_CONTROL_SCREEN_MODE InitialMode, IN OC_CONSOLE_RENDERER Renderer, IN OC_STORAGE_CONTEXT *Storage OPTIONAL, IN CONST CHAR8 *Font OPTIONAL, IN BOOLEAN IgnoreTextOutput, IN BOOLEAN SanitiseClearScreen, IN BOOLEAN ClearScreenOnModeSwitch, IN BOOLEAN ReplaceTabWithSpace, IN UINT32 Width, IN UINT32 Height)
EFI_STATUS OcUseSystemTextOutput(IN EFI_CONSOLE_CONTROL_SCREEN_MODE InitialMode, IN OC_CONSOLE_RENDERER Renderer, IN BOOLEAN IgnoreTextOutput, IN BOOLEAN SanitiseClearScreen, IN BOOLEAN ClearScreenOnModeSwitch, IN BOOLEAN ReplaceTabWithSpace)