Chromium Code Reviews| 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 "ui/aura/display_change_observer_x11.h" | 5 #include "ui/aura/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 "base/message_pump_aurax11.h" | 14 #include "base/message_pump_aurax11.h" |
| 15 #include "ui/aura/dispatcher_linux.h" | 15 #include "ui/aura/dispatcher_linux.h" |
| 16 #include "ui/aura/env.h" | 16 #include "ui/aura/env.h" |
| 17 #include "ui/aura/display_manager.h" | 17 #include "ui/aura/display_manager.h" |
| 18 #include "ui/base/x/x11_util.h" | |
| 18 #include "ui/compositor/dip_util.h" | 19 #include "ui/compositor/dip_util.h" |
| 19 #include "ui/gfx/display.h" | 20 #include "ui/gfx/display.h" |
| 20 | 21 |
| 21 namespace aura { | 22 namespace aura { |
| 22 namespace internal { | 23 namespace internal { |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| 25 | 26 |
| 26 // The DPI threshold to detect high density screen. | 27 // The DPI threshold to detect high density screen. |
| 27 // Higher DPI than this will use device_scale_factor=2. | 28 // Higher DPI than this will use device_scale_factor=2. |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 143 displays.push_back(gfx::Display( | 144 displays.push_back(gfx::Display( |
| 144 0, | 145 0, |
| 145 gfx::Rect(crtc_info->x, crtc_info->y, mode->width, mode->height))); | 146 gfx::Rect(crtc_info->x, crtc_info->y, mode->width, mode->height))); |
| 146 | 147 |
| 147 float device_scale_factor = 1.0f; | 148 float device_scale_factor = 1.0f; |
| 148 if (!ShouldIgnoreSize(output_info) && | 149 if (!ShouldIgnoreSize(output_info) && |
| 149 (kInchInMm * mode->width / output_info->mm_width) > | 150 (kInchInMm * mode->width / output_info->mm_width) > |
| 150 kHighDensityDIPThreshold) { | 151 kHighDensityDIPThreshold) { |
| 151 device_scale_factor = 2.0f; | 152 device_scale_factor = 2.0f; |
| 152 } | 153 } |
| 154 | |
| 155 uint16 manufacturer_id = 0; | |
| 156 uint32 serial_number = 0; | |
| 157 if (ui::GetOutputDeviceData(screen_resources->outputs[o], &manufacturer_id, | |
| 158 &serial_number, NULL) && manufacturer_id != 0) { | |
| 159 // An ID based on display's index will be assigned later if this call | |
| 160 // fails. | |
| 161 displays.back().set_id( | |
| 162 gfx::Display::GetID(manufacturer_id, serial_number)); | |
|
Daniel Erat
2012/08/17 14:33:46
Maybe I'm being overly paranoid here, but I wonder
Jun Mukai
2012/08/20 05:56:38
Hmm, I see. Added a check code so that index-base
| |
| 163 } | |
| 164 | |
| 153 displays.back().set_device_scale_factor(device_scale_factor); | 165 displays.back().set_device_scale_factor(device_scale_factor); |
| 154 y_coords.insert(crtc_info->y); | 166 y_coords.insert(crtc_info->y); |
| 155 XRRFreeOutputInfo(output_info); | 167 XRRFreeOutputInfo(output_info); |
| 156 } | 168 } |
| 157 | 169 |
| 158 // Free all allocated resources. | 170 // Free all allocated resources. |
| 159 for (std::map<XID, XRRCrtcInfo*>::const_iterator iter = crtc_info_map.begin(); | 171 for (std::map<XID, XRRCrtcInfo*>::const_iterator iter = crtc_info_map.begin(); |
| 160 iter != crtc_info_map.end(); ++iter) { | 172 iter != crtc_info_map.end(); ++iter) { |
| 161 XRRFreeCrtcInfo(iter->second); | 173 XRRFreeCrtcInfo(iter->second); |
| 162 } | 174 } |
| 163 XRRFreeScreenResources(screen_resources); | 175 XRRFreeScreenResources(screen_resources); |
| 164 | 176 |
| 165 // PowerManager lays out the outputs vertically. Sort them by Y | 177 // PowerManager lays out the outputs vertically. Sort them by Y |
| 166 // coordinates. | 178 // coordinates. |
| 167 std::sort(displays.begin(), displays.end(), CompareDisplayY); | 179 std::sort(displays.begin(), displays.end(), CompareDisplayY); |
| 168 // TODO(oshima): Assisgn index as ID for now. Use unique ID. | |
| 169 int id = 0; | 180 int id = 0; |
| 170 for (std::vector<gfx::Display>::iterator iter = displays.begin(); | 181 for (std::vector<gfx::Display>::iterator iter = displays.begin(); |
| 171 iter != displays.end(); ++iter, ++id) | 182 iter != displays.end(); ++iter) { |
| 172 (*iter).set_id(id); | 183 if (iter->id() == gfx::Display::kInvalidID) { |
| 184 iter->set_id(id); | |
| 185 ++id; | |
| 186 } | |
| 187 } | |
| 173 | 188 |
| 174 Env::GetInstance()->display_manager()->OnNativeDisplaysChanged(displays); | 189 Env::GetInstance()->display_manager()->OnNativeDisplaysChanged(displays); |
| 175 } | 190 } |
| 176 | 191 |
| 177 } // namespace internal | 192 } // namespace internal |
| 178 } // namespace aura | 193 } // namespace aura |
| OLD | NEW |