| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ash/display/display_change_observer_x11.h" | 5 #include "ash/display/display_change_observer_x11.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include <X11/extensions/Xrandr.h> | 12 #include <X11/extensions/Xrandr.h> |
| 13 | 13 |
| 14 #include "ash/ash_switches.h" | 14 #include "ash/ash_switches.h" |
| 15 #include "ash/display/display_info.h" | 15 #include "ash/display/display_info.h" |
| 16 #include "ash/display/display_layout_store.h" | 16 #include "ash/display/display_layout_store.h" |
| 17 #include "ash/display/display_manager.h" | 17 #include "ash/display/display_manager.h" |
| 18 #include "ash/display/display_util_x11.h" | 18 #include "ash/display/display_util_x11.h" |
| 19 #include "ash/shell.h" | 19 #include "ash/shell.h" |
| 20 #include "base/command_line.h" | 20 #include "base/command_line.h" |
| 21 #include "base/message_loop/message_pump_aurax11.h" | 21 #include "base/message_loop/message_pump_aurax11.h" |
| 22 #include "chromeos/display/output_util.h" | 22 #include "chromeos/display/output_util.h" |
| 23 #include "grit/ash_strings.h" | 23 #include "grit/ash_strings.h" |
| 24 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
| 25 #include "ui/compositor/dip_util.h" | 25 #include "ui/compositor/dip_util.h" |
| 26 #include "ui/gfx/display.h" | 26 #include "ui/gfx/display.h" |
| 27 | 27 |
| 28 namespace ash { | 28 namespace ash { |
| 29 namespace internal { | 29 namespace internal { |
| 30 |
| 31 using chromeos::OutputConfigurator; |
| 32 |
| 30 namespace { | 33 namespace { |
| 31 | 34 |
| 32 // The DPI threshold to detect high density screen. | 35 // The DPI threshold to detect high density screen. |
| 33 // Higher DPI than this will use device_scale_factor=2. | 36 // Higher DPI than this will use device_scale_factor=2. |
| 34 const unsigned int kHighDensityDPIThreshold = 160; | 37 const unsigned int kHighDensityDPIThreshold = 160; |
| 35 | 38 |
| 36 // 1 inch in mm. | 39 // 1 inch in mm. |
| 37 const float kInchInMm = 25.4f; | 40 const float kInchInMm = 25.4f; |
| 38 | 41 |
| 39 int64 GetDisplayId(XID output, size_t output_index) { | 42 int64 GetDisplayId(XID output, size_t output_index) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 if (!Shell::GetInstance()->display_manager()-> | 85 if (!Shell::GetInstance()->display_manager()-> |
| 83 GetSelectedResolutionForDisplayId(display_id, &resolution)) { | 86 GetSelectedResolutionForDisplayId(display_id, &resolution)) { |
| 84 return false; | 87 return false; |
| 85 } | 88 } |
| 86 | 89 |
| 87 *width = resolution.width(); | 90 *width = resolution.width(); |
| 88 *height = resolution.height(); | 91 *height = resolution.height(); |
| 89 return true; | 92 return true; |
| 90 } | 93 } |
| 91 | 94 |
| 92 void DisplayChangeObserverX11::OnDisplayModeChanged() { | 95 void DisplayChangeObserverX11::OnDisplayModeChanged( |
| 96 const std::vector<OutputConfigurator::OutputSnapshot>& outputs) { |
| 97 // TODO(derat): Use |outputs| instead of re-fetching information. |
| 93 XRRScreenResources* screen_resources = | 98 XRRScreenResources* screen_resources = |
| 94 XRRGetScreenResources(xdisplay_, x_root_window_); | 99 XRRGetScreenResources(xdisplay_, x_root_window_); |
| 95 std::map<XID, XRRCrtcInfo*> crtc_info_map; | 100 std::map<XID, XRRCrtcInfo*> crtc_info_map; |
| 96 | 101 |
| 97 for (int c = 0; c < screen_resources->ncrtc; c++) { | 102 for (int c = 0; c < screen_resources->ncrtc; c++) { |
| 98 XID crtc_id = screen_resources->crtcs[c]; | 103 XID crtc_id = screen_resources->crtcs[c]; |
| 99 XRRCrtcInfo *crtc_info = | 104 XRRCrtcInfo *crtc_info = |
| 100 XRRGetCrtcInfo(xdisplay_, screen_resources, crtc_id); | 105 XRRGetCrtcInfo(xdisplay_, screen_resources, crtc_id); |
| 101 crtc_info_map[crtc_id] = crtc_info; | 106 crtc_info_map[crtc_id] = crtc_info; |
| 102 } | 107 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 124 XRRFreeOutputInfo(output_info); | 129 XRRFreeOutputInfo(output_info); |
| 125 continue; | 130 continue; |
| 126 } | 131 } |
| 127 const XRRCrtcInfo* crtc_info = crtc_info_map[output_info->crtc]; | 132 const XRRCrtcInfo* crtc_info = crtc_info_map[output_info->crtc]; |
| 128 if (!crtc_info) { | 133 if (!crtc_info) { |
| 129 LOG(WARNING) << "Crtc not found for output: output_index=" | 134 LOG(WARNING) << "Crtc not found for output: output_index=" |
| 130 << output_index; | 135 << output_index; |
| 131 continue; | 136 continue; |
| 132 } | 137 } |
| 133 const XRRModeInfo* mode = | 138 const XRRModeInfo* mode = |
| 134 chromeos::FindModeInfo(screen_resources, crtc_info->mode); | 139 chromeos::FindXRRModeInfo(screen_resources, crtc_info->mode); |
| 135 if (!mode) { | 140 if (!mode) { |
| 136 LOG(WARNING) << "Could not find a mode for the output: output_index=" | 141 LOG(WARNING) << "Could not find a mode for the output: output_index=" |
| 137 << output_index; | 142 << output_index; |
| 138 continue; | 143 continue; |
| 139 } | 144 } |
| 140 | 145 |
| 141 float device_scale_factor = 1.0f; | 146 float device_scale_factor = 1.0f; |
| 142 if (!ShouldIgnoreSize(output_info->mm_width, output_info->mm_height) && | 147 if (!ShouldIgnoreSize(output_info->mm_width, output_info->mm_height) && |
| 143 (kInchInMm * mode->width / output_info->mm_width) > | 148 (kInchInMm * mode->width / output_info->mm_width) > |
| 144 kHighDensityDPIThreshold) { | 149 kHighDensityDPIThreshold) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 void DisplayChangeObserverX11::OnAppTerminating() { | 195 void DisplayChangeObserverX11::OnAppTerminating() { |
| 191 #if defined(USE_ASH) | 196 #if defined(USE_ASH) |
| 192 // Stop handling display configuration events once the shutdown | 197 // Stop handling display configuration events once the shutdown |
| 193 // process starts. crbug.com/177014. | 198 // process starts. crbug.com/177014. |
| 194 Shell::GetInstance()->output_configurator()->Stop(); | 199 Shell::GetInstance()->output_configurator()->Stop(); |
| 195 #endif | 200 #endif |
| 196 } | 201 } |
| 197 | 202 |
| 198 } // namespace internal | 203 } // namespace internal |
| 199 } // namespace ash | 204 } // namespace ash |
| OLD | NEW |