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

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: Updates display manager and display preferences to handle touch calibration data. 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 stroes
stevenjb 2016/12/02 20:02:48 stores
malaykeshav 2016/12/02 20:12:32 Done
79 // it in an instance of TouchCalibrationData struct.
80 bool ValueToTouchData(const base::DictionaryValue& value,
81 display::TouchCalibrationData* touch_calibration_data) {
82 int x, y;
83 x = y = 0;
stevenjb 2016/12/02 20:02:48 nit: int x = 0, y = 0;
malaykeshav 2016/12/02 20:12:33 Done
84 bool got_value = true;
85
86 display::TouchCalibrationData::CalibrationPointPairQuad* point_pair_quad =
87 &(touch_calibration_data->point_pairs);
88
89 gfx::Point display_point;
90 gfx::Point touch_point;
91 for (std::size_t row = 0; row < point_pair_quad->size(); row++) {
92 // Get the display point
93 got_value &= value.GetInteger(kTouchCalibrationDataKeys[row * 4], &x);
94 got_value &= value.GetInteger(kTouchCalibrationDataKeys[row * 4 + 1], &y);
95 if (!got_value)
96 return false;
stevenjb 2016/12/02 20:02:48 nit: Instead of using |got_value|, these could all
malaykeshav 2016/12/02 20:12:32 Done
97 display_point.SetPoint(x, y);
98
99 // Get the touch point
100 got_value &= value.GetInteger(kTouchCalibrationDataKeys[row * 4 + 2], &x);
101 got_value &= value.GetInteger(kTouchCalibrationDataKeys[row * 4 + 3], &y);
102 if (!got_value)
103 return false;
104 touch_point.SetPoint(x, y);
105
106 (*point_pair_quad)[row] = std::make_pair(display_point, touch_point);
107 }
108
109 int width, height;
110 got_value &= value.GetInteger(kTouchCalibrationWidth, &width);
111 got_value &= value.GetInteger(kTouchCalibrationHeight, &height);
112 if (!got_value)
113 return false;
114 touch_calibration_data->bounds = gfx::Size(width, height);
115
116 return true;
117 }
118
119 // Stores the touch calibration data into the dictionary.
120 void TouchDataToValue(
121 base::DictionaryValue* value,
122 const display::TouchCalibrationData& touch_calibration_data) {
stevenjb 2016/12/02 20:02:48 |value| (output) should follow input.
malaykeshav 2016/12/02 20:12:33 Done
123 DCHECK(value);
124 for (std::size_t row = 0; row < touch_calibration_data.point_pairs.size();
125 row++) {
126 // Store the display points
127 value->SetInteger(kTouchCalibrationDataKeys[row * 4],
128 touch_calibration_data.point_pairs[row].first.x());
129 value->SetInteger(kTouchCalibrationDataKeys[row * 4 + 1],
130 touch_calibration_data.point_pairs[row].first.y());
131 // Store the touch points.
132 value->SetInteger(kTouchCalibrationDataKeys[row * 4 + 2],
133 touch_calibration_data.point_pairs[row].second.x());
134 value->SetInteger(kTouchCalibrationDataKeys[row * 4 + 3],
135 touch_calibration_data.point_pairs[row].second.y());
136 }
137 value->SetInteger(kTouchCalibrationWidth,
138 touch_calibration_data.bounds.width());
139 value->SetInteger(kTouchCalibrationHeight,
140 touch_calibration_data.bounds.height());
141 }
142
69 std::string ColorProfileToString(ui::ColorCalibrationProfile profile) { 143 std::string ColorProfileToString(ui::ColorCalibrationProfile profile) {
70 switch (profile) { 144 switch (profile) {
71 case ui::COLOR_PROFILE_STANDARD: 145 case ui::COLOR_PROFILE_STANDARD:
72 return "standard"; 146 return "standard";
73 case ui::COLOR_PROFILE_DYNAMIC: 147 case ui::COLOR_PROFILE_DYNAMIC:
74 return "dynamic"; 148 return "dynamic";
75 case ui::COLOR_PROFILE_MOVIE: 149 case ui::COLOR_PROFILE_MOVIE:
76 return "movie"; 150 return "movie";
77 case ui::COLOR_PROFILE_READING: 151 case ui::COLOR_PROFILE_READING:
78 return "reading"; 152 return "reading";
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 249
176 float device_scale_factor = 1.0; 250 float device_scale_factor = 1.0;
177 int dsf_value = 0; 251 int dsf_value = 0;
178 if (dict_value->GetInteger("device-scale-factor", &dsf_value)) 252 if (dict_value->GetInteger("device-scale-factor", &dsf_value))
179 device_scale_factor = static_cast<float>(dsf_value) / 1000.0f; 253 device_scale_factor = static_cast<float>(dsf_value) / 1000.0f;
180 254
181 gfx::Insets insets; 255 gfx::Insets insets;
182 if (ValueToInsets(*dict_value, &insets)) 256 if (ValueToInsets(*dict_value, &insets))
183 insets_to_set = &insets; 257 insets_to_set = &insets;
184 258
259 display::TouchCalibrationData calibration_data;
260 display::TouchCalibrationData* calibration_data_to_set = nullptr;
261 if (ValueToTouchData(*dict_value, &calibration_data))
262 calibration_data_to_set = &calibration_data;
263
185 ui::ColorCalibrationProfile color_profile = ui::COLOR_PROFILE_STANDARD; 264 ui::ColorCalibrationProfile color_profile = ui::COLOR_PROFILE_STANDARD;
186 std::string color_profile_name; 265 std::string color_profile_name;
187 if (dict_value->GetString("color_profile_name", &color_profile_name)) 266 if (dict_value->GetString("color_profile_name", &color_profile_name))
188 color_profile = StringToColorProfile(color_profile_name); 267 color_profile = StringToColorProfile(color_profile_name);
189 GetDisplayManager()->RegisterDisplayProperty(id, 268 GetDisplayManager()->RegisterDisplayProperty(
190 rotation, 269 id, rotation, ui_scale, insets_to_set, resolution_in_pixels,
191 ui_scale, 270 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 } 271 }
197 } 272 }
198 273
199 void LoadDisplayRotationState() { 274 void LoadDisplayRotationState() {
200 PrefService* local_state = g_browser_process->local_state(); 275 PrefService* local_state = g_browser_process->local_state();
201 const base::DictionaryValue* properties = 276 const base::DictionaryValue* properties =
202 local_state->GetDictionary(prefs::kDisplayRotationLock); 277 local_state->GetDictionary(prefs::kDisplayRotationLock);
203 278
204 bool rotation_lock = false; 279 bool rotation_lock = false;
205 if (!properties->GetBoolean("lock", &rotation_lock)) 280 if (!properties->GetBoolean("lock", &rotation_lock))
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 property_value->SetInteger( 351 property_value->SetInteger(
277 "device-scale-factor", 352 "device-scale-factor",
278 static_cast<int>(mode->device_scale_factor() * 1000)); 353 static_cast<int>(mode->device_scale_factor() * 1000));
279 } 354 }
280 if (!info.overscan_insets_in_dip().IsEmpty()) 355 if (!info.overscan_insets_in_dip().IsEmpty())
281 InsetsToValue(info.overscan_insets_in_dip(), property_value.get()); 356 InsetsToValue(info.overscan_insets_in_dip(), property_value.get());
282 if (info.color_profile() != ui::COLOR_PROFILE_STANDARD) { 357 if (info.color_profile() != ui::COLOR_PROFILE_STANDARD) {
283 property_value->SetString( 358 property_value->SetString(
284 "color_profile_name", ColorProfileToString(info.color_profile())); 359 "color_profile_name", ColorProfileToString(info.color_profile()));
285 } 360 }
361 if (info.has_touch_calibration_data())
362 TouchDataToValue(property_value.get(), info.GetTouchCalibrationData());
286 pref_data->Set(base::Int64ToString(id), property_value.release()); 363 pref_data->Set(base::Int64ToString(id), property_value.release());
287 } 364 }
288 } 365 }
289 366
290 typedef std::map<chromeos::DisplayPowerState, std::string> 367 typedef std::map<chromeos::DisplayPowerState, std::string>
291 DisplayPowerStateToStringMap; 368 DisplayPowerStateToStringMap;
292 369
293 const DisplayPowerStateToStringMap* GetDisplayPowerStateToStringMap() { 370 const DisplayPowerStateToStringMap* GetDisplayPowerStateToStringMap() {
294 // Don't save or retore ALL_OFF state. crbug.com/318456. 371 // Don't save or retore ALL_OFF state. crbug.com/318456.
295 static const DisplayPowerStateToStringMap* map = ash::CreateToStringMap( 372 static const DisplayPowerStateToStringMap* map = ash::CreateToStringMap(
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 const display::DisplayLayout& layout) { 472 const display::DisplayLayout& layout) {
396 StoreDisplayLayoutPref(list, layout); 473 StoreDisplayLayoutPref(list, layout);
397 } 474 }
398 475
399 // Stores the given |power_state|. 476 // Stores the given |power_state|.
400 void StoreDisplayPowerStateForTest(DisplayPowerState power_state) { 477 void StoreDisplayPowerStateForTest(DisplayPowerState power_state) {
401 StoreDisplayPowerState(power_state); 478 StoreDisplayPowerState(power_state);
402 } 479 }
403 480
404 } // namespace chromeos 481 } // 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