Skip to content

Commit 18b04e2

Browse files
committed
requestAnimationFrame
1 parent 54c2ded commit 18b04e2

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/browser/html/window.zig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,23 @@ pub const Window = struct {
138138
return &self.performance;
139139
}
140140

141+
// Tells the browser you wish to perform an animation. It requests the browser to call a user-supplied callback function before the next repaint.
142+
// fn callback(timestamp: f64)
143+
// Returns the request ID, that uniquely identifies the entry in the callback list.
144+
pub fn _requestAnimationFrame(
145+
self: *Window,
146+
callback: Callback,
147+
) !u32 {
148+
// We immediately execute the callback, but this may not be correct TBD.
149+
// Since: When multiple callbacks queued by requestAnimationFrame() begin to fire in a single frame, each receives the same timestamp even though time has passed during the computation of every previous callback's workload.
150+
var result: Callback.Result = undefined;
151+
callback.tryCall(.{self.performance._now()}, &result) catch {
152+
log.err("Window.requestAnimationFrame(): {s}", .{result.exception});
153+
log.debug("stack:\n{s}", .{result.stack orelse "???"});
154+
};
155+
return 99; // not unique, but user cannot make assumptions about it. cancelAnimationFrame will be too late anyway.
156+
}
157+
141158
// TODO handle callback arguments.
142159
pub fn _setTimeout(self: *Window, cbk: Callback, delay: ?u32, state: *SessionState) !u32 {
143160
return self.createTimeout(cbk, delay, state, false);

0 commit comments

Comments
 (0)