Skip to content

Commit

Permalink
OcAppleEventLib: Do not cache screen resolution
Browse files Browse the repository at this point in the history
Fixes an issue where drivers requesting AppleEvent events early (e.g. CrScreenshotLib) cause caching of a screen resolution that is later changed, leading to an out-of-sync cursor movement rectangle.
  • Loading branch information
mhaeuser committed Apr 7, 2021
1 parent e55a700 commit 7235a99
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 90 deletions.
3 changes: 3 additions & 0 deletions Changelog.md
@@ -1,5 +1,8 @@
OpenCore Changelog
==================
#### v0.6.9
- Fixed out-of-sync cursor movement rectangle when loading e.g. CrScreenshotDxe

#### v0.6.8
- Switched to VS2019 toolchain for Windows builds
- Reduced legacy boot install interaction effort
Expand Down
161 changes: 71 additions & 90 deletions Library/OcAppleEventLib/PointerHandler.c
Expand Up @@ -125,11 +125,8 @@ STATIC DIMENSION mCursorPosition;
// mMouseMoved
STATIC BOOLEAN mMouseMoved;

// mScreenResolutionSet
STATIC BOOLEAN mScreenResolutionSet;

// mScreenResolution
STATIC DIMENSION mResolution;
STATIC DIMENSION mResolution = { 800, 600 };

STATIC UINT64 mMaxPointerResolutionX = 1;
STATIC UINT64 mMaxPointerResolutionY = 1;
Expand Down Expand Up @@ -439,7 +436,7 @@ EventCloseSimplePointerInstallNotifyEvent (

// InternalGetScreenResolution
STATIC
EFI_STATUS
VOID
InternalGetScreenResolution (
VOID
)
Expand All @@ -455,85 +452,75 @@ InternalGetScreenResolution (

DEBUG ((DEBUG_VERBOSE, "InternalGetScreenResolution\n"));

Status = gBS->HandleProtocol (
gST->ConsoleOutHandle,
&gEfiGraphicsOutputProtocolGuid,
(VOID **)&GraphicsOutput
);
//
// CHANGE: Do not cache screen resolution to account for changes.
//

if (Status == EFI_UNSUPPORTED) {
//
// Fallback to default resolution.
//
mResolution.Horizontal = 800;
mResolution.Vertical = 600;
HorizontalResolution = 0;
VerticalResolution = 0;

Status = gBS->HandleProtocol (
gST->ConsoleOutHandle,
&gEfiGraphicsOutputProtocolGuid,
(VOID **)&GraphicsOutput
);
if (!EFI_ERROR (Status)) {
Info = GraphicsOutput->Mode->Info;
HorizontalResolution = Info->HorizontalResolution;
VerticalResolution = Info->VerticalResolution;
} else if (Status == EFI_UNSUPPORTED) {
Status = gBS->HandleProtocol (
gST->ConsoleOutHandle,
&gEfiUgaDrawProtocolGuid,
(VOID **)&UgaDraw
);
gST->ConsoleOutHandle,
&gEfiUgaDrawProtocolGuid,
(VOID **)&UgaDraw
);
DEBUG ((
DEBUG_INFO,
"OCAE: Failed to handle GOP, discovering UGA - %r\n",
Status
));

if (!EFI_ERROR (Status)) {
Status = UgaDraw->GetMode (
UgaDraw,
&HorizontalResolution,
&VerticalResolution,
&ColorDepth,
&RefreshRate
);
UgaDraw,
&HorizontalResolution,
&VerticalResolution,
&ColorDepth,
&RefreshRate
);
}
}

//
// Apple does not check for Horizontal/Vertical resolution being > 0 here
//
if (!EFI_ERROR (Status) && HorizontalResolution > 0 && VerticalResolution > 0) {
mResolution.Horizontal = HorizontalResolution;
mResolution.Vertical = VerticalResolution;
//
// Apple does not set mScreenResolutionSet to true here
//
mScreenResolutionSet = TRUE;
}
if (!EFI_ERROR (Status)) {
if (HorizontalResolution > 0 && VerticalResolution > 0) {
mResolution.Horizontal = (INT32) HorizontalResolution;
mResolution.Vertical = (INT32) VerticalResolution;

DEBUG ((
DEBUG_INFO,
"OCAE: Failed to handle GOP, discovering UGA - %r\n",
Status
));
if (mCursorPosition.Horizontal >= mResolution.Horizontal) {
mCursorPosition.Horizontal = mResolution.Horizontal - 1;
}

Status = EFI_SUCCESS;
} else if (!EFI_ERROR (Status)) {
Info = GraphicsOutput->Mode->Info;
mResolution.Horizontal = Info->HorizontalResolution;
mResolution.Vertical = Info->VerticalResolution;
if (mCursorPosition.Vertical >= mResolution.Vertical) {
mCursorPosition.Vertical = mResolution.Vertical - 1;
}

//
// Apple does not check Info->HorizontalResolution being > 0 here
//
if (Info->HorizontalResolution > 0 && Info->VerticalResolution > 0) {
mScreenResolutionSet = TRUE;
DEBUG ((
DEBUG_INFO,
"OCAE: Set screen resolution to %dx%d - %r\n",
mResolution.Horizontal,
mResolution.Vertical,
Status
));
} else {
Status = EFI_NOT_READY;
DEBUG ((DEBUG_INFO, "OCAE: Screen resolution has 0-dimension\n"));
}
} else {
DEBUG ((
DEBUG_INFO,
"OCAE: Failed to handle GOP - %r\n",
"OCAE: Failed to get screen resolution - %r\n",
Status
));
}

DEBUG ((
DEBUG_INFO,
"OCAE: Set screen resolution to %dx%d [%d] - %r\n",
mResolution.Horizontal,
mResolution.Vertical,
mScreenResolutionSet,
Status
));

return Status;
}

// InternalGetUiScaleData
Expand Down Expand Up @@ -988,34 +975,28 @@ EventSetCursorPositionImpl (

DEBUG ((DEBUG_VERBOSE, "EventSetCursorPositionImpl\n"));

if (!mScreenResolutionSet) {
Status = InternalGetScreenResolution ();
}
InternalGetScreenResolution ();

if (mScreenResolutionSet) {
Status = EFI_INVALID_PARAMETER;
Status = EFI_INVALID_PARAMETER;

//
// Apple did not check for negatives here.
//
//
// Apple did not check for negatives here.
//

if (Position->Horizontal >= 0 && Position->Vertical >= 0
&& (Position->Horizontal < mResolution.Horizontal)
&& (Position->Vertical < mResolution.Vertical)) {
mCursorPosition.Horizontal = Position->Horizontal;
mCursorPosition.Vertical = Position->Vertical;
mPointerRawX = MultS64x64 (
mCursorPosition.Horizontal,
(INT64) mMaxPointerResolutionX
);
mPointerRawY = MultS64x64 (
mCursorPosition.Vertical,
(INT64) mMaxPointerResolutionY
);
Status = EFI_SUCCESS;
}
} else if (EFI_ERROR (Status)) {
Status = EFI_NOT_READY;
if (Position->Horizontal >= 0 && Position->Vertical >= 0
&& (Position->Horizontal < mResolution.Horizontal)
&& (Position->Vertical < mResolution.Vertical)) {
mCursorPosition.Horizontal = Position->Horizontal;
mCursorPosition.Vertical = Position->Vertical;
mPointerRawX = MultS64x64 (
mCursorPosition.Horizontal,
(INT64) mMaxPointerResolutionX
);
mPointerRawY = MultS64x64 (
mCursorPosition.Vertical,
(INT64) mMaxPointerResolutionY
);
Status = EFI_SUCCESS;
}

return Status;
Expand Down

0 comments on commit 7235a99

Please sign in to comment.