blob: 651c28474d752bc2f99cfc492d81672349b41381 [file] [log] [blame]
Sasha McIntoshf8c14112024-12-11 12:03:32 -05001/*
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 McIntoshf8c14112024-12-11 12:03:32 -050019#if HAS_LIBDISPLAY_INFO
20extern "C" {
Lucas Berthou30808a22025-02-05 17:52:33 +000021#include <libdisplay-info/edid.h>
Sasha McIntoshf8c14112024-12-11 12:03:32 -050022#include <libdisplay-info/info.h>
23}
24#endif
25
Sasha McIntoshf9062b62024-11-12 10:55:06 -050026#include <ui/GraphicTypes.h>
27
Sasha McIntosh851ea4d2024-12-04 17:14:55 -050028#include "compositor/DisplayInfo.h"
Sasha McIntoshf8c14112024-12-11 12:03:32 -050029#include "drm/DrmUnique.h"
Sasha McIntoshf8c14112024-12-11 12:03:32 -050030
31namespace android {
32
33// Stub wrapper class for edid parsing
34class EdidWrapper {
35 public:
36 EdidWrapper() = default;
37 EdidWrapper(const EdidWrapper &) = delete;
38 virtual ~EdidWrapper() = default;
Sasha McIntoshf9062b62024-11-12 10:55:06 -050039
40 virtual void GetSupportedHdrTypes(std::vector<ui::Hdr> &types) {
41 types.clear();
42 };
43 virtual void GetHdrCapabilities(std::vector<ui::Hdr> &types,
Sasha McIntosh7009cc12025-03-11 17:58:37 -040044 float * /*max_luminance*/,
45 float * /*max_average_luminance*/,
46 float * /*min_luminance*/) {
Sasha McIntoshf9062b62024-11-12 10:55:06 -050047 GetSupportedHdrTypes(types);
48 };
Sasha McIntosh851ea4d2024-12-04 17:14:55 -050049 virtual void GetColorModes(std::vector<Colormode> &color_modes) {
50 color_modes.clear();
51 };
Lucas Berthou30808a22025-02-05 17:52:33 +000052 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 McIntoshf8c14112024-12-11 12:03:32 -050062};
63
64#if HAS_LIBDISPLAY_INFO
65// Wrapper class for that uses libdisplay-info to parse edids
66class LibdisplayEdidWrapper final : public EdidWrapper {
67 public:
68 LibdisplayEdidWrapper() = delete;
Sasha McIntoshf8c14112024-12-11 12:03:32 -050069 ~LibdisplayEdidWrapper() override {
70 di_info_destroy(info_);
71 }
72 static auto Create(DrmModePropertyBlobUnique blob)
Sasha McIntoshf9062b62024-11-12 10:55:06 -050073 -> std::unique_ptr<LibdisplayEdidWrapper>;
Sasha McIntoshf8c14112024-12-11 12:03:32 -050074
Sasha McIntoshf9062b62024-11-12 10:55:06 -050075 void GetSupportedHdrTypes(std::vector<ui::Hdr> &types) override;
Sasha McIntoshf8c14112024-12-11 12:03:32 -050076
Sasha McIntoshf9062b62024-11-12 10:55:06 -050077 void GetHdrCapabilities(std::vector<ui::Hdr> &types,
Sasha McIntosh7009cc12025-03-11 17:58:37 -040078 float *max_luminance,
79 float *max_average_luminance,
80 float *min_luminance) override;
Sasha McIntoshf8c14112024-12-11 12:03:32 -050081
Sasha McIntosh851ea4d2024-12-04 17:14:55 -050082 void GetColorModes(std::vector<Colormode> &color_modes) override;
83
Lucas Berthou30808a22025-02-05 17:52:33 +000084 auto GetDpiX() -> int override;
85 auto GetDpiY() -> int override;
86
87 auto GetBoundsMm() -> std::pair<int32_t, int32_t> override;
88
Sasha McIntoshf8c14112024-12-11 12:03:32 -050089 private:
Sasha McIntoshf9062b62024-11-12 10:55:06 -050090 LibdisplayEdidWrapper(di_info *info) : info_(std::move(info)) {
91 }
92
Lucas Berthou30808a22025-02-05 17:52:33 +000093 std::pair<int32_t, int32_t> GetDpi();
94
Sasha McIntoshf8c14112024-12-11 12:03:32 -050095 di_info *info_{};
96};
97#endif
98
99} // namespace android