Ensure it compiles on Linux again

This commit is contained in:
loki
2020-04-15 21:07:00 +02:00
parent 525e8b3c6d
commit 0b1a69a067
3 changed files with 37 additions and 24 deletions
-2
View File
@@ -139,8 +139,6 @@ int alloc_gamepad(input_t &input, int nr);
void free_gamepad(input_t &input, int nr); void free_gamepad(input_t &input, int nr);
[[nodiscard]] std::unique_ptr<deinit_t> init(); [[nodiscard]] std::unique_ptr<deinit_t> init();
int thread_priority();
} }
#endif //SUNSHINE_COMMON_H #endif //SUNSHINE_COMMON_H
+36 -21
View File
@@ -145,14 +145,22 @@ struct x11_attr_t : public display_t {
xwindow = DefaultRootWindow(xdisplay.get()); xwindow = DefaultRootWindow(xdisplay.get());
refresh(); refresh();
width = xattr.width;
height = xattr.height;
} }
void refresh() { void refresh() {
XGetWindowAttributes(xdisplay.get(), xwindow, &xattr); XGetWindowAttributes(xdisplay.get(), xwindow, &xattr);
} }
capture_e snapshot(img_t *img_out_base, bool cursor) override { capture_e snapshot(img_t *img_out_base, std::chrono::milliseconds timeout, bool cursor) override {
refresh(); refresh();
if(width != xattr.width || height != xattr.height) {
return capture_e::reinit;
}
XImage *img { XGetImage( XImage *img { XGetImage(
xdisplay.get(), xdisplay.get(),
xwindow, xwindow,
@@ -180,6 +188,11 @@ struct x11_attr_t : public display_t {
return std::make_shared<x11_img_t>(); return std::make_shared<x11_img_t>();
} }
int dummy_img(img_t *img) override {
snapshot(img, 0s, true);
return 0;
}
xdisplay_t xdisplay; xdisplay_t xdisplay;
Window xwindow; Window xwindow;
XWindowAttributes xattr; XWindowAttributes xattr;
@@ -210,8 +223,8 @@ struct shm_attr_t : public x11_attr_t {
while(!task_pool.cancel(refresh_task_id)); while(!task_pool.cancel(refresh_task_id));
} }
capture_e snapshot(img_t *img, bool cursor) override { capture_e snapshot(img_t *img, std::chrono::milliseconds timeout, bool cursor) override {
if(display->width_in_pixels != xattr.width || display->height_in_pixels != xattr.height) { if(width != xattr.width || height != xattr.height) {
return capture_e::reinit; return capture_e::reinit;
} }
@@ -219,7 +232,7 @@ struct shm_attr_t : public x11_attr_t {
xcb.get(), xcb.get(),
display->root, display->root,
0, 0, 0, 0,
display->width_in_pixels, display->height_in_pixels, width, height,
~0, ~0,
XCB_IMAGE_FORMAT_Z_PIXMAP, XCB_IMAGE_FORMAT_Z_PIXMAP,
seg, seg,
@@ -232,16 +245,6 @@ struct shm_attr_t : public x11_attr_t {
return capture_e::reinit; return capture_e::reinit;
} }
if(img->width != display->width_in_pixels || img->height != display->height_in_pixels) {
delete[] img->data;
img->data = new std::uint8_t[frame_size()];
img->width = display->width_in_pixels;
img->height = display->height_in_pixels;
img->pixel_pitch = 4;
img->row_pitch = img->width * img->pixel_pitch;
}
std::copy_n((std::uint8_t*)data.data, frame_size(), img->data); std::copy_n((std::uint8_t*)data.data, frame_size(), img->data);
if(cursor) { if(cursor) {
@@ -252,13 +255,18 @@ struct shm_attr_t : public x11_attr_t {
} }
std::shared_ptr<img_t> alloc_img() override { std::shared_ptr<img_t> alloc_img() override {
return std::make_shared<shm_img_t>(); auto img = std::make_shared<shm_img_t>();
img->width = width;
img->height = height;
img->pixel_pitch = 4;
img->row_pitch = img->pixel_pitch * width;
img->data = new std::uint8_t[height * img->row_pitch];
return img;
} }
int dummy_img(platf::img_t *img, int &) override { int dummy_img(platf::img_t *img) override {
auto dummy_data_p = new int[1]; return 0;
return platf::display_t::dummy_img(img, *dummy_data_p);
} }
int init() { int init() {
@@ -293,11 +301,14 @@ struct shm_attr_t : public x11_attr_t {
return -1; return -1;
} }
width = display->width_in_pixels;
height = display->height_in_pixels;
return 0; return 0;
} }
std::uint32_t frame_size() { std::uint32_t frame_size() {
return display->height_in_pixels * display->width_in_pixels * 4; return width * height * 4;
} }
}; };
@@ -331,7 +342,11 @@ std::shared_ptr<display_t> shm_display() {
return shm; return shm;
} }
std::shared_ptr<display_t> display(int hwdevice_type) { std::shared_ptr<display_t> display(platf::dev_type_e hwdevice_type) {
if(hwdevice_type != platf::dev_type_e::none) {
return nullptr;
}
auto shm_disp = shm_display(); auto shm_disp = shm_display();
if(!shm_disp) { if(!shm_disp) {