diff options
author | Mitya Selivanov <automainint@guattari.tech> | 2025-01-23 13:23:23 +0100 |
---|---|---|
committer | Mitya Selivanov <automainint@guattari.tech> | 2025-01-23 13:23:23 +0100 |
commit | 600df042f89ab4d3ce72b84c83ca4134d69f67bf (patch) | |
tree | 9d2618926eb85aacba5384b1640a02abe9fc8f3e | |
parent | 6ec822ee73734aafa598c642e91fb2194792397b (diff) | |
download | reduced_system_layer-600df042f89ab4d3ce72b84c83ca4134d69f67bf.zip |
Cleanup
-rwxr-xr-x | graphics.c | 91 | ||||
-rw-r--r-- | reduced_system_layer.c | 33 |
2 files changed, 65 insertions, 59 deletions
@@ -41,6 +41,7 @@ exit $? # */ #define REDUCED_SYSTEM_LAYER_HEADER #endif +#define NO_WAYLAND 1 #include "reduced_system_layer.c" // ================================================================ @@ -217,6 +218,10 @@ enum { CHAR_NUM_BITS_ = CHAR_NUM_BITS_X_ * CHAR_NUM_BITS_Y_, }; +static f32 max2_f32_(f32 a, f32 b) { + return a < b ? b : a; +} + static f64 min3_(f64 a, f64 b, f64 c) { if (a < b && a < c) return a; @@ -233,26 +238,6 @@ static f64 max3_(f64 a, f64 b, f64 c) { return c; } -static f64 min4_(f64 a, f64 b, f64 c, f64 d) { - if (a < b && a < c && a < d) - return a; - if (b < c && b < d) - return b; - if (c < d) - return c; - return d; -} - -static f64 max4_(f64 a, f64 b, f64 c, f64 d) { - if (a > b && a > c && a > d) - return a; - if (b > c && b > d) - return b; - if (c > d) - return c; - return d; -} - static b8 same_sign_(f64 a, f64 b) { if (a >= EPSILON && b <= -EPSILON) return 0; if (a <= -EPSILON && b >= EPSILON) return 0; @@ -274,15 +259,19 @@ static f64 gamma_re_(f64 x) { static void put_pixel_alpha_(Pixel_Buffer dst, vec4_f32 color, i64 x, i64 y) { i64 n = y * dst.stride + x; - vec4_f32 dst_color = dst.pixels[n]; - f64 a = color.w; - - dst.pixels[n] = (vec4_f32) { - .x = (f32) (dst_color.x * (1. - a) + color.x * a), - .y = (f32) (dst_color.y * (1. - a) + color.y * a), - .z = (f32) (dst_color.z * (1. - a) + color.z * a), - .w = 1., - }; + if (color.w == 1.f) + dst.pixels[n] = color; + else { + vec4_f32 dst_color = dst.pixels[n]; + f32 dst_amount = 1. - color.w; + + dst.pixels[n] = (vec4_f32) { + .x = dst_color.x * dst_amount + color.x * color.w, + .y = dst_color.y * dst_amount + color.y * color.w, + .z = dst_color.z * dst_amount + color.z * color.w, + .w = max2_f32_(dst_color.w, color.w), + }; + } } void draw_pixels_raw(Pixel_Buffer dst, f64 x0, f64 y0, f64 w, f64 h, Pixel_Buffer src) { @@ -442,6 +431,8 @@ void fill_triangle_raw(Pixel_Buffer dst, vec4_f32 color, f64 x0, f64 y0, f64 x1, if (j1 >= dst.height) j1 = dst.height - 1; for (i64 j = j0; j <= j1; ++j) { + // FIXME, PERF: Calculate the exact intersection. + i64 left = i1; i64 right = i0; @@ -474,6 +465,8 @@ void fill_quad_raw(Pixel_Buffer dst, vec4_f32 color, f64 x0, f64 y0, f64 x1, f64 if (j1 >= dst.height) j1 = dst.height - 1; for (i64 j = j0; j <= j1; ++j) { + // FIXME, PERF: Calculate the exact intersection. + i64 left = i1; i64 right = i0; @@ -495,33 +488,33 @@ void fill_quad_raw(Pixel_Buffer dst, vec4_f32 color, f64 x0, f64 y0, f64 x1, f64 } void fill_ellipse_raw(Pixel_Buffer dst, vec4_f32 color, f64 x0, f64 y0, f64 w, f64 h) { - f64 x1 = x0 + w; f64 y1 = y0 + h; - i64 i0 = (i64) floor(x0); - i64 i1 = (i64) ceil (x1); i64 j0 = (i64) floor(y0); i64 j1 = (i64) ceil (y1); if (j0 < 0) j0 = 0; if (j1 >= dst.height) j1 = dst.height - 1; + f64 half_w = w / 2.0; + f64 half_h = h / 2.0; + + if (half_h < EPSILON) + return; + f64 inv_half_h = 1.0 / half_h; + + f64 cx = x0 + half_w; + f64 cy = y0 + half_h; + for (i64 j = j0; j <= j1; ++j) { - i64 left = i1; - i64 right = i0; + f64 ry = (j - cy) * inv_half_h; + if (ry > 1.0 - EPSILON || ry < -1.0 + EPSILON) + continue; - for (i64 i = i0; i <= i1; ++i) - if (ellipse_contains(x0, y0, x1 - x0, y1 - y0, (f64) i, (f64) j)) { - left = i; - right = (i64) ceil(x0 + x1 - left); // symmetry - break; - } + f64 dx = half_w * sqrt(1.0 - ry * ry); - for (i64 i = right; i >= i0; --i) - if (ellipse_contains(x0, y0, x1 - x0, y1 - y0, (f64) i, (f64) j)) { - right = i; - break; - } + i64 left = (i64) ceil (cx - dx - EPSILON); + i64 right = (i64) floor(cx + dx + EPSILON); if (left < 0) left = 0; if (right >= dst.width) right = dst.width - 1; @@ -1164,9 +1157,7 @@ b8 line_contains(f64 x0, f64 y0, f64 x1, f64 y1, f64 width, f64 px, f64 py) { tx *= width * .5; ty *= width * .5; - return - triangle_contains(x0 - tx, y0 - ty, x0 + tx, y0 + ty, x1 + tx, y1 + ty, px, py) - || triangle_contains(x0 - tx, y0 - ty, x1 + tx, y1 + ty, x1 - tx, y1 - ty, px, py); + return quad_contains(x0 - tx, y0 - ty, x0 + tx, y0 + ty, x1 + tx, y1 + ty, x1 - tx, y1 - ty, px, py); } // ================================================================ @@ -1326,8 +1317,8 @@ Gx_Request gx_scaled_(Gx_Request req, vec2 scale) { scaled.quad.vertices[1].y *= scale.y; scaled.quad.vertices[2].x *= scale.x; scaled.quad.vertices[2].y *= scale.y; - scaled.quad.vertices[4].x *= scale.x; - scaled.quad.vertices[4].y *= scale.y; + scaled.quad.vertices[3].x *= scale.x; + scaled.quad.vertices[3].y *= scale.y; break; case OP_ELLIPSE: diff --git a/reduced_system_layer.c b/reduced_system_layer.c index c945ed1..055cd3a 100644 --- a/reduced_system_layer.c +++ b/reduced_system_layer.c @@ -792,6 +792,14 @@ static u32 rgb_u32_from_f32_(vec3_f32 c) { return (r << 16) | (g << 8) | b; } +static vec3_f32 rgb_f32_from_u32_(u32 c) { + return (vec3_f32) { + .x = ((c >> 16) & 0xff) / 255.f, + .y = ((c >> 8) & 0xff) / 255.f, + .z = ( c & 0xff) / 255.f, + }; +} + static i64 average_frame_duration_(i64 duration) { _frame_duration[_frame_index] = duration; _frame_index = (_frame_index + 1) % NUM_FRAMES_AVERAGED; @@ -1767,6 +1775,8 @@ static void screencopy_frame_handle_flags( void *frame, u32 flags ) { + (void) frame; + WL_Output_ *output = data; output->screencopy_frame_flags = flags; } @@ -1778,6 +1788,11 @@ static void screencopy_frame_handle_ready( u32 tv_sec_lo, u32 tv_nsec ) { + (void) frame; + (void) tv_sec_hi; + (void) tv_sec_lo; + (void) tv_nsec; + WL_Output_ *output = data; ++output->state->n_done; } @@ -1786,6 +1801,8 @@ static void screencopy_frame_handle_failed( void *data, void *frame ) { + (void) frame; + WL_Output_ *output = data; output->state->ok = 0; LOG_ERROR("Screenshot copy failed."); @@ -1831,7 +1848,11 @@ static void handle_global( ); } -static void handle_global_remove(void *data, struct wl_registry *registry, u32 name) { } +static void handle_global_remove(void *data, struct wl_registry *registry, u32 name) { + (void) data; + (void) registry; + (void) name; +} static struct wl_registry_listener _wayland_registry_listener = { .global = handle_global, @@ -1854,14 +1875,6 @@ b8 check_format_(i32 format) { return 0; } -static vec3_f32 rgb_f32_from_u32_(u32 c) { - return (vec3_f32) { - .x = ((c >> 16) & 0xff) / 255.f, - .y = ((c >> 8) & 0xff) / 255.f, - .z = ( c & 0xff) / 255.f, - }; -} - b8 wayland_screenshot_(i64 max_num_pixels, i64 *width, i64 *height, vec4_f32 *pixels) { b8 ok = 0; @@ -3140,6 +3153,8 @@ void p_sleep_for(i64 duration) { } void p_init(void) { + (void) rgb_f32_from_u32_; + ++_num_events; g_platform.done = 1; |