summaryrefslogtreecommitdiff
path: root/graphics.c
diff options
context:
space:
mode:
authorMitya Selivanov <automainint@guattari.tech>2025-01-18 03:58:23 +0100
committerMitya Selivanov <automainint@guattari.tech>2025-01-18 03:58:23 +0100
commita7070a52f3f32a24822ddd9bf0efebc4272661ab (patch)
treeb46528f7d5604a955aa5782f2cb86069e4bd4c88 /graphics.c
parent43585fc93cd5e682777829f088d825ee13404d60 (diff)
downloadreduced_system_layer-a7070a52f3f32a24822ddd9bf0efebc4272661ab.zip
Add graphics benchmarks
Diffstat (limited to 'graphics.c')
-rwxr-xr-x[-rw-r--r--]graphics.c148
1 files changed, 140 insertions, 8 deletions
diff --git a/graphics.c b/graphics.c
index 1650d32..bc49267 100644..100755
--- a/graphics.c
+++ b/graphics.c
@@ -1,13 +1,42 @@
-// ================================================================
-//
-// graphics.c
-//
-// ----------------------------------------------------------------
-//
-// (C) 2025 Mitya Selivanov <guattari.tech>
-//
+#if 0 /*
+#/ ================================================================
+#/
+#/ graphics.c
+#/
+#/ ----------------------------------------------------------------
+#/
+#/ (C) 2025 Mitya Selivanov <guattari.tech>
+#/
+#/ ================================================================
+#/
+#/ Self-testing shell script
+#/
+#/ ================================================================
+SRC=${0##*./}
+BIN=${SRC%.*}
+gcc \
+ -Wall -Wextra -Werror -pedantic \
+ -Wno-old-style-declaration \
+ -Wno-missing-braces \
+ -Wno-unused-variable \
+ -Wno-unused-but-set-variable \
+ -Wno-unused-parameter \
+ -Wno-overlength-strings \
+ -O3 -D NDEBUG \
+ -D GRAPHICS_TEST_SUITE \
+ -lX11 -lm -lasound \
+ -o $BIN $SRC && \
+ ./$BIN $@
+STATUS=$?
+rm -f $BIN
+exit $? # */
+#endif
// ================================================================
+#ifdef EVERY_TEST_SUITE
+#define GRAPHICS_TEST_SUITE
+#endif
+
#ifndef GRAPHICS_HEADER_GUARD_
#define GRAPHICS_HEADER_GUARD_
@@ -1449,5 +1478,108 @@ void draw_text_cursor(Brush brush, f64 x, f64 y, f64 width, f64 height, f64 max_
);
}
+// ================================================================
+//
+// Test suite
+//
+// ================================================================
+
+#ifdef GRAPHICS_TEST_SUITE
+
+#define TEST_FILE graphics
+#include "test.c"
+
+vec4_f32 g_pixels[MAX_NUM_PIXELS] = {0};
+
+Brush brush = {
+ .buffer = {
+ .width = 1280,
+ .height = 720,
+ .line_size = 1280,
+ .pixels = g_pixels,
+ },
+ .position = { 0.f, 0.f, },
+ .scale = { 1.f, 1.f, },
+ .color = { 1.f, 1.f, 1.f, 1.f },
+};
+
+BENCHMARK("fill rectangle") {
+ BENCHMARK_BEGIN;
+ {
+ fill_rectangle(brush, 100, 100, 300, 200);
+ }
+ BENCHMARK_END;
+
+ for (i64 i = 0; i < MAX_NUM_PIXELS; ++i)
+ g_pixels[i] = (vec4_f32) {0};
+}
+
+BENCHMARK("fill triangle") {
+ BENCHMARK_BEGIN;
+ {
+ fill_triangle(brush, 100, 100, 300, 100, 200, 250);
+ }
+ BENCHMARK_END;
+
+ for (i64 i = 0; i < MAX_NUM_PIXELS; ++i)
+ g_pixels[i] = (vec4_f32) {0};
+}
+
+BENCHMARK("fill quad") {
+ BENCHMARK_BEGIN;
+ {
+ fill_quad(brush, 100, 100, 300, 100, 300, 200, 100, 200);
+ }
+ BENCHMARK_END;
+
+ for (i64 i = 0; i < MAX_NUM_PIXELS; ++i)
+ g_pixels[i] = (vec4_f32) {0};
+}
+
+BENCHMARK("fill ellipse") {
+ BENCHMARK_BEGIN;
+ {
+ fill_ellipse(brush, 80, 80, 340, 240);
+ }
+ BENCHMARK_END;
+
+ for (i64 i = 0; i < MAX_NUM_PIXELS; ++i)
+ g_pixels[i] = (vec4_f32) {0};
+}
+
+BENCHMARK("fill line") {
+ BENCHMARK_BEGIN;
+ {
+ fill_line(brush, 100, 100, 300, 200, 40);
+ }
+ BENCHMARK_END;
+
+ for (i64 i = 0; i < MAX_NUM_PIXELS; ++i)
+ g_pixels[i] = (vec4_f32) {0};
+}
+
+BENCHMARK("draw text area") {
+ BENCHMARK_BEGIN;
+ {
+ c32 text[] = { 'H', 'e', 'l', 'l', 'o', ',', ' ', 'S', 'a', 'i', 'l', 'o', 'r', '!', };
+ draw_text_area(brush, 100, 100, 300, 200, 100, 200, sizeof text / sizeof *text, text);
+ }
+ BENCHMARK_END;
+
+ for (i64 i = 0; i < MAX_NUM_PIXELS; ++i)
+ g_pixels[i] = (vec4_f32) {0};
+}
+
+void update_and_render_frame(void) {}
+
+i32 main(i32 argc, c8 **argv) {
+ return run_tests_and_benchmarks(argc, argv);
+}
+
+#undef TEST_FILE
+#endif // GRAPHICS_TEST_SUITE
+
+// ================================================================
+
#endif // GRAPHICS_IMPL_GUARD_
#endif // GRAPHICS_HEADER