17
17
#include <xf86drmMode.h>
18
18
19
19
#include "pixel_format.h"
20
- #include "util/macros.h"
21
20
#include "util/bitset.h"
22
21
#include "util/list.h"
22
+ #include "util/macros.h"
23
23
24
24
FILE_DESCR ("modesetting" )
25
25
@@ -487,11 +487,7 @@ static int free_crtcs(struct drm_crtc *crtcs, size_t n_crtcs) {
487
487
return 0 ;
488
488
}
489
489
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 ) {
495
491
struct drm_format_modifier_blob * blob ;
496
492
struct drm_format_modifier * modifiers ;
497
493
uint32_t * formats ;
@@ -527,77 +523,34 @@ void drm_plane_foreach_modified_format(
527
523
}
528
524
}
529
525
530
- exit :
526
+ exit :
531
527
return ;
532
528
}
533
529
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
-
576
530
struct _drmModeFB2 ;
577
531
578
532
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 */
589
543
};
590
544
591
545
#ifdef HAVE_FUNC_ATTRIBUTE_WEAK
592
546
extern struct _drmModeFB2 * drmModeGetFB2 (int fd , uint32_t bufferId ) __attribute__((weak ));
593
547
extern void drmModeFreeFB2 (struct _drmModeFB2 * ptr ) __attribute__((weak ));
594
- #define HAVE_WEAK_DRM_MODE_GET_FB2
548
+ #define HAVE_WEAK_DRM_MODE_GET_FB2
595
549
#endif
596
550
597
551
static int fetch_plane (int drm_fd , uint32_t plane_id , struct drm_plane * plane_out ) {
598
552
struct drm_plane_prop_ids ids ;
599
553
drmModeObjectProperties * props ;
600
- struct modified_format * supported_modified_formats ;
601
554
drm_plane_transform_t hardcoded_rotation , supported_rotations , committed_rotation ;
602
555
enum drm_blend_mode committed_blend_mode ;
603
556
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
609
562
int64_t min_zpos , max_zpos , hardcoded_zpos , committed_zpos ;
610
563
bool supported_blend_modes [kCount_DrmBlendMode ] = { 0 };
611
564
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 ;
614
567
615
568
drm_plane_prop_ids_init (& ids );
616
569
@@ -628,24 +581,24 @@ static int fetch_plane(int drm_fd, uint32_t plane_id, struct drm_plane *plane_ou
628
581
goto fail_free_plane ;
629
582
}
630
583
584
+ // zero-initialize plane_out.
585
+ memset (plane_out , 0 , sizeof (* plane_out ));
586
+
631
587
has_type = false;
632
588
has_rotation = false;
633
589
has_hardcoded_rotation = false;
634
590
has_zpos = false;
635
591
has_hardcoded_zpos = false;
636
- supports_modifiers = false;
637
592
has_alpha = false;
638
593
has_blend_mode = false;
639
- n_supported_modified_formats = 0 ;
640
- supported_modified_formats = NULL ;
641
594
comitted_crtc_x = comitted_crtc_y = comitted_crtc_w = comitted_crtc_h = 0 ;
642
595
comitted_src_x = comitted_src_y = comitted_src_w = comitted_src_h = 0 ;
643
596
for (int j = 0 ; j < props -> count_props ; j ++ ) {
644
597
info = drmModeGetProperty (drm_fd , props -> props [j ]);
645
598
if (info == NULL ) {
646
599
ok = errno ;
647
600
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 ;
649
602
}
650
603
651
604
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
738
691
}
739
692
740
693
plane_out -> supports_modifiers = true;
741
- plane_out -> n_supported_modified_formats = 0 ;
742
694
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 );
769
696
770
697
drmModeFreePropertyBlob (blob );
771
698
} 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
849
776
}
850
777
}
851
778
852
- drmModeFreeFB2 ((struct _drmModeFB2 * ) fb );
779
+ drmModeFreeFB2 ((struct _drmModeFB2 * ) fb );
853
780
}
854
781
}
855
782
#endif
@@ -868,9 +795,6 @@ static int fetch_plane(int drm_fd, uint32_t plane_id, struct drm_plane *plane_ou
868
795
plane_out -> has_hardcoded_rotation = has_hardcoded_rotation ;
869
796
plane_out -> hardcoded_rotation = hardcoded_rotation ;
870
797
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;
874
798
plane_out -> has_alpha = has_alpha ;
875
799
plane_out -> has_blend_mode = has_blend_mode ;
876
800
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
894
818
drmModeFreePlane (plane );
895
819
return 0 ;
896
820
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 );
900
824
901
825
fail_free_props :
902
826
drmModeFreeObjectProperties (props );
@@ -1543,15 +1467,7 @@ uint32_t drmdev_add_fb_multiplanar(
1543
1467
1544
1468
drmdev_lock (drmdev );
1545
1469
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 );
1555
1471
1556
1472
drmdev_unlock (drmdev );
1557
1473
@@ -1644,15 +1560,7 @@ uint32_t drmdev_add_fb_from_dmabuf(
1644
1560
1645
1561
drmdev_lock (drmdev );
1646
1562
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 );
1656
1564
1657
1565
drmdev_unlock (drmdev );
1658
1566
@@ -1952,7 +1860,8 @@ drmModeModeInfo *__next_mode(const struct drm_connector *connector, const drmMod
1952
1860
#define LOG_DRM_PLANE_ALLOCATION_DEBUG (...)
1953
1861
#endif
1954
1862
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 ) {
1956
1865
struct {
1957
1866
enum pixfmt format ;
1958
1867
uint64_t modifier ;
@@ -2022,7 +1931,7 @@ static bool plane_qualifies(
2022
1931
};
2023
1932
2024
1933
// 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 );
2026
1935
2027
1936
// Otherwise fail.
2028
1937
if (!context .found ) {
@@ -2662,7 +2571,7 @@ kms_req_commit_common(struct kms_req *req, bool blocking, kms_scanout_cb_t scano
2662
2571
drmModeFreeFB (committed_fb );
2663
2572
#endif
2664
2573
}
2665
-
2574
+
2666
2575
/// TODO: Handle {src,dst}_{x,y,w,h} here
2667
2576
/// TODO: Handle setting other properties as well
2668
2577
if (needs_set_crtc ) {
@@ -2789,7 +2698,7 @@ kms_req_commit_common(struct kms_req *req, bool blocking, kms_scanout_cb_t scano
2789
2698
2790
2699
// update struct drm_connector.committed_state
2791
2700
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;
2793
2702
2794
2703
drmdev_set_scanout_callback_locked (builder -> drmdev , builder -> crtc -> id , scanout_cb , userdata , destroy_cb );
2795
2704
0 commit comments