RDFU  1.0
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
Screen.c File Reference

Screen support functions. More...

#include "EfiScannerHeaders.h"
#include "Screen.h"
#include "efiGraphicsOutput.h"
#include "efiUgaDraw.h"
#include "ConsoleControl.h"
#include "logo.h"
Include dependency graph for Screen.c:

Go to the source code of this file.

Macros

#define EFI_CONSOLE_CONTROL_PROTOCOL_GUID   { 0xf42f7782, 0x12e, 0x4c12, {0x99, 0x56, 0x49, 0xf9, 0x43, 0x4, 0xf7, 0x21} }
 

Functions

EFI_STATUS PickBestTextMode (VOID)
 
EFI_STATUS ScreenEnableGraphicsMode (BOOLEAN Enable)
 
EFI_STATUS ScreenGetResolution (VOID)
 
EFI_STATUS ScreenInit (VOID)
 
EFI_STATUS ScreenClearToColor (RGBPIXEL *Color)
 
EFI_STATUS ScreenDrawImage (GIMAGE *Image, UINTN ScreenPosX, UINTN ScreenPosY)
 
EFI_STATUS ScreenShowSplashLogo (VOID)
 

Variables

static EFI_GUID ggConsoleControlProtocolGuid = EFI_CONSOLE_CONTROL_PROTOCOL_GUID
 
static
EFI_CONSOLE_CONTROL_PROTOCOL * 
gConsoleControlProt = NULL
 
static EFI_GUID ggUgaDrawProtocolGuid = EFI_UGA_DRAW_PROTOCOL_GUID
 
static EFI_UGA_DRAW_PROTOCOL * gUgaDrawProt = NULL
 
static EFI_GUID ggGraphicsOutputProtocolGuid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID
 
static
EFI_GRAPHICS_OUTPUT_PROTOCOL * 
gGraphicsOutputProt = NULL
 
UINTN ScreenWidthProbed = 0
 
UINTN ScreenHeightProbed = 0
 
BOOLEAN GraphicsAvailable = FALSE
 

Detailed Description

Screen support functions.

Author
Piotr Bania
Date
Feb 2013 Support for GraphicsOutputProtocol, ConsoleControlProtocol, UgaDrawProtocol. Displaying images, switching from gfx mode to text mode and vice versa, etc.

Definition in file Screen.c.

Macro Definition Documentation

#define EFI_CONSOLE_CONTROL_PROTOCOL_GUID   { 0xf42f7782, 0x12e, 0x4c12, {0x99, 0x56, 0x49, 0xf9, 0x43, 0x4, 0xf7, 0x21} }

Definition at line 22 of file Screen.c.

Function Documentation

EFI_STATUS PickBestTextMode ( VOID  )

following function is not used.

Definition at line 47 of file Screen.c.

References EFI_STATUS(), and LogFullAscii().

48 {
49  EFI_STATUS Status;
50  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *SimpleTextProt;
51  UINTN TestMode, Columns, Rows;
52 
53 
54  Status = gBS->LocateProtocol(&gEfiSimpleTextOutProtocolGuid, NULL, (VOID **) &SimpleTextProt);
55  if (EFI_ERROR(Status))
56  {
57  LogFullAscii("PickBestTextMode: error unable to locate SimpleTextProtocol\r\n");
58  return Status;
59  }
60 
61 
62  // lets enumerate all possible modes
63  // appending to the UEFI documentation the Text Output Protocol
64  // should at least provide the 0-Mode (80x25 text mode)
65  // we assume everything beyond that is better
66  // not used because even if there is a higher resolution mode
67  // it is provided typically as 0-Mode as well
68  // (so there is no 80x25 mode it is exchanged with higher
69  // resolution, but still there is only one mode available)
70 
71  TestMode = 0;
72  do
73  {
74  Status = SimpleTextProt->QueryMode(SimpleTextProt, TestMode, &Columns, &Rows);
75 
76  LogFullAscii("ScreenEnableGraphicsMode: Mode=%d Columns=%d Rows=%d\r\n",
77  TestMode,
78  Columns,
79  Rows);
80  TestMode++;
81  } while (Status == EFI_SUCCESS);
82 
83 
84  return EFI_SUCCESS;
85 }

Here is the call graph for this function:

EFI_STATUS ScreenClearToColor ( RGBPIXEL *  Color)

Function clears screen to selected color.

Definition at line 207 of file Screen.c.

References _EFI_UGA_DRAW_PROTOCOL::Blt, _EFI_GRAPHICS_OUTPUT_PROTOCOL::Blt, EfiBltVideoFill, EfiUgaVideoFill, GraphicsAvailable, ScreenHeightProbed, and ScreenWidthProbed.

Referenced by ScreenShowSplashLogo().

208 {
209 
210  if (!GraphicsAvailable)
211  return EFI_NOT_FOUND;
212 
213  if (gGraphicsOutputProt != NULL)
214  {
218  0, 0, 0, 0,
221  0);
222  return EFI_SUCCESS;
223  }
224 
225  if (gUgaDrawProt != NULL)
226  {
228  (EFI_UGA_PIXEL*)&Color,
230  0, 0, 0, 0,
233  0);
234  return EFI_SUCCESS;
235  }
236 
237  return EFI_NOT_FOUND;
238 }

Here is the caller graph for this function:

EFI_STATUS ScreenDrawImage ( GIMAGE *  Image,
UINTN  ScreenPosX,
UINTN  ScreenPosY 
)

Function draws image on the screen at position x and y.

Definition at line 246 of file Screen.c.

References _EFI_UGA_DRAW_PROTOCOL::Blt, _EFI_GRAPHICS_OUTPUT_PROTOCOL::Blt, _GIMAGE::Data, EfiBltBufferToVideo, EfiUgaBltBufferToVideo, GraphicsAvailable, _GIMAGE::Height, and _GIMAGE::Width.

Referenced by ScreenShowSplashLogo().

249 {
250  if (!GraphicsAvailable || !Image)
251  return EFI_NOT_FOUND;
252 
253 
254  if (gGraphicsOutputProt != NULL)
255  {
256 
260  0, 0,
261  ScreenPosX,
262  ScreenPosY,
263  Image->Width,
264  Image->Height,
265  0);
266  return EFI_SUCCESS;
267 
268  }
269 
270  if (gUgaDrawProt != NULL)
271  {
273  (EFI_UGA_PIXEL *)Image->Data,
275  0, 0,
276  ScreenPosX,
277  ScreenPosY,
278  Image->Width,
279  Image->Height, 0);
280  return EFI_SUCCESS;
281  }
282 
283  return EFI_NOT_FOUND;
284 }

Here is the caller graph for this function:

EFI_STATUS ScreenEnableGraphicsMode ( BOOLEAN  Enable)

Functions switches to gfx or text mode

Definition at line 90 of file Screen.c.

References EfiConsoleControlScreenGraphics, EfiConsoleControlScreenText, _EFI_CONSOLE_CONTROL_PROTOCOL::GetMode, and _EFI_CONSOLE_CONTROL_PROTOCOL::SetMode.

Referenced by ScreenShowSplashLogo().

91 {
92 
93  EFI_CONSOLE_CONTROL_SCREEN_MODE NewMode, CurrentMode;
94 
96 
97  if (gConsoleControlProt != NULL)
98  {
99 
100  gConsoleControlProt->GetMode(gConsoleControlProt, &CurrentMode, NULL, NULL);
101 
102  if (CurrentMode != NewMode)
104  }
105 
106  return EFI_SUCCESS;
107 }

Here is the caller graph for this function:

EFI_STATUS ScreenGetResolution ( VOID  )

Function get the screen resolution and puts it into global variables. (using both UGA and GOP protocols if available)

Definition at line 114 of file Screen.c.

References EFI_STATUS(), _EFI_UGA_DRAW_PROTOCOL::GetMode, GraphicsAvailable, EFI_GRAPHICS_OUTPUT_MODE_INFORMATION::HorizontalResolution, EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE::Info, LogFullAscii(), _EFI_GRAPHICS_OUTPUT_PROTOCOL::Mode, ScreenHeightProbed, ScreenWidthProbed, and EFI_GRAPHICS_OUTPUT_MODE_INFORMATION::VerticalResolution.

Referenced by ScreenInit().

115 {
116  EFI_STATUS Status;
117  UINT32 UGAWidth, UGAHeight, UGADepth, UGARefreshRate;
118 
119  GraphicsAvailable = FALSE;
120 
121 
122  if (gGraphicsOutputProt != NULL)
123  {
124 
127  GraphicsAvailable = TRUE;
128  return EFI_SUCCESS;
129  }
130 
131  if (gUgaDrawProt != NULL)
132  {
133  Status = gUgaDrawProt->GetMode(gUgaDrawProt,
134  &UGAWidth,
135  &UGAHeight,
136  &UGADepth,
137  &UGARefreshRate);
138 
139  if (EFI_ERROR(Status))
140  {
141  LogFullAscii("ScreenGetResolution: calling gUgaDrawProt->GetMode failed!\r\n");
142 
143  gUgaDrawProt = NULL;
144  return Status;
145  }
146 
147  // all good
148  ScreenHeightProbed = UGAHeight;
149  ScreenWidthProbed = UGAWidth;
150  GraphicsAvailable = TRUE;
151  return EFI_SUCCESS;
152  }
153 
154  return EFI_NOT_FOUND;
155 }

Here is the call graph for this function:

Here is the caller graph for this function:

EFI_STATUS ScreenInit ( VOID  )

Function inits the screen and resolves are necessary protocols.

In order to stay compatible we need to support Universal Graphics Adapter Protocol (UGA) and the Graphics Output Protocol (GOP) which was introduced later as an UGA replacement. The console control protocol is essential for console output.

Definition at line 168 of file Screen.c.

References EFI_STATUS(), ggConsoleControlProtocolGuid, ggGraphicsOutputProtocolGuid, ggUgaDrawProtocolGuid, LogFullAscii(), and ScreenGetResolution().

Referenced by ScreenShowSplashLogo().

169 {
170  EFI_STATUS Status;
171 
172  gConsoleControlProt = NULL;
173  gUgaDrawProt = NULL;
174  gGraphicsOutputProt = NULL;
175 
176  // get protocols
177  Status = gBS->LocateProtocol(&ggConsoleControlProtocolGuid,
178  NULL,
179  (VOID**)&gConsoleControlProt);
180 
181  if (EFI_ERROR(Status))
182  LogFullAscii("ScreenInit: error unable to locate gConsoleControlProtocol\r\n");
183 
184  Status = gBS->LocateProtocol(&ggUgaDrawProtocolGuid,
185  NULL,
186  (VOID**)&gUgaDrawProt);
187 
188  if (EFI_ERROR(Status))
189  LogFullAscii("ScreenInit: error unable to locate gUgaDrawProtocol\r\n");
190 
191  Status = gBS->LocateProtocol(&ggGraphicsOutputProtocolGuid,
192  NULL,
193  (VOID**)&gGraphicsOutputProt);
194 
195  if (EFI_ERROR(Status))
196  LogFullAscii("ScreenInit: error unable to locate gGraphicsOutputProtocol");
197 
198  return ScreenGetResolution();
199 }

Here is the call graph for this function:

Here is the caller graph for this function:

EFI_STATUS ScreenShowSplashLogo ( VOID  )

Function shows the main logo on the screen (for 5 seconds) and then switches back to console mode.

Definition at line 295 of file Screen.c.

References _GIMAGE::Data, EFI_STATUS(), _GIMAGE::Height, ImageLoadBMPFromMem(), LogFullAscii(), logo, ScreenClearToColor(), ScreenDrawImage(), ScreenEnableGraphicsMode(), ScreenHeightProbed, ScreenInit(), ScreenWidthProbed, TICKS_PER_MS, and _GIMAGE::Width.

Referenced by MainLoop(), and TestDumpHandles().

296 {
297  EFI_STATUS Status;
298  GIMAGE *Image;
299  UINTN x, y;
300 
301 
302  Status = ScreenInit();
303  if (EFI_ERROR(Status))
304  {
305  LogFullAscii("ScreenShowSplashLogo: unable to initialize screen!\r\n");
306  return EFI_NOT_FOUND;
307  }
308 
310 
311  Image = ImageLoadBMPFromMem((UINT8*)&logo, sizeof(logo));
312  if (!Image)
313  {
314  LogFullAscii("ScreenShowSplashLogo: unable to load splash image!\r\n");
315  return EFI_NOT_FOUND;
316  }
317 
318 
319  // clear screen to the color of first pixel
320  ScreenClearToColor(&Image->Data[0]);
321 
322  // draw it
323  x = (ScreenWidthProbed/2) - (Image->Width/2);
324  y = (ScreenHeightProbed/2) - (Image->Height/2);
325 
326  ScreenDrawImage(Image, x, y);
327 
328  // sleep for 5 sec (5000000 us)
329  gBS->Stall(500*TICKS_PER_MS);
330 
331  // switch back to console mode
333 
334  return EFI_SUCCESS;
335 }

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

EFI_CONSOLE_CONTROL_PROTOCOL* gConsoleControlProt = NULL
static

Definition at line 26 of file Screen.c.

EFI_GUID ggConsoleControlProtocolGuid = EFI_CONSOLE_CONTROL_PROTOCOL_GUID
static

Definition at line 25 of file Screen.c.

Referenced by ScreenInit().

EFI_GUID ggGraphicsOutputProtocolGuid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID
static

Definition at line 31 of file Screen.c.

Referenced by ScreenInit().

EFI_GRAPHICS_OUTPUT_PROTOCOL* gGraphicsOutputProt = NULL
static

Definition at line 32 of file Screen.c.

EFI_GUID ggUgaDrawProtocolGuid = EFI_UGA_DRAW_PROTOCOL_GUID
static

Definition at line 28 of file Screen.c.

Referenced by ScreenInit().

BOOLEAN GraphicsAvailable = FALSE

Definition at line 40 of file Screen.c.

Referenced by ScreenClearToColor(), ScreenDrawImage(), and ScreenGetResolution().

EFI_UGA_DRAW_PROTOCOL* gUgaDrawProt = NULL
static

Definition at line 29 of file Screen.c.

UINTN ScreenHeightProbed = 0

Definition at line 37 of file Screen.c.

Referenced by ScreenClearToColor(), ScreenGetResolution(), and ScreenShowSplashLogo().

UINTN ScreenWidthProbed = 0

Definition at line 36 of file Screen.c.

Referenced by ScreenClearToColor(), ScreenGetResolution(), and ScreenShowSplashLogo().