1 /*
2 * Copyright (C) 2015 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 "hwc-drm-crtc"
18
19 #include "DrmCrtc.h"
20
21 #include <utils/log.h>
22 #include <xf86drmMode.h>
23
24 #include <cstdint>
25
26 #include "DrmDevice.h"
27
28 namespace android {
29
GetCrtcProperty(const DrmDevice & dev,const DrmCrtc & crtc,const char * prop_name,DrmProperty * property)30 static int GetCrtcProperty(const DrmDevice &dev, const DrmCrtc &crtc,
31 const char *prop_name, DrmProperty *property) {
32 return dev.GetProperty(crtc.GetId(), DRM_MODE_OBJECT_CRTC, prop_name,
33 property);
34 }
35
CreateInstance(DrmDevice & dev,uint32_t crtc_id,uint32_t index)36 auto DrmCrtc::CreateInstance(DrmDevice &dev, uint32_t crtc_id, uint32_t index)
37 -> std::unique_ptr<DrmCrtc> {
38 auto crtc = MakeDrmModeCrtcUnique(dev.GetFd(), crtc_id);
39 if (!crtc) {
40 ALOGE("Failed to get CRTC %d", crtc_id);
41 return {};
42 }
43
44 auto c = std::unique_ptr<DrmCrtc>(new DrmCrtc(std::move(crtc), index));
45
46 int ret = GetCrtcProperty(dev, *c, "ACTIVE", &c->active_property_);
47 if (ret != 0) {
48 ALOGE("Failed to get ACTIVE property");
49 return {};
50 }
51
52 ret = GetCrtcProperty(dev, *c, "MODE_ID", &c->mode_property_);
53 if (ret != 0) {
54 ALOGE("Failed to get MODE_ID property");
55 return {};
56 }
57
58 ret = GetCrtcProperty(dev, *c, "OUT_FENCE_PTR", &c->out_fence_ptr_property_);
59 if (ret != 0) {
60 ALOGE("Failed to get OUT_FENCE_PTR property");
61 return {};
62 }
63
64 return c;
65 }
66
67 } // namespace android
68