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

Slightly clean up the final URL creation in canvas.toDataURL #21850

Merged
merged 7 commits into from Oct 3, 2018
Next

Clean up create_webgl_context

  • Loading branch information
nox committed Oct 2, 2018
commit 99b6091b7a2d0782e60cef881cd2a48e44df4654
@@ -216,50 +216,48 @@ impl<VR: WebVRRenderHandler + 'static> WebGLThread<VR> {
}

/// Creates a new WebGLContext
fn create_webgl_context(&mut self,
version: WebGLVersion,
size: Size2D<i32>,
attributes: GLContextAttributes)
-> Result<(WebGLContextId, GLLimits, WebGLContextShareMode), String> {
// First try to create a shared context for the best performance.
// Fallback to readback mode if the shared context creation fails.
let result = self.gl_factory.new_shared_context(version, size, attributes)
.map(|r| (r, WebGLContextShareMode::SharedTexture))
.or_else(|err| {
warn!("Couldn't create shared GL context ({}), using slow \
readback context instead.", err);
let ctx = self.gl_factory.new_context(version, size, attributes);
ctx.map(|r| (r, WebGLContextShareMode::Readback))
});

fn create_webgl_context(
&mut self,
version: WebGLVersion,
size: Size2D<i32>,
attributes: GLContextAttributes,
) -> Result<(WebGLContextId, GLLimits, WebGLContextShareMode), String> {
// Creating a new GLContext may make the current bound context_id dirty.
// Clear it to ensure that make_current() is called in subsequent commands.
self.bound_context_id = None;

match result {
Ok((ctx, share_mode)) => {
let id = WebGLContextId(self.next_webgl_id);
let (size, texture_id, limits) = ctx.get_info();
self.next_webgl_id += 1;
self.contexts.insert(id, GLContextData {
ctx,
state: Default::default(),
});
self.cached_context_info.insert(id, WebGLContextInfo {
texture_id,
size,
alpha: attributes.alpha,
image_key: None,
share_mode,
gl_sync: None,
});

Ok((id, limits, share_mode))
},
Err(msg) => {
Err(msg.to_owned())
}
}
// First try to create a shared context for the best performance.
// Fallback to readback mode if the shared context creation fails.
let (ctx, share_mode) = self.gl_factory
.new_shared_context(version, size, attributes)
.map(|r| (r, WebGLContextShareMode::SharedTexture))
.or_else(|err| {
warn!(
"Couldn't create shared GL context ({}), using slow readback context instead.",
err
);
let ctx = self.gl_factory.new_context(version, size, attributes)?;
Ok((ctx, WebGLContextShareMode::Readback))
})
.map_err(|msg| msg.to_owned())?;

let id = WebGLContextId(self.next_webgl_id);
let (size, texture_id, limits) = ctx.get_info();
self.next_webgl_id += 1;
self.contexts.insert(id, GLContextData {
ctx,
state: Default::default(),
});
self.cached_context_info.insert(id, WebGLContextInfo {
texture_id,
size,
alpha: attributes.alpha,
image_key: None,
share_mode,
gl_sync: None,
});

Ok((id, limits, share_mode))
}

/// Resizes a WebGLContext
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.