Skip to content

Is Context needed for anything other than performance? #306

Description

@madsmtm

I've read #37 and #64, and from my understanding, the split between Context and Surface is purely for performance, to allow sharing resources that are expensive to create.

Is that correct?

If so, then I feel it might make sense to add a convenience wrapper like:

impl<W: HasDisplayHandle + HasWindowHandle> Surface<W, W> {
    pub fn new_single_window_bikeshed(window: W) -> Result<Self, CreationError> {
        // Conceptual implementation, needs to be done differently in reality
        // since the window needs to only be stored in the surface.
        let context = Context::new(window);
        Self::new(&context, window)
    }
}

And perhaps change Surface to be something like struct Surface<D, W = D> (make the two type parameters default to be the same type).

This would simplify the common use-case of having a single window to be:

struct App {
    surface: softbuffer::Surface<winit::Window>,
    // + possibly an `Option` if you want to support Android too.
}

While still allowing the more complex multi-window case:

struct App {
    context: softbuffer::Context<winit::OwnedDisplayHandle>,
    surfaces: Vec<softbuffer::Surface<winit::OwnedDisplayHandle, winit::Window>>,
}

See relatedly #298.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions