From de8d5cfb5fd2e2c7e78f004170fbb1d6cea614df Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Tue, 15 Oct 2024 16:10:34 -0400 Subject: [PATCH] bootloader & kernel: Unify computation of splash logo and icons placement. Removes some more code duplication. Change-Id: I9423be740015bef996b77bf2c30652fdadbd8a50 --- .../boot/platform/generic/video_splash.h | 51 +++++++++++++++++++ .../boot/platform/generic/video_splash.cpp | 35 +++---------- src/system/kernel/boot_splash.cpp | 15 ++---- 3 files changed, 63 insertions(+), 38 deletions(-) create mode 100644 headers/private/kernel/boot/platform/generic/video_splash.h diff --git a/headers/private/kernel/boot/platform/generic/video_splash.h b/headers/private/kernel/boot/platform/generic/video_splash.h new file mode 100644 index 0000000000..cb1815506c --- /dev/null +++ b/headers/private/kernel/boot/platform/generic/video_splash.h @@ -0,0 +1,51 @@ +/* + * Copyright 2024, Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef GENERIC_VIDEO_SPLASH_H +#define GENERIC_VIDEO_SPLASH_H + + +#include + + +void +compute_splash_logo_placement(uint32 screenWidth, uint32 screenHeight, + int& width, int& height, int& x, int& y) +{ + uint16 iconsHalfHeight = kSplashIconsHeight / 2; + + width = min_c(kSplashLogoWidth, screenWidth); + height = min_c(uint32(kSplashLogoHeight) + iconsHalfHeight, + screenHeight); + int placementX = max_c(0, min_c(100, kSplashLogoPlacementX)); + int placementY = max_c(0, min_c(100, kSplashLogoPlacementY)); + + x = (screenWidth - width) * placementX / 100; + y = (screenHeight - height) * placementY / 100; + + height = min_c(kSplashLogoHeight, screenHeight); +} + + +void +compute_splash_icons_placement(uint32 screenWidth, uint32 screenHeight, + int& width, int& height, int& x, int& y) +{ + uint16 iconsHalfHeight = kSplashIconsHeight / 2; + + width = min_c(kSplashIconsWidth, screenWidth); + height = min_c(uint32(kSplashLogoHeight) + iconsHalfHeight, + screenHeight); + int placementX = max_c(0, min_c(100, kSplashIconsPlacementX)); + int placementY = max_c(0, min_c(100, kSplashIconsPlacementY)); + + x = (screenWidth - width) * placementX / 100; + y = kSplashLogoHeight + (screenHeight - height) + * placementY / 100; + + height = min_c(iconsHalfHeight, screenHeight); +} + + +#endif /* GENERIC_VIDEO_SPLASH_H */ diff --git a/src/system/boot/platform/generic/video_splash.cpp b/src/system/boot/platform/generic/video_splash.cpp index 84471b8f32..d6703840de 100644 --- a/src/system/boot/platform/generic/video_splash.cpp +++ b/src/system/boot/platform/generic/video_splash.cpp @@ -13,7 +13,9 @@ #include #include #include + #include +#include #include #include @@ -159,22 +161,9 @@ video_display_splash(addr_t frameBuffer) // TODO: support 4-bit indexed version of the images! // render splash logo - uint16 iconsHalfHeight = kSplashIconsHeight / 2; - - int width = min_c(kSplashLogoWidth, gKernelArgs.frame_buffer.width); - int height = min_c(kSplashLogoHeight + iconsHalfHeight, - gKernelArgs.frame_buffer.height); - int placementX = max_c(0, min_c(100, kSplashLogoPlacementX)); - int placementY = max_c(0, min_c(100, kSplashLogoPlacementY)); - - int x = (gKernelArgs.frame_buffer.width - width) * placementX / 100; - int y = (gKernelArgs.frame_buffer.height - height) * placementY / 100; - - height = min_c(kSplashLogoHeight, gKernelArgs.frame_buffer.height); - switch (gKernelArgs.frame_buffer.depth) { - case 8: - break; - } + int width, height, x, y; + compute_splash_logo_placement(gKernelArgs.frame_buffer.width, gKernelArgs.frame_buffer.height, + width, height, x, y); video_blit_image(frameBuffer, uncompressedLogo, width, height, kSplashLogoWidth, x, y); @@ -182,6 +171,7 @@ video_display_splash(addr_t frameBuffer) const uint8* lowerHalfIconImage; uncompressedSize = kSplashIconsWidth * kSplashIconsHeight; + const uint16 iconsHalfHeight = kSplashIconsHeight / 2; switch (gKernelArgs.frame_buffer.depth) { case 8: // pointer into the lower half of the icons image data @@ -212,18 +202,9 @@ video_display_splash(addr_t frameBuffer) // render initial (grayed out) icons // the grayed out version is the lower half of the icons image + compute_splash_icons_placement(gKernelArgs.frame_buffer.width, gKernelArgs.frame_buffer.height, + width, height, x, y); - width = min_c(kSplashIconsWidth, gKernelArgs.frame_buffer.width); - height = min_c(kSplashLogoHeight + iconsHalfHeight, - gKernelArgs.frame_buffer.height); - placementX = max_c(0, min_c(100, kSplashIconsPlacementX)); - placementY = max_c(0, min_c(100, kSplashIconsPlacementY)); - - x = (gKernelArgs.frame_buffer.width - width) * placementX / 100; - y = kSplashLogoHeight + (gKernelArgs.frame_buffer.height - height) - * placementY / 100; - - height = min_c(iconsHalfHeight, gKernelArgs.frame_buffer.height); video_blit_image(frameBuffer, lowerHalfIconImage, width, height, kSplashIconsWidth, x, y); return B_OK; diff --git a/src/system/kernel/boot_splash.cpp b/src/system/kernel/boot_splash.cpp index eab9e40a66..8e1fd901e7 100644 --- a/src/system/kernel/boot_splash.cpp +++ b/src/system/kernel/boot_splash.cpp @@ -17,6 +17,7 @@ #define __BOOTSPLASH_KERNEL__ #include #include +#include #include #include @@ -70,20 +71,13 @@ boot_splash_set_stage(int stage) if (sInfo == NULL || stage < 0 || stage >= BOOT_SPLASH_STAGE_MAX) return; - int iconsHalfHeight = kSplashIconsHeight / 2; - int width = min_c(kSplashIconsWidth, sInfo->width); - int height = min_c(kSplashLogoHeight + iconsHalfHeight, sInfo->height); - int placementX = max_c(0, min_c(100, kSplashIconsPlacementX)); - int placementY = max_c(0, min_c(100, kSplashIconsPlacementY)); - - int x = (sInfo->width - width) * placementX / 100; - int y = kSplashLogoHeight + (sInfo->height - height) * placementY / 100; + int width, height, x, y; + compute_splash_icons_placement(sInfo->width, sInfo->height, + width, height, x, y); int stageLeftEdge = width * stage / BOOT_SPLASH_STAGE_MAX; int stageRightEdge = width * (stage + 1) / BOOT_SPLASH_STAGE_MAX; - height = min_c(iconsHalfHeight, sInfo->height); - BlitParameters params; params.from = sUncompressedIcons; params.fromWidth = kSplashIconsWidth; @@ -98,4 +92,3 @@ boot_splash_set_stage(int stage) blit(params, sInfo->depth); } -