Line | Branch | Exec | Source |
---|---|---|---|
1 | #include <errno.h> | ||
2 | #include <stdlib.h> | ||
3 | #include <string.h> | ||
4 | #include <unistd.h> | ||
5 | #include "log.h" | ||
6 | #include "private.h" | ||
7 | |||
8 | struct liftoff_device * | ||
9 | 57 | liftoff_device_create(int drm_fd) | |
10 | { | ||
11 | struct liftoff_device *device; | ||
12 | drmModeRes *drm_res; | ||
13 | drmModePlaneRes *drm_plane_res; | ||
14 | |||
15 | 57 | device = calloc(1, sizeof(*device)); | |
16 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 57 times.
|
57 | if (device == NULL) { |
17 | ✗ | liftoff_log_errno(LIFTOFF_ERROR, "calloc"); | |
18 | ✗ | return NULL; | |
19 | } | ||
20 | |||
21 | 57 | liftoff_list_init(&device->planes); | |
22 | 57 | liftoff_list_init(&device->outputs); | |
23 | |||
24 | 57 | device->drm_fd = dup(drm_fd); | |
25 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 57 times.
|
57 | if (device->drm_fd < 0) { |
26 | ✗ | liftoff_log_errno(LIFTOFF_ERROR, "dup"); | |
27 | ✗ | liftoff_device_destroy(device); | |
28 | ✗ | return NULL; | |
29 | } | ||
30 | |||
31 | 57 | drm_res = drmModeGetResources(drm_fd); | |
32 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 57 times.
|
57 | if (drm_res == NULL) { |
33 | ✗ | liftoff_log_errno(LIFTOFF_ERROR, "drmModeGetResources"); | |
34 | ✗ | liftoff_device_destroy(device); | |
35 | ✗ | return NULL; | |
36 | } | ||
37 | |||
38 | 57 | device->crtcs_len = (size_t)drm_res->count_crtcs; | |
39 | 57 | device->crtcs = malloc(device->crtcs_len * sizeof(device->crtcs[0])); | |
40 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 57 times.
|
57 | if (device->crtcs == NULL) { |
41 | ✗ | liftoff_log_errno(LIFTOFF_ERROR, "malloc"); | |
42 | ✗ | drmModeFreeResources(drm_res); | |
43 | ✗ | liftoff_device_destroy(device); | |
44 | ✗ | return NULL; | |
45 | } | ||
46 | 57 | memcpy(device->crtcs, drm_res->crtcs, device->crtcs_len * sizeof(device->crtcs[0])); | |
47 | |||
48 | 57 | drmModeFreeResources(drm_res); | |
49 | |||
50 | 57 | drm_plane_res = drmModeGetPlaneResources(device->drm_fd); | |
51 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 57 times.
|
57 | if (drm_plane_res == NULL) { |
52 | ✗ | liftoff_log_errno(LIFTOFF_ERROR, "drmModeGetPlaneResources"); | |
53 | ✗ | liftoff_device_destroy(device); | |
54 | ✗ | return NULL; | |
55 | } | ||
56 | 57 | device->planes_cap = drm_plane_res->count_planes; | |
57 | 57 | drmModeFreePlaneResources(drm_plane_res); | |
58 | |||
59 | 57 | return device; | |
60 | } | ||
61 | |||
62 | void | ||
63 | 57 | liftoff_device_destroy(struct liftoff_device *device) | |
64 | { | ||
65 | struct liftoff_plane *plane, *tmp; | ||
66 | |||
67 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 57 times.
|
57 | if (device == NULL) { |
68 | ✗ | return; | |
69 | } | ||
70 | |||
71 | 57 | close(device->drm_fd); | |
72 |
2/2✓ Branch 0 taken 148 times.
✓ Branch 1 taken 57 times.
|
205 | liftoff_list_for_each_safe(plane, tmp, &device->planes, link) { |
73 | 148 | liftoff_plane_destroy(plane); | |
74 | } | ||
75 | 57 | free(device->crtcs); | |
76 | 57 | free(device); | |
77 | } | ||
78 | |||
79 | int | ||
80 | 56 | liftoff_device_register_all_planes(struct liftoff_device *device) | |
81 | { | ||
82 | drmModePlaneRes *drm_plane_res; | ||
83 | uint32_t i; | ||
84 | |||
85 | 56 | drm_plane_res = drmModeGetPlaneResources(device->drm_fd); | |
86 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 56 times.
|
56 | if (drm_plane_res == NULL) { |
87 | ✗ | liftoff_log_errno(LIFTOFF_ERROR, "drmModeGetPlaneResources"); | |
88 | ✗ | return -errno; | |
89 | } | ||
90 | |||
91 |
2/2✓ Branch 0 taken 146 times.
✓ Branch 1 taken 56 times.
|
202 | for (i = 0; i < drm_plane_res->count_planes; i++) { |
92 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 146 times.
|
146 | if (liftoff_plane_create(device, drm_plane_res->planes[i]) == NULL) { |
93 | ✗ | return -errno; | |
94 | } | ||
95 | } | ||
96 | 56 | drmModeFreePlaneResources(drm_plane_res); | |
97 | |||
98 | 56 | return 0; | |
99 | } | ||
100 | |||
101 | int | ||
102 | 1543 | device_test_commit(struct liftoff_device *device, drmModeAtomicReq *req, | |
103 | uint32_t flags) | ||
104 | { | ||
105 | int ret; | ||
106 | |||
107 | 1543 | device->test_commit_counter++; | |
108 | |||
109 | 1543 | flags &= ~(uint32_t)DRM_MODE_PAGE_FLIP_EVENT; | |
110 | do { | ||
111 | 1543 | ret = drmModeAtomicCommit(device->drm_fd, req, | |
112 | DRM_MODE_ATOMIC_TEST_ONLY | flags, | ||
113 | NULL); | ||
114 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 1543 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1543 times.
|
1543 | } while (ret == -EINTR || ret == -EAGAIN); |
115 | |||
116 | /* The kernel will return -EINVAL for invalid configuration, -ERANGE for | ||
117 | * CRTC coords overflow, and -ENOSPC for invalid SRC coords. */ | ||
118 |
3/8✓ Branch 0 taken 238 times.
✓ Branch 1 taken 1305 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 238 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
1543 | if (ret != 0 && ret != -EINVAL && ret != -ERANGE && ret != -ENOSPC) { |
119 | ✗ | liftoff_log(LIFTOFF_ERROR, "drmModeAtomicCommit: %s", | |
120 | strerror(-ret)); | ||
121 | } | ||
122 | |||
123 | 1543 | return ret; | |
124 | } | ||
125 | |||
126 | ssize_t | ||
127 | 5573 | core_property_index(const char *name) | |
128 | { | ||
129 |
2/2✓ Branch 0 taken 1636 times.
✓ Branch 1 taken 3937 times.
|
5573 | if (strcmp(name, "FB_ID") == 0) { |
130 | 1636 | return LIFTOFF_PROP_FB_ID; | |
131 |
2/2✓ Branch 0 taken 148 times.
✓ Branch 1 taken 3789 times.
|
3937 | } else if (strcmp(name, "CRTC_ID") == 0) { |
132 | 148 | return LIFTOFF_PROP_CRTC_ID; | |
133 |
2/2✓ Branch 0 taken 426 times.
✓ Branch 1 taken 3363 times.
|
3789 | } else if (strcmp(name, "CRTC_X") == 0) { |
134 | 426 | return LIFTOFF_PROP_CRTC_X; | |
135 |
2/2✓ Branch 0 taken 425 times.
✓ Branch 1 taken 2938 times.
|
3363 | } else if (strcmp(name, "CRTC_Y") == 0) { |
136 | 425 | return LIFTOFF_PROP_CRTC_Y; | |
137 |
2/2✓ Branch 0 taken 424 times.
✓ Branch 1 taken 2514 times.
|
2938 | } else if (strcmp(name, "CRTC_W") == 0) { |
138 | 424 | return LIFTOFF_PROP_CRTC_W; | |
139 |
2/2✓ Branch 0 taken 424 times.
✓ Branch 1 taken 2090 times.
|
2514 | } else if (strcmp(name, "CRTC_H") == 0) { |
140 | 424 | return LIFTOFF_PROP_CRTC_H; | |
141 |
2/2✓ Branch 0 taken 424 times.
✓ Branch 1 taken 1666 times.
|
2090 | } else if (strcmp(name, "SRC_X") == 0) { |
142 | 424 | return LIFTOFF_PROP_SRC_X; | |
143 |
2/2✓ Branch 0 taken 424 times.
✓ Branch 1 taken 1242 times.
|
1666 | } else if (strcmp(name, "SRC_Y") == 0) { |
144 | 424 | return LIFTOFF_PROP_SRC_Y; | |
145 |
2/2✓ Branch 0 taken 424 times.
✓ Branch 1 taken 818 times.
|
1242 | } else if (strcmp(name, "SRC_W") == 0) { |
146 | 424 | return LIFTOFF_PROP_SRC_W; | |
147 |
2/2✓ Branch 0 taken 424 times.
✓ Branch 1 taken 394 times.
|
818 | } else if (strcmp(name, "SRC_H") == 0) { |
148 | 424 | return LIFTOFF_PROP_SRC_H; | |
149 |
2/2✓ Branch 0 taken 130 times.
✓ Branch 1 taken 264 times.
|
394 | } else if (strcmp(name, "zpos") == 0) { |
150 | 130 | return LIFTOFF_PROP_ZPOS; | |
151 |
2/2✓ Branch 0 taken 48 times.
✓ Branch 1 taken 216 times.
|
264 | } else if (strcmp(name, "alpha") == 0) { |
152 | 48 | return LIFTOFF_PROP_ALPHA; | |
153 |
2/2✓ Branch 0 taken 9 times.
✓ Branch 1 taken 207 times.
|
216 | } else if (strcmp(name, "rotation") == 0) { |
154 | 9 | return LIFTOFF_PROP_ROTATION; | |
155 | } | ||
156 | 207 | return -1; | |
157 | } | ||
158 |