blob: 5a17b937b89fd5ed32e08b778d45410c327940b2 [file] [log] [blame]
Sasha McIntoshf9062b62024-11-12 10:55:06 -05001/*
2 * Copyright (C) 2024 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#define LOG_TAG "drmhwc"
18
19#if HAS_LIBDISPLAY_INFO
20#include "utils/EdidWrapper.h"
21#include "utils/log.h"
22
23namespace android {
24
25auto LibdisplayEdidWrapper::Create(DrmModePropertyBlobUnique blob)
26 -> std::unique_ptr<LibdisplayEdidWrapper> {
27 if (!blob)
28 return nullptr;
29
30 auto *info = di_info_parse_edid(blob->data, blob->length);
31 if (!info) {
32 ALOGW("Failed to parse edid blob.");
33 return nullptr;
34 }
35
36 return std::unique_ptr<LibdisplayEdidWrapper>(
37 new LibdisplayEdidWrapper(std::move(info)));
38}
39
40void LibdisplayEdidWrapper::GetSupportedHdrTypes(std::vector<ui::Hdr> &types) {
41 types.clear();
42
43 const auto *hdr_static_meta = di_info_get_hdr_static_metadata(info_);
44 const auto *colorimetries = di_info_get_supported_signal_colorimetry(info_);
45 if (colorimetries->bt2020_cycc || colorimetries->bt2020_ycc ||
46 colorimetries->bt2020_rgb) {
47 if (hdr_static_meta->pq)
48 types.emplace_back(ui::Hdr::HDR10);
49 if (hdr_static_meta->hlg)
50 types.emplace_back(ui::Hdr::HLG);
51 }
52}
53
54void LibdisplayEdidWrapper::GetHdrCapabilities(
55 std::vector<ui::Hdr> &types, const float *max_luminance,
56 const float *max_average_luminance, const float *min_luminance) {
57 GetSupportedHdrTypes(types);
58
59 const auto *hdr_static_meta = di_info_get_hdr_static_metadata(info_);
60 max_luminance = &hdr_static_meta->desired_content_max_luminance;
61 max_average_luminance = &hdr_static_meta
62 ->desired_content_max_frame_avg_luminance;
63 min_luminance = &hdr_static_meta->desired_content_min_luminance;
64}
65
66} // namespace android
67#endif