Skip to content

Commit 11f5312

Browse files
committed
Add Atomic path
1 parent cd9e3f9 commit 11f5312

File tree

3 files changed

+68
-7
lines changed

3 files changed

+68
-7
lines changed

video/out/drm_common.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,14 @@ struct kms *kms_create(struct mp_log *log, const char *connector_spec,
291291
goto err;
292292
}
293293

294+
if (drmSetClientCap(kms->fd, DRM_CLIENT_CAP_ATOMIC, 1)) {
295+
mp_info(log, "No DRM atomic support found\n");
296+
}
297+
else {
298+
mp_info(log, "DRM atomic support found\n");
299+
kms->hasAtomic = 1;
300+
}
301+
294302
if (!setup_connector(kms, res, connector_name))
295303
goto err;
296304
if (!setup_crtc(kms, res, plane_res, layer_id))
@@ -410,7 +418,34 @@ int drm_validate_connector_opt(struct mp_log *log, const struct m_option *opt,
410418
return 1;
411419
}
412420

421+
int drm_add_plane_property(const struct kms *kms, drmModeAtomicReq *req, uint32_t plane_id,
422+
const char *name, uint64_t value)
423+
{
424+
drmModeObjectPropertiesPtr props;
425+
drmModePropertyPtr prop_info;
426+
int ret;
427+
428+
props = drmModeObjectGetProperties(kms->fd, plane_id, DRM_MODE_OBJECT_PLANE);
429+
if (props) {
430+
for (int i = 0; i < props->count_props; i++) {
431+
prop_info = drmModeGetProperty(kms->fd, props->props[i]);
432+
if (prop_info) {
433+
if (strcmp(prop_info->name, name) == 0) {
434+
ret = drmModeAtomicAddProperty(req, plane_id, prop_info->prop_id, value);
435+
drmModeFreeProperty(prop_info);
436+
drmModeFreeObjectProperties(props);
437+
return ret;
438+
}
439+
drmModeFreeProperty(prop_info);
440+
}
441+
}
442+
drmModeFreeObjectProperties(props);
443+
}
444+
else
445+
MP_ERR(kms,"Failed to get object properties for plane %d\n", plane_id);
413446

447+
return -1;
448+
}
414449

415450
// VT switcher ----------------------------------------------------------------
416451

video/out/drm_common.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ struct kms {
3232
uint32_t crtc_id;
3333
uint32_t plane_id;
3434
int card_no;
35+
int hasAtomic;
3536
};
3637

3738
struct vt_switcher {
@@ -63,5 +64,7 @@ void kms_show_available_cards_and_connectors(struct mp_log *log);
6364

6465
int drm_validate_connector_opt(struct mp_log *log, const struct m_option *opt,
6566
struct bstr name, struct bstr param);
67+
int drm_add_plane_property(const struct kms *kms, drmModeAtomicReq *req, uint32_t plane_id,
68+
const char *name, uint64_t value);
6669

6770
#endif

video/out/opengl/hwdec_drmprime_drm.c

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,36 @@ static int overlay_frame(struct ra_hwdec *hw, struct mp_image *hw_image,
182182
goto err;
183183
}
184184

185-
ret = drmModeSetPlane(p->kms->fd, p->kms->plane_id, p->kms->crtc_id, next_frame.fb_id, 0,
186-
MP_ALIGN_DOWN(p->dst.x0, 2), MP_ALIGN_DOWN(p->dst.y0, 2), dstw, dsth,
187-
p->src.x0 << 16, p->src.y0 << 16 , srcw << 16, srch << 16);
188-
if (ret < 0) {
189-
MP_ERR(hw, "Failed to set the plane %d (buffer %d).\n", p->kms->plane_id,
190-
next_frame.fb_id);
191-
goto err;
185+
if (p->kms->hasAtomic) {
186+
drmModeAtomicReq *req = drmModeAtomicAlloc();
187+
188+
if (req) {
189+
drm_add_plane_property(p->kms, req, p->kms->plane_id, "FB_ID", next_frame.fb_id);
190+
drm_add_plane_property(p->kms, req, p->kms->plane_id, "CRTC_ID", p->kms->crtc_id);
191+
drm_add_plane_property(p->kms, req, p->kms->plane_id, "SRC_X", p->src.x0 << 16);
192+
drm_add_plane_property(p->kms, req, p->kms->plane_id, "SRC_Y", p->src.y0 << 16);
193+
drm_add_plane_property(p->kms, req, p->kms->plane_id, "SRC_W", srcw << 16);
194+
drm_add_plane_property(p->kms, req, p->kms->plane_id, "SRC_H", srch << 16);
195+
drm_add_plane_property(p->kms, req, p->kms->plane_id, "CRTC_X", MP_ALIGN_DOWN(p->dst.x0, 2));
196+
drm_add_plane_property(p->kms, req, p->kms->plane_id, "CRTC_Y", MP_ALIGN_DOWN(p->dst.y0, 2));
197+
drm_add_plane_property(p->kms, req, p->kms->plane_id, "CRTC_W", dstw);
198+
drm_add_plane_property(p->kms, req, p->kms->plane_id, "CRTC_H", dsth);
199+
200+
ret = drmModeAtomicCommit(p->kms->fd, req, DRM_MODE_ATOMIC_NONBLOCK, NULL);
201+
if (ret)
202+
MP_ERR(hw, "Atomic commit failed with error code %d.\n", ret);
203+
} else
204+
MP_ERR(hw, "Failed to create Atomic request\n");
205+
206+
} else {
207+
ret = drmModeSetPlane(p->kms->fd, p->kms->plane_id, p->kms->crtc_id, next_frame.fb_id, 0,
208+
MP_ALIGN_DOWN(p->dst.x0, 2), MP_ALIGN_DOWN(p->dst.y0, 2), dstw, dsth,
209+
p->src.x0 << 16, p->src.y0 << 16 , srcw << 16, srch << 16);
210+
if (ret < 0) {
211+
MP_ERR(hw, "Failed to set the plane %d (buffer %d).\n", p->kms->plane_id,
212+
next_frame.fb_id);
213+
goto err;
214+
}
192215
}
193216

194217
next_frame.image = hw_image;

0 commit comments

Comments
 (0)