Sasha McIntosh | f8c1411 | 2024-12-11 12:03:32 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2025 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 | |
| 17 | #pragma once |
| 18 | |
Sasha McIntosh | f8c1411 | 2024-12-11 12:03:32 -0500 | [diff] [blame] | 19 | #if HAS_LIBDISPLAY_INFO |
| 20 | extern "C" { |
Lucas Berthou | 30808a2 | 2025-02-05 17:52:33 +0000 | [diff] [blame] | 21 | #include <libdisplay-info/edid.h> |
Sasha McIntosh | f8c1411 | 2024-12-11 12:03:32 -0500 | [diff] [blame] | 22 | #include <libdisplay-info/info.h> |
| 23 | } |
| 24 | #endif |
| 25 | |
Sasha McIntosh | f9062b6 | 2024-11-12 10:55:06 -0500 | [diff] [blame] | 26 | #include <ui/GraphicTypes.h> |
| 27 | |
Sasha McIntosh | 851ea4d | 2024-12-04 17:14:55 -0500 | [diff] [blame] | 28 | #include "compositor/DisplayInfo.h" |
Sasha McIntosh | f8c1411 | 2024-12-11 12:03:32 -0500 | [diff] [blame] | 29 | #include "drm/DrmUnique.h" |
Sasha McIntosh | f8c1411 | 2024-12-11 12:03:32 -0500 | [diff] [blame] | 30 | |
| 31 | namespace android { |
| 32 | |
| 33 | // Stub wrapper class for edid parsing |
| 34 | class EdidWrapper { |
| 35 | public: |
| 36 | EdidWrapper() = default; |
| 37 | EdidWrapper(const EdidWrapper &) = delete; |
| 38 | virtual ~EdidWrapper() = default; |
Sasha McIntosh | f9062b6 | 2024-11-12 10:55:06 -0500 | [diff] [blame] | 39 | |
| 40 | virtual void GetSupportedHdrTypes(std::vector<ui::Hdr> &types) { |
| 41 | types.clear(); |
| 42 | }; |
| 43 | virtual void GetHdrCapabilities(std::vector<ui::Hdr> &types, |
Sasha McIntosh | 7009cc1 | 2025-03-11 17:58:37 -0400 | [diff] [blame] | 44 | float * /*max_luminance*/, |
| 45 | float * /*max_average_luminance*/, |
| 46 | float * /*min_luminance*/) { |
Sasha McIntosh | f9062b6 | 2024-11-12 10:55:06 -0500 | [diff] [blame] | 47 | GetSupportedHdrTypes(types); |
| 48 | }; |
Sasha McIntosh | 851ea4d | 2024-12-04 17:14:55 -0500 | [diff] [blame] | 49 | virtual void GetColorModes(std::vector<Colormode> &color_modes) { |
| 50 | color_modes.clear(); |
| 51 | }; |
Lucas Berthou | 30808a2 | 2025-02-05 17:52:33 +0000 | [diff] [blame] | 52 | virtual int GetDpiX() { |
| 53 | return -1; |
| 54 | } |
| 55 | virtual int GetDpiY() { |
| 56 | return -1; |
| 57 | } |
| 58 | |
| 59 | virtual auto GetBoundsMm() -> std::pair<int32_t, int32_t> { |
| 60 | return {-1, -1}; |
| 61 | } |
Sasha McIntosh | f8c1411 | 2024-12-11 12:03:32 -0500 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | #if HAS_LIBDISPLAY_INFO |
| 65 | // Wrapper class for that uses libdisplay-info to parse edids |
| 66 | class LibdisplayEdidWrapper final : public EdidWrapper { |
| 67 | public: |
| 68 | LibdisplayEdidWrapper() = delete; |
Sasha McIntosh | f8c1411 | 2024-12-11 12:03:32 -0500 | [diff] [blame] | 69 | ~LibdisplayEdidWrapper() override { |
| 70 | di_info_destroy(info_); |
| 71 | } |
| 72 | static auto Create(DrmModePropertyBlobUnique blob) |
Sasha McIntosh | f9062b6 | 2024-11-12 10:55:06 -0500 | [diff] [blame] | 73 | -> std::unique_ptr<LibdisplayEdidWrapper>; |
Sasha McIntosh | f8c1411 | 2024-12-11 12:03:32 -0500 | [diff] [blame] | 74 | |
Sasha McIntosh | f9062b6 | 2024-11-12 10:55:06 -0500 | [diff] [blame] | 75 | void GetSupportedHdrTypes(std::vector<ui::Hdr> &types) override; |
Sasha McIntosh | f8c1411 | 2024-12-11 12:03:32 -0500 | [diff] [blame] | 76 | |
Sasha McIntosh | f9062b6 | 2024-11-12 10:55:06 -0500 | [diff] [blame] | 77 | void GetHdrCapabilities(std::vector<ui::Hdr> &types, |
Sasha McIntosh | 7009cc1 | 2025-03-11 17:58:37 -0400 | [diff] [blame] | 78 | float *max_luminance, |
| 79 | float *max_average_luminance, |
| 80 | float *min_luminance) override; |
Sasha McIntosh | f8c1411 | 2024-12-11 12:03:32 -0500 | [diff] [blame] | 81 | |
Sasha McIntosh | 851ea4d | 2024-12-04 17:14:55 -0500 | [diff] [blame] | 82 | void GetColorModes(std::vector<Colormode> &color_modes) override; |
| 83 | |
Lucas Berthou | 30808a2 | 2025-02-05 17:52:33 +0000 | [diff] [blame] | 84 | auto GetDpiX() -> int override; |
| 85 | auto GetDpiY() -> int override; |
| 86 | |
| 87 | auto GetBoundsMm() -> std::pair<int32_t, int32_t> override; |
| 88 | |
Sasha McIntosh | f8c1411 | 2024-12-11 12:03:32 -0500 | [diff] [blame] | 89 | private: |
Sasha McIntosh | f9062b6 | 2024-11-12 10:55:06 -0500 | [diff] [blame] | 90 | LibdisplayEdidWrapper(di_info *info) : info_(std::move(info)) { |
| 91 | } |
| 92 | |
Lucas Berthou | 30808a2 | 2025-02-05 17:52:33 +0000 | [diff] [blame] | 93 | std::pair<int32_t, int32_t> GetDpi(); |
| 94 | |
Sasha McIntosh | f8c1411 | 2024-12-11 12:03:32 -0500 | [diff] [blame] | 95 | di_info *info_{}; |
| 96 | }; |
| 97 | #endif |
| 98 | |
| 99 | } // namespace android |