aboutsummaryrefslogtreecommitdiffstats
path: root/components/script
diff options
context:
space:
mode:
authorJosh Matthews <josh@joshmatthews.net>2018-08-24 13:43:32 -0400
committerJosh Matthews <josh@joshmatthews.net>2018-09-10 16:31:29 -0400
commit1b08dd523274b1fb346b413cb986cd47409f3aa7 (patch)
treed0ce47aa92454438e98b8b1ac0f29906c0c994a2 /components/script
parentdf8e36aa783b9f6a50a5a16a39f7dcbd65ffde76 (diff)
downloadservo-1b08dd523274b1fb346b413cb986cd47409f3aa7.tar.gz
servo-1b08dd523274b1fb346b413cb986cd47409f3aa7.zip
webgl: Move framebuffer initialization logic to WebGL thread.
Diffstat (limited to 'components/script')
-rw-r--r--components/script/dom/webglframebuffer.rs22
-rw-r--r--components/script/dom/webglrenderbuffer.rs10
-rw-r--r--components/script/dom/webglrenderingcontext.rs17
3 files changed, 39 insertions, 10 deletions
diff --git a/components/script/dom/webglframebuffer.rs b/components/script/dom/webglframebuffer.rs
index 09a1cbea7cc..277b8b2fcba 100644
--- a/components/script/dom/webglframebuffer.rs
+++ b/components/script/dom/webglframebuffer.rs
@@ -34,10 +34,17 @@ enum WebGLFramebufferAttachment {
impl WebGLFramebufferAttachment {
fn needs_initialization(&self) -> bool {
match *self {
- WebGLFramebufferAttachment::Renderbuffer(_) => true,
+ WebGLFramebufferAttachment::Renderbuffer(ref r) => !r.is_initialized(),
WebGLFramebufferAttachment::Texture { .. } => false,
}
}
+
+ fn mark_initialized(&self) {
+ match *self {
+ WebGLFramebufferAttachment::Renderbuffer(ref r) => r.mark_initialized(),
+ WebGLFramebufferAttachment::Texture { .. } => ()
+ }
+ }
}
#[derive(Clone, JSTraceable, MallocSizeOf)]
@@ -239,15 +246,14 @@ impl WebGLFramebuffer {
];
let mut clear_bits = 0;
for &(attachment, bits) in &attachments {
- if attachment.borrow().as_ref().map_or(false, |att| att.needs_initialization()) {
- clear_bits |= bits;
+ if let Some(ref att) = *attachment.borrow() {
+ if att.needs_initialization() {
+ att.mark_initialized();
+ clear_bits |= bits;
+ }
}
}
- if clear_bits != 0 {
- self.upcast::<WebGLObject>().context().send_command(
- WebGLCommand::Clear(clear_bits)
- );
- }
+ self.upcast::<WebGLObject>().context().initialize_framebuffer(clear_bits);
self.is_initialized.set(true);
}
diff --git a/components/script/dom/webglrenderbuffer.rs b/components/script/dom/webglrenderbuffer.rs
index fa7d7324f94..f346407581f 100644
--- a/components/script/dom/webglrenderbuffer.rs
+++ b/components/script/dom/webglrenderbuffer.rs
@@ -23,6 +23,7 @@ pub struct WebGLRenderbuffer {
is_deleted: Cell<bool>,
size: Cell<Option<(i32, i32)>>,
internal_format: Cell<Option<u32>>,
+ is_initialized: Cell<bool>,
}
impl WebGLRenderbuffer {
@@ -34,6 +35,7 @@ impl WebGLRenderbuffer {
is_deleted: Cell::new(false),
internal_format: Cell::new(None),
size: Cell::new(None),
+ is_initialized: Cell::new(false),
}
}
@@ -66,6 +68,14 @@ impl WebGLRenderbuffer {
self.internal_format.get().unwrap_or(constants::RGBA4)
}
+ pub fn mark_initialized(&self) {
+ self.is_initialized.set(true);
+ }
+
+ pub fn is_initialized(&self) -> bool {
+ self.is_initialized.get()
+ }
+
pub fn bind(&self, target: u32) {
self.ever_bound.set(true);
self.upcast::<WebGLObject>()
diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs
index db0fabf452d..6ca010a0b6e 100644
--- a/components/script/dom/webglrenderingcontext.rs
+++ b/components/script/dom/webglrenderingcontext.rs
@@ -1061,6 +1061,17 @@ impl WebGLRenderingContext {
_ => Err(InvalidEnum),
}
}
+
+ pub fn initialize_framebuffer(&self, clear_bits: u32) {
+ if clear_bits == 0 {
+ return;
+ }
+ self.send_command(WebGLCommand::InitializeFramebuffer {
+ color: clear_bits & constants::COLOR_BUFFER_BIT != 0,
+ depth: clear_bits & constants::DEPTH_BUFFER_BIT != 0,
+ stencil: clear_bits & constants::STENCIL_BUFFER_BIT != 0,
+ });
+ }
}
impl Drop for WebGLRenderingContext {
@@ -2727,10 +2738,12 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.3
fn StencilMaskSeparate(&self, face: u32, mask: u32) {
match face {
- constants::FRONT | constants::BACK | constants::FRONT_AND_BACK =>
+ constants::FRONT |
+ constants::BACK |
+ constants::FRONT_AND_BACK =>
self.send_command(WebGLCommand::StencilMaskSeparate(face, mask)),
_ => return self.webgl_error(InvalidEnum),
- }
+ };
}
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.3