| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_chromeos.h" | 5 #include "ash/display/display_change_observer_chromeos.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 "ash/ash_switches.h" | 12 #include "ash/ash_switches.h" |
| 13 #include "ash/display/display_info.h" | 13 #include "ash/display/display_info.h" |
| 14 #include "ash/display/display_layout_store.h" | 14 #include "ash/display/display_layout_store.h" |
| 15 #include "ash/display/display_manager.h" | 15 #include "ash/display/display_manager.h" |
| 16 #include "ash/shell.h" | 16 #include "ash/shell.h" |
| 17 #include "base/command_line.h" | 17 #include "base/command_line.h" |
| 18 #include "base/logging.h" | 18 #include "base/logging.h" |
| 19 #include "grit/ash_strings.h" | 19 #include "grit/ash_strings.h" |
| 20 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
| 21 #include "ui/base/x/x11_util.h" | 21 #include "ui/base/x/x11_util.h" |
| 22 #include "ui/compositor/dip_util.h" | 22 #include "ui/compositor/dip_util.h" |
| 23 #include "ui/display/chromeos/x11/display_util.h" | 23 #include "ui/display/chromeos/display_mode.h" |
| 24 #include "ui/display/chromeos/display_snapshot.h" |
| 24 #include "ui/gfx/display.h" | 25 #include "ui/gfx/display.h" |
| 25 | 26 |
| 26 namespace ash { | 27 namespace ash { |
| 27 namespace internal { | 28 namespace internal { |
| 28 | 29 |
| 29 using ui::OutputConfigurator; | 30 using ui::OutputConfigurator; |
| 30 | 31 |
| 31 namespace { | 32 namespace { |
| 32 | 33 |
| 33 // The DPI threshold to detect high density screen. | 34 // The DPI threshold to detect high density screen. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 45 if (a.size.GetArea() == b.size.GetArea()) | 46 if (a.size.GetArea() == b.size.GetArea()) |
| 46 return (a.refresh_rate > b.refresh_rate); | 47 return (a.refresh_rate > b.refresh_rate); |
| 47 return (a.size.GetArea() > b.size.GetArea()); | 48 return (a.size.GetArea() > b.size.GetArea()); |
| 48 } | 49 } |
| 49 }; | 50 }; |
| 50 | 51 |
| 51 } // namespace | 52 } // namespace |
| 52 | 53 |
| 53 // static | 54 // static |
| 54 std::vector<DisplayMode> DisplayChangeObserver::GetDisplayModeList( | 55 std::vector<DisplayMode> DisplayChangeObserver::GetDisplayModeList( |
| 55 const OutputConfigurator::OutputSnapshot& output) { | 56 const OutputConfigurator::DisplayState& output) { |
| 56 typedef std::map<std::pair<int, int>, DisplayMode> DisplayModeMap; | 57 typedef std::map<std::pair<int, int>, DisplayMode> DisplayModeMap; |
| 57 DisplayModeMap display_mode_map; | 58 DisplayModeMap display_mode_map; |
| 58 | 59 |
| 59 for (std::map<RRMode, OutputConfigurator::ModeInfo>::const_iterator it = | 60 for (std::vector<const ui::DisplayMode*>::const_iterator it = |
| 60 output.mode_infos.begin(); it != output.mode_infos.end(); ++it) { | 61 output.display->modes().begin(); |
| 61 const OutputConfigurator::ModeInfo& mode_info = it->second; | 62 it != output.display->modes().end(); |
| 62 const std::pair<int, int> size(mode_info.width, mode_info.height); | 63 ++it) { |
| 63 const DisplayMode display_mode(gfx::Size(mode_info.width, mode_info.height), | 64 const ui::DisplayMode& mode_info = **it; |
| 64 mode_info.refresh_rate, | 65 const std::pair<int, int> size(mode_info.size().width(), |
| 65 mode_info.interlaced, | 66 mode_info.size().height()); |
| 66 output.native_mode == it->first); | 67 const DisplayMode display_mode(mode_info.size(), |
| 68 mode_info.refresh_rate(), |
| 69 mode_info.is_interlaced(), |
| 70 output.display->native_mode() == *it); |
| 67 | 71 |
| 68 // Add the display mode if it isn't already present and override interlaced | 72 // Add the display mode if it isn't already present and override interlaced |
| 69 // display modes with non-interlaced ones. | 73 // display modes with non-interlaced ones. |
| 70 DisplayModeMap::iterator display_mode_it = display_mode_map.find(size); | 74 DisplayModeMap::iterator display_mode_it = display_mode_map.find(size); |
| 71 if (display_mode_it == display_mode_map.end()) | 75 if (display_mode_it == display_mode_map.end()) |
| 72 display_mode_map.insert(std::make_pair(size, display_mode)); | 76 display_mode_map.insert(std::make_pair(size, display_mode)); |
| 73 else if (display_mode_it->second.interlaced && !display_mode.interlaced) | 77 else if (display_mode_it->second.interlaced && !display_mode.interlaced) |
| 74 display_mode_it->second = display_mode; | 78 display_mode_it->second = display_mode; |
| 75 } | 79 } |
| 76 | 80 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 97 const std::vector<int64>& display_ids) const { | 101 const std::vector<int64>& display_ids) const { |
| 98 CHECK_EQ(2U, display_ids.size()); | 102 CHECK_EQ(2U, display_ids.size()); |
| 99 DisplayIdPair pair = std::make_pair(display_ids[0], display_ids[1]); | 103 DisplayIdPair pair = std::make_pair(display_ids[0], display_ids[1]); |
| 100 DisplayLayout layout = Shell::GetInstance()->display_manager()-> | 104 DisplayLayout layout = Shell::GetInstance()->display_manager()-> |
| 101 layout_store()->GetRegisteredDisplayLayout(pair); | 105 layout_store()->GetRegisteredDisplayLayout(pair); |
| 102 return layout.mirrored ? ui::OUTPUT_STATE_DUAL_MIRROR : | 106 return layout.mirrored ? ui::OUTPUT_STATE_DUAL_MIRROR : |
| 103 ui::OUTPUT_STATE_DUAL_EXTENDED; | 107 ui::OUTPUT_STATE_DUAL_EXTENDED; |
| 104 } | 108 } |
| 105 | 109 |
| 106 bool DisplayChangeObserver::GetResolutionForDisplayId(int64 display_id, | 110 bool DisplayChangeObserver::GetResolutionForDisplayId(int64 display_id, |
| 107 int* width, | 111 gfx::Size* size) const { |
| 108 int* height) const { | |
| 109 DisplayMode mode; | 112 DisplayMode mode; |
| 110 if (!Shell::GetInstance()->display_manager()->GetSelectedModeForDisplayId( | 113 if (!Shell::GetInstance()->display_manager()->GetSelectedModeForDisplayId( |
| 111 display_id, &mode)) | 114 display_id, &mode)) |
| 112 return false; | 115 return false; |
| 113 | 116 |
| 114 *width = mode.size.width(); | 117 *size = mode.size; |
| 115 *height = mode.size.height(); | |
| 116 return true; | 118 return true; |
| 117 } | 119 } |
| 118 | 120 |
| 119 void DisplayChangeObserver::OnDisplayModeChanged( | 121 void DisplayChangeObserver::OnDisplayModeChanged( |
| 120 const std::vector<OutputConfigurator::OutputSnapshot>& outputs) { | 122 const std::vector<OutputConfigurator::DisplayState>& outputs) { |
| 121 std::vector<DisplayInfo> displays; | 123 std::vector<DisplayInfo> displays; |
| 122 std::set<int64> ids; | 124 std::set<int64> ids; |
| 123 for (size_t i = 0; i < outputs.size(); ++i) { | 125 for (size_t i = 0; i < outputs.size(); ++i) { |
| 124 const OutputConfigurator::OutputSnapshot& output = outputs[i]; | 126 const OutputConfigurator::DisplayState& output = outputs[i]; |
| 125 | 127 |
| 126 if (output.type == ui::OUTPUT_TYPE_INTERNAL && | 128 if (output.display->type() == ui::OUTPUT_TYPE_INTERNAL && |
| 127 gfx::Display::InternalDisplayId() == gfx::Display::kInvalidDisplayID) { | 129 gfx::Display::InternalDisplayId() == gfx::Display::kInvalidDisplayID) { |
| 128 // Fall back to output index. crbug.com/180100 | 130 gfx::Display::SetInternalDisplayId(output.display->display_id()); |
| 129 gfx::Display::SetInternalDisplayId( | |
| 130 output.display_id == gfx::Display::kInvalidDisplayID ? output.index : | |
| 131 output.display_id); | |
| 132 } | 131 } |
| 133 | 132 |
| 134 const OutputConfigurator::ModeInfo* mode_info = | 133 const ui::DisplayMode* mode_info = output.display->current_mode(); |
| 135 OutputConfigurator::GetModeInfo(output, output.current_mode); | |
| 136 if (!mode_info) | 134 if (!mode_info) |
| 137 continue; | 135 continue; |
| 138 | 136 |
| 139 float device_scale_factor = 1.0f; | 137 float device_scale_factor = 1.0f; |
| 140 if (!ui::IsXDisplaySizeBlackListed(output.width_mm, output.height_mm) && | 138 if (!ui::IsXDisplaySizeBlackListed( |
| 141 (kInchInMm * mode_info->width / output.width_mm) > | 139 output.display->physical_size().width(), |
| 142 kHighDensityDPIThreshold) { | 140 output.display->physical_size().height()) && |
| 141 (kInchInMm * mode_info->size().width() / |
| 142 output.display->physical_size().width()) > kHighDensityDPIThreshold) { |
| 143 device_scale_factor = 2.0f; | 143 device_scale_factor = 2.0f; |
| 144 } | 144 } |
| 145 gfx::Rect display_bounds( | 145 gfx::Rect display_bounds(output.display->origin(), mode_info->size()); |
| 146 output.x, output.y, mode_info->width, mode_info->height); | |
| 147 | 146 |
| 148 std::vector<DisplayMode> display_modes = GetDisplayModeList(output); | 147 std::vector<DisplayMode> display_modes = GetDisplayModeList(output); |
| 149 | 148 |
| 150 std::string name = | 149 std::string name = |
| 151 output.type == ui::OUTPUT_TYPE_INTERNAL | 150 output.display->type() == ui::OUTPUT_TYPE_INTERNAL |
| 152 ? l10n_util::GetStringUTF8(IDS_ASH_INTERNAL_DISPLAY_NAME) : | 151 ? l10n_util::GetStringUTF8(IDS_ASH_INTERNAL_DISPLAY_NAME) : |
| 153 ui::GetDisplayName(output); | 152 output.display->GetDisplayName(); |
| 154 if (name.empty()) | 153 if (name.empty()) |
| 155 name = l10n_util::GetStringUTF8(IDS_ASH_STATUS_TRAY_UNKNOWN_DISPLAY_NAME); | 154 name = l10n_util::GetStringUTF8(IDS_ASH_STATUS_TRAY_UNKNOWN_DISPLAY_NAME); |
| 156 | 155 |
| 157 bool has_overscan = false; | 156 bool has_overscan = output.display->GetOverscanFlag(); |
| 158 ui::GetOutputOverscanFlag(output, &has_overscan); | 157 int64 id = output.display->display_id(); |
| 159 | |
| 160 int64 id = output.display_id; | |
| 161 if (id == gfx::Display::kInvalidDisplayID || ids.find(id) != ids.end()) | |
| 162 id = output.index; | |
| 163 ids.insert(id); | 158 ids.insert(id); |
| 164 | 159 |
| 165 displays.push_back(DisplayInfo(id, name, has_overscan)); | 160 displays.push_back(DisplayInfo(id, name, has_overscan)); |
| 166 displays.back().set_device_scale_factor(device_scale_factor); | 161 displays.back().set_device_scale_factor(device_scale_factor); |
| 167 displays.back().SetBounds(display_bounds); | 162 displays.back().SetBounds(display_bounds); |
| 168 displays.back().set_native(true); | 163 displays.back().set_native(true); |
| 169 displays.back().set_display_modes(display_modes); | 164 displays.back().set_display_modes(display_modes); |
| 170 displays.back().set_touch_support( | 165 displays.back().set_touch_support( |
| 171 output.touch_device_id == 0 ? gfx::Display::TOUCH_SUPPORT_UNAVAILABLE : | 166 output.touch_device_id == 0 ? gfx::Display::TOUCH_SUPPORT_UNAVAILABLE : |
| 172 gfx::Display::TOUCH_SUPPORT_AVAILABLE); | 167 gfx::Display::TOUCH_SUPPORT_AVAILABLE); |
| 173 } | 168 } |
| 174 | 169 |
| 175 // DisplayManager can be null during the boot. | 170 // DisplayManager can be null during the boot. |
| 176 Shell::GetInstance()->display_manager()->OnNativeDisplaysChanged(displays); | 171 Shell::GetInstance()->display_manager()->OnNativeDisplaysChanged(displays); |
| 177 } | 172 } |
| 178 | 173 |
| 179 void DisplayChangeObserver::OnAppTerminating() { | 174 void DisplayChangeObserver::OnAppTerminating() { |
| 180 #if defined(USE_ASH) | 175 #if defined(USE_ASH) |
| 181 // Stop handling display configuration events once the shutdown | 176 // Stop handling display configuration events once the shutdown |
| 182 // process starts. crbug.com/177014. | 177 // process starts. crbug.com/177014. |
| 183 Shell::GetInstance()->output_configurator()->PrepareForExit(); | 178 Shell::GetInstance()->output_configurator()->PrepareForExit(); |
| 184 #endif | 179 #endif |
| 185 } | 180 } |
| 186 | 181 |
| 187 } // namespace internal | 182 } // namespace internal |
| 188 } // namespace ash | 183 } // namespace ash |
| OLD | NEW |