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

Remove canvas->compositing dependency #23758

Merged
merged 1 commit into from Jul 12, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Some generated files are not rendered by default. Learn more.

@@ -21,7 +21,6 @@ no_wgl = ["offscreen_gl_context/no_wgl"]
azure = {git = "https://github.com/servo/rust-azure", optional = true}
byteorder = "1"
canvas_traits = {path = "../canvas_traits"}
compositing = {path = "../compositing"}
cssparser = "0.25"
euclid = "0.19"
fnv = "1.0"
@@ -6,7 +6,6 @@ use super::webgl_thread::{GLState, WebGLImpl};
use canvas_traits::webgl::{
GLContextAttributes, GLLimits, WebGLCommand, WebGLCommandBacktrace, WebGLVersion,
};
use compositing::compositor_thread::{self, CompositorProxy};
use euclid::Size2D;
use gleam::gl;
use offscreen_gl_context::{
@@ -16,31 +15,38 @@ use offscreen_gl_context::{
use offscreen_gl_context::{GLLimits as RawGLLimits, GLVersion};
use offscreen_gl_context::{NativeGLContext, NativeGLContextHandle, NativeGLContextMethods};
use offscreen_gl_context::{OSMesaContext, OSMesaContextHandle};
use std::sync::{Arc, Mutex};

pub trait CloneableDispatcher: GLContextDispatcher {
fn clone(&self) -> Box<dyn GLContextDispatcher>;
}

/// The GLContextFactory is used to create shared GL contexts with the main thread GL context.
/// Currently, shared textures are used to render WebGL textures into the WR compositor.
/// In order to create a shared context, the GLContextFactory stores the handle of the main GL context.
pub enum GLContextFactory {
Native(NativeGLContextHandle, Option<MainThreadDispatcher>),
Native(
NativeGLContextHandle,
Option<Box<dyn CloneableDispatcher + Send>>,
),
OSMesa(OSMesaContextHandle),
}

impl GLContextFactory {
/// Creates a new GLContextFactory that uses the currently bound GL context to create shared contexts.
pub fn current_native_handle(proxy: &CompositorProxy) -> Option<GLContextFactory> {
pub fn current_native_handle(
dispatcher: Box<dyn CloneableDispatcher + Send>,
) -> Option<GLContextFactory> {
let dispatcher = if cfg!(target_os = "windows") {
// Used to dispatch functions from the GLContext thread to the main thread's
// event loop. Required to allow WGL GLContext sharing in Windows.
Some(dispatcher)
} else {
None
};
// FIXME(emilio): This assumes a single GL backend per platform which is
// not true on Linux, we probably need a third `Egl` variant or abstract
// it a bit more...
NativeGLContext::current_handle().map(|handle| {
if cfg!(target_os = "windows") {
// Used to dispatch functions from the GLContext thread to the main thread's event loop.
// Required to allow WGL GLContext sharing in Windows.
GLContextFactory::Native(handle, Some(MainThreadDispatcher::new(proxy.clone())))
} else {
GLContextFactory::Native(handle, None)
}
})
NativeGLContext::current_handle().map(|handle| GLContextFactory::Native(handle, dispatcher))
}

/// Creates a new GLContextFactory that uses the currently bound OSMesa context to create shared contexts.
@@ -58,7 +64,6 @@ impl GLContextFactory {
let attributes = map_attrs(attributes);
Ok(match *self {
GLContextFactory::Native(ref handle, ref dispatcher) => {
let dispatcher = dispatcher.as_ref().map(|d| Box::new(d.clone()) as Box<_>);
GLContextWrapper::Native(GLContext::new_shared_with_dispatcher(
// FIXME(nox): Why are those i32 values?
size.to_i32(),
@@ -67,7 +72,7 @@ impl GLContextFactory {
gl::GlType::default(),
Self::gl_version(webgl_version),
Some(handle),
dispatcher,
dispatcher.as_ref().map(|d| (**d).clone()),
)?)
},
GLContextFactory::OSMesa(ref handle) => {
@@ -215,29 +220,6 @@ impl GLContextWrapper {
}
}

/// Implements GLContextDispatcher to dispatch functions from GLContext threads to the main thread's event loop.
/// It's used in Windows to allow WGL GLContext sharing.
#[derive(Clone)]
pub struct MainThreadDispatcher {
compositor_proxy: Arc<Mutex<CompositorProxy>>,
}

impl MainThreadDispatcher {
fn new(proxy: CompositorProxy) -> Self {
Self {
compositor_proxy: Arc::new(Mutex::new(proxy)),
}
}
}
impl GLContextDispatcher for MainThreadDispatcher {
fn dispatch(&self, f: Box<dyn Fn() + Send>) {
self.compositor_proxy
.lock()
.unwrap()
.send(compositor_thread::Msg::Dispatch(f));
}
}

fn map_limits(limits: RawGLLimits) -> GLLimits {
GLLimits {
max_vertex_attribs: limits.max_vertex_attribs,
@@ -60,6 +60,7 @@ layout_thread_2020 = {path = "../layout_thread_2020", optional = true}
log = "0.4"
media = {path = "../media"}
msg = {path = "../msg"}
offscreen_gl_context = "0.22"
net = {path = "../net"}
net_traits = {path = "../net_traits"}
profile = {path = "../profile"}
@@ -64,7 +64,7 @@ fn webdriver(_port: u16, _constellation: Sender<ConstellationMsg>) {}

use bluetooth::BluetoothThreadFactory;
use bluetooth_traits::BluetoothRequest;
use canvas::gl_context::GLContextFactory;
use canvas::gl_context::{CloneableDispatcher, GLContextFactory};
use canvas::webgl_thread::WebGLThreads;
use compositing::compositor_thread::{
CompositorProxy, CompositorReceiver, InitialCompositorState, Msg,
@@ -99,6 +99,7 @@ use media::{GLPlayerThreads, WindowGLContext};
use msg::constellation_msg::{PipelineNamespace, PipelineNamespaceId};
use net::resource_thread::new_resource_threads;
use net_traits::IpcSend;
use offscreen_gl_context::GLContextDispatcher;
use profile::mem as profile_mem;
use profile::time as profile_time;
use profile_traits::mem;
@@ -734,7 +735,8 @@ fn create_constellation(
let gl_factory = if opts.should_use_osmesa() {
GLContextFactory::current_osmesa_handle()
} else {
GLContextFactory::current_native_handle(&compositor_proxy)
let dispatcher = Box::new(MainThreadDispatcher::new(compositor_proxy.clone())) as Box<_>;
GLContextFactory::current_native_handle(dispatcher)
};

let (external_image_handlers, external_images) = WebrenderExternalImageHandlers::new();
@@ -926,3 +928,29 @@ fn create_sandbox() {
fn create_sandbox() {
panic!("Sandboxing is not supported on Windows, iOS, ARM targets and android.");
}

/// Implements GLContextDispatcher to dispatch functions from GLContext threads to the main thread's event loop.
/// It's used in Windows to allow WGL GLContext sharing.
pub struct MainThreadDispatcher {
compositor_proxy: CompositorProxy,
}

impl MainThreadDispatcher {
fn new(proxy: CompositorProxy) -> Self {
Self {
compositor_proxy: proxy,
}
}
}
impl GLContextDispatcher for MainThreadDispatcher {
fn dispatch(&self, f: Box<dyn Fn() + Send>) {
self.compositor_proxy.send(Msg::Dispatch(f));
}
}
impl CloneableDispatcher for MainThreadDispatcher {
fn clone(&self) -> Box<dyn GLContextDispatcher> {
Box::new(MainThreadDispatcher {
compositor_proxy: self.compositor_proxy.clone(),
}) as Box<_>
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.