blob: 3b749b1078f571fe612d4ade852cf5da062d42c7 [file] [log] [blame]
Sean Paul6a55e9f2015-04-30 15:31:06 -04001/*
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
Sean Paul877be972015-06-03 14:08:27 -040017#define LOG_TAG "hwc-drm-crtc"
18
Roman Stratiienko13cc3662020-08-29 21:35:39 +030019#include "DrmCrtc.h"
Sean Paul6a55e9f2015-04-30 15:31:06 -040020
Roman Stratiienkod518a052021-02-25 19:15:14 +020021#include <utils/log.h>
Sean Paul6a55e9f2015-04-30 15:31:06 -040022#include <xf86drmMode.h>
23
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +020024#include <cstdint>
25
Roman Stratiienko13cc3662020-08-29 21:35:39 +030026#include "DrmDevice.h"
Sean Paul877be972015-06-03 14:08:27 -040027
Sean Paul6a55e9f2015-04-30 15:31:06 -040028namespace android {
29
Roman Stratiienko10be8752022-01-30 20:28:46 +020030static 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);
Sean Paul6a55e9f2015-04-30 15:31:06 -040034}
35
Roman Stratiienko10be8752022-01-30 20:28:46 +020036auto DrmCrtc::CreateInstance(DrmDevice &dev, uint32_t crtc_id, uint32_t index)
37 -> std::unique_ptr<DrmCrtc> {
Roman Stratiienko76892782023-01-16 17:15:53 +020038 auto crtc = MakeDrmModeCrtcUnique(*dev.GetFd(), crtc_id);
Roman Stratiienko10be8752022-01-30 20:28:46 +020039 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_);
Roman Stratiienkofc014f52021-12-23 19:04:29 +020047 if (ret != 0) {
Sean Paul877be972015-06-03 14:08:27 -040048 ALOGE("Failed to get ACTIVE property");
Roman Stratiienko10be8752022-01-30 20:28:46 +020049 return {};
Sean Paul877be972015-06-03 14:08:27 -040050 }
51
Roman Stratiienko10be8752022-01-30 20:28:46 +020052 ret = GetCrtcProperty(dev, *c, "MODE_ID", &c->mode_property_);
Roman Stratiienkofc014f52021-12-23 19:04:29 +020053 if (ret != 0) {
Sean Paul877be972015-06-03 14:08:27 -040054 ALOGE("Failed to get MODE_ID property");
Roman Stratiienko10be8752022-01-30 20:28:46 +020055 return {};
Sean Paul877be972015-06-03 14:08:27 -040056 }
Robert Fossca0fbba2016-10-20 10:14:43 -040057
Roman Stratiienko10be8752022-01-30 20:28:46 +020058 ret = GetCrtcProperty(dev, *c, "OUT_FENCE_PTR", &c->out_fence_ptr_property_);
Roman Stratiienkofc014f52021-12-23 19:04:29 +020059 if (ret != 0) {
Robert Fossca0fbba2016-10-20 10:14:43 -040060 ALOGE("Failed to get OUT_FENCE_PTR property");
Roman Stratiienko10be8752022-01-30 20:28:46 +020061 return {};
Robert Fossca0fbba2016-10-20 10:14:43 -040062 }
Roman Stratiienko10be8752022-01-30 20:28:46 +020063
64 return c;
Sean Paul877be972015-06-03 14:08:27 -040065}
66
Sean Paulf72cccd2018-08-27 13:59:08 -040067} // namespace android