Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernauer committed Jun 10, 2024
1 parent d236fd2 commit 04138e3
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 6 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,17 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: test
args: --no-default-features
args: --no-default-features --all-targets
- name: Test with all features turned on
uses: actions-rs/cargo@v1
with:
command: test
args: --all-features
- name: Test vnc features
args: --all-features --all-targets
- name: Test vnc feature
uses: actions-rs/cargo@v1
with:
command: test
args: --no-default-features --features vnc
args: --no-default-features --features vnc --all-targets

run_build:
name: Build for ${{ matrix.target }}
Expand Down
16 changes: 16 additions & 0 deletions breakwater-parser/src/original.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::Parser;
pub const PARSER_LOOKAHEAD: usize = "PX 1234 1234 rrggbbaa\n".len(); // Longest possible command

pub(crate) const PX_PATTERN: u64 = string_to_number(b"PX \0\0\0\0\0");
pub(crate) const PB_PATTERN: u64 = string_to_number(b"PB\0\0\0\0\0\0");
pub(crate) const OFFSET_PATTERN: u64 = string_to_number(b"OFFSET \0\0");
pub(crate) const SIZE_PATTERN: u64 = string_to_number(b"SIZE\0\0\0\0");
pub(crate) const HELP_PATTERN: u64 = string_to_number(b"HELP\0\0\0\0");
Expand Down Expand Up @@ -140,6 +141,21 @@ impl Parser for OriginalParser {
continue;
}
}
// In case the feature is disabled this if should be optimized away, as "cfg!" should be a constant expression.
} else if cfg!(feature = "binary-commands")
&& current_command & 0x0000_ffff == PB_PATTERN
{
let command_bytes =
unsafe { (buffer.as_ptr().add(i + 2) as *const u64).read_unaligned() };

let x = u16::from_le((command_bytes) as u16);
let y = u16::from_le((command_bytes >> 16) as u16);
let rgba = u32::from_le((command_bytes >> 32) as u32);

self.fb.set(x as usize, y as usize, rgba & 0x00ff_ffff);

i += 10;
continue;
} else if current_command & 0x00ff_ffff_ffff_ffff == OFFSET_PATTERN {
i += 7;

Expand Down
42 changes: 40 additions & 2 deletions breakwater/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,44 @@ async fn test_setting_pixel(
assert_eq!(expected, stream.get_output());
}

#[cfg(feature = "binary-commands")]
#[rstest]
// No newline in between needed
#[case("PB\0\0\0\0\0\0\0\0PX 0 0\n", "PX 0 0 000000\n")]
#[case("PB\0\0\0\01234PX 0 0\n", "PX 0 0 313233\n")]
#[case("PB\0\0\0\0\0\0\0\0PB\0\0\0\01234PX 0 0\n", "PX 0 0 313233\n")]
#[case(
"PB\0\0\0\0\0\0\0\0PX 0 0\nPB\0\0\0\01234PX 0 0\n",
"PX 0 0 000000\nPX 0 0 313233\n"
)]
#[case("PB \0*\0____PX 32 42\n", "PX 32 42 5f5f5f\n")]
#[tokio::test]
async fn test_binary_commands(
#[case] input: &str,
#[case] expected: &str,
ip: IpAddr,
fb: Arc<FrameBuffer>,
statistics_channel: (
mpsc::Sender<StatisticsEvent>,
mpsc::Receiver<StatisticsEvent>,
),
) {
let mut stream = MockTcpStream::from_input(input);
handle_connection(
&mut stream,
ip,
fb,
statistics_channel.0,
DEFAULT_NETWORK_BUFFER_SIZE,
page_size::get(),
None,
)
.await
.unwrap();

assert_eq!(expected, stream.get_output());
}

#[rstest]
#[case("PX 0 0 aaaaaa\n")]
#[case("PX 0 0 aa\n")]
Expand Down Expand Up @@ -180,8 +218,8 @@ async fn test_safe(
#[case(479, 361, 721, 391)]
#[case(500, 500, 0, 0)]
#[case(500, 500, 300, 400)]
#[case(fb().get_width(), fb().get_height(), 0, 0)]
#[case(fb().get_width() - 1, fb().get_height() - 1, 1, 1)]
// Yes, this exceeds the framebuffer size
#[case(10, 10, fb().get_width(), fb().get_height())]
#[tokio::test]
async fn test_drawing_rect(
#[case] width: usize,
Expand Down

0 comments on commit 04138e3

Please sign in to comment.