Skip to content

Commit 599d5d6

Browse files
committed
modesetting: rename method
- `drm_plane_foreach_modified_format ==> drm_plane_for_each_modified_format` - remove drm_plane.n_supported_modified_formats - fix some old modified formats initialization - update docs for supported_modified_formats_blob window: fix check for plane explicit modifier support
1 parent 55d0db5 commit 599d5d6

File tree

3 files changed

+43
-135
lines changed

3 files changed

+43
-135
lines changed

src/modesetting.c

Lines changed: 32 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
#include <xf86drmMode.h>
1818

1919
#include "pixel_format.h"
20-
#include "util/macros.h"
2120
#include "util/bitset.h"
2221
#include "util/list.h"
22+
#include "util/macros.h"
2323

2424
FILE_DESCR("modesetting")
2525

@@ -487,11 +487,7 @@ static int free_crtcs(struct drm_crtc *crtcs, size_t n_crtcs) {
487487
return 0;
488488
}
489489

490-
void drm_plane_foreach_modified_format(
491-
struct drm_plane *plane,
492-
drm_plane_modified_format_callback_t callback,
493-
void *userdata
494-
) {
490+
void drm_plane_for_each_modified_format(struct drm_plane *plane, drm_plane_modified_format_callback_t callback, void *userdata) {
495491
struct drm_format_modifier_blob *blob;
496492
struct drm_format_modifier *modifiers;
497493
uint32_t *formats;
@@ -527,77 +523,34 @@ void drm_plane_foreach_modified_format(
527523
}
528524
}
529525

530-
exit:
526+
exit:
531527
return;
532528
}
533529

534-
static int get_supported_modified_formats(
535-
struct drm_format_modifier_blob *blob,
536-
int max_formats_out,
537-
int *n_formats_out,
538-
struct modified_format *formats_out
539-
) {
540-
struct drm_format_modifier *modifiers;
541-
uint32_t *formats;
542-
543-
ASSERT_NOT_NULL(blob);
544-
ASSERT_NOT_NULL(n_formats_out);
545-
assert(blob->version == FORMAT_BLOB_CURRENT);
546-
547-
modifiers = (void *) (((char *) blob) + blob->modifiers_offset);
548-
formats = (void *) (((char *) blob) + blob->formats_offset);
549-
550-
int index = 0;
551-
for (int i = 0; i < blob->count_modifiers; i++) {
552-
for (int j = modifiers[i].offset; (j < blob->count_formats) && (j < modifiers[i].offset + 64); j++) {
553-
bool is_format_bit_set = (modifiers[i].formats & (1ull << (j % 64))) != 0;
554-
if (!is_format_bit_set) {
555-
continue;
556-
}
557-
558-
for (int k = 0; k < kCount_PixFmt; k++) {
559-
if (get_pixfmt_info(k)->drm_format == formats[j]) {
560-
if ((index >= max_formats_out) && formats_out) {
561-
return ENOMEM;
562-
} else if (formats_out) {
563-
formats_out[index].format = k;
564-
formats_out[index].modifier = modifiers[i].modifier;
565-
}
566-
index++;
567-
}
568-
}
569-
}
570-
}
571-
572-
*n_formats_out = index;
573-
return 0;
574-
}
575-
576530
struct _drmModeFB2;
577531

578532
struct drm_mode_fb2 {
579-
uint32_t fb_id;
580-
uint32_t width, height;
581-
uint32_t pixel_format; /* fourcc code from drm_fourcc.h */
582-
uint64_t modifier; /* applies to all buffers */
583-
uint32_t flags;
584-
585-
/* per-plane GEM handle; may be duplicate entries for multiple planes */
586-
uint32_t handles[4];
587-
uint32_t pitches[4]; /* bytes */
588-
uint32_t offsets[4]; /* bytes */
533+
uint32_t fb_id;
534+
uint32_t width, height;
535+
uint32_t pixel_format; /* fourcc code from drm_fourcc.h */
536+
uint64_t modifier; /* applies to all buffers */
537+
uint32_t flags;
538+
539+
/* per-plane GEM handle; may be duplicate entries for multiple planes */
540+
uint32_t handles[4];
541+
uint32_t pitches[4]; /* bytes */
542+
uint32_t offsets[4]; /* bytes */
589543
};
590544

591545
#ifdef HAVE_FUNC_ATTRIBUTE_WEAK
592546
extern struct _drmModeFB2 *drmModeGetFB2(int fd, uint32_t bufferId) __attribute__((weak));
593547
extern void drmModeFreeFB2(struct _drmModeFB2 *ptr) __attribute__((weak));
594-
#define HAVE_WEAK_DRM_MODE_GET_FB2
548+
#define HAVE_WEAK_DRM_MODE_GET_FB2
595549
#endif
596550

597551
static int fetch_plane(int drm_fd, uint32_t plane_id, struct drm_plane *plane_out) {
598552
struct drm_plane_prop_ids ids;
599553
drmModeObjectProperties *props;
600-
struct modified_format *supported_modified_formats;
601554
drm_plane_transform_t hardcoded_rotation, supported_rotations, committed_rotation;
602555
enum drm_blend_mode committed_blend_mode;
603556
enum drm_plane_type type;
@@ -609,8 +562,8 @@ static int fetch_plane(int drm_fd, uint32_t plane_id, struct drm_plane *plane_ou
609562
int64_t min_zpos, max_zpos, hardcoded_zpos, committed_zpos;
610563
bool supported_blend_modes[kCount_DrmBlendMode] = { 0 };
611564
bool supported_formats[kCount_PixFmt] = { 0 };
612-
bool has_type, has_rotation, has_zpos, has_hardcoded_zpos, has_hardcoded_rotation, supports_modifiers, has_alpha, has_blend_mode;
613-
int ok, n_supported_modified_formats;
565+
bool has_type, has_rotation, has_zpos, has_hardcoded_zpos, has_hardcoded_rotation, has_alpha, has_blend_mode;
566+
int ok;
614567

615568
drm_plane_prop_ids_init(&ids);
616569

@@ -628,24 +581,24 @@ static int fetch_plane(int drm_fd, uint32_t plane_id, struct drm_plane *plane_ou
628581
goto fail_free_plane;
629582
}
630583

584+
// zero-initialize plane_out.
585+
memset(plane_out, 0, sizeof(*plane_out));
586+
631587
has_type = false;
632588
has_rotation = false;
633589
has_hardcoded_rotation = false;
634590
has_zpos = false;
635591
has_hardcoded_zpos = false;
636-
supports_modifiers = false;
637592
has_alpha = false;
638593
has_blend_mode = false;
639-
n_supported_modified_formats = 0;
640-
supported_modified_formats = NULL;
641594
comitted_crtc_x = comitted_crtc_y = comitted_crtc_w = comitted_crtc_h = 0;
642595
comitted_src_x = comitted_src_y = comitted_src_w = comitted_src_h = 0;
643596
for (int j = 0; j < props->count_props; j++) {
644597
info = drmModeGetProperty(drm_fd, props->props[j]);
645598
if (info == NULL) {
646599
ok = errno;
647600
perror("[modesetting] Could not get DRM device planes' properties' info. drmModeGetProperty");
648-
goto fail_maybe_free_supported_formats;
601+
goto fail_maybe_free_supported_modified_formats_blob;
649602
}
650603

651604
if (streq(info->name, "type")) {
@@ -738,34 +691,8 @@ static int fetch_plane(int drm_fd, uint32_t plane_id, struct drm_plane *plane_ou
738691
}
739692

740693
plane_out->supports_modifiers = true;
741-
plane_out->n_supported_modified_formats = 0;
742694
plane_out->supported_modified_formats_blob = memdup(blob->data, blob->length);
743-
744-
supports_modifiers = true;
745-
n_supported_modified_formats = 0;
746-
747-
get_supported_modified_formats(blob->data, 0, &n_supported_modified_formats, NULL);
748-
749-
supported_modified_formats = calloc(sizeof *supported_modified_formats, n_supported_modified_formats);
750-
if (supported_modified_formats == NULL) {
751-
ok = ENOMEM;
752-
drmModeFreePropertyBlob(blob);
753-
drmModeFreeProperty(info);
754-
goto fail_free_props;
755-
}
756-
757-
ok = get_supported_modified_formats(
758-
blob->data,
759-
n_supported_modified_formats,
760-
&n_supported_modified_formats,
761-
supported_modified_formats
762-
);
763-
if (ok != 0) {
764-
free(supported_modified_formats);
765-
drmModeFreePropertyBlob(blob);
766-
drmModeFreeProperty(info);
767-
goto fail_free_props;
768-
}
695+
ASSERT_NOT_NULL(plane_out->supported_modified_formats_blob);
769696

770697
drmModeFreePropertyBlob(blob);
771698
} else if (streq(info->name, "alpha")) {
@@ -849,7 +776,7 @@ static int fetch_plane(int drm_fd, uint32_t plane_id, struct drm_plane *plane_ou
849776
}
850777
}
851778

852-
drmModeFreeFB2((struct _drmModeFB2*) fb);
779+
drmModeFreeFB2((struct _drmModeFB2 *) fb);
853780
}
854781
}
855782
#endif
@@ -868,9 +795,6 @@ static int fetch_plane(int drm_fd, uint32_t plane_id, struct drm_plane *plane_ou
868795
plane_out->has_hardcoded_rotation = has_hardcoded_rotation;
869796
plane_out->hardcoded_rotation = hardcoded_rotation;
870797
memcpy(plane_out->supported_formats, supported_formats, sizeof supported_formats);
871-
plane_out->supports_modifiers = supports_modifiers;
872-
plane_out->n_supported_modified_formats = n_supported_modified_formats;
873-
// plane_out->supported_modified_formats = supported_modified_formats;
874798
plane_out->has_alpha = has_alpha;
875799
plane_out->has_blend_mode = has_blend_mode;
876800
memcpy(plane_out->supported_blend_modes, supported_blend_modes, sizeof supported_blend_modes);
@@ -894,9 +818,9 @@ static int fetch_plane(int drm_fd, uint32_t plane_id, struct drm_plane *plane_ou
894818
drmModeFreePlane(plane);
895819
return 0;
896820

897-
fail_maybe_free_supported_formats:
898-
if (supported_modified_formats != NULL)
899-
free(supported_modified_formats);
821+
fail_maybe_free_supported_modified_formats_blob:
822+
if (plane_out->supported_modified_formats_blob != NULL)
823+
free(plane_out->supported_modified_formats_blob);
900824

901825
fail_free_props:
902826
drmModeFreeObjectProperties(props);
@@ -1543,15 +1467,7 @@ uint32_t drmdev_add_fb_multiplanar(
15431467

15441468
drmdev_lock(drmdev);
15451469

1546-
fb = drmdev_add_fb_multiplanar_locked(
1547-
drmdev,
1548-
width, height,
1549-
pixel_format,
1550-
bo_handles,
1551-
pitches,
1552-
offsets,
1553-
has_modifiers, modifiers
1554-
);
1470+
fb = drmdev_add_fb_multiplanar_locked(drmdev, width, height, pixel_format, bo_handles, pitches, offsets, has_modifiers, modifiers);
15551471

15561472
drmdev_unlock(drmdev);
15571473

@@ -1644,15 +1560,7 @@ uint32_t drmdev_add_fb_from_dmabuf(
16441560

16451561
drmdev_lock(drmdev);
16461562

1647-
fb = drmdev_add_fb_from_dmabuf_locked(
1648-
drmdev,
1649-
width, height,
1650-
pixel_format,
1651-
prime_fd,
1652-
pitch,
1653-
offset,
1654-
has_modifier, modifier
1655-
);
1563+
fb = drmdev_add_fb_from_dmabuf_locked(drmdev, width, height, pixel_format, prime_fd, pitch, offset, has_modifier, modifier);
16561564

16571565
drmdev_unlock(drmdev);
16581566

@@ -1952,7 +1860,8 @@ drmModeModeInfo *__next_mode(const struct drm_connector *connector, const drmMod
19521860
#define LOG_DRM_PLANE_ALLOCATION_DEBUG(...)
19531861
#endif
19541862

1955-
static bool check_modified_format_supported(UNUSED struct drm_plane *plane, UNUSED int index, enum pixfmt format, uint64_t modifier, void *userdata) {
1863+
static bool
1864+
check_modified_format_supported(UNUSED struct drm_plane *plane, UNUSED int index, enum pixfmt format, uint64_t modifier, void *userdata) {
19561865
struct {
19571866
enum pixfmt format;
19581867
uint64_t modifier;
@@ -2022,7 +1931,7 @@ static bool plane_qualifies(
20221931
};
20231932

20241933
// Check if the requested format & modifier is supported.
2025-
drm_plane_foreach_modified_format(plane, check_modified_format_supported, &context);
1934+
drm_plane_for_each_modified_format(plane, check_modified_format_supported, &context);
20261935

20271936
// Otherwise fail.
20281937
if (!context.found) {
@@ -2662,7 +2571,7 @@ kms_req_commit_common(struct kms_req *req, bool blocking, kms_scanout_cb_t scano
26622571
drmModeFreeFB(committed_fb);
26632572
#endif
26642573
}
2665-
2574+
26662575
/// TODO: Handle {src,dst}_{x,y,w,h} here
26672576
/// TODO: Handle setting other properties as well
26682577
if (needs_set_crtc) {
@@ -2789,7 +2698,7 @@ kms_req_commit_common(struct kms_req *req, bool blocking, kms_scanout_cb_t scano
27892698

27902699
// update struct drm_connector.committed_state
27912700
builder->connector->committed_state.crtc_id = builder->crtc->id;
2792-
// builder->connector->committed_state.encoder_id = 0;
2701+
// builder->connector->committed_state.encoder_id = 0;
27932702

27942703
drmdev_set_scanout_callback_locked(builder->drmdev, builder->crtc->id, scanout_cb, userdata, destroy_cb);
27952704

src/modesetting.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -486,16 +486,15 @@ struct drm_plane {
486486
/// supports scanning out buffers with explicit format modifiers.
487487
bool supports_modifiers;
488488

489-
/// @brief The number of entries in the @ref supported_format_modifier_pairs
490-
/// array below.
491-
int n_supported_modified_formats;
492-
493489
/// @brief A pair of pixel format / modifier that is definitely supported.
494490
///
495491
/// DRM_FORMAT_MOD_LINEAR is supported for most (but not all pixel formats).
496492
/// There are some format & modifier pairs that may be faster to scanout by the GPU.
497493
///
498494
/// Is NULL if the plane didn't specify an IN_FORMATS property.
495+
///
496+
/// Use @ref drm_plane_for_each_modified_format to iterate over the supported modified
497+
/// formats.
499498
struct drm_format_modifier_blob *supported_modified_formats_blob;
500499

501500
/// @brief Whether this plane has a mutable alpha property we can set.
@@ -576,16 +575,16 @@ struct drm_plane {
576575

577576
/**
578577
* @brief Callback that will be called on each iteration of
579-
* @ref drm_plane_foreach_modified_format.
578+
* @ref drm_plane_for_each_modified_format.
580579
*
581580
* Should return true if looping should continue. False if iterating should be
582581
* stopped.
583582
*
584-
* @param plane The plane that was passed to @ref drm_plane_foreach_modified_format.
583+
* @param plane The plane that was passed to @ref drm_plane_for_each_modified_format.
585584
* @param index The index of the pixel format. Is incremented for each call of the callback.
586585
* @param pixel_format The pixel format.
587586
* @param modifier The modifier of this pixel format.
588-
* @param userdata Userdata that was passed to @ref drm_plane_foreach_modified_format.
587+
* @param userdata Userdata that was passed to @ref drm_plane_for_each_modified_format.
589588
*/
590589
typedef bool (*drm_plane_modified_format_callback_t)(
591590
struct drm_plane *plane,
@@ -600,7 +599,7 @@ typedef bool (*drm_plane_modified_format_callback_t)(
600599
*
601600
* See @ref drm_plane_modified_format_callback_t for documentation on the callback.
602601
*/
603-
void drm_plane_foreach_modified_format(struct drm_plane *plane, drm_plane_modified_format_callback_t callback, void *userdata);
602+
void drm_plane_for_each_modified_format(struct drm_plane *plane, drm_plane_modified_format_callback_t callback, void *userdata);
604603

605604
struct drmdev;
606605
struct _drmModeModeInfo;

src/window.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,11 +1356,11 @@ static struct render_surface *kms_window_get_render_surface_internal(struct wind
13561356
continue;
13571357
}
13581358

1359-
if (plane->supports_modifiers == NULL) {
1359+
if (!plane->supports_modifiers) {
13601360
// The plane does not have an IN_FORMATS property and does not support
13611361
// explicit modifiers.
13621362
//
1363-
// Calling drm_plane_foreach_modified_format below will segfault.
1363+
// Calling drm_plane_for_each_modified_format below will segfault.
13641364
continue;
13651365
}
13661366

@@ -1377,14 +1377,14 @@ static struct render_surface *kms_window_get_render_surface_internal(struct wind
13771377
};
13781378

13791379
// First, count the allowed modifiers for this pixel format.
1380-
drm_plane_foreach_modified_format(plane, count_modifiers_for_pixel_format, &context);
1380+
drm_plane_for_each_modified_format(plane, count_modifiers_for_pixel_format, &context);
13811381

13821382
n_allowed_modifiers = context.n_modifiers;
13831383
allowed_modifiers = calloc(n_allowed_modifiers, sizeof(*context.modifiers));
13841384
context.modifiers = allowed_modifiers;
13851385

13861386
// Next, fill context.modifiers with the allowed modifiers.
1387-
drm_plane_foreach_modified_format(plane, extract_modifiers_for_pixel_format, &context);
1387+
drm_plane_for_each_modified_format(plane, extract_modifiers_for_pixel_format, &context);
13881388
break;
13891389
}
13901390
}

0 commit comments

Comments
 (0)