Handle screen orientation

This commit is contained in:
Lauri Kenttä
2023-09-10 15:02:58 +03:00
parent e5616c6cd2
commit 75e64a7ef3
4 changed files with 34 additions and 16 deletions
+5 -4
View File
@@ -11,6 +11,7 @@ boot=MS
# - "n=(number)", a weight for this image in the randomization process. Default: n=1. # - "n=(number)", a weight for this image in the randomization process. Default: n=1.
# - "x=(number)" or "x=keep", the x offset from the center. Default: x=0. # - "x=(number)" or "x=keep", the x offset from the center. Default: x=0.
# - "y=(number)" or "y=keep", the y offset from the center. Default: y=0. # - "y=(number)" or "y=keep", the y offset from the center. Default: y=0.
# - "o=(0|90|180|270|keep)", the screen orientation, degrees anticlockwise. Default: o=keep.
# One of the following: # One of the following:
# - "keep" to keep the firmware logo. Also keeps coordinates by default. # - "keep" to keep the firmware logo. Also keeps coordinates by default.
# - "remove" to remove the BGRT. Makes x and y meaningless. # - "remove" to remove the BGRT. Makes x and y meaningless.
@@ -23,14 +24,14 @@ boot=MS
# - image=remove # - image=remove
# - image=black # - image=black
# - image= x=0 y=-200 path=\EFI\HackBGRT\topimage.bmp # - image= x=0 y=-200 path=\EFI\HackBGRT\topimage.bmp
# - image=n=1,path=\EFI\HackBGRT\splash.bmp # - image= n=1 o=90 path=\EFI\HackBGRT\sideways.bmp
# - image=n=50,path=\EFI\HackBGRT\probable.bmp # - image= n=50 y=999999 o=keep path=\EFI\HackBGRT\probable.bmp
# The above examples together would produce # The above examples together would produce
# - 1/54 chance for the default OS logo # - 1/54 chance for the default OS logo
# - 1/54 chance for black screen # - 1/54 chance for black screen
# - 1/54 chance for topimage.bmp, 200 px above the center of the screen # - 1/54 chance for topimage.bmp, 200 px above the center of the screen
# - 1/54 chance for splash.bmp, automatically positioned # - 1/54 chance for splash.bmp, centered, orientation set to 90 degrees
# - 50/54 chance for probable.bmp, automatically positioned # - 50/54 chance for probable.bmp, at the bottom edge, explicitly default orientation
# Default: just one image. # Default: just one image.
image= y=-200 path=\EFI\HackBGRT\splash.bmp image= y=-200 path=\EFI\HackBGRT\splash.bmp
+8 -3
View File
@@ -70,16 +70,17 @@ BOOLEAN ReadConfigFile(struct HackBGRT_config* config, EFI_FILE_HANDLE root_dir,
return TRUE; return TRUE;
} }
static void SetBMPWithRandom(struct HackBGRT_config* config, int weight, enum HackBGRT_action action, int x, int y, const CHAR16* path) { static void SetBMPWithRandom(struct HackBGRT_config* config, int weight, enum HackBGRT_action action, int x, int y, int o, const CHAR16* path) {
config->image_weight_sum += weight; config->image_weight_sum += weight;
UINT32 random = Random(); UINT32 random = Random();
UINT32 limit = 0xfffffffful / config->image_weight_sum * weight; UINT32 limit = 0xfffffffful / config->image_weight_sum * weight;
if (config->debug) { if (config->debug) {
Print(L"HackBGRT: weight %d, action %d, x %d, y %d, path %s, random = %08x, limit = %08x\n", weight, action, x, y, path, random, limit); Print(L"HackBGRT: weight %d, action %d, x %d, y %d, o %d, path %s, random = %08x, limit = %08x\n", weight, action, x, y, o, path, random, limit);
} }
if (!config->image_weight_sum || random <= limit) { if (!config->image_weight_sum || random <= limit) {
config->action = action; config->action = action;
config->image_path = path; config->image_path = path;
config->orientation = o;
config->image_x = x; config->image_x = x;
config->image_y = y; config->image_y = y;
} }
@@ -99,6 +100,7 @@ static void ReadConfigImage(struct HackBGRT_config* config, const CHAR16* line)
const CHAR16* n = StrStrAfter(line, L"n="); const CHAR16* n = StrStrAfter(line, L"n=");
const CHAR16* x = StrStrAfter(line, L"x="); const CHAR16* x = StrStrAfter(line, L"x=");
const CHAR16* y = StrStrAfter(line, L"y="); const CHAR16* y = StrStrAfter(line, L"y=");
const CHAR16* o = StrStrAfter(line, L"o=");
const CHAR16* f = StrStrAfter(line, L"path="); const CHAR16* f = StrStrAfter(line, L"path=");
enum HackBGRT_action action = HackBGRT_KEEP; enum HackBGRT_action action = HackBGRT_KEEP;
if (f) { if (f) {
@@ -114,7 +116,10 @@ static void ReadConfigImage(struct HackBGRT_config* config, const CHAR16* line)
return; return;
} }
int weight = n && (!f || n < f) ? Atoi(n) : 1; int weight = n && (!f || n < f) ? Atoi(n) : 1;
SetBMPWithRandom(config, weight, action, ParseCoordinate(x, action), ParseCoordinate(y, action), f); int x_val = ParseCoordinate(x, action);
int y_val = ParseCoordinate(y, action);
int o_val = o ? ParseCoordinate(o, action) : HackBGRT_coord_keep;
SetBMPWithRandom(config, weight, action, x_val, y_val, o_val, f);
} }
static void ReadConfigResolution(struct HackBGRT_config* config, const CHAR16* line) { static void ReadConfigResolution(struct HackBGRT_config* config, const CHAR16* line) {
+2 -1
View File
@@ -14,7 +14,7 @@ enum HackBGRT_action {
* @see struct HackBGRT_config * @see struct HackBGRT_config
*/ */
enum HackBGRT_coordinate { enum HackBGRT_coordinate {
HackBGRT_coord_keep = -999999 HackBGRT_coord_keep = -1000000001
}; };
/** /**
@@ -27,6 +27,7 @@ struct HackBGRT_config {
int image_x; int image_x;
int image_y; int image_y;
int image_weight_sum; int image_weight_sum;
int orientation;
int resolution_x; int resolution_x;
int resolution_y; int resolution_y;
int old_resolution_x; int old_resolution_x;
+19 -8
View File
@@ -248,8 +248,12 @@ void HackBgrt(EFI_FILE_HANDLE root_dir) {
// Get the old BMP and position (relative to screen center), if possible. // Get the old BMP and position (relative to screen center), if possible.
const int old_valid = bgrt && VerifyAcpiSdtChecksum(bgrt); const int old_valid = bgrt && VerifyAcpiSdtChecksum(bgrt);
BMP* old_bmp = old_valid ? (BMP*) (UINTN) bgrt->image_address : 0; BMP* old_bmp = old_valid ? (BMP*) (UINTN) bgrt->image_address : 0;
const int old_x = old_bmp ? bgrt->image_offset_x + (old_bmp->width - config.old_resolution_x) / 2 : 0; const int old_orientation = old_valid ? ((bgrt->status >> 1) & 3) : 0;
const int old_y = old_bmp ? bgrt->image_offset_y + (old_bmp->height - config.old_resolution_y) / 2 : 0; const int old_swap = old_orientation & 1;
const int old_reso_x = old_swap ? config.old_resolution_y : config.old_resolution_x;
const int old_reso_y = old_swap ? config.old_resolution_x : config.old_resolution_y;
const int old_x = old_bmp ? bgrt->image_offset_x + (old_bmp->width - old_reso_x) / 2 : 0;
const int old_y = old_bmp ? bgrt->image_offset_y + (old_bmp->height - old_reso_y) / 2 : 0;
// Missing BGRT? // Missing BGRT?
if (!bgrt) { if (!bgrt) {
@@ -284,22 +288,29 @@ void HackBgrt(EFI_FILE_HANDLE root_dir) {
return; return;
} }
// Set the image address and orientation.
bgrt->image_address = (UINTN) new_bmp; bgrt->image_address = (UINTN) new_bmp;
const int new_orientation = config.orientation == HackBGRT_coord_keep ? old_orientation : ((config.orientation / 90) & 3);
bgrt->status = new_orientation << 1;
// New center coordinates. // New center coordinates.
const int new_x = config.image_x == HackBGRT_coord_keep ? old_x : config.image_x; const int new_x = config.image_x == HackBGRT_coord_keep ? old_x : config.image_x;
const int new_y = config.image_y == HackBGRT_coord_keep ? old_y : config.image_y; const int new_y = config.image_y == HackBGRT_coord_keep ? old_y : config.image_y;
const int new_swap = new_orientation & 1;
const int new_reso_x = new_swap ? config.resolution_y : config.resolution_x;
const int new_reso_y = new_swap ? config.resolution_x : config.resolution_y;
// Calculate absolute position. // Calculate absolute position.
const int max_x = config.resolution_x - new_bmp->width; const int max_x = new_reso_x - new_bmp->width;
const int max_y = config.resolution_y - new_bmp->height; const int max_y = new_reso_y - new_bmp->height;
bgrt->image_offset_x = max(0, min(max_x, new_x + (config.resolution_x - new_bmp->width) / 2)); bgrt->image_offset_x = max(0, min(max_x, new_x + (new_reso_x - new_bmp->width) / 2));
bgrt->image_offset_y = max(0, min(max_y, new_y + (config.resolution_y - new_bmp->height) / 2)); bgrt->image_offset_y = max(0, min(max_y, new_y + (new_reso_y - new_bmp->height) / 2));
Debug( Debug(
L"HackBGRT: BMP at (%d, %d), center (%d, %d), resolution (%d, %d).\n", L"HackBGRT: BMP at (%d, %d), center (%d, %d), resolution (%d, %d) with orientation %d applied.\n",
(int) bgrt->image_offset_x, (int) bgrt->image_offset_y, (int) bgrt->image_offset_x, (int) bgrt->image_offset_y,
new_x, new_y, config.resolution_x, config.resolution_y new_x, new_y, new_reso_x, new_reso_y,
new_orientation * 90
); );
// Store this BGRT in the ACPI tables. // Store this BGRT in the ACPI tables.