Split the geometry information from weston_surface out into weston_view

The weston_surface structure is split into two structures:

 * The weston_surface structure storres everything required for a
   client-side or server-side surface.  This includes buffers; callbacks;
   backend private data; input, damage, and opaque regions; and a few other
   bookkeeping bits.

 * The weston_view structure represents an entity in the scenegraph and
   storres all of the geometry information.  This includes clip region,
   alpha, position, and the transformation list as well as all of the
   temporary information derived from the geometry state.  Because a view,
   and not a surface, is a scenegraph element, the view is what is placed
   in layers and planes.

There are a few things worth noting about the surface/view split:

 1. This is *not* a modification to the protocol.  It is, instead, a
    modification to Weston's internal scenegraph to allow a single surface
    to exist in multiple places at a time.  Clients are completely unaware
    of how many views to a particular surface exist.

 2. A view is considered a direct child of a surface and is destroyed when
    the surface is destroyed.  Because of this, the view.surface pointer is
    always valid and non-null.

 3. The compositor's surface_list is replaced with a view_list.  Due to
    subsurfaces, building the view list is a little more complicated than
    it used to be and involves building a tree of views on the fly whenever
    subsurfaces are used.  However, this means that backends can remain
    completely subsurface-agnostic.

 4. Surfaces and views both keep track of which outputs they are on.

 5. The weston_surface structure now has width and height fields.  These
    are populated when a new buffer is attached before surface.configure
    is called.  This is because there are many surface-based operations
    that really require the width and height and digging through the views
    didn't work well.

Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
diff --git a/src/compositor.h b/src/compositor.h
index 5128875..8ae757b 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -92,6 +92,8 @@
 	struct shell_surface *(*create_shell_surface)(void *shell,
 						      struct weston_surface *surface,
 						      const struct weston_shell_client *client);
+	struct weston_view *(*get_primary_view)(void *shell,
+						struct shell_surface *shsurf);
 
 	void (*set_toplevel)(struct shell_surface *shsurf);
 
@@ -140,18 +142,12 @@
 	uint32_t clip;
 };
 
-enum {
-	ZOOM_FOCUS_POINTER,
-	ZOOM_FOCUS_TEXT
-};
-
 struct weston_fixed_point {
 	wl_fixed_t x, y;
 };
 
 struct weston_output_zoom {
 	int active;
-	uint32_t type;
 	float increment;
 	float level;
 	float max_level;
@@ -163,7 +159,6 @@
 	struct weston_fixed_point from;
 	struct weston_fixed_point to;
 	struct weston_fixed_point current;
-	struct weston_fixed_point text_cursor;
 };
 
 /* bit compatible with drm definitions. */
@@ -311,11 +306,11 @@
 
 	struct wl_list resource_list;
 	struct wl_list focus_resource_list;
-	struct weston_surface *focus;
+	struct weston_view *focus;
 	uint32_t focus_serial;
 	struct wl_signal focus_signal;
 
-	struct weston_surface *sprite;
+	struct weston_view *sprite;
 	struct wl_listener sprite_destroy_listener;
 	int32_t hotspot_x, hotspot_y;
 
@@ -336,7 +331,7 @@
 
 	struct wl_list resource_list;
 	struct wl_list focus_resource_list;
-	struct weston_surface *focus;
+	struct weston_view *focus;
 	uint32_t focus_serial;
 	struct wl_signal focus_signal;
 
@@ -354,7 +349,7 @@
 weston_pointer_destroy(struct weston_pointer *pointer);
 void
 weston_pointer_set_focus(struct weston_pointer *pointer,
-			 struct weston_surface *surface,
+			 struct weston_view *view,
 			 wl_fixed_t sx, wl_fixed_t sy);
 void
 weston_pointer_start_grab(struct weston_pointer *pointer,
@@ -384,7 +379,7 @@
 weston_touch_destroy(struct weston_touch *touch);
 void
 weston_touch_set_focus(struct weston_seat *seat,
-			  struct weston_surface *surface);
+		       struct weston_view *view);
 void
 weston_touch_start_grab(struct weston_touch *device,
 			struct weston_touch_grab *grab);
@@ -504,7 +499,7 @@
 };
 
 struct weston_layer {
-	struct wl_list surface_list;
+	struct wl_list view_list;
 	struct wl_list link;
 };
 
@@ -525,10 +520,12 @@
 	void (*flush_damage)(struct weston_surface *surface);
 	void (*attach)(struct weston_surface *es, struct weston_buffer *buffer);
 	int (*create_surface)(struct weston_surface *surface);
+	int (*create_view)(struct weston_view *view);
 	void (*surface_set_color)(struct weston_surface *surface,
 			       float red, float green,
 			       float blue, float alpha);
 	void (*destroy_surface)(struct weston_surface *surface);
+	void (*destroy_view)(struct weston_view *view);
 	void (*destroy)(struct weston_compositor *ec);
 };
 
@@ -574,7 +571,7 @@
 	struct wl_list output_list;
 	struct wl_list seat_list;
 	struct wl_list layer_list;
-	struct wl_list surface_list;
+	struct wl_list view_list;
 	struct wl_list plane_list;
 	struct wl_list key_binding_list;
 	struct wl_list button_binding_list;
@@ -685,51 +682,52 @@
 	} cached;
 
 	int synchronized;
+
+	/* Used for constructing the view tree */
+	struct wl_list unused_views;
 };
 
-/* Using weston_surface transformations
+/* Using weston_view transformations
  *
- * To add a transformation to a surface, create a struct weston_transform, and
- * add it to the list surface->geometry.transformation_list. Whenever you
- * change the list, anything under surface->geometry, or anything in the
+ * To add a transformation to a view, create a struct weston_transform, and
+ * add it to the list view->geometry.transformation_list. Whenever you
+ * change the list, anything under view->geometry, or anything in the
  * weston_transforms linked into the list, you must call
- * weston_surface_geometry_dirty().
+ * weston_view_geometry_dirty().
  *
  * The order in the list defines the order of transformations. Let the list
  * contain the transformation matrices M1, ..., Mn as head to tail. The
- * transformation is applied to surface-local coordinate vector p as
+ * transformation is applied to view-local coordinate vector p as
  *    P = Mn * ... * M2 * M1 * p
  * to produce the global coordinate vector P. The total transform
  *    Mn * ... * M2 * M1
- * is cached in surface->transform.matrix, and the inverse of it in
- * surface->transform.inverse.
+ * is cached in view->transform.matrix, and the inverse of it in
+ * view->transform.inverse.
  *
- * The list always contains surface->transform.position transformation, which
- * is the translation by surface->geometry.x and y.
+ * The list always contains view->transform.position transformation, which
+ * is the translation by view->geometry.x and y.
  *
  * If you want to apply a transformation in local coordinates, add your
  * weston_transform to the head of the list. If you want to apply a
  * transformation in global coordinates, add it to the tail of the list.
  *
- * If surface->geometry.parent is set, the total transformation of this
- * surface will be the parent's total transformation and this transformation
+ * If view->geometry.parent is set, the total transformation of this
+ * view will be the parent's total transformation and this transformation
  * combined:
  *    Mparent * Mn * ... * M2 * M1
  */
 
-struct weston_surface {
-	struct wl_resource *resource;
+struct weston_view {
+	struct weston_surface *surface;
+	struct wl_list surface_link;
 	struct wl_signal destroy_signal;
-	struct weston_compositor *compositor;
-	pixman_region32_t clip;
-	pixman_region32_t damage;
-	pixman_region32_t opaque;        /* part of geometry, see below */
-	pixman_region32_t input;
+
 	struct wl_list link;
 	struct wl_list layer_link;
-	float alpha;                     /* part of geometry, see below */
 	struct weston_plane *plane;
-	int32_t ref_count;
+
+	pixman_region32_t clip;
+	float alpha;                     /* part of geometry, see below */
 
 	void *renderer_state;
 
@@ -745,14 +743,14 @@
 		struct wl_list transformation_list;
 
 		/* managed by weston_surface_set_transform_parent() */
-		struct weston_surface *parent;
+		struct weston_view *parent;
 		struct wl_listener parent_destroy_listener;
 		struct wl_list child_list; /* geometry.parent_link */
 		struct wl_list parent_link;
 	} geometry;
 
 	/* State derived from geometry state, read-only.
-	 * This is updated by weston_surface_update_transform().
+	 * This is updated by weston_view_update_transform().
 	 */
 	struct {
 		int dirty;
@@ -782,6 +780,39 @@
 	 * displayed on.
 	 */
 	uint32_t output_mask;
+};
+
+struct weston_surface {
+	struct wl_resource *resource;
+	struct wl_signal destroy_signal;
+	struct weston_compositor *compositor;
+	pixman_region32_t damage;
+	pixman_region32_t opaque;        /* part of geometry, see below */
+	pixman_region32_t input;
+	int32_t width, height;
+	int32_t ref_count;
+
+	/* Not for long-term storage.  This exists for book-keeping while
+	 * iterating over surfaces and views
+	 */
+	int32_t touched;
+
+	void *renderer_state;
+
+	struct wl_list views;
+
+	/*
+	 * Which output to vsync this surface to.
+	 * Used to determine, whether to send or queue frame events.
+	 * Must be NULL, if 'link' is not in weston_compositor::surface_list.
+	 */
+	struct weston_output *output;
+
+	/*
+	 * A more complete representation of all outputs this surface is
+	 * displayed on.
+	 */
+	uint32_t output_mask;
 
 	struct wl_list frame_callback_list;
 
@@ -843,29 +874,29 @@
 weston_version(int *major, int *minor, int *micro);
 
 void
-weston_surface_update_transform(struct weston_surface *surface);
+weston_view_update_transform(struct weston_view *view);
 
 void
-weston_surface_geometry_dirty(struct weston_surface *surface);
+weston_view_geometry_dirty(struct weston_view *view);
 
 void
-weston_surface_to_global_fixed(struct weston_surface *surface,
-			       wl_fixed_t sx, wl_fixed_t sy,
-			       wl_fixed_t *x, wl_fixed_t *y);
+weston_view_to_global_fixed(struct weston_view *view,
+			    wl_fixed_t sx, wl_fixed_t sy,
+			    wl_fixed_t *x, wl_fixed_t *y);
 void
-weston_surface_to_global_float(struct weston_surface *surface,
-			       float sx, float sy, float *x, float *y);
+weston_view_to_global_float(struct weston_view *view,
+			    float sx, float sy, float *x, float *y);
 
 void
-weston_surface_from_global_float(struct weston_surface *surface,
-				 float x, float y, float *sx, float *sy);
+weston_view_from_global_float(struct weston_view *view,
+			      float x, float y, float *vx, float *vy);
 void
-weston_surface_from_global(struct weston_surface *surface,
-			   int32_t x, int32_t y, int32_t *sx, int32_t *sy);
+weston_view_from_global(struct weston_view *view,
+			int32_t x, int32_t y, int32_t *vx, int32_t *vy);
 void
-weston_surface_from_global_fixed(struct weston_surface *surface,
-			         wl_fixed_t x, wl_fixed_t y,
-			         wl_fixed_t *sx, wl_fixed_t *sy);
+weston_view_from_global_fixed(struct weston_view *view,
+			      wl_fixed_t x, wl_fixed_t y,
+			      wl_fixed_t *vx, wl_fixed_t *vy);
 int32_t
 weston_surface_buffer_width(struct weston_surface *surface);
 int32_t
@@ -876,8 +907,7 @@
 			       float x, float y, float *bx, float *by);
 WL_EXPORT void
 weston_surface_to_buffer(struct weston_surface *surface,
-                         int sx, int sy, int *bx, int *by);
-
+			 int sx, int sy, int *bx, int *by);
 pixman_box32_t
 weston_surface_to_buffer_rect(struct weston_surface *surface,
 			      pixman_box32_t rect);
@@ -959,10 +989,10 @@
 weston_compositor_offscreen(struct weston_compositor *compositor);
 void
 weston_compositor_sleep(struct weston_compositor *compositor);
-struct weston_surface *
-weston_compositor_pick_surface(struct weston_compositor *compositor,
-			       wl_fixed_t x, wl_fixed_t y,
-			       wl_fixed_t *sx, wl_fixed_t *sy);
+struct weston_view *
+weston_compositor_pick_view(struct weston_compositor *compositor,
+			    wl_fixed_t x, wl_fixed_t y,
+			    wl_fixed_t *sx, wl_fixed_t *sy);
 
 
 struct weston_binding;
@@ -1048,20 +1078,32 @@
 struct weston_surface *
 weston_surface_create(struct weston_compositor *compositor);
 
-void
-weston_surface_configure(struct weston_surface *surface,
-			 float x, float y, int width, int height);
+struct weston_view *
+weston_view_create(struct weston_surface *surface);
 
 void
-weston_surface_restack(struct weston_surface *surface, struct wl_list *below);
+weston_view_destroy(struct weston_view *view);
 
 void
-weston_surface_set_position(struct weston_surface *surface,
-			    float x, float y);
+weston_view_configure(struct weston_view *view,
+		      float x, float y, int width, int height);
 
 void
-weston_surface_set_transform_parent(struct weston_surface *surface,
-				    struct weston_surface *parent);
+weston_view_restack(struct weston_view *surface, struct wl_list *below);
+
+void
+weston_view_set_position(struct weston_view *view,
+			 float x, float y);
+
+void
+weston_view_set_transform_parent(struct weston_view *view,
+				 struct weston_view *parent);
+
+int
+weston_view_is_mapped(struct weston_view *view);
+
+void
+weston_view_schedule_repaint(struct weston_view *view);
 
 int
 weston_surface_is_mapped(struct weston_surface *surface);
@@ -1073,11 +1115,14 @@
 weston_surface_damage(struct weston_surface *surface);
 
 void
-weston_surface_damage_below(struct weston_surface *surface);
+weston_view_damage_below(struct weston_view *view);
 
 void
-weston_surface_move_to_plane(struct weston_surface *surface,
-			     struct weston_plane *plane);
+weston_view_move_to_plane(struct weston_view *view,
+			  struct weston_plane *plane);
+void
+weston_view_unmap(struct weston_view *view);
+
 void
 weston_surface_unmap(struct weston_surface *surface);
 
@@ -1100,12 +1145,9 @@
 void
 weston_compositor_shutdown(struct weston_compositor *ec);
 void
-weston_text_cursor_position_notify(struct weston_surface *surface,
-						wl_fixed_t x, wl_fixed_t y);
-void
 weston_output_init_zoom(struct weston_output *output);
 void
-weston_output_update_zoom(struct weston_output *output, uint32_t type);
+weston_output_update_zoom(struct weston_output *output);
 void
 weston_output_update_matrix(struct weston_output *output);
 void
@@ -1187,9 +1229,6 @@
 struct clipboard *
 clipboard_create(struct weston_seat *seat);
 
-void
-text_cursor_position_notifier_create(struct weston_compositor *ec);
-
 int
 text_backend_init(struct weston_compositor *ec);
 
@@ -1212,23 +1251,23 @@
 void
 weston_watch_process(struct weston_process *process);
 
-struct weston_surface_animation;
-typedef	void (*weston_surface_animation_done_func_t)(struct weston_surface_animation *animation, void *data);
+struct weston_view_animation;
+typedef	void (*weston_view_animation_done_func_t)(struct weston_view_animation *animation, void *data);
 
-struct weston_surface_animation *
-weston_zoom_run(struct weston_surface *surface, float start, float stop,
-		weston_surface_animation_done_func_t done, void *data);
+struct weston_view_animation *
+weston_zoom_run(struct weston_view *view, float start, float stop,
+		weston_view_animation_done_func_t done, void *data);
 
-struct weston_surface_animation *
-weston_fade_run(struct weston_surface *surface,
+struct weston_view_animation *
+weston_fade_run(struct weston_view *view,
 		float start, float end, float k,
-		weston_surface_animation_done_func_t done, void *data);
+		weston_view_animation_done_func_t done, void *data);
 void
-weston_fade_update(struct weston_surface_animation *fade, float target);
+weston_fade_update(struct weston_view_animation *fade, float target);
 
-struct weston_surface_animation *
-weston_slide_run(struct weston_surface *surface, float start, float stop,
-		 weston_surface_animation_done_func_t done, void *data);
+struct weston_view_animation *
+weston_slide_run(struct weston_view *view, float start, float stop,
+		 weston_view_animation_done_func_t done, void *data);
 
 void
 weston_surface_set_color(struct weston_surface *surface,