forma/utils.rs
1// Copyright 2020 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5pub fn clear_buffer(buffer: &mut [u8], clear_color: [u8; 4]) {
6 for color in buffer.chunks_exact_mut(4) {
7 color.copy_from_slice(&clear_color);
8 }
9}
10
11#[cfg(test)]
12mod tests {
13 use super::*;
14
15 const RED: [u8; 4] = [0xFF, 0x00, 0x00, 0xFF];
16 const GREEN: [u8; 4] = [0x00, 0xFF, 0x00, 0xFF];
17
18 #[test]
19 fn clear_to_red() {
20 let mut buffer = [GREEN; 3].concat();
21 clear_buffer(&mut buffer, RED);
22 assert_eq!(buffer, [RED, RED, RED].concat());
23 }
24}