Screen.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include "Screen.h"
  7. #include "Compositor.h"
  8. #include "Event.h"
  9. #include "EventLoop.h"
  10. #include "WindowManager.h"
  11. #include <AK/Debug.h>
  12. #include <Kernel/API/FB.h>
  13. #include <Kernel/API/MousePacket.h>
  14. #include <fcntl.h>
  15. #include <stdio.h>
  16. #include <sys/mman.h>
  17. #include <unistd.h>
  18. namespace WindowServer {
  19. NonnullRefPtrVector<Screen, default_screen_count> Screen::s_screens;
  20. Screen* Screen::s_main_screen { nullptr };
  21. Gfx::IntRect Screen::s_bounding_screens_rect {};
  22. ScreenLayout Screen::s_layout;
  23. Vector<int, default_scale_factors_in_use_count> Screen::s_scale_factors_in_use;
  24. struct ScreenFBData {
  25. Vector<FBRect, 32> pending_flush_rects;
  26. bool too_many_pending_flush_rects { false };
  27. };
  28. ScreenInput& ScreenInput::the()
  29. {
  30. static ScreenInput s_the;
  31. return s_the;
  32. }
  33. Screen& ScreenInput::cursor_location_screen()
  34. {
  35. auto* screen = Screen::find_by_location(m_cursor_location);
  36. VERIFY(screen);
  37. return *screen;
  38. }
  39. const Screen& ScreenInput::cursor_location_screen() const
  40. {
  41. auto* screen = Screen::find_by_location(m_cursor_location);
  42. VERIFY(screen);
  43. return *screen;
  44. }
  45. bool Screen::apply_layout(ScreenLayout&& screen_layout, String& error_msg)
  46. {
  47. if (!screen_layout.is_valid(&error_msg))
  48. return false;
  49. if (screen_layout == s_layout)
  50. return true;
  51. bool place_cursor_on_main_screen = find_by_location(ScreenInput::the().cursor_location()) == nullptr;
  52. HashMap<size_t, size_t> current_to_new_indices_map;
  53. HashMap<size_t, size_t> new_to_current_indices_map;
  54. HashMap<size_t, NonnullRefPtr<Screen>> devices_no_longer_used;
  55. for (size_t i = 0; i < s_layout.screens.size(); i++) {
  56. auto& screen = s_layout.screens[i];
  57. bool found = false;
  58. for (size_t j = 0; j < screen_layout.screens.size(); j++) {
  59. auto& new_screen = screen_layout.screens[j];
  60. if (new_screen.device == screen.device) {
  61. current_to_new_indices_map.set(i, j);
  62. new_to_current_indices_map.set(j, i);
  63. found = true;
  64. break;
  65. }
  66. }
  67. if (!found)
  68. devices_no_longer_used.set(i, s_screens[i]);
  69. }
  70. HashMap<Screen*, size_t> screens_with_resolution_change;
  71. HashMap<Screen*, size_t> screens_with_scale_change;
  72. for (auto& it : current_to_new_indices_map) {
  73. auto& screen = s_layout.screens[it.key];
  74. auto& new_screen = screen_layout.screens[it.value];
  75. if (screen.resolution != new_screen.resolution)
  76. screens_with_resolution_change.set(&s_screens[it.key], it.value);
  77. if (screen.scale_factor != new_screen.scale_factor)
  78. screens_with_scale_change.set(&s_screens[it.key], it.value);
  79. }
  80. auto screens_backup = move(s_screens);
  81. auto layout_backup = move(s_layout);
  82. for (auto& it : screens_with_resolution_change) {
  83. auto& existing_screen = *it.key;
  84. dbgln("Closing device {} in preparation for resolution change", layout_backup.screens[existing_screen.index()].device);
  85. existing_screen.close_device();
  86. }
  87. AK::ArmedScopeGuard rollback([&] {
  88. for (auto& screen : s_screens)
  89. screen.close_device();
  90. s_screens = move(screens_backup);
  91. s_layout = move(layout_backup);
  92. for (size_t i = 0; i < s_screens.size(); i++) {
  93. auto& old_screen = s_screens[i];
  94. // Restore the original screen index in case it changed
  95. old_screen.set_index(i);
  96. if (i == s_layout.main_screen_index)
  97. old_screen.make_main_screen();
  98. bool changed_scale = screens_with_scale_change.contains(&old_screen);
  99. if (screens_with_resolution_change.contains(&old_screen)) {
  100. if (old_screen.open_device()) {
  101. // The resolution was changed, so we also implicitly applied the new scale factor
  102. changed_scale = false;
  103. } else {
  104. // Don't set error_msg here, it should already be set
  105. dbgln("Rolling back screen layout failed: could not open device");
  106. }
  107. }
  108. old_screen.update_virtual_rect();
  109. if (changed_scale)
  110. old_screen.scale_factor_changed();
  111. }
  112. update_bounding_rect();
  113. });
  114. s_layout = move(screen_layout);
  115. for (size_t index = 0; index < s_layout.screens.size(); index++) {
  116. Screen* screen;
  117. bool need_to_open_device;
  118. if (auto it = new_to_current_indices_map.find(index); it != new_to_current_indices_map.end()) {
  119. // Re-use the existing screen instance
  120. screen = &screens_backup[it->value];
  121. s_screens.append(*screen);
  122. screen->set_index(index);
  123. need_to_open_device = screens_with_resolution_change.contains(screen);
  124. } else {
  125. screen = WindowServer::Screen::create(index);
  126. if (!screen) {
  127. error_msg = String::formatted("Error creating screen #{}", index);
  128. return false;
  129. }
  130. need_to_open_device = true;
  131. }
  132. if (need_to_open_device && !screen->open_device()) {
  133. error_msg = String::formatted("Error opening device for screen #{}", index);
  134. return false;
  135. }
  136. screen->update_virtual_rect();
  137. if (!need_to_open_device && screens_with_scale_change.contains(screen))
  138. screen->scale_factor_changed();
  139. VERIFY(screen);
  140. VERIFY(index == screen->index());
  141. if (s_layout.main_screen_index == index)
  142. screen->make_main_screen();
  143. }
  144. rollback.disarm();
  145. if (place_cursor_on_main_screen) {
  146. ScreenInput::the().set_cursor_location(Screen::main().rect().center());
  147. } else {
  148. auto cursor_location = ScreenInput::the().cursor_location();
  149. if (!find_by_location(cursor_location)) {
  150. // Cursor is off screen, try to find the closest location on another screen
  151. float closest_distance = 0;
  152. Optional<Gfx::IntPoint> closest_point;
  153. for (auto& screen : s_screens) {
  154. auto closest_point_on_screen_rect = screen.rect().closest_to(cursor_location);
  155. auto distance = closest_point_on_screen_rect.distance_from(cursor_location);
  156. if (!closest_point.has_value() || distance < closest_distance) {
  157. closest_distance = distance;
  158. closest_point = closest_point_on_screen_rect;
  159. }
  160. }
  161. ScreenInput::the().set_cursor_location(closest_point.value()); // We should always have one
  162. }
  163. }
  164. update_bounding_rect();
  165. update_scale_factors_in_use();
  166. return true;
  167. }
  168. void Screen::update_scale_factors_in_use()
  169. {
  170. s_scale_factors_in_use.clear();
  171. for_each([&](auto& screen) {
  172. auto scale_factor = screen.scale_factor();
  173. // The This doesn't have to be extremely efficient as this
  174. // code is only run when we start up or the screen configuration
  175. // changes. But using a vector allows for efficient iteration,
  176. // which is the most common use case.
  177. if (!s_scale_factors_in_use.contains_slow(scale_factor))
  178. s_scale_factors_in_use.append(scale_factor);
  179. return IterationDecision::Continue;
  180. });
  181. }
  182. Screen::Screen(size_t screen_index)
  183. : m_index(screen_index)
  184. , m_framebuffer_data(adopt_own(*new ScreenFBData()))
  185. , m_compositor_screen_data(Compositor::create_screen_data({}))
  186. {
  187. update_virtual_rect();
  188. open_device();
  189. }
  190. Screen::~Screen()
  191. {
  192. close_device();
  193. }
  194. bool Screen::open_device()
  195. {
  196. close_device();
  197. auto& info = screen_layout_info();
  198. m_framebuffer_fd = open(info.device.characters(), O_RDWR | O_CLOEXEC);
  199. if (m_framebuffer_fd < 0) {
  200. perror(String::formatted("failed to open {}", info.device).characters());
  201. return false;
  202. }
  203. m_can_set_buffer = (fb_set_buffer(m_framebuffer_fd, 0) == 0);
  204. m_can_device_flush_buffers = true; // If the device can't do it we revert to false
  205. set_resolution(true);
  206. return true;
  207. }
  208. void Screen::close_device()
  209. {
  210. if (m_framebuffer_fd >= 0) {
  211. close(m_framebuffer_fd);
  212. m_framebuffer_fd = -1;
  213. }
  214. if (m_framebuffer) {
  215. int rc = munmap(m_framebuffer, m_size_in_bytes);
  216. VERIFY(rc == 0);
  217. m_framebuffer = nullptr;
  218. m_size_in_bytes = 0;
  219. }
  220. }
  221. void Screen::update_virtual_rect()
  222. {
  223. auto& screen_info = screen_layout_info();
  224. m_virtual_rect = { screen_info.location, { screen_info.resolution.width() / screen_info.scale_factor, screen_info.resolution.height() / screen_info.scale_factor } };
  225. dbgln("update_virtual_rect for screen #{}: {}", index(), m_virtual_rect);
  226. }
  227. void Screen::scale_factor_changed()
  228. {
  229. // Flush rects are affected by the screen factor
  230. constrain_pending_flush_rects();
  231. }
  232. void Screen::init()
  233. {
  234. set_resolution(true);
  235. }
  236. Screen& Screen::closest_to_rect(const Gfx::IntRect& rect)
  237. {
  238. Screen* best_screen = nullptr;
  239. int best_area = 0;
  240. for (auto& screen : s_screens) {
  241. auto r = screen.rect().intersected(rect);
  242. int area = r.width() * r.height();
  243. if (!best_screen || area > best_area) {
  244. best_screen = &screen;
  245. best_area = area;
  246. }
  247. }
  248. if (!best_screen) {
  249. // TODO: try to find the best screen in close proximity
  250. best_screen = &Screen::main();
  251. }
  252. return *best_screen;
  253. }
  254. Screen& Screen::closest_to_location(const Gfx::IntPoint& point)
  255. {
  256. for (auto& screen : s_screens) {
  257. if (screen.rect().contains(point))
  258. return screen;
  259. }
  260. // TODO: guess based on how close the point is to the next screen rectangle
  261. return Screen::main();
  262. }
  263. void Screen::update_bounding_rect()
  264. {
  265. if (!s_screens.is_empty()) {
  266. s_bounding_screens_rect = s_screens[0].rect();
  267. for (size_t i = 1; i < s_screens.size(); i++)
  268. s_bounding_screens_rect = s_bounding_screens_rect.united(s_screens[i].rect());
  269. } else {
  270. s_bounding_screens_rect = {};
  271. }
  272. }
  273. bool Screen::set_resolution(bool initial)
  274. {
  275. // Remember the screen that the cursor is on. Make sure it stays on the same screen if we change its resolution...
  276. Screen* screen_with_cursor = nullptr;
  277. if (!initial)
  278. screen_with_cursor = &ScreenInput::the().cursor_location_screen();
  279. auto& info = screen_layout_info();
  280. FBResolution physical_resolution { 0, (unsigned)info.resolution.width(), (unsigned)info.resolution.height() };
  281. int rc = fb_set_resolution(m_framebuffer_fd, &physical_resolution);
  282. dbgln_if(WSSCREEN_DEBUG, "Screen #{}: fb_set_resolution() - return code {}", index(), rc);
  283. auto on_change_resolution = [&]() {
  284. if (initial || physical_resolution.width != (unsigned)info.resolution.width() || physical_resolution.height != (unsigned)info.resolution.height()) {
  285. if (m_framebuffer) {
  286. size_t previous_size_in_bytes = m_size_in_bytes;
  287. int rc = munmap(m_framebuffer, previous_size_in_bytes);
  288. VERIFY(rc == 0);
  289. }
  290. int rc = fb_get_size_in_bytes(m_framebuffer_fd, &m_size_in_bytes);
  291. VERIFY(rc == 0);
  292. m_framebuffer = (Gfx::RGBA32*)mmap(nullptr, m_size_in_bytes, PROT_READ | PROT_WRITE, MAP_SHARED, m_framebuffer_fd, 0);
  293. VERIFY(m_framebuffer && m_framebuffer != (void*)-1);
  294. if (m_can_set_buffer) {
  295. unsigned buffer_offset = 0;
  296. rc = fb_get_buffer_offset(m_framebuffer_fd, 1, &buffer_offset);
  297. if (rc == 0) {
  298. m_back_buffer_offset = buffer_offset;
  299. } else {
  300. // fall back to assuming the second buffer starts right after the last line of the first
  301. m_back_buffer_offset = physical_resolution.pitch * physical_resolution.height;
  302. }
  303. } else {
  304. m_back_buffer_offset = 0;
  305. }
  306. }
  307. info.resolution = { physical_resolution.width, physical_resolution.height };
  308. m_pitch = physical_resolution.pitch;
  309. update_virtual_rect();
  310. // Since pending flush rects are affected by the scale factor
  311. // update even if only the scale factor changed
  312. constrain_pending_flush_rects();
  313. if (this == screen_with_cursor) {
  314. auto& screen_input = ScreenInput::the();
  315. screen_input.set_cursor_location(screen_input.cursor_location().constrained(rect()));
  316. }
  317. };
  318. if (rc == 0) {
  319. on_change_resolution();
  320. return true;
  321. }
  322. if (rc == -1) {
  323. int err = errno;
  324. dbgln("Screen #{}: Failed to set resolution {}: {}", index(), info.resolution, strerror(err));
  325. on_change_resolution();
  326. return false;
  327. }
  328. VERIFY_NOT_REACHED();
  329. }
  330. void Screen::set_buffer(int index)
  331. {
  332. VERIFY(m_can_set_buffer);
  333. int rc = fb_set_buffer(m_framebuffer_fd, index);
  334. VERIFY(rc == 0);
  335. }
  336. size_t Screen::buffer_offset(int index) const
  337. {
  338. if (index == 0)
  339. return 0;
  340. if (index == 1)
  341. return m_back_buffer_offset;
  342. VERIFY_NOT_REACHED();
  343. }
  344. void ScreenInput::set_acceleration_factor(double factor)
  345. {
  346. VERIFY(factor >= mouse_accel_min && factor <= mouse_accel_max);
  347. m_acceleration_factor = factor;
  348. }
  349. void ScreenInput::set_scroll_step_size(unsigned step_size)
  350. {
  351. VERIFY(step_size >= scroll_step_size_min);
  352. m_scroll_step_size = step_size;
  353. }
  354. void ScreenInput::on_receive_mouse_data(const MousePacket& packet)
  355. {
  356. auto& current_screen = cursor_location_screen();
  357. auto prev_location = m_cursor_location;
  358. if (packet.is_relative) {
  359. m_cursor_location.translate_by(packet.x * m_acceleration_factor, packet.y * m_acceleration_factor);
  360. dbgln_if(WSSCREEN_DEBUG, "Screen: New Relative mouse point @ {}", m_cursor_location);
  361. } else {
  362. m_cursor_location = { packet.x * current_screen.width() / 0xffff, packet.y * current_screen.height() / 0xffff };
  363. dbgln_if(WSSCREEN_DEBUG, "Screen: New Absolute mouse point @ {}", m_cursor_location);
  364. }
  365. auto* moved_to_screen = Screen::find_by_location(m_cursor_location);
  366. if (!moved_to_screen) {
  367. m_cursor_location = m_cursor_location.constrained(current_screen.rect());
  368. moved_to_screen = &current_screen;
  369. }
  370. unsigned buttons = packet.buttons;
  371. unsigned prev_buttons = m_mouse_button_state;
  372. m_mouse_button_state = buttons;
  373. unsigned changed_buttons = prev_buttons ^ buttons;
  374. auto post_mousedown_or_mouseup_if_needed = [&](MouseButton button) {
  375. if (!(changed_buttons & (unsigned)button))
  376. return;
  377. auto message = make<MouseEvent>(buttons & (unsigned)button ? Event::MouseDown : Event::MouseUp, m_cursor_location, buttons, button, m_modifiers);
  378. Core::EventLoop::current().post_event(WindowManager::the(), move(message));
  379. };
  380. post_mousedown_or_mouseup_if_needed(MouseButton::Left);
  381. post_mousedown_or_mouseup_if_needed(MouseButton::Right);
  382. post_mousedown_or_mouseup_if_needed(MouseButton::Middle);
  383. post_mousedown_or_mouseup_if_needed(MouseButton::Back);
  384. post_mousedown_or_mouseup_if_needed(MouseButton::Forward);
  385. if (m_cursor_location != prev_location) {
  386. auto message = make<MouseEvent>(Event::MouseMove, m_cursor_location, buttons, MouseButton::None, m_modifiers);
  387. if (WindowManager::the().dnd_client())
  388. message->set_mime_data(WindowManager::the().dnd_mime_data());
  389. Core::EventLoop::current().post_event(WindowManager::the(), move(message));
  390. }
  391. if (packet.z) {
  392. auto message = make<MouseEvent>(Event::MouseWheel, m_cursor_location, buttons, MouseButton::None, m_modifiers, packet.z * m_scroll_step_size);
  393. Core::EventLoop::current().post_event(WindowManager::the(), move(message));
  394. }
  395. if (m_cursor_location != prev_location)
  396. Compositor::the().invalidate_cursor();
  397. }
  398. void ScreenInput::on_receive_keyboard_data(::KeyEvent kernel_event)
  399. {
  400. m_modifiers = kernel_event.modifiers();
  401. auto message = make<KeyEvent>(kernel_event.is_press() ? Event::KeyDown : Event::KeyUp, kernel_event.key, kernel_event.code_point, kernel_event.modifiers(), kernel_event.scancode);
  402. Core::EventLoop::current().post_event(WindowManager::the(), move(message));
  403. }
  404. void Screen::constrain_pending_flush_rects()
  405. {
  406. auto& fb_data = *m_framebuffer_data;
  407. if (fb_data.pending_flush_rects.is_empty())
  408. return;
  409. Gfx::IntRect screen_rect({}, rect().size());
  410. Gfx::DisjointRectSet rects;
  411. for (auto& fb_rect : fb_data.pending_flush_rects) {
  412. Gfx::IntRect rect { (int)fb_rect.x, (int)fb_rect.y, (int)fb_rect.width, (int)fb_rect.height };
  413. auto intersected_rect = rect.intersected(screen_rect);
  414. if (!intersected_rect.is_empty())
  415. rects.add(intersected_rect);
  416. }
  417. fb_data.pending_flush_rects.clear_with_capacity();
  418. for (auto& rect : rects.rects()) {
  419. fb_data.pending_flush_rects.append({
  420. x : (unsigned)rect.x(),
  421. y : (unsigned)rect.y(),
  422. width : (unsigned)rect.width(),
  423. height : (unsigned)rect.height()
  424. });
  425. }
  426. }
  427. void Screen::queue_flush_display_rect(Gfx::IntRect const& flush_region)
  428. {
  429. // NOTE: we don't scale until in Screen::flush_display so that when
  430. // there are too many rectangles that we end up throwing away, we didn't
  431. // waste accounting for scale factor!
  432. auto& fb_data = *m_framebuffer_data;
  433. if (fb_data.too_many_pending_flush_rects) {
  434. // We already have too many, just make sure we extend it if needed
  435. VERIFY(!fb_data.pending_flush_rects.is_empty());
  436. if (fb_data.pending_flush_rects.size() == 1) {
  437. auto& union_rect = fb_data.pending_flush_rects[0];
  438. auto new_union = flush_region.united(Gfx::IntRect((int)union_rect.x, (int)union_rect.y, (int)union_rect.width, (int)union_rect.height));
  439. union_rect.x = new_union.left();
  440. union_rect.y = new_union.top();
  441. union_rect.width = new_union.width();
  442. union_rect.height = new_union.height();
  443. } else {
  444. // Convert all the rectangles into one union
  445. auto new_union = flush_region;
  446. for (auto& flush_rect : fb_data.pending_flush_rects)
  447. new_union = new_union.united(Gfx::IntRect((int)flush_rect.x, (int)flush_rect.y, (int)flush_rect.width, (int)flush_rect.height));
  448. fb_data.pending_flush_rects.resize(1, true);
  449. auto& union_rect = fb_data.pending_flush_rects[0];
  450. union_rect.x = new_union.left();
  451. union_rect.y = new_union.top();
  452. union_rect.width = new_union.width();
  453. union_rect.height = new_union.height();
  454. }
  455. return;
  456. }
  457. VERIFY(fb_data.pending_flush_rects.size() < fb_data.pending_flush_rects.capacity());
  458. fb_data.pending_flush_rects.append({ (unsigned)flush_region.left(),
  459. (unsigned)flush_region.top(),
  460. (unsigned)flush_region.width(),
  461. (unsigned)flush_region.height() });
  462. if (fb_data.pending_flush_rects.size() == fb_data.pending_flush_rects.capacity()) {
  463. // If we get one more rectangle then we need to convert it to a single union rectangle
  464. fb_data.too_many_pending_flush_rects = true;
  465. }
  466. }
  467. void Screen::flush_display(int buffer_index)
  468. {
  469. VERIFY(m_can_device_flush_buffers);
  470. auto& fb_data = *m_framebuffer_data;
  471. if (fb_data.pending_flush_rects.is_empty())
  472. return;
  473. // Now that we have a final set of rects, apply the scale factor
  474. auto scale_factor = this->scale_factor();
  475. for (auto& flush_rect : fb_data.pending_flush_rects) {
  476. VERIFY(Gfx::IntRect({}, m_virtual_rect.size()).contains({ (int)flush_rect.x, (int)flush_rect.y, (int)flush_rect.width, (int)flush_rect.height }));
  477. flush_rect.x *= scale_factor;
  478. flush_rect.y *= scale_factor;
  479. flush_rect.width *= scale_factor;
  480. flush_rect.height *= scale_factor;
  481. }
  482. if (fb_flush_buffers(m_framebuffer_fd, buffer_index, fb_data.pending_flush_rects.data(), (unsigned)fb_data.pending_flush_rects.size()) < 0) {
  483. int err = errno;
  484. if (err == ENOTSUP)
  485. m_can_device_flush_buffers = false;
  486. else
  487. dbgln("Screen #{}: Error ({}) flushing display: {}", index(), err, strerror(err));
  488. }
  489. fb_data.too_many_pending_flush_rects = false;
  490. fb_data.pending_flush_rects.clear_with_capacity();
  491. }
  492. void Screen::flush_display_front_buffer(int front_buffer_index, Gfx::IntRect& rect)
  493. {
  494. VERIFY(m_can_device_flush_buffers);
  495. auto scale_factor = this->scale_factor();
  496. FBRect flush_rect {
  497. .x = (unsigned)(rect.x() * scale_factor),
  498. .y = (unsigned)(rect.y() * scale_factor),
  499. .width = (unsigned)(rect.width() * scale_factor),
  500. .height = (unsigned)(rect.height() * scale_factor)
  501. };
  502. VERIFY(Gfx::IntRect({}, m_virtual_rect.size()).contains(rect));
  503. if (fb_flush_buffers(m_framebuffer_fd, front_buffer_index, &flush_rect, 1) < 0) {
  504. int err = errno;
  505. if (err == ENOTSUP)
  506. m_can_device_flush_buffers = false;
  507. else
  508. dbgln("Screen #{}: Error ({}) flushing display front buffer: {}", index(), err, strerror(err));
  509. }
  510. }
  511. }