| 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> |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 } | 78 } |
| 79 return false; | 79 return false; |
| 80 } | 80 } |
| 81 | 81 |
| 82 std::string GetDisplayName(XID output_id) { | 82 std::string GetDisplayName(XID output_id) { |
| 83 std::string display_name; | 83 std::string display_name; |
| 84 ui::GetOutputDeviceData(output_id, NULL, NULL, &display_name); | 84 ui::GetOutputDeviceData(output_id, NULL, NULL, &display_name); |
| 85 return display_name; | 85 return display_name; |
| 86 } | 86 } |
| 87 | 87 |
| 88 int64 GetDisplayId(XID output_id, int output_index) { |
| 89 uint16 manufacturer_id = 0; |
| 90 uint16 product_code = 0; |
| 91 if (ui::GetOutputDeviceData( |
| 92 output_id, &manufacturer_id, &product_code, NULL) && |
| 93 manufacturer_id != 0) { |
| 94 // An ID based on display's index will be assigned later if this call |
| 95 // fails. |
| 96 return gfx::Display::GetID(manufacturer_id, product_code, output_index); |
| 97 } |
| 98 return gfx::Display::kInvalidDisplayID; |
| 99 } |
| 100 |
| 88 } // namespace | 101 } // namespace |
| 89 | 102 |
| 90 DisplayChangeObserverX11::DisplayChangeObserverX11() | 103 DisplayChangeObserverX11::DisplayChangeObserverX11() |
| 91 : xdisplay_(base::MessagePumpAuraX11::GetDefaultXDisplay()), | 104 : xdisplay_(base::MessagePumpAuraX11::GetDefaultXDisplay()), |
| 92 x_root_window_(DefaultRootWindow(xdisplay_)), | 105 x_root_window_(DefaultRootWindow(xdisplay_)), |
| 93 xrandr_event_base_(0) { | 106 xrandr_event_base_(0) { |
| 94 int error_base_ignored; | 107 int error_base_ignored; |
| 95 XRRQueryExtension(xdisplay_, &xrandr_event_base_, &error_base_ignored); | 108 XRRQueryExtension(xdisplay_, &xrandr_event_base_, &error_base_ignored); |
| 109 |
| 110 // Find internal display. |
| 111 XRRScreenResources* screen_resources = |
| 112 XRRGetScreenResources(xdisplay_, x_root_window_); |
| 113 for (int output_index = 0; output_index < screen_resources->noutput; |
| 114 output_index++) { |
| 115 XID output = screen_resources->outputs[output_index]; |
| 116 XRROutputInfo *output_info = |
| 117 XRRGetOutputInfo(xdisplay_, screen_resources, output); |
| 118 bool is_internal = chromeos::OutputConfigurator::IsInternalOutputName( |
| 119 std::string(output_info->name)); |
| 120 XRRFreeOutputInfo(output_info); |
| 121 if (is_internal) { |
| 122 // No need to check the return value of |GetDisplayID()| as |
| 123 // the default value is |gfx::Display::kInvalidDisplayID| anyway. |
| 124 gfx::Display::SetInternalDisplayId(GetDisplayId(output, output_index)); |
| 125 break; |
| 126 } |
| 127 } |
| 128 XRRFreeScreenResources(screen_resources); |
| 96 } | 129 } |
| 97 | 130 |
| 98 DisplayChangeObserverX11::~DisplayChangeObserverX11() { | 131 DisplayChangeObserverX11::~DisplayChangeObserverX11() { |
| 99 } | 132 } |
| 100 | 133 |
| 101 void DisplayChangeObserverX11::OnDisplayModeChanged() { | 134 void DisplayChangeObserverX11::OnDisplayModeChanged() { |
| 102 XRRScreenResources* screen_resources = | 135 XRRScreenResources* screen_resources = |
| 103 XRRGetScreenResources(xdisplay_, x_root_window_); | 136 XRRGetScreenResources(xdisplay_, x_root_window_); |
| 104 std::map<XID, XRRCrtcInfo*> crtc_info_map; | 137 std::map<XID, XRRCrtcInfo*> crtc_info_map; |
| 105 | 138 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 | 186 |
| 154 std::string name = is_internal ? | 187 std::string name = is_internal ? |
| 155 l10n_util::GetStringUTF8(IDS_ASH_INTERNAL_DISPLAY_NAME) : | 188 l10n_util::GetStringUTF8(IDS_ASH_INTERNAL_DISPLAY_NAME) : |
| 156 GetDisplayName(output); | 189 GetDisplayName(output); |
| 157 if (name.empty()) | 190 if (name.empty()) |
| 158 name = l10n_util::GetStringUTF8(IDS_ASH_STATUS_TRAY_UNKNOWN_DISPLAY_NAME); | 191 name = l10n_util::GetStringUTF8(IDS_ASH_STATUS_TRAY_UNKNOWN_DISPLAY_NAME); |
| 159 | 192 |
| 160 bool has_overscan = false; | 193 bool has_overscan = false; |
| 161 ui::GetOutputOverscanFlag(output, &has_overscan); | 194 ui::GetOutputOverscanFlag(output, &has_overscan); |
| 162 | 195 |
| 163 uint16 manufacturer_id = 0; | 196 int64 id = GetDisplayId(output, output_index); |
| 164 uint16 product_code = 0; | |
| 165 int64 id = gfx::Display::kInvalidDisplayID; | |
| 166 | 197 |
| 167 if (ui::GetOutputDeviceData( | 198 // If ID is invalid or there is an duplicate, just use output index. |
| 168 output, &manufacturer_id, &product_code, NULL) && | 199 if (id == gfx::Display::kInvalidDisplayID || ids.find(id) != ids.end()) |
| 169 manufacturer_id != 0) { | |
| 170 // An ID based on display's index will be assigned later if this call | |
| 171 // fails. | |
| 172 int64 new_id = gfx::Display::GetID( | |
| 173 manufacturer_id, product_code, output_index); | |
| 174 if (ids.find(new_id) == ids.end()) | |
| 175 id = new_id; | |
| 176 } | |
| 177 if (id == gfx::Display::kInvalidDisplayID) | |
| 178 id = output_index; | 200 id = output_index; |
| 179 ids.insert(id); | 201 ids.insert(id); |
| 180 | 202 |
| 181 displays.push_back(DisplayInfo(id, name, has_overscan)); | 203 displays.push_back(DisplayInfo(id, name, has_overscan)); |
| 182 displays.back().set_device_scale_factor(device_scale_factor); | 204 displays.back().set_device_scale_factor(device_scale_factor); |
| 183 displays.back().SetBounds(display_bounds); | 205 displays.back().SetBounds(display_bounds); |
| 184 | 206 |
| 185 y_coords.insert(crtc_info->y); | 207 y_coords.insert(crtc_info->y); |
| 186 } | 208 } |
| 187 | 209 |
| 188 // Free all allocated resources. | 210 // Free all allocated resources. |
| 189 for (std::map<XID, XRRCrtcInfo*>::const_iterator iter = crtc_info_map.begin(); | 211 for (std::map<XID, XRRCrtcInfo*>::const_iterator iter = crtc_info_map.begin(); |
| 190 iter != crtc_info_map.end(); ++iter) { | 212 iter != crtc_info_map.end(); ++iter) { |
| 191 XRRFreeCrtcInfo(iter->second); | 213 XRRFreeCrtcInfo(iter->second); |
| 192 } | 214 } |
| 193 XRRFreeScreenResources(screen_resources); | 215 XRRFreeScreenResources(screen_resources); |
| 194 | 216 |
| 195 // PowerManager lays out the outputs vertically. Sort them by Y | 217 // PowerManager lays out the outputs vertically. Sort them by Y |
| 196 // coordinates. | 218 // coordinates. |
| 197 std::sort(displays.begin(), displays.end(), CompareDisplayY); | 219 std::sort(displays.begin(), displays.end(), CompareDisplayY); |
| 198 | 220 |
| 199 // DisplayManager can be null during the boot. | 221 // DisplayManager can be null during the boot. |
| 200 Shell::GetInstance()->display_manager()->OnNativeDisplaysChanged(displays); | 222 Shell::GetInstance()->display_manager()->OnNativeDisplaysChanged(displays); |
| 201 } | 223 } |
| 202 | 224 |
| 203 } // namespace internal | 225 } // namespace internal |
| 204 } // namespace ash | 226 } // namespace ash |
| OLD | NEW |