Hermes
0.7.0
Linux game streaming host
Toggle main menu visibility
Loading...
Searching...
No Matches
session_frame.h
Go to the documentation of this file.
1
4
#pragma once
5
6
#include <cstddef>
7
#include <cstdint>
8
#include <cstring>
9
#include <limits>
10
#include <vector>
11
12
namespace
platf::kwin {
13
// This receiver deliberately negotiates positive-stride packed BGRx.
14
// Reject unsupported layouts instead of interpreting them as that format.
15
inline
bool
copy_bgrx(std::vector<std::uint8_t> &destination,
const
void
*mapping, std::size_t mapping_size, std::size_t offset, std::size_t chunk_size, std::int32_t stride, std::uint32_t width, std::uint32_t height) {
16
if
(!mapping || !width || !height || width > 16384 || height > 16384 || stride <= 0) {
17
return
false
;
18
}
19
const
std::size_t row_bytes =
static_cast<
std::size_t
>
(width) * 4;
20
const
auto
row_stride =
static_cast<
std::size_t
>
(stride);
21
if
(row_stride < row_bytes || offset > mapping_size || chunk_size > mapping_size - offset) {
22
return
false
;
23
}
24
if
(height - 1 > (std::numeric_limits<std::size_t>::max() - row_bytes) / row_stride) {
25
return
false
;
26
}
27
const
auto
required =
static_cast<
std::size_t
>
(height - 1) * row_stride + row_bytes;
28
if
(required > chunk_size || height > std::numeric_limits<std::size_t>::max() / row_bytes) {
29
return
false
;
30
}
31
destination.resize(row_bytes * height);
32
const
auto
*source =
static_cast<
const
std::uint8_t *
>
(mapping) + offset;
33
for
(std::size_t y = 0; y < height; ++y) {
34
std::memcpy(destination.data() + y * row_bytes, source + y * row_stride, row_bytes);
35
}
36
return
true
;
37
}
38
}
// namespace platf::kwin
src
platform
linux
session_frame.h
Generated by
1.18.0