DisplayIdentification.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright (C) 2018 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #pragma once
  17. #include <array>
  18. #include <cstdint>
  19. #include <optional>
  20. #include <string>
  21. #include <string_view>
  22. #include <vector>
  23. #include <ui/GraphicTypes.h>
  24. namespace android {
  25. struct DisplayId {
  26. using Type = PhysicalDisplayId;
  27. Type value;
  28. uint16_t manufacturerId() const;
  29. static DisplayId fromEdid(uint8_t port, uint16_t manufacturerId, uint32_t displayNameHash);
  30. };
  31. inline bool operator==(DisplayId lhs, DisplayId rhs) {
  32. return lhs.value == rhs.value;
  33. }
  34. inline bool operator!=(DisplayId lhs, DisplayId rhs) {
  35. return !(lhs == rhs);
  36. }
  37. inline std::string to_string(DisplayId displayId) {
  38. return std::to_string(displayId.value);
  39. }
  40. using DisplayIdentificationData = std::vector<uint8_t>;
  41. struct DisplayIdentificationInfo {
  42. DisplayId id;
  43. std::string name;
  44. };
  45. // NUL-terminated plug and play ID.
  46. using PnpId = std::array<char, 4>;
  47. struct Edid {
  48. uint16_t manufacturerId;
  49. PnpId pnpId;
  50. std::string_view displayName;
  51. };
  52. bool isEdid(const DisplayIdentificationData&);
  53. std::optional<Edid> parseEdid(const DisplayIdentificationData&);
  54. std::optional<PnpId> getPnpId(uint16_t manufacturerId);
  55. std::optional<PnpId> getPnpId(DisplayId);
  56. std::optional<DisplayIdentificationInfo> parseDisplayIdentificationData(
  57. uint8_t port, const DisplayIdentificationData&);
  58. DisplayId getFallbackDisplayId(uint8_t port);
  59. DisplayId getVirtualDisplayId(uint32_t id);
  60. } // namespace android
  61. namespace std {
  62. template <>
  63. struct hash<android::DisplayId> {
  64. size_t operator()(android::DisplayId displayId) const {
  65. return hash<android::DisplayId::Type>()(displayId.value);
  66. }
  67. };
  68. } // namespace std