Reduce amount of data being cloned in begin_frame

This commit is contained in:
Emil Ernerfeldt 2021-04-01 22:09:58 +02:00
parent 44869a6718
commit d702e3078a

View file

@ -307,6 +307,11 @@ impl CtxRef {
/// but you are likely the first person to try it. /// but you are likely the first person to try it.
#[derive(Default)] #[derive(Default)]
pub struct Context { pub struct Context {
// We clone the Context each frame so we can set a new `input`.
// This is so we can avoid a mutex lock to access the `InputState`.
// This means everything else needs to be behind an Arc.
// We can probably come up with a nicer design.
//
/// None until first call to `begin_frame`. /// None until first call to `begin_frame`.
fonts: Option<Arc<Fonts>>, fonts: Option<Arc<Fonts>>,
memory: Arc<Mutex<Memory>>, memory: Arc<Mutex<Memory>>,
@ -315,13 +320,13 @@ pub struct Context {
input: InputState, input: InputState,
/// State that is collected during a frame and then cleared /// State that is collected during a frame and then cleared
frame_state: Mutex<FrameState>, frame_state: Arc<Mutex<FrameState>>,
// The output of a frame: // The output of a frame:
graphics: Mutex<GraphicLayers>, graphics: Arc<Mutex<GraphicLayers>>,
output: Mutex<Output>, output: Arc<Mutex<Output>>,
paint_stats: Mutex<PaintStats>, paint_stats: Arc<Mutex<PaintStats>>,
/// While positive, keep requesting repaints. Decrement at the end of each frame. /// While positive, keep requesting repaints. Decrement at the end of each frame.
repaint_requests: AtomicU32, repaint_requests: AtomicU32,