1 /*
2  * Copyright 2022 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 #include <android-base/logging.h>
20 #include <android-base/unique_fd.h>
21 #include <xf86drm.h>
22 #include <xf86drmMode.h>
23 
24 #include <cstdint>
25 #include <memory>
26 
27 #include "Common.h"
28 
29 namespace aidl::android::hardware::graphics::composer3::impl {
30 
31 class DrmMode {
32    public:
33     static std::unique_ptr<DrmMode> create(::android::base::borrowed_fd drmFd,
34                                            const drmModeModeInfo& info);
35 
36     ~DrmMode();
37 
38     const uint32_t clock;
39     const uint16_t hdisplay;
40     const uint16_t hsync_start;
41     const uint16_t hsync_end;
42     const uint16_t htotal;
43     const uint16_t hskew;
44     const uint16_t vdisplay;
45     const uint16_t vsync_start;
46     const uint16_t vsync_end;
47     const uint16_t vtotal;
48     const uint16_t vscan;
49     const uint32_t vrefresh;
50     const uint32_t flags;
51     const uint32_t type;
52     const std::string name;
53 
getBlobId()54     uint32_t getBlobId() const { return mBlobId; }
55 
56    private:
DrmMode(const drmModeModeInfo & info,uint32_t blobId)57     DrmMode(const drmModeModeInfo& info, uint32_t blobId)
58         : clock(info.clock),
59           hdisplay(info.hdisplay),
60           hsync_start(info.hsync_start),
61           hsync_end(info.hsync_end),
62           htotal(info.htotal),
63           hskew(info.hskew),
64           vdisplay(info.vdisplay),
65           vsync_start(info.vsync_start),
66           vsync_end(info.vsync_end),
67           vtotal(info.vtotal),
68           vscan(info.vscan),
69           vrefresh(info.vrefresh),
70           flags(info.flags),
71           type(info.type),
72           name(info.name),
73           mBlobId(blobId) {}
74 
75     const uint32_t mBlobId;
76 };
77 
78 }  // namespace aidl::android::hardware::graphics::composer3::impl
79