2017-10-23 15:51:49 +00:00
|
|
|
/*
|
|
|
|
* This file is part of mpv.
|
|
|
|
*
|
|
|
|
* mpv is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* mpv is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
|
|
|
|
#include "common/common.h"
|
|
|
|
#include "common/msg.h"
|
|
|
|
#include "drm_atomic.h"
|
|
|
|
|
|
|
|
int drm_object_create_properties(struct mp_log *log, int fd,
|
|
|
|
struct drm_object *object)
|
|
|
|
{
|
|
|
|
object->props = drmModeObjectGetProperties(fd, object->id, object->type);
|
|
|
|
if (object->props) {
|
|
|
|
object->props_info = talloc_zero_size(NULL, object->props->count_props
|
|
|
|
* sizeof(object->props_info));
|
|
|
|
if (object->props_info) {
|
|
|
|
for (int i = 0; i < object->props->count_props; i++)
|
|
|
|
object->props_info[i] = drmModeGetProperty(fd, object->props->props[i]);
|
|
|
|
} else {
|
|
|
|
mp_err(log, "Out of memory\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mp_err(log, "Failed to retrieve properties for object id %d\n", object->id);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
drm_object_free_properties(object);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void drm_object_free_properties(struct drm_object *object)
|
|
|
|
{
|
|
|
|
if (object->props) {
|
|
|
|
for (int i = 0; i < object->props->count_props; i++) {
|
|
|
|
if (object->props_info[i]) {
|
|
|
|
drmModeFreeProperty(object->props_info[i]);
|
|
|
|
object->props_info[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
talloc_free(object->props_info);
|
|
|
|
object->props_info = NULL;
|
|
|
|
|
|
|
|
drmModeFreeObjectProperties(object->props);
|
|
|
|
object->props = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int drm_object_get_property(struct drm_object *object, char *name, uint64_t *value)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < object->props->count_props; i++) {
|
|
|
|
if (strcasecmp(name, object->props_info[i]->name) == 0) {
|
|
|
|
*value = object->props->prop_values[i];
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2018-03-17 07:21:56 +00:00
|
|
|
drmModePropertyBlobPtr drm_object_get_property_blob(struct drm_object *object, char *name)
|
|
|
|
{
|
|
|
|
uint64_t blob_id;
|
|
|
|
|
|
|
|
if (!drm_object_get_property(object, name, &blob_id)) {
|
|
|
|
return drmModeGetPropertyBlob(object->fd, blob_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-10-23 15:51:49 +00:00
|
|
|
int drm_object_set_property(drmModeAtomicReq *request, struct drm_object *object,
|
|
|
|
char *name, uint64_t value)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < object->props->count_props; i++) {
|
|
|
|
if (strcasecmp(name, object->props_info[i]->name) == 0) {
|
2020-02-02 15:27:54 +00:00
|
|
|
if (object->props_info[i]->flags & DRM_MODE_PROP_IMMUTABLE) {
|
|
|
|
/* Do not try to set immutable values, as this might cause the
|
|
|
|
* atomic commit operation to fail. */
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2017-10-23 15:51:49 +00:00
|
|
|
return drmModeAtomicAddProperty(request, object->id,
|
|
|
|
object->props_info[i]->prop_id, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct drm_object * drm_object_create(struct mp_log *log, int fd,
|
|
|
|
uint32_t object_id, uint32_t type)
|
|
|
|
{
|
|
|
|
struct drm_object *obj = NULL;
|
|
|
|
obj = talloc_zero(NULL, struct drm_object);
|
|
|
|
obj->id = object_id;
|
|
|
|
obj->type = type;
|
2018-03-17 07:21:56 +00:00
|
|
|
obj->fd = fd;
|
2017-10-23 15:51:49 +00:00
|
|
|
|
|
|
|
if (drm_object_create_properties(log, fd, obj)) {
|
|
|
|
talloc_free(obj);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
void drm_object_free(struct drm_object *object)
|
|
|
|
{
|
|
|
|
if (object) {
|
|
|
|
drm_object_free_properties(object);
|
|
|
|
talloc_free(object);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void drm_object_print_info(struct mp_log *log, struct drm_object *object)
|
|
|
|
{
|
|
|
|
mp_err(log, "Object ID = %d (type = %x) has %d properties\n",
|
|
|
|
object->id, object->type, object->props->count_props);
|
|
|
|
|
|
|
|
for (int i = 0; i < object->props->count_props; i++)
|
|
|
|
mp_err(log, " Property '%s' = %lld\n", object->props_info[i]->name,
|
|
|
|
(long long)object->props->prop_values[i]);
|
|
|
|
}
|
|
|
|
|
2018-04-29 15:46:23 +00:00
|
|
|
struct drm_atomic_context *drm_atomic_create_context(struct mp_log *log, int fd, int crtc_id,
|
2018-06-02 10:54:05 +00:00
|
|
|
int connector_id,
|
2018-12-01 11:01:17 +00:00
|
|
|
int draw_plane_idx, int drmprime_video_plane_idx)
|
2017-10-23 15:51:49 +00:00
|
|
|
{
|
|
|
|
drmModePlaneRes *plane_res = NULL;
|
|
|
|
drmModeRes *res = NULL;
|
|
|
|
struct drm_object *plane = NULL;
|
|
|
|
struct drm_atomic_context *ctx;
|
|
|
|
int crtc_index = -1;
|
2018-04-29 15:46:23 +00:00
|
|
|
int layercount = -1;
|
|
|
|
int primary_id = 0;
|
|
|
|
int overlay_id = 0;
|
|
|
|
|
2017-10-23 15:51:49 +00:00
|
|
|
uint64_t value;
|
|
|
|
|
|
|
|
res = drmModeGetResources(fd);
|
|
|
|
if (!res) {
|
|
|
|
mp_err(log, "Cannot retrieve DRM resources: %s\n", mp_strerror(errno));
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
plane_res = drmModeGetPlaneResources(fd);
|
|
|
|
if (!plane_res) {
|
2021-08-24 22:48:27 +00:00
|
|
|
mp_err(log, "Cannot retrieve plane resources: %s\n", mp_strerror(errno));
|
2017-10-23 15:51:49 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx = talloc_zero(NULL, struct drm_atomic_context);
|
|
|
|
if (!ctx) {
|
|
|
|
mp_err(log, "Out of memory\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx->fd = fd;
|
|
|
|
ctx->crtc = drm_object_create(log, ctx->fd, crtc_id, DRM_MODE_OBJECT_CRTC);
|
|
|
|
if (!ctx->crtc) {
|
|
|
|
mp_err(log, "Failed to create CRTC object\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < res->count_crtcs; i++) {
|
|
|
|
if (res->crtcs[i] == crtc_id) {
|
|
|
|
crtc_index = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-17 07:21:56 +00:00
|
|
|
for (int i = 0; i < res->count_connectors; i++) {
|
|
|
|
drmModeConnector *connector = drmModeGetConnector(fd, res->connectors[i]);
|
|
|
|
if (connector) {
|
|
|
|
if (connector->connector_id == connector_id)
|
|
|
|
ctx->connector = drm_object_create(log, ctx->fd, connector->connector_id,
|
|
|
|
DRM_MODE_OBJECT_CONNECTOR);
|
|
|
|
|
|
|
|
drmModeFreeConnector(connector);
|
|
|
|
if (ctx->connector)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-23 15:51:49 +00:00
|
|
|
for (unsigned int j = 0; j < plane_res->count_planes; j++) {
|
|
|
|
|
2018-05-02 11:26:57 +00:00
|
|
|
drmModePlane *drmplane = drmModeGetPlane(ctx->fd, plane_res->planes[j]);
|
|
|
|
const uint32_t possible_crtcs = drmplane->possible_crtcs;
|
|
|
|
const uint32_t plane_id = drmplane->plane_id;
|
|
|
|
drmModeFreePlane(drmplane);
|
|
|
|
drmplane = NULL;
|
|
|
|
|
|
|
|
if (possible_crtcs & (1 << crtc_index)) {
|
|
|
|
plane = drm_object_create(log, ctx->fd, plane_id,
|
2017-10-23 15:51:49 +00:00
|
|
|
DRM_MODE_OBJECT_PLANE);
|
|
|
|
|
2018-05-02 11:26:57 +00:00
|
|
|
if (!plane) {
|
|
|
|
mp_err(log, "Failed to create Plane object from plane ID %d\n",
|
|
|
|
plane_id);
|
|
|
|
goto fail;
|
|
|
|
}
|
2018-04-21 13:16:54 +00:00
|
|
|
|
2018-05-02 11:26:57 +00:00
|
|
|
if (drm_object_get_property(plane, "TYPE", &value) == -EINVAL) {
|
|
|
|
mp_err(log, "Unable to retrieve type property from plane %d\n", j);
|
|
|
|
goto fail;
|
|
|
|
}
|
2018-04-29 15:46:23 +00:00
|
|
|
|
2018-05-02 11:26:57 +00:00
|
|
|
if (value != DRM_PLANE_TYPE_CURSOR) { // Skip cursor planes
|
|
|
|
layercount++;
|
2018-04-29 15:46:23 +00:00
|
|
|
|
2018-05-02 11:26:57 +00:00
|
|
|
if ((!primary_id) && (value == DRM_PLANE_TYPE_PRIMARY))
|
|
|
|
primary_id = plane_id;
|
2018-04-29 15:46:23 +00:00
|
|
|
|
2018-05-02 11:26:57 +00:00
|
|
|
if ((!overlay_id) && (value == DRM_PLANE_TYPE_OVERLAY))
|
|
|
|
overlay_id = plane_id;
|
2018-04-29 15:46:23 +00:00
|
|
|
|
2018-12-01 11:01:17 +00:00
|
|
|
if (layercount == draw_plane_idx) {
|
|
|
|
ctx->draw_plane = plane;
|
2018-05-02 11:26:57 +00:00
|
|
|
continue;
|
|
|
|
}
|
2017-10-23 15:51:49 +00:00
|
|
|
|
2018-12-01 11:01:17 +00:00
|
|
|
if (layercount == drmprime_video_plane_idx) {
|
|
|
|
ctx->drmprime_video_plane = plane;
|
2018-05-02 11:26:57 +00:00
|
|
|
continue;
|
2017-10-23 15:51:49 +00:00
|
|
|
}
|
|
|
|
}
|
2018-05-02 11:26:57 +00:00
|
|
|
|
|
|
|
drm_object_free(plane);
|
|
|
|
plane = NULL;
|
2017-10-23 15:51:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-01 11:01:17 +00:00
|
|
|
// draw plane was specified as either of the special options: any primary plane or any overlay plane
|
|
|
|
if (!ctx->draw_plane) {
|
|
|
|
const int draw_plane_id = (draw_plane_idx == DRM_OPTS_OVERLAY_PLANE) ? overlay_id : primary_id;
|
|
|
|
const char *plane_type = (draw_plane_idx == DRM_OPTS_OVERLAY_PLANE) ? "overlay" : "primary";
|
|
|
|
if (draw_plane_id) {
|
|
|
|
mp_verbose(log, "Using %s plane %d as draw plane\n", plane_type, draw_plane_id);
|
|
|
|
ctx->draw_plane = drm_object_create(log, ctx->fd, draw_plane_id, DRM_MODE_OBJECT_PLANE);
|
2018-04-29 15:46:23 +00:00
|
|
|
} else {
|
2018-12-01 11:01:17 +00:00
|
|
|
mp_err(log, "Failed to find draw plane with idx=%d\n", draw_plane_idx);
|
2018-04-29 15:46:23 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
} else {
|
2018-12-01 11:01:17 +00:00
|
|
|
mp_verbose(log, "Found draw plane with ID %d\n", ctx->draw_plane->id);
|
2017-10-23 15:51:49 +00:00
|
|
|
}
|
|
|
|
|
2018-12-01 11:01:17 +00:00
|
|
|
// drmprime plane was specified as either of the special options: any primary plane or any overlay plane
|
|
|
|
if (!ctx->drmprime_video_plane) {
|
|
|
|
const int drmprime_video_plane_id = (drmprime_video_plane_idx == DRM_OPTS_PRIMARY_PLANE) ? primary_id : overlay_id;
|
|
|
|
const char *plane_type = (drmprime_video_plane_idx == DRM_OPTS_PRIMARY_PLANE) ? "primary" : "overlay";
|
2018-06-02 10:54:05 +00:00
|
|
|
|
2018-12-01 11:01:17 +00:00
|
|
|
if (drmprime_video_plane_id) {
|
|
|
|
mp_verbose(log, "Using %s plane %d as drmprime plane\n", plane_type, drmprime_video_plane_id);
|
|
|
|
ctx->drmprime_video_plane = drm_object_create(log, ctx->fd, drmprime_video_plane_id, DRM_MODE_OBJECT_PLANE);
|
2018-04-29 15:46:23 +00:00
|
|
|
} else {
|
2018-12-01 11:01:17 +00:00
|
|
|
mp_verbose(log, "Failed to find drmprime plane with idx=%d. drmprime-drm hwdec interop will not work\n", drmprime_video_plane_idx);
|
2018-04-29 15:46:23 +00:00
|
|
|
}
|
|
|
|
} else {
|
2018-12-01 11:01:17 +00:00
|
|
|
mp_verbose(log, "Found drmprime plane with ID %d\n", ctx->drmprime_video_plane->id);
|
2017-10-23 15:51:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
drmModeFreePlaneResources(plane_res);
|
|
|
|
drmModeFreeResources(res);
|
|
|
|
return ctx;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
if (res)
|
|
|
|
drmModeFreeResources(res);
|
|
|
|
if (plane_res)
|
|
|
|
drmModeFreePlaneResources(plane_res);
|
|
|
|
if (plane)
|
|
|
|
drm_object_free(plane);
|
2017-11-05 23:30:48 +00:00
|
|
|
return NULL;
|
2017-10-23 15:51:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void drm_atomic_destroy_context(struct drm_atomic_context *ctx)
|
|
|
|
{
|
2018-06-02 10:53:54 +00:00
|
|
|
drm_mode_destroy_blob(ctx->fd, &ctx->old_state.crtc.mode);
|
2017-10-23 15:51:49 +00:00
|
|
|
drm_object_free(ctx->crtc);
|
2018-03-17 07:21:56 +00:00
|
|
|
drm_object_free(ctx->connector);
|
2018-12-01 11:01:17 +00:00
|
|
|
drm_object_free(ctx->draw_plane);
|
|
|
|
drm_object_free(ctx->drmprime_video_plane);
|
2017-10-23 15:51:49 +00:00
|
|
|
talloc_free(ctx);
|
|
|
|
}
|
2018-06-02 10:53:54 +00:00
|
|
|
|
|
|
|
static bool drm_atomic_save_plane_state(struct drm_object *plane,
|
|
|
|
struct drm_atomic_plane_state *plane_state)
|
|
|
|
{
|
2018-07-01 07:12:52 +00:00
|
|
|
if (!plane)
|
|
|
|
return true;
|
|
|
|
|
2018-06-02 10:53:54 +00:00
|
|
|
bool ret = true;
|
|
|
|
|
|
|
|
if (0 > drm_object_get_property(plane, "FB_ID", &plane_state->fb_id))
|
|
|
|
ret = false;
|
|
|
|
if (0 > drm_object_get_property(plane, "CRTC_ID", &plane_state->crtc_id))
|
|
|
|
ret = false;
|
|
|
|
if (0 > drm_object_get_property(plane, "SRC_X", &plane_state->src_x))
|
|
|
|
ret = false;
|
|
|
|
if (0 > drm_object_get_property(plane, "SRC_Y", &plane_state->src_y))
|
|
|
|
ret = false;
|
|
|
|
if (0 > drm_object_get_property(plane, "SRC_W", &plane_state->src_w))
|
|
|
|
ret = false;
|
|
|
|
if (0 > drm_object_get_property(plane, "SRC_H", &plane_state->src_h))
|
|
|
|
ret = false;
|
|
|
|
if (0 > drm_object_get_property(plane, "CRTC_X", &plane_state->crtc_x))
|
|
|
|
ret = false;
|
|
|
|
if (0 > drm_object_get_property(plane, "CRTC_Y", &plane_state->crtc_y))
|
|
|
|
ret = false;
|
|
|
|
if (0 > drm_object_get_property(plane, "CRTC_W", &plane_state->crtc_w))
|
|
|
|
ret = false;
|
|
|
|
if (0 > drm_object_get_property(plane, "CRTC_H", &plane_state->crtc_h))
|
|
|
|
ret = false;
|
|
|
|
// ZPOS might not exist, so ignore whether or not this succeeds
|
|
|
|
drm_object_get_property(plane, "ZPOS", &plane_state->zpos);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool drm_atomic_restore_plane_state(drmModeAtomicReq *request,
|
|
|
|
struct drm_object *plane,
|
|
|
|
const struct drm_atomic_plane_state *plane_state)
|
|
|
|
{
|
2018-07-01 07:12:52 +00:00
|
|
|
if (!plane)
|
|
|
|
return true;
|
|
|
|
|
2018-06-02 10:53:54 +00:00
|
|
|
bool ret = true;
|
|
|
|
|
|
|
|
if (0 > drm_object_set_property(request, plane, "FB_ID", plane_state->fb_id))
|
|
|
|
ret = false;
|
|
|
|
if (0 > drm_object_set_property(request, plane, "CRTC_ID", plane_state->crtc_id))
|
|
|
|
ret = false;
|
|
|
|
if (0 > drm_object_set_property(request, plane, "SRC_X", plane_state->src_x))
|
|
|
|
ret = false;
|
|
|
|
if (0 > drm_object_set_property(request, plane, "SRC_Y", plane_state->src_y))
|
|
|
|
ret = false;
|
|
|
|
if (0 > drm_object_set_property(request, plane, "SRC_W", plane_state->src_w))
|
|
|
|
ret = false;
|
|
|
|
if (0 > drm_object_set_property(request, plane, "SRC_H", plane_state->src_h))
|
|
|
|
ret = false;
|
|
|
|
if (0 > drm_object_set_property(request, plane, "CRTC_X", plane_state->crtc_x))
|
|
|
|
ret = false;
|
|
|
|
if (0 > drm_object_set_property(request, plane, "CRTC_Y", plane_state->crtc_y))
|
|
|
|
ret = false;
|
|
|
|
if (0 > drm_object_set_property(request, plane, "CRTC_W", plane_state->crtc_w))
|
|
|
|
ret = false;
|
|
|
|
if (0 > drm_object_set_property(request, plane, "CRTC_H", plane_state->crtc_h))
|
|
|
|
ret = false;
|
2020-02-02 15:27:54 +00:00
|
|
|
// ZPOS might not exist, or be immutable, so ignore whether or not this succeeds
|
2018-06-02 10:53:54 +00:00
|
|
|
drm_object_set_property(request, plane, "ZPOS", plane_state->zpos);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool drm_atomic_save_old_state(struct drm_atomic_context *ctx)
|
|
|
|
{
|
|
|
|
if (ctx->old_state.saved)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
bool ret = true;
|
|
|
|
|
|
|
|
drmModeCrtc *crtc = drmModeGetCrtc(ctx->fd, ctx->crtc->id);
|
|
|
|
if (crtc == NULL)
|
|
|
|
return false;
|
|
|
|
ctx->old_state.crtc.mode.mode = crtc->mode;
|
|
|
|
drmModeFreeCrtc(crtc);
|
|
|
|
|
|
|
|
if (0 > drm_object_get_property(ctx->crtc, "ACTIVE", &ctx->old_state.crtc.active))
|
|
|
|
ret = false;
|
|
|
|
|
2022-04-04 03:08:33 +00:00
|
|
|
// This property was added in kernel 5.0. We will just ignore any errors.
|
|
|
|
drm_object_get_property(ctx->crtc, "VRR_ENABLED", &ctx->old_state.crtc.vrr_enabled);
|
|
|
|
|
2018-06-02 10:53:54 +00:00
|
|
|
if (0 > drm_object_get_property(ctx->connector, "CRTC_ID", &ctx->old_state.connector.crtc_id))
|
|
|
|
ret = false;
|
|
|
|
|
2018-12-01 11:01:17 +00:00
|
|
|
if (!drm_atomic_save_plane_state(ctx->draw_plane, &ctx->old_state.draw_plane))
|
2018-06-02 10:53:54 +00:00
|
|
|
ret = false;
|
2018-12-01 11:01:17 +00:00
|
|
|
if (!drm_atomic_save_plane_state(ctx->drmprime_video_plane, &ctx->old_state.drmprime_video_plane))
|
2018-06-02 10:53:54 +00:00
|
|
|
ret = false;
|
|
|
|
|
|
|
|
ctx->old_state.saved = true;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool drm_atomic_restore_old_state(drmModeAtomicReqPtr request, struct drm_atomic_context *ctx)
|
|
|
|
{
|
|
|
|
if (!ctx->old_state.saved)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
bool ret = true;
|
|
|
|
|
|
|
|
if (0 > drm_object_set_property(request, ctx->connector, "CRTC_ID", ctx->old_state.connector.crtc_id))
|
|
|
|
ret = false;
|
|
|
|
|
2022-04-04 03:08:33 +00:00
|
|
|
// This property was added in kernel 5.0. We will just ignore any errors.
|
|
|
|
drm_object_set_property(request, ctx->crtc, "VRR_ENABLED", ctx->old_state.crtc.vrr_enabled);
|
|
|
|
|
2018-06-02 10:53:54 +00:00
|
|
|
if (!drm_mode_ensure_blob(ctx->fd, &ctx->old_state.crtc.mode))
|
|
|
|
ret = false;
|
|
|
|
if (0 > drm_object_set_property(request, ctx->crtc, "MODE_ID", ctx->old_state.crtc.mode.blob_id))
|
|
|
|
ret = false;
|
|
|
|
if (0 > drm_object_set_property(request, ctx->crtc, "ACTIVE", ctx->old_state.crtc.active))
|
|
|
|
ret = false;
|
|
|
|
|
2018-12-01 11:01:17 +00:00
|
|
|
if (!drm_atomic_restore_plane_state(request, ctx->draw_plane, &ctx->old_state.draw_plane))
|
2018-06-02 10:53:54 +00:00
|
|
|
ret = false;
|
2018-12-01 11:01:17 +00:00
|
|
|
if (!drm_atomic_restore_plane_state(request, ctx->drmprime_video_plane, &ctx->old_state.drmprime_video_plane))
|
2018-06-02 10:53:54 +00:00
|
|
|
ret = false;
|
|
|
|
|
|
|
|
ctx->old_state.saved = false;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool drm_mode_ensure_blob(int fd, struct drm_mode *mode)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (!mode->blob_id) {
|
|
|
|
ret = drmModeCreatePropertyBlob(fd, &mode->mode, sizeof(drmModeModeInfo),
|
|
|
|
&mode->blob_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (ret == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool drm_mode_destroy_blob(int fd, struct drm_mode *mode)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (mode->blob_id) {
|
|
|
|
ret = drmModeDestroyPropertyBlob(fd, mode->blob_id);
|
|
|
|
mode->blob_id = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (ret == 0);
|
|
|
|
}
|