OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/display/chromeos/x11/native_display_delegate_x11.h" | 5 #include "ui/display/chromeos/x11/native_display_delegate_x11.h" |
6 | 6 |
7 #include <X11/Xatom.h> | 7 #include <X11/Xatom.h> |
8 #include <X11/Xlib.h> | 8 #include <X11/Xlib.h> |
9 #include <X11/extensions/dpms.h> | 9 #include <X11/extensions/dpms.h> |
10 #include <X11/extensions/Xrandr.h> | 10 #include <X11/extensions/Xrandr.h> |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
290 | 290 |
291 void NativeDisplayDelegateX11::CreateFrameBuffer(const gfx::Size& size) { | 291 void NativeDisplayDelegateX11::CreateFrameBuffer(const gfx::Size& size) { |
292 CHECK(screen_) << "Server not grabbed"; | 292 CHECK(screen_) << "Server not grabbed"; |
293 int current_width = DisplayWidth(display_, DefaultScreen(display_)); | 293 int current_width = DisplayWidth(display_, DefaultScreen(display_)); |
294 int current_height = DisplayHeight(display_, DefaultScreen(display_)); | 294 int current_height = DisplayHeight(display_, DefaultScreen(display_)); |
295 VLOG(1) << "CreateFrameBuffer: new=" << size.width() << "x" << size.height() | 295 VLOG(1) << "CreateFrameBuffer: new=" << size.width() << "x" << size.height() |
296 << " current=" << current_width << "x" << current_height; | 296 << " current=" << current_width << "x" << current_height; |
297 if (size.width() == current_width && size.height() == current_height) | 297 if (size.width() == current_width && size.height() == current_height) |
298 return; | 298 return; |
299 | 299 |
300 DestroyUnusedCrtcs(); | 300 DestroyUnusedCrtcs(size); |
301 int mm_width = size.width() * kPixelsToMmScale; | 301 int mm_width = size.width() * kPixelsToMmScale; |
302 int mm_height = size.height() * kPixelsToMmScale; | 302 int mm_height = size.height() * kPixelsToMmScale; |
303 XRRSetScreenSize( | 303 XRRSetScreenSize( |
304 display_, window_, size.width(), size.height(), mm_width, mm_height); | 304 display_, window_, size.width(), size.height(), mm_width, mm_height); |
305 // We don't wait for root window resize, therefore this end up with drawing | 305 // We don't wait for root window resize, therefore this end up with drawing |
306 // in the old window size, which we care during the boot. | 306 // in the old window size, which we care during the boot. |
307 DrawBackground(); | 307 DrawBackground(); |
308 | 308 |
309 // Don't redraw the background upon framebuffer change again. This should | 309 // Don't redraw the background upon framebuffer change again. This should |
310 // happen only once after boot. | 310 // happen only once after boot. |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
511 XRRChangeOutputProperty( | 511 XRRChangeOutputProperty( |
512 display_, output_id, name, XA_ATOM, 32, PropModeReplace, data, 1); | 512 display_, output_id, name, XA_ATOM, 32, PropModeReplace, data, 1); |
513 if (err_tracker.FoundNewError()) { | 513 if (err_tracker.FoundNewError()) { |
514 LOG(ERROR) << "XRRChangeOutputProperty failed"; | 514 LOG(ERROR) << "XRRChangeOutputProperty failed"; |
515 return false; | 515 return false; |
516 } else { | 516 } else { |
517 return true; | 517 return true; |
518 } | 518 } |
519 } | 519 } |
520 | 520 |
521 void NativeDisplayDelegateX11::DestroyUnusedCrtcs() { | 521 void NativeDisplayDelegateX11::DestroyUnusedCrtcs(const gfx::Size& new_size) { |
522 CHECK(screen_) << "Server not grabbed"; | 522 CHECK(screen_) << "Server not grabbed"; |
523 // Setting the screen size will fail if any CRTC doesn't fit afterwards. | 523 // Setting the screen size will fail if any CRTC doesn't fit afterwards. |
524 // At the same time, turning CRTCs off and back on uses up a lot of time. | 524 // At the same time, turning CRTCs off and back on uses up a lot of time. |
525 // This function tries to be smart to avoid too many off/on cycles: | 525 // This function tries to be smart to avoid too many off/on cycles: |
526 // - We disable all the CRTCs we won't need after the FB resize. | 526 // - We disable all the CRTCs we won't need after the FB resize. |
527 // - We set the new modes on CRTCs, if they fit in both the old and new | 527 // - We set the new modes on CRTCs, if they fit in both the old and new |
528 // FBs, and park them at (0,0) | 528 // FBs, and park them at (0,0) |
529 // - We disable the CRTCs we will need but don't fit in the old FB. Those | 529 // - We disable the CRTCs we will need but don't fit in the old FB. Those |
530 // will be reenabled after the resize. | 530 // will be reenabled after the resize. |
531 // We don't worry about the cached state of the outputs here since we are | 531 // We don't worry about the cached state of the outputs here since we are |
(...skipping 12 matching lines...) Expand all Loading... | |
544 DisplaySnapshotX11* x11_output = static_cast<DisplaySnapshotX11*>(*it); | 544 DisplaySnapshotX11* x11_output = static_cast<DisplaySnapshotX11*>(*it); |
545 if (crtc == x11_output->crtc()) { | 545 if (crtc == x11_output->crtc()) { |
546 mode_info = x11_output->current_mode(); | 546 mode_info = x11_output->current_mode(); |
547 output = x11_output->output(); | 547 output = x11_output->output(); |
548 break; | 548 break; |
549 } | 549 } |
550 } | 550 } |
551 | 551 |
552 if (mode_info) { | 552 if (mode_info) { |
553 mode = static_cast<const DisplayModeX11*>(mode_info)->mode_id(); | 553 mode = static_cast<const DisplayModeX11*>(mode_info)->mode_id(); |
554 // In case our CRTC doesn't fit in our current framebuffer, disable it. | 554 // In case our CRTC doesn't fit in common area of our current and about |
555 // to be resized framebuffer, disable it. | |
555 // It'll get reenabled after we resize the framebuffer. | 556 // It'll get reenabled after we resize the framebuffer. |
556 int current_width = DisplayWidth(display_, DefaultScreen(display_)); | 557 int max_width = std::min(DisplayWidth(display_, |
557 int current_height = DisplayHeight(display_, DefaultScreen(display_)); | 558 DefaultScreen(display_)), new_size.width()); |
Daniel Kurtz
2014/04/25 04:35:29
I think this would have been easier to read:
int
| |
558 if (mode_info->size().width() > current_width || | 559 int max_height = std::min(DisplayHeight(display_, |
559 mode_info->size().height() > current_height) { | 560 DefaultScreen(display_)), new_size.height()); |
561 if (mode_info->size().width() > max_width || | |
562 mode_info->size().height() > max_height) { | |
560 mode = None; | 563 mode = None; |
561 output = None; | 564 output = None; |
562 mode_info = NULL; | 565 mode_info = NULL; |
563 } | 566 } |
564 } | 567 } |
565 | 568 |
566 ConfigureCrtc(crtc, mode, output, 0, 0); | 569 ConfigureCrtc(crtc, mode, output, 0, 0); |
567 } | 570 } |
568 } | 571 } |
569 | 572 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
671 XSetForeground(display_, gc, color.pixel); | 674 XSetForeground(display_, gc, color.pixel); |
672 XSetFillStyle(display_, gc, FillSolid); | 675 XSetFillStyle(display_, gc, FillSolid); |
673 int width = DisplayWidth(display_, DefaultScreen(display_)); | 676 int width = DisplayWidth(display_, DefaultScreen(display_)); |
674 int height = DisplayHeight(display_, DefaultScreen(display_)); | 677 int height = DisplayHeight(display_, DefaultScreen(display_)); |
675 XFillRectangle(display_, window_, gc, 0, 0, width, height); | 678 XFillRectangle(display_, window_, gc, 0, 0, width, height); |
676 XFreeGC(display_, gc); | 679 XFreeGC(display_, gc); |
677 XFreeColors(display_, colormap, &color.pixel, 1, 0); | 680 XFreeColors(display_, colormap, &color.pixel, 1, 0); |
678 } | 681 } |
679 | 682 |
680 } // namespace ui | 683 } // namespace ui |
OLD | NEW |