> compile NEMU
221220000 张三 Linux zzy 5.15.146.1-microsoft-standard-WSL2 #1 SMP Thu Jan 11 04:09:03 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux 13:07:18 up 7 days, 13:07, 1 user, load average: 0.28, 0.15, 0.06
This commit is contained in:
@ -26,6 +26,31 @@ int NDL_PollEvent(char *buf, int len) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void _get_screen(int *w, int *h) {
|
||||
static int dev_w = -1, dev_h = -1, num = -1;
|
||||
|
||||
FILE* fp = fopen("/proc/dispinfo", "r");
|
||||
if (fp == NULL) {
|
||||
printf("cannot open /proc/dispinfo");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
char buf[64], name[32];
|
||||
const char* pos = buf;
|
||||
fread(buf, 1, sizeof(buf), fp);
|
||||
int life = 2;
|
||||
// FIXME this have a bug to phase the ` [KEY] : [VALUE] `
|
||||
while (sscanf(pos, "%s : %d\n", name, &num) == 2 && life--) {
|
||||
pos = strchr(pos, '\n');
|
||||
if (pos == NULL) break;
|
||||
if (strcmp(name, "WIDTH") == 0) { dev_w = num; }
|
||||
if (strcmp(name, "HEIGHT") == 0) { dev_h = num; }
|
||||
}
|
||||
*w = dev_w;
|
||||
*h = dev_h;
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
void NDL_OpenCanvas(int *w, int *h) {
|
||||
// if (getenv("NWM_APP")) {
|
||||
// int fbctl = 4;
|
||||
@ -45,27 +70,8 @@ void NDL_OpenCanvas(int *w, int *h) {
|
||||
// close(fbctl);
|
||||
// }
|
||||
|
||||
FILE* fp = fopen("/proc/dispinfo", "r");
|
||||
if (fp == NULL) {
|
||||
printf("cannot open /proc/dispinfo");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
int dev_w, dev_h, num;
|
||||
char buf[64], name[32];
|
||||
const char* pos = buf;
|
||||
fread(buf, 1, sizeof(buf), fp);
|
||||
int life = 2;
|
||||
while (sscanf(pos, "%s : %d\n", name, &num) == 2 && life--) {
|
||||
printf("log:%s,%d\n", name, num);
|
||||
pos = strchr(pos, '\n');
|
||||
if (pos == NULL) break;
|
||||
if (strcmp(name, "WIDTH") == 0) { dev_w = num; }
|
||||
if (strcmp(name, "HEIGHT") == 0) { dev_h = num; }
|
||||
}
|
||||
fclose(fp);
|
||||
|
||||
printf("w %d, h %d\n", dev_w, dev_h);
|
||||
int dev_w, dev_h;
|
||||
_get_screen(&dev_w, &dev_h);
|
||||
screen_w = (*w == 0 || *w > dev_w) ? dev_w : *w;
|
||||
screen_h = (*h == 0 || *h > dev_h) ? dev_h : *h;
|
||||
}
|
||||
@ -76,6 +82,11 @@ void NDL_DrawRect(uint32_t *pixels, int x, int y, int w, int h) {
|
||||
printf("cannot open /dev/fb");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
int dev_w, dev_h;
|
||||
_get_screen(&dev_w, &dev_h);
|
||||
x += (dev_w - x) / 2;
|
||||
y += (dev_h - y) / 2;
|
||||
for (int i = 0; i < h; i ++) {
|
||||
fwrite(pixels + (screen_w * (y + i)) + x, sizeof(uint32_t), w, fp);
|
||||
}
|
||||
|
Reference in New Issue
Block a user