Use separate IPC-only locking mechanism when locking from webxr

This commit is contained in:
Manish Goregaokar 2019-07-10 23:36:21 -07:00
parent 036b495cb2
commit c5a0fc56ea
2 changed files with 25 additions and 7 deletions

View file

@ -9,6 +9,7 @@ use euclid::Size2D;
use fnv::FnvHashMap; use fnv::FnvHashMap;
use gleam::gl; use gleam::gl;
use half::f16; use half::f16;
use ipc_channel::ipc::IpcSender;
use offscreen_gl_context::{DrawBuffer, GLContext, NativeGLContextMethods}; use offscreen_gl_context::{DrawBuffer, GLContext, NativeGLContextMethods};
use pixels::{self, PixelFormat}; use pixels::{self, PixelFormat};
use std::borrow::Cow; use std::borrow::Cow;
@ -181,6 +182,9 @@ impl<VR: WebVRRenderHandler + 'static> WebGLThread<VR> {
WebGLMsg::Lock(ctx_id, sender) => { WebGLMsg::Lock(ctx_id, sender) => {
self.handle_lock(ctx_id, sender); self.handle_lock(ctx_id, sender);
}, },
WebGLMsg::LockIPC(ctx_id, sender) => {
self.handle_lock_ipc(ctx_id, sender);
},
WebGLMsg::Unlock(ctx_id) => { WebGLMsg::Unlock(ctx_id) => {
self.handle_unlock(ctx_id); self.handle_unlock(ctx_id);
}, },
@ -231,13 +235,27 @@ impl<VR: WebVRRenderHandler + 'static> WebGLThread<VR> {
); );
} }
} }
/// Handles a lock external callback received from webrender::ExternalImageHandler /// Handles a lock external callback received from webrender::ExternalImageHandler
fn handle_lock( fn handle_lock(
&mut self, &mut self,
context_id: WebGLContextId, context_id: WebGLContextId,
sender: WebGLSender<(u32, Size2D<i32>, usize)>, sender: WebGLSender<(u32, Size2D<i32>, usize)>,
) { ) {
sender.send(self.handle_lock_inner(context_id)).unwrap();
}
/// handle_lock, but unconditionally IPC (used by webxr)
fn handle_lock_ipc(
&mut self,
context_id: WebGLContextId,
sender: IpcSender<(u32, Size2D<i32>, usize)>,
) {
sender.send(self.handle_lock_inner(context_id)).unwrap();
}
/// Shared code between handle_lock and handle_lock_ipc, does the actual syncing/flushing
/// but the caller must send the response back
fn handle_lock_inner(&mut self, context_id: WebGLContextId) -> (u32, Size2D<i32>, usize) {
let data = let data =
Self::make_current_if_needed(context_id, &self.contexts, &mut self.bound_context_id) Self::make_current_if_needed(context_id, &self.contexts, &mut self.bound_context_id)
.expect("WebGLContext not found in a WebGLMsg::Lock message"); .expect("WebGLContext not found in a WebGLMsg::Lock message");
@ -251,9 +269,7 @@ impl<VR: WebVRRenderHandler + 'static> WebGLThread<VR> {
// Without proper flushing, the sync object may never be signaled. // Without proper flushing, the sync object may never be signaled.
data.ctx.gl().flush(); data.ctx.gl().flush();
sender (info.texture_id, info.size, gl_sync as usize)
.send((info.texture_id, info.size, gl_sync as usize))
.unwrap();
} }
/// Handles an unlock external callback received from webrender::ExternalImageHandler /// Handles an unlock external callback received from webrender::ExternalImageHandler

View file

@ -7,7 +7,7 @@ use gleam::gl;
use gleam::gl::GLsync; use gleam::gl::GLsync;
use gleam::gl::GLuint; use gleam::gl::GLuint;
use gleam::gl::Gl; use gleam::gl::Gl;
use ipc_channel::ipc::{IpcBytesReceiver, IpcBytesSender, IpcSender, IpcSharedMemory}; use ipc_channel::ipc::{self, IpcBytesReceiver, IpcBytesSender, IpcSender, IpcSharedMemory};
use pixels::PixelFormat; use pixels::PixelFormat;
use std::borrow::Cow; use std::borrow::Cow;
use std::fmt; use std::fmt;
@ -61,6 +61,8 @@ pub enum WebGLMsg {
/// The WR client should not change the shared texture content until the Unlock call. /// The WR client should not change the shared texture content until the Unlock call.
/// Currently OpenGL Sync Objects are used to implement the synchronization mechanism. /// Currently OpenGL Sync Objects are used to implement the synchronization mechanism.
Lock(WebGLContextId, WebGLSender<(u32, Size2D<i32>, usize)>), Lock(WebGLContextId, WebGLSender<(u32, Size2D<i32>, usize)>),
/// Lock(), but unconditionally IPC (used by webxr)
LockIPC(WebGLContextId, IpcSender<(u32, Size2D<i32>, usize)>),
/// Unlocks a specific WebGLContext. Unlock messages are used for a correct synchronization /// Unlocks a specific WebGLContext. Unlock messages are used for a correct synchronization
/// with WebRender external image API. /// with WebRender external image API.
/// The WR unlocks a context when it finished reading the shared texture contents. /// The WR unlocks a context when it finished reading the shared texture contents.
@ -195,9 +197,9 @@ struct SerializableWebGLMsgSender {
#[typetag::serde] #[typetag::serde]
impl webxr_api::WebGLExternalImageApi for SerializableWebGLMsgSender { impl webxr_api::WebGLExternalImageApi for SerializableWebGLMsgSender {
fn lock(&self) -> Result<(GLuint, Size2D<i32>, GLsync), webxr_api::Error> { fn lock(&self) -> Result<(GLuint, Size2D<i32>, GLsync), webxr_api::Error> {
let (sender, receiver) = webgl_channel().or(Err(webxr_api::Error::CommunicationError))?; let (sender, receiver) = ipc::channel().or(Err(webxr_api::Error::CommunicationError))?;
self.sender self.sender
.send(WebGLMsg::Lock(self.ctx_id, sender)) .send(WebGLMsg::LockIPC(self.ctx_id, sender))
.or(Err(webxr_api::Error::CommunicationError))?; .or(Err(webxr_api::Error::CommunicationError))?;
let (texture, size, sync) = receiver let (texture, size, sync) = receiver
.recv() .recv()