blob: 35520014736ce7d6a5186403fb2b3a5d15061053 [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
19#define LOG_TAG "drmhwc"
20
21#if HAS_LIBDISPLAY_INFO
22extern "C" {
23#include <libdisplay-info/info.h>
24}
25#endif
26
27#include "drm/DrmUnique.h"
28#include "utils/log.h"
29
30namespace android {
31
32// Stub wrapper class for edid parsing
33class EdidWrapper {
34 public:
35 EdidWrapper() = default;
36 EdidWrapper(const EdidWrapper &) = delete;
37 virtual ~EdidWrapper() = default;
38};
39
40#if HAS_LIBDISPLAY_INFO
41// Wrapper class for that uses libdisplay-info to parse edids
42class LibdisplayEdidWrapper final : public EdidWrapper {
43 public:
44 LibdisplayEdidWrapper() = delete;
45 LibdisplayEdidWrapper(di_info *info) : info_(info) {
46 }
47 ~LibdisplayEdidWrapper() override {
48 di_info_destroy(info_);
49 }
50 static auto Create(DrmModePropertyBlobUnique blob)
51 -> std::unique_ptr<LibdisplayEdidWrapper> {
52 if (!blob)
53 return nullptr;
54
55 auto *info = di_info_parse_edid(blob->data, blob->length);
56 if (!info) {
57 ALOGW("Failed to parse edid blob.");
58 return nullptr;
59 }
60
61 return std::make_unique<LibdisplayEdidWrapper>(std::move(info));
62 }
63
64 private:
65 di_info *info_{};
66};
67#endif
68
69} // namespace android