clippy: fix some warnings in components/canvas (#31563)

This commit is contained in:
eri 2024-03-08 08:24:01 +01:00 committed by GitHub
parent ef3dad3a61
commit 5c4f8cf0df
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 90 additions and 98 deletions

View file

@ -74,23 +74,23 @@ impl PathState {
pub trait Backend { pub trait Backend {
fn get_composition_op(&self, opts: &DrawOptions) -> CompositionOp; fn get_composition_op(&self, opts: &DrawOptions) -> CompositionOp;
fn need_to_draw_shadow(&self, color: &Color) -> bool; fn need_to_draw_shadow(&self, color: &Color) -> bool;
fn set_shadow_color<'a>(&mut self, color: RGBA, state: &mut CanvasPaintState<'a>); fn set_shadow_color(&mut self, color: RGBA, state: &mut CanvasPaintState<'_>);
fn set_fill_style<'a>( fn set_fill_style(
&mut self, &mut self,
style: FillOrStrokeStyle, style: FillOrStrokeStyle,
state: &mut CanvasPaintState<'a>, state: &mut CanvasPaintState<'_>,
drawtarget: &dyn GenericDrawTarget, drawtarget: &dyn GenericDrawTarget,
); );
fn set_stroke_style<'a>( fn set_stroke_style(
&mut self, &mut self,
style: FillOrStrokeStyle, style: FillOrStrokeStyle,
state: &mut CanvasPaintState<'a>, state: &mut CanvasPaintState<'_>,
drawtarget: &dyn GenericDrawTarget, drawtarget: &dyn GenericDrawTarget,
); );
fn set_global_composition<'a>( fn set_global_composition(
&mut self, &mut self,
op: CompositionOrBlending, op: CompositionOrBlending,
state: &mut CanvasPaintState<'a>, state: &mut CanvasPaintState<'_>,
); );
fn create_drawtarget(&self, size: Size2D<u64>) -> Box<dyn GenericDrawTarget>; fn create_drawtarget(&self, size: Size2D<u64>) -> Box<dyn GenericDrawTarget>;
fn recreate_paint_state<'a>(&self, state: &CanvasPaintState<'a>) -> CanvasPaintState<'a>; fn recreate_paint_state<'a>(&self, state: &CanvasPaintState<'a>) -> CanvasPaintState<'a>;
@ -222,10 +222,9 @@ impl<'a> PathBuilderRef<'a> {
Some(i) => i, Some(i) => i,
None => return None, None => return None,
}; };
match self.builder.get_current_point() { self.builder
Some(point) => Some(inverse.transform_point(Point2D::new(point.x, point.y))), .get_current_point()
None => None, .map(|point| inverse.transform_point(Point2D::new(point.x, point.y)))
}
} }
fn close(&mut self) { fn close(&mut self) {
@ -428,7 +427,7 @@ impl<'a> CanvasData<'a> {
let source_rect = source_rect.ceil(); let source_rect = source_rect.ceil();
// It discards the extra pixels (if any) that won't be painted // It discards the extra pixels (if any) that won't be painted
let image_data = if Rect::from_size(image_size).contains_rect(&source_rect) { let image_data = if Rect::from_size(image_size).contains_rect(&source_rect) {
pixels::rgba8_get_rect(&image_data, image_size.to_u64(), source_rect.to_u64()).into() pixels::rgba8_get_rect(image_data, image_size.to_u64(), source_rect.to_u64()).into()
} else { } else {
image_data.into() image_data.into()
}; };
@ -493,7 +492,7 @@ impl<'a> CanvasData<'a> {
let font = font_style.map_or_else( let font = font_style.map_or_else(
|| load_system_font_from_style(None), || load_system_font_from_style(None),
|style| { |style| {
with_thread_local_font_context(&self, |font_context| { with_thread_local_font_context(self, |font_context| {
let font_group = font_context.font_group(ServoArc::new(style.clone())); let font_group = font_context.font_group(ServoArc::new(style.clone()));
let font = font_group let font = font_group
.borrow_mut() .borrow_mut()
@ -651,7 +650,7 @@ impl<'a> CanvasData<'a> {
} }
if self.need_to_draw_shadow() { if self.need_to_draw_shadow() {
self.draw_with_shadow(&rect, |new_draw_target: &mut dyn GenericDrawTarget| { self.draw_with_shadow(rect, |new_draw_target: &mut dyn GenericDrawTarget| {
new_draw_target.stroke_rect( new_draw_target.stroke_rect(
rect, rect,
self.state.stroke_style.clone(), self.state.stroke_style.clone(),
@ -918,7 +917,7 @@ impl<'a> CanvasData<'a> {
Some(p) => p, Some(p) => p,
None => { None => {
self.path_builder().move_to(cp1); self.path_builder().move_to(cp1);
cp1.clone() *cp1
}, },
}; };
let cp1 = *cp1; let cp1 = *cp1;
@ -1042,7 +1041,7 @@ impl<'a> CanvasData<'a> {
} }
}, },
} }
self.state.transform = transform.clone(); self.state.transform = *transform;
self.drawtarget.set_transform(transform) self.drawtarget.set_transform(transform)
} }
@ -1200,10 +1199,7 @@ impl<'a> CanvasData<'a> {
draw_shadow_source(&mut *new_draw_target); draw_shadow_source(&mut *new_draw_target);
self.drawtarget.draw_surface_with_shadow( self.drawtarget.draw_surface_with_shadow(
new_draw_target.snapshot(), new_draw_target.snapshot(),
&Point2D::new( &Point2D::new(shadow_src_rect.origin.x, shadow_src_rect.origin.y),
shadow_src_rect.origin.x as f32,
shadow_src_rect.origin.y as f32,
),
&self.state.shadow_color, &self.state.shadow_color,
&Vector2D::new( &Vector2D::new(
self.state.shadow_offset_x as f32, self.state.shadow_offset_x as f32,
@ -1394,18 +1390,18 @@ fn load_system_font_from_style(font_style: Option<&FontStyleStruct>) -> Option<F
}) })
.weight(Weight(style.font_weight.value())) .weight(Weight(style.font_weight.value()))
.stretch(Stretch(style.font_stretch.to_percentage().0)); .stretch(Stretch(style.font_stretch.to_percentage().0));
let font_handle = match SystemSource::new().select_best_match(&family_names, &properties) { let font_handle = match SystemSource::new().select_best_match(&family_names, properties) {
Ok(handle) => handle, Ok(handle) => handle,
Err(e) => { Err(e) => {
error!("error getting font handle for style {:?}: {}", style, e); error!("error getting font handle for style {:?}: {}", style, e);
return load_default_system_fallback_font(&properties); return load_default_system_fallback_font(properties);
}, },
}; };
match font_handle.load() { match font_handle.load() {
Ok(f) => Some(f), Ok(f) => Some(f),
Err(e) => { Err(e) => {
error!("error loading font for style {:?}: {}", style, e); error!("error loading font for style {:?}: {}", style, e);
load_default_system_fallback_font(&properties) load_default_system_fallback_font(properties)
}, },
} }
} }

View file

@ -130,7 +130,7 @@ impl<'a> CanvasPaintThread<'a> {
let font_cache_thread = self.font_cache_thread.clone(); let font_cache_thread = self.font_cache_thread.clone();
let canvas_id = self.next_canvas_id.clone(); let canvas_id = self.next_canvas_id;
self.next_canvas_id.0 += 1; self.next_canvas_id.0 += 1;
let canvas_data = CanvasData::new( let canvas_data = CanvasData::new(
@ -139,7 +139,7 @@ impl<'a> CanvasPaintThread<'a> {
antialias, antialias,
font_cache_thread, font_cache_thread,
); );
self.canvases.insert(canvas_id.clone(), canvas_data); self.canvases.insert(canvas_id, canvas_data);
canvas_id canvas_id
} }
@ -181,7 +181,7 @@ impl<'a> CanvasPaintThread<'a> {
source_rect, source_rect,
smoothing_enabled, smoothing_enabled,
) => self.canvas(canvas_id).draw_image( ) => self.canvas(canvas_id).draw_image(
&*image_data, image_data,
image_size, image_size,
dest_rect, dest_rect,
source_rect, source_rect,

View file

@ -29,14 +29,14 @@ impl Backend for RaqoteBackend {
color.as_raqote().a != 0 color.as_raqote().a != 0
} }
fn set_shadow_color<'a>(&mut self, color: RGBA, state: &mut CanvasPaintState<'a>) { fn set_shadow_color(&mut self, color: RGBA, state: &mut CanvasPaintState<'_>) {
state.shadow_color = Color::Raqote(color.to_raqote_style()); state.shadow_color = Color::Raqote(color.to_raqote_style());
} }
fn set_fill_style<'a>( fn set_fill_style(
&mut self, &mut self,
style: FillOrStrokeStyle, style: FillOrStrokeStyle,
state: &mut CanvasPaintState<'a>, state: &mut CanvasPaintState<'_>,
_drawtarget: &dyn GenericDrawTarget, _drawtarget: &dyn GenericDrawTarget,
) { ) {
if let Some(pattern) = style.to_raqote_pattern() { if let Some(pattern) = style.to_raqote_pattern() {
@ -44,10 +44,10 @@ impl Backend for RaqoteBackend {
} }
} }
fn set_stroke_style<'a>( fn set_stroke_style(
&mut self, &mut self,
style: FillOrStrokeStyle, style: FillOrStrokeStyle,
state: &mut CanvasPaintState<'a>, state: &mut CanvasPaintState<'_>,
_drawtarget: &dyn GenericDrawTarget, _drawtarget: &dyn GenericDrawTarget,
) { ) {
if let Some(pattern) = style.to_raqote_pattern() { if let Some(pattern) = style.to_raqote_pattern() {
@ -55,10 +55,10 @@ impl Backend for RaqoteBackend {
} }
} }
fn set_global_composition<'a>( fn set_global_composition(
&mut self, &mut self,
op: CompositionOrBlending, op: CompositionOrBlending,
state: &mut CanvasPaintState<'a>, state: &mut CanvasPaintState<'_>,
) { ) {
state.draw_options.as_raqote_mut().blend_mode = op.to_raqote_style(); state.draw_options.as_raqote_mut().blend_mode = op.to_raqote_style();
} }
@ -125,9 +125,9 @@ pub struct LinearGradientPattern {
impl LinearGradientPattern { impl LinearGradientPattern {
fn new(start: Point2D<f32>, end: Point2D<f32>, stops: Vec<raqote::GradientStop>) -> Self { fn new(start: Point2D<f32>, end: Point2D<f32>, stops: Vec<raqote::GradientStop>) -> Self {
LinearGradientPattern { LinearGradientPattern {
gradient: raqote::Gradient { stops: stops }, gradient: raqote::Gradient { stops },
start: start, start,
end: end, end,
} }
} }
} }
@ -150,11 +150,11 @@ impl RadialGradientPattern {
stops: Vec<raqote::GradientStop>, stops: Vec<raqote::GradientStop>,
) -> Self { ) -> Self {
RadialGradientPattern { RadialGradientPattern {
gradient: raqote::Gradient { stops: stops }, gradient: raqote::Gradient { stops },
center1: center1, center1,
radius1: radius1, radius1,
center2: center2, center2,
radius2: radius2, radius2,
} }
} }
} }
@ -177,10 +177,10 @@ impl<'a> SurfacePattern<'a> {
}, },
}; };
SurfacePattern { SurfacePattern {
image: image, image,
filter: filter, filter,
extend: extend, extend,
repeat: repeat, repeat,
transform: Transform2D::identity(), transform: Transform2D::identity(),
} }
} }
@ -389,7 +389,7 @@ impl GenericDrawTarget for raqote::DrawTarget {
fn create_gradient_stops(&self, gradient_stops: Vec<GradientStop>) -> GradientStops { fn create_gradient_stops(&self, gradient_stops: Vec<GradientStop>) -> GradientStops {
let mut stops = gradient_stops let mut stops = gradient_stops
.into_iter() .into_iter()
.map(|item| item.as_raqote().clone()) .map(|item| *item.as_raqote())
.collect::<Vec<raqote::GradientStop>>(); .collect::<Vec<raqote::GradientStop>>();
// https://www.w3.org/html/test/results/2dcontext/annotated-spec/canvas.html#testrefs.2d.gradient.interpolate.overlap // https://www.w3.org/html/test/results/2dcontext/annotated-spec/canvas.html#testrefs.2d.gradient.interpolate.overlap
stops.sort_by(|a, b| a.position.partial_cmp(&b.position).unwrap()); stops.sort_by(|a, b| a.position.partial_cmp(&b.position).unwrap());
@ -492,7 +492,7 @@ impl GenericDrawTarget for raqote::DrawTarget {
raqote::BlendMode::SrcOut | raqote::BlendMode::SrcOut |
raqote::BlendMode::DstIn | raqote::BlendMode::DstIn |
raqote::BlendMode::DstAtop => { raqote::BlendMode::DstAtop => {
let mut options = draw_options.as_raqote().clone(); let mut options = *draw_options.as_raqote();
self.push_layer_with_blend(1., options.blend_mode); self.push_layer_with_blend(1., options.blend_mode);
options.blend_mode = raqote::BlendMode::SrcOver; options.blend_mode = raqote::BlendMode::SrcOver;
self.fill(path.as_raqote(), &pattern.source(), &options); self.fill(path.as_raqote(), &pattern.source(), &options);
@ -654,22 +654,17 @@ impl GenericDrawTarget for raqote::DrawTarget {
#[allow(unsafe_code)] #[allow(unsafe_code)]
fn snapshot_data(&self, f: &dyn Fn(&[u8]) -> Vec<u8>) -> Vec<u8> { fn snapshot_data(&self, f: &dyn Fn(&[u8]) -> Vec<u8>) -> Vec<u8> {
let v = self.get_data(); let v = self.get_data();
f(unsafe { f(
std::slice::from_raw_parts( unsafe {
v.as_ptr() as *const u8, std::slice::from_raw_parts(v.as_ptr() as *const u8, std::mem::size_of_val(v))
v.len() * std::mem::size_of::<u32>(), },
) )
})
} }
#[allow(unsafe_code)] #[allow(unsafe_code)]
fn snapshot_data_owned(&self) -> Vec<u8> { fn snapshot_data_owned(&self) -> Vec<u8> {
let v = self.get_data(); let v = self.get_data();
unsafe { unsafe {
std::slice::from_raw_parts( std::slice::from_raw_parts(v.as_ptr() as *const u8, std::mem::size_of_val(v)).into()
v.as_ptr() as *const u8,
v.len() * std::mem::size_of::<u32>(),
)
.into()
} }
} }
} }

View file

@ -65,7 +65,7 @@ impl WebGLComm {
WebGLComm { WebGLComm {
webgl_threads: WebGLThreads(sender), webgl_threads: WebGLThreads(sender),
image_handler: Box::new(external), image_handler: Box::new(external),
webxr_layer_grand_manager: webxr_layer_grand_manager, webxr_layer_grand_manager,
} }
} }
} }

View file

@ -289,7 +289,7 @@ impl WebGLThread {
let exit = self.handle_msg(msg, &webgl_chan); let exit = self.handle_msg(msg, &webgl_chan);
if exit { if exit {
// Call remove_context functions in order to correctly delete WebRender image keys. // Call remove_context functions in order to correctly delete WebRender image keys.
let context_ids: Vec<WebGLContextId> = self.contexts.keys().map(|id| *id).collect(); let context_ids: Vec<WebGLContextId> = self.contexts.keys().copied().collect();
for id in context_ids { for id in context_ids {
self.remove_webgl_context(id); self.remove_webgl_context(id);
} }
@ -323,7 +323,7 @@ impl WebGLThread {
&mut self.bound_context_id, &mut self.bound_context_id,
) )
.expect("WebGLContext not found"); .expect("WebGLContext not found");
let glsl_version = Self::get_glsl_version(&*data.gl); let glsl_version = Self::get_glsl_version(&data.gl);
let api_type = match data.gl.get_type() { let api_type = match data.gl.get_type() {
gl::GlType::Gl => GlType::Gl, gl::GlType::Gl => GlType::Gl,
gl::GlType::Gles => GlType::Gles, gl::GlType::Gles => GlType::Gles,
@ -458,7 +458,7 @@ impl WebGLThread {
WebGLImpl::apply( WebGLImpl::apply(
&self.device, &self.device,
&data.ctx, &data.ctx,
&*data.gl, &data.gl,
&mut data.state, &mut data.state,
&data.attributes, &data.attributes,
command, command,
@ -497,12 +497,12 @@ impl WebGLThread {
ContextAttributeFlags::STENCIL; ContextAttributeFlags::STENCIL;
let context_attributes = &ContextAttributes { let context_attributes = &ContextAttributes {
version: webgl_version.to_surfman_version(self.api_type), version: webgl_version.to_surfman_version(self.api_type),
flags: flags, flags,
}; };
let context_descriptor = self let context_descriptor = self
.device .device
.create_context_descriptor(&context_attributes) .create_context_descriptor(context_attributes)
.map_err(|err| format!("Failed to create context descriptor: {:?}", err))?; .map_err(|err| format!("Failed to create context descriptor: {:?}", err))?;
let safe_size = Size2D::new( let safe_size = Size2D::new(
@ -562,7 +562,7 @@ impl WebGLThread {
})), })),
}; };
let limits = GLLimits::detect(&*gl, webgl_version); let limits = GLLimits::detect(&gl, webgl_version);
let size = clamp_viewport(&gl, requested_size); let size = clamp_viewport(&gl, requested_size);
if safe_size != size { if safe_size != size {
@ -583,7 +583,7 @@ impl WebGLThread {
.device .device
.context_surface_info(&ctx) .context_surface_info(&ctx)
.map_err(|err| format!("Failed to get context surface info: {:?}", err))? .map_err(|err| format!("Failed to get context surface info: {:?}", err))?
.ok_or_else(|| format!("Failed to get context surface info"))? .ok_or_else(|| "Failed to get context surface info".to_string())?
.framebuffer_object; .framebuffer_object;
gl.bind_framebuffer(gl::FRAMEBUFFER, framebuffer); gl.bind_framebuffer(gl::FRAMEBUFFER, framebuffer);
@ -616,7 +616,7 @@ impl WebGLThread {
}; };
debug!("Created state {:?}", state); debug!("Created state {:?}", state);
state.restore_invariant(&*gl); state.restore_invariant(&gl);
debug_assert_eq!(gl.get_error(), gl::NO_ERROR); debug_assert_eq!(gl.get_error(), gl::NO_ERROR);
self.contexts.insert( self.contexts.insert(
@ -663,7 +663,7 @@ impl WebGLThread {
// Check to see if any of the current framebuffer bindings are the surface we're about to // Check to see if any of the current framebuffer bindings are the surface we're about to
// throw out. If so, we'll have to reset them after destroying the surface. // throw out. If so, we'll have to reset them after destroying the surface.
let framebuffer_rebinding_info = let framebuffer_rebinding_info =
FramebufferRebindingInfo::detect(&self.device, &data.ctx, &*data.gl); FramebufferRebindingInfo::detect(&self.device, &data.ctx, &data.gl);
// Resize the swap chains // Resize the swap chains
if let Some(swap_chain) = self.webrender_swap_chains.get(context_id) { if let Some(swap_chain) = self.webrender_swap_chains.get(context_id) {
@ -676,14 +676,14 @@ impl WebGLThread {
.resize(&mut self.device, &mut data.ctx, size.to_i32()) .resize(&mut self.device, &mut data.ctx, size.to_i32())
.map_err(|err| format!("Failed to resize swap chain: {:?}", err))?; .map_err(|err| format!("Failed to resize swap chain: {:?}", err))?;
swap_chain swap_chain
.clear_surface(&mut self.device, &mut data.ctx, &*data.gl, clear_color) .clear_surface(&mut self.device, &mut data.ctx, &data.gl, clear_color)
.map_err(|err| format!("Failed to clear resized swap chain: {:?}", err))?; .map_err(|err| format!("Failed to clear resized swap chain: {:?}", err))?;
} else { } else {
error!("Failed to find swap chain"); error!("Failed to find swap chain");
} }
// Reset framebuffer bindings as appropriate. // Reset framebuffer bindings as appropriate.
framebuffer_rebinding_info.apply(&self.device, &data.ctx, &*data.gl); framebuffer_rebinding_info.apply(&self.device, &data.ctx, &data.gl);
debug_assert_eq!(data.gl.get_error(), gl::NO_ERROR); debug_assert_eq!(data.gl.get_error(), gl::NO_ERROR);
let has_alpha = data let has_alpha = data
@ -764,7 +764,7 @@ impl WebGLThread {
// Check to see if any of the current framebuffer bindings are the surface we're about // Check to see if any of the current framebuffer bindings are the surface we're about
// to swap out. If so, we'll have to reset them after destroying the surface. // to swap out. If so, we'll have to reset them after destroying the surface.
let framebuffer_rebinding_info = let framebuffer_rebinding_info =
FramebufferRebindingInfo::detect(&self.device, &data.ctx, &*data.gl); FramebufferRebindingInfo::detect(&self.device, &data.ctx, &data.gl);
debug_assert_eq!(data.gl.get_error(), gl::NO_ERROR); debug_assert_eq!(data.gl.get_error(), gl::NO_ERROR);
debug!("Getting swap chain for {:?}", context_id); debug!("Getting swap chain for {:?}", context_id);
@ -779,7 +779,7 @@ impl WebGLThread {
&mut self.device, &mut self.device,
&mut data.ctx, &mut data.ctx,
if data.attributes.preserve_drawing_buffer { if data.attributes.preserve_drawing_buffer {
PreserveBuffer::Yes(&*data.gl) PreserveBuffer::Yes(&data.gl)
} else { } else {
PreserveBuffer::No PreserveBuffer::No
}, },
@ -795,14 +795,14 @@ impl WebGLThread {
.contains(ContextAttributeFlags::ALPHA); .contains(ContextAttributeFlags::ALPHA);
let clear_color = [0.0, 0.0, 0.0, !alpha as i32 as f32]; let clear_color = [0.0, 0.0, 0.0, !alpha as i32 as f32];
swap_chain swap_chain
.clear_surface(&mut self.device, &mut data.ctx, &*data.gl, clear_color) .clear_surface(&mut self.device, &mut data.ctx, &data.gl, clear_color)
.unwrap(); .unwrap();
debug_assert_eq!(data.gl.get_error(), gl::NO_ERROR); debug_assert_eq!(data.gl.get_error(), gl::NO_ERROR);
} }
// Rebind framebuffers as appropriate. // Rebind framebuffers as appropriate.
debug!("Rebinding {:?}", context_id); debug!("Rebinding {:?}", context_id);
framebuffer_rebinding_info.apply(&self.device, &data.ctx, &*data.gl); framebuffer_rebinding_info.apply(&self.device, &data.ctx, &data.gl);
debug_assert_eq!(data.gl.get_error(), gl::NO_ERROR); debug_assert_eq!(data.gl.get_error(), gl::NO_ERROR);
let SurfaceInfo { let SurfaceInfo {
@ -941,7 +941,7 @@ impl WebGLThread {
image_buffer_kind: ImageBufferKind, image_buffer_kind: ImageBufferKind,
) -> ImageData { ) -> ImageData {
let data = ExternalImageData { let data = ExternalImageData {
id: ExternalImageId(context_id.0 as u64), id: ExternalImageId(context_id.0),
channel_index: 0, channel_index: 0,
image_type: ExternalImageType::TextureHandle(image_buffer_kind), image_type: ExternalImageType::TextureHandle(image_buffer_kind),
}; };
@ -1288,7 +1288,7 @@ impl WebGLImpl {
sender.send(location).unwrap(); sender.send(location).unwrap();
}, },
WebGLCommand::GetUniformLocation(program_id, ref name, ref chan) => { WebGLCommand::GetUniformLocation(program_id, ref name, ref chan) => {
Self::uniform_location(gl, program_id, &name, chan) Self::uniform_location(gl, program_id, name, chan)
}, },
WebGLCommand::GetShaderInfoLog(shader_id, ref chan) => { WebGLCommand::GetShaderInfoLog(shader_id, ref chan) => {
Self::shader_info_log(gl, shader_id, chan) Self::shader_info_log(gl, shader_id, chan)
@ -1297,7 +1297,7 @@ impl WebGLImpl {
Self::program_info_log(gl, program_id, chan) Self::program_info_log(gl, program_id, chan)
}, },
WebGLCommand::CompileShader(shader_id, ref source) => { WebGLCommand::CompileShader(shader_id, ref source) => {
Self::compile_shader(gl, shader_id, &source) Self::compile_shader(gl, shader_id, source)
}, },
WebGLCommand::CreateBuffer(ref chan) => Self::create_buffer(gl, chan), WebGLCommand::CreateBuffer(ref chan) => Self::create_buffer(gl, chan),
WebGLCommand::CreateFramebuffer(ref chan) => Self::create_framebuffer(gl, chan), WebGLCommand::CreateFramebuffer(ref chan) => Self::create_framebuffer(gl, chan),
@ -1426,7 +1426,7 @@ impl WebGLImpl {
alpha_treatment, alpha_treatment,
y_axis_treatment, y_axis_treatment,
pixel_format, pixel_format,
Cow::Borrowed(&*data), Cow::Borrowed(data),
); );
gl.pixel_store_i(gl::UNPACK_ALIGNMENT, unpacking_alignment as i32); gl.pixel_store_i(gl::UNPACK_ALIGNMENT, unpacking_alignment as i32);
@ -1489,7 +1489,7 @@ impl WebGLImpl {
alpha_treatment, alpha_treatment,
y_axis_treatment, y_axis_treatment,
pixel_format, pixel_format,
Cow::Borrowed(&*data), Cow::Borrowed(data),
); );
gl.pixel_store_i(gl::UNPACK_ALIGNMENT, unpacking_alignment as i32); gl.pixel_store_i(gl::UNPACK_ALIGNMENT, unpacking_alignment as i32);
@ -1519,7 +1519,7 @@ impl WebGLImpl {
size.width as i32, size.width as i32,
size.height as i32, size.height as i32,
0, 0,
&*data, data,
); );
}, },
WebGLCommand::CompressedTexSubImage2D { WebGLCommand::CompressedTexSubImage2D {
@ -1533,13 +1533,13 @@ impl WebGLImpl {
} => { } => {
gl.compressed_tex_sub_image_2d( gl.compressed_tex_sub_image_2d(
target, target,
level as i32, level,
xoffset as i32, xoffset,
yoffset as i32, yoffset,
size.width as i32, size.width as i32,
size.height as i32, size.height as i32,
format, format,
&*data, data,
); );
}, },
WebGLCommand::TexStorage2D(target, levels, internal_format, width, height) => gl WebGLCommand::TexStorage2D(target, levels, internal_format, width, height) => gl
@ -1561,7 +1561,7 @@ impl WebGLImpl {
), ),
WebGLCommand::DrawingBufferWidth(ref sender) => { WebGLCommand::DrawingBufferWidth(ref sender) => {
let size = device let size = device
.context_surface_info(&ctx) .context_surface_info(ctx)
.unwrap() .unwrap()
.expect("Where's the front buffer?") .expect("Where's the front buffer?")
.size; .size;
@ -1569,7 +1569,7 @@ impl WebGLImpl {
}, },
WebGLCommand::DrawingBufferHeight(ref sender) => { WebGLCommand::DrawingBufferHeight(ref sender) => {
let size = device let size = device
.context_surface_info(&ctx) .context_surface_info(ctx)
.unwrap() .unwrap()
.expect("Where's the front buffer?") .expect("Where's the front buffer?")
.size; .size;
@ -1615,7 +1615,7 @@ impl WebGLImpl {
sender.send(value).unwrap(); sender.send(value).unwrap();
}, },
WebGLCommand::ClientWaitSync(sync_id, flags, timeout, ref sender) => { WebGLCommand::ClientWaitSync(sync_id, flags, timeout, ref sender) => {
let value = gl.client_wait_sync(sync_id.get() as *const _, flags, timeout as u64); let value = gl.client_wait_sync(sync_id.get() as *const _, flags, timeout);
sender.send(value).unwrap(); sender.send(value).unwrap();
}, },
WebGLCommand::WaitSync(sync_id, flags, timeout) => { WebGLCommand::WaitSync(sync_id, flags, timeout) => {
@ -1744,10 +1744,10 @@ impl WebGLImpl {
} }
}, },
WebGLCommand::TexParameteri(target, param, value) => { WebGLCommand::TexParameteri(target, param, value) => {
gl.tex_parameter_i(target, param as u32, value) gl.tex_parameter_i(target, param, value)
}, },
WebGLCommand::TexParameterf(target, param, value) => { WebGLCommand::TexParameterf(target, param, value) => {
gl.tex_parameter_f(target, param as u32, value) gl.tex_parameter_f(target, param, value)
}, },
WebGLCommand::LinkProgram(program_id, ref sender) => { WebGLCommand::LinkProgram(program_id, ref sender) => {
return sender.send(Self::link_program(gl, program_id)).unwrap(); return sender.send(Self::link_program(gl, program_id)).unwrap();
@ -2503,7 +2503,7 @@ impl WebGLImpl {
/// ///
/// To avoid hard-coding this we would need to use the `sh::GetAttributes` and `sh::GetUniforms` /// To avoid hard-coding this we would need to use the `sh::GetAttributes` and `sh::GetUniforms`
/// API to look up the `x.name` and `x.mappedName` members. /// API to look up the `x.name` and `x.mappedName` members.
const ANGLE_NAME_PREFIX: &'static str = "_u"; const ANGLE_NAME_PREFIX: &str = "_u";
fn to_name_in_compiled_shader(s: &str) -> String { fn to_name_in_compiled_shader(s: &str) -> String {
map_dot_separated(s, |s, mapped| { map_dot_separated(s, |s, mapped| {
@ -3057,7 +3057,7 @@ impl WebXRBridge {
.map_err(|_| WebXRError::CommunicationError)?; .map_err(|_| WebXRError::CommunicationError)?;
let manager = factory.build(device, contexts)?; let manager = factory.build(device, contexts)?;
let manager_id = unsafe { WebXRLayerManagerId::new(self.next_manager_id) }; let manager_id = unsafe { WebXRLayerManagerId::new(self.next_manager_id) };
self.next_manager_id = self.next_manager_id + 1; self.next_manager_id += 1;
self.managers.insert(manager_id, manager); self.managers.insert(manager_id, manager);
Ok(manager_id) Ok(manager_id)
} }
@ -3315,8 +3315,8 @@ impl<'a> WebXRContexts<WebXRSurfman> for WebXRBridgeContexts<'a> {
let data = WebGLThread::make_current_if_needed_mut( let data = WebGLThread::make_current_if_needed_mut(
device, device,
WebGLContextId::from(context_id), WebGLContextId::from(context_id),
&mut self.contexts, self.contexts,
&mut self.bound_context_id, self.bound_context_id,
)?; )?;
Some(&mut data.ctx) Some(&mut data.ctx)
} }
@ -3324,8 +3324,8 @@ impl<'a> WebXRContexts<WebXRSurfman> for WebXRBridgeContexts<'a> {
let data = WebGLThread::make_current_if_needed( let data = WebGLThread::make_current_if_needed(
device, device,
WebGLContextId::from(context_id), WebGLContextId::from(context_id),
&self.contexts, self.contexts,
&mut self.bound_context_id, self.bound_context_id,
)?; )?;
Some(&data.gl) Some(&data.gl)
} }

View file

@ -38,11 +38,11 @@ fn main() {
.and_then(|pkg| pkg.get("source").and_then(|source| source.as_str())) .and_then(|pkg| pkg.get("source").and_then(|source| source.as_str()))
.unwrap_or("unknown"); .unwrap_or("unknown");
let parsed: Vec<&str> = source.split("#").collect(); let parsed: Vec<&str> = source.split('#').collect();
let revision = if parsed.len() > 1 { parsed[1] } else { source }; let revision = if parsed.len() > 1 { parsed[1] } else { source };
let mut revision_module_file = File::create(&revision_file_path).unwrap(); let mut revision_module_file = File::create(revision_file_path).unwrap();
write!(&mut revision_module_file, "{}", format!("\"{}\"", revision)).unwrap(); write!(&mut revision_module_file, "\"{}\"", revision).unwrap();
}, },
_ => panic!("Cannot find package definitions in lockfile"), _ => panic!("Cannot find package definitions in lockfile"),
} }

View file

@ -530,6 +530,7 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
/// and the system creates a new native surface that needs to bound to the current /// and the system creates a new native surface that needs to bound to the current
/// context. /// context.
#[allow(unsafe_code)] #[allow(unsafe_code)]
#[allow(clippy::not_unsafe_ptr_arg_deref)] // It has an unsafe block inside
pub fn replace_native_surface(&mut self, native_widget: *mut c_void, coords: DeviceIntSize) { pub fn replace_native_surface(&mut self, native_widget: *mut c_void, coords: DeviceIntSize) {
debug!("Replacing native surface in compositor: {native_widget:?}"); debug!("Replacing native surface in compositor: {native_widget:?}");
let connection = self.rendering_context.connection(); let connection = self.rendering_context.connection();