@@ -25,6 +25,13 @@ static const struct zwp_linux_dmabuf_feedback_v1_interface linux_dmabuf_feedback
25
25
static const struct wp_viewport_interface viewport_impl ;
26
26
static const struct wp_fractional_scale_v1_interface fractional_scale_impl ;
27
27
28
+ struct forward_params {
29
+ struct zwp_linux_buffer_params_v1 * params ;
30
+ struct wl_resource * resource ;
31
+ int32_t width ;
32
+ int32_t height ;
33
+ };
34
+
28
35
static bool does_transform_transpose_size (int32_t transform ) {
29
36
switch (transform ) {
30
37
default :
@@ -49,9 +56,12 @@ static void nested_surface_destroy(struct wl_client *client,
49
56
static void nested_surface_attach (struct wl_client * client ,
50
57
struct wl_resource * resource , struct wl_resource * buffer , int32_t x , int32_t y ) {
51
58
assert (wl_resource_instance_of (resource , & wl_surface_interface , & surface_impl ));
52
- assert (wl_resource_instance_of (buffer , & wl_buffer_interface , & buffer_impl ));
53
59
struct forward_surface * surface = wl_resource_get_user_data (resource );
54
- struct forward_buffer * f_buffer = wl_resource_get_user_data (buffer );
60
+ struct forward_buffer * f_buffer = NULL ;
61
+ if (buffer ) {
62
+ assert (wl_resource_instance_of (buffer , & wl_buffer_interface , & buffer_impl ));
63
+ f_buffer = wl_resource_get_user_data (buffer );
64
+ }
55
65
56
66
if (surface -> pending .attachment == f_buffer ) {
57
67
/* no change */
@@ -719,38 +729,49 @@ static void nested_dmabuf_params_add(struct wl_client *client,
719
729
struct wl_resource * resource , int32_t fd , uint32_t plane_idx ,
720
730
uint32_t offset , uint32_t stride , uint32_t modifier_hi , uint32_t modifier_lo ) {
721
731
assert (wl_resource_instance_of (resource , & zwp_linux_buffer_params_v1_interface , & linux_dmabuf_params_impl ));
722
- struct zwp_linux_buffer_params_v1 * params = wl_resource_get_user_data (resource );
723
- zwp_linux_buffer_params_v1_add (params , fd , plane_idx , offset , stride , modifier_hi , modifier_lo );
732
+ struct forward_params * params = wl_resource_get_user_data (resource );
733
+ zwp_linux_buffer_params_v1_add (params -> params , fd , plane_idx , offset , stride , modifier_hi , modifier_lo );
724
734
}
725
735
static void nested_dmabuf_params_create (struct wl_client * client ,
726
736
struct wl_resource * resource , int32_t width , int32_t height ,
727
737
uint32_t format , uint32_t flags ) {
728
- wl_client_post_implementation_error (client , "TODO IMPLEMENT CREATE" );
738
+ assert (wl_resource_instance_of (resource , & zwp_linux_buffer_params_v1_interface , & linux_dmabuf_params_impl ));
739
+ struct forward_params * params = wl_resource_get_user_data (resource );
740
+ params -> width = width ;
741
+ params -> height = height ;
742
+ zwp_linux_buffer_params_v1_create (params -> params , width , height , format , flags );
743
+ }
744
+ static struct forward_buffer * make_buffer (int width , int height ) {
745
+ struct forward_buffer * buffer = calloc (1 , sizeof (struct forward_buffer ));
746
+ if (!buffer ) {
747
+ return NULL ;
748
+ }
749
+ wl_list_init (& buffer -> pending_surfaces );
750
+ wl_list_init (& buffer -> committed_surfaces );
751
+ buffer -> width = width ;
752
+ buffer -> height = height ;
753
+ return buffer ;
729
754
}
730
755
static void nested_dmabuf_params_create_immed (struct wl_client * client ,
731
756
struct wl_resource * resource , uint32_t buffer_id , int32_t width ,
732
757
int32_t height , uint32_t format , uint32_t flags ) {
758
+ assert (wl_resource_instance_of (resource , & zwp_linux_buffer_params_v1_interface , & linux_dmabuf_params_impl ));
733
759
struct wl_resource * buffer_resource = wl_resource_create (client , & wl_buffer_interface ,
734
760
wl_resource_get_version (resource ), buffer_id );
735
761
if (buffer_resource == NULL ) {
736
762
wl_client_post_no_memory (client );
737
763
return ;
738
764
}
739
765
740
- struct zwp_linux_buffer_params_v1 * params = wl_resource_get_user_data (resource );
766
+ struct forward_params * params = wl_resource_get_user_data (resource );
741
767
742
- struct forward_buffer * buffer = calloc ( 1 , sizeof ( struct forward_buffer ) );
768
+ struct forward_buffer * buffer = make_buffer ( width , height );
743
769
if (!buffer ) {
744
770
wl_client_post_no_memory (client );
745
771
return ;
746
772
}
747
773
buffer -> resource = buffer_resource ;
748
- wl_list_init (& buffer -> pending_surfaces );
749
- wl_list_init (& buffer -> committed_surfaces );
750
- buffer -> width = width ;
751
- buffer -> height = height ;
752
-
753
- buffer -> buffer = zwp_linux_buffer_params_v1_create_immed (params , width , height , format , flags );
774
+ buffer -> buffer = zwp_linux_buffer_params_v1_create_immed (params -> params , width , height , format , flags );
754
775
if (!buffer -> buffer ) {
755
776
wl_client_post_no_memory (client );
756
777
return ;
@@ -772,25 +793,77 @@ static const struct zwp_linux_buffer_params_v1_interface linux_dmabuf_params_imp
772
793
773
794
static void linux_dmabuf_params_handle_resource_destroy (struct wl_resource * resource ) {
774
795
assert (wl_resource_instance_of (resource , & zwp_linux_buffer_params_v1_interface , & linux_dmabuf_params_impl ));
775
- struct zwp_linux_buffer_params_v1 * params = wl_resource_get_user_data (resource );
776
- zwp_linux_buffer_params_v1_destroy (params );
796
+ struct forward_params * params = wl_resource_get_user_data (resource );
797
+ zwp_linux_buffer_params_v1_destroy (params -> params );
798
+ free (params );
777
799
}
778
800
779
801
static void nested_linux_dmabuf_destroy (struct wl_client * client ,
780
802
struct wl_resource * resource ){
781
803
wl_resource_destroy (resource );
782
804
}
805
+
806
+ void handle_dmabuf_params_created (void * data ,
807
+ struct zwp_linux_buffer_params_v1 * zwp_linux_buffer_params_v1 ,
808
+ struct wl_buffer * wl_buffer ) {
809
+ struct forward_params * params = data ;
810
+
811
+ struct wl_client * client = wl_resource_get_client (params -> resource );
812
+ struct wl_resource * buffer_resource = wl_resource_create (client , & wl_buffer_interface ,
813
+ wl_resource_get_version (params -> resource ), 0 );
814
+ if (buffer_resource == NULL ) {
815
+ wl_client_post_no_memory (client );
816
+ return ;
817
+ }
818
+
819
+ struct forward_buffer * buffer = make_buffer (params -> width , params -> height );
820
+ if (!buffer ) {
821
+ wl_client_post_no_memory (client );
822
+ return ;
823
+ }
824
+ buffer -> resource = buffer_resource ;
825
+ buffer -> buffer = wl_buffer ;
826
+ wl_resource_set_implementation (buffer_resource , & buffer_impl ,
827
+ buffer , buffer_handle_resource_destroy );
828
+ wl_buffer_add_listener (buffer -> buffer , & buffer_listener , buffer );
829
+ zwp_linux_buffer_params_v1_send_created (params -> resource , buffer_resource );
830
+ }
831
+
832
+ static void handle_dmabuf_params_failed (void * data ,
833
+ struct zwp_linux_buffer_params_v1 * zwp_linux_buffer_params_v1 ) {
834
+ struct forward_params * params = data ;
835
+ zwp_linux_buffer_params_v1_send_failed (params -> resource );
836
+ }
837
+
838
+ static const struct zwp_linux_buffer_params_v1_listener params_listener = {
839
+ .created = handle_dmabuf_params_created ,
840
+ .failed = handle_dmabuf_params_failed ,
841
+ };
842
+
783
843
static void nested_linux_dmabuf_create_params (struct wl_client * client ,
784
844
struct wl_resource * resource , uint32_t params_id ) {
785
- struct wl_resource * params_resource = wl_resource_create (client , & zwp_linux_buffer_params_v1_interface ,
845
+ struct forward_params * params = calloc (1 , sizeof (* params ));
846
+ if (!params ) {
847
+ wl_client_post_no_memory (client );
848
+ return ;
849
+ }
850
+
851
+ struct wl_resource * params_resource = wl_resource_create (client ,
852
+ & zwp_linux_buffer_params_v1_interface ,
786
853
wl_resource_get_version (resource ), params_id );
787
854
if (params_resource == NULL ) {
855
+ free (params );
788
856
wl_client_post_no_memory (client );
789
857
return ;
790
858
}
791
- struct forward_state * forward = wl_resource_get_user_data (resource );
792
- struct zwp_linux_buffer_params_v1 * params = zwp_linux_dmabuf_v1_create_params (forward -> linux_dmabuf );
793
859
860
+ struct forward_state * forward = wl_resource_get_user_data (resource );
861
+ params -> resource = params_resource ;
862
+ params -> params = zwp_linux_dmabuf_v1_create_params (forward -> linux_dmabuf );
863
+ params -> width = 0 ;
864
+ params -> height = 0 ;
865
+ zwp_linux_buffer_params_v1_add_listener (params -> params , & params_listener ,
866
+ params );
794
867
wl_resource_set_implementation (params_resource , & linux_dmabuf_params_impl ,
795
868
params , linux_dmabuf_params_handle_resource_destroy );
796
869
}
0 commit comments