blob: 2be1eb90b9906b1fb95fd2cc30a542c848923c25 [file] [log] [blame]
Roman Stratiienko3e8ce572021-09-29 12:46:28 +03001/*
2 * Copyright (C) 2021 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
Roman Stratiienkobde95662022-12-10 20:27:58 +020017#pragma once
Roman Stratiienko3e8ce572021-09-29 12:46:28 +030018
19#include <xf86drmMode.h>
20
21#include <functional>
22#include <memory>
23
24template <typename T>
25using DUniquePtr = std::unique_ptr<T, std::function<void(T *)>>;
26
27using DrmModeAtomicReqUnique = DUniquePtr<drmModeAtomicReq>;
28auto inline MakeDrmModeAtomicReqUnique() {
29 return DrmModeAtomicReqUnique(drmModeAtomicAlloc(), [](drmModeAtomicReq *it) {
30 drmModeAtomicFree(it);
31 });
32};
33
34using DrmModeConnectorUnique = DUniquePtr<drmModeConnector>;
35auto inline MakeDrmModeConnectorUnique(int fd, uint32_t connector_id) {
36 return DrmModeConnectorUnique(drmModeGetConnector(fd, connector_id),
37 [](drmModeConnector *it) {
38 drmModeFreeConnector(it);
39 });
40}
41
42using DrmModeCrtcUnique = DUniquePtr<drmModeCrtc>;
43auto inline MakeDrmModeCrtcUnique(int fd, uint32_t crtc_id) {
44 return DrmModeCrtcUnique(drmModeGetCrtc(fd, crtc_id),
45 [](drmModeCrtc *it) { drmModeFreeCrtc(it); });
46}
47
48using DrmModeEncoderUnique = DUniquePtr<drmModeEncoder>;
49auto inline MakeDrmModeEncoderUnique(int fd, uint32_t encoder_id) {
50 return DrmModeEncoderUnique(drmModeGetEncoder(fd, encoder_id),
51 [](drmModeEncoder *it) {
52 drmModeFreeEncoder(it);
53 });
54}
55
56using DrmModePlaneUnique = DUniquePtr<drmModePlane>;
57auto inline MakeDrmModePlaneUnique(int fd, uint32_t plane_id) {
58 return DrmModePlaneUnique(drmModeGetPlane(fd, plane_id),
59 [](drmModePlane *it) { drmModeFreePlane(it); });
60}
61
62using DrmModePlaneResUnique = DUniquePtr<drmModePlaneRes>;
63auto inline MakeDrmModePlaneResUnique(int fd) {
64 return DrmModePlaneResUnique(drmModeGetPlaneResources(fd),
65 [](drmModePlaneRes *it) {
66 drmModeFreePlaneResources(it);
67 });
68}
69
Roman Stratiienko6ede4662021-09-30 10:18:28 +030070using DrmModeUserPropertyBlobUnique = DUniquePtr<uint32_t /*id*/>;
71
Roman Stratiienko3e8ce572021-09-29 12:46:28 +030072using DrmModePropertyBlobUnique = DUniquePtr<drmModePropertyBlobRes>;
73auto inline MakeDrmModePropertyBlobUnique(int fd, uint32_t blob_id) {
74 return DrmModePropertyBlobUnique(drmModeGetPropertyBlob(fd, blob_id),
75 [](drmModePropertyBlobRes *it) {
76 drmModeFreePropertyBlob(it);
77 });
78}
79
80using DrmModeResUnique = DUniquePtr<drmModeRes>;
81auto inline MakeDrmModeResUnique(int fd) {
82 return DrmModeResUnique(drmModeGetResources(fd),
83 [](drmModeRes *it) { drmModeFreeResources(it); });
84}