/* A complete CPU-rendered window. Build instructions: docs/getting-started.md. */ #include #include static bool failed; static void draw(void *ud, struct yasl_surface *surface, struct yasl_frame_context *frame) { (void)ud; int w = frame->size.x, h = frame->size.y; for (int y = 0; y < h; y++) { uint32_t *row = frame->cpu.pixels + (size_t)y * (frame->cpu.stride_bytes / 4); for (int x = 0; x < w; x++) { /* Red grows rightward, green downward, blue fades; opaque premultiplied ARGB. */ uint32_t r = (uint32_t)(x * 255 / (w > 1 ? w - 1 : 1)); uint32_t g = (uint32_t)(y * 255 / (h > 1 ? h - 1 : 1)); row[x] = 0xff000000 | r << 16 | g << 8 | (255 - r); } } if (!yasl_frame_present_cpu(frame, NULL, 0)) { fprintf(stderr, "Could not present the draw target\n"); failed = true; } if (failed) yasl_surface_destroy(surface); } int main(void) { struct yasl_window_spec window = {.title = "Hello YASL", .size = {640, 480}}; struct yasl_app_desc desc = { .app_id = "org.example.hello", .window = &window, .frame = draw, }; int result = yasl_run(&desc); if (result) fprintf(stderr, "Could not run the application\n"); return result || failed ? 1 : 0; }