From 32e23c4db4a80f8ebe01bead141c5ca04bc6b215 Mon Sep 17 00:00:00 2001 From: Imanol Fernandez Date: Tue, 16 May 2017 11:14:23 +0200 Subject: Implement WebGL extensions. --- components/script/dom/webgltexture.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'components/script/dom/webgltexture.rs') diff --git a/components/script/dom/webgltexture.rs b/components/script/dom/webgltexture.rs index d88f955a862..184a9c39131 100644 --- a/components/script/dom/webgltexture.rs +++ b/components/script/dom/webgltexture.rs @@ -42,6 +42,9 @@ pub struct WebGLTexture { /// Face count can only be 1 or 6 face_count: Cell, base_mipmap_level: u32, + // Store information for min and mag filters + min_filter: Cell>, + mag_filter: Cell>, #[ignore_heap_size_of = "Defined in ipc-channel"] renderer: IpcSender, } @@ -57,6 +60,8 @@ impl WebGLTexture { is_deleted: Cell::new(false), face_count: Cell::new(0), base_mipmap_level: 0, + min_filter: Cell::new(None), + mag_filter: Cell::new(None), image_info_array: DOMRefCell::new([ImageInfo::new(); MAX_LEVEL_COUNT * MAX_FACE_COUNT]), renderer: renderer, } @@ -209,6 +214,7 @@ impl WebGLTexture { constants::LINEAR_MIPMAP_NEAREST | constants::NEAREST_MIPMAP_LINEAR | constants::LINEAR_MIPMAP_LINEAR => { + self.min_filter.set(Some(int_value as u32)); self.renderer .send(CanvasMsg::WebGL(WebGLCommand::TexParameteri(target, name, int_value))) .unwrap(); @@ -222,6 +228,7 @@ impl WebGLTexture { match int_value as u32 { constants::NEAREST | constants::LINEAR => { + self.mag_filter.set(Some(int_value as u32)); self.renderer .send(CanvasMsg::WebGL(WebGLCommand::TexParameteri(target, name, int_value))) .unwrap(); @@ -251,6 +258,19 @@ impl WebGLTexture { } } + pub fn is_using_linear_filtering(&self) -> bool { + let filters = [self.min_filter.get(), self.mag_filter.get()]; + filters.iter().any(|filter| { + match *filter { + Some(constants::LINEAR) | + Some(constants::NEAREST_MIPMAP_LINEAR) | + Some(constants::LINEAR_MIPMAP_NEAREST) | + Some(constants::LINEAR_MIPMAP_LINEAR) => true, + _=> false + } + }) + } + pub fn populate_mip_chain(&self, first_level: u32, last_level: u32) -> WebGLResult<()> { let base_image_info = self.image_info_at_face(0, first_level); if !base_image_info.is_initialized() { @@ -408,7 +428,7 @@ impl ImageInfo { self.depth.is_power_of_two() } - fn is_initialized(&self) -> bool { + pub fn is_initialized(&self) -> bool { self.is_initialized } -- cgit v1.2.3 From e58e8ab42e832604cc71b01a25ca1e199323d7c6 Mon Sep 17 00:00:00 2001 From: Martin Robinson Date: Thu, 6 Jul 2017 19:21:22 +0200 Subject: Upgrade to the latest version of WebRender --- components/script/dom/webgltexture.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'components/script/dom/webgltexture.rs') diff --git a/components/script/dom/webgltexture.rs b/components/script/dom/webgltexture.rs index 184a9c39131..88d5faaf5c8 100644 --- a/components/script/dom/webgltexture.rs +++ b/components/script/dom/webgltexture.rs @@ -16,8 +16,8 @@ use dom_struct::dom_struct; use ipc_channel::ipc::IpcSender; use std::cell::Cell; use std::cmp; -use webrender_traits; -use webrender_traits::{WebGLCommand, WebGLError, WebGLResult, WebGLTextureId}; +use webrender_api; +use webrender_api::{WebGLCommand, WebGLError, WebGLResult, WebGLTextureId}; pub enum TexParameterValue { Float(f32), @@ -69,7 +69,7 @@ impl WebGLTexture { pub fn maybe_new(window: &Window, renderer: IpcSender) -> Option> { - let (sender, receiver) = webrender_traits::channel::msg_channel().unwrap(); + let (sender, receiver) = webrender_api::channel::msg_channel().unwrap(); renderer.send(CanvasMsg::WebGL(WebGLCommand::CreateTexture(sender))).unwrap(); let result = receiver.recv().unwrap(); -- cgit v1.2.3 From 703962fe61d673536eb982b45795ae13748f0f6a Mon Sep 17 00:00:00 2001 From: Imanol Fernandez Date: Tue, 15 Aug 2017 16:05:22 +0200 Subject: Improve WebGL architecture. --- components/script/dom/webgltexture.rs | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) (limited to 'components/script/dom/webgltexture.rs') diff --git a/components/script/dom/webgltexture.rs b/components/script/dom/webgltexture.rs index 88d5faaf5c8..048af5d10e0 100644 --- a/components/script/dom/webgltexture.rs +++ b/components/script/dom/webgltexture.rs @@ -3,7 +3,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ // https://www.khronos.org/registry/webgl/specs/latest/1.0/webgl.idl -use canvas_traits::CanvasMsg; + +use canvas_traits::webgl::{webgl_channel, WebGLCommand, WebGLError, WebGLMsgSender, WebGLResult, WebGLTextureId}; use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants; use dom::bindings::codegen::Bindings::WebGLTextureBinding; @@ -13,11 +14,8 @@ use dom::webgl_validations::types::{TexImageTarget, TexFormat, TexDataType}; use dom::webglobject::WebGLObject; use dom::window::Window; use dom_struct::dom_struct; -use ipc_channel::ipc::IpcSender; use std::cell::Cell; use std::cmp; -use webrender_api; -use webrender_api::{WebGLCommand, WebGLError, WebGLResult, WebGLTextureId}; pub enum TexParameterValue { Float(f32), @@ -46,11 +44,11 @@ pub struct WebGLTexture { min_filter: Cell>, mag_filter: Cell>, #[ignore_heap_size_of = "Defined in ipc-channel"] - renderer: IpcSender, + renderer: WebGLMsgSender, } impl WebGLTexture { - fn new_inherited(renderer: IpcSender, + fn new_inherited(renderer: WebGLMsgSender, id: WebGLTextureId) -> WebGLTexture { WebGLTexture { @@ -67,17 +65,17 @@ impl WebGLTexture { } } - pub fn maybe_new(window: &Window, renderer: IpcSender) + pub fn maybe_new(window: &Window, renderer: WebGLMsgSender) -> Option> { - let (sender, receiver) = webrender_api::channel::msg_channel().unwrap(); - renderer.send(CanvasMsg::WebGL(WebGLCommand::CreateTexture(sender))).unwrap(); + let (sender, receiver) = webgl_channel().unwrap(); + renderer.send(WebGLCommand::CreateTexture(sender)).unwrap(); let result = receiver.recv().unwrap(); result.map(|texture_id| WebGLTexture::new(window, renderer, texture_id)) } pub fn new(window: &Window, - renderer: IpcSender, + renderer: WebGLMsgSender, id: WebGLTextureId) -> Root { reflect_dom_object(box WebGLTexture::new_inherited(renderer, id), @@ -113,7 +111,7 @@ impl WebGLTexture { self.target.set(Some(target)); } - let msg = CanvasMsg::WebGL(WebGLCommand::BindTexture(target, Some(self.id))); + let msg = WebGLCommand::BindTexture(target, Some(self.id)); self.renderer.send(msg).unwrap(); Ok(()) @@ -168,7 +166,7 @@ impl WebGLTexture { return Err(WebGLError::InvalidOperation); } - self.renderer.send(CanvasMsg::WebGL(WebGLCommand::GenerateMipmap(target))).unwrap(); + self.renderer.send(WebGLCommand::GenerateMipmap(target)).unwrap(); if self.base_mipmap_level + base_image_info.get_max_mimap_levels() == 0 { return Err(WebGLError::InvalidOperation); @@ -181,7 +179,7 @@ impl WebGLTexture { pub fn delete(&self) { if !self.is_deleted.get() { self.is_deleted.set(true); - let _ = self.renderer.send(CanvasMsg::WebGL(WebGLCommand::DeleteTexture(self.id))); + let _ = self.renderer.send(WebGLCommand::DeleteTexture(self.id)); } } @@ -216,7 +214,7 @@ impl WebGLTexture { constants::LINEAR_MIPMAP_LINEAR => { self.min_filter.set(Some(int_value as u32)); self.renderer - .send(CanvasMsg::WebGL(WebGLCommand::TexParameteri(target, name, int_value))) + .send(WebGLCommand::TexParameteri(target, name, int_value)) .unwrap(); Ok(()) }, @@ -230,7 +228,7 @@ impl WebGLTexture { constants::LINEAR => { self.mag_filter.set(Some(int_value as u32)); self.renderer - .send(CanvasMsg::WebGL(WebGLCommand::TexParameteri(target, name, int_value))) + .send(WebGLCommand::TexParameteri(target, name, int_value)) .unwrap(); Ok(()) }, @@ -245,7 +243,7 @@ impl WebGLTexture { constants::MIRRORED_REPEAT | constants::REPEAT => { self.renderer - .send(CanvasMsg::WebGL(WebGLCommand::TexParameteri(target, name, int_value))) + .send(WebGLCommand::TexParameteri(target, name, int_value)) .unwrap(); Ok(()) }, -- cgit v1.2.3 From cfe22e3979b7270833a4b450b25fb2157deb1da2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 16 Aug 2017 16:42:13 +0200 Subject: Revert "Auto merge of #17891 - MortimerGoro:webgl_move, r=glennw,emilio" This reverts commit 90f55ea4580e2a15f7d70d0491444f18b972d450, reversing changes made to 2e60b27a2186a8cba4b952960155dfcf3f47d7db. --- components/script/dom/webgltexture.rs | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'components/script/dom/webgltexture.rs') diff --git a/components/script/dom/webgltexture.rs b/components/script/dom/webgltexture.rs index 048af5d10e0..88d5faaf5c8 100644 --- a/components/script/dom/webgltexture.rs +++ b/components/script/dom/webgltexture.rs @@ -3,8 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ // https://www.khronos.org/registry/webgl/specs/latest/1.0/webgl.idl - -use canvas_traits::webgl::{webgl_channel, WebGLCommand, WebGLError, WebGLMsgSender, WebGLResult, WebGLTextureId}; +use canvas_traits::CanvasMsg; use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants; use dom::bindings::codegen::Bindings::WebGLTextureBinding; @@ -14,8 +13,11 @@ use dom::webgl_validations::types::{TexImageTarget, TexFormat, TexDataType}; use dom::webglobject::WebGLObject; use dom::window::Window; use dom_struct::dom_struct; +use ipc_channel::ipc::IpcSender; use std::cell::Cell; use std::cmp; +use webrender_api; +use webrender_api::{WebGLCommand, WebGLError, WebGLResult, WebGLTextureId}; pub enum TexParameterValue { Float(f32), @@ -44,11 +46,11 @@ pub struct WebGLTexture { min_filter: Cell>, mag_filter: Cell>, #[ignore_heap_size_of = "Defined in ipc-channel"] - renderer: WebGLMsgSender, + renderer: IpcSender, } impl WebGLTexture { - fn new_inherited(renderer: WebGLMsgSender, + fn new_inherited(renderer: IpcSender, id: WebGLTextureId) -> WebGLTexture { WebGLTexture { @@ -65,17 +67,17 @@ impl WebGLTexture { } } - pub fn maybe_new(window: &Window, renderer: WebGLMsgSender) + pub fn maybe_new(window: &Window, renderer: IpcSender) -> Option> { - let (sender, receiver) = webgl_channel().unwrap(); - renderer.send(WebGLCommand::CreateTexture(sender)).unwrap(); + let (sender, receiver) = webrender_api::channel::msg_channel().unwrap(); + renderer.send(CanvasMsg::WebGL(WebGLCommand::CreateTexture(sender))).unwrap(); let result = receiver.recv().unwrap(); result.map(|texture_id| WebGLTexture::new(window, renderer, texture_id)) } pub fn new(window: &Window, - renderer: WebGLMsgSender, + renderer: IpcSender, id: WebGLTextureId) -> Root { reflect_dom_object(box WebGLTexture::new_inherited(renderer, id), @@ -111,7 +113,7 @@ impl WebGLTexture { self.target.set(Some(target)); } - let msg = WebGLCommand::BindTexture(target, Some(self.id)); + let msg = CanvasMsg::WebGL(WebGLCommand::BindTexture(target, Some(self.id))); self.renderer.send(msg).unwrap(); Ok(()) @@ -166,7 +168,7 @@ impl WebGLTexture { return Err(WebGLError::InvalidOperation); } - self.renderer.send(WebGLCommand::GenerateMipmap(target)).unwrap(); + self.renderer.send(CanvasMsg::WebGL(WebGLCommand::GenerateMipmap(target))).unwrap(); if self.base_mipmap_level + base_image_info.get_max_mimap_levels() == 0 { return Err(WebGLError::InvalidOperation); @@ -179,7 +181,7 @@ impl WebGLTexture { pub fn delete(&self) { if !self.is_deleted.get() { self.is_deleted.set(true); - let _ = self.renderer.send(WebGLCommand::DeleteTexture(self.id)); + let _ = self.renderer.send(CanvasMsg::WebGL(WebGLCommand::DeleteTexture(self.id))); } } @@ -214,7 +216,7 @@ impl WebGLTexture { constants::LINEAR_MIPMAP_LINEAR => { self.min_filter.set(Some(int_value as u32)); self.renderer - .send(WebGLCommand::TexParameteri(target, name, int_value)) + .send(CanvasMsg::WebGL(WebGLCommand::TexParameteri(target, name, int_value))) .unwrap(); Ok(()) }, @@ -228,7 +230,7 @@ impl WebGLTexture { constants::LINEAR => { self.mag_filter.set(Some(int_value as u32)); self.renderer - .send(WebGLCommand::TexParameteri(target, name, int_value)) + .send(CanvasMsg::WebGL(WebGLCommand::TexParameteri(target, name, int_value))) .unwrap(); Ok(()) }, @@ -243,7 +245,7 @@ impl WebGLTexture { constants::MIRRORED_REPEAT | constants::REPEAT => { self.renderer - .send(WebGLCommand::TexParameteri(target, name, int_value)) + .send(CanvasMsg::WebGL(WebGLCommand::TexParameteri(target, name, int_value))) .unwrap(); Ok(()) }, -- cgit v1.2.3 From 676f2c8acf6fec8ad77d4daa51bef5bdcae101c5 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Wed, 16 Aug 2017 23:23:18 +0200 Subject: Revert "Auto merge of #18114 - emilio:revert-webgl-refactor, r=nox" This reverts commit 4d10d39e8fe841c5fe2ac58da2daaa13c10c140e, reversing changes made to ee94e2b7c0bd327abe8f9545b2a1f792f67a2bdd. --- components/script/dom/webgltexture.rs | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) (limited to 'components/script/dom/webgltexture.rs') diff --git a/components/script/dom/webgltexture.rs b/components/script/dom/webgltexture.rs index 88d5faaf5c8..048af5d10e0 100644 --- a/components/script/dom/webgltexture.rs +++ b/components/script/dom/webgltexture.rs @@ -3,7 +3,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ // https://www.khronos.org/registry/webgl/specs/latest/1.0/webgl.idl -use canvas_traits::CanvasMsg; + +use canvas_traits::webgl::{webgl_channel, WebGLCommand, WebGLError, WebGLMsgSender, WebGLResult, WebGLTextureId}; use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants; use dom::bindings::codegen::Bindings::WebGLTextureBinding; @@ -13,11 +14,8 @@ use dom::webgl_validations::types::{TexImageTarget, TexFormat, TexDataType}; use dom::webglobject::WebGLObject; use dom::window::Window; use dom_struct::dom_struct; -use ipc_channel::ipc::IpcSender; use std::cell::Cell; use std::cmp; -use webrender_api; -use webrender_api::{WebGLCommand, WebGLError, WebGLResult, WebGLTextureId}; pub enum TexParameterValue { Float(f32), @@ -46,11 +44,11 @@ pub struct WebGLTexture { min_filter: Cell>, mag_filter: Cell>, #[ignore_heap_size_of = "Defined in ipc-channel"] - renderer: IpcSender, + renderer: WebGLMsgSender, } impl WebGLTexture { - fn new_inherited(renderer: IpcSender, + fn new_inherited(renderer: WebGLMsgSender, id: WebGLTextureId) -> WebGLTexture { WebGLTexture { @@ -67,17 +65,17 @@ impl WebGLTexture { } } - pub fn maybe_new(window: &Window, renderer: IpcSender) + pub fn maybe_new(window: &Window, renderer: WebGLMsgSender) -> Option> { - let (sender, receiver) = webrender_api::channel::msg_channel().unwrap(); - renderer.send(CanvasMsg::WebGL(WebGLCommand::CreateTexture(sender))).unwrap(); + let (sender, receiver) = webgl_channel().unwrap(); + renderer.send(WebGLCommand::CreateTexture(sender)).unwrap(); let result = receiver.recv().unwrap(); result.map(|texture_id| WebGLTexture::new(window, renderer, texture_id)) } pub fn new(window: &Window, - renderer: IpcSender, + renderer: WebGLMsgSender, id: WebGLTextureId) -> Root { reflect_dom_object(box WebGLTexture::new_inherited(renderer, id), @@ -113,7 +111,7 @@ impl WebGLTexture { self.target.set(Some(target)); } - let msg = CanvasMsg::WebGL(WebGLCommand::BindTexture(target, Some(self.id))); + let msg = WebGLCommand::BindTexture(target, Some(self.id)); self.renderer.send(msg).unwrap(); Ok(()) @@ -168,7 +166,7 @@ impl WebGLTexture { return Err(WebGLError::InvalidOperation); } - self.renderer.send(CanvasMsg::WebGL(WebGLCommand::GenerateMipmap(target))).unwrap(); + self.renderer.send(WebGLCommand::GenerateMipmap(target)).unwrap(); if self.base_mipmap_level + base_image_info.get_max_mimap_levels() == 0 { return Err(WebGLError::InvalidOperation); @@ -181,7 +179,7 @@ impl WebGLTexture { pub fn delete(&self) { if !self.is_deleted.get() { self.is_deleted.set(true); - let _ = self.renderer.send(CanvasMsg::WebGL(WebGLCommand::DeleteTexture(self.id))); + let _ = self.renderer.send(WebGLCommand::DeleteTexture(self.id)); } } @@ -216,7 +214,7 @@ impl WebGLTexture { constants::LINEAR_MIPMAP_LINEAR => { self.min_filter.set(Some(int_value as u32)); self.renderer - .send(CanvasMsg::WebGL(WebGLCommand::TexParameteri(target, name, int_value))) + .send(WebGLCommand::TexParameteri(target, name, int_value)) .unwrap(); Ok(()) }, @@ -230,7 +228,7 @@ impl WebGLTexture { constants::LINEAR => { self.mag_filter.set(Some(int_value as u32)); self.renderer - .send(CanvasMsg::WebGL(WebGLCommand::TexParameteri(target, name, int_value))) + .send(WebGLCommand::TexParameteri(target, name, int_value)) .unwrap(); Ok(()) }, @@ -245,7 +243,7 @@ impl WebGLTexture { constants::MIRRORED_REPEAT | constants::REPEAT => { self.renderer - .send(CanvasMsg::WebGL(WebGLCommand::TexParameteri(target, name, int_value))) + .send(WebGLCommand::TexParameteri(target, name, int_value)) .unwrap(); Ok(()) }, -- cgit v1.2.3 From c5fe2351124c673d1dc4d59355a03654b4fcc541 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20DAVID?= Date: Wed, 23 Aug 2017 14:10:08 +0200 Subject: order derivable traits lists Ignoring : - **generated**.rs - python/tidy/servo_tidy_tests/rust_tidy.rs --- components/script/dom/webgltexture.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'components/script/dom/webgltexture.rs') diff --git a/components/script/dom/webgltexture.rs b/components/script/dom/webgltexture.rs index 048af5d10e0..b4466ee9396 100644 --- a/components/script/dom/webgltexture.rs +++ b/components/script/dom/webgltexture.rs @@ -382,7 +382,7 @@ impl Drop for WebGLTexture { } } -#[derive(Clone, Copy, PartialEq, Debug, JSTraceable, HeapSizeOf)] +#[derive(Clone, Copy, Debug, HeapSizeOf, JSTraceable, PartialEq)] pub struct ImageInfo { width: u32, height: u32, -- cgit v1.2.3 From 0e3c54c1911ba2c3bf305ee04f04fcd9bf2fc2fe Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Mon, 25 Sep 2017 23:30:24 +0200 Subject: Rename dom::bindings::js to dom::bindings::root --- components/script/dom/webgltexture.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'components/script/dom/webgltexture.rs') diff --git a/components/script/dom/webgltexture.rs b/components/script/dom/webgltexture.rs index b4466ee9396..22800430a6b 100644 --- a/components/script/dom/webgltexture.rs +++ b/components/script/dom/webgltexture.rs @@ -8,8 +8,8 @@ use canvas_traits::webgl::{webgl_channel, WebGLCommand, WebGLError, WebGLMsgSend use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants; use dom::bindings::codegen::Bindings::WebGLTextureBinding; -use dom::bindings::js::Root; use dom::bindings::reflector::reflect_dom_object; +use dom::bindings::root::Root; use dom::webgl_validations::types::{TexImageTarget, TexFormat, TexDataType}; use dom::webglobject::WebGLObject; use dom::window::Window; -- cgit v1.2.3 From 577370746e2ce3da7fa25a20b8e1bbeed319df65 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Tue, 26 Sep 2017 01:32:40 +0200 Subject: Rename DOMRefCell to DomRefCell I don't want to do such a gratuitous rename, but with all the other types now having "Dom" as part of their name, and especially with "DomOnceCell", I feel like the other cell type that we already have should also follow the convention. That argument loses weight though when we realise there is still DOMString and other things. --- components/script/dom/webgltexture.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'components/script/dom/webgltexture.rs') diff --git a/components/script/dom/webgltexture.rs b/components/script/dom/webgltexture.rs index 22800430a6b..fe323b53efd 100644 --- a/components/script/dom/webgltexture.rs +++ b/components/script/dom/webgltexture.rs @@ -5,7 +5,7 @@ // https://www.khronos.org/registry/webgl/specs/latest/1.0/webgl.idl use canvas_traits::webgl::{webgl_channel, WebGLCommand, WebGLError, WebGLMsgSender, WebGLResult, WebGLTextureId}; -use dom::bindings::cell::DOMRefCell; +use dom::bindings::cell::DomRefCell; use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants; use dom::bindings::codegen::Bindings::WebGLTextureBinding; use dom::bindings::reflector::reflect_dom_object; @@ -36,7 +36,7 @@ pub struct WebGLTexture { is_deleted: Cell, /// Stores information about mipmap levels and cubemap faces. #[ignore_heap_size_of = "Arrays are cumbersome"] - image_info_array: DOMRefCell<[ImageInfo; MAX_LEVEL_COUNT * MAX_FACE_COUNT]>, + image_info_array: DomRefCell<[ImageInfo; MAX_LEVEL_COUNT * MAX_FACE_COUNT]>, /// Face count can only be 1 or 6 face_count: Cell, base_mipmap_level: u32, @@ -60,7 +60,7 @@ impl WebGLTexture { base_mipmap_level: 0, min_filter: Cell::new(None), mag_filter: Cell::new(None), - image_info_array: DOMRefCell::new([ImageInfo::new(); MAX_LEVEL_COUNT * MAX_FACE_COUNT]), + image_info_array: DomRefCell::new([ImageInfo::new(); MAX_LEVEL_COUNT * MAX_FACE_COUNT]), renderer: renderer, } } -- cgit v1.2.3 From f87c2a8d7616112ca924e30292db2d244cf87eec Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Tue, 26 Sep 2017 01:53:40 +0200 Subject: Rename Root to DomRoot In a later PR, DomRoot will become a type alias of Root>, where Root will be able to handle all the things that need to be rooted that have a stable traceable address that doesn't move for the whole lifetime of the root. Stay tuned. --- components/script/dom/webgltexture.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'components/script/dom/webgltexture.rs') diff --git a/components/script/dom/webgltexture.rs b/components/script/dom/webgltexture.rs index fe323b53efd..ec8dee28172 100644 --- a/components/script/dom/webgltexture.rs +++ b/components/script/dom/webgltexture.rs @@ -9,7 +9,7 @@ use dom::bindings::cell::DomRefCell; use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants; use dom::bindings::codegen::Bindings::WebGLTextureBinding; use dom::bindings::reflector::reflect_dom_object; -use dom::bindings::root::Root; +use dom::bindings::root::DomRoot; use dom::webgl_validations::types::{TexImageTarget, TexFormat, TexDataType}; use dom::webglobject::WebGLObject; use dom::window::Window; @@ -66,7 +66,7 @@ impl WebGLTexture { } pub fn maybe_new(window: &Window, renderer: WebGLMsgSender) - -> Option> { + -> Option> { let (sender, receiver) = webgl_channel().unwrap(); renderer.send(WebGLCommand::CreateTexture(sender)).unwrap(); @@ -77,7 +77,7 @@ impl WebGLTexture { pub fn new(window: &Window, renderer: WebGLMsgSender, id: WebGLTextureId) - -> Root { + -> DomRoot { reflect_dom_object(box WebGLTexture::new_inherited(renderer, id), window, WebGLTextureBinding::Wrap) -- cgit v1.2.3 From aa15dc269f41503d81ad44cd7e85d69e6f4aeac7 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Mon, 16 Oct 2017 14:35:30 +0200 Subject: Remove use of unstable box syntax. http://www.robohornet.org gives a score of 101.36 on master, and 102.68 with this PR. The latter is slightly better, but probably within noise level. So it looks like this PR does not affect DOM performance. This is expected since `Box::new` is defined as: ```rust impl Box { #[inline(always)] pub fn new(x: T) -> Box { box x } } ``` With inlining, it should compile to the same as box syntax. --- components/script/dom/webgltexture.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'components/script/dom/webgltexture.rs') diff --git a/components/script/dom/webgltexture.rs b/components/script/dom/webgltexture.rs index ec8dee28172..59be8681337 100644 --- a/components/script/dom/webgltexture.rs +++ b/components/script/dom/webgltexture.rs @@ -78,7 +78,7 @@ impl WebGLTexture { renderer: WebGLMsgSender, id: WebGLTextureId) -> DomRoot { - reflect_dom_object(box WebGLTexture::new_inherited(renderer, id), + reflect_dom_object(Box::new(WebGLTexture::new_inherited(renderer, id)), window, WebGLTextureBinding::Wrap) } -- cgit v1.2.3 From 8ae0739bab8a3c74e0685d9f53bbb155e4458aba Mon Sep 17 00:00:00 2001 From: Imanol Fernandez Date: Thu, 21 Sep 2017 15:16:46 +0200 Subject: Implement DOM to texture --- components/script/dom/webgltexture.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'components/script/dom/webgltexture.rs') diff --git a/components/script/dom/webgltexture.rs b/components/script/dom/webgltexture.rs index 59be8681337..6927fd10a48 100644 --- a/components/script/dom/webgltexture.rs +++ b/components/script/dom/webgltexture.rs @@ -5,6 +5,7 @@ // https://www.khronos.org/registry/webgl/specs/latest/1.0/webgl.idl use canvas_traits::webgl::{webgl_channel, WebGLCommand, WebGLError, WebGLMsgSender, WebGLResult, WebGLTextureId}; +use canvas_traits::webgl::DOMToTextureCommand; use dom::bindings::cell::DomRefCell; use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants; use dom::bindings::codegen::Bindings::WebGLTextureBinding; @@ -45,6 +46,8 @@ pub struct WebGLTexture { mag_filter: Cell>, #[ignore_heap_size_of = "Defined in ipc-channel"] renderer: WebGLMsgSender, + /// True if this texture is used for the DOMToTexture feature. + attached_to_dom: Cell, } impl WebGLTexture { @@ -62,6 +65,7 @@ impl WebGLTexture { mag_filter: Cell::new(None), image_info_array: DomRefCell::new([ImageInfo::new(); MAX_LEVEL_COUNT * MAX_FACE_COUNT]), renderer: renderer, + attached_to_dom: Cell::new(false), } } @@ -179,6 +183,10 @@ impl WebGLTexture { pub fn delete(&self) { if !self.is_deleted.get() { self.is_deleted.set(true); + // Notify WR to release the frame output when using DOMToTexture feature + if self.attached_to_dom.get() { + let _ = self.renderer.send_dom_to_texture(DOMToTextureCommand::Detach(self.id)); + } let _ = self.renderer.send(WebGLCommand::DeleteTexture(self.id)); } } @@ -374,6 +382,10 @@ impl WebGLTexture { Some(self.image_info_at_face(0, self.base_mipmap_level)) } + + pub fn set_attached_to_dom(&self) { + self.attached_to_dom.set(true); + } } impl Drop for WebGLTexture { -- cgit v1.2.3 From 4506f0d30cbbb02df32e9c16135ef288ad6b7e2e Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 18 Oct 2017 10:42:01 +1100 Subject: Replace all uses of the `heapsize` crate with `malloc_size_of`. Servo currently uses `heapsize`, but Stylo/Gecko use `malloc_size_of`. `malloc_size_of` is better -- it handles various cases that `heapsize` does not -- so this patch changes Servo to use `malloc_size_of`. This patch makes the following changes to the `malloc_size_of` crate. - Adds `MallocSizeOf` trait implementations for numerous types, some built-in (e.g. `VecDeque`), some external and Servo-only (e.g. `string_cache`). - Makes `enclosing_size_of_op` optional, because vanilla jemalloc doesn't support that operation. - For `HashSet`/`HashMap`, falls back to a computed estimate when `enclosing_size_of_op` isn't available. - Adds an extern "C" `malloc_size_of` function that does the actual heap measurement; this is based on the same functions from the `heapsize` crate. This patch makes the following changes elsewhere. - Converts all the uses of `heapsize` to instead use `malloc_size_of`. - Disables the "heapsize"/"heap_size" feature for the external crates that provide it. - Removes the `HeapSizeOf` implementation from `hashglobe`. - Adds `ignore` annotations to a few `Rc`/`Arc`, because `malloc_size_of` doesn't derive those types, unlike `heapsize`. --- components/script/dom/webgltexture.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'components/script/dom/webgltexture.rs') diff --git a/components/script/dom/webgltexture.rs b/components/script/dom/webgltexture.rs index 6927fd10a48..1336718eb00 100644 --- a/components/script/dom/webgltexture.rs +++ b/components/script/dom/webgltexture.rs @@ -36,7 +36,7 @@ pub struct WebGLTexture { target: Cell>, is_deleted: Cell, /// Stores information about mipmap levels and cubemap faces. - #[ignore_heap_size_of = "Arrays are cumbersome"] + #[ignore_malloc_size_of = "Arrays are cumbersome"] image_info_array: DomRefCell<[ImageInfo; MAX_LEVEL_COUNT * MAX_FACE_COUNT]>, /// Face count can only be 1 or 6 face_count: Cell, @@ -44,7 +44,7 @@ pub struct WebGLTexture { // Store information for min and mag filters min_filter: Cell>, mag_filter: Cell>, - #[ignore_heap_size_of = "Defined in ipc-channel"] + #[ignore_malloc_size_of = "Defined in ipc-channel"] renderer: WebGLMsgSender, /// True if this texture is used for the DOMToTexture feature. attached_to_dom: Cell, @@ -394,7 +394,7 @@ impl Drop for WebGLTexture { } } -#[derive(Clone, Copy, Debug, HeapSizeOf, JSTraceable, PartialEq)] +#[derive(Clone, Copy, Debug, JSTraceable, MallocSizeOf, PartialEq)] pub struct ImageInfo { width: u32, height: u32, -- cgit v1.2.3 From 661d234c3c8662423ee12e248c30e7d0e1dae78a Mon Sep 17 00:00:00 2001 From: janczer Date: Wed, 7 Feb 2018 09:18:59 +0100 Subject: Change debug assertions to specific ones --- components/script/dom/webgltexture.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'components/script/dom/webgltexture.rs') diff --git a/components/script/dom/webgltexture.rs b/components/script/dom/webgltexture.rs index 1336718eb00..ef980c75211 100644 --- a/components/script/dom/webgltexture.rs +++ b/components/script/dom/webgltexture.rs @@ -313,7 +313,7 @@ impl WebGLTexture { } fn is_cube_complete(&self) -> bool { - debug_assert!(self.face_count.get() == 6); + debug_assert_eq!(self.face_count.get(), 6); let image_info = self.base_image_info().unwrap(); if !image_info.is_defined() { -- cgit v1.2.3 From 68898f4ebd1a9112b7281ec766a725e24c62205e Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Mon, 9 Apr 2018 11:46:12 +0200 Subject: Fix the error emitted for invalid targets in WebGLTexture::bind It doesn't actually matter because this is only called from WebGLRenderingContext::BindTexture, which already checks the target, but better be safe than sorry. --- components/script/dom/webgltexture.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'components/script/dom/webgltexture.rs') diff --git a/components/script/dom/webgltexture.rs b/components/script/dom/webgltexture.rs index ef980c75211..45b26997bc3 100644 --- a/components/script/dom/webgltexture.rs +++ b/components/script/dom/webgltexture.rs @@ -109,7 +109,7 @@ impl WebGLTexture { let face_count = match target { constants::TEXTURE_2D => 1, constants::TEXTURE_CUBE_MAP => 6, - _ => return Err(WebGLError::InvalidOperation) + _ => return Err(WebGLError::InvalidEnum) }; self.face_count.set(face_count); self.target.set(Some(target)); -- cgit v1.2.3 From f1288cc6e0a52d377619f0ec9634eefd29ba15dc Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Fri, 25 May 2018 14:58:50 +0200 Subject: Implement EXT_texture_filter_anisotropic --- components/script/dom/webgltexture.rs | 121 ++++++++++++++++++---------------- 1 file changed, 66 insertions(+), 55 deletions(-) (limited to 'components/script/dom/webgltexture.rs') diff --git a/components/script/dom/webgltexture.rs b/components/script/dom/webgltexture.rs index 45b26997bc3..9fe77197825 100644 --- a/components/script/dom/webgltexture.rs +++ b/components/script/dom/webgltexture.rs @@ -4,8 +4,9 @@ // https://www.khronos.org/registry/webgl/specs/latest/1.0/webgl.idl -use canvas_traits::webgl::{webgl_channel, WebGLCommand, WebGLError, WebGLMsgSender, WebGLResult, WebGLTextureId}; -use canvas_traits::webgl::DOMToTextureCommand; +use canvas_traits::webgl::{DOMToTextureCommand, TexParameter, TexParameterFloat}; +use canvas_traits::webgl::{TexParameterInt, WebGLCommand, WebGLError, WebGLMsgSender}; +use canvas_traits::webgl::{WebGLResult, WebGLTextureId, webgl_channel}; use dom::bindings::cell::DomRefCell; use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants; use dom::bindings::codegen::Bindings::WebGLTextureBinding; @@ -202,65 +203,75 @@ impl WebGLTexture { /// We have to follow the conversion rules for GLES 2.0. See: /// https://www.khronos.org/webgl/public-mailing-list/archives/1008/msg00014.html /// - pub fn tex_parameter(&self, - target: u32, - name: u32, - value: TexParameterValue) -> WebGLResult<()> { - let (int_value, _float_value) = match value { + pub fn tex_parameter( + &self, + param: TexParameter, + value: TexParameterValue, + ) -> WebGLResult<()> { + let target = self.target().unwrap(); + + let (int_value, float_value) = match value { TexParameterValue::Int(int_value) => (int_value, int_value as f32), TexParameterValue::Float(float_value) => (float_value as i32, float_value), }; - match name { - constants::TEXTURE_MIN_FILTER => { - match int_value as u32 { - constants::NEAREST | - constants::LINEAR | - constants::NEAREST_MIPMAP_NEAREST | - constants::LINEAR_MIPMAP_NEAREST | - constants::NEAREST_MIPMAP_LINEAR | - constants::LINEAR_MIPMAP_LINEAR => { - self.min_filter.set(Some(int_value as u32)); - self.renderer - .send(WebGLCommand::TexParameteri(target, name, int_value)) - .unwrap(); - Ok(()) - }, - - _ => Err(WebGLError::InvalidEnum), + match param { + TexParameter::Int(int_param) => { + match int_param { + TexParameterInt::TextureMinFilter => { + match int_value as u32 { + constants::NEAREST | + constants::LINEAR | + constants::NEAREST_MIPMAP_NEAREST | + constants::LINEAR_MIPMAP_NEAREST | + constants::NEAREST_MIPMAP_LINEAR | + constants::LINEAR_MIPMAP_LINEAR => { + self.min_filter.set(Some(int_value as u32)); + self.renderer + .send(WebGLCommand::TexParameteri(target, int_param, int_value)) + .unwrap(); + Ok(()) + } + _ => Err(WebGLError::InvalidEnum), + } + } + TexParameterInt::TextureMagFilter => { + match int_value as u32 { + constants::NEAREST | constants::LINEAR => { + self.mag_filter.set(Some(int_value as u32)); + self.renderer + .send(WebGLCommand::TexParameteri(target, int_param, int_value)) + .unwrap(); + Ok(()) + } + _ => return Err(WebGLError::InvalidEnum), + } + } + TexParameterInt::TextureWrapS | TexParameterInt::TextureWrapT => { + match int_value as u32 { + constants::CLAMP_TO_EDGE | + constants::MIRRORED_REPEAT | + constants::REPEAT => { + self.renderer + .send(WebGLCommand::TexParameteri(target, int_param, int_value)) + .unwrap(); + Ok(()) + } + _ => Err(WebGLError::InvalidEnum), + } + } } - }, - constants::TEXTURE_MAG_FILTER => { - match int_value as u32 { - constants::NEAREST | - constants::LINEAR => { - self.mag_filter.set(Some(int_value as u32)); - self.renderer - .send(WebGLCommand::TexParameteri(target, name, int_value)) - .unwrap(); - Ok(()) - }, - - _ => Err(WebGLError::InvalidEnum), - } - }, - constants::TEXTURE_WRAP_S | - constants::TEXTURE_WRAP_T => { - match int_value as u32 { - constants::CLAMP_TO_EDGE | - constants::MIRRORED_REPEAT | - constants::REPEAT => { - self.renderer - .send(WebGLCommand::TexParameteri(target, name, int_value)) - .unwrap(); - Ok(()) - }, - - _ => Err(WebGLError::InvalidEnum), + } + TexParameter::Float(float_param @ TexParameterFloat::TextureMaxAnisotropyExt) => { + if float_value >= 1. { + self.renderer + .send(WebGLCommand::TexParameterf(target, float_param, float_value)) + .unwrap(); + Ok(()) + } else { + Err(WebGLError::InvalidValue) } - }, - - _ => Err(WebGLError::InvalidEnum), + } } } -- cgit v1.2.3 From 661e258b28fd7dcc92ab233f66bf49c061542865 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Tue, 24 Jul 2018 13:27:33 +0200 Subject: Store a reference to the WebGLRenderingContext in WebGLObject --- components/script/dom/webgltexture.rs | 80 +++++++++++++++++------------------ 1 file changed, 39 insertions(+), 41 deletions(-) (limited to 'components/script/dom/webgltexture.rs') diff --git a/components/script/dom/webgltexture.rs b/components/script/dom/webgltexture.rs index 9fe77197825..60c8487676b 100644 --- a/components/script/dom/webgltexture.rs +++ b/components/script/dom/webgltexture.rs @@ -5,16 +5,17 @@ // https://www.khronos.org/registry/webgl/specs/latest/1.0/webgl.idl use canvas_traits::webgl::{DOMToTextureCommand, TexParameter, TexParameterFloat}; -use canvas_traits::webgl::{TexParameterInt, WebGLCommand, WebGLError, WebGLMsgSender}; +use canvas_traits::webgl::{TexParameterInt, WebGLCommand, WebGLError}; use canvas_traits::webgl::{WebGLResult, WebGLTextureId, webgl_channel}; use dom::bindings::cell::DomRefCell; use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants; use dom::bindings::codegen::Bindings::WebGLTextureBinding; -use dom::bindings::reflector::reflect_dom_object; +use dom::bindings::inheritance::Castable; +use dom::bindings::reflector::{DomObject, reflect_dom_object}; use dom::bindings::root::DomRoot; use dom::webgl_validations::types::{TexImageTarget, TexFormat, TexDataType}; use dom::webglobject::WebGLObject; -use dom::window::Window; +use dom::webglrenderingcontext::WebGLRenderingContext; use dom_struct::dom_struct; use std::cell::Cell; use std::cmp; @@ -45,18 +46,14 @@ pub struct WebGLTexture { // Store information for min and mag filters min_filter: Cell>, mag_filter: Cell>, - #[ignore_malloc_size_of = "Defined in ipc-channel"] - renderer: WebGLMsgSender, /// True if this texture is used for the DOMToTexture feature. attached_to_dom: Cell, } impl WebGLTexture { - fn new_inherited(renderer: WebGLMsgSender, - id: WebGLTextureId) - -> WebGLTexture { - WebGLTexture { - webgl_object: WebGLObject::new_inherited(), + fn new_inherited(context: &WebGLRenderingContext, id: WebGLTextureId) -> Self { + Self { + webgl_object: WebGLObject::new_inherited(context), id: id, target: Cell::new(None), is_deleted: Cell::new(false), @@ -65,27 +62,22 @@ impl WebGLTexture { min_filter: Cell::new(None), mag_filter: Cell::new(None), image_info_array: DomRefCell::new([ImageInfo::new(); MAX_LEVEL_COUNT * MAX_FACE_COUNT]), - renderer: renderer, attached_to_dom: Cell::new(false), } } - pub fn maybe_new(window: &Window, renderer: WebGLMsgSender) - -> Option> { + pub fn maybe_new(context: &WebGLRenderingContext) -> Option> { let (sender, receiver) = webgl_channel().unwrap(); - renderer.send(WebGLCommand::CreateTexture(sender)).unwrap(); - - let result = receiver.recv().unwrap(); - result.map(|texture_id| WebGLTexture::new(window, renderer, texture_id)) + context.send_command(WebGLCommand::CreateTexture(sender)); + receiver.recv().unwrap().map(|id| WebGLTexture::new(context, id)) } - pub fn new(window: &Window, - renderer: WebGLMsgSender, - id: WebGLTextureId) - -> DomRoot { - reflect_dom_object(Box::new(WebGLTexture::new_inherited(renderer, id)), - window, - WebGLTextureBinding::Wrap) + pub fn new(context: &WebGLRenderingContext, id: WebGLTextureId) -> DomRoot { + reflect_dom_object( + Box::new(WebGLTexture::new_inherited(context, id)), + &*context.global(), + WebGLTextureBinding::Wrap, + ) } } @@ -116,8 +108,9 @@ impl WebGLTexture { self.target.set(Some(target)); } - let msg = WebGLCommand::BindTexture(target, Some(self.id)); - self.renderer.send(msg).unwrap(); + self.upcast::() + .context() + .send_command(WebGLCommand::BindTexture(target, Some(self.id))); Ok(()) } @@ -171,7 +164,9 @@ impl WebGLTexture { return Err(WebGLError::InvalidOperation); } - self.renderer.send(WebGLCommand::GenerateMipmap(target)).unwrap(); + self.upcast::() + .context() + .send_command(WebGLCommand::GenerateMipmap(target)); if self.base_mipmap_level + base_image_info.get_max_mimap_levels() == 0 { return Err(WebGLError::InvalidOperation); @@ -184,11 +179,14 @@ impl WebGLTexture { pub fn delete(&self) { if !self.is_deleted.get() { self.is_deleted.set(true); + let context = self.upcast::().context(); // Notify WR to release the frame output when using DOMToTexture feature if self.attached_to_dom.get() { - let _ = self.renderer.send_dom_to_texture(DOMToTextureCommand::Detach(self.id)); + let _ = context.webgl_sender().send_dom_to_texture( + DOMToTextureCommand::Detach(self.id), + ); } - let _ = self.renderer.send(WebGLCommand::DeleteTexture(self.id)); + context.send_command(WebGLCommand::DeleteTexture(self.id)); } } @@ -227,9 +225,9 @@ impl WebGLTexture { constants::NEAREST_MIPMAP_LINEAR | constants::LINEAR_MIPMAP_LINEAR => { self.min_filter.set(Some(int_value as u32)); - self.renderer - .send(WebGLCommand::TexParameteri(target, int_param, int_value)) - .unwrap(); + self.upcast::() + .context() + .send_command(WebGLCommand::TexParameteri(target, int_param, int_value)); Ok(()) } _ => Err(WebGLError::InvalidEnum), @@ -239,9 +237,9 @@ impl WebGLTexture { match int_value as u32 { constants::NEAREST | constants::LINEAR => { self.mag_filter.set(Some(int_value as u32)); - self.renderer - .send(WebGLCommand::TexParameteri(target, int_param, int_value)) - .unwrap(); + self.upcast::() + .context() + .send_command(WebGLCommand::TexParameteri(target, int_param, int_value)); Ok(()) } _ => return Err(WebGLError::InvalidEnum), @@ -252,9 +250,9 @@ impl WebGLTexture { constants::CLAMP_TO_EDGE | constants::MIRRORED_REPEAT | constants::REPEAT => { - self.renderer - .send(WebGLCommand::TexParameteri(target, int_param, int_value)) - .unwrap(); + self.upcast::() + .context() + .send_command(WebGLCommand::TexParameteri(target, int_param, int_value)); Ok(()) } _ => Err(WebGLError::InvalidEnum), @@ -264,9 +262,9 @@ impl WebGLTexture { } TexParameter::Float(float_param @ TexParameterFloat::TextureMaxAnisotropyExt) => { if float_value >= 1. { - self.renderer - .send(WebGLCommand::TexParameterf(target, float_param, float_value)) - .unwrap(); + self.upcast::() + .context() + .send_command(WebGLCommand::TexParameterf(target, float_param, float_value)); Ok(()) } else { Err(WebGLError::InvalidValue) -- cgit v1.2.3 From 9e912be4ea0b04f69987cf456ed126943f02abd8 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Thu, 2 Aug 2018 15:53:19 +0200 Subject: Properly set initial values for WebGL texture filters --- components/script/dom/webgltexture.rs | 42 +++++++++++++++++------------------ 1 file changed, 20 insertions(+), 22 deletions(-) (limited to 'components/script/dom/webgltexture.rs') diff --git a/components/script/dom/webgltexture.rs b/components/script/dom/webgltexture.rs index 60c8487676b..b78709da1eb 100644 --- a/components/script/dom/webgltexture.rs +++ b/components/script/dom/webgltexture.rs @@ -44,8 +44,8 @@ pub struct WebGLTexture { face_count: Cell, base_mipmap_level: u32, // Store information for min and mag filters - min_filter: Cell>, - mag_filter: Cell>, + min_filter: Cell, + mag_filter: Cell, /// True if this texture is used for the DOMToTexture feature. attached_to_dom: Cell, } @@ -59,8 +59,8 @@ impl WebGLTexture { is_deleted: Cell::new(false), face_count: Cell::new(0), base_mipmap_level: 0, - min_filter: Cell::new(None), - mag_filter: Cell::new(None), + min_filter: Cell::new(constants::NEAREST_MIPMAP_LINEAR), + mag_filter: Cell::new(constants::LINEAR), image_info_array: DomRefCell::new([ImageInfo::new(); MAX_LEVEL_COUNT * MAX_FACE_COUNT]), attached_to_dom: Cell::new(false), } @@ -215,6 +215,16 @@ impl WebGLTexture { match param { TexParameter::Int(int_param) => { + let update_filter = |filter: &Cell| { + if filter.get() == int_value as u32 { + return Ok(()); + } + filter.set(int_value as u32); + self.upcast::() + .context() + .send_command(WebGLCommand::TexParameteri(target, int_param, int_value)); + Ok(()) + }; match int_param { TexParameterInt::TextureMinFilter => { match int_value as u32 { @@ -223,25 +233,13 @@ impl WebGLTexture { constants::NEAREST_MIPMAP_NEAREST | constants::LINEAR_MIPMAP_NEAREST | constants::NEAREST_MIPMAP_LINEAR | - constants::LINEAR_MIPMAP_LINEAR => { - self.min_filter.set(Some(int_value as u32)); - self.upcast::() - .context() - .send_command(WebGLCommand::TexParameteri(target, int_param, int_value)); - Ok(()) - } + constants::LINEAR_MIPMAP_LINEAR => update_filter(&self.min_filter), _ => Err(WebGLError::InvalidEnum), } } TexParameterInt::TextureMagFilter => { match int_value as u32 { - constants::NEAREST | constants::LINEAR => { - self.mag_filter.set(Some(int_value as u32)); - self.upcast::() - .context() - .send_command(WebGLCommand::TexParameteri(target, int_param, int_value)); - Ok(()) - } + constants::NEAREST | constants::LINEAR => update_filter(&self.mag_filter), _ => return Err(WebGLError::InvalidEnum), } } @@ -277,10 +275,10 @@ impl WebGLTexture { let filters = [self.min_filter.get(), self.mag_filter.get()]; filters.iter().any(|filter| { match *filter { - Some(constants::LINEAR) | - Some(constants::NEAREST_MIPMAP_LINEAR) | - Some(constants::LINEAR_MIPMAP_NEAREST) | - Some(constants::LINEAR_MIPMAP_LINEAR) => true, + constants::LINEAR | + constants::NEAREST_MIPMAP_LINEAR | + constants::LINEAR_MIPMAP_NEAREST | + constants::LINEAR_MIPMAP_LINEAR => true, _=> false } }) -- cgit v1.2.3 From f7124886bc64158dd2ce2487a1f98990e157f3fe Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Thu, 2 Aug 2018 17:42:12 +0200 Subject: Use the DOM cache for gl.getTexParameter(gl.TEXTURE_*_FILTER) Part of #20596. --- components/script/dom/webgltexture.rs | 109 ++++++++++++++++++---------------- 1 file changed, 57 insertions(+), 52 deletions(-) (limited to 'components/script/dom/webgltexture.rs') diff --git a/components/script/dom/webgltexture.rs b/components/script/dom/webgltexture.rs index b78709da1eb..2ecfd0bfab2 100644 --- a/components/script/dom/webgltexture.rs +++ b/components/script/dom/webgltexture.rs @@ -4,10 +4,10 @@ // https://www.khronos.org/registry/webgl/specs/latest/1.0/webgl.idl -use canvas_traits::webgl::{DOMToTextureCommand, TexParameter, TexParameterFloat}; -use canvas_traits::webgl::{TexParameterInt, WebGLCommand, WebGLError}; +use canvas_traits::webgl::{DOMToTextureCommand, WebGLCommand, WebGLError}; use canvas_traits::webgl::{WebGLResult, WebGLTextureId, webgl_channel}; use dom::bindings::cell::DomRefCell; +use dom::bindings::codegen::Bindings::EXTTextureFilterAnisotropicBinding::EXTTextureFilterAnisotropicConstants; use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants; use dom::bindings::codegen::Bindings::WebGLTextureBinding; use dom::bindings::inheritance::Castable; @@ -203,7 +203,7 @@ impl WebGLTexture { /// pub fn tex_parameter( &self, - param: TexParameter, + param: u32, value: TexParameterValue, ) -> WebGLResult<()> { let target = self.target().unwrap(); @@ -213,64 +213,69 @@ impl WebGLTexture { TexParameterValue::Float(float_value) => (float_value as i32, float_value), }; + let update_filter = |filter: &Cell| { + if filter.get() == int_value as u32 { + return Ok(()); + } + filter.set(int_value as u32); + self.upcast::() + .context() + .send_command(WebGLCommand::TexParameteri(target, param, int_value)); + Ok(()) + }; match param { - TexParameter::Int(int_param) => { - let update_filter = |filter: &Cell| { - if filter.get() == int_value as u32 { - return Ok(()); - } - filter.set(int_value as u32); - self.upcast::() - .context() - .send_command(WebGLCommand::TexParameteri(target, int_param, int_value)); - Ok(()) - }; - match int_param { - TexParameterInt::TextureMinFilter => { - match int_value as u32 { - constants::NEAREST | - constants::LINEAR | - constants::NEAREST_MIPMAP_NEAREST | - constants::LINEAR_MIPMAP_NEAREST | - constants::NEAREST_MIPMAP_LINEAR | - constants::LINEAR_MIPMAP_LINEAR => update_filter(&self.min_filter), - _ => Err(WebGLError::InvalidEnum), - } - } - TexParameterInt::TextureMagFilter => { - match int_value as u32 { - constants::NEAREST | constants::LINEAR => update_filter(&self.mag_filter), - _ => return Err(WebGLError::InvalidEnum), - } - } - TexParameterInt::TextureWrapS | TexParameterInt::TextureWrapT => { - match int_value as u32 { - constants::CLAMP_TO_EDGE | - constants::MIRRORED_REPEAT | - constants::REPEAT => { - self.upcast::() - .context() - .send_command(WebGLCommand::TexParameteri(target, int_param, int_value)); - Ok(()) - } - _ => Err(WebGLError::InvalidEnum), - } + constants::TEXTURE_MIN_FILTER => { + match int_value as u32 { + constants::NEAREST | + constants::LINEAR | + constants::NEAREST_MIPMAP_NEAREST | + constants::LINEAR_MIPMAP_NEAREST | + constants::NEAREST_MIPMAP_LINEAR | + constants::LINEAR_MIPMAP_LINEAR => update_filter(&self.min_filter), + _ => Err(WebGLError::InvalidEnum), + } + } + constants::TEXTURE_MAG_FILTER => { + match int_value as u32 { + constants::NEAREST | constants::LINEAR => update_filter(&self.mag_filter), + _ => return Err(WebGLError::InvalidEnum), + } + } + constants::TEXTURE_WRAP_S | constants::TEXTURE_WRAP_T => { + match int_value as u32 { + constants::CLAMP_TO_EDGE | + constants::MIRRORED_REPEAT | + constants::REPEAT => { + self.upcast::() + .context() + .send_command(WebGLCommand::TexParameteri(target, param, int_value)); + Ok(()) } + _ => Err(WebGLError::InvalidEnum), } } - TexParameter::Float(float_param @ TexParameterFloat::TextureMaxAnisotropyExt) => { - if float_value >= 1. { - self.upcast::() - .context() - .send_command(WebGLCommand::TexParameterf(target, float_param, float_value)); - Ok(()) - } else { - Err(WebGLError::InvalidValue) + EXTTextureFilterAnisotropicConstants::TEXTURE_MAX_ANISOTROPY_EXT => { + // NaN is not less than 1., what a time to be alive. + if !(float_value >= 1.) { + return Err(WebGLError::InvalidValue); } + self.upcast::() + .context() + .send_command(WebGLCommand::TexParameterf(target, param, float_value)); + Ok(()) } + _ => Err(WebGLError::InvalidEnum), } } + pub fn min_filter(&self) -> u32 { + self.min_filter.get() + } + + pub fn mag_filter(&self) -> u32 { + self.mag_filter.get() + } + pub fn is_using_linear_filtering(&self) -> bool { let filters = [self.min_filter.get(), self.mag_filter.get()]; filters.iter().any(|filter| { -- cgit v1.2.3 From 03f6ce292eee9fe2ad62129fcb48ee74213436c1 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Wed, 15 Aug 2018 13:13:26 -0400 Subject: webgl: Remove unnecessary Option from texture API. --- components/script/dom/webgltexture.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'components/script/dom/webgltexture.rs') diff --git a/components/script/dom/webgltexture.rs b/components/script/dom/webgltexture.rs index 2ecfd0bfab2..83378519848 100644 --- a/components/script/dom/webgltexture.rs +++ b/components/script/dom/webgltexture.rs @@ -146,7 +146,7 @@ impl WebGLTexture { } }; - let base_image_info = self.base_image_info().unwrap(); + let base_image_info = self.base_image_info(); if !base_image_info.is_initialized() { return Err(WebGLError::InvalidOperation); } @@ -327,7 +327,7 @@ impl WebGLTexture { fn is_cube_complete(&self) -> bool { debug_assert_eq!(self.face_count.get(), 6); - let image_info = self.base_image_info().unwrap(); + let image_info = self.base_image_info(); if !image_info.is_defined() { return false; } @@ -389,10 +389,10 @@ impl WebGLTexture { self.image_info_array.borrow_mut()[pos as usize] = image_info; } - fn base_image_info(&self) -> Option { + fn base_image_info(&self) -> ImageInfo { assert!((self.base_mipmap_level as usize) < MAX_LEVEL_COUNT); - Some(self.image_info_at_face(0, self.base_mipmap_level)) + self.image_info_at_face(0, self.base_mipmap_level) } pub fn set_attached_to_dom(&self) { -- cgit v1.2.3 From bb8d9ba74c024a317fbbd49811541632404ef51c Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Fri, 24 Aug 2018 16:10:28 -0400 Subject: webgl: Ensure that depth and stencil attachments are rebound after messing with DEPTH_STENCIL attachments. --- components/script/dom/webgltexture.rs | 43 ++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) (limited to 'components/script/dom/webgltexture.rs') diff --git a/components/script/dom/webgltexture.rs b/components/script/dom/webgltexture.rs index 83378519848..4d085d51442 100644 --- a/components/script/dom/webgltexture.rs +++ b/components/script/dom/webgltexture.rs @@ -12,8 +12,9 @@ use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderi use dom::bindings::codegen::Bindings::WebGLTextureBinding; use dom::bindings::inheritance::Castable; use dom::bindings::reflector::{DomObject, reflect_dom_object}; -use dom::bindings::root::DomRoot; +use dom::bindings::root::{Dom, DomRoot}; use dom::webgl_validations::types::{TexImageTarget, TexFormat, TexDataType}; +use dom::webglframebuffer::WebGLFramebuffer; use dom::webglobject::WebGLObject; use dom::webglrenderingcontext::WebGLRenderingContext; use dom_struct::dom_struct; @@ -48,6 +49,8 @@ pub struct WebGLTexture { mag_filter: Cell, /// True if this texture is used for the DOMToTexture feature. attached_to_dom: Cell, + // Framebuffer that this texture is attached to. + attached_framebuffers: DomRefCell>>, } impl WebGLTexture { @@ -63,6 +66,7 @@ impl WebGLTexture { mag_filter: Cell::new(constants::LINEAR), image_info_array: DomRefCell::new([ImageInfo::new(); MAX_LEVEL_COUNT * MAX_FACE_COUNT]), attached_to_dom: Cell::new(false), + attached_framebuffers: Default::default(), } } @@ -186,6 +190,29 @@ impl WebGLTexture { DOMToTextureCommand::Detach(self.id), ); } + + /* + If a texture object is deleted while its image is attached to the currently + bound framebuffer, then it is as if FramebufferTexture2D had been called, with + a texture of 0, for each attachment point to which this image was attached + in the currently bound framebuffer. + - GLES 2.0, 4.4.3, "Attaching Texture Images to a Framebuffer" + */ + let currently_bound_framebuffer = + self.upcast::() + .context() + .bound_framebuffer() + .map_or(0, |fb| fb.id().get()); + let current_framebuffer = + self.attached_framebuffers + .borrow() + .iter() + .position(|fb| fb.id().get() == currently_bound_framebuffer); + if let Some(fb_index) = current_framebuffer { + self.attached_framebuffers.borrow()[fb_index].detach_texture(self); + self.attached_framebuffers.borrow_mut().remove(fb_index); + } + context.send_command(WebGLCommand::DeleteTexture(self.id)); } } @@ -398,6 +425,20 @@ impl WebGLTexture { pub fn set_attached_to_dom(&self) { self.attached_to_dom.set(true); } + + pub fn attach(&self, framebuffer: &WebGLFramebuffer) { + self.attached_framebuffers.borrow_mut().push(Dom::from_ref(framebuffer)); + } + + pub fn unattach(&self, fb: &WebGLFramebuffer) { + let mut attached_framebuffers = self.attached_framebuffers.borrow_mut(); + let idx = attached_framebuffers.iter().position(|attached| { + attached.id() == fb.id() + }); + if let Some(idx) = idx { + attached_framebuffers.remove(idx); + } + } } impl Drop for WebGLTexture { -- cgit v1.2.3 From 4edb7b194c99a1d394dddaeac2f5064ed8e93f62 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Mon, 10 Sep 2018 16:27:58 -0400 Subject: webgl: Remove knowledge of attached framebuffers from renderbuffers and textures. --- components/script/dom/webgltexture.rs | 33 ++++----------------------------- 1 file changed, 4 insertions(+), 29 deletions(-) (limited to 'components/script/dom/webgltexture.rs') diff --git a/components/script/dom/webgltexture.rs b/components/script/dom/webgltexture.rs index 4d085d51442..4d8e58380f7 100644 --- a/components/script/dom/webgltexture.rs +++ b/components/script/dom/webgltexture.rs @@ -12,9 +12,8 @@ use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderi use dom::bindings::codegen::Bindings::WebGLTextureBinding; use dom::bindings::inheritance::Castable; use dom::bindings::reflector::{DomObject, reflect_dom_object}; -use dom::bindings::root::{Dom, DomRoot}; +use dom::bindings::root::DomRoot; use dom::webgl_validations::types::{TexImageTarget, TexFormat, TexDataType}; -use dom::webglframebuffer::WebGLFramebuffer; use dom::webglobject::WebGLObject; use dom::webglrenderingcontext::WebGLRenderingContext; use dom_struct::dom_struct; @@ -49,8 +48,6 @@ pub struct WebGLTexture { mag_filter: Cell, /// True if this texture is used for the DOMToTexture feature. attached_to_dom: Cell, - // Framebuffer that this texture is attached to. - attached_framebuffers: DomRefCell>>, } impl WebGLTexture { @@ -66,7 +63,6 @@ impl WebGLTexture { mag_filter: Cell::new(constants::LINEAR), image_info_array: DomRefCell::new([ImageInfo::new(); MAX_LEVEL_COUNT * MAX_FACE_COUNT]), attached_to_dom: Cell::new(false), - attached_framebuffers: Default::default(), } } @@ -201,16 +197,9 @@ impl WebGLTexture { let currently_bound_framebuffer = self.upcast::() .context() - .bound_framebuffer() - .map_or(0, |fb| fb.id().get()); - let current_framebuffer = - self.attached_framebuffers - .borrow() - .iter() - .position(|fb| fb.id().get() == currently_bound_framebuffer); - if let Some(fb_index) = current_framebuffer { - self.attached_framebuffers.borrow()[fb_index].detach_texture(self); - self.attached_framebuffers.borrow_mut().remove(fb_index); + .bound_framebuffer(); + if let Some(fb) = currently_bound_framebuffer { + fb.detach_texture(self); } context.send_command(WebGLCommand::DeleteTexture(self.id)); @@ -425,20 +414,6 @@ impl WebGLTexture { pub fn set_attached_to_dom(&self) { self.attached_to_dom.set(true); } - - pub fn attach(&self, framebuffer: &WebGLFramebuffer) { - self.attached_framebuffers.borrow_mut().push(Dom::from_ref(framebuffer)); - } - - pub fn unattach(&self, fb: &WebGLFramebuffer) { - let mut attached_framebuffers = self.attached_framebuffers.borrow_mut(); - let idx = attached_framebuffers.iter().position(|attached| { - attached.id() == fb.id() - }); - if let Some(idx) = idx { - attached_framebuffers.remove(idx); - } - } } impl Drop for WebGLTexture { -- cgit v1.2.3 From c37a345dc9f4dda6ea29c42f96f6c7201c42cbac Mon Sep 17 00:00:00 2001 From: chansuke Date: Tue, 18 Sep 2018 23:24:15 +0900 Subject: Format script component --- components/script/dom/webgltexture.rs | 128 +++++++++++++++------------------- 1 file changed, 57 insertions(+), 71 deletions(-) (limited to 'components/script/dom/webgltexture.rs') diff --git a/components/script/dom/webgltexture.rs b/components/script/dom/webgltexture.rs index 4d8e58380f7..7037656ed5c 100644 --- a/components/script/dom/webgltexture.rs +++ b/components/script/dom/webgltexture.rs @@ -69,7 +69,10 @@ impl WebGLTexture { pub fn maybe_new(context: &WebGLRenderingContext) -> Option> { let (sender, receiver) = webgl_channel().unwrap(); context.send_command(WebGLCommand::CreateTexture(sender)); - receiver.recv().unwrap().map(|id| WebGLTexture::new(context, id)) + receiver + .recv() + .unwrap() + .map(|id| WebGLTexture::new(context, id)) } pub fn new(context: &WebGLRenderingContext, id: WebGLTextureId) -> DomRoot { @@ -81,7 +84,6 @@ impl WebGLTexture { } } - impl WebGLTexture { pub fn id(&self) -> WebGLTextureId { self.id @@ -102,7 +104,7 @@ impl WebGLTexture { let face_count = match target { constants::TEXTURE_2D => 1, constants::TEXTURE_CUBE_MAP => 6, - _ => return Err(WebGLError::InvalidEnum) + _ => return Err(WebGLError::InvalidEnum), }; self.face_count.set(face_count); self.target.set(Some(target)); @@ -115,14 +117,16 @@ impl WebGLTexture { Ok(()) } - pub fn initialize(&self, - target: TexImageTarget, - width: u32, - height: u32, - depth: u32, - internal_format: TexFormat, - level: u32, - data_type: Option) -> WebGLResult<()> { + pub fn initialize( + &self, + target: TexImageTarget, + width: u32, + height: u32, + depth: u32, + internal_format: TexFormat, + level: u32, + data_type: Option, + ) -> WebGLResult<()> { let image_info = ImageInfo { width: width, height: height, @@ -143,7 +147,7 @@ impl WebGLTexture { None => { error!("Cannot generate mipmap on texture that has no target!"); return Err(WebGLError::InvalidOperation); - } + }, }; let base_image_info = self.base_image_info(); @@ -182,9 +186,9 @@ impl WebGLTexture { let context = self.upcast::().context(); // Notify WR to release the frame output when using DOMToTexture feature if self.attached_to_dom.get() { - let _ = context.webgl_sender().send_dom_to_texture( - DOMToTextureCommand::Detach(self.id), - ); + let _ = context + .webgl_sender() + .send_dom_to_texture(DOMToTextureCommand::Detach(self.id)); } /* @@ -195,9 +199,7 @@ impl WebGLTexture { - GLES 2.0, 4.4.3, "Attaching Texture Images to a Framebuffer" */ let currently_bound_framebuffer = - self.upcast::() - .context() - .bound_framebuffer(); + self.upcast::().context().bound_framebuffer(); if let Some(fb) = currently_bound_framebuffer { fb.detach_texture(self); } @@ -217,11 +219,7 @@ impl WebGLTexture { /// We have to follow the conversion rules for GLES 2.0. See: /// https://www.khronos.org/webgl/public-mailing-list/archives/1008/msg00014.html /// - pub fn tex_parameter( - &self, - param: u32, - value: TexParameterValue, - ) -> WebGLResult<()> { + pub fn tex_parameter(&self, param: u32, value: TexParameterValue) -> WebGLResult<()> { let target = self.target().unwrap(); let (int_value, float_value) = match value { @@ -240,36 +238,28 @@ impl WebGLTexture { Ok(()) }; match param { - constants::TEXTURE_MIN_FILTER => { - match int_value as u32 { - constants::NEAREST | - constants::LINEAR | - constants::NEAREST_MIPMAP_NEAREST | - constants::LINEAR_MIPMAP_NEAREST | - constants::NEAREST_MIPMAP_LINEAR | - constants::LINEAR_MIPMAP_LINEAR => update_filter(&self.min_filter), - _ => Err(WebGLError::InvalidEnum), - } - } - constants::TEXTURE_MAG_FILTER => { - match int_value as u32 { - constants::NEAREST | constants::LINEAR => update_filter(&self.mag_filter), - _ => return Err(WebGLError::InvalidEnum), - } - } - constants::TEXTURE_WRAP_S | constants::TEXTURE_WRAP_T => { - match int_value as u32 { - constants::CLAMP_TO_EDGE | - constants::MIRRORED_REPEAT | - constants::REPEAT => { - self.upcast::() - .context() - .send_command(WebGLCommand::TexParameteri(target, param, int_value)); - Ok(()) - } - _ => Err(WebGLError::InvalidEnum), - } - } + constants::TEXTURE_MIN_FILTER => match int_value as u32 { + constants::NEAREST | + constants::LINEAR | + constants::NEAREST_MIPMAP_NEAREST | + constants::LINEAR_MIPMAP_NEAREST | + constants::NEAREST_MIPMAP_LINEAR | + constants::LINEAR_MIPMAP_LINEAR => update_filter(&self.min_filter), + _ => Err(WebGLError::InvalidEnum), + }, + constants::TEXTURE_MAG_FILTER => match int_value as u32 { + constants::NEAREST | constants::LINEAR => update_filter(&self.mag_filter), + _ => return Err(WebGLError::InvalidEnum), + }, + constants::TEXTURE_WRAP_S | constants::TEXTURE_WRAP_T => match int_value as u32 { + constants::CLAMP_TO_EDGE | constants::MIRRORED_REPEAT | constants::REPEAT => { + self.upcast::() + .context() + .send_command(WebGLCommand::TexParameteri(target, param, int_value)); + Ok(()) + }, + _ => Err(WebGLError::InvalidEnum), + }, EXTTextureFilterAnisotropicConstants::TEXTURE_MAX_ANISOTROPY_EXT => { // NaN is not less than 1., what a time to be alive. if !(float_value >= 1.) { @@ -279,7 +269,7 @@ impl WebGLTexture { .context() .send_command(WebGLCommand::TexParameterf(target, param, float_value)); Ok(()) - } + }, _ => Err(WebGLError::InvalidEnum), } } @@ -294,14 +284,12 @@ impl WebGLTexture { pub fn is_using_linear_filtering(&self) -> bool { let filters = [self.min_filter.get(), self.mag_filter.get()]; - filters.iter().any(|filter| { - match *filter { - constants::LINEAR | - constants::NEAREST_MIPMAP_LINEAR | - constants::LINEAR_MIPMAP_NEAREST | - constants::LINEAR_MIPMAP_LINEAR => true, - _=> false - } + filters.iter().any(|filter| match *filter { + constants::LINEAR | + constants::NEAREST_MIPMAP_LINEAR | + constants::LINEAR_MIPMAP_NEAREST | + constants::LINEAR_MIPMAP_LINEAR => true, + _ => false, }) } @@ -359,8 +347,9 @@ impl WebGLTexture { // Compares height with width to enforce square dimensions if current_image_info.internal_format != ref_format || - current_image_info.width != ref_width || - current_image_info.height != ref_width { + current_image_info.width != ref_width || + current_image_info.height != ref_width + { return false; } } @@ -368,8 +357,7 @@ impl WebGLTexture { true } - fn face_index_for_target(&self, - target: &TexImageTarget) -> u8 { + fn face_index_for_target(&self, target: &TexImageTarget) -> u8 { match *target { TexImageTarget::Texture2D => 0, TexImageTarget::CubeMapPositiveX => 0, @@ -381,9 +369,7 @@ impl WebGLTexture { } } - pub fn image_info_for_target(&self, - target: &TexImageTarget, - level: u32) -> ImageInfo { + pub fn image_info_for_target(&self, target: &TexImageTarget, level: u32) -> ImageInfo { let face_index = self.face_index_for_target(&target); self.image_info_at_face(face_index, level) } @@ -462,8 +448,8 @@ impl ImageInfo { fn is_power_of_two(&self) -> bool { self.width.is_power_of_two() && - self.height.is_power_of_two() && - self.depth.is_power_of_two() + self.height.is_power_of_two() && + self.depth.is_power_of_two() } pub fn is_initialized(&self) -> bool { -- cgit v1.2.3 From 45f7199eee82c66637ec68287eafa40a651001c4 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Thu, 1 Nov 2018 23:45:06 +0100 Subject: `cargo fix --edition` --- components/script/dom/webgltexture.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'components/script/dom/webgltexture.rs') diff --git a/components/script/dom/webgltexture.rs b/components/script/dom/webgltexture.rs index 7037656ed5c..443c5d031a1 100644 --- a/components/script/dom/webgltexture.rs +++ b/components/script/dom/webgltexture.rs @@ -6,16 +6,16 @@ use canvas_traits::webgl::{DOMToTextureCommand, WebGLCommand, WebGLError}; use canvas_traits::webgl::{WebGLResult, WebGLTextureId, webgl_channel}; -use dom::bindings::cell::DomRefCell; -use dom::bindings::codegen::Bindings::EXTTextureFilterAnisotropicBinding::EXTTextureFilterAnisotropicConstants; -use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants; -use dom::bindings::codegen::Bindings::WebGLTextureBinding; -use dom::bindings::inheritance::Castable; -use dom::bindings::reflector::{DomObject, reflect_dom_object}; -use dom::bindings::root::DomRoot; -use dom::webgl_validations::types::{TexImageTarget, TexFormat, TexDataType}; -use dom::webglobject::WebGLObject; -use dom::webglrenderingcontext::WebGLRenderingContext; +use crate::dom::bindings::cell::DomRefCell; +use crate::dom::bindings::codegen::Bindings::EXTTextureFilterAnisotropicBinding::EXTTextureFilterAnisotropicConstants; +use crate::dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants; +use crate::dom::bindings::codegen::Bindings::WebGLTextureBinding; +use crate::dom::bindings::inheritance::Castable; +use crate::dom::bindings::reflector::{DomObject, reflect_dom_object}; +use crate::dom::bindings::root::DomRoot; +use crate::dom::webgl_validations::types::{TexImageTarget, TexFormat, TexDataType}; +use crate::dom::webglobject::WebGLObject; +use crate::dom::webglrenderingcontext::WebGLRenderingContext; use dom_struct::dom_struct; use std::cell::Cell; use std::cmp; -- cgit v1.2.3 From 9e92eb205a2a12fe0be883e42cb7f82deebc9031 Mon Sep 17 00:00:00 2001 From: Pyfisch Date: Tue, 6 Nov 2018 20:38:02 +0100 Subject: Reorder imports --- components/script/dom/webgltexture.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'components/script/dom/webgltexture.rs') diff --git a/components/script/dom/webgltexture.rs b/components/script/dom/webgltexture.rs index 443c5d031a1..2cc42a91f42 100644 --- a/components/script/dom/webgltexture.rs +++ b/components/script/dom/webgltexture.rs @@ -4,16 +4,16 @@ // https://www.khronos.org/registry/webgl/specs/latest/1.0/webgl.idl +use canvas_traits::webgl::{webgl_channel, WebGLResult, WebGLTextureId}; use canvas_traits::webgl::{DOMToTextureCommand, WebGLCommand, WebGLError}; -use canvas_traits::webgl::{WebGLResult, WebGLTextureId, webgl_channel}; use crate::dom::bindings::cell::DomRefCell; use crate::dom::bindings::codegen::Bindings::EXTTextureFilterAnisotropicBinding::EXTTextureFilterAnisotropicConstants; use crate::dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants; use crate::dom::bindings::codegen::Bindings::WebGLTextureBinding; use crate::dom::bindings::inheritance::Castable; -use crate::dom::bindings::reflector::{DomObject, reflect_dom_object}; +use crate::dom::bindings::reflector::{reflect_dom_object, DomObject}; use crate::dom::bindings::root::DomRoot; -use crate::dom::webgl_validations::types::{TexImageTarget, TexFormat, TexDataType}; +use crate::dom::webgl_validations::types::{TexDataType, TexFormat, TexImageTarget}; use crate::dom::webglobject::WebGLObject; use crate::dom::webglrenderingcontext::WebGLRenderingContext; use dom_struct::dom_struct; -- cgit v1.2.3 From adf363a2085f8af08a38046fae148131d0cbdd06 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Thu, 15 Nov 2018 10:01:19 +0100 Subject: Move prepare_pixels helper functions to canvas_traits --- components/script/dom/webgltexture.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'components/script/dom/webgltexture.rs') diff --git a/components/script/dom/webgltexture.rs b/components/script/dom/webgltexture.rs index 2cc42a91f42..c17747a779a 100644 --- a/components/script/dom/webgltexture.rs +++ b/components/script/dom/webgltexture.rs @@ -4,7 +4,7 @@ // https://www.khronos.org/registry/webgl/specs/latest/1.0/webgl.idl -use canvas_traits::webgl::{webgl_channel, WebGLResult, WebGLTextureId}; +use canvas_traits::webgl::{webgl_channel, TexDataType, TexFormat, WebGLResult, WebGLTextureId}; use canvas_traits::webgl::{DOMToTextureCommand, WebGLCommand, WebGLError}; use crate::dom::bindings::cell::DomRefCell; use crate::dom::bindings::codegen::Bindings::EXTTextureFilterAnisotropicBinding::EXTTextureFilterAnisotropicConstants; @@ -13,7 +13,7 @@ use crate::dom::bindings::codegen::Bindings::WebGLTextureBinding; use crate::dom::bindings::inheritance::Castable; use crate::dom::bindings::reflector::{reflect_dom_object, DomObject}; use crate::dom::bindings::root::DomRoot; -use crate::dom::webgl_validations::types::{TexDataType, TexFormat, TexImageTarget}; +use crate::dom::webgl_validations::types::TexImageTarget; use crate::dom::webglobject::WebGLObject; use crate::dom::webglrenderingcontext::WebGLRenderingContext; use dom_struct::dom_struct; -- cgit v1.2.3 From a1a14459c141afc6ac6771b8a6c9ca374537edf2 Mon Sep 17 00:00:00 2001 From: Jan Andre Ikenmeyer Date: Mon, 19 Nov 2018 14:47:12 +0100 Subject: Update MPL license to https (part 3) --- components/script/dom/webgltexture.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'components/script/dom/webgltexture.rs') diff --git a/components/script/dom/webgltexture.rs b/components/script/dom/webgltexture.rs index c17747a779a..626ceb22cf7 100644 --- a/components/script/dom/webgltexture.rs +++ b/components/script/dom/webgltexture.rs @@ -1,6 +1,6 @@ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ // https://www.khronos.org/registry/webgl/specs/latest/1.0/webgl.idl -- cgit v1.2.3 From be69f9c3e6a6f5efb5ba1edd50955cb12c111bf8 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Fri, 14 Dec 2018 08:31:30 +0100 Subject: Rustfmt has changed its default style :/ --- components/script/dom/webgltexture.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'components/script/dom/webgltexture.rs') diff --git a/components/script/dom/webgltexture.rs b/components/script/dom/webgltexture.rs index 626ceb22cf7..261edbe67be 100644 --- a/components/script/dom/webgltexture.rs +++ b/components/script/dom/webgltexture.rs @@ -4,8 +4,6 @@ // https://www.khronos.org/registry/webgl/specs/latest/1.0/webgl.idl -use canvas_traits::webgl::{webgl_channel, TexDataType, TexFormat, WebGLResult, WebGLTextureId}; -use canvas_traits::webgl::{DOMToTextureCommand, WebGLCommand, WebGLError}; use crate::dom::bindings::cell::DomRefCell; use crate::dom::bindings::codegen::Bindings::EXTTextureFilterAnisotropicBinding::EXTTextureFilterAnisotropicConstants; use crate::dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants; @@ -16,6 +14,8 @@ use crate::dom::bindings::root::DomRoot; use crate::dom::webgl_validations::types::TexImageTarget; use crate::dom::webglobject::WebGLObject; use crate::dom::webglrenderingcontext::WebGLRenderingContext; +use canvas_traits::webgl::{webgl_channel, TexDataType, TexFormat, WebGLResult, WebGLTextureId}; +use canvas_traits::webgl::{DOMToTextureCommand, WebGLCommand, WebGLError}; use dom_struct::dom_struct; use std::cell::Cell; use std::cmp; -- cgit v1.2.3 From 7f0b820d4ee87351aba9e7c785a704c6c83f135f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1ty=C3=A1s=20Mustoha?= Date: Mon, 25 Mar 2019 12:50:45 +0100 Subject: Add initial support for WebGL compressed textures --- components/script/dom/webgltexture.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'components/script/dom/webgltexture.rs') diff --git a/components/script/dom/webgltexture.rs b/components/script/dom/webgltexture.rs index 261edbe67be..8982e4bca0c 100644 --- a/components/script/dom/webgltexture.rs +++ b/components/script/dom/webgltexture.rs @@ -470,7 +470,24 @@ impl ImageInfo { } fn is_compressed_format(&self) -> bool { - // TODO: Once Servo supports compressed formats, check for them here - false + match self.internal_format { + Some(format) => format.is_compressed(), + None => false, + } } } + +#[derive(Clone, Copy, Debug, JSTraceable, MallocSizeOf)] +pub enum TexCompressionValidation { + None, + S3TC, +} + +#[derive(Clone, Copy, Debug, JSTraceable, MallocSizeOf)] +pub struct TexCompression { + pub format: TexFormat, + pub bytes_per_block: u8, + pub block_width: u8, + pub block_height: u8, + pub validation: TexCompressionValidation, +} -- cgit v1.2.3 From 8f5c37c0b5011fa526f2b932bf7abb0bca8a7fd0 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Mon, 29 Jul 2019 10:05:48 -0400 Subject: Don't panic if WebGL thread can't be reached during finalization. --- components/script/dom/webgltexture.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'components/script/dom/webgltexture.rs') diff --git a/components/script/dom/webgltexture.rs b/components/script/dom/webgltexture.rs index 8982e4bca0c..a7e548dcdef 100644 --- a/components/script/dom/webgltexture.rs +++ b/components/script/dom/webgltexture.rs @@ -180,7 +180,7 @@ impl WebGLTexture { self.populate_mip_chain(self.base_mipmap_level, last_level) } - pub fn delete(&self) { + pub fn delete(&self, fallible: bool) { if !self.is_deleted.get() { self.is_deleted.set(true); let context = self.upcast::().context(); @@ -204,7 +204,12 @@ impl WebGLTexture { fb.detach_texture(self); } - context.send_command(WebGLCommand::DeleteTexture(self.id)); + let cmd = WebGLCommand::DeleteTexture(self.id); + if fallible { + context.send_command_ignored(cmd); + } else { + context.send_command(cmd); + } } } @@ -404,7 +409,7 @@ impl WebGLTexture { impl Drop for WebGLTexture { fn drop(&mut self) { - self.delete(); + self.delete(true); } } -- cgit v1.2.3 From ea715a7a4cae5d2a2f41b059f36e08010d544de1 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Fri, 20 Sep 2019 01:28:06 -0400 Subject: webgl: Update framebuffer completion status when attached renderbuffer/texture storage changes. --- components/script/dom/webgltexture.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'components/script/dom/webgltexture.rs') diff --git a/components/script/dom/webgltexture.rs b/components/script/dom/webgltexture.rs index a7e548dcdef..e4a18b519a3 100644 --- a/components/script/dom/webgltexture.rs +++ b/components/script/dom/webgltexture.rs @@ -10,8 +10,9 @@ use crate::dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGL use crate::dom::bindings::codegen::Bindings::WebGLTextureBinding; use crate::dom::bindings::inheritance::Castable; use crate::dom::bindings::reflector::{reflect_dom_object, DomObject}; -use crate::dom::bindings::root::DomRoot; +use crate::dom::bindings::root::{DomRoot, MutNullableDom}; use crate::dom::webgl_validations::types::TexImageTarget; +use crate::dom::webglframebuffer::WebGLFramebuffer; use crate::dom::webglobject::WebGLObject; use crate::dom::webglrenderingcontext::WebGLRenderingContext; use canvas_traits::webgl::{webgl_channel, TexDataType, TexFormat, WebGLResult, WebGLTextureId}; @@ -48,6 +49,8 @@ pub struct WebGLTexture { mag_filter: Cell, /// True if this texture is used for the DOMToTexture feature. attached_to_dom: Cell, + /// Framebuffer that this texture is attached to. + attached_framebuffer: MutNullableDom, } impl WebGLTexture { @@ -63,6 +66,7 @@ impl WebGLTexture { mag_filter: Cell::new(constants::LINEAR), image_info_array: DomRefCell::new([ImageInfo::new(); MAX_LEVEL_COUNT * MAX_FACE_COUNT]), attached_to_dom: Cell::new(false), + attached_framebuffer: Default::default(), } } @@ -138,6 +142,11 @@ impl WebGLTexture { let face_index = self.face_index_for_target(&target); self.set_image_infos_at_level_and_face(level, face_index, image_info); + + if let Some(fb) = self.attached_framebuffer.get() { + fb.update_status(); + } + Ok(()) } @@ -405,6 +414,14 @@ impl WebGLTexture { pub fn set_attached_to_dom(&self) { self.attached_to_dom.set(true); } + + pub fn attach_to_framebuffer(&self, fb: &WebGLFramebuffer) { + self.attached_framebuffer.set(Some(fb)); + } + + pub fn detach_from_framebuffer(&self) { + self.attached_framebuffer.set(None); + } } impl Drop for WebGLTexture { -- cgit v1.2.3 From a358bca7667a2da42024aca4ef619dad6d812862 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 15 Oct 2019 12:57:00 -0500 Subject: Use surfman for managing GL surfaces Co-authored-by: Alan Jeffrey Co-authored-by: Zakor Gyula Co-authored-by: Josh Matthews --- components/script/dom/webgltexture.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'components/script/dom/webgltexture.rs') diff --git a/components/script/dom/webgltexture.rs b/components/script/dom/webgltexture.rs index e4a18b519a3..a043528195c 100644 --- a/components/script/dom/webgltexture.rs +++ b/components/script/dom/webgltexture.rs @@ -210,7 +210,7 @@ impl WebGLTexture { let currently_bound_framebuffer = self.upcast::().context().bound_framebuffer(); if let Some(fb) = currently_bound_framebuffer { - fb.detach_texture(self); + let _ = fb.detach_texture(self); } let cmd = WebGLCommand::DeleteTexture(self.id); -- cgit v1.2.3 From a4fa36f9fb540357b8c9452598b729fba6688c46 Mon Sep 17 00:00:00 2001 From: teapotd Date: Thu, 31 Oct 2019 19:20:52 +0100 Subject: Store Option instead of making fields optional --- components/script/dom/webgltexture.rs | 73 +++++++++++------------------------ 1 file changed, 22 insertions(+), 51 deletions(-) (limited to 'components/script/dom/webgltexture.rs') diff --git a/components/script/dom/webgltexture.rs b/components/script/dom/webgltexture.rs index e4a18b519a3..1f1f73e1ebb 100644 --- a/components/script/dom/webgltexture.rs +++ b/components/script/dom/webgltexture.rs @@ -40,7 +40,7 @@ pub struct WebGLTexture { is_deleted: Cell, /// Stores information about mipmap levels and cubemap faces. #[ignore_malloc_size_of = "Arrays are cumbersome"] - image_info_array: DomRefCell<[ImageInfo; MAX_LEVEL_COUNT * MAX_FACE_COUNT]>, + image_info_array: DomRefCell<[Option; MAX_LEVEL_COUNT * MAX_FACE_COUNT]>, /// Face count can only be 1 or 6 face_count: Cell, base_mipmap_level: u32, @@ -64,7 +64,7 @@ impl WebGLTexture { base_mipmap_level: 0, min_filter: Cell::new(constants::NEAREST_MIPMAP_LINEAR), mag_filter: Cell::new(constants::LINEAR), - image_info_array: DomRefCell::new([ImageInfo::new(); MAX_LEVEL_COUNT * MAX_FACE_COUNT]), + image_info_array: DomRefCell::new([None; MAX_LEVEL_COUNT * MAX_FACE_COUNT]), attached_to_dom: Cell::new(false), attached_framebuffer: Default::default(), } @@ -135,8 +135,7 @@ impl WebGLTexture { width: width, height: height, depth: depth, - internal_format: Some(internal_format), - is_initialized: true, + internal_format: internal_format, data_type: data_type, }; @@ -159,10 +158,7 @@ impl WebGLTexture { }, }; - let base_image_info = self.base_image_info(); - if !base_image_info.is_initialized() { - return Err(WebGLError::InvalidOperation); - } + let base_image_info = self.base_image_info().ok_or(WebGLError::InvalidOperation)?; let is_cubic = target == constants::TEXTURE_CUBE_MAP; if is_cubic && !self.is_cube_complete() { @@ -308,10 +304,9 @@ impl WebGLTexture { } pub fn populate_mip_chain(&self, first_level: u32, last_level: u32) -> WebGLResult<()> { - let base_image_info = self.image_info_at_face(0, first_level); - if !base_image_info.is_initialized() { - return Err(WebGLError::InvalidOperation); - } + let base_image_info = self + .image_info_at_face(0, first_level) + .ok_or(WebGLError::InvalidOperation)?; let mut ref_width = base_image_info.width; let mut ref_height = base_image_info.height; @@ -333,7 +328,6 @@ impl WebGLTexture { height: ref_height, depth: 0, internal_format: base_image_info.internal_format, - is_initialized: base_image_info.is_initialized(), data_type: base_image_info.data_type, }; @@ -345,19 +339,19 @@ impl WebGLTexture { fn is_cube_complete(&self) -> bool { debug_assert_eq!(self.face_count.get(), 6); - let image_info = self.base_image_info(); - if !image_info.is_defined() { - return false; - } + let image_info = match self.base_image_info() { + Some(info) => info, + None => return false, + }; let ref_width = image_info.width; let ref_format = image_info.internal_format; for face in 0..self.face_count.get() { - let current_image_info = self.image_info_at_face(face, self.base_mipmap_level); - if !current_image_info.is_defined() { - return false; - } + let current_image_info = match self.image_info_at_face(face, self.base_mipmap_level) { + Some(info) => info, + None => return false, + }; // Compares height with width to enforce square dimensions if current_image_info.internal_format != ref_format || @@ -383,12 +377,12 @@ impl WebGLTexture { } } - pub fn image_info_for_target(&self, target: &TexImageTarget, level: u32) -> ImageInfo { + pub fn image_info_for_target(&self, target: &TexImageTarget, level: u32) -> Option { let face_index = self.face_index_for_target(&target); self.image_info_at_face(face_index, level) } - pub fn image_info_at_face(&self, face: u8, level: u32) -> ImageInfo { + pub fn image_info_at_face(&self, face: u8, level: u32) -> Option { let pos = (level * self.face_count.get() as u32) + face as u32; self.image_info_array.borrow()[pos as usize] } @@ -402,10 +396,10 @@ impl WebGLTexture { fn set_image_infos_at_level_and_face(&self, level: u32, face: u8, image_info: ImageInfo) { debug_assert!(face < self.face_count.get()); let pos = (level * self.face_count.get() as u32) + face as u32; - self.image_info_array.borrow_mut()[pos as usize] = image_info; + self.image_info_array.borrow_mut()[pos as usize] = Some(image_info); } - fn base_image_info(&self) -> ImageInfo { + fn base_image_info(&self) -> Option { assert!((self.base_mipmap_level as usize) < MAX_LEVEL_COUNT); self.image_info_at_face(0, self.base_mipmap_level) @@ -435,23 +429,11 @@ pub struct ImageInfo { width: u32, height: u32, depth: u32, - internal_format: Option, - is_initialized: bool, + internal_format: TexFormat, data_type: Option, } impl ImageInfo { - fn new() -> ImageInfo { - ImageInfo { - width: 0, - height: 0, - depth: 0, - internal_format: None, - is_initialized: false, - data_type: None, - } - } - pub fn width(&self) -> u32 { self.width } @@ -460,7 +442,7 @@ impl ImageInfo { self.height } - pub fn internal_format(&self) -> Option { + pub fn internal_format(&self) -> TexFormat { self.internal_format } @@ -474,14 +456,6 @@ impl ImageInfo { self.depth.is_power_of_two() } - pub fn is_initialized(&self) -> bool { - self.is_initialized - } - - fn is_defined(&self) -> bool { - self.internal_format.is_some() - } - fn get_max_mimap_levels(&self) -> u32 { let largest = cmp::max(cmp::max(self.width, self.height), self.depth); if largest == 0 { @@ -492,10 +466,7 @@ impl ImageInfo { } fn is_compressed_format(&self) -> bool { - match self.internal_format { - Some(format) => format.is_compressed(), - None => false, - } + self.internal_format.is_compressed() } } -- cgit v1.2.3 From 796ee705976f8072032a0fc88579ca18aed85999 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1ty=C3=A1s=20Mustoha?= Date: Fri, 14 Feb 2020 11:57:11 +0100 Subject: Add initial support for WebGL2 read framebuffer Adds support for binding to the read framebuffer slot and querying its status. --- components/script/dom/webgltexture.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'components/script/dom/webgltexture.rs') diff --git a/components/script/dom/webgltexture.rs b/components/script/dom/webgltexture.rs index f7d52c8708a..682f04f0bd8 100644 --- a/components/script/dom/webgltexture.rs +++ b/components/script/dom/webgltexture.rs @@ -197,15 +197,17 @@ impl WebGLTexture { } /* - If a texture object is deleted while its image is attached to the currently - bound framebuffer, then it is as if FramebufferTexture2D had been called, with - a texture of 0, for each attachment point to which this image was attached - in the currently bound framebuffer. - - GLES 2.0, 4.4.3, "Attaching Texture Images to a Framebuffer" - */ - let currently_bound_framebuffer = - self.upcast::().context().bound_framebuffer(); - if let Some(fb) = currently_bound_framebuffer { + If a texture object is deleted while its image is attached to one or more attachment + points in a currently bound framebuffer, then it is as if FramebufferTexture had been + called, with a texture of zero, for each attachment point to which this im-age was + attached in that framebuffer. In other words, this texture image is firstdetached from + all attachment points in a currently bound framebuffer. + - GLES 3.0, 4.4.2.3, "Attaching Texture Images to a Framebuffer" + */ + if let Some(fb) = context.get_draw_framebuffer_slot().get() { + let _ = fb.detach_texture(self); + } + if let Some(fb) = context.get_read_framebuffer_slot().get() { let _ = fb.detach_texture(self); } -- cgit v1.2.3 From 3ea6d87bcc37167464e856949a4b9b77d0e9318a Mon Sep 17 00:00:00 2001 From: YUAN LYU Date: Fri, 20 Mar 2020 22:14:18 -0400 Subject: Add trait DomObjectWrap to provide WRAP function --- components/script/dom/webgltexture.rs | 2 -- 1 file changed, 2 deletions(-) (limited to 'components/script/dom/webgltexture.rs') diff --git a/components/script/dom/webgltexture.rs b/components/script/dom/webgltexture.rs index 682f04f0bd8..682920df96e 100644 --- a/components/script/dom/webgltexture.rs +++ b/components/script/dom/webgltexture.rs @@ -7,7 +7,6 @@ use crate::dom::bindings::cell::DomRefCell; use crate::dom::bindings::codegen::Bindings::EXTTextureFilterAnisotropicBinding::EXTTextureFilterAnisotropicConstants; use crate::dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants; -use crate::dom::bindings::codegen::Bindings::WebGLTextureBinding; use crate::dom::bindings::inheritance::Castable; use crate::dom::bindings::reflector::{reflect_dom_object, DomObject}; use crate::dom::bindings::root::{DomRoot, MutNullableDom}; @@ -83,7 +82,6 @@ impl WebGLTexture { reflect_dom_object( Box::new(WebGLTexture::new_inherited(context, id)), &*context.global(), - WebGLTextureBinding::Wrap, ) } } -- cgit v1.2.3 From 9c343fcc9600a1a2b768a4632793d0856d55ddce Mon Sep 17 00:00:00 2001 From: Tobias Tschinkowitz Date: Thu, 23 Apr 2020 18:23:01 +0200 Subject: Replaced failible boolean with an enum --- components/script/dom/webgltexture.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'components/script/dom/webgltexture.rs') diff --git a/components/script/dom/webgltexture.rs b/components/script/dom/webgltexture.rs index 682920df96e..3059dc7bf4e 100644 --- a/components/script/dom/webgltexture.rs +++ b/components/script/dom/webgltexture.rs @@ -13,7 +13,7 @@ use crate::dom::bindings::root::{DomRoot, MutNullableDom}; use crate::dom::webgl_validations::types::TexImageTarget; use crate::dom::webglframebuffer::WebGLFramebuffer; use crate::dom::webglobject::WebGLObject; -use crate::dom::webglrenderingcontext::WebGLRenderingContext; +use crate::dom::webglrenderingcontext::{Operation, WebGLRenderingContext}; use canvas_traits::webgl::{webgl_channel, TexDataType, TexFormat, WebGLResult, WebGLTextureId}; use canvas_traits::webgl::{DOMToTextureCommand, WebGLCommand, WebGLError}; use dom_struct::dom_struct; @@ -183,7 +183,7 @@ impl WebGLTexture { self.populate_mip_chain(self.base_mipmap_level, last_level) } - pub fn delete(&self, fallible: bool) { + pub fn delete(&self, operation_fallibility: Operation) { if !self.is_deleted.get() { self.is_deleted.set(true); let context = self.upcast::().context(); @@ -210,10 +210,9 @@ impl WebGLTexture { } let cmd = WebGLCommand::DeleteTexture(self.id); - if fallible { - context.send_command_ignored(cmd); - } else { - context.send_command(cmd); + match operation_fallibility { + Operation::Fallible => context.send_command_ignored(cmd), + Operation::Infallible => context.send_command(cmd), } } } @@ -420,7 +419,7 @@ impl WebGLTexture { impl Drop for WebGLTexture { fn drop(&mut self) { - self.delete(true); + self.delete(Operation::Fallible); } } -- cgit v1.2.3 From 8789a6a8d8186416a766f7ef2a71af217e20f9fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1ty=C3=A1s=20Mustoha?= Date: Thu, 12 Mar 2020 14:55:46 +0100 Subject: Add support for WebGL2 TexStorage2D Adds initial support for the WebGL2 `TexStorage2D` call, adds support for the related texture enums and enables some of the texture tests. See: https://www.khronos.org/registry/webgl/specs/latest/2.0/#3.7.6 --- components/script/dom/webgltexture.rs | 62 +++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-) (limited to 'components/script/dom/webgltexture.rs') diff --git a/components/script/dom/webgltexture.rs b/components/script/dom/webgltexture.rs index 3059dc7bf4e..a9c37110c2e 100644 --- a/components/script/dom/webgltexture.rs +++ b/components/script/dom/webgltexture.rs @@ -6,7 +6,7 @@ use crate::dom::bindings::cell::DomRefCell; use crate::dom::bindings::codegen::Bindings::EXTTextureFilterAnisotropicBinding::EXTTextureFilterAnisotropicConstants; -use crate::dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants; +use crate::dom::bindings::codegen::Bindings::WebGL2RenderingContextBinding::WebGL2RenderingContextConstants as constants; use crate::dom::bindings::inheritance::Castable; use crate::dom::bindings::reflector::{reflect_dom_object, DomObject}; use crate::dom::bindings::root::{DomRoot, MutNullableDom}; @@ -37,6 +37,7 @@ pub struct WebGLTexture { /// The target to which this texture was bound the first time target: Cell>, is_deleted: Cell, + is_immutable: Cell, /// Stores information about mipmap levels and cubemap faces. #[ignore_malloc_size_of = "Arrays are cumbersome"] image_info_array: DomRefCell<[Option; MAX_LEVEL_COUNT * MAX_FACE_COUNT]>, @@ -59,6 +60,7 @@ impl WebGLTexture { id: id, target: Cell::new(None), is_deleted: Cell::new(false), + is_immutable: Cell::new(false), face_count: Cell::new(0), base_mipmap_level: 0, min_filter: Cell::new(constants::NEAREST_MIPMAP_LINEAR), @@ -221,6 +223,10 @@ impl WebGLTexture { self.is_deleted.get() } + pub fn is_immutable(&self) -> bool { + self.is_immutable.get() + } + pub fn target(&self) -> Option { self.target.get() } @@ -366,13 +372,13 @@ impl WebGLTexture { fn face_index_for_target(&self, target: &TexImageTarget) -> u8 { match *target { - TexImageTarget::Texture2D => 0, TexImageTarget::CubeMapPositiveX => 0, TexImageTarget::CubeMapNegativeX => 1, TexImageTarget::CubeMapPositiveY => 2, TexImageTarget::CubeMapNegativeY => 3, TexImageTarget::CubeMapPositiveZ => 4, TexImageTarget::CubeMapNegativeZ => 5, + _ => 0, } } @@ -415,6 +421,58 @@ impl WebGLTexture { pub fn detach_from_framebuffer(&self) { self.attached_framebuffer.set(None); } + + pub fn storage( + &self, + target: TexImageTarget, + levels: u32, + internal_format: TexFormat, + width: u32, + height: u32, + depth: u32, + ) -> WebGLResult<()> { + // Handled by the caller + assert!(!self.is_immutable()); + assert!(self.target().is_some()); + + let target_id = target.as_gl_constant(); + let command = match target { + TexImageTarget::Texture2D | TexImageTarget::CubeMap => { + WebGLCommand::TexStorage2D(target_id, levels, internal_format, width, height) + }, + TexImageTarget::Texture3D | TexImageTarget::Texture2DArray => { + WebGLCommand::TexStorage3D(target_id, levels, internal_format, width, height, depth) + }, + _ => unreachable!(), // handled by the caller + }; + self.upcast::().context().send_command(command); + + let mut width = width; + let mut height = height; + let mut depth = depth; + for level in 0..levels { + let image_info = ImageInfo { + width, + height, + depth, + internal_format, + data_type: None, + }; + self.set_image_infos_at_level(level, image_info); + + width = cmp::max(1, width / 2); + height = cmp::max(1, height / 2); + depth = cmp::max(1, depth / 2); + } + + self.is_immutable.set(true); + + if let Some(fb) = self.attached_framebuffer.get() { + fb.update_status(); + } + + Ok(()) + } } impl Drop for WebGLTexture { -- cgit v1.2.3 From 9ce84d94dea493404d0133a82adc564ce9f2b232 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Wed, 29 Apr 2020 14:29:53 -0400 Subject: webgl: Return TEXTURE_IMMUTABLE_FORMAT as a boolean; don't panic on macOS for TEXTURE_IMMUTABLE_LEVELS. --- components/script/dom/webgltexture.rs | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'components/script/dom/webgltexture.rs') diff --git a/components/script/dom/webgltexture.rs b/components/script/dom/webgltexture.rs index a9c37110c2e..2f46bb47198 100644 --- a/components/script/dom/webgltexture.rs +++ b/components/script/dom/webgltexture.rs @@ -14,7 +14,10 @@ use crate::dom::webgl_validations::types::TexImageTarget; use crate::dom::webglframebuffer::WebGLFramebuffer; use crate::dom::webglobject::WebGLObject; use crate::dom::webglrenderingcontext::{Operation, WebGLRenderingContext}; -use canvas_traits::webgl::{webgl_channel, TexDataType, TexFormat, WebGLResult, WebGLTextureId}; +use canvas_traits::webgl::{ + webgl_channel, TexDataType, TexFormat, TexParameter, TexParameterBool, TexParameterInt, + WebGLResult, WebGLTextureId, +}; use canvas_traits::webgl::{DOMToTextureCommand, WebGLCommand, WebGLError}; use dom_struct::dom_struct; use std::cell::Cell; @@ -23,6 +26,7 @@ use std::cmp; pub enum TexParameterValue { Float(f32), Int(i32), + Bool(bool), } const MAX_LEVEL_COUNT: usize = 31; @@ -37,7 +41,6 @@ pub struct WebGLTexture { /// The target to which this texture was bound the first time target: Cell>, is_deleted: Cell, - is_immutable: Cell, /// Stores information about mipmap levels and cubemap faces. #[ignore_malloc_size_of = "Arrays are cumbersome"] image_info_array: DomRefCell<[Option; MAX_LEVEL_COUNT * MAX_FACE_COUNT]>, @@ -51,6 +54,8 @@ pub struct WebGLTexture { attached_to_dom: Cell, /// Framebuffer that this texture is attached to. attached_framebuffer: MutNullableDom, + /// Number of immutable levels. + immutable_levels: Cell>, } impl WebGLTexture { @@ -60,7 +65,7 @@ impl WebGLTexture { id: id, target: Cell::new(None), is_deleted: Cell::new(false), - is_immutable: Cell::new(false), + immutable_levels: Cell::new(None), face_count: Cell::new(0), base_mipmap_level: 0, min_filter: Cell::new(constants::NEAREST_MIPMAP_LINEAR), @@ -224,13 +229,25 @@ impl WebGLTexture { } pub fn is_immutable(&self) -> bool { - self.is_immutable.get() + self.immutable_levels.get().is_some() } pub fn target(&self) -> Option { self.target.get() } + pub fn maybe_get_tex_parameter(&self, param: TexParameter) -> Option { + match param { + TexParameter::Int(TexParameterInt::TextureImmutableLevels) => Some( + TexParameterValue::Int(self.immutable_levels.get().unwrap_or(0) as i32), + ), + TexParameter::Bool(TexParameterBool::TextureImmutableFormat) => { + Some(TexParameterValue::Bool(self.is_immutable())) + }, + _ => None, + } + } + /// We have to follow the conversion rules for GLES 2.0. See: /// https://www.khronos.org/webgl/public-mailing-list/archives/1008/msg00014.html /// @@ -240,6 +257,7 @@ impl WebGLTexture { let (int_value, float_value) = match value { TexParameterValue::Int(int_value) => (int_value, int_value as f32), TexParameterValue::Float(float_value) => (float_value as i32, float_value), + TexParameterValue::Bool(_) => unreachable!("no settable tex params should be booleans"), }; let update_filter = |filter: &Cell| { @@ -465,7 +483,7 @@ impl WebGLTexture { depth = cmp::max(1, depth / 2); } - self.is_immutable.set(true); + self.immutable_levels.set(Some(levels)); if let Some(fb) = self.attached_framebuffer.get() { fb.update_status(); -- cgit v1.2.3 From dfc641d64841bab44cdca2cba0009901416f78f6 Mon Sep 17 00:00:00 2001 From: Alan Jeffrey Date: Wed, 29 Jul 2020 17:06:45 -0500 Subject: Don't delete GL textures created by WebXR --- components/script/dom/webgltexture.rs | 38 +++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'components/script/dom/webgltexture.rs') diff --git a/components/script/dom/webgltexture.rs b/components/script/dom/webgltexture.rs index 2f46bb47198..02cedeb5755 100644 --- a/components/script/dom/webgltexture.rs +++ b/components/script/dom/webgltexture.rs @@ -29,6 +29,14 @@ pub enum TexParameterValue { Bool(bool), } +// Textures generated for WebXR are owned by the WebXR device, not by the WebGL thread +// so the GL texture should not be deleted when the texture is garbage collected. +#[derive(Clone, Copy, Debug, Eq, JSTraceable, MallocSizeOf, PartialEq)] +enum WebGLTextureOwner { + WebGL, + WebXR, +} + const MAX_LEVEL_COUNT: usize = 31; const MAX_FACE_COUNT: usize = 6; @@ -41,6 +49,7 @@ pub struct WebGLTexture { /// The target to which this texture was bound the first time target: Cell>, is_deleted: Cell, + owner: WebGLTextureOwner, /// Stores information about mipmap levels and cubemap faces. #[ignore_malloc_size_of = "Arrays are cumbersome"] image_info_array: DomRefCell<[Option; MAX_LEVEL_COUNT * MAX_FACE_COUNT]>, @@ -59,12 +68,17 @@ pub struct WebGLTexture { } impl WebGLTexture { - fn new_inherited(context: &WebGLRenderingContext, id: WebGLTextureId) -> Self { + fn new_inherited( + context: &WebGLRenderingContext, + id: WebGLTextureId, + owner: WebGLTextureOwner, + ) -> Self { Self { webgl_object: WebGLObject::new_inherited(context), id: id, target: Cell::new(None), is_deleted: Cell::new(false), + owner: owner, immutable_levels: Cell::new(None), face_count: Cell::new(0), base_mipmap_level: 0, @@ -87,7 +101,22 @@ impl WebGLTexture { pub fn new(context: &WebGLRenderingContext, id: WebGLTextureId) -> DomRoot { reflect_dom_object( - Box::new(WebGLTexture::new_inherited(context, id)), + Box::new(WebGLTexture::new_inherited( + context, + id, + WebGLTextureOwner::WebGL, + )), + &*context.global(), + ) + } + + pub fn new_webxr(context: &WebGLRenderingContext, id: WebGLTextureId) -> DomRoot { + reflect_dom_object( + Box::new(WebGLTexture::new_inherited( + context, + id, + WebGLTextureOwner::WebXR, + )), &*context.global(), ) } @@ -216,6 +245,11 @@ impl WebGLTexture { let _ = fb.detach_texture(self); } + // We don't delete textures owned by WebXR + if self.owner == WebGLTextureOwner::WebXR { + return; + } + let cmd = WebGLCommand::DeleteTexture(self.id); match operation_fallibility { Operation::Fallible => context.send_command_ignored(cmd), -- cgit v1.2.3 From c1d064b626e73d92c118a9abcb566f2bf0817214 Mon Sep 17 00:00:00 2001 From: Alan Jeffrey Date: Thu, 6 Aug 2020 17:51:58 -0500 Subject: Make textures that come from webxr invalid outside an rAF --- components/script/dom/webgltexture.rs | 43 ++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 18 deletions(-) (limited to 'components/script/dom/webgltexture.rs') diff --git a/components/script/dom/webgltexture.rs b/components/script/dom/webgltexture.rs index 02cedeb5755..7456f772dec 100644 --- a/components/script/dom/webgltexture.rs +++ b/components/script/dom/webgltexture.rs @@ -9,11 +9,13 @@ use crate::dom::bindings::codegen::Bindings::EXTTextureFilterAnisotropicBinding: use crate::dom::bindings::codegen::Bindings::WebGL2RenderingContextBinding::WebGL2RenderingContextConstants as constants; use crate::dom::bindings::inheritance::Castable; use crate::dom::bindings::reflector::{reflect_dom_object, DomObject}; +use crate::dom::bindings::root::Dom; use crate::dom::bindings::root::{DomRoot, MutNullableDom}; use crate::dom::webgl_validations::types::TexImageTarget; use crate::dom::webglframebuffer::WebGLFramebuffer; use crate::dom::webglobject::WebGLObject; use crate::dom::webglrenderingcontext::{Operation, WebGLRenderingContext}; +use crate::dom::xrsession::XRSession; use canvas_traits::webgl::{ webgl_channel, TexDataType, TexFormat, TexParameter, TexParameterBool, TexParameterInt, WebGLResult, WebGLTextureId, @@ -31,10 +33,11 @@ pub enum TexParameterValue { // Textures generated for WebXR are owned by the WebXR device, not by the WebGL thread // so the GL texture should not be deleted when the texture is garbage collected. -#[derive(Clone, Copy, Debug, Eq, JSTraceable, MallocSizeOf, PartialEq)] +#[unrooted_must_root_lint::must_root] +#[derive(JSTraceable, MallocSizeOf)] enum WebGLTextureOwner { WebGL, - WebXR, + WebXR(Dom), } const MAX_LEVEL_COUNT: usize = 31; @@ -71,14 +74,16 @@ impl WebGLTexture { fn new_inherited( context: &WebGLRenderingContext, id: WebGLTextureId, - owner: WebGLTextureOwner, + owner: Option<&XRSession>, ) -> Self { Self { webgl_object: WebGLObject::new_inherited(context), id: id, target: Cell::new(None), is_deleted: Cell::new(false), - owner: owner, + owner: owner + .map(|session| WebGLTextureOwner::WebXR(Dom::from_ref(session))) + .unwrap_or(WebGLTextureOwner::WebGL), immutable_levels: Cell::new(None), face_count: Cell::new(0), base_mipmap_level: 0, @@ -101,22 +106,18 @@ impl WebGLTexture { pub fn new(context: &WebGLRenderingContext, id: WebGLTextureId) -> DomRoot { reflect_dom_object( - Box::new(WebGLTexture::new_inherited( - context, - id, - WebGLTextureOwner::WebGL, - )), + Box::new(WebGLTexture::new_inherited(context, id, None)), &*context.global(), ) } - pub fn new_webxr(context: &WebGLRenderingContext, id: WebGLTextureId) -> DomRoot { + pub fn new_webxr( + context: &WebGLRenderingContext, + id: WebGLTextureId, + session: &XRSession, + ) -> DomRoot { reflect_dom_object( - Box::new(WebGLTexture::new_inherited( - context, - id, - WebGLTextureOwner::WebXR, - )), + Box::new(WebGLTexture::new_inherited(context, id, Some(session))), &*context.global(), ) } @@ -129,7 +130,7 @@ impl WebGLTexture { // NB: Only valid texture targets come here pub fn bind(&self, target: u32) -> WebGLResult<()> { - if self.is_deleted.get() { + if self.is_invalid() { return Err(WebGLError::InvalidOperation); } @@ -246,7 +247,7 @@ impl WebGLTexture { } // We don't delete textures owned by WebXR - if self.owner == WebGLTextureOwner::WebXR { + if let WebGLTextureOwner::WebXR(_) = self.owner { return; } @@ -258,7 +259,13 @@ impl WebGLTexture { } } - pub fn is_deleted(&self) -> bool { + pub fn is_invalid(&self) -> bool { + // https://immersive-web.github.io/layers/#xrwebglsubimagetype + if let WebGLTextureOwner::WebXR(ref session) = self.owner { + if session.is_outside_raf() { + return true; + } + } self.is_deleted.get() } -- cgit v1.2.3