|
|
f96e0b |
From 4b187937acb52b5ee5da7c687ded09e7b2c1825a Mon Sep 17 00:00:00 2001
|
|
|
f96e0b |
From: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
|
|
|
f96e0b |
Date: Thu, 2 May 2013 14:39:03 +0200
|
|
|
f96e0b |
Subject: [PATCH 401/482] First automated video test (running videotest
|
|
|
f96e0b |
and comparing results)
|
|
|
f96e0b |
|
|
|
f96e0b |
---
|
|
|
f96e0b |
ChangeLog | 4 +
|
|
|
f96e0b |
Makefile.util.def | 7 +
|
|
|
f96e0b |
grub-core/Makefile.core.def | 8 +
|
|
|
f96e0b |
grub-core/tests/checksums.c | 27 +++
|
|
|
f96e0b |
grub-core/tests/fake_input.c | 67 ++++++
|
|
|
f96e0b |
grub-core/tests/lib/functional_test.c | 29 ++-
|
|
|
f96e0b |
grub-core/tests/video_checksum.c | 435 ++++++++++++++++++++++++++++++++++
|
|
|
f96e0b |
grub-core/tests/videotest_checksum.c | 286 ++++++++++++++++++++++
|
|
|
f96e0b |
grub-core/video/capture.c | 128 ++++++++++
|
|
|
f96e0b |
grub-core/video/video.c | 13 +-
|
|
|
f96e0b |
include/grub/emu/export.h | 3 +-
|
|
|
f96e0b |
include/grub/test.h | 9 +
|
|
|
f96e0b |
include/grub/video.h | 120 +++++++++-
|
|
|
f96e0b |
tests/grub_func_test.in | 12 +
|
|
|
f96e0b |
tests/util/grub-shell.in | 2 +
|
|
|
f96e0b |
util/grub-render-label.c | 97 ++------
|
|
|
f96e0b |
16 files changed, 1150 insertions(+), 97 deletions(-)
|
|
|
f96e0b |
create mode 100644 grub-core/tests/checksums.c
|
|
|
f96e0b |
create mode 100644 grub-core/tests/fake_input.c
|
|
|
f96e0b |
create mode 100644 grub-core/tests/video_checksum.c
|
|
|
f96e0b |
create mode 100644 grub-core/tests/videotest_checksum.c
|
|
|
f96e0b |
create mode 100644 grub-core/video/capture.c
|
|
|
f96e0b |
create mode 100644 tests/grub_func_test.in
|
|
|
f96e0b |
|
|
|
f96e0b |
diff --git a/ChangeLog b/ChangeLog
|
|
|
f96e0b |
index b202abe..37595a9 100644
|
|
|
f96e0b |
--- a/ChangeLog
|
|
|
f96e0b |
+++ b/ChangeLog
|
|
|
f96e0b |
@@ -1,5 +1,9 @@
|
|
|
f96e0b |
2013-05-02 Vladimir Serbinenko <phcoder@gmail.com>
|
|
|
f96e0b |
|
|
|
f96e0b |
+ First automated video test (running videotest and comparing results)
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+2013-05-02 Vladimir Serbinenko <phcoder@gmail.com>
|
|
|
f96e0b |
+
|
|
|
f96e0b |
* grub-core/commands/videotest.c: Reduce flickering and draw 6 squares
|
|
|
f96e0b |
instead of 2 to have full RGB/CMY test pattern.
|
|
|
f96e0b |
|
|
|
f96e0b |
diff --git a/Makefile.util.def b/Makefile.util.def
|
|
|
f96e0b |
index fbd37eb..a357341 100644
|
|
|
f96e0b |
--- a/Makefile.util.def
|
|
|
f96e0b |
+++ b/Makefile.util.def
|
|
|
f96e0b |
@@ -67,6 +67,7 @@ library = {
|
|
|
f96e0b |
common = grub-core/video/fb/fbfill.c;
|
|
|
f96e0b |
common = grub-core/video/fb/video_fb.c;
|
|
|
f96e0b |
common = grub-core/video/video.c;
|
|
|
f96e0b |
+ common = grub-core/video/capture.c;
|
|
|
f96e0b |
common = grub-core/video/colors.c;
|
|
|
f96e0b |
common = grub-core/unidata.c;
|
|
|
f96e0b |
common = grub-core/io/bufio.c;
|
|
|
f96e0b |
@@ -814,6 +815,12 @@ script = {
|
|
|
f96e0b |
common = tests/grub_script_strcmp.in;
|
|
|
f96e0b |
};
|
|
|
f96e0b |
|
|
|
f96e0b |
+script = {
|
|
|
f96e0b |
+ testcase;
|
|
|
f96e0b |
+ name = grub_func_test;
|
|
|
f96e0b |
+ common = tests/grub_func_test.in;
|
|
|
f96e0b |
+};
|
|
|
f96e0b |
+
|
|
|
f96e0b |
program = {
|
|
|
f96e0b |
testcase;
|
|
|
f96e0b |
name = example_unit_test;
|
|
|
f96e0b |
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
|
|
|
f96e0b |
index 7e19acb..2fa0ea7 100644
|
|
|
f96e0b |
--- a/grub-core/Makefile.core.def
|
|
|
f96e0b |
+++ b/grub-core/Makefile.core.def
|
|
|
f96e0b |
@@ -1731,6 +1731,9 @@ module = {
|
|
|
f96e0b |
name = functional_test;
|
|
|
f96e0b |
common = tests/lib/functional_test.c;
|
|
|
f96e0b |
common = tests/lib/test.c;
|
|
|
f96e0b |
+ common = tests/video_checksum.c;
|
|
|
f96e0b |
+ common = tests/fake_input.c;
|
|
|
f96e0b |
+ common = video/capture.c;
|
|
|
f96e0b |
};
|
|
|
f96e0b |
|
|
|
f96e0b |
module = {
|
|
|
f96e0b |
@@ -1739,6 +1742,11 @@ module = {
|
|
|
f96e0b |
};
|
|
|
f96e0b |
|
|
|
f96e0b |
module = {
|
|
|
f96e0b |
+ name = videotest_checksum;
|
|
|
f96e0b |
+ common = tests/videotest_checksum.c;
|
|
|
f96e0b |
+};
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+module = {
|
|
|
f96e0b |
name = bitmap;
|
|
|
f96e0b |
common = video/bitmap.c;
|
|
|
f96e0b |
enable = videomodules;
|
|
|
f96e0b |
diff --git a/grub-core/tests/checksums.c b/grub-core/tests/checksums.c
|
|
|
f96e0b |
new file mode 100644
|
|
|
f96e0b |
index 0000000..93d100f
|
|
|
f96e0b |
--- /dev/null
|
|
|
f96e0b |
+++ b/grub-core/tests/checksums.c
|
|
|
f96e0b |
@@ -0,0 +1,27 @@
|
|
|
f96e0b |
+ { "videotest", 640, 480, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 640x480xi16 */, (grub_uint32_t []) { 0x7f1853ba, 0x7f1853ba, 0x7f1853ba, 0x7f1853ba, 0x7f1853ba, }, 5 },
|
|
|
f96e0b |
+ { "videotest", 800, 600, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 800x600xi16 */, (grub_uint32_t []) { 0xff1957f0, 0xff1957f0, 0xff1957f0, 0xff1957f0, 0xff1957f0, }, 5 },
|
|
|
f96e0b |
+ { "videotest", 1024, 768, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 1024x768xi16 */, (grub_uint32_t []) { 0xcb45d8c5, 0xcb45d8c5, 0xcb45d8c5, 0xcb45d8c5, 0xcb45d8c5, }, 5 },
|
|
|
f96e0b |
+ { "videotest", 640, 480, 0x1, 256, 15, 2, 10, 5, 5, 5, 0, 5, 0, 0 /* 640x480xrgb555 */, (grub_uint32_t []) { 0x2c97569c, 0x2c97569c, 0x2c97569c, 0x2c97569c, 0x2c97569c, }, 5 },
|
|
|
f96e0b |
+ { "videotest", 800, 600, 0x1, 256, 15, 2, 10, 5, 5, 5, 0, 5, 0, 0 /* 800x600xrgb555 */, (grub_uint32_t []) { 0x9bd7a3ac, 0x9bd7a3ac, 0x9bd7a3ac, 0x9bd7a3ac, 0x9bd7a3ac, }, 5 },
|
|
|
f96e0b |
+ { "videotest", 1024, 768, 0x1, 256, 15, 2, 10, 5, 5, 5, 0, 5, 0, 0 /* 1024x768xrgb555 */, (grub_uint32_t []) { 0xedbceb9c, 0xedbceb9c, 0xedbceb9c, 0xedbceb9c, 0xedbceb9c, }, 5 },
|
|
|
f96e0b |
+ { "videotest", 640, 480, 0x1, 256, 16, 2, 11, 5, 5, 6, 0, 5, 0, 0 /* 640x480xrgb565 */, (grub_uint32_t []) { 0x3c2a42f1, 0x3c2a42f1, 0x3c2a42f1, 0x3c2a42f1, 0x3c2a42f1, }, 5 },
|
|
|
f96e0b |
+ { "videotest", 800, 600, 0x1, 256, 16, 2, 11, 5, 5, 6, 0, 5, 0, 0 /* 800x600xrgb565 */, (grub_uint32_t []) { 0xb25ce62a, 0xb25ce62a, 0xb25ce62a, 0xb25ce62a, 0xb25ce62a, }, 5 },
|
|
|
f96e0b |
+ { "videotest", 1024, 768, 0x1, 256, 16, 2, 11, 5, 5, 6, 0, 5, 0, 0 /* 1024x768xrgb565 */, (grub_uint32_t []) { 0x66cee14c, 0x66cee14c, 0x66cee14c, 0x66cee14c, 0x66cee14c, }, 5 },
|
|
|
f96e0b |
+ { "videotest", 640, 480, 0x1, 256, 24, 3, 16, 8, 8, 8, 0, 8, 0, 0 /* 640x480xrgb888 */, (grub_uint32_t []) { 0x61db45b7, 0x1d867efe, 0x99613325, 0xe53c086c, 0x9543de62, }, 5 },
|
|
|
f96e0b |
+ { "videotest", 800, 600, 0x1, 256, 24, 3, 16, 8, 8, 8, 0, 8, 0, 0 /* 800x600xrgb888 */, (grub_uint32_t []) { 0xa46eb37f, 0xd2a59656, 0x49f8f92d, 0x3f33dc04, 0x7aae512a, }, 5 },
|
|
|
f96e0b |
+ { "videotest", 1024, 768, 0x1, 256, 24, 3, 16, 8, 8, 8, 0, 8, 0, 0 /* 1024x768xrgb888 */, (grub_uint32_t []) { 0xb864a496, 0x6c22313b, 0x1505f93d, 0xc1436c90, 0xe74a6931, }, 5 },
|
|
|
f96e0b |
+ { "videotest", 640, 480, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 640x480xrgb888 */, (grub_uint32_t []) { 0x2b154617, 0x692e98df, 0xaf62fb87, 0xed59254f, 0x26164bc6, }, 5 },
|
|
|
f96e0b |
+ { "videotest", 800, 600, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 800x600xrgb888 */, (grub_uint32_t []) { 0x3b0fbc56, 0xd9d57c0e, 0xfb564a17, 0x198c8a4f, 0xbe502625, }, 5 },
|
|
|
f96e0b |
+ { "videotest", 1024, 768, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 1024x768xrgb888 */, (grub_uint32_t []) { 0x6e6c9b36, 0x4ae9f137, 0x27664f34, 0x3e32535, 0xfc793332, }, 5 },
|
|
|
f96e0b |
+ { "videotest", 640, 480, 0x1, 256, 15, 2, 0, 5, 5, 5, 10, 5, 0, 0 /* 640x480xbgr555 */, (grub_uint32_t []) { 0x9056f776, 0x9056f776, 0x9056f776, 0x9056f776, 0x9056f776, }, 5 },
|
|
|
f96e0b |
+ { "videotest", 800, 600, 0x1, 256, 15, 2, 0, 5, 5, 5, 10, 5, 0, 0 /* 800x600xbgr555 */, (grub_uint32_t []) { 0x2bde3c67, 0x2bde3c67, 0x2bde3c67, 0x2bde3c67, 0x2bde3c67, }, 5 },
|
|
|
f96e0b |
+ { "videotest", 1024, 768, 0x1, 256, 15, 2, 0, 5, 5, 5, 10, 5, 0, 0 /* 1024x768xbgr555 */, (grub_uint32_t []) { 0xb04615f3, 0xb04615f3, 0xb04615f3, 0xb04615f3, 0xb04615f3, }, 5 },
|
|
|
f96e0b |
+ { "videotest", 640, 480, 0x1, 256, 16, 2, 0, 5, 5, 6, 11, 5, 0, 0 /* 640x480xbgr565 */, (grub_uint32_t []) { 0xba8df8dd, 0xba8df8dd, 0xba8df8dd, 0xba8df8dd, 0xba8df8dd, }, 5 },
|
|
|
f96e0b |
+ { "videotest", 800, 600, 0x1, 256, 16, 2, 0, 5, 5, 6, 11, 5, 0, 0 /* 800x600xbgr565 */, (grub_uint32_t []) { 0x84ac1329, 0x84ac1329, 0x84ac1329, 0x84ac1329, 0x84ac1329, }, 5 },
|
|
|
f96e0b |
+ { "videotest", 1024, 768, 0x1, 256, 16, 2, 0, 5, 5, 6, 11, 5, 0, 0 /* 1024x768xbgr565 */, (grub_uint32_t []) { 0x145ad698, 0x145ad698, 0x145ad698, 0x145ad698, 0x145ad698, }, 5 },
|
|
|
f96e0b |
+ { "videotest", 640, 480, 0x1, 256, 24, 3, 0, 8, 8, 8, 16, 8, 0, 0 /* 640x480xbgr888 */, (grub_uint32_t []) { 0x4af6b480, 0x923db79c, 0xfe8cc449, 0x2647c755, 0x27ee23e3, }, 5 },
|
|
|
f96e0b |
+ { "videotest", 800, 600, 0x1, 256, 24, 3, 0, 8, 8, 8, 16, 8, 0, 0 /* 800x600xbgr888 */, (grub_uint32_t []) { 0x121d5e29, 0xf66c0aed, 0xdf138150, 0x3b62d594, 0x8dec962a, }, 5 },
|
|
|
f96e0b |
+ { "videotest", 1024, 768, 0x1, 256, 24, 3, 0, 8, 8, 8, 16, 8, 0, 0 /* 1024x768xbgr888 */, (grub_uint32_t []) { 0xae86a12c, 0x4dabbe89, 0x6d30e897, 0x8e1df732, 0x2c0644ab, }, 5 },
|
|
|
f96e0b |
+ { "videotest", 640, 480, 0x1, 256, 32, 4, 0, 8, 8, 8, 16, 8, 24, 8 /* 640x480xbgr888 */, (grub_uint32_t []) { 0x2605d280, 0xc06e3172, 0xef3e6395, 0x9558067, 0xb19ec65b, }, 5 },
|
|
|
f96e0b |
+ { "videotest", 800, 600, 0x1, 256, 32, 4, 0, 8, 8, 8, 16, 8, 24, 8 /* 800x600xbgr888 */, (grub_uint32_t []) { 0x9404ef3b, 0xa4fdf18, 0xad7ef98c, 0x3335c9af, 0xe6f0c255, }, 5 },
|
|
|
f96e0b |
+ { "videotest", 1024, 768, 0x1, 256, 32, 4, 0, 8, 8, 8, 16, 8, 24, 8 /* 1024x768xbgr888 */, (grub_uint32_t []) { 0xa008b770, 0xb98eb0d8, 0x9304b820, 0x8a82bf88, 0xc610a9d0, }, 5 },
|
|
|
f96e0b |
diff --git a/grub-core/tests/fake_input.c b/grub-core/tests/fake_input.c
|
|
|
f96e0b |
new file mode 100644
|
|
|
f96e0b |
index 0000000..b514c2a
|
|
|
f96e0b |
--- /dev/null
|
|
|
f96e0b |
+++ b/grub-core/tests/fake_input.c
|
|
|
f96e0b |
@@ -0,0 +1,67 @@
|
|
|
f96e0b |
+/*
|
|
|
f96e0b |
+ * GRUB -- GRand Unified Bootloader
|
|
|
f96e0b |
+ * Copyright (C) 2013 Free Software Foundation, Inc.
|
|
|
f96e0b |
+ *
|
|
|
f96e0b |
+ * GRUB is free software: you can redistribute it and/or modify
|
|
|
f96e0b |
+ * it under the terms of the GNU General Public License as published by
|
|
|
f96e0b |
+ * the Free Software Foundation, either version 3 of the License, or
|
|
|
f96e0b |
+ * (at your option) any later version.
|
|
|
f96e0b |
+ *
|
|
|
f96e0b |
+ * GRUB is distributed in the hope that it will be useful,
|
|
|
f96e0b |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
f96e0b |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
f96e0b |
+ * GNU General Public License for more details.
|
|
|
f96e0b |
+ *
|
|
|
f96e0b |
+ * You should have received a copy of the GNU General Public License
|
|
|
f96e0b |
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
|
|
f96e0b |
+ */
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+#include <grub/term.h>
|
|
|
f96e0b |
+#include <grub/mm.h>
|
|
|
f96e0b |
+#include <grub/dl.h>
|
|
|
f96e0b |
+#include <grub/test.h>
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+GRUB_MOD_LICENSE ("GPLv3+");
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+static int *seq;
|
|
|
f96e0b |
+static int seqptr, nseq;
|
|
|
f96e0b |
+static struct grub_term_input *saved;
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+static int
|
|
|
f96e0b |
+fake_getkey (struct grub_term_input *term __attribute__ ((unused)))
|
|
|
f96e0b |
+{
|
|
|
f96e0b |
+ if (seq && seqptr < nseq)
|
|
|
f96e0b |
+ return seq[seqptr++];
|
|
|
f96e0b |
+ return -1;
|
|
|
f96e0b |
+}
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+static struct grub_term_input fake_input_term =
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ .name = "fake",
|
|
|
f96e0b |
+ .getkey = fake_getkey
|
|
|
f96e0b |
+ };
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+void
|
|
|
f96e0b |
+grub_terminal_input_fake_sequence (int *seq_in, int nseq_in)
|
|
|
f96e0b |
+{
|
|
|
f96e0b |
+ if (!saved)
|
|
|
f96e0b |
+ saved = grub_term_inputs;
|
|
|
f96e0b |
+ if (seq)
|
|
|
f96e0b |
+ grub_free (seq);
|
|
|
f96e0b |
+ seq = grub_malloc (nseq_in * sizeof (seq[0]));
|
|
|
f96e0b |
+ if (seq)
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ grub_term_inputs = &fake_input_term;
|
|
|
f96e0b |
+ grub_memcpy (seq, seq_in, nseq_in * sizeof (seq[0]));
|
|
|
f96e0b |
+ }
|
|
|
f96e0b |
+ nseq = nseq_in;
|
|
|
f96e0b |
+}
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+void
|
|
|
f96e0b |
+grub_terminal_input_fake_sequence_end (void)
|
|
|
f96e0b |
+{
|
|
|
f96e0b |
+ grub_term_inputs = saved;
|
|
|
f96e0b |
+ grub_free (seq);
|
|
|
f96e0b |
+ seq = 0;
|
|
|
f96e0b |
+ nseq = 0;
|
|
|
f96e0b |
+}
|
|
|
f96e0b |
diff --git a/grub-core/tests/lib/functional_test.c b/grub-core/tests/lib/functional_test.c
|
|
|
f96e0b |
index fd199bd..da4d5f8 100644
|
|
|
f96e0b |
--- a/grub-core/tests/lib/functional_test.c
|
|
|
f96e0b |
+++ b/grub-core/tests/lib/functional_test.c
|
|
|
f96e0b |
@@ -30,9 +30,34 @@ grub_functional_test (grub_extcmd_context_t ctxt __attribute__ ((unused)),
|
|
|
f96e0b |
char **args __attribute__ ((unused)))
|
|
|
f96e0b |
{
|
|
|
f96e0b |
grub_test_t test;
|
|
|
f96e0b |
+ int ok = 1;
|
|
|
f96e0b |
|
|
|
f96e0b |
FOR_LIST_ELEMENTS (test, grub_test_list)
|
|
|
f96e0b |
- grub_test_run (test);
|
|
|
f96e0b |
+ ok = ok && !grub_test_run (test);
|
|
|
f96e0b |
+ if (ok)
|
|
|
f96e0b |
+ grub_printf ("ALL TESTS PASSED\n");
|
|
|
f96e0b |
+ else
|
|
|
f96e0b |
+ grub_printf ("TEST FAILURE\n");
|
|
|
f96e0b |
+ return GRUB_ERR_NONE;
|
|
|
f96e0b |
+}
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+static grub_err_t
|
|
|
f96e0b |
+grub_functional_all_tests (grub_extcmd_context_t ctxt __attribute__ ((unused)),
|
|
|
f96e0b |
+ int argc __attribute__ ((unused)),
|
|
|
f96e0b |
+ char **args __attribute__ ((unused)))
|
|
|
f96e0b |
+{
|
|
|
f96e0b |
+ grub_test_t test;
|
|
|
f96e0b |
+ int ok = 1;
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ grub_dl_load ("exfctest");
|
|
|
f96e0b |
+ grub_dl_load ("videotest_checksum");
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ FOR_LIST_ELEMENTS (test, grub_test_list)
|
|
|
f96e0b |
+ ok = ok && !grub_test_run (test);
|
|
|
f96e0b |
+ if (ok)
|
|
|
f96e0b |
+ grub_printf ("ALL TESTS PASSED\n");
|
|
|
f96e0b |
+ else
|
|
|
f96e0b |
+ grub_printf ("TEST FAILURE\n");
|
|
|
f96e0b |
return GRUB_ERR_NONE;
|
|
|
f96e0b |
}
|
|
|
f96e0b |
|
|
|
f96e0b |
@@ -41,6 +66,8 @@ static grub_extcmd_t cmd;
|
|
|
f96e0b |
GRUB_MOD_INIT (functional_test)
|
|
|
f96e0b |
{
|
|
|
f96e0b |
cmd = grub_register_extcmd ("functional_test", grub_functional_test, 0, 0,
|
|
|
f96e0b |
+ "Run all loaded functional tests.", 0);
|
|
|
f96e0b |
+ cmd = grub_register_extcmd ("all_functional_test", grub_functional_all_tests, 0, 0,
|
|
|
f96e0b |
"Run all functional tests.", 0);
|
|
|
f96e0b |
}
|
|
|
f96e0b |
|
|
|
f96e0b |
diff --git a/grub-core/tests/video_checksum.c b/grub-core/tests/video_checksum.c
|
|
|
f96e0b |
new file mode 100644
|
|
|
f96e0b |
index 0000000..b2aab79
|
|
|
f96e0b |
--- /dev/null
|
|
|
f96e0b |
+++ b/grub-core/tests/video_checksum.c
|
|
|
f96e0b |
@@ -0,0 +1,435 @@
|
|
|
f96e0b |
+/*
|
|
|
f96e0b |
+ * GRUB -- GRand Unified Bootloader
|
|
|
f96e0b |
+ * Copyright (C) 2013 Free Software Foundation, Inc.
|
|
|
f96e0b |
+ *
|
|
|
f96e0b |
+ * GRUB is free software: you can redistribute it and/or modify
|
|
|
f96e0b |
+ * it under the terms of the GNU General Public License as published by
|
|
|
f96e0b |
+ * the Free Software Foundation, either version 3 of the License, or
|
|
|
f96e0b |
+ * (at your option) any later version.
|
|
|
f96e0b |
+ *
|
|
|
f96e0b |
+ * GRUB is distributed in the hope that it will be useful,
|
|
|
f96e0b |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
f96e0b |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
f96e0b |
+ * GNU General Public License for more details.
|
|
|
f96e0b |
+ *
|
|
|
f96e0b |
+ * You should have received a copy of the GNU General Public License
|
|
|
f96e0b |
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
|
|
f96e0b |
+ */
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+/* All tests need to include test.h for GRUB testing framework. */
|
|
|
f96e0b |
+#include <grub/test.h>
|
|
|
f96e0b |
+#include <grub/dl.h>
|
|
|
f96e0b |
+#include <grub/video.h>
|
|
|
f96e0b |
+#include <grub/lib/crc.h>
|
|
|
f96e0b |
+#include <grub/mm.h>
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+GRUB_MOD_LICENSE ("GPLv3+");
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+static int ctr;
|
|
|
f96e0b |
+static int nchk;
|
|
|
f96e0b |
+static char *basename;
|
|
|
f96e0b |
+static const grub_uint32_t *checksums;
|
|
|
f96e0b |
+static struct grub_video_mode_info capt_mode_info;
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+#ifdef GRUB_MACHINE_EMU
|
|
|
f96e0b |
+#include <grub/emu/misc.h>
|
|
|
f96e0b |
+#include <sys/types.h>
|
|
|
f96e0b |
+#include <sys/stat.h>
|
|
|
f96e0b |
+#include <fcntl.h>
|
|
|
f96e0b |
+#include <unistd.h>
|
|
|
f96e0b |
+#include <errno.h>
|
|
|
f96e0b |
+#include <string.h>
|
|
|
f96e0b |
+#include <stdlib.h>
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+struct bmp_header
|
|
|
f96e0b |
+{
|
|
|
f96e0b |
+ grub_uint8_t magic[2];
|
|
|
f96e0b |
+ grub_uint32_t filesize;
|
|
|
f96e0b |
+ grub_uint32_t reserved;
|
|
|
f96e0b |
+ grub_uint32_t bmp_off;
|
|
|
f96e0b |
+ grub_uint32_t head_size;
|
|
|
f96e0b |
+ grub_uint16_t width;
|
|
|
f96e0b |
+ grub_uint16_t height;
|
|
|
f96e0b |
+ grub_uint16_t planes;
|
|
|
f96e0b |
+ grub_uint16_t bpp;
|
|
|
f96e0b |
+} __attribute__ ((packed));
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+static void
|
|
|
f96e0b |
+grub_video_capture_write_bmp (const char *fname,
|
|
|
f96e0b |
+ void *ptr,
|
|
|
f96e0b |
+ const struct grub_video_mode_info *mode_info)
|
|
|
f96e0b |
+{
|
|
|
f96e0b |
+ int fd = open (fname, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
|
|
|
f96e0b |
+ struct bmp_header head;
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ if (fd < 0)
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ grub_printf (_("cannot open `%s': %s"),
|
|
|
f96e0b |
+ fname, strerror (errno));
|
|
|
f96e0b |
+ }
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ grub_memset (&head, 0, sizeof (head));
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ head.magic[0] = 'B';
|
|
|
f96e0b |
+ head.magic[1] = 'M';
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ if (mode_info->mode_type & GRUB_VIDEO_MODE_TYPE_RGB)
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ head.filesize = grub_cpu_to_le32 (sizeof (head) + mode_info->width * mode_info->height * 3);
|
|
|
f96e0b |
+ head.bmp_off = grub_cpu_to_le32 (sizeof (head));
|
|
|
f96e0b |
+ head.bpp = grub_cpu_to_le16_compile_time (24);
|
|
|
f96e0b |
+ }
|
|
|
f96e0b |
+ else
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ head.filesize = grub_cpu_to_le32 (sizeof (head) + 3 * 256 + mode_info->width * mode_info->height);
|
|
|
f96e0b |
+ head.bmp_off = grub_cpu_to_le32 (sizeof (head) + 3 * 256);
|
|
|
f96e0b |
+ head.bpp = grub_cpu_to_le16_compile_time (8);
|
|
|
f96e0b |
+ }
|
|
|
f96e0b |
+ head.head_size = grub_cpu_to_le32 (sizeof (head) - 14);
|
|
|
f96e0b |
+ head.width = grub_cpu_to_le16 (mode_info->width);
|
|
|
f96e0b |
+ head.height = grub_cpu_to_le16 (mode_info->height);
|
|
|
f96e0b |
+ head.planes = grub_cpu_to_le16_compile_time (1);
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ head.width = grub_cpu_to_le16 (mode_info->width);
|
|
|
f96e0b |
+ head.height = grub_cpu_to_le16 (mode_info->height);
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ write (fd, &head, sizeof (head));
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ if (!(mode_info->mode_type & GRUB_VIDEO_MODE_TYPE_RGB))
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ struct grub_video_palette_data palette_data[256];
|
|
|
f96e0b |
+ int i;
|
|
|
f96e0b |
+ int palette_len = mode_info->number_of_colors;
|
|
|
f96e0b |
+ grub_memset (palette_data, 0, sizeof (palette_data));
|
|
|
f96e0b |
+ if (palette_len > 256)
|
|
|
f96e0b |
+ palette_len = 256;
|
|
|
f96e0b |
+ grub_video_get_palette (0, palette_len, palette_data);
|
|
|
f96e0b |
+ for (i = 0; i < 256; i++)
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ grub_uint8_t r, g, b;
|
|
|
f96e0b |
+ r = palette_data[i].r;
|
|
|
f96e0b |
+ g = palette_data[i].g;
|
|
|
f96e0b |
+ b = palette_data[i].b;
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ write (fd, &b, 1);
|
|
|
f96e0b |
+ write (fd, &g, 1);
|
|
|
f96e0b |
+ write (fd, &r, 1);
|
|
|
f96e0b |
+ }
|
|
|
f96e0b |
+ }
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ /* This does essentialy the same as some fbblit functions yet using
|
|
|
f96e0b |
+ them would mean testing them against themselves so keep this
|
|
|
f96e0b |
+ implemetation separate. */
|
|
|
f96e0b |
+ switch (mode_info->bytes_per_pixel)
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ case 4:
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ grub_uint8_t *buffer = xmalloc (mode_info->width * 3);
|
|
|
f96e0b |
+ grub_uint32_t rmask = ((1 << mode_info->red_mask_size) - 1);
|
|
|
f96e0b |
+ grub_uint32_t gmask = ((1 << mode_info->green_mask_size) - 1);
|
|
|
f96e0b |
+ grub_uint32_t bmask = ((1 << mode_info->blue_mask_size) - 1);
|
|
|
f96e0b |
+ int rshift = mode_info->red_field_pos;
|
|
|
f96e0b |
+ int gshift = mode_info->green_field_pos;
|
|
|
f96e0b |
+ int bshift = mode_info->blue_field_pos;
|
|
|
f96e0b |
+ int mulrshift = (8 - mode_info->red_mask_size);
|
|
|
f96e0b |
+ int mulgshift = (8 - mode_info->green_mask_size);
|
|
|
f96e0b |
+ int mulbshift = (8 - mode_info->blue_mask_size);
|
|
|
f96e0b |
+ int y;
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ for (y = mode_info->height - 1; y >= 0; y--)
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ grub_uint32_t *iptr = (grub_uint32_t *) ((grub_uint8_t *) ptr + mode_info->pitch * y);
|
|
|
f96e0b |
+ int x;
|
|
|
f96e0b |
+ grub_uint8_t *optr = buffer;
|
|
|
f96e0b |
+ for (x = 0; x < (int) mode_info->width; x++)
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ grub_uint32_t val = *iptr++;
|
|
|
f96e0b |
+ *optr++ = ((val >> bshift) & bmask) << mulbshift;
|
|
|
f96e0b |
+ *optr++ = ((val >> gshift) & gmask) << mulgshift;
|
|
|
f96e0b |
+ *optr++ = ((val >> rshift) & rmask) << mulrshift;
|
|
|
f96e0b |
+ }
|
|
|
f96e0b |
+ write (fd, buffer, mode_info->width * 3);
|
|
|
f96e0b |
+ }
|
|
|
f96e0b |
+ grub_free (buffer);
|
|
|
f96e0b |
+ break;
|
|
|
f96e0b |
+ }
|
|
|
f96e0b |
+ case 3:
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ grub_uint8_t *buffer = xmalloc (mode_info->width * 3);
|
|
|
f96e0b |
+ grub_uint32_t rmask = ((1 << mode_info->red_mask_size) - 1);
|
|
|
f96e0b |
+ grub_uint32_t gmask = ((1 << mode_info->green_mask_size) - 1);
|
|
|
f96e0b |
+ grub_uint32_t bmask = ((1 << mode_info->blue_mask_size) - 1);
|
|
|
f96e0b |
+ int rshift = mode_info->red_field_pos;
|
|
|
f96e0b |
+ int gshift = mode_info->green_field_pos;
|
|
|
f96e0b |
+ int bshift = mode_info->blue_field_pos;
|
|
|
f96e0b |
+ int mulrshift = (8 - mode_info->red_mask_size);
|
|
|
f96e0b |
+ int mulgshift = (8 - mode_info->green_mask_size);
|
|
|
f96e0b |
+ int mulbshift = (8 - mode_info->blue_mask_size);
|
|
|
f96e0b |
+ int y;
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ for (y = mode_info->height - 1; y >= 0; y--)
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ grub_uint8_t *iptr = ((grub_uint8_t *) ptr + mode_info->pitch * y);
|
|
|
f96e0b |
+ int x;
|
|
|
f96e0b |
+ grub_uint8_t *optr = buffer;
|
|
|
f96e0b |
+ for (x = 0; x < (int) mode_info->width; x++)
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ grub_uint32_t val = 0;
|
|
|
f96e0b |
+#ifdef GRUB_CPU_WORDS_BIGENDIAN
|
|
|
f96e0b |
+ val |= *iptr++ << 16;
|
|
|
f96e0b |
+ val |= *iptr++ << 8;
|
|
|
f96e0b |
+ val |= *iptr++;
|
|
|
f96e0b |
+#else
|
|
|
f96e0b |
+ val |= *iptr++;
|
|
|
f96e0b |
+ val |= *iptr++ << 8;
|
|
|
f96e0b |
+ val |= *iptr++ << 16;
|
|
|
f96e0b |
+#endif
|
|
|
f96e0b |
+ *optr++ = ((val >> bshift) & bmask) << mulbshift;
|
|
|
f96e0b |
+ *optr++ = ((val >> gshift) & gmask) << mulgshift;
|
|
|
f96e0b |
+ *optr++ = ((val >> rshift) & rmask) << mulrshift;
|
|
|
f96e0b |
+ }
|
|
|
f96e0b |
+ write (fd, buffer, mode_info->width * 3);
|
|
|
f96e0b |
+ }
|
|
|
f96e0b |
+ grub_free (buffer);
|
|
|
f96e0b |
+ break;
|
|
|
f96e0b |
+ }
|
|
|
f96e0b |
+ case 2:
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ grub_uint8_t *buffer = xmalloc (mode_info->width * 3);
|
|
|
f96e0b |
+ grub_uint16_t rmask = ((1 << mode_info->red_mask_size) - 1);
|
|
|
f96e0b |
+ grub_uint16_t gmask = ((1 << mode_info->green_mask_size) - 1);
|
|
|
f96e0b |
+ grub_uint16_t bmask = ((1 << mode_info->blue_mask_size) - 1);
|
|
|
f96e0b |
+ int rshift = mode_info->red_field_pos;
|
|
|
f96e0b |
+ int gshift = mode_info->green_field_pos;
|
|
|
f96e0b |
+ int bshift = mode_info->blue_field_pos;
|
|
|
f96e0b |
+ int mulrshift = (8 - mode_info->red_mask_size);
|
|
|
f96e0b |
+ int mulgshift = (8 - mode_info->green_mask_size);
|
|
|
f96e0b |
+ int mulbshift = (8 - mode_info->blue_mask_size);
|
|
|
f96e0b |
+ int y;
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ for (y = mode_info->height - 1; y >= 0; y--)
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ grub_uint16_t *iptr = (grub_uint16_t *) ((grub_uint8_t *) ptr + mode_info->pitch * y);
|
|
|
f96e0b |
+ int x;
|
|
|
f96e0b |
+ grub_uint8_t *optr = buffer;
|
|
|
f96e0b |
+ for (x = 0; x < (int) mode_info->width; x++)
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ grub_uint16_t val = *iptr++;
|
|
|
f96e0b |
+ *optr++ = ((val >> bshift) & bmask) << mulbshift;
|
|
|
f96e0b |
+ *optr++ = ((val >> gshift) & gmask) << mulgshift;
|
|
|
f96e0b |
+ *optr++ = ((val >> rshift) & rmask) << mulrshift;
|
|
|
f96e0b |
+ }
|
|
|
f96e0b |
+ write (fd, buffer, mode_info->width * 3);
|
|
|
f96e0b |
+ }
|
|
|
f96e0b |
+ grub_free (buffer);
|
|
|
f96e0b |
+ break;
|
|
|
f96e0b |
+ }
|
|
|
f96e0b |
+ case 1:
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ int y;
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ for (y = mode_info->height - 1; y >= 0; y--)
|
|
|
f96e0b |
+ write (fd, ((grub_uint8_t *) ptr + mode_info->pitch * y), mode_info->width);
|
|
|
f96e0b |
+ break;
|
|
|
f96e0b |
+ }
|
|
|
f96e0b |
+ }
|
|
|
f96e0b |
+ close (fd);
|
|
|
f96e0b |
+}
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+#endif
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+static const char *
|
|
|
f96e0b |
+get_modename (void)
|
|
|
f96e0b |
+{
|
|
|
f96e0b |
+ static char buf[40];
|
|
|
f96e0b |
+ if (capt_mode_info.mode_type & GRUB_VIDEO_MODE_TYPE_INDEX_COLOR)
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ grub_snprintf (buf, sizeof (buf), "i%d", capt_mode_info.number_of_colors);
|
|
|
f96e0b |
+ return buf;
|
|
|
f96e0b |
+ }
|
|
|
f96e0b |
+ if (capt_mode_info.red_field_pos == 0)
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ grub_snprintf (buf, sizeof (buf), "bgr%d%d%d", capt_mode_info.blue_mask_size,
|
|
|
f96e0b |
+ capt_mode_info.green_mask_size,
|
|
|
f96e0b |
+ capt_mode_info.red_mask_size);
|
|
|
f96e0b |
+ return buf;
|
|
|
f96e0b |
+ }
|
|
|
f96e0b |
+ grub_snprintf (buf, sizeof (buf), "rgb%d%d%d", capt_mode_info.red_mask_size,
|
|
|
f96e0b |
+ capt_mode_info.green_mask_size,
|
|
|
f96e0b |
+ capt_mode_info.blue_mask_size);
|
|
|
f96e0b |
+ return buf;
|
|
|
f96e0b |
+}
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+//#define GENERATE_MODE 1
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+#if defined (GENERATE_MODE) && defined (GRUB_MACHINE_EMU)
|
|
|
f96e0b |
+int genfd = -1;
|
|
|
f96e0b |
+#endif
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+static void
|
|
|
f96e0b |
+checksum (void)
|
|
|
f96e0b |
+{
|
|
|
f96e0b |
+ void *ptr;
|
|
|
f96e0b |
+ grub_uint32_t crc;
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ ptr = grub_video_capture_get_framebuffer ();
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ crc = grub_getcrc32c (0, ptr, capt_mode_info.pitch * capt_mode_info.height);
|
|
|
f96e0b |
+ if (!checksums || ctr >= nchk)
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ grub_test_assert (0, "Unexpected checksum %s_%dx%dx%s:%d: 0x%x",
|
|
|
f96e0b |
+ basename,
|
|
|
f96e0b |
+ capt_mode_info.width,
|
|
|
f96e0b |
+ capt_mode_info.height, get_modename (), ctr, crc);
|
|
|
f96e0b |
+ }
|
|
|
f96e0b |
+ else if (crc != checksums[ctr])
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ grub_test_assert (0, "Checksum %s_%dx%dx%s:%d failed: 0x%x vs 0x%x",
|
|
|
f96e0b |
+ basename,
|
|
|
f96e0b |
+ capt_mode_info.width,
|
|
|
f96e0b |
+ capt_mode_info.height, get_modename (),
|
|
|
f96e0b |
+ ctr, crc, checksums[ctr]);
|
|
|
f96e0b |
+ }
|
|
|
f96e0b |
+ else
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+#if !(defined (GENERATE_MODE) && defined (GRUB_MACHINE_EMU))
|
|
|
f96e0b |
+ ctr++;
|
|
|
f96e0b |
+ return;
|
|
|
f96e0b |
+#endif
|
|
|
f96e0b |
+ }
|
|
|
f96e0b |
+#ifdef GRUB_MACHINE_EMU
|
|
|
f96e0b |
+ char *name = grub_xasprintf ("%s_%dx%dx%s_%d.bmp", basename,
|
|
|
f96e0b |
+ capt_mode_info.width,
|
|
|
f96e0b |
+ capt_mode_info.height, get_modename (),
|
|
|
f96e0b |
+ ctr);
|
|
|
f96e0b |
+ grub_video_capture_write_bmp (name, ptr, &capt_mode_info);
|
|
|
f96e0b |
+#endif
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+#if defined (GENERATE_MODE) && defined (GRUB_MACHINE_EMU)
|
|
|
f96e0b |
+ if (genfd >= 0)
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ char buf[20];
|
|
|
f96e0b |
+ grub_snprintf (buf, sizeof (buf), "0x%x, ", crc);
|
|
|
f96e0b |
+ write (genfd, buf, grub_strlen (buf));
|
|
|
f96e0b |
+ }
|
|
|
f96e0b |
+#endif
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ ctr++;
|
|
|
f96e0b |
+}
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+struct checksum_desc
|
|
|
f96e0b |
+{
|
|
|
f96e0b |
+ const char *name;
|
|
|
f96e0b |
+ unsigned width;
|
|
|
f96e0b |
+ unsigned height;
|
|
|
f96e0b |
+ unsigned mode_type;
|
|
|
f96e0b |
+ unsigned number_of_colors;
|
|
|
f96e0b |
+ unsigned bpp;
|
|
|
f96e0b |
+ unsigned bytes_per_pixel;
|
|
|
f96e0b |
+ unsigned red_field_pos;
|
|
|
f96e0b |
+ unsigned red_mask_size;
|
|
|
f96e0b |
+ unsigned green_field_pos;
|
|
|
f96e0b |
+ unsigned green_mask_size;
|
|
|
f96e0b |
+ unsigned blue_field_pos;
|
|
|
f96e0b |
+ unsigned blue_mask_size;
|
|
|
f96e0b |
+ unsigned reserved_field_pos;
|
|
|
f96e0b |
+ unsigned reserved_mask_size;
|
|
|
f96e0b |
+ const grub_uint32_t *checksums;
|
|
|
f96e0b |
+ int nchk;
|
|
|
f96e0b |
+};
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+const struct checksum_desc checksum_table[] = {
|
|
|
f96e0b |
+#include "checksums.c"
|
|
|
f96e0b |
+};
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+void
|
|
|
f96e0b |
+grub_video_checksum (const char *basename_in)
|
|
|
f96e0b |
+{
|
|
|
f96e0b |
+ unsigned i;
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ grub_video_get_info (&capt_mode_info);
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+#if defined (GENERATE_MODE) && defined (GRUB_MACHINE_EMU)
|
|
|
f96e0b |
+ if (genfd < 0)
|
|
|
f96e0b |
+ genfd = open ("checksums.c", O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
|
|
|
f96e0b |
+ if (genfd >= 0)
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ char buf[400];
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ grub_snprintf (buf, sizeof (buf), "\", %d, %d, 0x%x, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d /* %dx%dx%s */, (grub_uint32_t []) { ",
|
|
|
f96e0b |
+ capt_mode_info.width,
|
|
|
f96e0b |
+ capt_mode_info.height,
|
|
|
f96e0b |
+ capt_mode_info.mode_type,
|
|
|
f96e0b |
+ capt_mode_info.number_of_colors,
|
|
|
f96e0b |
+ capt_mode_info.bpp,
|
|
|
f96e0b |
+ capt_mode_info.bytes_per_pixel,
|
|
|
f96e0b |
+ capt_mode_info.red_field_pos,
|
|
|
f96e0b |
+ capt_mode_info.red_mask_size,
|
|
|
f96e0b |
+ capt_mode_info.green_field_pos,
|
|
|
f96e0b |
+ capt_mode_info.green_mask_size,
|
|
|
f96e0b |
+ capt_mode_info.blue_field_pos,
|
|
|
f96e0b |
+ capt_mode_info.blue_mask_size,
|
|
|
f96e0b |
+ capt_mode_info.reserved_field_pos,
|
|
|
f96e0b |
+ capt_mode_info.reserved_mask_size,
|
|
|
f96e0b |
+ capt_mode_info.width,
|
|
|
f96e0b |
+ capt_mode_info.height, get_modename ());
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ write (genfd, " { \"", 5);
|
|
|
f96e0b |
+ write (genfd, basename_in, grub_strlen (basename_in));
|
|
|
f96e0b |
+ write (genfd, buf, grub_strlen (buf));
|
|
|
f96e0b |
+ }
|
|
|
f96e0b |
+#endif
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ basename = grub_strdup (basename_in);
|
|
|
f96e0b |
+ nchk = 0;
|
|
|
f96e0b |
+ checksums = 0;
|
|
|
f96e0b |
+ /* FIXME: optimize this. */
|
|
|
f96e0b |
+ for (i = 0; i < ARRAY_SIZE (checksum_table); i++)
|
|
|
f96e0b |
+ if (grub_strcmp (checksum_table[i].name, basename_in) == 0
|
|
|
f96e0b |
+ && capt_mode_info.width == checksum_table[i].width
|
|
|
f96e0b |
+ && capt_mode_info.height == checksum_table[i].height
|
|
|
f96e0b |
+ && capt_mode_info.mode_type == checksum_table[i].mode_type
|
|
|
f96e0b |
+ && capt_mode_info.number_of_colors == checksum_table[i].number_of_colors
|
|
|
f96e0b |
+ && capt_mode_info.bpp == checksum_table[i].bpp
|
|
|
f96e0b |
+ && capt_mode_info.bytes_per_pixel == checksum_table[i].bytes_per_pixel
|
|
|
f96e0b |
+ && capt_mode_info.red_field_pos == checksum_table[i].red_field_pos
|
|
|
f96e0b |
+ && capt_mode_info.red_mask_size == checksum_table[i].red_mask_size
|
|
|
f96e0b |
+ && capt_mode_info.green_field_pos == checksum_table[i].green_field_pos
|
|
|
f96e0b |
+ && capt_mode_info.green_mask_size == checksum_table[i].green_mask_size
|
|
|
f96e0b |
+ && capt_mode_info.blue_field_pos == checksum_table[i].blue_field_pos
|
|
|
f96e0b |
+ && capt_mode_info.blue_mask_size == checksum_table[i].blue_mask_size
|
|
|
f96e0b |
+ && capt_mode_info.reserved_field_pos == checksum_table[i].reserved_field_pos
|
|
|
f96e0b |
+ && capt_mode_info.reserved_mask_size == checksum_table[i].reserved_mask_size)
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ nchk = checksum_table[i].nchk;
|
|
|
f96e0b |
+ checksums = checksum_table[i].checksums;
|
|
|
f96e0b |
+ break;
|
|
|
f96e0b |
+ }
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ ctr = 0;
|
|
|
f96e0b |
+ grub_video_capture_refresh_cb = checksum;
|
|
|
f96e0b |
+}
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+void
|
|
|
f96e0b |
+grub_video_checksum_end (void)
|
|
|
f96e0b |
+{
|
|
|
f96e0b |
+#if defined (GENERATE_MODE) && defined (GRUB_MACHINE_EMU)
|
|
|
f96e0b |
+ if (genfd >= 0)
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ char buf[40];
|
|
|
f96e0b |
+ grub_snprintf (buf, sizeof (buf), "}, %x },\n", ctr);
|
|
|
f96e0b |
+ write (genfd, buf, grub_strlen (buf));
|
|
|
f96e0b |
+ }
|
|
|
f96e0b |
+#endif
|
|
|
f96e0b |
+ grub_test_assert (ctr == nchk, "Not enough checksums %s_%dx%dx%s: %d vs %d",
|
|
|
f96e0b |
+ basename,
|
|
|
f96e0b |
+ capt_mode_info.width,
|
|
|
f96e0b |
+ capt_mode_info.height, get_modename (),
|
|
|
f96e0b |
+ ctr, nchk);
|
|
|
f96e0b |
+ grub_free (basename);
|
|
|
f96e0b |
+ basename = 0;
|
|
|
f96e0b |
+ nchk = 0;
|
|
|
f96e0b |
+ checksums = 0;
|
|
|
f96e0b |
+ ctr = 0;
|
|
|
f96e0b |
+ grub_video_capture_refresh_cb = 0;
|
|
|
f96e0b |
+}
|
|
|
f96e0b |
diff --git a/grub-core/tests/videotest_checksum.c b/grub-core/tests/videotest_checksum.c
|
|
|
f96e0b |
new file mode 100644
|
|
|
f96e0b |
index 0000000..e57dae7
|
|
|
f96e0b |
--- /dev/null
|
|
|
f96e0b |
+++ b/grub-core/tests/videotest_checksum.c
|
|
|
f96e0b |
@@ -0,0 +1,286 @@
|
|
|
f96e0b |
+/*
|
|
|
f96e0b |
+ * GRUB -- GRand Unified Bootloader
|
|
|
f96e0b |
+ * Copyright (C) 2013 Free Software Foundation, Inc.
|
|
|
f96e0b |
+ *
|
|
|
f96e0b |
+ * GRUB is free software: you can redistribute it and/or modify
|
|
|
f96e0b |
+ * it under the terms of the GNU General Public License as published by
|
|
|
f96e0b |
+ * the Free Software Foundation, either version 3 of the License, or
|
|
|
f96e0b |
+ * (at your option) any later version.
|
|
|
f96e0b |
+ *
|
|
|
f96e0b |
+ * GRUB is distributed in the hope that it will be useful,
|
|
|
f96e0b |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
f96e0b |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
f96e0b |
+ * GNU General Public License for more details.
|
|
|
f96e0b |
+ *
|
|
|
f96e0b |
+ * You should have received a copy of the GNU General Public License
|
|
|
f96e0b |
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
|
|
f96e0b |
+ */
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+/* All tests need to include test.h for GRUB testing framework. */
|
|
|
f96e0b |
+#include <grub/test.h>
|
|
|
f96e0b |
+#include <grub/dl.h>
|
|
|
f96e0b |
+#include <grub/video.h>
|
|
|
f96e0b |
+#include <grub/video_fb.h>
|
|
|
f96e0b |
+#include <grub/command.h>
|
|
|
f96e0b |
+#include <grub/font.h>
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+GRUB_MOD_LICENSE ("GPLv3+");
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+struct
|
|
|
f96e0b |
+{
|
|
|
f96e0b |
+ struct grub_video_mode_info mode_info;
|
|
|
f96e0b |
+} tests[] = {
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ .mode_info = {
|
|
|
f96e0b |
+ .width = 640,
|
|
|
f96e0b |
+ .height = 480,
|
|
|
f96e0b |
+ .pitch = 640,
|
|
|
f96e0b |
+ .mode_type = GRUB_VIDEO_MODE_TYPE_INDEX_COLOR,
|
|
|
f96e0b |
+ .bpp = 8,
|
|
|
f96e0b |
+ .bytes_per_pixel = 1,
|
|
|
f96e0b |
+ .number_of_colors = GRUB_VIDEO_FBSTD_NUMCOLORS
|
|
|
f96e0b |
+ },
|
|
|
f96e0b |
+ },
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ .mode_info = {
|
|
|
f96e0b |
+ .width = 800,
|
|
|
f96e0b |
+ .height = 600,
|
|
|
f96e0b |
+ .pitch = 800,
|
|
|
f96e0b |
+ .mode_type = GRUB_VIDEO_MODE_TYPE_INDEX_COLOR,
|
|
|
f96e0b |
+ .bpp = 8,
|
|
|
f96e0b |
+ .bytes_per_pixel = 1,
|
|
|
f96e0b |
+ .number_of_colors = GRUB_VIDEO_FBSTD_NUMCOLORS
|
|
|
f96e0b |
+ },
|
|
|
f96e0b |
+ },
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ .mode_info = {
|
|
|
f96e0b |
+ .width = 1024,
|
|
|
f96e0b |
+ .height = 768,
|
|
|
f96e0b |
+ .pitch = 1024,
|
|
|
f96e0b |
+ .mode_type = GRUB_VIDEO_MODE_TYPE_INDEX_COLOR,
|
|
|
f96e0b |
+ .bpp = 8,
|
|
|
f96e0b |
+ .bytes_per_pixel = 1,
|
|
|
f96e0b |
+ .number_of_colors = GRUB_VIDEO_FBSTD_NUMCOLORS
|
|
|
f96e0b |
+ },
|
|
|
f96e0b |
+ },
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ .mode_info = {
|
|
|
f96e0b |
+ .width = 640,
|
|
|
f96e0b |
+ .height = 480,
|
|
|
f96e0b |
+ .pitch = 1280,
|
|
|
f96e0b |
+ GRUB_VIDEO_MI_RGB555 ()
|
|
|
f96e0b |
+ },
|
|
|
f96e0b |
+ },
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ .mode_info = {
|
|
|
f96e0b |
+ .width = 800,
|
|
|
f96e0b |
+ .height = 600,
|
|
|
f96e0b |
+ .pitch = 1600,
|
|
|
f96e0b |
+ GRUB_VIDEO_MI_RGB555 ()
|
|
|
f96e0b |
+ },
|
|
|
f96e0b |
+ },
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ .mode_info = {
|
|
|
f96e0b |
+ .width = 1024,
|
|
|
f96e0b |
+ .height = 768,
|
|
|
f96e0b |
+ .pitch = 2048,
|
|
|
f96e0b |
+ GRUB_VIDEO_MI_RGB555 ()
|
|
|
f96e0b |
+ },
|
|
|
f96e0b |
+ },
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ .mode_info = {
|
|
|
f96e0b |
+ .width = 640,
|
|
|
f96e0b |
+ .height = 480,
|
|
|
f96e0b |
+ .pitch = 1280,
|
|
|
f96e0b |
+ GRUB_VIDEO_MI_RGB565 ()
|
|
|
f96e0b |
+ },
|
|
|
f96e0b |
+ },
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ .mode_info = {
|
|
|
f96e0b |
+ .width = 800,
|
|
|
f96e0b |
+ .height = 600,
|
|
|
f96e0b |
+ .pitch = 1600,
|
|
|
f96e0b |
+ GRUB_VIDEO_MI_RGB565 ()
|
|
|
f96e0b |
+ },
|
|
|
f96e0b |
+ },
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ .mode_info = {
|
|
|
f96e0b |
+ .width = 1024,
|
|
|
f96e0b |
+ .height = 768,
|
|
|
f96e0b |
+ .pitch = 2048,
|
|
|
f96e0b |
+ GRUB_VIDEO_MI_RGB565 ()
|
|
|
f96e0b |
+ },
|
|
|
f96e0b |
+ },
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ .mode_info = {
|
|
|
f96e0b |
+ .width = 640,
|
|
|
f96e0b |
+ .height = 480,
|
|
|
f96e0b |
+ .pitch = 640 * 3,
|
|
|
f96e0b |
+ GRUB_VIDEO_MI_RGB888 ()
|
|
|
f96e0b |
+ },
|
|
|
f96e0b |
+ },
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ .mode_info = {
|
|
|
f96e0b |
+ .width = 800,
|
|
|
f96e0b |
+ .height = 600,
|
|
|
f96e0b |
+ .pitch = 800 * 3,
|
|
|
f96e0b |
+ GRUB_VIDEO_MI_RGB888 ()
|
|
|
f96e0b |
+ },
|
|
|
f96e0b |
+ },
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ .mode_info = {
|
|
|
f96e0b |
+ .width = 1024,
|
|
|
f96e0b |
+ .height = 768,
|
|
|
f96e0b |
+ .pitch = 1024 * 3,
|
|
|
f96e0b |
+ GRUB_VIDEO_MI_RGB888 ()
|
|
|
f96e0b |
+ },
|
|
|
f96e0b |
+ },
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ .mode_info = {
|
|
|
f96e0b |
+ .width = 640,
|
|
|
f96e0b |
+ .height = 480,
|
|
|
f96e0b |
+ .pitch = 640 * 4,
|
|
|
f96e0b |
+ GRUB_VIDEO_MI_RGBA8888()
|
|
|
f96e0b |
+ },
|
|
|
f96e0b |
+ },
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ .mode_info = {
|
|
|
f96e0b |
+ .width = 800,
|
|
|
f96e0b |
+ .height = 600,
|
|
|
f96e0b |
+ .pitch = 800 * 4,
|
|
|
f96e0b |
+ GRUB_VIDEO_MI_RGBA8888()
|
|
|
f96e0b |
+ },
|
|
|
f96e0b |
+ },
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ .mode_info = {
|
|
|
f96e0b |
+ .width = 1024,
|
|
|
f96e0b |
+ .height = 768,
|
|
|
f96e0b |
+ .pitch = 1024 * 4,
|
|
|
f96e0b |
+ GRUB_VIDEO_MI_RGBA8888()
|
|
|
f96e0b |
+ },
|
|
|
f96e0b |
+ },
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ .mode_info = {
|
|
|
f96e0b |
+ .width = 640,
|
|
|
f96e0b |
+ .height = 480,
|
|
|
f96e0b |
+ .pitch = 1280,
|
|
|
f96e0b |
+ GRUB_VIDEO_MI_BGR555 ()
|
|
|
f96e0b |
+ },
|
|
|
f96e0b |
+ },
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ .mode_info = {
|
|
|
f96e0b |
+ .width = 800,
|
|
|
f96e0b |
+ .height = 600,
|
|
|
f96e0b |
+ .pitch = 1600,
|
|
|
f96e0b |
+ GRUB_VIDEO_MI_BGR555 ()
|
|
|
f96e0b |
+ },
|
|
|
f96e0b |
+ },
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ .mode_info = {
|
|
|
f96e0b |
+ .width = 1024,
|
|
|
f96e0b |
+ .height = 768,
|
|
|
f96e0b |
+ .pitch = 2048,
|
|
|
f96e0b |
+ GRUB_VIDEO_MI_BGR555 ()
|
|
|
f96e0b |
+ },
|
|
|
f96e0b |
+ },
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ .mode_info = {
|
|
|
f96e0b |
+ .width = 640,
|
|
|
f96e0b |
+ .height = 480,
|
|
|
f96e0b |
+ .pitch = 1280,
|
|
|
f96e0b |
+ GRUB_VIDEO_MI_BGR565 ()
|
|
|
f96e0b |
+ },
|
|
|
f96e0b |
+ },
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ .mode_info = {
|
|
|
f96e0b |
+ .width = 800,
|
|
|
f96e0b |
+ .height = 600,
|
|
|
f96e0b |
+ .pitch = 1600,
|
|
|
f96e0b |
+ GRUB_VIDEO_MI_BGR565 ()
|
|
|
f96e0b |
+ },
|
|
|
f96e0b |
+ },
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ .mode_info = {
|
|
|
f96e0b |
+ .width = 1024,
|
|
|
f96e0b |
+ .height = 768,
|
|
|
f96e0b |
+ .pitch = 2048,
|
|
|
f96e0b |
+ GRUB_VIDEO_MI_BGR565 ()
|
|
|
f96e0b |
+ },
|
|
|
f96e0b |
+ },
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ .mode_info = {
|
|
|
f96e0b |
+ .width = 640,
|
|
|
f96e0b |
+ .height = 480,
|
|
|
f96e0b |
+ .pitch = 640 * 3,
|
|
|
f96e0b |
+ GRUB_VIDEO_MI_BGR888 ()
|
|
|
f96e0b |
+ },
|
|
|
f96e0b |
+ },
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ .mode_info = {
|
|
|
f96e0b |
+ .width = 800,
|
|
|
f96e0b |
+ .height = 600,
|
|
|
f96e0b |
+ .pitch = 800 * 3,
|
|
|
f96e0b |
+ GRUB_VIDEO_MI_BGR888 ()
|
|
|
f96e0b |
+ },
|
|
|
f96e0b |
+ },
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ .mode_info = {
|
|
|
f96e0b |
+ .width = 1024,
|
|
|
f96e0b |
+ .height = 768,
|
|
|
f96e0b |
+ .pitch = 1024 * 3,
|
|
|
f96e0b |
+ GRUB_VIDEO_MI_BGR888 ()
|
|
|
f96e0b |
+ },
|
|
|
f96e0b |
+ },
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ .mode_info = {
|
|
|
f96e0b |
+ .width = 640,
|
|
|
f96e0b |
+ .height = 480,
|
|
|
f96e0b |
+ .pitch = 640 * 4,
|
|
|
f96e0b |
+ GRUB_VIDEO_MI_BGRA8888()
|
|
|
f96e0b |
+ },
|
|
|
f96e0b |
+ },
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ .mode_info = {
|
|
|
f96e0b |
+ .width = 800,
|
|
|
f96e0b |
+ .height = 600,
|
|
|
f96e0b |
+ .pitch = 800 * 4,
|
|
|
f96e0b |
+ GRUB_VIDEO_MI_BGRA8888()
|
|
|
f96e0b |
+ },
|
|
|
f96e0b |
+ },
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ .mode_info = {
|
|
|
f96e0b |
+ .width = 1024,
|
|
|
f96e0b |
+ .height = 768,
|
|
|
f96e0b |
+ .pitch = 1024 * 4,
|
|
|
f96e0b |
+ GRUB_VIDEO_MI_BGRA8888()
|
|
|
f96e0b |
+ },
|
|
|
f96e0b |
+ },
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ };
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+/* Functional test main method. */
|
|
|
f96e0b |
+static void
|
|
|
f96e0b |
+videotest_checksum (void)
|
|
|
f96e0b |
+{
|
|
|
f96e0b |
+ unsigned i;
|
|
|
f96e0b |
+ grub_font_load ("unicode");
|
|
|
f96e0b |
+ for (i = 0; i < ARRAY_SIZE (tests); i++)
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ grub_video_capture_start (&tests[i].mode_info,
|
|
|
f96e0b |
+ grub_video_fbstd_colors,
|
|
|
f96e0b |
+ GRUB_VIDEO_FBSTD_NUMCOLORS);
|
|
|
f96e0b |
+ grub_terminal_input_fake_sequence ((int []) { '\n' }, 1);
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ grub_video_checksum ("videotest");
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ char *args[] = { 0 };
|
|
|
f96e0b |
+ grub_command_execute ("videotest", 0, args);
|
|
|
f96e0b |
+ grub_video_checksum_end ();
|
|
|
f96e0b |
+ grub_video_capture_end ();
|
|
|
f96e0b |
+ }
|
|
|
f96e0b |
+}
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+/* Register example_test method as a functional test. */
|
|
|
f96e0b |
+GRUB_FUNCTIONAL_TEST (videotest_checksum, videotest_checksum);
|
|
|
f96e0b |
diff --git a/grub-core/video/capture.c b/grub-core/video/capture.c
|
|
|
f96e0b |
new file mode 100644
|
|
|
f96e0b |
index 0000000..be7fb61
|
|
|
f96e0b |
--- /dev/null
|
|
|
f96e0b |
+++ b/grub-core/video/capture.c
|
|
|
f96e0b |
@@ -0,0 +1,128 @@
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+#define grub_video_render_target grub_video_fbrender_target
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+#include <grub/video.h>
|
|
|
f96e0b |
+#include <grub/video_fb.h>
|
|
|
f96e0b |
+#include <grub/mm.h>
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+static struct
|
|
|
f96e0b |
+{
|
|
|
f96e0b |
+ struct grub_video_mode_info mode_info;
|
|
|
f96e0b |
+ struct grub_video_render_target *render_target;
|
|
|
f96e0b |
+ grub_uint8_t *ptr;
|
|
|
f96e0b |
+} framebuffer;
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+void (*grub_video_capture_refresh_cb) (void);
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+static grub_err_t
|
|
|
f96e0b |
+grub_video_capture_swap_buffers (void)
|
|
|
f96e0b |
+{
|
|
|
f96e0b |
+ if (grub_video_capture_refresh_cb)
|
|
|
f96e0b |
+ grub_video_capture_refresh_cb ();
|
|
|
f96e0b |
+ return GRUB_ERR_NONE;
|
|
|
f96e0b |
+}
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+static grub_err_t
|
|
|
f96e0b |
+grub_video_capture_set_active_render_target (struct grub_video_render_target *target)
|
|
|
f96e0b |
+{
|
|
|
f96e0b |
+ if (target == GRUB_VIDEO_RENDER_TARGET_DISPLAY)
|
|
|
f96e0b |
+ target = framebuffer.render_target;
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ return grub_video_fb_set_active_render_target (target);
|
|
|
f96e0b |
+}
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+static struct grub_video_adapter grub_video_capture_adapter =
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ .name = "Render capture",
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ .prio = 0,
|
|
|
f96e0b |
+ .id = GRUB_VIDEO_ADAPTER_CAPTURE,
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ .fini = grub_video_fb_fini,
|
|
|
f96e0b |
+ .get_info = grub_video_fb_get_info,
|
|
|
f96e0b |
+ .get_info_and_fini = 0,
|
|
|
f96e0b |
+ .set_palette = grub_video_fb_set_palette,
|
|
|
f96e0b |
+ .get_palette = grub_video_fb_get_palette,
|
|
|
f96e0b |
+ .set_viewport = grub_video_fb_set_viewport,
|
|
|
f96e0b |
+ .get_viewport = grub_video_fb_get_viewport,
|
|
|
f96e0b |
+ .map_color = grub_video_fb_map_color,
|
|
|
f96e0b |
+ .map_rgb = grub_video_fb_map_rgb,
|
|
|
f96e0b |
+ .map_rgba = grub_video_fb_map_rgba,
|
|
|
f96e0b |
+ .unmap_color = grub_video_fb_unmap_color,
|
|
|
f96e0b |
+ .fill_rect = grub_video_fb_fill_rect,
|
|
|
f96e0b |
+ .blit_bitmap = grub_video_fb_blit_bitmap,
|
|
|
f96e0b |
+ .blit_render_target = grub_video_fb_blit_render_target,
|
|
|
f96e0b |
+ .scroll = grub_video_fb_scroll,
|
|
|
f96e0b |
+ .swap_buffers = grub_video_capture_swap_buffers,
|
|
|
f96e0b |
+ .create_render_target = grub_video_fb_create_render_target,
|
|
|
f96e0b |
+ .delete_render_target = grub_video_fb_delete_render_target,
|
|
|
f96e0b |
+ .set_active_render_target = grub_video_capture_set_active_render_target,
|
|
|
f96e0b |
+ .get_active_render_target = grub_video_fb_get_active_render_target,
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ .next = 0
|
|
|
f96e0b |
+ };
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+static struct grub_video_adapter *saved;
|
|
|
f96e0b |
+static struct grub_video_mode_info saved_mode_info;
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+grub_err_t
|
|
|
f96e0b |
+grub_video_capture_start (const struct grub_video_mode_info *mode_info,
|
|
|
f96e0b |
+ struct grub_video_palette_data *palette,
|
|
|
f96e0b |
+ unsigned int palette_size)
|
|
|
f96e0b |
+{
|
|
|
f96e0b |
+ grub_err_t err;
|
|
|
f96e0b |
+ grub_memset (&framebuffer, 0, sizeof (framebuffer));
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ grub_video_fb_init ();
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ framebuffer.mode_info = *mode_info;
|
|
|
f96e0b |
+ framebuffer.mode_info.blit_format = grub_video_get_blit_format (&framebuffer.mode_info);
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ framebuffer.ptr = grub_malloc (framebuffer.mode_info.height * framebuffer.mode_info.pitch);
|
|
|
f96e0b |
+ if (!framebuffer.ptr)
|
|
|
f96e0b |
+ return grub_errno;
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ err = grub_video_fb_create_render_target_from_pointer (&framebuffer.render_target,
|
|
|
f96e0b |
+ &framebuffer.mode_info,
|
|
|
f96e0b |
+ framebuffer.ptr);
|
|
|
f96e0b |
+ if (err)
|
|
|
f96e0b |
+ return err;
|
|
|
f96e0b |
+ err = grub_video_fb_set_active_render_target (framebuffer.render_target);
|
|
|
f96e0b |
+ if (err)
|
|
|
f96e0b |
+ return err;
|
|
|
f96e0b |
+ err = grub_video_fb_set_palette (0, palette_size, palette);
|
|
|
f96e0b |
+ if (err)
|
|
|
f96e0b |
+ return err;
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ saved = grub_video_adapter_active;
|
|
|
f96e0b |
+ if (saved)
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ grub_video_get_info (&saved_mode_info);
|
|
|
f96e0b |
+ if (saved->fini)
|
|
|
f96e0b |
+ saved->fini ();
|
|
|
f96e0b |
+ }
|
|
|
f96e0b |
+ grub_video_adapter_active = &grub_video_capture_adapter;
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ return GRUB_ERR_NONE;
|
|
|
f96e0b |
+}
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+void *
|
|
|
f96e0b |
+grub_video_capture_get_framebuffer (void)
|
|
|
f96e0b |
+{
|
|
|
f96e0b |
+ return framebuffer.ptr;
|
|
|
f96e0b |
+}
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+void
|
|
|
f96e0b |
+grub_video_capture_end (void)
|
|
|
f96e0b |
+{
|
|
|
f96e0b |
+ grub_free (framebuffer.ptr);
|
|
|
f96e0b |
+ grub_video_fb_fini ();
|
|
|
f96e0b |
+ grub_video_adapter_active = saved;
|
|
|
f96e0b |
+ if (saved)
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ if (saved->init)
|
|
|
f96e0b |
+ saved->init ();
|
|
|
f96e0b |
+ if (saved->setup)
|
|
|
f96e0b |
+ saved->setup (saved_mode_info.width, saved_mode_info.height, 0, 0);
|
|
|
f96e0b |
+ }
|
|
|
f96e0b |
+}
|
|
|
f96e0b |
diff --git a/grub-core/video/video.c b/grub-core/video/video.c
|
|
|
f96e0b |
index 844f36c..90b5253 100644
|
|
|
f96e0b |
--- a/grub-core/video/video.c
|
|
|
f96e0b |
+++ b/grub-core/video/video.c
|
|
|
f96e0b |
@@ -29,7 +29,7 @@ GRUB_MOD_LICENSE ("GPLv3+");
|
|
|
f96e0b |
grub_video_adapter_t grub_video_adapter_list = NULL;
|
|
|
f96e0b |
|
|
|
f96e0b |
/* Active video adapter. */
|
|
|
f96e0b |
-static grub_video_adapter_t grub_video_adapter_active;
|
|
|
f96e0b |
+grub_video_adapter_t grub_video_adapter_active;
|
|
|
f96e0b |
|
|
|
f96e0b |
/* Restore back to initial mode (where applicable). */
|
|
|
f96e0b |
grub_err_t
|
|
|
f96e0b |
@@ -510,6 +510,9 @@ grub_video_set_mode (const char *modestring,
|
|
|
f96e0b |
if (! modevar)
|
|
|
f96e0b |
return grub_errno;
|
|
|
f96e0b |
|
|
|
f96e0b |
+ if (grub_video_adapter_active && grub_video_adapter_active->id == GRUB_VIDEO_ADAPTER_CAPTURE)
|
|
|
f96e0b |
+ return GRUB_ERR_NONE;
|
|
|
f96e0b |
+
|
|
|
f96e0b |
if (grub_memcmp (next_mode, "keep", sizeof ("keep")) == 0
|
|
|
f96e0b |
|| grub_memcmp (next_mode, "keep,", sizeof ("keep,") - 1) == 0
|
|
|
f96e0b |
|| grub_memcmp (next_mode, "keep;", sizeof ("keep;") - 1) == 0)
|
|
|
f96e0b |
@@ -714,11 +717,3 @@ grub_video_set_mode (const char *modestring,
|
|
|
f96e0b |
return grub_error (GRUB_ERR_BAD_ARGUMENT,
|
|
|
f96e0b |
N_("no suitable video mode found"));
|
|
|
f96e0b |
}
|
|
|
f96e0b |
-
|
|
|
f96e0b |
-#ifdef GRUB_UTIL
|
|
|
f96e0b |
-void
|
|
|
f96e0b |
-grub_video_set_adapter (grub_video_adapter_t adapter)
|
|
|
f96e0b |
-{
|
|
|
f96e0b |
- grub_video_adapter_active = adapter;
|
|
|
f96e0b |
-}
|
|
|
f96e0b |
-#endif
|
|
|
f96e0b |
diff --git a/include/grub/emu/export.h b/include/grub/emu/export.h
|
|
|
f96e0b |
index 1e2f043..7f9e4e1 100644
|
|
|
f96e0b |
--- a/include/grub/emu/export.h
|
|
|
f96e0b |
+++ b/include/grub/emu/export.h
|
|
|
f96e0b |
@@ -3,4 +3,5 @@ void EXPORT_FUNC (close) (void);
|
|
|
f96e0b |
void EXPORT_FUNC (read) (void);
|
|
|
f96e0b |
void EXPORT_FUNC (write) (void);
|
|
|
f96e0b |
void EXPORT_FUNC (ioctl) (void);
|
|
|
f96e0b |
-
|
|
|
f96e0b |
+void EXPORT_FUNC (__errno_location) (void);
|
|
|
f96e0b |
+void EXPORT_FUNC (strerror) (void);
|
|
|
f96e0b |
diff --git a/include/grub/test.h b/include/grub/test.h
|
|
|
f96e0b |
index d876f57..6aa4069 100644
|
|
|
f96e0b |
--- a/include/grub/test.h
|
|
|
f96e0b |
+++ b/include/grub/test.h
|
|
|
f96e0b |
@@ -90,4 +90,13 @@ void grub_unit_test_fini (void);
|
|
|
f96e0b |
grub_test_unregister (#name); \
|
|
|
f96e0b |
}
|
|
|
f96e0b |
|
|
|
f96e0b |
+void
|
|
|
f96e0b |
+grub_video_checksum (const char *basename_in);
|
|
|
f96e0b |
+void
|
|
|
f96e0b |
+grub_video_checksum_end (void);
|
|
|
f96e0b |
+void
|
|
|
f96e0b |
+grub_terminal_input_fake_sequence (int *seq_in, int nseq_in);
|
|
|
f96e0b |
+void
|
|
|
f96e0b |
+grub_terminal_input_fake_sequence_end (void);
|
|
|
f96e0b |
+
|
|
|
f96e0b |
#endif /* ! GRUB_TEST_HEADER */
|
|
|
f96e0b |
diff --git a/include/grub/video.h b/include/grub/video.h
|
|
|
f96e0b |
index bd5852e..6308177 100644
|
|
|
f96e0b |
--- a/include/grub/video.h
|
|
|
f96e0b |
+++ b/include/grub/video.h
|
|
|
f96e0b |
@@ -284,7 +284,8 @@ typedef enum grub_video_driver_id
|
|
|
f96e0b |
GRUB_VIDEO_DRIVER_SIS315PRO,
|
|
|
f96e0b |
GRUB_VIDEO_DRIVER_RADEON_FULOONG2E,
|
|
|
f96e0b |
GRUB_VIDEO_DRIVER_COREBOOT,
|
|
|
f96e0b |
- GRUB_VIDEO_DRIVER_IEEE1275
|
|
|
f96e0b |
+ GRUB_VIDEO_DRIVER_IEEE1275,
|
|
|
f96e0b |
+ GRUB_VIDEO_ADAPTER_CAPTURE
|
|
|
f96e0b |
} grub_video_driver_id_t;
|
|
|
f96e0b |
|
|
|
f96e0b |
typedef enum grub_video_adapter_prio
|
|
|
f96e0b |
@@ -544,9 +545,122 @@ extern void grub_video_sis315pro_fini (void);
|
|
|
f96e0b |
extern void grub_video_radeon_fuloong2e_fini (void);
|
|
|
f96e0b |
#endif
|
|
|
f96e0b |
|
|
|
f96e0b |
-#ifdef GRUB_UTIL
|
|
|
f96e0b |
void
|
|
|
f96e0b |
grub_video_set_adapter (grub_video_adapter_t adapter);
|
|
|
f96e0b |
-#endif
|
|
|
f96e0b |
+grub_video_adapter_t
|
|
|
f96e0b |
+grub_video_get_adapter (void);
|
|
|
f96e0b |
+grub_err_t
|
|
|
f96e0b |
+grub_video_capture_start (const struct grub_video_mode_info *mode_info,
|
|
|
f96e0b |
+ struct grub_video_palette_data *palette,
|
|
|
f96e0b |
+ unsigned int palette_size);
|
|
|
f96e0b |
+void
|
|
|
f96e0b |
+grub_video_capture_end (void);
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+void *
|
|
|
f96e0b |
+grub_video_capture_get_framebuffer (void);
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+extern grub_video_adapter_t EXPORT_VAR (grub_video_adapter_active);
|
|
|
f96e0b |
+extern void (*grub_video_capture_refresh_cb) (void);
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+#define GRUB_VIDEO_MI_RGB555(x) \
|
|
|
f96e0b |
+ x.mode_type = GRUB_VIDEO_MODE_TYPE_RGB, \
|
|
|
f96e0b |
+ x.bpp = 15, \
|
|
|
f96e0b |
+ x.bytes_per_pixel = 2, \
|
|
|
f96e0b |
+ x.number_of_colors = 256, \
|
|
|
f96e0b |
+ x.red_mask_size = 5, \
|
|
|
f96e0b |
+ x.red_field_pos = 10, \
|
|
|
f96e0b |
+ x.green_mask_size = 5, \
|
|
|
f96e0b |
+ x.green_field_pos = 5, \
|
|
|
f96e0b |
+ x.blue_mask_size = 5, \
|
|
|
f96e0b |
+ x.blue_field_pos = 0
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+#define GRUB_VIDEO_MI_RGB565(x) \
|
|
|
f96e0b |
+ x.mode_type = GRUB_VIDEO_MODE_TYPE_RGB, \
|
|
|
f96e0b |
+ x.bpp = 16, \
|
|
|
f96e0b |
+ x.bytes_per_pixel = 2, \
|
|
|
f96e0b |
+ x.number_of_colors = 256, \
|
|
|
f96e0b |
+ x.red_mask_size = 5, \
|
|
|
f96e0b |
+ x.red_field_pos = 11, \
|
|
|
f96e0b |
+ x.green_mask_size = 6, \
|
|
|
f96e0b |
+ x.green_field_pos = 5, \
|
|
|
f96e0b |
+ x.blue_mask_size = 5, \
|
|
|
f96e0b |
+ x.blue_field_pos = 0
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+#define GRUB_VIDEO_MI_RGB888(x) \
|
|
|
f96e0b |
+ x.mode_type = GRUB_VIDEO_MODE_TYPE_RGB, \
|
|
|
f96e0b |
+ x.bpp = 24, \
|
|
|
f96e0b |
+ x.bytes_per_pixel = 3, \
|
|
|
f96e0b |
+ x.number_of_colors = 256, \
|
|
|
f96e0b |
+ x.red_mask_size = 8, \
|
|
|
f96e0b |
+ x.red_field_pos = 16, \
|
|
|
f96e0b |
+ x.green_mask_size = 8, \
|
|
|
f96e0b |
+ x.green_field_pos = 8, \
|
|
|
f96e0b |
+ x.blue_mask_size = 8, \
|
|
|
f96e0b |
+ x.blue_field_pos = 0
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+#define GRUB_VIDEO_MI_RGBA8888(x) \
|
|
|
f96e0b |
+ x.mode_type = GRUB_VIDEO_MODE_TYPE_RGB, \
|
|
|
f96e0b |
+ x.bpp = 32, \
|
|
|
f96e0b |
+ x.bytes_per_pixel = 4, \
|
|
|
f96e0b |
+ x.number_of_colors = 256, \
|
|
|
f96e0b |
+ x.reserved_mask_size = 8, \
|
|
|
f96e0b |
+ x.reserved_field_pos = 24, \
|
|
|
f96e0b |
+ x.red_mask_size = 8, \
|
|
|
f96e0b |
+ x.red_field_pos = 16, \
|
|
|
f96e0b |
+ x.green_mask_size = 8, \
|
|
|
f96e0b |
+ x.green_field_pos = 8, \
|
|
|
f96e0b |
+ x.blue_mask_size = 8, \
|
|
|
f96e0b |
+ x.blue_field_pos = 0
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+#define GRUB_VIDEO_MI_BGR555(x) \
|
|
|
f96e0b |
+ x.mode_type = GRUB_VIDEO_MODE_TYPE_RGB, \
|
|
|
f96e0b |
+ x.bpp = 15, \
|
|
|
f96e0b |
+ x.bytes_per_pixel = 2, \
|
|
|
f96e0b |
+ x.number_of_colors = 256, \
|
|
|
f96e0b |
+ x.red_mask_size = 5, \
|
|
|
f96e0b |
+ x.red_field_pos = 0, \
|
|
|
f96e0b |
+ x.green_mask_size = 5, \
|
|
|
f96e0b |
+ x.green_field_pos = 5, \
|
|
|
f96e0b |
+ x.blue_mask_size = 5, \
|
|
|
f96e0b |
+ x.blue_field_pos = 10
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+#define GRUB_VIDEO_MI_BGR565(x) \
|
|
|
f96e0b |
+ x.mode_type = GRUB_VIDEO_MODE_TYPE_RGB, \
|
|
|
f96e0b |
+ x.bpp = 16, \
|
|
|
f96e0b |
+ x.bytes_per_pixel = 2, \
|
|
|
f96e0b |
+ x.number_of_colors = 256, \
|
|
|
f96e0b |
+ x.red_mask_size = 5, \
|
|
|
f96e0b |
+ x.red_field_pos = 0, \
|
|
|
f96e0b |
+ x.green_mask_size = 6, \
|
|
|
f96e0b |
+ x.green_field_pos = 5, \
|
|
|
f96e0b |
+ x.blue_mask_size = 5, \
|
|
|
f96e0b |
+ x.blue_field_pos = 11
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+#define GRUB_VIDEO_MI_BGR888(x) \
|
|
|
f96e0b |
+ x.mode_type = GRUB_VIDEO_MODE_TYPE_RGB, \
|
|
|
f96e0b |
+ x.bpp = 24, \
|
|
|
f96e0b |
+ x.bytes_per_pixel = 3, \
|
|
|
f96e0b |
+ x.number_of_colors = 256, \
|
|
|
f96e0b |
+ x.red_mask_size = 8, \
|
|
|
f96e0b |
+ x.red_field_pos = 0, \
|
|
|
f96e0b |
+ x.green_mask_size = 8, \
|
|
|
f96e0b |
+ x.green_field_pos = 8, \
|
|
|
f96e0b |
+ x.blue_mask_size = 8, \
|
|
|
f96e0b |
+ x.blue_field_pos = 16
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+#define GRUB_VIDEO_MI_BGRA8888(x) \
|
|
|
f96e0b |
+ x.mode_type = GRUB_VIDEO_MODE_TYPE_RGB, \
|
|
|
f96e0b |
+ x.bpp = 32, \
|
|
|
f96e0b |
+ x.bytes_per_pixel = 4, \
|
|
|
f96e0b |
+ x.number_of_colors = 256, \
|
|
|
f96e0b |
+ x.reserved_mask_size = 8, \
|
|
|
f96e0b |
+ x.reserved_field_pos = 24, \
|
|
|
f96e0b |
+ x.red_mask_size = 8, \
|
|
|
f96e0b |
+ x.red_field_pos = 0, \
|
|
|
f96e0b |
+ x.green_mask_size = 8, \
|
|
|
f96e0b |
+ x.green_field_pos = 8, \
|
|
|
f96e0b |
+ x.blue_mask_size = 8, \
|
|
|
f96e0b |
+ x.blue_field_pos = 16
|
|
|
f96e0b |
|
|
|
f96e0b |
#endif /* ! GRUB_VIDEO_HEADER */
|
|
|
f96e0b |
diff --git a/tests/grub_func_test.in b/tests/grub_func_test.in
|
|
|
f96e0b |
new file mode 100644
|
|
|
f96e0b |
index 0000000..a149cf9
|
|
|
f96e0b |
--- /dev/null
|
|
|
f96e0b |
+++ b/tests/grub_func_test.in
|
|
|
f96e0b |
@@ -0,0 +1,12 @@
|
|
|
f96e0b |
+#! /bin/bash
|
|
|
f96e0b |
+set -e
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+. "@builddir@/grub-core/modinfo.sh"
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+out=`echo all_functional_test | @builddir@/grub-shell`
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+if [ "$(echo "$out" | tail -n 1)" != "ALL TESTS PASSED" ]; then
|
|
|
f96e0b |
+ echo "Functional test failure: $out"
|
|
|
f96e0b |
+ exit 1
|
|
|
f96e0b |
+fi
|
|
|
f96e0b |
+
|
|
|
f96e0b |
diff --git a/tests/util/grub-shell.in b/tests/util/grub-shell.in
|
|
|
f96e0b |
index 1d7dfb8..dfde836 100644
|
|
|
f96e0b |
--- a/tests/util/grub-shell.in
|
|
|
f96e0b |
+++ b/tests/util/grub-shell.in
|
|
|
f96e0b |
@@ -408,6 +408,8 @@ if [ x$boot = xnet ]; then
|
|
|
f96e0b |
timeout -s KILL $timeout "${qemu}" ${qemuopts} -nographic ${serial_null} -serial file:/dev/stdout -monitor file:/dev/null -boot n -net "user,tftp=$netdir,bootfile=/boot/grub/${grub_modinfo_target_cpu}-${grub_modinfo_platform}/core.$netbootext" -net nic | cat | tr -d "\r" | do_trim
|
|
|
f96e0b |
elif [ x$boot = xemu ]; then
|
|
|
f96e0b |
grubdir="$(mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX")"
|
|
|
f96e0b |
+ mkdir -p "$grubdir/fonts"
|
|
|
f96e0b |
+ cp "@builddir@/"unicode.pf2 "$grubdir/fonts/unicode.pf2"
|
|
|
f96e0b |
cp "${cfgfile}" "$grubdir/grub.cfg"
|
|
|
f96e0b |
cp "${source}" "$grubdir/testcase.cfg"
|
|
|
f96e0b |
@builddir@/grub-core/grub-emu -m "$device_map" -d "$grubdir" | tr -d "\r" | do_trim
|
|
|
f96e0b |
diff --git a/util/grub-render-label.c b/util/grub-render-label.c
|
|
|
f96e0b |
index 7237759..32d3774 100644
|
|
|
f96e0b |
--- a/util/grub-render-label.c
|
|
|
f96e0b |
+++ b/util/grub-render-label.c
|
|
|
f96e0b |
@@ -1,6 +1,6 @@
|
|
|
f96e0b |
/*
|
|
|
f96e0b |
* GRUB -- GRand Unified Bootloader
|
|
|
f96e0b |
- * Copyright (C) 2010,2012 Free Software Foundation, Inc.
|
|
|
f96e0b |
+ * Copyright (C) 2010,2012,2013 Free Software Foundation, Inc.
|
|
|
f96e0b |
*
|
|
|
f96e0b |
* GRUB is free software: you can redistribute it and/or modify
|
|
|
f96e0b |
* it under the terms of the GNU General Public License as published by
|
|
|
f96e0b |
@@ -17,8 +17,6 @@
|
|
|
f96e0b |
*/
|
|
|
f96e0b |
|
|
|
f96e0b |
|
|
|
f96e0b |
-#define grub_video_render_target grub_video_fbrender_target
|
|
|
f96e0b |
-
|
|
|
f96e0b |
#include <config.h>
|
|
|
f96e0b |
|
|
|
f96e0b |
#include <grub/util/misc.h>
|
|
|
f96e0b |
@@ -74,58 +72,6 @@ static struct argp_option options[] = {
|
|
|
f96e0b |
#include <grub/video.h>
|
|
|
f96e0b |
#include <grub/video_fb.h>
|
|
|
f96e0b |
|
|
|
f96e0b |
-static struct
|
|
|
f96e0b |
-{
|
|
|
f96e0b |
- struct grub_video_mode_info mode_info;
|
|
|
f96e0b |
- struct grub_video_render_target *render_target;
|
|
|
f96e0b |
- grub_uint8_t *ptr;
|
|
|
f96e0b |
-} framebuffer;
|
|
|
f96e0b |
-
|
|
|
f96e0b |
-static grub_err_t
|
|
|
f96e0b |
-grub_video_text_render_swap_buffers (void)
|
|
|
f96e0b |
-{
|
|
|
f96e0b |
- return GRUB_ERR_NONE;
|
|
|
f96e0b |
-}
|
|
|
f96e0b |
-
|
|
|
f96e0b |
-static grub_err_t
|
|
|
f96e0b |
-grub_video_text_render_set_active_render_target (struct grub_video_render_target *target)
|
|
|
f96e0b |
-{
|
|
|
f96e0b |
- if (target == GRUB_VIDEO_RENDER_TARGET_DISPLAY)
|
|
|
f96e0b |
- target = framebuffer.render_target;
|
|
|
f96e0b |
-
|
|
|
f96e0b |
- return grub_video_fb_set_active_render_target (target);
|
|
|
f96e0b |
-}
|
|
|
f96e0b |
-
|
|
|
f96e0b |
-static struct grub_video_adapter grub_video_text_render_adapter =
|
|
|
f96e0b |
- {
|
|
|
f96e0b |
- .name = "Text rendering",
|
|
|
f96e0b |
-
|
|
|
f96e0b |
- .prio = GRUB_VIDEO_ADAPTER_PRIO_FIRMWARE,
|
|
|
f96e0b |
-
|
|
|
f96e0b |
- .fini = grub_video_fb_fini,
|
|
|
f96e0b |
- .get_info = grub_video_fb_get_info,
|
|
|
f96e0b |
- .get_info_and_fini = 0,
|
|
|
f96e0b |
- .set_palette = grub_video_fb_set_palette,
|
|
|
f96e0b |
- .get_palette = grub_video_fb_get_palette,
|
|
|
f96e0b |
- .set_viewport = grub_video_fb_set_viewport,
|
|
|
f96e0b |
- .get_viewport = grub_video_fb_get_viewport,
|
|
|
f96e0b |
- .map_color = grub_video_fb_map_color,
|
|
|
f96e0b |
- .map_rgb = grub_video_fb_map_rgb,
|
|
|
f96e0b |
- .map_rgba = grub_video_fb_map_rgba,
|
|
|
f96e0b |
- .unmap_color = grub_video_fb_unmap_color,
|
|
|
f96e0b |
- .fill_rect = grub_video_fb_fill_rect,
|
|
|
f96e0b |
- .blit_bitmap = grub_video_fb_blit_bitmap,
|
|
|
f96e0b |
- .blit_render_target = grub_video_fb_blit_render_target,
|
|
|
f96e0b |
- .scroll = grub_video_fb_scroll,
|
|
|
f96e0b |
- .swap_buffers = grub_video_text_render_swap_buffers,
|
|
|
f96e0b |
- .create_render_target = grub_video_fb_create_render_target,
|
|
|
f96e0b |
- .delete_render_target = grub_video_fb_delete_render_target,
|
|
|
f96e0b |
- .set_active_render_target = grub_video_text_render_set_active_render_target,
|
|
|
f96e0b |
- .get_active_render_target = grub_video_fb_get_active_render_target,
|
|
|
f96e0b |
-
|
|
|
f96e0b |
- .next = 0
|
|
|
f96e0b |
- };
|
|
|
f96e0b |
-
|
|
|
f96e0b |
static error_t
|
|
|
f96e0b |
argp_parser (int key, char *arg, struct argp_state *state)
|
|
|
f96e0b |
{
|
|
|
f96e0b |
@@ -208,6 +154,7 @@ main (int argc, char *argv[])
|
|
|
f96e0b |
0x77, 0x66, 0x3f, 0x27 };
|
|
|
f96e0b |
int i, j, k, cptr = 0;
|
|
|
f96e0b |
grub_uint8_t bg, fg;
|
|
|
f96e0b |
+ struct grub_video_mode_info mode_info;
|
|
|
f96e0b |
|
|
|
f96e0b |
for (i = 0; i < 256; i++)
|
|
|
f96e0b |
ieee1275_palette[i].a = 0xff;
|
|
|
f96e0b |
@@ -340,32 +287,17 @@ main (int argc, char *argv[])
|
|
|
f96e0b |
width = grub_font_get_string_width (font, text) + 10;
|
|
|
f96e0b |
height = grub_font_get_height (font);
|
|
|
f96e0b |
|
|
|
f96e0b |
- grub_memset (&framebuffer, 0, sizeof (framebuffer));
|
|
|
f96e0b |
-
|
|
|
f96e0b |
- grub_video_fb_init ();
|
|
|
f96e0b |
+ mode_info.width = width;
|
|
|
f96e0b |
+ mode_info.height = height;
|
|
|
f96e0b |
+ mode_info.pitch = width;
|
|
|
f96e0b |
|
|
|
f96e0b |
- framebuffer.mode_info.width = width;
|
|
|
f96e0b |
- framebuffer.mode_info.height = height;
|
|
|
f96e0b |
- framebuffer.mode_info.pitch = width;
|
|
|
f96e0b |
+ mode_info.mode_type = GRUB_VIDEO_MODE_TYPE_INDEX_COLOR;
|
|
|
f96e0b |
+ mode_info.bpp = 8;
|
|
|
f96e0b |
+ mode_info.bytes_per_pixel = 1;
|
|
|
f96e0b |
+ mode_info.number_of_colors = 256;
|
|
|
f96e0b |
|
|
|
f96e0b |
- framebuffer.mode_info.mode_type = GRUB_VIDEO_MODE_TYPE_INDEX_COLOR;
|
|
|
f96e0b |
- framebuffer.mode_info.bpp = 8;
|
|
|
f96e0b |
- framebuffer.mode_info.bytes_per_pixel = 1;
|
|
|
f96e0b |
- framebuffer.mode_info.number_of_colors = 256;
|
|
|
f96e0b |
-
|
|
|
f96e0b |
- framebuffer.mode_info.blit_format = grub_video_get_blit_format (&framebuffer.mode_info);
|
|
|
f96e0b |
-
|
|
|
f96e0b |
- /* For some reason sparc64 uses 32-bit pointer too. */
|
|
|
f96e0b |
- framebuffer.ptr = xmalloc (height * width);
|
|
|
f96e0b |
-
|
|
|
f96e0b |
- grub_video_fb_create_render_target_from_pointer (&framebuffer.render_target,
|
|
|
f96e0b |
- &framebuffer.mode_info,
|
|
|
f96e0b |
- framebuffer.ptr);
|
|
|
f96e0b |
- grub_video_fb_set_active_render_target (framebuffer.render_target);
|
|
|
f96e0b |
- grub_video_fb_set_palette (0, ARRAY_SIZE (ieee1275_palette),
|
|
|
f96e0b |
- ieee1275_palette);
|
|
|
f96e0b |
-
|
|
|
f96e0b |
- grub_video_set_adapter (&grub_video_text_render_adapter);
|
|
|
f96e0b |
+ grub_video_capture_start (&mode_info, ieee1275_palette,
|
|
|
f96e0b |
+ ARRAY_SIZE (ieee1275_palette));
|
|
|
f96e0b |
|
|
|
f96e0b |
fg = grub_video_map_rgb (arguments.fgcolor.red,
|
|
|
f96e0b |
arguments.fgcolor.green,
|
|
|
f96e0b |
@@ -374,18 +306,17 @@ main (int argc, char *argv[])
|
|
|
f96e0b |
arguments.bgcolor.green,
|
|
|
f96e0b |
arguments.bgcolor.blue);
|
|
|
f96e0b |
|
|
|
f96e0b |
- grub_memset (framebuffer.ptr, bg, height * width);
|
|
|
f96e0b |
+ grub_memset (grub_video_capture_get_framebuffer (), bg, height * width);
|
|
|
f96e0b |
grub_font_draw_string (text, font, fg,
|
|
|
f96e0b |
5, grub_font_get_ascent (font));
|
|
|
f96e0b |
|
|
|
f96e0b |
- grub_video_set_adapter (0);
|
|
|
f96e0b |
-
|
|
|
f96e0b |
head.magic = 1;
|
|
|
f96e0b |
head.width = grub_cpu_to_be16 (width);
|
|
|
f96e0b |
head.height = grub_cpu_to_be16 (height);
|
|
|
f96e0b |
fwrite (&head, 1, sizeof (head), out);
|
|
|
f96e0b |
- fwrite (framebuffer.ptr, 1, width * height, out);
|
|
|
f96e0b |
+ fwrite (grub_video_capture_get_framebuffer (), 1, width * height, out);
|
|
|
f96e0b |
|
|
|
f96e0b |
+ grub_video_capture_end ();
|
|
|
f96e0b |
if (out != stdout)
|
|
|
f96e0b |
fclose (out);
|
|
|
f96e0b |
|
|
|
f96e0b |
--
|
|
|
f96e0b |
1.8.2.1
|
|
|
f96e0b |
|