Skip to content
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

Refactor epi::Frame #673

Closed
emilk opened this issue Aug 28, 2021 · 1 comment · Fixed by #999
Closed

Refactor epi::Frame #673

emilk opened this issue Aug 28, 2021 · 1 comment · Fixed by #999
Labels
eframe Relates to epi and eframe

Comments

@emilk
Copy link
Owner

emilk commented Aug 28, 2021

epi::Frame contains methods for controlling the surrounding app (i.e. the native winit window or the web browser). At the moment this includes allocating texture, quitting and changing the window size. We may soon also be able to toggle decorations, toggle fullscreen and request user attention.

At the moment Frame is only available in App::update which means you cannot call this methods from a separate thread.

I think it would be useful if we could change App::update (and App::setup) from taking a &Frame<'_> to taking a &Arc<Frame>. A user could clone this Arc and send to a background thread. This would allow users to e.g. start HTTP requests, and when finished request user attention, allocate a texture, or similar.

Perhaps we want something like struct FrameRef(Arc<Frame>) or FrameRef(Arc<Mutex<Frame>>) to encapsulate this in a nicer way (similar to egui::CtxRef vs egui::Context).

We could then replace the current repaint_signal with just a normal call (frame.request_repaint();, perhaps more appropriately named request_update).

@emilk emilk added the eframe Relates to epi and eframe label Aug 28, 2021
@emilk emilk mentioned this issue Sep 20, 2021
@cessen
Copy link

cessen commented Oct 31, 2021

Just want to drop a note here that I would find this especially useful with the applications I'm writing. I go out of my way to make sure that any long-running jobs aren't on the same thread as the GUI, but often these are jobs computing or updating raster images to display.

Currently I kind-of-sort-of work around this by having those long-running image processing jobs (taking tens of seconds in my case) mark the image as "ready" for a texture update when they're done, on a thread-safe bool variable. Then the GUI code checks that variable on every update, and transfers the image to a texture when true.

It works okay, since the long-running work happens on another thread. But even just transferring the image data to a texture takes a small bit of time (these are very high-res images) and makes the gui hiccup whenever it happens.

Being able to allocate textures from other threads would both simplify the code a lot and eliminate the hiccups.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
eframe Relates to epi and eframe
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants