bootloader & kernel: Unify computation of splash logo and icons placement.

Removes some more code duplication.

Change-Id: I9423be740015bef996b77bf2c30652fdadbd8a50
This commit is contained in:
Augustin Cavalier 2024-10-15 16:10:34 -04:00
parent 029e447bde
commit de8d5cfb5f
3 changed files with 63 additions and 38 deletions

View File

@ -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 <SupportDefs.h>
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 */

View File

@ -13,7 +13,9 @@
#include <boot/kernel_args.h>
#include <boot/platform/generic/video.h>
#include <boot/platform/generic/video_blitter.h>
#include <boot/images.h>
#include <boot/platform/generic/video_splash.h>
#include <stdio.h>
#include <stdlib.h>
@ -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;

View File

@ -17,6 +17,7 @@
#define __BOOTSPLASH_KERNEL__
#include <boot/images.h>
#include <boot/platform/generic/video_blitter.h>
#include <boot/platform/generic/video_splash.h>
#include <boot_item.h>
#include <debug.h>
@ -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);
}