Skip to content

Commit af8c8d6

Browse files
committed
fix: don't assume 0x0000..0xFFFF as KMS plane alpha range
xilinx drivers don't follow this convention and use a smaller range (0..255).
1 parent 55c8161 commit af8c8d6

File tree

2 files changed

+34
-24
lines changed

2 files changed

+34
-24
lines changed

src/modesetting.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -757,11 +757,16 @@ static int fetch_plane(int drm_fd, uint32_t plane_id, struct drm_plane *plane_ou
757757
} else if (streq(info->name, "alpha")) {
758758
has_alpha = true;
759759
assert(info->flags == DRM_MODE_PROP_RANGE);
760-
assert(info->values[0] == 0);
761-
assert(info->values[1] == 0xFFFF);
762-
assert(props->prop_values[j] <= 0xFFFF);
763-
764-
committed_alpha = (uint16_t) props->prop_values[j];
760+
assert(info->values[0] <= 0xFFFF);
761+
assert(info->values[1] <= 0xFFFF);
762+
assert(info->values[0] <= info->values[1]);
763+
plane_out->min_alpha = (uint16_t) info->values[0];
764+
plane_out->max_alpha = (uint16_t) info->values[1];
765+
766+
uint64_t value = props->prop_values[j];
767+
assert(plane_out->min_alpha <= value);
768+
assert(value <= plane_out->max_alpha);
769+
committed_alpha = (uint16_t) value;
765770
} else if (streq(info->name, "pixel blend mode")) {
766771
has_blend_mode = true;
767772
assert(info->flags == DRM_MODE_PROP_ENUM);
@@ -2568,7 +2573,7 @@ int kms_req_builder_push_fb_layer(
25682573

25692574
if (index == 0) {
25702575
if (plane->has_alpha) {
2571-
drmModeAtomicAddProperty(builder->req, plane_id, plane->ids.alpha, DRM_BLEND_ALPHA_OPAQUE);
2576+
drmModeAtomicAddProperty(builder->req, plane_id, plane->ids.alpha, plane->max_alpha);
25722577
}
25732578

25742579
if (plane->has_blend_mode && plane->supported_blend_modes[kNone_DrmBlendMode]) {

src/modesetting.h

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,6 @@
215215

216216
#define DECLARE_PROP_ID_AS_UINT32(prop_name, prop_var_name) uint32_t prop_var_name;
217217

218-
#define DRM_BLEND_ALPHA_OPAQUE 0xFFFF
219-
220218
enum drm_blend_mode {
221219
kPremultiplied_DrmBlendMode,
222220
kCoverage_DrmBlendMode,
@@ -502,6 +500,13 @@ struct drm_plane {
502500
/// @brief Whether this plane has a mutable alpha property we can set.
503501
bool has_alpha;
504502

503+
/// @brief The minimum and maximum alpha values.
504+
///
505+
/// Only valid if @ref has_alpha is true.
506+
///
507+
/// This should be 0x0000..0xFFFF, but the xilinx driver uses different values.
508+
uint16_t min_alpha, max_alpha;
509+
505510
/// @brief Whether this plane has a mutable pixel blend mode we can set.
506511
bool has_blend_mode;
507512

@@ -750,15 +755,15 @@ DECLARE_REF_OPS(kms_req_builder);
750755

751756
/**
752757
* @brief Gets the @ref drmdev associated with this KMS request builder.
753-
*
758+
*
754759
* @param builder The KMS request builder.
755760
* @returns The drmdev associated with this KMS request builder.
756761
*/
757762
struct drmdev *kms_req_builder_get_drmdev(struct kms_req_builder *builder);
758763

759764
/**
760765
* @brief Gets the CRTC associated with this KMS request builder.
761-
*
766+
*
762767
* @param builder The KMS request builder.
763768
* @returns The CRTC associated with this KMS request builder.
764769
*/
@@ -768,7 +773,7 @@ struct drm_crtc *kms_req_builder_get_crtc(struct kms_req_builder *builder);
768773
* @brief Adds a property to the KMS request that will set the given video mode
769774
* on this CRTC on commit, regardless of whether the currently committed output
770775
* mode is the same.
771-
*
776+
*
772777
* @param builder The KMS request builder.
773778
* @param mode The output mode to set (on @ref kms_req_commit)
774779
* @returns Zero if successful, positive errno-style error on failure.
@@ -779,7 +784,7 @@ int kms_req_builder_set_mode(struct kms_req_builder *builder, const drmModeModeI
779784
* @brief Adds a property to the KMS request that will unset the configured
780785
* output mode for this CRTC on commit, regardless of whether the currently
781786
* committed output mdoe is already unset.
782-
*
787+
*
783788
* @param builder The KMS request builder.
784789
* @returns Zero if successful, positive errno-style error on failure.
785790
*/
@@ -788,7 +793,7 @@ int kms_req_builder_unset_mode(struct kms_req_builder *builder);
788793
/**
789794
* @brief Adds a property to the KMS request that will change the connector
790795
* that this CRTC is displaying content on to @param connector_id.
791-
*
796+
*
792797
* @param builder The KMS request builder.
793798
* @param connector_id The connector that this CRTC should display contents on.
794799
* @returns Zero if successful, EINVAL if the @param connector_id is invalid.
@@ -799,11 +804,11 @@ int kms_req_builder_set_connector(struct kms_req_builder *builder, uint32_t conn
799804
* @brief True if the next layer pushed using @ref kms_req_builder_push_fb_layer
800805
* should be opaque, i.e. use a framebuffer which has a pixel format that has no
801806
* alpha channel.
802-
*
807+
*
803808
* This is true for the bottom-most layer. There are some display controllers
804809
* that don't support non-opaque pixel formats for the bottom-most (primary)
805810
* plane. So ignoring this might lead to an EINVAL on commit.
806-
*
811+
*
807812
* @param builder The KMS request builder.
808813
* @returns True if the next layer should preferably be opaque, false if there's
809814
* no preference.
@@ -812,30 +817,30 @@ bool kms_req_builder_prefer_next_layer_opaque(struct kms_req_builder *builder);
812817

813818
/**
814819
* @brief Adds a new framebuffer (display) layer on top of the last layer.
815-
*
820+
*
816821
* If this is the first layer, the framebuffer should cover the entire screen
817822
* (CRTC).
818-
*
823+
*
819824
* To allow the use of explicit fencing, specify an in_fence_fd in @param layer
820825
* and a @param deferred_release_callback.
821-
*
826+
*
822827
* If explicit fencing is supported:
823828
* - the in_fence_fd should be a DRM syncobj fd that signals
824829
* when the GPU has finished rendering to the framebuffer and is ready
825830
* to be scanned out.
826831
* - @param deferred_release_callback will be called
827832
* with a DRM syncobj fd that is signaled once the framebuffer is no longer
828833
* being displayed on screen (and can be rendered into again)
829-
*
834+
*
830835
* If explicit fencing is not supported:
831836
* - the in_fence_fd in @param layer will be closed by this procedure.
832837
* - @param deferred_release_callback will NOT be called and
833838
* @param release_callback will be called instead.
834-
*
839+
*
835840
* Explicit fencing is supported: When atomic modesetting is being used and
836841
* the driver supports it. (Driver has IN_FENCE_FD plane and OUT_FENCE_PTR crtc
837842
* properties)
838-
*
843+
*
839844
* @param builder The KMS request builder.
840845
* @param layer The exact details (src pos, output pos, rotation,
841846
* framebuffer) of the layer that should be shown on
@@ -878,7 +883,7 @@ int kms_req_builder_push_fb_layer(
878883
/**
879884
* @brief Push a "fake" layer that just keeps one zpos free, incase something
880885
* other than KMS wants to display contents there. (e.g. omxplayer)
881-
*
886+
*
882887
* @param builder The KMS request builder.
883888
* @param zpos_out Filled with the zpos that won't be occupied by the request
884889
* builder.
@@ -889,7 +894,7 @@ int kms_req_builder_push_zpos_placeholder_layer(struct kms_req_builder *builder,
889894
/**
890895
* @brief A KMS request (atomic or legacy modesetting) that can be committed to
891896
* change the state of a single CRTC.
892-
*
897+
*
893898
* Only way to construct this is by building a KMS request using
894899
* @ref kms_req_builder and then calling @ref kms_req_builder_build.
895900
*/
@@ -900,7 +905,7 @@ DECLARE_REF_OPS(kms_req);
900905
/**
901906
* @brief Build the KMS request builder into an actual, immutable KMS request
902907
* that can be committed. Internally this doesn't do much at all.
903-
*
908+
*
904909
* @param builder The KMS request builder that should be built.
905910
* @returns KMS request that can be committed using @ref kms_req_commit_blocking
906911
* or @ref kms_req_commit_nonblocking.

0 commit comments

Comments
 (0)