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

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

Powered by Google App Engine
This is Rietveld 408576698