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

Side by Side Diff: chrome/browser/chromeos/display/display_preferences.cc

Issue 2540383002: Updates display manager and display preferences to handle touch calibration data. (Closed)
Patch Set: nit Created 4 years 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
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 "chrome/browser/chromeos/display/display_preferences.h" 5 #include "chrome/browser/chromeos/display/display_preferences.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "ash/display/display_pref_util.h" 9 #include "ash/display/display_pref_util.h"
10 #include "ash/display/json_converter.h" 10 #include "ash/display/json_converter.h"
(...skipping 21 matching lines...) Expand all
32 #include "url/url_util.h" 32 #include "url/url_util.h"
33 33
34 namespace chromeos { 34 namespace chromeos {
35 namespace { 35 namespace {
36 36
37 const char kInsetsTopKey[] = "insets_top"; 37 const char kInsetsTopKey[] = "insets_top";
38 const char kInsetsLeftKey[] = "insets_left"; 38 const char kInsetsLeftKey[] = "insets_left";
39 const char kInsetsBottomKey[] = "insets_bottom"; 39 const char kInsetsBottomKey[] = "insets_bottom";
40 const char kInsetsRightKey[] = "insets_right"; 40 const char kInsetsRightKey[] = "insets_right";
41 41
42 const char kTouchCalibrationWidth[] = "touch_calibration_width";
43 const char kTouchCalibrationHeight[] = "touch_calibration_height";
44 const char* kTouchCalibrationDataKeys[] = {
45 "display_1_x", "display_1_y", "touch_1_x", "touch_1_y", // Pair 1
46 "display_2_x", "display_2_y", "touch_2_x", "touch_2_y", // Pair 2
47 "display_3_x", "display_3_y", "touch_3_x", "touch_3_y", // Pair 3
48 "display_4_x", "display_4_y", "touch_4_x", "touch_4_y" // Pair 4
49 };
50
42 // This kind of boilerplates should be done by base::JSONValueConverter but it 51 // This kind of boilerplates should be done by base::JSONValueConverter but it
43 // doesn't support classes like gfx::Insets for now. 52 // doesn't support classes like gfx::Insets for now.
44 // TODO(mukai): fix base::JSONValueConverter and use it here. 53 // TODO(mukai): fix base::JSONValueConverter and use it here.
45 bool ValueToInsets(const base::DictionaryValue& value, gfx::Insets* insets) { 54 bool ValueToInsets(const base::DictionaryValue& value, gfx::Insets* insets) {
46 DCHECK(insets); 55 DCHECK(insets);
47 int top = 0; 56 int top = 0;
48 int left = 0; 57 int left = 0;
49 int bottom = 0; 58 int bottom = 0;
50 int right = 0; 59 int right = 0;
51 if (value.GetInteger(kInsetsTopKey, &top) && 60 if (value.GetInteger(kInsetsTopKey, &top) &&
52 value.GetInteger(kInsetsLeftKey, &left) && 61 value.GetInteger(kInsetsLeftKey, &left) &&
53 value.GetInteger(kInsetsBottomKey, &bottom) && 62 value.GetInteger(kInsetsBottomKey, &bottom) &&
54 value.GetInteger(kInsetsRightKey, &right)) { 63 value.GetInteger(kInsetsRightKey, &right)) {
55 insets->Set(top, left, bottom, right); 64 insets->Set(top, left, bottom, right);
56 return true; 65 return true;
57 } 66 }
58 return false; 67 return false;
59 } 68 }
60 69
61 void InsetsToValue(const gfx::Insets& insets, base::DictionaryValue* value) { 70 void InsetsToValue(const gfx::Insets& insets, base::DictionaryValue* value) {
62 DCHECK(value); 71 DCHECK(value);
63 value->SetInteger(kInsetsTopKey, insets.top()); 72 value->SetInteger(kInsetsTopKey, insets.top());
64 value->SetInteger(kInsetsLeftKey, insets.left()); 73 value->SetInteger(kInsetsLeftKey, insets.left());
65 value->SetInteger(kInsetsBottomKey, insets.bottom()); 74 value->SetInteger(kInsetsBottomKey, insets.bottom());
66 value->SetInteger(kInsetsRightKey, insets.right()); 75 value->SetInteger(kInsetsRightKey, insets.right());
67 } 76 }
68 77
78 // Retrieves touch calibration associated data from the dictionary and stores
79 // it in an instance of TouchCalibrationData struct.
80 bool ValueToTouchData(const base::DictionaryValue& value,
81 display::TouchCalibrationData* touch_calibration_data) {
82 int x = 0, y = 0;
83 bool got_value = true;
84
85 display::TouchCalibrationData::CalibrationPointPairQuad* point_pair_quad =
86 &(touch_calibration_data->point_pairs);
87
88 gfx::Point display_point;
89 gfx::Point touch_point;
90 for (std::size_t row = 0; row < point_pair_quad->size(); row++) {
91 // Get the display point
92 if (!(value.GetInteger(kTouchCalibrationDataKeys[row * 4], &x) &&
93 value.GetInteger(kTouchCalibrationDataKeys[row * 4 + 1], &y))) {
stevenjb 2016/12/02 20:16:48 nit: I find if (!a || !b) easier to read, especial
94 return false;
95 }
96 display_point.SetPoint(x, y);
97
98 // Get the touch point
99 if (!(value.GetInteger(kTouchCalibrationDataKeys[row * 4 + 2], &x) &&
100 value.GetInteger(kTouchCalibrationDataKeys[row * 4 + 3], &y))) {
101 return false;
102 }
103 touch_point.SetPoint(x, y);
104 (*point_pair_quad)[row] = std::make_pair(display_point, touch_point);
105 }
106
107 int width, height;
108 got_value &= value.GetInteger(kTouchCalibrationWidth, &width);
109 got_value &= value.GetInteger(kTouchCalibrationHeight, &height);
110 if (!got_value)
111 return false;
stevenjb 2016/12/02 20:16:48 Elim got_value here also (and remove the unnecessa
112 touch_calibration_data->bounds = gfx::Size(width, height);
113
114 return true;
115 }
116
117 // Stores the touch calibration data into the dictionary.
118 void TouchDataToValue(
119 const display::TouchCalibrationData& touch_calibration_data,
120 base::DictionaryValue* value) {
121 DCHECK(value);
122 for (std::size_t row = 0; row < touch_calibration_data.point_pairs.size();
123 row++) {
124 // Store the display points
125 value->SetInteger(kTouchCalibrationDataKeys[row * 4],
126 touch_calibration_data.point_pairs[row].first.x());
127 value->SetInteger(kTouchCalibrationDataKeys[row * 4 + 1],
128 touch_calibration_data.point_pairs[row].first.y());
129 // Store the touch points.
130 value->SetInteger(kTouchCalibrationDataKeys[row * 4 + 2],
131 touch_calibration_data.point_pairs[row].second.x());
132 value->SetInteger(kTouchCalibrationDataKeys[row * 4 + 3],
133 touch_calibration_data.point_pairs[row].second.y());
134 }
135 value->SetInteger(kTouchCalibrationWidth,
136 touch_calibration_data.bounds.width());
137 value->SetInteger(kTouchCalibrationHeight,
138 touch_calibration_data.bounds.height());
139 }
140
69 std::string ColorProfileToString(ui::ColorCalibrationProfile profile) { 141 std::string ColorProfileToString(ui::ColorCalibrationProfile profile) {
70 switch (profile) { 142 switch (profile) {
71 case ui::COLOR_PROFILE_STANDARD: 143 case ui::COLOR_PROFILE_STANDARD:
72 return "standard"; 144 return "standard";
73 case ui::COLOR_PROFILE_DYNAMIC: 145 case ui::COLOR_PROFILE_DYNAMIC:
74 return "dynamic"; 146 return "dynamic";
75 case ui::COLOR_PROFILE_MOVIE: 147 case ui::COLOR_PROFILE_MOVIE:
76 return "movie"; 148 return "movie";
77 case ui::COLOR_PROFILE_READING: 149 case ui::COLOR_PROFILE_READING:
78 return "reading"; 150 return "reading";
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 247
176 float device_scale_factor = 1.0; 248 float device_scale_factor = 1.0;
177 int dsf_value = 0; 249 int dsf_value = 0;
178 if (dict_value->GetInteger("device-scale-factor", &dsf_value)) 250 if (dict_value->GetInteger("device-scale-factor", &dsf_value))
179 device_scale_factor = static_cast<float>(dsf_value) / 1000.0f; 251 device_scale_factor = static_cast<float>(dsf_value) / 1000.0f;
180 252
181 gfx::Insets insets; 253 gfx::Insets insets;
182 if (ValueToInsets(*dict_value, &insets)) 254 if (ValueToInsets(*dict_value, &insets))
183 insets_to_set = &insets; 255 insets_to_set = &insets;
184 256
257 display::TouchCalibrationData calibration_data;
258 display::TouchCalibrationData* calibration_data_to_set = nullptr;
259 if (ValueToTouchData(*dict_value, &calibration_data))
260 calibration_data_to_set = &calibration_data;
261
185 ui::ColorCalibrationProfile color_profile = ui::COLOR_PROFILE_STANDARD; 262 ui::ColorCalibrationProfile color_profile = ui::COLOR_PROFILE_STANDARD;
186 std::string color_profile_name; 263 std::string color_profile_name;
187 if (dict_value->GetString("color_profile_name", &color_profile_name)) 264 if (dict_value->GetString("color_profile_name", &color_profile_name))
188 color_profile = StringToColorProfile(color_profile_name); 265 color_profile = StringToColorProfile(color_profile_name);
189 GetDisplayManager()->RegisterDisplayProperty(id, 266 GetDisplayManager()->RegisterDisplayProperty(
190 rotation, 267 id, rotation, ui_scale, insets_to_set, resolution_in_pixels,
191 ui_scale, 268 device_scale_factor, color_profile, calibration_data_to_set);
192 insets_to_set,
193 resolution_in_pixels,
194 device_scale_factor,
195 color_profile);
196 } 269 }
197 } 270 }
198 271
199 void LoadDisplayRotationState() { 272 void LoadDisplayRotationState() {
200 PrefService* local_state = g_browser_process->local_state(); 273 PrefService* local_state = g_browser_process->local_state();
201 const base::DictionaryValue* properties = 274 const base::DictionaryValue* properties =
202 local_state->GetDictionary(prefs::kDisplayRotationLock); 275 local_state->GetDictionary(prefs::kDisplayRotationLock);
203 276
204 bool rotation_lock = false; 277 bool rotation_lock = false;
205 if (!properties->GetBoolean("lock", &rotation_lock)) 278 if (!properties->GetBoolean("lock", &rotation_lock))
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 property_value->SetInteger( 349 property_value->SetInteger(
277 "device-scale-factor", 350 "device-scale-factor",
278 static_cast<int>(mode->device_scale_factor() * 1000)); 351 static_cast<int>(mode->device_scale_factor() * 1000));
279 } 352 }
280 if (!info.overscan_insets_in_dip().IsEmpty()) 353 if (!info.overscan_insets_in_dip().IsEmpty())
281 InsetsToValue(info.overscan_insets_in_dip(), property_value.get()); 354 InsetsToValue(info.overscan_insets_in_dip(), property_value.get());
282 if (info.color_profile() != ui::COLOR_PROFILE_STANDARD) { 355 if (info.color_profile() != ui::COLOR_PROFILE_STANDARD) {
283 property_value->SetString( 356 property_value->SetString(
284 "color_profile_name", ColorProfileToString(info.color_profile())); 357 "color_profile_name", ColorProfileToString(info.color_profile()));
285 } 358 }
359 if (info.has_touch_calibration_data())
360 TouchDataToValue(info.GetTouchCalibrationData(), property_value.get());
286 pref_data->Set(base::Int64ToString(id), property_value.release()); 361 pref_data->Set(base::Int64ToString(id), property_value.release());
287 } 362 }
288 } 363 }
289 364
290 typedef std::map<chromeos::DisplayPowerState, std::string> 365 typedef std::map<chromeos::DisplayPowerState, std::string>
291 DisplayPowerStateToStringMap; 366 DisplayPowerStateToStringMap;
292 367
293 const DisplayPowerStateToStringMap* GetDisplayPowerStateToStringMap() { 368 const DisplayPowerStateToStringMap* GetDisplayPowerStateToStringMap() {
294 // Don't save or retore ALL_OFF state. crbug.com/318456. 369 // Don't save or retore ALL_OFF state. crbug.com/318456.
295 static const DisplayPowerStateToStringMap* map = ash::CreateToStringMap( 370 static const DisplayPowerStateToStringMap* map = ash::CreateToStringMap(
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 const display::DisplayLayout& layout) { 470 const display::DisplayLayout& layout) {
396 StoreDisplayLayoutPref(list, layout); 471 StoreDisplayLayoutPref(list, layout);
397 } 472 }
398 473
399 // Stores the given |power_state|. 474 // Stores the given |power_state|.
400 void StoreDisplayPowerStateForTest(DisplayPowerState power_state) { 475 void StoreDisplayPowerStateForTest(DisplayPowerState power_state) {
401 StoreDisplayPowerState(power_state); 476 StoreDisplayPowerState(power_state);
402 } 477 }
403 478
404 } // namespace chromeos 479 } // namespace chromeos
OLDNEW
« no previous file with comments | « ash/display/display_manager_unittest.cc ('k') | chrome/browser/chromeos/display/display_preferences_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698