@@ -12,6 +12,15 @@ const displayBackend = phantom.display.Backend(displayBackendType);
1212const sceneBackendType : phantom.scene.BackendType = @enumFromInt (@intFromEnum (options .scene_backend ));
1313const sceneBackend = phantom .scene .Backend (sceneBackendType );
1414
15+ fn simpleTextOutputWrite (sto : * std.os.uefi.protocol.SimpleTextOutput , buf : []const u8 ) ! usize {
16+ const buf16 = try std .unicode .utf8ToUtf16LeWithNull (alloc , buf );
17+ defer alloc .free (buf16 );
18+ try sto .outputString (buf16 ).err ();
19+ return buf .len ;
20+ }
21+
22+ const SimpleTextOutputWriter = std .io .Writer (* std .os .uefi .protocol .SimpleTextOutput , std .os .uefi .Status .EfiError || std .mem .Allocator .Error || error {InvalidUtf8 }, simpleTextOutputWrite );
23+
1524pub fn main () void {
1625 var display = displayBackend .Display .init (alloc , .compositor );
1726 defer display .deinit ();
@@ -58,11 +67,27 @@ pub fn main() void {
5867 .source = image .buffer (0 ) catch | e | @panic (@errorName (e )),
5968 }) catch | e | @panic (@errorName (e ));
6069
70+ const stderr = if (builtin .os .tag == .uefi ) SimpleTextOutputWriter {
71+ .context = std .os .uefi .system_table .std_err .? ,
72+ } else std .os .getStdErr ().writer ();
73+
74+ var prevTime = std .time .milliTimestamp ();
6175 while (true ) {
76+ const currTime = std .time .milliTimestamp ();
77+ const deltaTime = currTime - prevTime ;
78+ _ = stderr .print ("FPS: {} (Delta time: {}, Prev: {}, Curr: {})\n " , .{
79+ 60 / @max (deltaTime , 1 ),
80+ deltaTime ,
81+ prevTime ,
82+ currTime ,
83+ }) catch {};
84+
6285 _ = scene .frame (fb ) catch | e | @panic (@errorName (e ));
6386
6487 fb .setProperties (.{
6588 .source = image .buffer (scene .seq % image .info ().seqCount ) catch | e | @panic (@errorName (e )),
6689 }) catch | e | @panic (@errorName (e ));
90+
91+ prevTime = currTime ;
6792 }
6893}
0 commit comments