aboutsummaryrefslogtreecommitdiff
path: root/system/hwc3/DrmDisplay.h
blob: 0a349c7b5d0696fa024afe9ca9681927ea94fd15 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
 * Copyright 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include <android-base/logging.h>
#include <android-base/unique_fd.h>
#include <xf86drm.h>
#include <xf86drmMode.h>

#include <cstdint>
#include <memory>
#include <string>
#include <unordered_map>

#include "Common.h"
#include "DrmBuffer.h"
#include "DrmConnector.h"
#include "DrmCrtc.h"
#include "DrmPlane.h"

namespace aidl::android::hardware::graphics::composer3::impl {

enum class DrmHotplugChange {
    kNoChange,
    kConnected,
    kDisconnected,
};

class DrmDisplay {
   public:
    static std::unique_ptr<DrmDisplay> create(uint32_t id, std::unique_ptr<DrmConnector> connector,
                                              std::unique_ptr<DrmCrtc> crtc,
                                              std::unique_ptr<DrmPlane> plane,
                                              ::android::base::borrowed_fd drmFd);

    uint32_t getId() const { return mId; }

    uint32_t getWidth() const { return mConnector->getWidth(); }
    uint32_t getHeight() const { return mConnector->getHeight(); }

    uint32_t getDpiX() const { return mConnector->getDpiX(); }
    uint32_t getDpiY() const { return mConnector->getDpiY(); }

    uint32_t getRefreshRateUint() const { return mConnector->getRefreshRateUint(); }

    bool isConnected() const { return mConnector->isConnected(); }

    std::optional<std::vector<uint8_t>> getEdid() const { return mConnector->getEdid(); }

    std::tuple<HWC3::Error, ::android::base::unique_fd> flush(
        ::android::base::borrowed_fd drmFd, ::android::base::borrowed_fd inWaitSyncFd,
        const std::shared_ptr<DrmBuffer>& buffer);

    DrmHotplugChange checkAndHandleHotplug(::android::base::borrowed_fd drmFd);

   private:
    DrmDisplay(uint32_t id, std::unique_ptr<DrmConnector> connector, std::unique_ptr<DrmCrtc> crtc,
               std::unique_ptr<DrmPlane> plane)
        : mId(id),
          mConnector(std::move(connector)),
          mCrtc(std::move(crtc)),
          mPlane(std::move(plane)) {}

    bool onConnect(::android::base::borrowed_fd drmFd);

    bool onDisconnect(::android::base::borrowed_fd drmFd);

    const uint32_t mId;
    std::unique_ptr<DrmConnector> mConnector;
    std::unique_ptr<DrmCrtc> mCrtc;
    std::unique_ptr<DrmPlane> mPlane;

    // The last presented buffer / DRM framebuffer is cached until
    // the next present to avoid toggling the display on and off.
    std::shared_ptr<DrmBuffer> mPreviousBuffer;
};

}  // namespace aidl::android::hardware::graphics::composer3::impl