-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat(core): add Deck#waitForFrameReady() Promise API #10362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
akre54
wants to merge
1
commit into
visgl:master
Choose a base branch
from
akre54:frame-ready-api
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -690,6 +690,43 @@ Parameters: | |
| * `force` (boolean) - if `false`, only redraw if necessary (e.g. changes have been made to views or layers). If `true`, skip the check. Default `false`. | ||
|
|
||
|
|
||
| #### `waitForFrameReady` {#waitforframeready} | ||
|
|
||
| Wait until all pending updates have settled and a frame has been rendered. Useful for headless capture, video export, or any flow that needs to read back canvas pixels and must know that the next read will reflect a fully-settled scene. | ||
|
|
||
| The returned Promise resolves once: | ||
|
|
||
| * All layers report `layer.isLoaded === true` (no pending async props or resources) | ||
| * The layer manager has no pending updates (`needsUpdate() === false`) | ||
| * No redraw is queued (`needsRedraw() === false`) | ||
| * If the scene was not already settled, an `onAfterRender` cycle has completed since the call started | ||
|
|
||
| If the deadline passes before the scene settles, the Promise rejects with an `Error`. | ||
|
|
||
| ```ts | ||
| const result = await deck.waitForFrameReady({timeout: 5000}); | ||
| // result: {layersReady: boolean, attributesReady: boolean, duration: number} | ||
| ``` | ||
|
|
||
| Parameters: | ||
|
|
||
| * `options.timeout` (number, optional) - maximum wait time in milliseconds before the Promise rejects. Default `5000`. | ||
| * `options.checkLayers` (boolean, optional) - if `false`, skip the per-layer `isLoaded` check. Default `true`. | ||
| * `options.checkAttributes` (boolean, optional) - if `false`, skip the layer-manager `needsUpdate` check. Default `true`. | ||
|
|
||
| Returns: | ||
|
|
||
| * A Promise that resolves with an object describing the final state: | ||
| + `layersReady` (boolean) - whether all layers reported loaded | ||
| + `attributesReady` (boolean) - whether the attribute manager reported settled | ||
| + `duration` (number) - elapsed time in milliseconds | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do the majority of applications need |
||
|
|
||
| Notes: | ||
|
|
||
| * `waitForFrameReady` does not force a redraw on its own. If you need to ensure a render happens, call `setProps`, mutate `layers`, or call `redraw('forced')` before/while awaiting. | ||
| * The implementation chains its own `onAfterRender` handler over the user-provided one and restores the original handler before resolving or rejecting. | ||
|
|
||
|
|
||
| #### `pickObjectAsync` {#pickobjectasync} | ||
|
|
||
| Get the closest pickable and visible object at the given screen coordinate. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good pattern, but I don't see why this needs to be a part of deck's API.
Wouldn't a utility function with deck as a parameter be just as effective?