2021-01-12 18:22:11 +00:00
|
|
|
/* SPDX-License-Identifier: MIT */
|
|
|
|
|
|
|
|
#include "fb.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "xnuboot.h"
|
|
|
|
|
|
|
|
u32 *fb;
|
2021-02-06 13:27:45 +00:00
|
|
|
int fb_s, fb_w, fb_h, fb_d;
|
|
|
|
int scale = 1;
|
2021-01-12 18:22:11 +00:00
|
|
|
|
|
|
|
static u32 *logo;
|
|
|
|
static int logo_w, logo_h;
|
|
|
|
|
|
|
|
extern char _binary_build_bootlogo_128_bin_start[0];
|
|
|
|
extern char _binary_build_bootlogo_256_bin_start[0];
|
|
|
|
|
2021-02-12 21:27:39 +00:00
|
|
|
extern u8 _binary_build_font_bin_start[];
|
|
|
|
extern u8 _binary_build_font_retina_bin_start[];
|
|
|
|
|
2021-01-12 18:22:11 +00:00
|
|
|
void fb_init(void)
|
|
|
|
{
|
|
|
|
fb = (void *)cur_boot_args.video.base;
|
|
|
|
fb_s = cur_boot_args.video.stride / 4;
|
|
|
|
fb_w = cur_boot_args.video.width;
|
|
|
|
fb_h = cur_boot_args.video.height;
|
2021-02-06 13:27:45 +00:00
|
|
|
fb_d = cur_boot_args.video.depth & 0xff;
|
|
|
|
printf("fb init: %dx%d (%d) [s=%d] @%p\n", fb_w, fb_h, fb_d, fb_s, fb);
|
2021-01-12 18:22:11 +00:00
|
|
|
|
2021-02-06 13:27:45 +00:00
|
|
|
if (cur_boot_args.video.depth & 0x10000) {
|
2021-01-12 18:22:11 +00:00
|
|
|
logo = (void *)_binary_build_bootlogo_256_bin_start;
|
|
|
|
logo_w = logo_h = 256;
|
|
|
|
} else {
|
|
|
|
logo = (void *)_binary_build_bootlogo_128_bin_start;
|
|
|
|
logo_w = logo_h = 128;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint32_t rgbx_to_rgb30(u32 c)
|
|
|
|
{
|
|
|
|
u8 r = c;
|
|
|
|
u8 g = c >> 8;
|
|
|
|
u8 b = c >> 16;
|
|
|
|
return (b << 2) | (g << 12) | (r << 22);
|
|
|
|
}
|
|
|
|
|
|
|
|
void fb_blit(int x, int y, int w, int h, void *data, int stride)
|
|
|
|
{
|
|
|
|
uint32_t *p = data;
|
|
|
|
|
|
|
|
for (int i = 0; i < h; i++)
|
|
|
|
for (int j = 0; j < w; j++)
|
|
|
|
fb[x + j + (y + i) * fb_s] = rgbx_to_rgb30(p[j + i * stride]);
|
|
|
|
}
|
|
|
|
|
|
|
|
void fb_fill(int x, int y, int w, int h, u32 color)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < h; i++)
|
|
|
|
for (int j = 0; j < w; j++)
|
|
|
|
fb[x + j + (y + i) * fb_s] = rgbx_to_rgb30(color);
|
|
|
|
}
|
|
|
|
|
|
|
|
void fb_display_logo(void)
|
|
|
|
{
|
|
|
|
printf("fb: display logo\n");
|
2021-01-28 06:27:35 +00:00
|
|
|
fb_blit((fb_w - logo_w) / 2, (fb_h - logo_h) / 2, logo_w, logo_h, logo, logo_w);
|
2021-01-12 18:22:11 +00:00
|
|
|
}
|