OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
FramebufferInfo.c
Go to the documentation of this file.
1
16#include "ConsoleGopInternal.h"
17
19#include <Protocol/GraphicsOutput.h>
20
21#include <Library/BaseLib.h>
22#include <Library/DebugLib.h>
24#include <Library/OcMiscLib.h>
25#include <Library/UefiBootServicesTableLib.h>
26#include <Library/UefiRuntimeServicesTableLib.h>
27
28STATIC
29EFI_STATUS
30EFIAPI
33 OUT EFI_PHYSICAL_ADDRESS *FramebufferBase,
34 OUT UINT32 *FramebufferSize,
35 OUT UINT32 *ScreenRowBytes,
36 OUT UINT32 *ScreenWidth,
37 OUT UINT32 *ScreenHeight,
38 OUT UINT32 *ScreenDepth
39 )
40{
41 EFI_STATUS Status;
42 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
43 EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE *Mode;
44 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;
45 CONST CONSOLE_GOP_CONTEXT *DirectConsole;
46
47 if ( (This == NULL)
48 || (FramebufferBase == NULL)
49 || (FramebufferSize == NULL)
50 || (ScreenRowBytes == NULL)
51 || (ScreenWidth == NULL)
52 || (ScreenHeight == NULL)
53 || (ScreenDepth == NULL))
54 {
55 return EFI_INVALID_PARAMETER;
56 }
57
58 DirectConsole = InternalGetDirectGopContext ();
59 if (DirectConsole != NULL) {
60 *FramebufferBase = DirectConsole->OriginalFrameBufferBase;
61 *FramebufferSize = (UINT32)DirectConsole->OriginalFrameBufferSize;
62 *ScreenRowBytes = (UINT32)(DirectConsole->OriginalModeInfo.PixelsPerScanLine * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
63 *ScreenWidth = DirectConsole->CustomModeInfo.HorizontalResolution;
64 *ScreenHeight = DirectConsole->CustomModeInfo.VerticalResolution;
65 *ScreenDepth = DEFAULT_COLOUR_DEPTH;
66 return EFI_SUCCESS;
67 }
68
69 Status = gBS->HandleProtocol (
70 gST->ConsoleOutHandle,
72 (VOID **)&GraphicsOutput
73 );
74
75 if (EFI_ERROR (Status)) {
76 return EFI_UNSUPPORTED;
77 }
78
79 Mode = GraphicsOutput->Mode;
80 Info = Mode->Info;
81
82 if (Info == NULL) {
83 return EFI_UNSUPPORTED;
84 }
85
86 //
87 // This is a bit inaccurate as it assumes 32-bit BPP, but will do for most cases.
88 //
89 *FramebufferBase = Mode->FrameBufferBase;
90 *FramebufferSize = (UINT32)Mode->FrameBufferSize;
91 *ScreenRowBytes = (UINT32)(Info->PixelsPerScanLine * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
92 *ScreenWidth = Info->HorizontalResolution;
93 *ScreenHeight = Info->VerticalResolution;
94 *ScreenDepth = DEFAULT_COLOUR_DEPTH;
95
96 return EFI_SUCCESS;
97}
98
99STATIC
104
107 IN BOOLEAN Reinstall
108 )
109{
110 EFI_STATUS Status;
112 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
113 EFI_HANDLE NewHandle;
114
115 DEBUG ((DEBUG_VERBOSE, "OcAppleFbInfoInstallProtocol\n"));
116
117 Status = gBS->LocateProtocol (
119 NULL,
120 (VOID *)&GraphicsOutput
121 );
122
123 if (EFI_ERROR (Status)) {
124 DEBUG ((DEBUG_INFO, "OCFB: No GOP protocols for FB info, ignoring\n"));
125 return NULL;
126 }
127
128 if (Reinstall) {
130 if (EFI_ERROR (Status)) {
131 DEBUG ((DEBUG_ERROR, "OCFB: Uninstall failed: %r\n", Status));
132 return NULL;
133 }
134 } else {
135 Status = gBS->LocateProtocol (
137 NULL,
138 (VOID *)&Protocol
139 );
140
141 if (!EFI_ERROR (Status)) {
142 return Protocol;
143 }
144 }
145
146 NewHandle = NULL;
147 Status = gBS->InstallMultipleProtocolInterfaces (
148 &NewHandle,
150 (VOID *)&mAppleFramebufferInfo,
151 NULL
152 );
153
154 if (EFI_ERROR (Status)) {
155 return NULL;
156 }
157
158 return &mAppleFramebufferInfo;
159}
EFI_GUID gAppleFramebufferInfoProtocolGuid
CONST CONSOLE_GOP_CONTEXT * InternalGetDirectGopContext(VOID)
Definition ConsoleGop.c:635
STATIC APPLE_FRAMEBUFFER_INFO_PROTOCOL mAppleFramebufferInfo
STATIC EFI_STATUS EFIAPI AppleFramebufferGetInfo(IN APPLE_FRAMEBUFFER_INFO_PROTOCOL *This, OUT EFI_PHYSICAL_ADDRESS *FramebufferBase, OUT UINT32 *FramebufferSize, OUT UINT32 *ScreenRowBytes, OUT UINT32 *ScreenWidth, OUT UINT32 *ScreenHeight, OUT UINT32 *ScreenDepth)
APPLE_FRAMEBUFFER_INFO_PROTOCOL * OcAppleFbInfoInstallProtocol(IN BOOLEAN Reinstall)
EFI_SYSTEM_TABLE * gST
EFI_BOOT_SERVICES * gBS
#define DEFAULT_COLOUR_DEPTH
EFI_STATUS OcUninstallAllProtocolInstances(EFI_GUID *Protocol)
EFI_GUID gEfiGraphicsOutputProtocolGuid