Replace sparkle with glow in components/canvas (#33918)

* Replace sparkle with glow in components/canvas

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

* Replace safe_gl with #34300

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

---------

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This commit is contained in:
Samson 2024-11-20 10:05:24 +01:00 committed by GitHub
parent 910e8dc89f
commit 063071ba72
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 958 additions and 703 deletions

10
Cargo.lock generated
View file

@ -714,7 +714,6 @@ dependencies = [
"range", "range",
"raqote", "raqote",
"servo_arc", "servo_arc",
"sparkle",
"style", "style",
"style_traits", "style_traits",
"surfman", "surfman",
@ -6918,15 +6917,6 @@ dependencies = [
"windows-sys 0.52.0", "windows-sys 0.52.0",
] ]
[[package]]
name = "sparkle"
version = "0.1.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74fc6c6346da9177de9894230716709c223c62adbf910a5c1e6096b2ee2e58e0"
dependencies = [
"gl_generator",
]
[[package]] [[package]]
name = "speexdsp-resampler" name = "speexdsp-resampler"
version = "0.1.0" version = "0.1.0"

View file

@ -117,7 +117,6 @@ servo_arc = { git = "https://github.com/servo/stylo", branch = "2024-10-04", fea
servo_atoms = { git = "https://github.com/servo/stylo", branch = "2024-10-04" } servo_atoms = { git = "https://github.com/servo/stylo", branch = "2024-10-04" }
smallbitvec = "2.5.3" smallbitvec = "2.5.3"
smallvec = "1.13" smallvec = "1.13"
sparkle = "0.1.26"
static_assertions = "1.1" static_assertions = "1.1"
string_cache = "0.8" string_cache = "0.8"
string_cache_codegen = "0.5" string_cache_codegen = "0.5"

View file

@ -39,7 +39,6 @@ pixels = { path = "../pixels" }
range = { path = "../range" } range = { path = "../range" }
raqote = "0.8.5" raqote = "0.8.5"
servo_arc = { workspace = true } servo_arc = { workspace = true }
sparkle = { workspace = true }
style = { workspace = true } style = { workspace = true }
style_traits = { workspace = true } style_traits = { workspace = true }
surfman = { workspace = true } surfman = { workspace = true }

View file

@ -3,8 +3,8 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use canvas_traits::webgl::{GLLimits, WebGLVersion}; use canvas_traits::webgl::{GLLimits, WebGLVersion};
use sparkle::gl; use glow::{self as gl, Context as Gl, HasContext};
use sparkle::gl::{GLenum, Gl, GlType}; type GLenum = u32;
pub trait GLLimitsDetect { pub trait GLLimitsDetect {
fn detect(gl: &Gl, webgl_version: WebGLVersion) -> Self; fn detect(gl: &Gl, webgl_version: WebGLVersion) -> Self;
@ -32,7 +32,7 @@ impl GLLimitsDetect for GLLimits {
max_vertex_output_vectors, max_vertex_output_vectors,
max_fragment_input_vectors, max_fragment_input_vectors,
); );
if gl.get_type() == GlType::Gles { if gl.version().is_embedded {
max_fragment_uniform_vectors = gl.get_integer(gl::MAX_FRAGMENT_UNIFORM_VECTORS); max_fragment_uniform_vectors = gl.get_integer(gl::MAX_FRAGMENT_UNIFORM_VECTORS);
max_varying_vectors = gl.get_integer(gl::MAX_VARYING_VECTORS); max_varying_vectors = gl.get_integer(gl::MAX_VARYING_VECTORS);
max_vertex_uniform_vectors = gl.get_integer(gl::MAX_VERTEX_UNIFORM_VECTORS); max_vertex_uniform_vectors = gl.get_integer(gl::MAX_VERTEX_UNIFORM_VECTORS);
@ -220,7 +220,7 @@ macro_rules! create_fun {
unsafe { unsafe {
self.$glcall(parameter, &mut value); self.$glcall(parameter, &mut value);
} }
if self.get_error() != gl::NO_ERROR { if unsafe { self.get_error() } != gl::NO_ERROR {
None None
} else { } else {
Some(value[0] as $rstype) Some(value[0] as $rstype)
@ -234,14 +234,26 @@ macro_rules! create_fun {
} }
impl<'a> GLExt for &'a Gl { impl<'a> GLExt for &'a Gl {
create_fun!(try_get_integer, get_integer, i32, get_integer_v, u32); create_fun!(
create_fun!(try_get_integer64, get_integer64, i64, get_integer64_v, u64); try_get_integer,
get_integer,
i32,
get_parameter_i32_slice,
u32
);
create_fun!(
try_get_integer64,
get_integer64,
i64,
get_parameter_i64_slice,
u64
);
create_fun!( create_fun!(
try_get_signed_integer, try_get_signed_integer,
get_signed_integer, get_signed_integer,
i32, i32,
get_integer_v, get_parameter_i32_slice,
i32 i32
); );
create_fun!(try_get_float, get_float, f32, get_float_v, f32); create_fun!(try_get_float, get_float, f32, get_parameter_f32_slice, f32);
} }

File diff suppressed because it is too large Load diff

View file

@ -320,6 +320,7 @@ impl<'a> WebXRContexts<WebXRSurfman> for WebXRBridgeContexts<'a> {
)?; )?;
Some(&mut data.ctx) Some(&mut data.ctx)
} }
fn bindings(&mut self, device: &Device, context_id: WebXRContextId) -> Option<&glow::Context> { fn bindings(&mut self, device: &Device, context_id: WebXRContextId) -> Option<&glow::Context> {
let data = WebGLThread::make_current_if_needed( let data = WebGLThread::make_current_if_needed(
device, device,
@ -327,6 +328,6 @@ impl<'a> WebXRContexts<WebXRSurfman> for WebXRBridgeContexts<'a> {
self.contexts, self.contexts,
self.bound_context_id, self.bound_context_id,
)?; )?;
Some(&data.glow) Some(&data.gl)
} }
} }

View file

@ -219,11 +219,11 @@ impl VertexArrayObject {
let mut has_active_attrib = false; let mut has_active_attrib = false;
let mut has_divisor_0 = false; let mut has_divisor_0 = false;
for active_info in active_attribs { for active_info in active_attribs {
if active_info.location < 0 { let Some(location) = active_info.location else {
continue; continue;
} };
has_active_attrib = true; has_active_attrib = true;
let attrib = &attribs[active_info.location as usize]; let attrib = &attribs[location as usize];
if attrib.divisor == 0 { if attrib.divisor == 0 {
has_divisor_0 = true; has_divisor_0 = true;
} }

View file

@ -294,13 +294,17 @@ impl WebGL2RenderingContext {
for prog_attrib in program.active_attribs().iter() { for prog_attrib in program.active_attribs().iter() {
let attrib = handle_potential_webgl_error!( let attrib = handle_potential_webgl_error!(
self.base, self.base,
vao.get_vertex_attrib(prog_attrib.location as u32) // TODO(#34300): remove unwrap
vao.get_vertex_attrib(prog_attrib.location.unwrap_or(u32::MAX))
.ok_or(InvalidOperation), .ok_or(InvalidOperation),
return return
); );
let current_vertex_attrib = // TODO(#34300): remove unwrap
self.base.current_vertex_attribs()[prog_attrib.location as usize]; let current_vertex_attrib = self.base.current_vertex_attribs()[prog_attrib
.location
.map(|l| l as usize)
.unwrap_or(usize::MAX)];
let attrib_data_base_type = if !attrib.enabled_as_array { let attrib_data_base_type = if !attrib.enabled_as_array {
match current_vertex_attrib { match current_vertex_attrib {
VertexAttrib::Int(_, _, _, _) => constants::INT, VertexAttrib::Int(_, _, _, _) => constants::INT,

View file

@ -173,9 +173,9 @@ impl WebGLProgram {
let mut used_locs = FnvHashSet::default(); let mut used_locs = FnvHashSet::default();
let mut used_names = FnvHashSet::default(); let mut used_names = FnvHashSet::default();
for active_attrib in &*link_info.active_attribs { for active_attrib in &*link_info.active_attribs {
if active_attrib.location == -1 { let Some(location) = active_attrib.location else {
continue; continue;
} };
let columns = match active_attrib.type_ { let columns = match active_attrib.type_ {
constants::FLOAT_MAT2 => 2, constants::FLOAT_MAT2 => 2,
constants::FLOAT_MAT3 => 3, constants::FLOAT_MAT3 => 3,
@ -185,7 +185,7 @@ impl WebGLProgram {
assert!(used_names.insert(&*active_attrib.name)); assert!(used_names.insert(&*active_attrib.name));
for column in 0..columns { for column in 0..columns {
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#6.31 // https://www.khronos.org/registry/webgl/specs/latest/1.0/#6.31
if !used_locs.insert(active_attrib.location as u32 + column) { if !used_locs.insert(location + column) {
return Ok(()); return Ok(());
} }
} }
@ -364,7 +364,8 @@ impl WebGLProgram {
.borrow() .borrow()
.iter() .iter()
.find(|attrib| attrib.name == *name) .find(|attrib| attrib.name == *name)
.map_or(-1, |attrib| attrib.location); .and_then(|attrib| attrib.location.map(|l| l as i32))
.unwrap_or(-1);
Ok(location) Ok(location)
} }

View file

@ -14,7 +14,10 @@ pub use base::generic_channel::GenericSender as WebGLSender;
/// Result type for send()/recv() calls in in WebGLCommands. /// Result type for send()/recv() calls in in WebGLCommands.
pub use base::generic_channel::SendResult as WebGLSendResult; pub use base::generic_channel::SendResult as WebGLSendResult;
use euclid::default::{Rect, Size2D}; use euclid::default::{Rect, Size2D};
use glow as gl; use glow::{
self as gl, NativeBuffer, NativeFence, NativeFramebuffer, NativeProgram, NativeQuery,
NativeRenderbuffer, NativeSampler, NativeShader, NativeTexture, NativeVertexArray,
};
use ipc_channel::ipc::{IpcBytesReceiver, IpcBytesSender, IpcSender, IpcSharedMemory}; use ipc_channel::ipc::{IpcBytesReceiver, IpcBytesSender, IpcSender, IpcSharedMemory};
use malloc_size_of_derive::MallocSizeOf; use malloc_size_of_derive::MallocSizeOf;
use pixels::PixelFormat; use pixels::PixelFormat;
@ -632,18 +635,43 @@ macro_rules! define_resource_id {
} }
} }
}; };
($name:ident, $type:tt, $glow:tt) => {
impl $name {
#[inline]
pub fn glow(self) -> $glow {
$glow(self.0)
}
#[inline]
pub fn from_glow(glow: $glow) -> Self {
Self(glow.0)
}
}
define_resource_id!($name, $type);
};
} }
define_resource_id!(WebGLBufferId, u32); define_resource_id!(WebGLBufferId, u32, NativeBuffer);
define_resource_id!(WebGLFramebufferId, u32); define_resource_id!(WebGLFramebufferId, u32, NativeFramebuffer);
define_resource_id!(WebGLRenderbufferId, u32); define_resource_id!(WebGLRenderbufferId, u32, NativeRenderbuffer);
define_resource_id!(WebGLTextureId, u32); define_resource_id!(WebGLTextureId, u32, NativeTexture);
define_resource_id!(WebGLProgramId, u32); define_resource_id!(WebGLProgramId, u32, NativeProgram);
define_resource_id!(WebGLQueryId, u32); define_resource_id!(WebGLQueryId, u32, NativeQuery);
define_resource_id!(WebGLSamplerId, u32); define_resource_id!(WebGLSamplerId, u32, NativeSampler);
define_resource_id!(WebGLShaderId, u32); define_resource_id!(WebGLShaderId, u32, NativeShader);
define_resource_id!(WebGLSyncId, u64); define_resource_id!(WebGLSyncId, u64);
define_resource_id!(WebGLVertexArrayId, u32); impl WebGLSyncId {
#[inline]
pub fn glow(&self) -> NativeFence {
NativeFence(self.0.get() as _)
}
#[inline]
pub fn from_glow(glow: NativeFence) -> Self {
Self::maybe_new(glow.0 as _).expect("Glow should have valid fence")
}
}
define_resource_id!(WebGLVertexArrayId, u32, NativeVertexArray);
define_resource_id!(WebXRLayerManagerId, u32); define_resource_id!(WebXRLayerManagerId, u32);
#[derive( #[derive(
@ -708,7 +736,7 @@ pub struct ActiveAttribInfo {
/// The type of the attribute. /// The type of the attribute.
pub type_: u32, pub type_: u32,
/// The location of the attribute. /// The location of the attribute.
pub location: i32, pub location: Option<u32>,
} }
/// Description of a single active uniform. /// Description of a single active uniform.

View file

@ -1,5 +1,5 @@
[readbuffer.html] [readbuffer.html]
[WebGL test #28: the color should be [0,0,0,255\]\nat (0, 0) expected: 0,0,0,255 was 0,0,255,255] [WebGL test #28: the color should be [0,0,0,255\]\nat (0, 0) expected: 0,0,0,255 was 0,0,0,0]
expected: FAIL expected: FAIL
[WebGL test #15: getError expected: INVALID_OPERATION. Was INVALID_ENUM : calling readBuffer with GL_COLOR_ATTACHMENTi that exceeds MAX_COLOR_ATTACHMENT on fbo should generate INVALID_OPERATION.] [WebGL test #15: getError expected: INVALID_OPERATION. Was INVALID_ENUM : calling readBuffer with GL_COLOR_ATTACHMENTi that exceeds MAX_COLOR_ATTACHMENT on fbo should generate INVALID_OPERATION.]

View file

@ -1,5 +1,5 @@
[readbuffer.html] [readbuffer.html]
[WebGL test #28: the color should be [0,0,0,255\]\nat (0, 0) expected: 0,0,0,255 was 0,0,255,255] [WebGL test #28: the color should be [0,0,0,255\]\nat (0, 0) expected: 0,0,0,255 was 0,0,0,0]
expected: FAIL expected: FAIL
[WebGL test #15: getError expected: INVALID_OPERATION. Was INVALID_ENUM : calling readBuffer with GL_COLOR_ATTACHMENTi that exceeds MAX_COLOR_ATTACHMENT on fbo should generate INVALID_OPERATION.] [WebGL test #15: getError expected: INVALID_OPERATION. Was INVALID_ENUM : calling readBuffer with GL_COLOR_ATTACHMENTi that exceeds MAX_COLOR_ATTACHMENT on fbo should generate INVALID_OPERATION.]