Change weston_surface.resource to a wl_resource pointer.

This is the first in what will be a series of weston patches to convert
instances of wl_resource to pointers so we can make wl_resource opaque.
This patch handles weston_surface and should be the most invasive of the
entire series.  I am sending this one out ahead of the rest for review.

Specifically, my machine is not set up to build XWayland so I have no
ability to test it fully.  Could someone please test with XWayland and let
me know if this causes problems?

Because a surface may be created from XWayland, the resource may not always
exist.  Therefore, a destroy signal was added to weston_surface and
everything used to listen to surface->resource.destroy_signal now listens
to surface->destroy_signal.
diff --git a/src/compositor.c b/src/compositor.c
index 099600d..42011f5 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -276,13 +276,13 @@
 	if (surface == NULL)
 		return NULL;
 
-	wl_signal_init(&surface->resource.destroy_signal);
+	wl_signal_init(&surface->destroy_signal);
+
+	surface->resource = NULL;
 
 	wl_list_init(&surface->link);
 	wl_list_init(&surface->layer_link);
 
-	surface->resource.client = NULL;
-
 	surface->compositor = compositor;
 	surface->alpha = 1.0;
 
@@ -523,14 +523,16 @@
 	uint32_t left = es->output_mask & different;
 	struct weston_output *output;
 	struct wl_resource *resource = NULL;
-	struct wl_client *client = es->resource.client;
+	struct wl_client *client;
 
 	es->output_mask = mask;
-	if (es->resource.client == NULL)
+	if (es->resource == NULL)
 		return;
 	if (different == 0)
 		return;
 
+	client = wl_resource_get_client(es->resource);
+
 	wl_list_for_each(output, &es->compositor->output_list, link) {
 		if (1 << output->id & different)
 			resource =
@@ -539,9 +541,9 @@
 		if (resource == NULL)
 			continue;
 		if (1 << output->id & entered)
-			wl_surface_send_enter(&es->resource, resource);
+			wl_surface_send_enter(es->resource, resource);
 		if (1 << output->id & left)
-			wl_surface_send_leave(&es->resource, resource);
+			wl_surface_send_leave(es->resource, resource);
 	}
 }
 
@@ -882,7 +884,7 @@
 	surface->geometry.parent_destroy_listener.notify =
 		transform_parent_handle_parent_destroy;
 	if (parent) {
-		wl_signal_add(&parent->resource.destroy_signal,
+		wl_signal_add(&parent->destroy_signal,
 			      &surface->geometry.parent_destroy_listener);
 		wl_list_insert(&parent->geometry.child_list,
 			       &surface->geometry.parent_link);
@@ -1004,11 +1006,15 @@
 	struct wl_list link;
 };
 
-static void
-destroy_surface(struct wl_resource *resource)
+
+WL_EXPORT void
+weston_surface_destroy(struct weston_surface *surface)
 {
-	struct weston_surface *surface =
-		container_of(resource, struct weston_surface, resource);
+	/* Not a valid way to destroy a client surface */
+	assert(surface->resource == NULL);
+
+	wl_signal_emit(&surface->destroy_signal, &surface->resource);
+
 	struct weston_compositor *compositor = surface->compositor;
 	struct weston_frame_callback *cb, *next;
 
@@ -1048,14 +1054,13 @@
 	free(surface);
 }
 
-WL_EXPORT void
-weston_surface_destroy(struct weston_surface *surface)
+static void
+destroy_surface(struct wl_resource *resource)
 {
-	/* Not a valid way to destroy a client surface */
-	assert(surface->resource.client == NULL);
+	struct weston_surface *surface = wl_resource_get_user_data(resource);
 
-	wl_signal_emit(&surface->resource.destroy_signal, &surface->resource);
-	destroy_surface(&surface->resource);
+	surface->resource = NULL;
+	weston_surface_destroy(surface);
 }
 
 static void
@@ -1660,15 +1665,10 @@
 		return;
 	}
 
-	surface->resource.destroy = destroy_surface;
-
-	surface->resource.object.id = id;
-	surface->resource.object.interface = &wl_surface_interface;
-	surface->resource.object.implementation =
-		(void (**)(void)) &surface_interface;
-	surface->resource.data = surface;
-
-	wl_client_add_resource(client, &surface->resource);
+	surface->resource = wl_client_add_object(client, &wl_surface_interface,
+						 &surface_interface,
+						 id, surface);
+	wl_resource_set_destructor(surface->resource, destroy_surface);
 }
 
 static void
@@ -2035,7 +2035,7 @@
 		wl_resource_post_error(sub->resource,
 			WL_SUBSURFACE_ERROR_BAD_SURFACE,
 			"%s: wl_surface@%d is not a parent or sibling",
-			request, surface->resource.object.id);
+			request, wl_resource_get_id(surface->resource));
 		return NULL;
 	}
 
@@ -2043,7 +2043,7 @@
 		wl_resource_post_error(sub->resource,
 			WL_SUBSURFACE_ERROR_BAD_SURFACE,
 			"%s: wl_surface@%d has a different parent",
-			request, surface->resource.object.id);
+			request, wl_resource_get_id(surface->resource));
 		return NULL;
 	}
 
@@ -2204,7 +2204,7 @@
 {
 	sub->parent = parent;
 	sub->parent_destroy_listener.notify = subsurface_handle_parent_destroy;
-	wl_signal_add(&parent->resource.destroy_signal,
+	wl_signal_add(&parent->destroy_signal,
 		      &sub->parent_destroy_listener);
 
 	wl_list_insert(&parent->subsurface_list, &sub->parent_link);
@@ -2219,7 +2219,7 @@
 	sub->surface = surface;
 	sub->surface_destroy_listener.notify =
 		subsurface_handle_surface_destroy;
-	wl_signal_add(&surface->resource.destroy_signal,
+	wl_signal_add(&surface->destroy_signal,
 		      &sub->surface_destroy_listener);
 }
 
@@ -2266,12 +2266,13 @@
 			 struct weston_surface *parent)
 {
 	struct weston_subsurface *sub;
+	struct wl_client *client = wl_resource_get_client(surface->resource);
 
 	sub = calloc(1, sizeof *sub);
 	if (!sub)
 		return NULL;
 
-	sub->resource = wl_client_add_object(surface->resource.client,
+	sub->resource = wl_client_add_object(client,
 					     &wl_subsurface_interface,
 					     &subsurface_implementation,
 					     id, sub);