u
This commit is contained in:
parent
87c91c0c5a
commit
f129866f2c
1 changed files with 5 additions and 32 deletions
37
server.c
37
server.c
|
@ -81,40 +81,12 @@ static inline void convert_kmsbuf(const int XSTRIPE, const int YSTRIPE, const ch
|
|||
convert_bgrx_to_rgb(kms_convert_buf, width, height, buff);
|
||||
}
|
||||
|
||||
static size_t get_extra_mmap_bytes(const int XSTRIPE, const int YSTRIPE, int width, int height) {
|
||||
if (height % YSTRIPE) {
|
||||
int offset_max = 0;
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
int sno = (x / XSTRIPE) + (y / YSTRIPE) * (width / XSTRIPE);
|
||||
int ord = (x % XSTRIPE) + (y % YSTRIPE) * XSTRIPE;
|
||||
int offset = sno * XSTRIPE * YSTRIPE + ord;
|
||||
if (offset > offset_max) {
|
||||
offset_max = offset;
|
||||
}
|
||||
}
|
||||
}
|
||||
return offset_max * 4 - height*width * 4;
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#define XSTRIPE_INTEL 128
|
||||
#define YSTRIPE_INTEL 8
|
||||
#define XSTRIPE_NVIDIA 16
|
||||
#define YSTRIPE_NVIDIA 128
|
||||
#define XSTRIPE_INTEL 16
|
||||
#define YSTRIPE_INTEL 128
|
||||
static size_t get_nvidia_extra_mmap_bytes(int width, int height) {
|
||||
return get_extra_mmap_bytes(XSTRIPE_NVIDIA, YSTRIPE_NVIDIA, width, height);
|
||||
}
|
||||
static size_t get_intel_extra_mmap_bytes(int width, int height) {
|
||||
return get_extra_mmap_bytes(XSTRIPE_NVIDIA, YSTRIPE_NVIDIA, width, height);
|
||||
}
|
||||
static void convert_nvidia_kmsbuf(const char* in, int width, int height, char* buff) {
|
||||
convert_kmsbuf(XSTRIPE_INTEL, YSTRIPE_INTEL, in, width, height, buff);
|
||||
convert_kmsbuf(XSTRIPE_NVIDIA, YSTRIPE_NVIDIA, in, width, height, buff);
|
||||
}
|
||||
static void convert_intel_kmsbuf(const char* in, int width, int height, char* buff) {
|
||||
convert_kmsbuf(XSTRIPE_INTEL, YSTRIPE_INTEL, in, width, height, buff);
|
||||
|
@ -456,7 +428,6 @@ int main(int argc, const char **argv)
|
|||
|
||||
if (strcmp(drm_ver->name, "i915") == 0) {
|
||||
funcs.convert = &convert_intel_kmsbuf;
|
||||
mmap_size += get_intel_extra_mmap_bytes(fb->width, fb->height);
|
||||
}
|
||||
else if (strcmp(drm_ver->name, "amdgpu") == 0) {
|
||||
struct drm_gem_flink flink;
|
||||
|
@ -485,7 +456,6 @@ int main(int argc, const char **argv)
|
|||
else if (strcmp(drm_ver->name, "nvidia-drm") == 0) {
|
||||
// quirky and slow
|
||||
funcs.convert = &convert_nvidia_kmsbuf;
|
||||
mmap_size += get_nvidia_extra_mmap_bytes(fb->width, fb->height);
|
||||
}
|
||||
else if (strcmp(drm_ver->name, "vmwgfx") == 0 || strcmp(drm_ver->name, "vboxvideo") == 0 || strcmp(drm_ver->name, "virtio_gpu") == 0) {
|
||||
// virgl does not work
|
||||
|
@ -507,7 +477,9 @@ int main(int argc, const char **argv)
|
|||
|
||||
size_t buflen = fb->width * fb->height * 32 / 8;
|
||||
char *buf = malloc(buflen);
|
||||
char *buf2 = malloc(buflen);
|
||||
memset(buf, 0, buflen);
|
||||
memset(buf2, 0, buflen);
|
||||
|
||||
resolution.x = fb->width;
|
||||
resolution.y = fb->height;
|
||||
|
@ -528,8 +500,9 @@ int main(int argc, const char **argv)
|
|||
while (rfbIsActive(server)) {
|
||||
if (server->clientHead && TimeToTakePicture()) {
|
||||
funcs.sync_start(primefd);
|
||||
funcs.convert(mapped, fb->width, fb->height, buf);
|
||||
memcpy(buf2, mapped, buflen);
|
||||
funcs.sync_end(primefd);
|
||||
funcs.convert(buf2, fb->width, fb->height, buf);
|
||||
rfbMarkRectAsModified(server, 0, 0, fb->width, fb->height);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue