Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(318)

Side by Side Diff: ash/display/display_change_observer_x11.cc

Issue 15067012: Move chromeos specific utility functions for display to chromeos/display (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: added test Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ash/display/display_change_observer_x11.h ('k') | chromeos/chromeos.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/display/display_controller.h" 14 #include "ash/display/display_controller.h"
15 #include "ash/display/display_info.h" 15 #include "ash/display/display_info.h"
16 #include "ash/display/display_manager.h" 16 #include "ash/display/display_manager.h"
17 #include "ash/shell.h" 17 #include "ash/shell.h"
18 #include "base/message_pump_aurax11.h" 18 #include "base/message_pump_aurax11.h"
19 #include "chromeos/display/output_util.h"
19 #include "grit/ash_strings.h" 20 #include "grit/ash_strings.h"
20 #include "ui/base/l10n/l10n_util.h" 21 #include "ui/base/l10n/l10n_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/gfx/display.h" 23 #include "ui/gfx/display.h"
24 24
25 namespace ash { 25 namespace ash {
26 namespace internal { 26 namespace internal {
27 27
28 namespace { 28 namespace {
29 29
30 // The DPI threshold to detect high density screen. 30 // The DPI threshold to detect high density screen.
31 // Higher DPI than this will use device_scale_factor=2. 31 // Higher DPI than this will use device_scale_factor=2.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 const unsigned long* size = kInvalidDisplaySizeList[i]; 69 const unsigned long* size = kInvalidDisplaySizeList[i];
70 if (output_info->mm_width == size[0] && output_info->mm_height == size[1]) { 70 if (output_info->mm_width == size[0] && output_info->mm_height == size[1]) {
71 LOG(WARNING) << "Black listed display size detected:" 71 LOG(WARNING) << "Black listed display size detected:"
72 << size[0] << "x" << size[1]; 72 << size[0] << "x" << size[1];
73 return true; 73 return true;
74 } 74 }
75 } 75 }
76 return false; 76 return false;
77 } 77 }
78 78
79 std::string GetDisplayName(XID output_id) { 79 int64 GetDisplayId(XID output, size_t output_index) {
80 std::string display_name; 80 int64 display_id;
81 ui::GetOutputDeviceData(output_id, NULL, NULL, &display_name); 81 if (chromeos::GetDisplayId(output, output_index, &display_id))
82 return display_name; 82 return display_id;
83 }
84
85 int64 GetDisplayId(XID output_id, int output_index) {
86 uint16 manufacturer_id = 0;
87 uint16 product_code = 0;
88 if (ui::GetOutputDeviceData(
89 output_id, &manufacturer_id, &product_code, NULL) &&
90 manufacturer_id != 0) {
91 // An ID based on display's index will be assigned later if this call
92 // fails.
93 return gfx::Display::GetID(manufacturer_id, product_code, output_index);
94 }
95 return gfx::Display::kInvalidDisplayID; 83 return gfx::Display::kInvalidDisplayID;
96 } 84 }
97 85
98 } // namespace 86 } // namespace
99 87
100 DisplayChangeObserverX11::DisplayChangeObserverX11() 88 DisplayChangeObserverX11::DisplayChangeObserverX11()
101 : xdisplay_(base::MessagePumpAuraX11::GetDefaultXDisplay()), 89 : xdisplay_(base::MessagePumpAuraX11::GetDefaultXDisplay()),
102 x_root_window_(DefaultRootWindow(xdisplay_)), 90 x_root_window_(DefaultRootWindow(xdisplay_)),
103 xrandr_event_base_(0) { 91 xrandr_event_base_(0) {
104 int error_base_ignored; 92 int error_base_ignored;
105 XRRQueryExtension(xdisplay_, &xrandr_event_base_, &error_base_ignored); 93 XRRQueryExtension(xdisplay_, &xrandr_event_base_, &error_base_ignored);
106 94
107 // Find internal display. 95 // Find internal display.
108 XRRScreenResources* screen_resources = 96 XRRScreenResources* screen_resources =
109 XRRGetScreenResources(xdisplay_, x_root_window_); 97 XRRGetScreenResources(xdisplay_, x_root_window_);
110 for (int output_index = 0; output_index < screen_resources->noutput; 98 for (int output_index = 0; output_index < screen_resources->noutput;
111 output_index++) { 99 output_index++) {
112 XID output = screen_resources->outputs[output_index]; 100 XID output = screen_resources->outputs[output_index];
113 XRROutputInfo *output_info = 101 XRROutputInfo *output_info =
114 XRRGetOutputInfo(xdisplay_, screen_resources, output); 102 XRRGetOutputInfo(xdisplay_, screen_resources, output);
115 bool is_internal = chromeos::OutputConfigurator::IsInternalOutputName( 103 bool is_internal = chromeos::IsInternalOutputName(
116 std::string(output_info->name)); 104 std::string(output_info->name));
117 XRRFreeOutputInfo(output_info); 105 XRRFreeOutputInfo(output_info);
118 if (is_internal) { 106 if (is_internal) {
119 int64 id = GetDisplayId(output, output_index); 107 int64 id = GetDisplayId(output, output_index);
120 // Fallback to output index. crbug.com/180100 108 // Fallback to output index. crbug.com/180100
121 gfx::Display::SetInternalDisplayId( 109 gfx::Display::SetInternalDisplayId(
122 id == gfx::Display::kInvalidDisplayID ? output_index : id); 110 id == gfx::Display::kInvalidDisplayID ? output_index : id);
123 break; 111 break;
124 } 112 }
125 } 113 }
126 XRRFreeScreenResources(screen_resources); 114 XRRFreeScreenResources(screen_resources);
127 Shell::GetInstance()->AddShellObserver(this); 115 Shell::GetInstance()->AddShellObserver(this);
128 } 116 }
129 117
130 DisplayChangeObserverX11::~DisplayChangeObserverX11() { 118 DisplayChangeObserverX11::~DisplayChangeObserverX11() {
131 Shell::GetInstance()->RemoveShellObserver(this); 119 Shell::GetInstance()->RemoveShellObserver(this);
132 } 120 }
133 121
134 chromeos::OutputState DisplayChangeObserverX11::GetStateForOutputs( 122 chromeos::OutputState DisplayChangeObserverX11::GetStateForDisplayIds(
135 const chromeos::OutputSnapshotList& outputs) const { 123 const std::vector<int64>& display_ids) const {
136 CHECK(outputs.size() == 2); 124 CHECK_EQ(2U, display_ids.size());
137 DisplayIdPair pair = std::make_pair( 125 DisplayIdPair pair = std::make_pair(display_ids[0], display_ids[1]);
138 GetDisplayId(outputs[0].output, outputs[0].index),
139 GetDisplayId(outputs[1].output, outputs[1].index));
140 DisplayLayout layout = Shell::GetInstance()->display_controller()-> 126 DisplayLayout layout = Shell::GetInstance()->display_controller()->
141 GetRegisteredDisplayLayout(pair); 127 GetRegisteredDisplayLayout(pair);
142 return layout.mirrored ? 128 return layout.mirrored ?
143 chromeos::STATE_DUAL_MIRROR : chromeos::STATE_DUAL_EXTENDED; 129 chromeos::STATE_DUAL_MIRROR : chromeos::STATE_DUAL_EXTENDED;
144 } 130 }
145 131
146 void DisplayChangeObserverX11::OnDisplayModeChanged() { 132 void DisplayChangeObserverX11::OnDisplayModeChanged() {
147 XRRScreenResources* screen_resources = 133 XRRScreenResources* screen_resources =
148 XRRGetScreenResources(xdisplay_, x_root_window_); 134 XRRGetScreenResources(xdisplay_, x_root_window_);
149 std::map<XID, XRRCrtcInfo*> crtc_info_map; 135 std::map<XID, XRRCrtcInfo*> crtc_info_map;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 167
182 float device_scale_factor = 1.0f; 168 float device_scale_factor = 1.0f;
183 if (!ShouldIgnoreSize(output_info) && 169 if (!ShouldIgnoreSize(output_info) &&
184 (kInchInMm * mode->width / output_info->mm_width) > 170 (kInchInMm * mode->width / output_info->mm_width) >
185 kHighDensityDPIThreshold) { 171 kHighDensityDPIThreshold) {
186 device_scale_factor = 2.0f; 172 device_scale_factor = 2.0f;
187 } 173 }
188 gfx::Rect display_bounds( 174 gfx::Rect display_bounds(
189 crtc_info->x, crtc_info->y, mode->width, mode->height); 175 crtc_info->x, crtc_info->y, mode->width, mode->height);
190 176
191 bool is_internal = chromeos::OutputConfigurator::IsInternalOutputName( 177 bool is_internal = chromeos::IsInternalOutputName(
192 std::string(output_info->name)); 178 std::string(output_info->name));
193 XRRFreeOutputInfo(output_info); 179 XRRFreeOutputInfo(output_info);
194 180
195 std::string name = is_internal ? 181 std::string name = is_internal ?
196 l10n_util::GetStringUTF8(IDS_ASH_INTERNAL_DISPLAY_NAME) : 182 l10n_util::GetStringUTF8(IDS_ASH_INTERNAL_DISPLAY_NAME) :
197 GetDisplayName(output); 183 chromeos::GetDisplayName(output);
198 if (name.empty()) 184 if (name.empty())
199 name = l10n_util::GetStringUTF8(IDS_ASH_STATUS_TRAY_UNKNOWN_DISPLAY_NAME); 185 name = l10n_util::GetStringUTF8(IDS_ASH_STATUS_TRAY_UNKNOWN_DISPLAY_NAME);
200 186
201 bool has_overscan = false; 187 bool has_overscan = false;
202 ui::GetOutputOverscanFlag(output, &has_overscan); 188 chromeos::GetOutputOverscanFlag(output, &has_overscan);
203 189
204 int64 id = GetDisplayId(output, output_index); 190 int64 id = GetDisplayId(output, output_index);
205 191
206 // If ID is invalid or there is an duplicate, just use output index. 192 // If ID is invalid or there is an duplicate, just use output index.
207 if (id == gfx::Display::kInvalidDisplayID || ids.find(id) != ids.end()) 193 if (id == gfx::Display::kInvalidDisplayID || ids.find(id) != ids.end())
208 id = output_index; 194 id = output_index;
209 ids.insert(id); 195 ids.insert(id);
210 196
211 displays.push_back(DisplayInfo(id, name, has_overscan)); 197 displays.push_back(DisplayInfo(id, name, has_overscan));
212 displays.back().set_device_scale_factor(device_scale_factor); 198 displays.back().set_device_scale_factor(device_scale_factor);
(...skipping 15 matching lines...) Expand all
228 void DisplayChangeObserverX11::OnAppTerminating() { 214 void DisplayChangeObserverX11::OnAppTerminating() {
229 #if defined(USE_ASH) 215 #if defined(USE_ASH)
230 // Stop handling display configuration events once the shutdown 216 // Stop handling display configuration events once the shutdown
231 // process starts. crbug.com/177014. 217 // process starts. crbug.com/177014.
232 Shell::GetInstance()->output_configurator()->Stop(); 218 Shell::GetInstance()->output_configurator()->Stop();
233 #endif 219 #endif
234 } 220 }
235 221
236 } // namespace internal 222 } // namespace internal
237 } // namespace ash 223 } // namespace ash
OLDNEW
« no previous file with comments | « ash/display/display_change_observer_x11.h ('k') | chromeos/chromeos.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698