Merge branch 'simplify/b17' into simplify/w1a
Browse files at this commit4 changed files +21 -20
- shims/cros-libva/src/config.rs +3 -3
- shims/cros-libva/src/display.rs +6 -10
- shims/cros-libva/src/image.rs +11 -4
- shims/cros-libva/src/surface.rs +1 -3
shims/cros-libva/src/config.rsmodified+3 -3
| @@ -74,13 +74,13 @@ impl Config { | ||
| 74 | 74 | // Safe because `self` represents a valid VAConfig. We first query how |
| 75 | 75 | // much space is needed by the C API by passing in NULL in the first |
| 76 | 76 | // call to `vaQuerySurfaceAttributes`. |
| 77 | - let attrs_len: std::os::raw::c_uint = 0; | |
| 77 | + let mut attrs_len: std::os::raw::c_uint = 0; | |
| 78 | 78 | va_check(unsafe { |
| 79 | 79 | bindings::vaQuerySurfaceAttributes( |
| 80 | 80 | self.display.handle(), |
| 81 | 81 | self.id, |
| 82 | 82 | std::ptr::null_mut(), |
| 83 | - &attrs_len as *const _ as *mut std::os::raw::c_uint, | |
| 83 | + &mut attrs_len, | |
| 84 | 84 | ) |
| 85 | 85 | })?; |
| 86 | 86 | |
| @@ -93,7 +93,7 @@ impl Config { | ||
| 93 | 93 | self.display.handle(), |
| 94 | 94 | self.id, |
| 95 | 95 | attrs.as_mut_ptr(), |
| 96 | - &attrs_len as *const _ as *mut std::os::raw::c_uint, | |
| 96 | + &mut attrs_len, | |
| 97 | 97 | ) |
| 98 | 98 | })?; |
| 99 | 99 |
shims/cros-libva/src/display.rsmodified+6 -10
| @@ -45,18 +45,14 @@ impl Iterator for DrmDeviceIterator { | ||
| 45 | 45 | type Item = PathBuf; |
| 46 | 46 | |
| 47 | 47 | fn next(&mut self) -> Option<Self::Item> { |
| 48 | - match self.cur_idx { | |
| 49 | - idx if idx >= DRM_RENDER_NODE_START + DRM_NUM_NODES => None, | |
| 50 | - idx => { | |
| 51 | - let path = PathBuf::from(format!("{}{}", DRM_NODE_DEFAULT_PREFIX, idx)); | |
| 52 | - if !path.exists() { | |
| 53 | - None | |
| 54 | - } else { | |
| 55 | - self.cur_idx += 1; | |
| 56 | - Some(path) | |
| 57 | - } | |
| 48 | + while self.cur_idx < DRM_RENDER_NODE_START + DRM_NUM_NODES { | |
| 49 | + let path = PathBuf::from(format!("{}{}", DRM_NODE_DEFAULT_PREFIX, self.cur_idx)); | |
| 50 | + self.cur_idx += 1; | |
| 51 | + if path.exists() { | |
| 52 | + return Some(path); | |
| 58 | 53 | } |
| 59 | 54 | } |
| 55 | + None | |
| 60 | 56 | } |
| 61 | 57 | } |
| 62 | 58 |
shims/cros-libva/src/image.rsmodified+11 -4
| @@ -57,10 +57,17 @@ impl<'a> Image<'a> { | ||
| 57 | 57 | bindings::vaMapBuffer(surface.display().handle(), image.buf, &mut addr) |
| 58 | 58 | }) { |
| 59 | 59 | Ok(_) => { |
| 60 | - // Assert that libva provided us with a coded resolution that is | |
| 61 | - // at least as large as `display_resolution`. | |
| 62 | - assert!(u32::from(image.width) >= display_resolution.0); | |
| 63 | - assert!(u32::from(image.height) >= display_resolution.1); | |
| 60 | + if u32::from(image.width) < display_resolution.0 | |
| 61 | + || u32::from(image.height) < display_resolution.1 | |
| 62 | + { | |
| 63 | + // Safe because the buffer was mapped above and `image` is a valid `VAImage`. | |
| 64 | + unsafe { | |
| 65 | + bindings::vaUnmapBuffer(surface.display().handle(), image.buf); | |
| 66 | + bindings::vaDestroyImage(surface.display().handle(), image.image_id); | |
| 67 | + } | |
| 68 | + | |
| 69 | + return Err(va_check(bindings::VA_STATUS_ERROR_INVALID_IMAGE as _).unwrap_err()); | |
| 70 | + } | |
| 64 | 71 | |
| 65 | 72 | // Safe since `addr` points to data mapped onto our address space since we called |
| 66 | 73 | // `vaMapBuffer` above, which also guarantees that the data is valid for |
shims/cros-libva/src/surface.rsmodified+1 -3
| @@ -364,9 +364,7 @@ impl<D: SurfaceMemoryDescriptor> Surface<D> { | ||
| 364 | 364 | // to create "safe" descriptors outside of this method and thus from made up values, |
| 365 | 365 | // violating the safety guarantee that our FDs are legit. |
| 366 | 366 | |
| 367 | - let objects = (0..desc.num_objects as usize) | |
| 368 | - // Make sure we don't go out of bounds. | |
| 369 | - .take(4) | |
| 367 | + let objects = (0..(desc.num_objects as usize).min(4)) | |
| 370 | 368 | .map(|i| desc.objects[i]) |
| 371 | 369 | .map(|o| { |
| 372 | 370 | DrmPrimeSurfaceDescriptorObject { |