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

[libsimpleservo port] Support OpenGL #21305

Open
paulrouget opened this issue Aug 1, 2018 · 2 comments
Open

[libsimpleservo port] Support OpenGL #21305

paulrouget opened this issue Aug 1, 2018 · 2 comments

Comments

@paulrouget
Copy link
Contributor

@paulrouget paulrouget commented Aug 1, 2018

#20912 followup

As of now, libsimpleservo only supports GLES. There is no reason to not also support OpenGL. This could be interesting if we ever want the regular port to rely on libsimpleservo.

@Hyperion101010
Copy link
Contributor

@Hyperion101010 Hyperion101010 commented Jan 30, 2019

I am interested to build projects in Rust !
Comparatively i am new to Rust, but i did some projects in Python and C++.If i get some guidance/mentor it'll helpful .So what are pre-req for solving this bug.I would like to work on it .

@paulrouget
Copy link
Contributor Author

@paulrouget paulrouget commented Jan 30, 2019

Unless you're familiar with cross platform OpenGL, I'm not sure it's an easy project :) But it's totally doable:

See the unimplemented section in

// FIXME: Add an OpenGL version

I see 2 possible approaches:

full callback implementation

Implement gl::init for Mac, Linux and Windows.

I've been toying with this in the past and came up with something like this for MacOS:

#[cfg(target_os = "macos")]
pub mod gl {
    use servo::gl;
    use std::os::raw::c_void;
    use std::rc::Rc;
    use std::str;
    use core_foundation::base::TCFType;
    use core_foundation::string::CFString;
    use core_foundation::bundle::{CFBundleGetBundleWithIdentifier, CFBundleGetFunctionPointerForName};

    #[cfg(target_os = "macos")]
    pub fn init() -> Rc<gl::Gl> {
        info!("init_gl");
        unsafe {
            gl::GlFns::load_with(|addr| {
                let symbol_name: CFString = str::FromStr::from_str(addr).unwrap();
                let framework_name: CFString = str::FromStr::from_str("com.apple.opengl").unwrap();
                let framework = CFBundleGetBundleWithIdentifier(framework_name.as_concrete_TypeRef());
                let symbol = CFBundleGetFunctionPointerForName(framework, symbol_name.as_concrete_TypeRef());
                symbol as *const c_void
            })
        }
    }
}

Please note that it's not exactly compatible with the new API. Current code requires a Result<crate::gl_glue::ServoGl, &'static str> and this returns a Rc<gl::Gl>. I think these are the same types though (modulo the Result).

We need to do the same thing for Windows and Linux as well. It all comes down to rewritting the callback in gl::GlFns::load_with.

The goals of this work is to add OpenGL support to libsimpleservo. Note that we already support OpenGL in ports/servo. ports/servo doesn't use libsimpleservo. But in the future, we want ports/servo to rely on libsimpleservo. So you can look at what ports/servo does to create the GL object:

let gl = match window_kind {
- You can see that it's using get_proc_address. The implementation of get_proc_address comes from glutin: https://github.com/tomaka/glutin and you will find that, for mac, the implementation of get_proc_address is exactly what my snipped above does. So you would need to find how GL is initialized in Glutin for Windows and Linux, and just "copy" what it's done there and put it in gl::init.

delegate GL creation

Another approach, that is probably easier, is to have one single gl::init implementation. It would take a callback as an argument. This callback would be passed to load_with. That would require api.rs to call gl::init with that new argument. So we will need a way to pass the callback from who ever is using libsimpleservo to gl_glue.rs.

I would recommend trying approach 1 first and see how it goes. If it turns out we need extra arguments for approach 1, then it's better to go for approach 2.

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

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.