Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 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 | |
Sean Paul | 468a754 | 2024-07-16 19:50:58 +0000 | [diff] [blame] | 17 | #define LOG_TAG "drmhwc" |
Sean Paul | 877be97 | 2015-06-03 14:08:27 -0400 | [diff] [blame] | 18 | |
Roman Stratiienko | 13cc366 | 2020-08-29 21:35:39 +0300 | [diff] [blame] | 19 | #include "DrmCrtc.h" |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 20 | |
Roman Stratiienko | d518a05 | 2021-02-25 19:15:14 +0200 | [diff] [blame] | 21 | #include <utils/log.h> |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 22 | #include <xf86drmMode.h> |
| 23 | |
Roman Stratiienko | e2f2c92 | 2021-02-13 10:57:47 +0200 | [diff] [blame] | 24 | #include <cstdint> |
| 25 | |
Roman Stratiienko | 13cc366 | 2020-08-29 21:35:39 +0300 | [diff] [blame] | 26 | #include "DrmDevice.h" |
Sean Paul | 877be97 | 2015-06-03 14:08:27 -0400 | [diff] [blame] | 27 | |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 28 | namespace android { |
| 29 | |
Roman Stratiienko | 10be875 | 2022-01-30 20:28:46 +0200 | [diff] [blame] | 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); |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 34 | } |
| 35 | |
Roman Stratiienko | 10be875 | 2022-01-30 20:28:46 +0200 | [diff] [blame] | 36 | auto DrmCrtc::CreateInstance(DrmDevice &dev, uint32_t crtc_id, uint32_t index) |
| 37 | -> std::unique_ptr<DrmCrtc> { |
Roman Stratiienko | 7689278 | 2023-01-16 17:15:53 +0200 | [diff] [blame] | 38 | auto crtc = MakeDrmModeCrtcUnique(*dev.GetFd(), crtc_id); |
Roman Stratiienko | 10be875 | 2022-01-30 20:28:46 +0200 | [diff] [blame] | 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_); |
Roman Stratiienko | fc014f5 | 2021-12-23 19:04:29 +0200 | [diff] [blame] | 47 | if (ret != 0) { |
Sean Paul | 877be97 | 2015-06-03 14:08:27 -0400 | [diff] [blame] | 48 | ALOGE("Failed to get ACTIVE property"); |
Roman Stratiienko | 10be875 | 2022-01-30 20:28:46 +0200 | [diff] [blame] | 49 | return {}; |
Sean Paul | 877be97 | 2015-06-03 14:08:27 -0400 | [diff] [blame] | 50 | } |
| 51 | |
Roman Stratiienko | 10be875 | 2022-01-30 20:28:46 +0200 | [diff] [blame] | 52 | ret = GetCrtcProperty(dev, *c, "MODE_ID", &c->mode_property_); |
Roman Stratiienko | fc014f5 | 2021-12-23 19:04:29 +0200 | [diff] [blame] | 53 | if (ret != 0) { |
Sean Paul | 877be97 | 2015-06-03 14:08:27 -0400 | [diff] [blame] | 54 | ALOGE("Failed to get MODE_ID property"); |
Roman Stratiienko | 10be875 | 2022-01-30 20:28:46 +0200 | [diff] [blame] | 55 | return {}; |
Sean Paul | 877be97 | 2015-06-03 14:08:27 -0400 | [diff] [blame] | 56 | } |
Robert Foss | ca0fbba | 2016-10-20 10:14:43 -0400 | [diff] [blame] | 57 | |
Roman Stratiienko | 10be875 | 2022-01-30 20:28:46 +0200 | [diff] [blame] | 58 | ret = GetCrtcProperty(dev, *c, "OUT_FENCE_PTR", &c->out_fence_ptr_property_); |
Roman Stratiienko | fc014f5 | 2021-12-23 19:04:29 +0200 | [diff] [blame] | 59 | if (ret != 0) { |
Robert Foss | ca0fbba | 2016-10-20 10:14:43 -0400 | [diff] [blame] | 60 | ALOGE("Failed to get OUT_FENCE_PTR property"); |
Roman Stratiienko | 10be875 | 2022-01-30 20:28:46 +0200 | [diff] [blame] | 61 | return {}; |
Robert Foss | ca0fbba | 2016-10-20 10:14:43 -0400 | [diff] [blame] | 62 | } |
Roman Stratiienko | 10be875 | 2022-01-30 20:28:46 +0200 | [diff] [blame] | 63 | |
Roman Stratiienko | 0da91bf | 2023-01-17 18:06:04 +0200 | [diff] [blame] | 64 | ret = GetCrtcProperty(dev, *c, "CTM", &c->ctm_property_); |
| 65 | if (ret != 0) { |
| 66 | ALOGV("Missing optional CTM property"); |
| 67 | } |
| 68 | |
Roman Stratiienko | 10be875 | 2022-01-30 20:28:46 +0200 | [diff] [blame] | 69 | return c; |
Sean Paul | 877be97 | 2015-06-03 14:08:27 -0400 | [diff] [blame] | 70 | } |
| 71 | |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 72 | } // namespace android |