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

Make flutter engine independent of GLFW #90

Merged
merged 32 commits into from Dec 17, 2019
Merged

Make flutter engine independent of GLFW #90

merged 32 commits into from Dec 17, 2019

Conversation

csnewman
Copy link
Member

@csnewman csnewman commented Dec 8, 2019

As a follow up to #88, I propose refactoring the library into:

flutter-engine-sys: the ffi code
flutter-engine: codec, channels, pointer events, tasks etc (i.e. wrapper around sys crate)
flutter-engine-plugins: text-input etc, each plugin could be a feature flag
flutter-engine-glfw: current logic around glfw rendering

This means that the flutter-engine crate is no longer dependent on opengl etc, or glfw, and can be used as an independent library in the following manor:

struct MyHandler {

}

impl FlutterEngineHandler for MyHandler {
    fn swap_buffers(&self) -> bool {
        unimplemented!()
    }

    fn make_current(&self) -> bool {
        unimplemented!()
    }

    fn clear_current(&self) -> bool {
        unimplemented!()
    }

    fn fbo_callback(&self) -> u32 {
        unimplemented!()
    }

    fn make_resource_current(&self) -> bool {
        unimplemented!()
    }

    fn gl_proc_resolver(&self, proc: *const i8) -> *mut c_void {
        unimplemented!()
    }

    fn wake_platform_thread(&self) {
        unimplemented!()
    }

    fn run_in_background(&self,  func: Box<dyn Future<Output = ()> + Send + 'static>) {
        unimplemented!()
    }

    fn get_texture_frame(
        &self,
        texture_id: i64,
        size: (usize, usize),
    ) -> Option<ExternalTextureFrame> {
        unimplemented!()
    }
}
// Handler is called by the engine on different threads to handle embedder specific tasks
let handler = Arc::new(MyHandler);
let engine = FlutterEngine::new(Arc::downgrade(&handler) as _);

// Add plugins (plugins can registered before the engine starts)
engine.add_plugin(KeyEventPlugin::default());

// Start engine
engine.run(assets_path, icu_data_path, arguments).expect("Failed to create engine");

// In some sort of loop, you can call execute_platform_tasks, which will give the time you should sleep to for the next task
let next_task_time = engine.execute_platform_tasks();

If in the future flutter gets alternative renderers, such as Vulkan, we can break down the FlutterEngineHandler into multiple traits, or use a feature flag.

TaskRunner are now an independent concept, meaning if flutter adds extra task runners in the future, the logic should be reusable.

@csnewman
Copy link
Member Author

csnewman commented Dec 8, 2019

@gliheng Any thoughts on the current state?

@gliheng
Copy link
Collaborator

gliheng commented Dec 12, 2019

LGTM. dvc94ch is working on winit port. I fear you guys work may conflict somehow.

@csnewman
Copy link
Member Author

csnewman commented Dec 12, 2019

I can get this PR finished over the next few days, and then it's probably best for @dvc94ch to refactor his changes, then we can keep both the current GLFW code and the new winit renderer (incase people have some very specific reason for using GLFW)

@dvc94ch
Copy link
Member

dvc94ch commented Dec 12, 2019

This makes things easier, I can refactor my changes...

@dvc94ch
Copy link
Member

dvc94ch commented Dec 16, 2019

@csnewman I opened a PR against your branch with some improvements.

Things that still are missing:

  • fix window plugin (and update flutter-app-demo)
  • texture loading using a shared opengl context in flutter-glfw

@csnewman
Copy link
Member Author

@dvc94ch Thanks for that. I've added a small comment. Otherwise looks great.

I have mostly rewrote the window plugin, just need to push it. And the texture loader should be easy enough for me to finish off today.

@csnewman csnewman changed the title [WIP] Make flutter engine independent of GLFW Make flutter engine independent of GLFW Dec 16, 2019
@csnewman
Copy link
Member Author

@gliheng The refactor is now complete. Everything seems to be working as it was before.

I plan on a few follow up PRs with updating to the latest flutter engine features.

@gliheng gliheng merged commit 4f5c58c into flutter-rs:master Dec 17, 2019
@gliheng
Copy link
Collaborator

gliheng commented Dec 17, 2019

That's a huge refactor. Thanks for your great work!

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

Successfully merging this pull request may close these issues.

None yet

3 participants