@ -615,6 +615,8 @@ static void subsurface_destroy(struct wlr_subsurface *subsurface) {
wl_list_remove ( & subsurface - > parent_destroy . link ) ;
}
wl_list_remove ( wl_resource_get_link ( subsurface - > resource ) ) ;
wl_resource_set_user_data ( subsurface - > resource , NULL ) ;
if ( subsurface - > surface ) {
subsurface - > surface - > role_data = NULL ;
@ -627,6 +629,9 @@ static void surface_handle_resource_destroy(struct wl_resource *resource) {
wlr_signal_emit_safe ( & surface - > events . destroy , surface ) ;
wl_list_remove ( wl_resource_get_link ( surface - > resource ) ) ;
wl_list_remove ( & surface - > renderer_destroy . link ) ;
wlr_texture_destroy ( surface - > texture ) ;
surface_state_destroy ( surface - > pending ) ;
surface_state_destroy ( surface - > current ) ;
@ -641,16 +646,27 @@ static void surface_handle_renderer_destroy(struct wl_listener *listener,
wl_resource_destroy ( surface - > resource ) ;
}
struct wlr_surface * wlr_surface_create ( struct wl_resource * res ,
struct wlr_renderer * renderer ) {
struct wlr_surface * wlr_surface_create ( struct wl_client * client ,
uint32_t version , uint32_t id , struct wlr_renderer * renderer ,
struct wl_list * resource_list ) {
struct wlr_surface * surface = calloc ( 1 , sizeof ( struct wlr_surface ) ) ;
if ( ! surface ) {
wl_resource_post_no_memory ( res ) ;
wl_client_post_no_memory ( client ) ;
return NULL ;
}
surface - > resource = wl_resource_create ( client , & wl_surface_interface ,
version , id ) ;
if ( surface - > resource = = NULL ) {
free ( surface ) ;
wl_client_post_no_memory ( client ) ;
return NULL ;
}
wlr_log ( L_DEBUG , " New wlr_surface %p (res %p) " , surface , res ) ;
wl_resource_set_implementation ( surface - > resource , & surface_interface ,
surface , surface_handle_resource_destroy ) ;
wlr_log ( L_DEBUG , " New wlr_surface %p (res %p) " , surface , surface - > resource ) ;
surface - > renderer = renderer ;
surface - > resource = res ;
surface - > current = surface_state_create ( ) ;
surface - > pending = surface_state_create ( ) ;
@ -660,12 +676,17 @@ struct wlr_surface *wlr_surface_create(struct wl_resource *res,
wl_signal_init ( & surface - > events . new_subsurface ) ;
wl_list_init ( & surface - > subsurfaces ) ;
wl_list_init ( & surface - > subsurface_pending_list ) ;
wl_resource_set_implementation ( res , & surface_interface ,
surface , surface_handle_resource_destroy ) ;
wl_signal_add ( & renderer - > events . destroy , & surface - > renderer_destroy ) ;
surface - > renderer_destroy . notify = surface_handle_renderer_destroy ;
struct wl_list * resource_link = wl_resource_get_link ( surface - > resource ) ;
if ( resource_list ! = NULL ) {
wl_list_insert ( resource_list , resource_link ) ;
} else {
wl_list_init ( resource_link ) ;
}
return surface ;
}
@ -838,8 +859,9 @@ static void subsurface_handle_surface_destroy(struct wl_listener *listener,
subsurface_destroy ( subsurface ) ;
}
struct wlr_subsurface * wlr_surface_make_subsurface ( struct wlr_surface * surface ,
struct wlr_surface * parent , uint32_t id ) {
struct wlr_subsurface * wlr_subsurface_create ( struct wlr_surface * surface ,
struct wlr_surface * parent , uint32_t version , uint32_t id ,
struct wl_list * resource_list ) {
struct wl_client * client = wl_resource_get_client ( surface - > resource ) ;
struct wlr_subsurface * subsurface =
@ -856,7 +878,20 @@ struct wlr_subsurface *wlr_surface_make_subsurface(struct wlr_surface *surface,
}
subsurface - > synchronized = true ;
subsurface - > surface = surface ;
subsurface - > resource =
wl_resource_create ( client , & wl_subsurface_interface , version , id ) ;
if ( subsurface - > resource = = NULL ) {
surface_state_destroy ( subsurface - > cached ) ;
free ( subsurface ) ;
wl_client_post_no_memory ( client ) ;
return NULL ;
}
wl_resource_set_implementation ( subsurface - > resource ,
& subsurface_implementation , subsurface ,
subsurface_resource_destroy ) ;
wl_signal_init ( & subsurface - > events . destroy ) ;
wl_signal_add ( & surface - > events . destroy , & subsurface - > surface_destroy ) ;
subsurface - > surface_destroy . notify = subsurface_handle_surface_destroy ;
@ -868,21 +903,15 @@ struct wlr_subsurface *wlr_surface_make_subsurface(struct wlr_surface *surface,
wl_list_insert ( & parent - > subsurface_pending_list ,
& subsurface - > parent_pending_link ) ;
subsurface - > resource =
wl_resource_create ( client , & wl_subsurface_interface , 1 , id ) ;
if ( subsurface - > resource = = NULL ) {
surface_state_destroy ( subsurface - > cached ) ;
free ( subsurface ) ;
wl_client_post_no_memory ( client ) ;
return NULL ;
}
wl_resource_set_implementation ( subsurface - > resource ,
& subsurface_implementation , subsurface ,
subsurface_resource_destroy ) ;
surface - > role_data = subsurface ;
struct wl_list * resource_link = wl_resource_get_link ( subsurface - > resource ) ;
if ( resource_list ! = NULL ) {
wl_list_insert ( resource_list , resource_link ) ;
} else {
wl_list_init ( resource_link ) ;
}
wlr_signal_emit_safe ( & parent - > events . new_subsurface , subsurface ) ;
return subsurface ;