This repository has been archived on 2026-10-10. You can view files and clone it, but cannot push or open issues or pull requests.
molotov/crates/molotov-core/tests/graphics_surface_test.rs

38 lines
1.6 KiB
Rust

// SPDX-License-Identifier: GPL-3.0-or-later
use molotov_core::graphics::c_api::*;
use molotov_core::graphics::surface::GraphicsSurface;
use molotov_core::graphics::types::{ANativeWindow_Buffer, WindowFormat};
use molotov_core::jni::activity::ActivityRunner;
use std::sync::Arc;
#[test]
fn test_end_to_end_graphics_surface_and_activity_binding() {
let mut runner = ActivityRunner::new();
let surface = Arc::new(GraphicsSurface::new(1280, 720, WindowFormat::Rgba8888));
let window_handle = register_window_surface(surface);
unsafe {
// 1. Notify activity that native window was created
runner.trigger_window_created(window_handle as *mut _);
// 2. Engine queries window geometry
assert_eq!(ANativeWindow_getWidth(window_handle), 1280);
assert_eq!(ANativeWindow_getHeight(window_handle), 720);
// 3. Engine renders frame
let mut buf = std::mem::MaybeUninit::<ANativeWindow_Buffer>::uninit();
assert_eq!(ANativeWindow_lock(window_handle, buf.as_mut_ptr(), std::ptr::null_mut()), 0);
let buffer = buf.assume_init();
// Write solid color into buffer (RGBA = 255, 0, 0, 255)
let pixel_count = (buffer.width * buffer.height) as usize;
let pixels = std::slice::from_raw_parts_mut(buffer.bits as *mut u32, pixel_count);
pixels.fill(0xff00_00ff);
assert_eq!(ANativeWindow_unlockAndPost(window_handle), 0);
// 4. Notify activity on window destroy
runner.trigger_window_destroyed(window_handle as *mut _);
ANativeWindow_release(window_handle);
}
}