Skip to content

Commit f0b3330

Browse files
committed
don't enforce rotation
If a device doesn't support rotation, there's really nothing we can do. So just try to apply rotation, but don't fail if it doesn't work. adds enforce_rotation property to struct kms_fb_layer, and makes egl_gbm_render_surface, vk_gbm_render_surface, dmabuf_surface specify false.
1 parent c81869e commit f0b3330

File tree

6 files changed

+111
-2
lines changed

6 files changed

+111
-2
lines changed

src/dmabuf_surface.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,8 @@ static int dmabuf_surface_present_kms(struct surface *_s, const struct fl_layer_
305305

306306
.has_rotation = false,
307307
.rotation = PLANE_TRANSFORM_ROTATE_0,
308+
.enforce_rotation = false,
309+
308310
.has_in_fence_fd = false,
309311
.in_fence_fd = 0,
310312
},

src/egl_gbm_render_surface.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,7 @@ static int egl_gbm_render_surface_present_kms(struct surface *s, const struct fl
539539
// so just use zero rotation for all planes.
540540
.has_rotation = true,
541541
.rotation = PLANE_TRANSFORM_ROTATE_0,
542+
.enforce_rotation = false,
542543

543544
.has_in_fence_fd = false,
544545
.in_fence_fd = 0,

src/modesetting.c

Lines changed: 103 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <xf86drmMode.h>
1919

2020
#include "pixel_format.h"
21+
#include "util/asserts.h"
2122
#include "util/bitset.h"
2223
#include "util/list.h"
2324
#include "util/lock_ops.h"
@@ -2450,6 +2451,24 @@ int kms_req_builder_push_fb_layer(
24502451
/* id_range */ false, 0
24512452
// clang-format on
24522453
);
2454+
2455+
// If allocation failed due to rotation and rotation is not enforced, retry without rotation
2456+
if (plane == NULL && layer->has_rotation && !layer->enforce_rotation) {
2457+
plane = allocate_plane(
2458+
// clang-format off
2459+
builder,
2460+
/* allow_primary */ false,
2461+
/* allow_overlay */ false,
2462+
/* allow_cursor */ true,
2463+
/* format */ layer->format,
2464+
/* modifier */ layer->has_modifier, layer->modifier,
2465+
/* zpos */ false, 0, 0,
2466+
/* rotation */ false, PLANE_TRANSFORM_NONE,
2467+
/* id_range */ false, 0
2468+
// clang-format on
2469+
);
2470+
}
2471+
24532472
if (plane == NULL) {
24542473
if (allocated_cursor_plane) *allocated_cursor_plane = false;
24552474
LOG_DEBUG("Couldn't find a fitting cursor plane.\n");
@@ -2494,6 +2513,39 @@ int kms_req_builder_push_fb_layer(
24942513
// clang-format on
24952514
);
24962515
}
2516+
2517+
// If allocation failed due to rotation and rotation is not enforced, retry without rotation
2518+
if (plane == NULL && layer->has_rotation && !layer->enforce_rotation) {
2519+
plane = allocate_plane(
2520+
// clang-format off
2521+
builder,
2522+
/* allow_primary */ true,
2523+
/* allow_overlay */ false,
2524+
/* allow_cursor */ false,
2525+
/* format */ layer->format,
2526+
/* modifier */ layer->has_modifier, layer->modifier,
2527+
/* zpos */ false, 0, 0,
2528+
/* rotation */ false, PLANE_TRANSFORM_NONE,
2529+
/* id_range */ false, 0
2530+
// clang-format on
2531+
);
2532+
2533+
if (plane == NULL && !get_pixfmt_info(layer->format)->is_opaque) {
2534+
plane = allocate_plane(
2535+
// clang-format off
2536+
builder,
2537+
/* allow_primary */ true,
2538+
/* allow_overlay */ false,
2539+
/* allow_cursor */ false,
2540+
/* format */ pixfmt_opaque(layer->format),
2541+
/* modifier */ layer->has_modifier, layer->modifier,
2542+
/* zpos */ false, 0, 0,
2543+
/* rotation */ false, PLANE_TRANSFORM_NONE,
2544+
/* id_range */ false, 0
2545+
// clang-format on
2546+
);
2547+
}
2548+
}
24972549
} else if (plane == NULL) {
24982550
// First try to find an overlay plane with a higher zpos.
24992551
plane = allocate_plane(
@@ -2529,6 +2581,39 @@ int kms_req_builder_push_fb_layer(
25292581
// clang-format on
25302582
);
25312583
}
2584+
2585+
// If allocation failed due to rotation and rotation is not enforced, retry without rotation
2586+
if (plane == NULL && layer->has_rotation && !layer->enforce_rotation) {
2587+
plane = allocate_plane(
2588+
// clang-format off
2589+
builder,
2590+
/* allow_primary */ false,
2591+
/* allow_overlay */ true,
2592+
/* allow_cursor */ false,
2593+
/* format */ layer->format,
2594+
/* modifier */ layer->has_modifier, layer->modifier,
2595+
/* zpos */ true, builder->next_zpos, INT64_MAX,
2596+
/* rotation */ false, PLANE_TRANSFORM_NONE,
2597+
/* id_range */ false, 0
2598+
// clang-format on
2599+
);
2600+
2601+
if (plane == NULL) {
2602+
plane = allocate_plane(
2603+
// clang-format off
2604+
builder,
2605+
/* allow_primary */ false,
2606+
/* allow_overlay */ true,
2607+
/* allow_cursor */ false,
2608+
/* format */ layer->format,
2609+
/* modifier */ layer->has_modifier, layer->modifier,
2610+
/* zpos */ false, 0, 0,
2611+
/* rotation */ false, PLANE_TRANSFORM_NONE,
2612+
/* id_range */ true, builder->layers[index - 1].plane_id + 1
2613+
// clang-format on
2614+
);
2615+
}
2616+
}
25322617
}
25332618

25342619
if (plane == NULL) {
@@ -2572,8 +2657,24 @@ int kms_req_builder_push_fb_layer(
25722657
drmModeAtomicAddProperty(builder->req, plane_id, plane->ids.zpos, zpos);
25732658
}
25742659

2575-
if (layer->has_rotation && plane->has_rotation && !plane->has_hardcoded_rotation) {
2576-
drmModeAtomicAddProperty(builder->req, plane_id, plane->ids.rotation, layer->rotation.u64);
2660+
if (layer->has_rotation) {
2661+
// Check if the plane can apply the requested rotation:
2662+
// 1. Plane must have a rotation property
2663+
// 2. If hardcoded, it must match the requested rotation
2664+
// 3. The requested rotation bits must be supported by the plane
2665+
bool can_apply_rotation = plane->has_rotation &&
2666+
(!plane->has_hardcoded_rotation || plane->hardcoded_rotation.u32 == layer->rotation.u32) &&
2667+
!(layer->rotation.u32 & ~plane->supported_rotations.u32);
2668+
2669+
if (can_apply_rotation && !plane->has_hardcoded_rotation) {
2670+
drmModeAtomicAddProperty(builder->req, plane_id, plane->ids.rotation, layer->rotation.u64);
2671+
} else if (!can_apply_rotation && layer->enforce_rotation) {
2672+
// Rotation was requested and must be enforced, but plane can't apply it
2673+
LOG_ERROR("Rotation requested with enforce_rotation=true, but plane %" PRIu32 " cannot apply it.\n", plane_id);
2674+
ok = EINVAL;
2675+
goto fail_release_plane;
2676+
}
2677+
// else: rotation requested but not enforced, or hardcoded rotation matches - silently skip setting property
25772678
}
25782679

25792680
if (index == 0) {

src/modesetting.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,7 @@ struct kms_fb_layer {
736736

737737
bool has_rotation;
738738
drm_plane_transform_t rotation;
739+
bool enforce_rotation;
739740

740741
bool has_in_fence_fd;
741742
int in_fence_fd;

src/vk_gbm_render_surface.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,7 @@ static int vk_gbm_render_surface_present_kms(struct surface *s, const struct fl_
690690
// see egl_gbm_render_surface_present_kms
691691
.has_rotation = true,
692692
.rotation = PLANE_TRANSFORM_ROTATE_0,
693+
.enforce_rotation = false,
693694

694695
.has_in_fence_fd = false,
695696
.in_fence_fd = 0,

src/window.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,8 +1203,11 @@ static int kms_window_push_composition_locked(struct window *window, struct fl_l
12031203
.dst_y = window->cursor_pos.y - window->kms.cursor->hotspot.y,
12041204
.dst_w = window->kms.cursor->width,
12051205
.dst_h = window->kms.cursor->height,
1206+
12061207
.has_rotation = true,
12071208
.rotation = PLANE_TRANSFORM_ROTATE_0,
1209+
.enforce_rotation = false,
1210+
12081211
.has_in_fence_fd = false,
12091212
.in_fence_fd = 0,
12101213
.prefer_cursor = true,

0 commit comments

Comments
 (0)