Skip to content
Permalink
Browse files

WebGLSender doesn't really implement Serializable

  • Loading branch information...
asajeffrey committed Jul 11, 2019
1 parent 15be654 commit 1b05ad4bb37a44583f295304d7df1b40268b06ac
Showing with 38 additions and 2 deletions.
  1. +17 −2 components/canvas_traits/webgl.rs
  2. +21 −0 components/canvas_traits/webgl_channel/mod.rs
@@ -7,7 +7,7 @@ use gleam::gl;
use gleam::gl::GLsync;
use gleam::gl::GLuint;
use gleam::gl::Gl;
use ipc_channel::ipc::{IpcBytesReceiver, IpcBytesSender, IpcSharedMemory};
use ipc_channel::ipc::{IpcBytesReceiver, IpcBytesSender, IpcSender, IpcSharedMemory};
use pixels::PixelFormat;
use std::borrow::Cow;
use std::fmt;
@@ -175,10 +175,25 @@ impl WebGLMsgSender {
pub fn send_dom_to_texture(&self, command: DOMToTextureCommand) -> WebGLSendResult {
self.sender.send(WebGLMsg::DOMToTextureCommand(command))
}

pub fn webxr_external_image_api(&self) -> impl webxr_api::WebGLExternalImageApi {
SerializableWebGLMsgSender {
ctx_id: self.ctx_id,
sender: self.sender.to_ipc(),
}
}
}

// WegGLMsgSender isn't actually serializable, despite what it claims.
#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
struct SerializableWebGLMsgSender {
ctx_id: WebGLContextId,
#[ignore_malloc_size_of = "channels are hard"]
sender: IpcSender<WebGLMsg>,
}

#[typetag::serde]
impl webxr_api::WebGLExternalImageApi for WebGLMsgSender {
impl webxr_api::WebGLExternalImageApi for SerializableWebGLMsgSender {
fn lock(&self) -> Result<(GLuint, Size2D<i32>, GLsync), webxr_api::Error> {
let (sender, receiver) = webgl_channel().or(Err(webxr_api::Error::CommunicationError))?;
self.sender
@@ -8,6 +8,7 @@ mod ipc;
mod mpsc;

use crate::webgl::WebGLMsg;
use ipc_channel::ipc::IpcSender;
use serde::{Deserialize, Serialize};
use servo_config::opts;
use std::fmt;
@@ -93,6 +94,26 @@ impl WebGLChan {
pub fn send(&self, msg: WebGLMsg) -> WebGLSendResult {
self.0.send(msg)
}

pub fn to_ipc(&self) -> IpcSender<WebGLMsg> {
match self.0 {
WebGLSender::Ipc(ref sender) => sender.clone(),
WebGLSender::Mpsc(ref mpsc_sender) => {
let (sender, receiver) =
ipc_channel::ipc::channel().expect("IPC Channel creation failed");
let mpsc_sender = mpsc_sender.clone();
ipc_channel::router::ROUTER.add_route(
receiver.to_opaque(),
Box::new(move |message| {
if let Ok(message) = message.to() {
let _ = mpsc_sender.send(message);
}
}),
);
sender
},
}
}
}

#[derive(Clone, Debug, Deserialize, Serialize)]

0 comments on commit 1b05ad4

Please sign in to comment.
You can’t perform that action at this time.