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

Side by Side Diff: ui/display/util/edid_parser.cc

Issue 1456623002: Add support for virtual displays (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use std::max as suggested by oshima@ Created 5 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
« no previous file with comments | « ui/display/util/display_util.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/display/util/edid_parser.h" 5 #include "ui/display/util/edid_parser.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/hash.h" 9 #include "base/hash.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
11 #include "base/sys_byteorder.h" 11 #include "base/sys_byteorder.h"
12 #include "ui/display/util/display_util.h"
12 #include "ui/gfx/geometry/size.h" 13 #include "ui/gfx/geometry/size.h"
13 14
14 namespace ui { 15 namespace ui {
15 16
16 namespace { 17 namespace {
17 18
18 // Returns 64-bit persistent ID for the specified manufacturer's ID and
19 // product_code_hash, and the index of the output it is connected to.
20 // |output_index| is used to distinguish the displays of the same type. For
21 // example, swapping two identical display between two outputs will not be
22 // treated as swap. The 'serial number' field in EDID isn't used here because
23 // it is not guaranteed to have unique number and it may have the same fixed
24 // value (like 0).
25 int64_t GetID(uint16_t manufacturer_id,
26 uint32_t product_code_hash,
27 uint8_t output_index) {
28 return ((static_cast<int64_t>(manufacturer_id) << 40) |
29 (static_cast<int64_t>(product_code_hash) << 8) | output_index);
30 }
31
32 // Returns a 32-bit identifier for this model of display, using 19 // Returns a 32-bit identifier for this model of display, using
33 // |manufacturer_id| and |product_code|. 20 // |manufacturer_id| and |product_code|.
34 uint32_t GetProductID(uint16_t manufacturer_id, uint16_t product_code) { 21 uint32_t GetProductID(uint16_t manufacturer_id, uint16_t product_code) {
35 return ((static_cast<uint32_t>(manufacturer_id) << 16) | 22 return ((static_cast<uint32_t>(manufacturer_id) << 16) |
36 (static_cast<uint32_t>(product_code))); 23 (static_cast<uint32_t>(product_code)));
37 } 24 }
38 25
39 } // namespace 26 } // namespace
40 27
41 bool GetDisplayIdFromEDID(const std::vector<uint8_t>& edid, 28 bool GetDisplayIdFromEDID(const std::vector<uint8_t>& edid,
42 uint8_t output_index, 29 uint8_t output_index,
43 int64_t* display_id_out, 30 int64_t* display_id_out,
44 int64_t* product_id_out) { 31 int64_t* product_id_out) {
45 uint16_t manufacturer_id = 0; 32 uint16_t manufacturer_id = 0;
46 uint16_t product_code = 0; 33 uint16_t product_code = 0;
47 std::string product_name; 34 std::string product_name;
48 35
49 // ParseOutputDeviceData fails if it doesn't have product_name. 36 // ParseOutputDeviceData fails if it doesn't have product_name.
50 ParseOutputDeviceData(edid, &manufacturer_id, &product_code, &product_name, 37 ParseOutputDeviceData(edid, &manufacturer_id, &product_code, &product_name,
51 nullptr, nullptr); 38 nullptr, nullptr);
52 39
53 if (manufacturer_id != 0) { 40 if (manufacturer_id != 0) {
54 // Generates product specific value from product_name instead of product 41 // Generates product specific value from product_name instead of product
55 // code. 42 // code.
56 // See crbug.com/240341 43 // See crbug.com/240341
57 uint32_t product_code_hash = 44 uint32_t product_code_hash =
58 product_name.empty() ? 0 : base::Hash(product_name); 45 product_name.empty() ? 0 : base::Hash(product_name);
59 // An ID based on display's index will be assigned later if this call 46 // An ID based on display's index will be assigned later if this call
60 // fails. 47 // fails.
61 *display_id_out = GetID( 48 *display_id_out =
62 manufacturer_id, product_code_hash, output_index); 49 GenerateDisplayID(manufacturer_id, product_code_hash, output_index);
63 // product_id is 64-bit signed so it can store -1 as kInvalidProductID and 50 // product_id is 64-bit signed so it can store -1 as kInvalidProductID and
64 // not match a valid product id which will all be in the lowest 32-bits. 51 // not match a valid product id which will all be in the lowest 32-bits.
65 if (product_id_out) 52 if (product_id_out)
66 *product_id_out = GetProductID(manufacturer_id, product_code); 53 *product_id_out = GetProductID(manufacturer_id, product_code);
67 return true; 54 return true;
68 } 55 }
69 return false; 56 return false;
70 } 57 }
71 58
72 bool ParseOutputDeviceData(const std::vector<uint8_t>& edid, 59 bool ParseOutputDeviceData(const std::vector<uint8_t>& edid,
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 *flag = false; 252 *flag = false;
266 } 253 }
267 return true; 254 return true;
268 } 255 }
269 } 256 }
270 257
271 return false; 258 return false;
272 } 259 }
273 260
274 } // namespace ui 261 } // namespace ui
OLDNEW
« no previous file with comments | « ui/display/util/display_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698