Merge branch 'simplify/b17' into simplify/w1a
Browse files at this commit4 changed files +20 -19
- shims/cros-libva/src/config.rs +3 -3
- shims/cros-libva/src/display.rs +5 -9
- 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 | // Safe because `self` represents a valid VAConfig. We first query how | 74 | // Safe because `self` represents a valid VAConfig. We first query how |
| 75 | // much space is needed by the C API by passing in NULL in the first | 75 | // much space is needed by the C API by passing in NULL in the first |
| 76 | // call to `vaQuerySurfaceAttributes`. | 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 | va_check(unsafe { | 78 | va_check(unsafe { |
| 79 | bindings::vaQuerySurfaceAttributes( | 79 | bindings::vaQuerySurfaceAttributes( |
| 80 | self.display.handle(), | 80 | self.display.handle(), |
| 81 | self.id, | 81 | self.id, |
| 82 | std::ptr::null_mut(), | 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 | self.display.handle(), | 93 | self.display.handle(), |
| 94 | self.id, | 94 | self.id, |
| 95 | attrs.as_mut_ptr(), | 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+5 -9
| @@ -45,18 +45,14 @@ impl Iterator for DrmDeviceIterator { | |||
| 45 | type Item = PathBuf; | 45 | type Item = PathBuf; |
| 46 | 46 | ||
| 47 | fn next(&mut self) -> Option<Self::Item> { | 47 | fn next(&mut self) -> Option<Self::Item> { |
| 48 | - match self.cur_idx { | 48 | + while self.cur_idx < DRM_RENDER_NODE_START + DRM_NUM_NODES { |
| 49 | - idx if idx >= DRM_RENDER_NODE_START + DRM_NUM_NODES => None, | 49 | + let path = PathBuf::from(format!("{}{}", DRM_NODE_DEFAULT_PREFIX, self.cur_idx)); |
| 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; | 50 | self.cur_idx += 1; |
| 56 | - Some(path) | 51 | + if path.exists() { |
| 57 | - } | 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 | bindings::vaMapBuffer(surface.display().handle(), image.buf, &mut addr) | 57 | bindings::vaMapBuffer(surface.display().handle(), image.buf, &mut addr) |
| 58 | }) { | 58 | }) { |
| 59 | Ok(_) => { | 59 | Ok(_) => { |
| 60 | - // Assert that libva provided us with a coded resolution that is | 60 | + if u32::from(image.width) < display_resolution.0 |
| 61 | - // at least as large as `display_resolution`. | 61 | + || u32::from(image.height) < display_resolution.1 |
| 62 | - assert!(u32::from(image.width) >= display_resolution.0); | 62 | + { |
| 63 | - assert!(u32::from(image.height) >= display_resolution.1); | 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 | // Safe since `addr` points to data mapped onto our address space since we called | 72 | // Safe since `addr` points to data mapped onto our address space since we called |
| 66 | // `vaMapBuffer` above, which also guarantees that the data is valid for | 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 | // to create "safe" descriptors outside of this method and thus from made up values, | 364 | // to create "safe" descriptors outside of this method and thus from made up values, |
| 365 | // violating the safety guarantee that our FDs are legit. | 365 | // violating the safety guarantee that our FDs are legit. |
| 366 | 366 | ||
| 367 | - let objects = (0..desc.num_objects as usize) | 367 | + let objects = (0..(desc.num_objects as usize).min(4)) |
| 368 | - // Make sure we don't go out of bounds. | ||
| 369 | - .take(4) | ||
| 370 | .map(|i| desc.objects[i]) | 368 | .map(|i| desc.objects[i]) |
| 371 | .map(|o| { | 369 | .map(|o| { |
| 372 | DrmPrimeSurfaceDescriptorObject { | 370 | DrmPrimeSurfaceDescriptorObject { |