Skip to content

Commit

Permalink
Extract canvas operations for reuse by OffscreenCanvas.
Browse files Browse the repository at this point in the history
  • Loading branch information
maharsh312 authored and jdm committed May 22, 2019
1 parent 6fb7a8c commit 85c20db
Show file tree
Hide file tree
Showing 257 changed files with 1,791 additions and 1,804 deletions.
2,024 changes: 1,254 additions & 770 deletions components/script/dom/canvasrenderingcontext2d.rs

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions components/script/dom/dedicatedworkerglobalscope.rs
Expand Up @@ -38,6 +38,7 @@ use js::jsapi::{JSAutoRealm, JSContext};
use js::jsval::UndefinedValue;
use js::rust::HandleValue;
use msg::constellation_msg::{PipelineId, TopLevelBrowsingContextId};
use net_traits::image_cache::ImageCache;
use net_traits::request::{CredentialsMode, Destination, ParserMetadata};
use net_traits::request::{Referrer, RequestBuilder, RequestMode};
use net_traits::IpcSend;
Expand Down Expand Up @@ -174,6 +175,8 @@ pub struct DedicatedWorkerGlobalScope {
#[ignore_malloc_size_of = "Can't measure trait objects"]
/// Sender to the parent thread.
parent_sender: Box<ScriptChan + Send>,
#[ignore_malloc_size_of = "Arc"]
image_cache: Arc<ImageCache>,
}

impl WorkerEventLoopMethods for DedicatedWorkerGlobalScope {
Expand Down Expand Up @@ -225,6 +228,7 @@ impl DedicatedWorkerGlobalScope {
timer_event_chan: IpcSender<TimerEvent>,
timer_event_port: Receiver<(TrustedWorkerAddress, TimerEvent)>,
closing: Arc<AtomicBool>,
image_cache: Arc<dyn ImageCache>,
) -> DedicatedWorkerGlobalScope {
DedicatedWorkerGlobalScope {
workerglobalscope: WorkerGlobalScope::new_inherited(
Expand All @@ -242,6 +246,7 @@ impl DedicatedWorkerGlobalScope {
timer_event_port: timer_event_port,
parent_sender: parent_sender,
worker: DomRefCell::new(None),
image_cache: image_cache,
}
}

Expand All @@ -259,6 +264,7 @@ impl DedicatedWorkerGlobalScope {
timer_event_chan: IpcSender<TimerEvent>,
timer_event_port: Receiver<(TrustedWorkerAddress, TimerEvent)>,
closing: Arc<AtomicBool>,
image_cache: Arc<dyn ImageCache>,
) -> DomRoot<DedicatedWorkerGlobalScope> {
let cx = runtime.cx();
let scope = Box::new(DedicatedWorkerGlobalScope::new_inherited(
Expand All @@ -274,6 +280,7 @@ impl DedicatedWorkerGlobalScope {
timer_event_chan,
timer_event_port,
closing,
image_cache,
));
unsafe { DedicatedWorkerGlobalScopeBinding::Wrap(cx, scope) }
}
Expand All @@ -292,6 +299,7 @@ impl DedicatedWorkerGlobalScope {
worker_name: String,
worker_type: WorkerType,
closing: Arc<AtomicBool>,
image_cache: Arc<dyn ImageCache>,
) {
let serialized_worker_url = worker_url.to_string();
let name = format!("WebWorker for {}", serialized_worker_url);
Expand Down Expand Up @@ -363,6 +371,7 @@ impl DedicatedWorkerGlobalScope {
timer_ipc_chan,
timer_rx,
closing,
image_cache,
);
// FIXME(njn): workers currently don't have a unique ID suitable for using in reporter
// registration (#6631), so we instead use a random number and cross our fingers.
Expand Down Expand Up @@ -428,6 +437,10 @@ impl DedicatedWorkerGlobalScope {
.expect("Thread spawning failed");
}

pub fn image_cache(&self) -> Arc<dyn ImageCache> {
self.image_cache.clone()
}

pub fn script_chan(&self) -> Box<dyn ScriptChan + Send> {
Box::new(WorkerThreadWorkerChan {
sender: self.own_sender.clone(),
Expand Down
15 changes: 15 additions & 0 deletions components/script/dom/globalscope.rs
Expand Up @@ -20,6 +20,7 @@ use crate::dom::errorevent::ErrorEvent;
use crate::dom::event::{Event, EventBubbles, EventCancelable, EventStatus};
use crate::dom::eventsource::EventSource;
use crate::dom::eventtarget::EventTarget;
use crate::dom::paintworkletglobalscope::PaintWorkletGlobalScope;
use crate::dom::performance::Performance;
use crate::dom::window::Window;
use crate::dom::workerglobalscope::WorkerGlobalScope;
Expand Down Expand Up @@ -51,6 +52,7 @@ use js::rust::{get_object_class, CompileOptionsWrapper, ParentRuntime, Runtime};
use js::rust::{HandleValue, MutableHandleValue};
use js::{JSCLASS_IS_DOMJSCLASS, JSCLASS_IS_GLOBAL};
use msg::constellation_msg::PipelineId;
use net_traits::image_cache::ImageCache;
use net_traits::{CoreResourceThread, IpcSend, ResourceThreads};
use profile_traits::{mem as profile_mem, time as profile_time};
use script_traits::{MsDuration, ScriptToConstellationChan, TimerEvent};
Expand Down Expand Up @@ -376,6 +378,19 @@ impl GlobalScope {
&self.origin
}

pub fn image_cache(&self) -> Arc<dyn ImageCache> {
if let Some(window) = self.downcast::<Window>() {
return window.image_cache();
}
if let Some(worker) = self.downcast::<DedicatedWorkerGlobalScope>() {
return worker.image_cache();
}
if let Some(worker) = self.downcast::<PaintWorkletGlobalScope>() {
return worker.image_cache();
}
unreachable!();
}

/// Get the [base url](https://html.spec.whatwg.org/multipage/#api-base-url)
/// for this global scope.
pub fn api_base_url(&self) -> ServoUrl {
Expand Down
7 changes: 6 additions & 1 deletion components/script/dom/offscreencanvas.rs
Expand Up @@ -93,7 +93,12 @@ impl OffscreenCanvas {
};
}
let size = self.get_size();
let context = OffscreenCanvasRenderingContext2D::new(&self.global(), self, size);
let context = OffscreenCanvasRenderingContext2D::new(
&self.global(),
self,
size,
self.placeholder.as_ref().map(|c| &**c),
);
*self.context.borrow_mut() = Some(OffscreenCanvasContext::OffscreenContext2d(
Dom::from_ref(&*context),
));
Expand Down

0 comments on commit 85c20db

Please sign in to comment.