| 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 | 111 |
| 111 for (int c = 0; c < screen_resources->ncrtc; c++) { | 112 for (int c = 0; c < screen_resources->ncrtc; c++) { |
| 112 XID crtc_id = screen_resources->crtcs[c]; | 113 XID crtc_id = screen_resources->crtcs[c]; |
| 113 XRRCrtcInfo *crtc_info = | 114 XRRCrtcInfo *crtc_info = |
| 114 XRRGetCrtcInfo(xdisplay_, screen_resources, crtc_id); | 115 XRRGetCrtcInfo(xdisplay_, screen_resources, crtc_id); |
| 115 crtc_info_map[crtc_id] = crtc_info; | 116 crtc_info_map[crtc_id] = crtc_info; |
| 116 } | 117 } |
| 117 | 118 |
| 118 std::vector<gfx::Display> displays; | 119 std::vector<gfx::Display> displays; |
| 119 std::set<int> y_coords; | 120 std::set<int> y_coords; |
| 121 std::set<int64> ids; |
| 120 for (int o = 0; o < screen_resources->noutput; o++) { | 122 for (int o = 0; o < screen_resources->noutput; o++) { |
| 121 XRROutputInfo *output_info = | 123 XRROutputInfo *output_info = |
| 122 XRRGetOutputInfo(xdisplay_, | 124 XRRGetOutputInfo(xdisplay_, |
| 123 screen_resources, | 125 screen_resources, |
| 124 screen_resources->outputs[o]); | 126 screen_resources->outputs[o]); |
| 125 if (output_info->connection != RR_Connected) { | 127 if (output_info->connection != RR_Connected) { |
| 126 XRRFreeOutputInfo(output_info); | 128 XRRFreeOutputInfo(output_info); |
| 127 continue; | 129 continue; |
| 128 } | 130 } |
| 129 XRRCrtcInfo* crtc_info = crtc_info_map[output_info->crtc]; | 131 XRRCrtcInfo* crtc_info = crtc_info_map[output_info->crtc]; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 143 displays.push_back(gfx::Display( | 145 displays.push_back(gfx::Display( |
| 144 0, | 146 0, |
| 145 gfx::Rect(crtc_info->x, crtc_info->y, mode->width, mode->height))); | 147 gfx::Rect(crtc_info->x, crtc_info->y, mode->width, mode->height))); |
| 146 | 148 |
| 147 float device_scale_factor = 1.0f; | 149 float device_scale_factor = 1.0f; |
| 148 if (!ShouldIgnoreSize(output_info) && | 150 if (!ShouldIgnoreSize(output_info) && |
| 149 (kInchInMm * mode->width / output_info->mm_width) > | 151 (kInchInMm * mode->width / output_info->mm_width) > |
| 150 kHighDensityDIPThreshold) { | 152 kHighDensityDIPThreshold) { |
| 151 device_scale_factor = 2.0f; | 153 device_scale_factor = 2.0f; |
| 152 } | 154 } |
| 155 |
| 156 uint16 manufacturer_id = 0; |
| 157 uint32 serial_number = 0; |
| 158 if (ui::GetOutputDeviceData(screen_resources->outputs[o], &manufacturer_id, |
| 159 &serial_number, NULL) && manufacturer_id != 0) { |
| 160 // An ID based on display's index will be assigned later if this call |
| 161 // fails. |
| 162 int64 new_id = gfx::Display::GetID(manufacturer_id, serial_number); |
| 163 if (ids.find(new_id) == ids.end()) { |
| 164 displays.back().set_id(new_id); |
| 165 ids.insert(new_id); |
| 166 } |
| 167 } |
| 168 |
| 153 displays.back().set_device_scale_factor(device_scale_factor); | 169 displays.back().set_device_scale_factor(device_scale_factor); |
| 154 y_coords.insert(crtc_info->y); | 170 y_coords.insert(crtc_info->y); |
| 155 XRRFreeOutputInfo(output_info); | 171 XRRFreeOutputInfo(output_info); |
| 156 } | 172 } |
| 157 | 173 |
| 158 // Free all allocated resources. | 174 // Free all allocated resources. |
| 159 for (std::map<XID, XRRCrtcInfo*>::const_iterator iter = crtc_info_map.begin(); | 175 for (std::map<XID, XRRCrtcInfo*>::const_iterator iter = crtc_info_map.begin(); |
| 160 iter != crtc_info_map.end(); ++iter) { | 176 iter != crtc_info_map.end(); ++iter) { |
| 161 XRRFreeCrtcInfo(iter->second); | 177 XRRFreeCrtcInfo(iter->second); |
| 162 } | 178 } |
| 163 XRRFreeScreenResources(screen_resources); | 179 XRRFreeScreenResources(screen_resources); |
| 164 | 180 |
| 165 // PowerManager lays out the outputs vertically. Sort them by Y | 181 // PowerManager lays out the outputs vertically. Sort them by Y |
| 166 // coordinates. | 182 // coordinates. |
| 167 std::sort(displays.begin(), displays.end(), CompareDisplayY); | 183 std::sort(displays.begin(), displays.end(), CompareDisplayY); |
| 168 // TODO(oshima): Assisgn index as ID for now. Use unique ID. | |
| 169 int id = 0; | 184 int id = 0; |
| 170 for (std::vector<gfx::Display>::iterator iter = displays.begin(); | 185 for (std::vector<gfx::Display>::iterator iter = displays.begin(); |
| 171 iter != displays.end(); ++iter, ++id) | 186 iter != displays.end(); ++iter) { |
| 172 (*iter).set_id(id); | 187 if (iter->id() == gfx::Display::kInvalidID) { |
| 188 iter->set_id(id); |
| 189 ++id; |
| 190 } |
| 191 } |
| 173 | 192 |
| 174 Env::GetInstance()->display_manager()->OnNativeDisplaysChanged(displays); | 193 Env::GetInstance()->display_manager()->OnNativeDisplaysChanged(displays); |
| 175 } | 194 } |
| 176 | 195 |
| 177 } // namespace internal | 196 } // namespace internal |
| 178 } // namespace aura | 197 } // namespace aura |
| OLD | NEW |