edid_parser.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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
  3. // found in the LICENSE file.
  4. #ifndef UI_DISPLAY_UTIL_EDID_PARSER_H_
  5. #define UI_DISPLAY_UTIL_EDID_PARSER_H_
  6. #include <stdint.h>
  7. #include <string>
  8. #include <vector>
  9. #include "base/containers/flat_set.h"
  10. #include "third_party/abseil-cpp/absl/types/optional.h"
  11. #include "third_party/skia/include/core/SkColorSpace.h"
  12. #include "ui/display/types/display_constants.h"
  13. #include "ui/display/util/display_util_export.h"
  14. #include "ui/gfx/color_space.h"
  15. #include "ui/gfx/geometry/size.h"
  16. #include "ui/gfx/hdr_static_metadata.h"
  17. namespace display {
  18. // This class parses a EDID (Extended Display Identification Data) binary blob
  19. // passed on constructor, and provides access to the parsed information, plus
  20. // a few utility postprocessings.
  21. class DISPLAY_UTIL_EXPORT EdidParser {
  22. public:
  23. explicit EdidParser(const std::vector<uint8_t>& edid_blob,
  24. bool is_external = false);
  25. EdidParser(const EdidParser&) = delete;
  26. EdidParser& operator=(const EdidParser&) = delete;
  27. ~EdidParser();
  28. uint16_t manufacturer_id() const { return manufacturer_id_; }
  29. uint16_t product_id() const { return product_id_; }
  30. std::string block_zero_serial_number_hash() const {
  31. return block_zero_serial_number_hash_.value_or("");
  32. }
  33. std::string descriptor_block_serial_number_hash() const {
  34. return descriptor_block_serial_number_hash_.value_or("");
  35. }
  36. gfx::Size max_image_size() const {
  37. return max_image_size_.value_or(gfx::Size());
  38. }
  39. const std::string& display_name() const { return display_name_; }
  40. const gfx::Size& active_pixel_size() const { return active_pixel_size_; }
  41. int32_t week_of_manufacture() const {
  42. return week_of_manufacture_.value_or(0);
  43. }
  44. int32_t year_of_manufacture() const { return year_of_manufacture_; }
  45. bool has_overscan_flag() const { return overscan_flag_.has_value(); }
  46. bool overscan_flag() const { return overscan_flag_.value(); }
  47. double gamma() const { return gamma_; }
  48. int32_t bits_per_channel() const { return bits_per_channel_; }
  49. const SkColorSpacePrimaries& primaries() const { return primaries_; }
  50. const base::flat_set<gfx::ColorSpace::PrimaryID>&
  51. supported_color_primary_ids() const {
  52. return supported_color_primary_ids_;
  53. }
  54. const base::flat_set<gfx::ColorSpace::TransferID>&
  55. supported_color_transfer_ids() const {
  56. return supported_color_transfer_ids_;
  57. }
  58. const absl::optional<gfx::HDRStaticMetadata>& hdr_static_metadata() const {
  59. return hdr_static_metadata_;
  60. }
  61. const absl::optional<uint16_t>& min_vfreq() const { return min_vfreq_; }
  62. const absl::optional<uint16_t>& max_vfreq() const { return max_vfreq_; }
  63. // Returns a 32-bit identifier for this display |manufacturer_id_| and
  64. // |product_id_|.
  65. uint32_t GetProductCode() const;
  66. // Generates a unique display id out of a mix of |manufacturer_id_|, hashed
  67. // |display_name_| if available, and |output_index|.
  68. // Here, uniqueness is heavily based on the connector's index to which the
  69. // display is attached to.
  70. int64_t GetIndexBasedDisplayId(uint8_t output_index) const;
  71. // Generates a unique display ID out of a mix of |manufacturer_id_|,
  72. // |product_id_|, |display_name_|, |week_of_manufacture_|,
  73. // |year_of_manufacture_|, |max_image_size_|,
  74. // |block_zero_serial_number_hash_|, and
  75. // |descriptor_block_serial_number_hash_|. Note that a hash will be produced
  76. // regardless of whether or not some (or all) of the fields are
  77. // missing/empty/default.
  78. // Here, uniqueness is solely based on a display's EDID and is not guaranteed
  79. // due to known EDIDs' completeness and correctness issues.
  80. int64_t GetEdidBasedDisplayId() const;
  81. // Splits the |product_code| (as returned by GetDisplayId()) into its
  82. // constituents |manufacturer_id| and |product_id|.
  83. static void SplitProductCodeInManufacturerIdAndProductId(
  84. int64_t product_code,
  85. uint16_t* manufacturer_id,
  86. uint16_t* product_id);
  87. // Extracts the three letter Manufacturer ID out of |manufacturer_id|.
  88. static std::string ManufacturerIdToString(uint16_t manufacturer_id);
  89. // Extracts the 2 Byte Product ID as hex out of |product_id|.
  90. static std::string ProductIdToString(uint16_t product_id);
  91. private:
  92. // Parses |edid_blob|, filling up as many as possible fields below.
  93. void ParseEdid(const std::vector<uint8_t>& edid);
  94. // We collect optional fields UMAs for external external displays only.
  95. void ReportEdidOptionalsForExternalDisplay() const;
  96. // Whether or not this EDID belongs to an external display.
  97. bool is_external_display_;
  98. uint16_t manufacturer_id_;
  99. uint16_t product_id_;
  100. absl::optional<std::string> block_zero_serial_number_hash_;
  101. absl::optional<std::string> descriptor_block_serial_number_hash_;
  102. absl::optional<gfx::Size> max_image_size_;
  103. std::string display_name_;
  104. // Active pixel size from the first detailed timing descriptor in the EDID.
  105. gfx::Size active_pixel_size_;
  106. // When |week_of_manufacture_| == 0xFF, |year_of_manufacture_| is model year.
  107. absl::optional<int32_t> week_of_manufacture_;
  108. int32_t year_of_manufacture_;
  109. absl::optional<bool> overscan_flag_;
  110. double gamma_;
  111. int bits_per_channel_;
  112. SkColorSpacePrimaries primaries_;
  113. base::flat_set<gfx::ColorSpace::PrimaryID> supported_color_primary_ids_;
  114. base::flat_set<gfx::ColorSpace::TransferID> supported_color_transfer_ids_;
  115. absl::optional<gfx::HDRStaticMetadata> hdr_static_metadata_;
  116. absl::optional<uint16_t> min_vfreq_;
  117. absl::optional<uint16_t> max_vfreq_;
  118. };
  119. } // namespace display
  120. #endif // UI_DISPLAY_UTIL_EDID_PARSER_H_