display_util.h 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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_DISPLAY_UTIL_H_
  5. #define UI_DISPLAY_UTIL_DISPLAY_UTIL_H_
  6. #include <stdint.h>
  7. #include "base/containers/flat_set.h"
  8. #include "ui/display/util/display_util_export.h"
  9. #include "ui/gfx/color_space.h"
  10. #include "ui/gfx/display_color_spaces.h"
  11. #include "ui/gfx/geometry/size.h"
  12. namespace display {
  13. class EdidParser;
  14. // 1 inch in mm.
  15. constexpr float kInchInMm = 25.4f;
  16. // These values are persisted to logs. Entries should not be renumbered and
  17. // numeric values should never be reused.
  18. enum class EdidColorSpaceChecksOutcome {
  19. kSuccess = 0,
  20. kErrorBadCoordinates = 1,
  21. kErrorPrimariesAreaTooSmall = 2,
  22. kErrorBluePrimaryIsBroken = 3,
  23. kErrorCannotExtractToXYZD50 = 4,
  24. kErrorBadGamma = 5,
  25. kMaxValue = kErrorBadGamma
  26. };
  27. // Returns true if a given size is allowed. Will return false for certain bogus
  28. // sizes in mm that should be ignored.
  29. DISPLAY_UTIL_EXPORT bool IsDisplaySizeValid(const gfx::Size& physical_size);
  30. // Returns 64-bit persistent ID for the specified manufacturer's ID and
  31. // product_code_hash, and the index of the output it is connected to.
  32. // |output_index| is used to distinguish the displays of the same type. For
  33. // example, swapping two identical display between two outputs will not be
  34. // treated as swap. The 'serial number' field in EDID isn't used here because
  35. // it is not guaranteed to have unique number and it may have the same fixed
  36. // value (like 0).
  37. DISPLAY_UTIL_EXPORT int64_t GenerateDisplayID(uint16_t manufacturer_id,
  38. uint32_t product_code_hash,
  39. uint8_t output_index);
  40. // Uses |edid_parser| to extract a gfx::ColorSpace which will be IsValid() if
  41. // both gamma and the color primaries were correctly found.
  42. DISPLAY_UTIL_EXPORT gfx::ColorSpace GetColorSpaceFromEdid(
  43. const display::EdidParser& edid_parser);
  44. // Returns true if one of following conditions is met.
  45. // 1) id1 is internal.
  46. // 2) output index of id1 < output index of id2 and id2 isn't internal.
  47. DISPLAY_UTIL_EXPORT bool CompareDisplayIds(int64_t id1, int64_t id2);
  48. // Returns true if the `display_id` is internal.
  49. DISPLAY_UTIL_EXPORT bool IsInternalDisplayId(int64_t display_id);
  50. // Returns true if the system has at least one internal display.
  51. DISPLAY_UTIL_EXPORT bool HasInternalDisplay();
  52. // Gets/Sets an id of display corresponding to internal panel.
  53. DISPLAY_UTIL_EXPORT const base::flat_set<int64_t>& GetInternalDisplayIds();
  54. DISPLAY_UTIL_EXPORT void SetInternalDisplayIds(
  55. base::flat_set<int64_t> display_ids);
  56. // Converts the color string name into a gfx::ColorSpace profile.
  57. DISPLAY_UTIL_EXPORT gfx::ColorSpace ForcedColorProfileStringToColorSpace(
  58. const std::string& value);
  59. // Returns the forced display color profile, which is given by
  60. // "--force-color-profile".
  61. DISPLAY_UTIL_EXPORT gfx::ColorSpace GetForcedDisplayColorProfile();
  62. // Indicates if a display color profile is being explicitly enforced from the
  63. // command line via "--force-color-profile".
  64. DISPLAY_UTIL_EXPORT bool HasForceDisplayColorProfile();
  65. #if BUILDFLAG(IS_CHROMEOS)
  66. // Taken from DisplayChangeObserver::CreateDisplayColorSpaces()
  67. // Constructs the raster DisplayColorSpaces out of |snapshot_color_space|,
  68. // including the HDR ones if present and |allow_high_bit_depth| is set.
  69. DISPLAY_UTIL_EXPORT gfx::DisplayColorSpaces CreateDisplayColorSpaces(
  70. const gfx::ColorSpace& snapshot_color_space,
  71. bool allow_high_bit_depth,
  72. const absl::optional<gfx::HDRStaticMetadata>& hdr_static_metadata);
  73. #endif // BUILDFLAG(IS_CHROMEOS)
  74. } // namespace display
  75. #endif // UI_DISPLAY_UTIL_DISPLAY_UTIL_H_