OLD | NEW |
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" |
(...skipping 11 matching lines...) Expand all Loading... |
22 // treated as swap. The 'serial number' field in EDID isn't used here because | 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 | 23 // it is not guaranteed to have unique number and it may have the same fixed |
24 // value (like 0). | 24 // value (like 0). |
25 int64_t GetID(uint16_t manufacturer_id, | 25 int64_t GetID(uint16_t manufacturer_id, |
26 uint32_t product_code_hash, | 26 uint32_t product_code_hash, |
27 uint8_t output_index) { | 27 uint8_t output_index) { |
28 return ((static_cast<int64_t>(manufacturer_id) << 40) | | 28 return ((static_cast<int64_t>(manufacturer_id) << 40) | |
29 (static_cast<int64_t>(product_code_hash) << 8) | output_index); | 29 (static_cast<int64_t>(product_code_hash) << 8) | output_index); |
30 } | 30 } |
31 | 31 |
| 32 // Returns a 64-bit identifier for this model of display, using |
| 33 // |manufacturer_id| and |product_code_hash|. |
| 34 int64_t GetProductID(uint16_t manufacturer_id, uint32_t product_code_hash) { |
| 35 return ((static_cast<int64_t>(manufacturer_id) << 32) | |
| 36 (static_cast<int64_t>(product_code_hash))); |
| 37 } |
| 38 |
32 } // namespace | 39 } // namespace |
33 | 40 |
34 bool GetDisplayIdFromEDID(const std::vector<uint8_t>& edid, | 41 bool GetDisplayIdFromEDID(const std::vector<uint8_t>& edid, |
35 uint8_t output_index, | 42 uint8_t output_index, |
36 int64_t* display_id_out) { | 43 int64_t* display_id_out, |
| 44 int64_t* product_id_out) { |
37 uint16_t manufacturer_id = 0; | 45 uint16_t manufacturer_id = 0; |
38 std::string product_name; | 46 std::string product_name; |
39 | 47 |
40 // ParseOutputDeviceData fails if it doesn't have product_name. | 48 // ParseOutputDeviceData fails if it doesn't have product_name. |
41 ParseOutputDeviceData(edid, &manufacturer_id, &product_name, nullptr, | 49 ParseOutputDeviceData(edid, &manufacturer_id, &product_name, nullptr, |
42 nullptr); | 50 nullptr); |
43 | 51 |
44 // Generates product specific value from product_name instead of product code. | 52 // Generates product specific value from product_name instead of product code. |
45 // See crbug.com/240341 | 53 // See crbug.com/240341 |
46 uint32_t product_code_hash = product_name.empty() ? | 54 uint32_t product_code_hash = product_name.empty() ? |
47 0 : base::Hash(product_name); | 55 0 : base::Hash(product_name); |
48 if (manufacturer_id != 0) { | 56 if (manufacturer_id != 0) { |
49 // An ID based on display's index will be assigned later if this call | 57 // An ID based on display's index will be assigned later if this call |
50 // fails. | 58 // fails. |
51 *display_id_out = GetID( | 59 *display_id_out = GetID( |
52 manufacturer_id, product_code_hash, output_index); | 60 manufacturer_id, product_code_hash, output_index); |
| 61 if (product_id_out) |
| 62 *product_id_out = GetProductID(manufacturer_id, product_code_hash); |
53 return true; | 63 return true; |
54 } | 64 } |
55 return false; | 65 return false; |
56 } | 66 } |
57 | 67 |
58 bool ParseOutputDeviceData(const std::vector<uint8_t>& edid, | 68 bool ParseOutputDeviceData(const std::vector<uint8_t>& edid, |
59 uint16_t* manufacturer_id, | 69 uint16_t* manufacturer_id, |
60 std::string* human_readable_name, | 70 std::string* human_readable_name, |
61 gfx::Size* active_pixel_out, | 71 gfx::Size* active_pixel_out, |
62 gfx::Size* physical_display_size_out) { | 72 gfx::Size* physical_display_size_out) { |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 *flag = false; | 248 *flag = false; |
239 } | 249 } |
240 return true; | 250 return true; |
241 } | 251 } |
242 } | 252 } |
243 | 253 |
244 return false; | 254 return false; |
245 } | 255 } |
246 | 256 |
247 } // namespace ui | 257 } // namespace ui |
OLD | NEW |