1*0a9764feSAndroid Build Coastguard Worker /*
2*0a9764feSAndroid Build Coastguard Worker * Copyright (C) 2015 The Android Open Source Project
3*0a9764feSAndroid Build Coastguard Worker *
4*0a9764feSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
5*0a9764feSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
6*0a9764feSAndroid Build Coastguard Worker * You may obtain a copy of the License at
7*0a9764feSAndroid Build Coastguard Worker *
8*0a9764feSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0
9*0a9764feSAndroid Build Coastguard Worker *
10*0a9764feSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
11*0a9764feSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
12*0a9764feSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*0a9764feSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
14*0a9764feSAndroid Build Coastguard Worker * limitations under the License.
15*0a9764feSAndroid Build Coastguard Worker */
16*0a9764feSAndroid Build Coastguard Worker
17*0a9764feSAndroid Build Coastguard Worker #define LOG_TAG "drmhwc"
18*0a9764feSAndroid Build Coastguard Worker
19*0a9764feSAndroid Build Coastguard Worker #include "DrmCrtc.h"
20*0a9764feSAndroid Build Coastguard Worker
21*0a9764feSAndroid Build Coastguard Worker #include <utils/log.h>
22*0a9764feSAndroid Build Coastguard Worker #include <xf86drmMode.h>
23*0a9764feSAndroid Build Coastguard Worker
24*0a9764feSAndroid Build Coastguard Worker #include <cstdint>
25*0a9764feSAndroid Build Coastguard Worker
26*0a9764feSAndroid Build Coastguard Worker #include "DrmDevice.h"
27*0a9764feSAndroid Build Coastguard Worker
28*0a9764feSAndroid Build Coastguard Worker namespace android {
29*0a9764feSAndroid Build Coastguard Worker
GetCrtcProperty(const DrmDevice & dev,const DrmCrtc & crtc,const char * prop_name,DrmProperty * property)30*0a9764feSAndroid Build Coastguard Worker static int GetCrtcProperty(const DrmDevice &dev, const DrmCrtc &crtc,
31*0a9764feSAndroid Build Coastguard Worker const char *prop_name, DrmProperty *property) {
32*0a9764feSAndroid Build Coastguard Worker return dev.GetProperty(crtc.GetId(), DRM_MODE_OBJECT_CRTC, prop_name,
33*0a9764feSAndroid Build Coastguard Worker property);
34*0a9764feSAndroid Build Coastguard Worker }
35*0a9764feSAndroid Build Coastguard Worker
CreateInstance(DrmDevice & dev,uint32_t crtc_id,uint32_t index)36*0a9764feSAndroid Build Coastguard Worker auto DrmCrtc::CreateInstance(DrmDevice &dev, uint32_t crtc_id, uint32_t index)
37*0a9764feSAndroid Build Coastguard Worker -> std::unique_ptr<DrmCrtc> {
38*0a9764feSAndroid Build Coastguard Worker auto crtc = MakeDrmModeCrtcUnique(*dev.GetFd(), crtc_id);
39*0a9764feSAndroid Build Coastguard Worker if (!crtc) {
40*0a9764feSAndroid Build Coastguard Worker ALOGE("Failed to get CRTC %d", crtc_id);
41*0a9764feSAndroid Build Coastguard Worker return {};
42*0a9764feSAndroid Build Coastguard Worker }
43*0a9764feSAndroid Build Coastguard Worker
44*0a9764feSAndroid Build Coastguard Worker auto c = std::unique_ptr<DrmCrtc>(new DrmCrtc(std::move(crtc), index));
45*0a9764feSAndroid Build Coastguard Worker
46*0a9764feSAndroid Build Coastguard Worker int ret = GetCrtcProperty(dev, *c, "ACTIVE", &c->active_property_);
47*0a9764feSAndroid Build Coastguard Worker if (ret != 0) {
48*0a9764feSAndroid Build Coastguard Worker ALOGE("Failed to get ACTIVE property");
49*0a9764feSAndroid Build Coastguard Worker return {};
50*0a9764feSAndroid Build Coastguard Worker }
51*0a9764feSAndroid Build Coastguard Worker
52*0a9764feSAndroid Build Coastguard Worker ret = GetCrtcProperty(dev, *c, "MODE_ID", &c->mode_property_);
53*0a9764feSAndroid Build Coastguard Worker if (ret != 0) {
54*0a9764feSAndroid Build Coastguard Worker ALOGE("Failed to get MODE_ID property");
55*0a9764feSAndroid Build Coastguard Worker return {};
56*0a9764feSAndroid Build Coastguard Worker }
57*0a9764feSAndroid Build Coastguard Worker
58*0a9764feSAndroid Build Coastguard Worker ret = GetCrtcProperty(dev, *c, "OUT_FENCE_PTR", &c->out_fence_ptr_property_);
59*0a9764feSAndroid Build Coastguard Worker if (ret != 0) {
60*0a9764feSAndroid Build Coastguard Worker ALOGE("Failed to get OUT_FENCE_PTR property");
61*0a9764feSAndroid Build Coastguard Worker return {};
62*0a9764feSAndroid Build Coastguard Worker }
63*0a9764feSAndroid Build Coastguard Worker
64*0a9764feSAndroid Build Coastguard Worker ret = GetCrtcProperty(dev, *c, "CTM", &c->ctm_property_);
65*0a9764feSAndroid Build Coastguard Worker if (ret != 0) {
66*0a9764feSAndroid Build Coastguard Worker ALOGV("Missing optional CTM property");
67*0a9764feSAndroid Build Coastguard Worker }
68*0a9764feSAndroid Build Coastguard Worker
69*0a9764feSAndroid Build Coastguard Worker return c;
70*0a9764feSAndroid Build Coastguard Worker }
71*0a9764feSAndroid Build Coastguard Worker
72*0a9764feSAndroid Build Coastguard Worker } // namespace android
73