-
Notifications
You must be signed in to change notification settings - Fork 67
Remove DamageOutOfRange error
#314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
1c34cbd
6c68049
1ec2833
ab16475
bc04c6e
55ce8e9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -260,16 +260,14 @@ impl BufferInterface for BufferImpl<'_> { | |
| self.surface.damage(0, 0, i32::MAX, i32::MAX); | ||
| } else { | ||
| for rect in damage { | ||
| // Damage that falls outside the surface is ignored. | ||
| // https://wayland.freedesktop.org/docs/html/apa.html#protocol-spec-wl_surface | ||
| let x = rect.x.try_into().unwrap_or(i32::MAX); | ||
| let y = rect.y.try_into().unwrap_or(i32::MAX); | ||
|
Comment on lines
+265
to
+266
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, no, |
||
| let width = rect.width.get().try_into().unwrap_or(i32::MAX); | ||
| let height = rect.height.get().try_into().unwrap_or(i32::MAX); | ||
|
|
||
| // Introduced in version 4, it is an error to use this request in version 3 or lower. | ||
| let (x, y, width, height) = (|| { | ||
| Some(( | ||
| i32::try_from(rect.x).ok()?, | ||
| i32::try_from(rect.y).ok()?, | ||
| i32::try_from(rect.width.get()).ok()?, | ||
| i32::try_from(rect.height.get()).ok()?, | ||
| )) | ||
| })() | ||
| .ok_or(SoftBufferError::DamageOutOfRange { rect: *rect })?; | ||
| self.surface.damage_buffer(x, y, width, height); | ||
| } | ||
| } | ||
|
|
@@ -284,17 +282,6 @@ impl BufferInterface for BufferImpl<'_> { | |
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| fn present(self) -> Result<(), SoftBufferError> { | ||
| let (width, height) = (self.width, self.height); | ||
| self.present_with_damage(&[Rect { | ||
| x: 0, | ||
| y: 0, | ||
| // We know width/height will be non-negative and non-zero. | ||
| width: (width as u32).try_into().unwrap(), | ||
| height: (height as u32).try_into().unwrap(), | ||
| }]) | ||
| } | ||
| } | ||
|
|
||
| impl Dispatch<wl_registry::WlRegistry, GlobalListContents> for State { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -331,20 +331,8 @@ impl BufferInterface for BufferImpl<'_> { | |
| } | ||
|
|
||
| /// Push the buffer to the canvas. | ||
| fn present(self) -> Result<(), SoftBufferError> { | ||
| let (width, height) = self | ||
| .size | ||
| .expect("Must set size of surface before calling `present()`"); | ||
| self.present_with_damage(&[Rect { | ||
| x: 0, | ||
| y: 0, | ||
| width, | ||
| height, | ||
| }]) | ||
| } | ||
|
|
||
| fn present_with_damage(self, damage: &[Rect]) -> Result<(), SoftBufferError> { | ||
| let (buffer_width, _buffer_height) = self | ||
| let (buffer_width, buffer_height) = self | ||
| .size | ||
| .expect("Must set size of surface before calling `present_with_damage()`"); | ||
|
|
||
|
|
@@ -370,8 +358,10 @@ impl BufferInterface for BufferImpl<'_> { | |
| .collect(); | ||
|
|
||
| debug_assert_eq!( | ||
| bitmap.len() as u32, | ||
| union_damage.width.get() * union_damage.height.get() * 4 | ||
| bitmap.len(), | ||
| union_damage.width.get().min(buffer_width.get()) as usize | ||
| * union_damage.height.get().min(buffer_height.get()) as usize | ||
| * 4 | ||
| ); | ||
|
|
||
| #[cfg(target_feature = "atomics")] | ||
|
|
@@ -394,14 +384,14 @@ impl BufferInterface for BufferImpl<'_> { | |
| let array = Uint8Array::new_with_length(bitmap.len() as u32); | ||
| array.copy_from(&bitmap); | ||
| let array = Uint8ClampedArray::new(&array); | ||
| ImageDataExt::new(array, union_damage.width.get()) | ||
| ImageDataExt::new(array, union_damage.width.get().min(buffer_width.get())) | ||
| .map(JsValue::from) | ||
| .map(ImageData::unchecked_from_js) | ||
| }; | ||
| #[cfg(not(target_feature = "atomics"))] | ||
| let result = ImageData::new_with_u8_clamped_array( | ||
| wasm_bindgen::Clamped(&bitmap), | ||
| union_damage.width.get(), | ||
| union_damage.width.get().min(buffer_width.get()), | ||
| ); | ||
| // This should only throw an error if the buffer we pass's size is incorrect. | ||
| let image_data = result.unwrap(); | ||
|
|
@@ -411,12 +401,12 @@ impl BufferInterface for BufferImpl<'_> { | |
| self.canvas | ||
| .put_image_data( | ||
| &image_data, | ||
| union_damage.x.into(), | ||
| union_damage.y.into(), | ||
| union_damage.x.min(buffer_width.get()).into(), | ||
| union_damage.y.min(buffer_height.get()).into(), | ||
| (rect.x - union_damage.x).into(), | ||
| (rect.y - union_damage.y).into(), | ||
| rect.width.get().into(), | ||
| rect.height.get().into(), | ||
| rect.width.get().min(buffer_width.get()).into(), | ||
| rect.height.get().min(buffer_height.get()).into(), | ||
|
Comment on lines
+408
to
+409
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't the width/height take into account the x/y offset before calling
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not entirely sure, but I think no? See the docs for I'd assume it's correct then to pass the size of the surface, though to be honest, I haven't really tested the Web part that much, only that it doesn't crash with width/height = |
||
| ) | ||
| .unwrap(); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, it seems that not having
xorymeans the rect should be infinitely large, starting at0rather thanMAX(and ending atMAX, making it 0×0)?