Auto merge of #23746 - asajeffrey:webgl-lies-damn-lies-and-serialization, r=Manishearth

WebGLSender doesn't really implement Serializable

<!-- Please describe your changes on the following line: -->

Add an API which turns a `WebGLSender` into something that is actually serializable.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes do not require tests because this is fixing a panic

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23746)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2019-07-11 01:07:13 -04:00 committed by GitHub
commit 305312e93b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 2 deletions

View file

@ -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

View file

@ -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)]