aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/globalscope.rs
diff options
context:
space:
mode:
authorMaharsh <maharsh312@gmail.com>2019-05-14 02:15:20 -0400
committerJosh Matthews <josh@joshmatthews.net>2019-05-22 10:24:54 -0400
commit85c20db495b25af653e6cb77130e166fae8d4b20 (patch)
treec19296c2d3108b6ca59a4ecb8ca3e12cf2a0389b /components/script/dom/globalscope.rs
parent6fb7a8cdc787abf7c69304d3186b0a318ef25412 (diff)
downloadservo-85c20db495b25af653e6cb77130e166fae8d4b20.tar.gz
servo-85c20db495b25af653e6cb77130e166fae8d4b20.zip
Extract canvas operations for reuse by OffscreenCanvas.
Diffstat (limited to 'components/script/dom/globalscope.rs')
-rw-r--r--components/script/dom/globalscope.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/components/script/dom/globalscope.rs b/components/script/dom/globalscope.rs
index f803d6228b7..1330021035a 100644
--- a/components/script/dom/globalscope.rs
+++ b/components/script/dom/globalscope.rs
@@ -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;
@@ -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};
@@ -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 {