commit 18acb9d

Michael Forney  ·  2014-08-03 02:00:44 +0000 UTC
parent 1b0c5c6
Make view_attach return a negative error code instead of just false

This way, the compositor can appropriately handle EACCES from a failed
page flip.
6 files changed,  +59, -45
+10, -8
 1@@ -43,6 +43,7 @@
 2 #include "util.h"
 3 #include "view.h"
 4 
 5+#include <errno.h>
 6 #include <stdlib.h>
 7 #include <stdio.h>
 8 #include <assert.h>
 9@@ -273,8 +274,8 @@ static void renderer_repaint(struct target * target,
10     wld_flush(swc.drm->renderer);
11 }
12 
13-static bool renderer_attach(struct compositor_view * view,
14-                            struct wld_buffer * client_buffer)
15+static int renderer_attach(struct compositor_view * view,
16+                           struct wld_buffer * client_buffer)
17 {
18     struct wld_buffer * buffer;
19     bool was_proxy = view->buffer != view->base.buffer;
20@@ -300,7 +301,7 @@ static bool renderer_attach(struct compositor_view * view,
21                                            client_buffer->format, WLD_FLAG_MAP);
22 
23                 if (!buffer)
24-                    return false;
25+                    return -ENOMEM;
26             }
27             else
28             {
29@@ -324,7 +325,7 @@ static bool renderer_attach(struct compositor_view * view,
30 
31     view->buffer = buffer;
32 
33-    return true;
34+    return 0;
35 }
36 
37 static void renderer_flush_view(struct compositor_view * view)
38@@ -408,12 +409,13 @@ static bool update(struct view * base)
39     return true;
40 }
41 
42-static bool attach(struct view * base, struct wld_buffer * buffer)
43+static int attach(struct view * base, struct wld_buffer * buffer)
44 {
45     struct compositor_view * view = (void *) base;
46+    int ret;
47 
48-    if (!renderer_attach(view, buffer))
49-        return false;
50+    if ((ret = renderer_attach(view, buffer)) < 0)
51+        return ret;
52 
53     if (view->visible && view->base.buffer)
54     {
55@@ -433,7 +435,7 @@ static bool attach(struct view * base, struct wld_buffer * buffer)
56         }
57     }
58 
59-    return true;
60+    return 0;
61 }
62 
63 static bool move(struct view * base, int32_t x, int32_t y)
+15, -11
 1@@ -38,9 +38,10 @@ static bool update(struct view * view)
 2     return true;
 3 }
 4 
 5-static bool attach(struct view * view, struct wld_buffer * buffer)
 6+static int attach(struct view * view, struct wld_buffer * buffer)
 7 {
 8     struct cursor_plane * plane = wl_container_of(view, plane, view);
 9+    int ret;
10 
11     if (buffer)
12     {
13@@ -49,28 +50,31 @@ static bool attach(struct view * view, struct wld_buffer * buffer)
14         if (!wld_export(buffer, WLD_DRM_OBJECT_HANDLE, &object))
15         {
16             ERROR("Could not get export buffer to DRM handle\n");
17-            return false;
18+            /* XXX: Not the best error code, but we don't know better until wld
19+             * returns an actual error code. */
20+            return -EINVAL;
21         }
22 
23-        if (drmModeSetCursor(swc.drm->fd, plane->crtc, object.u32,
24-                             buffer->width, buffer->height) != 0)
25+        ret = drmModeSetCursor(swc.drm->fd, plane->crtc, object.u32,
26+                               buffer->width, buffer->height);
27+
28+        if (ret < 0)
29         {
30-            ERROR("Could not set cursor: %s\n", strerror(errno));
31-            return false;
32+            ERROR("Could not set cursor: %s\n", strerror(-ret));
33+            return ret;
34         }
35     }
36     else
37     {
38-        if (drmModeSetCursor(swc.drm->fd, plane->crtc, 0, 0, 0) != 0)
39+        if ((ret = drmModeSetCursor(swc.drm->fd, plane->crtc, 0, 0, 0)) < 0)
40         {
41-            ERROR("Could not unset cursor: %s\n", strerror(errno));
42-            return false;
43+            ERROR("Could not unset cursor: %s\n", strerror(-ret));
44+            return ret;
45         }
46     }
47 
48     view_set_size_from_buffer(view, buffer);
49-
50-    return true;
51+    return 0;
52 }
53 
54 static bool move(struct view * view, int32_t x, int32_t y)
+22, -15
 1@@ -84,10 +84,11 @@ static void send_frame(void * data)
 2     view_frame(&plane->view, swc_time());
 3 }
 4 
 5-static bool attach(struct view * view, struct wld_buffer * buffer)
 6+static int attach(struct view * view, struct wld_buffer * buffer)
 7 {
 8     struct framebuffer_plane * plane = wl_container_of(view, plane, view);
 9     union wld_object object;
10+    int ret;
11 
12     if (!wld_export(buffer, WLD_USER_OBJECT_FRAMEBUFFER, &object))
13     {
14@@ -96,17 +97,19 @@ static bool attach(struct view * view, struct wld_buffer * buffer)
15         if (!wld_export(buffer, WLD_DRM_OBJECT_HANDLE, &object))
16         {
17             ERROR("Could not get buffer handle\n");
18-            return false;
19+            return -EINVAL;
20         }
21 
22         if (!(framebuffer = malloc(sizeof *framebuffer)))
23-            return false;
24+            return -ENOMEM;
25 
26-        if (drmModeAddFB(swc.drm->fd, buffer->width, buffer->height, 24, 32,
27-                         buffer->pitch, object.u32, &framebuffer->id) != 0)
28+        ret = drmModeAddFB(swc.drm->fd, buffer->width, buffer->height, 24, 32,
29+                           buffer->pitch, object.u32, &framebuffer->id);
30+
31+        if (ret < 0)
32         {
33             free(framebuffer);
34-            return false;
35+            return ret;
36         }
37 
38         framebuffer->exporter.export = &framebuffer_export;
39@@ -119,9 +122,11 @@ static bool attach(struct view * view, struct wld_buffer * buffer)
40 
41     if (plane->need_modeset)
42     {
43-        if (drmModeSetCrtc(swc.drm->fd, plane->crtc, object.u32, 0, 0,
44-                           plane->connectors.data, plane->connectors.size / 4,
45-                           &plane->mode.info) == 0)
46+        ret = drmModeSetCrtc(swc.drm->fd, plane->crtc, object.u32, 0, 0,
47+                             plane->connectors.data, plane->connectors.size / 4,
48+                             &plane->mode.info);
49+
50+        if (ret == 0)
51         {
52             wl_event_loop_add_idle(swc.event_loop, &send_frame, plane);
53             plane->need_modeset = false;
54@@ -129,21 +134,23 @@ static bool attach(struct view * view, struct wld_buffer * buffer)
55         else
56         {
57             ERROR("Could not set CRTC to next framebuffer: %s\n",
58-                  strerror(errno));
59-            return false;
60+                  strerror(-ret));
61+            return ret;
62         }
63     }
64     else
65     {
66-        if (drmModePageFlip(swc.drm->fd, plane->crtc, object.u32,
67-                            DRM_MODE_PAGE_FLIP_EVENT, &plane->drm_handler) != 0)
68+        ret = drmModePageFlip(swc.drm->fd, plane->crtc, object.u32,
69+                              DRM_MODE_PAGE_FLIP_EVENT, &plane->drm_handler);
70+
71+        if (ret < 0)
72         {
73             ERROR("Page flip failed: %s\n", strerror(errno));
74-            return false;
75+            return ret;
76         }
77     }
78 
79-    return true;
80+    return 0;
81 }
82 
83 static bool move(struct view * view, int32_t x, int32_t y)
+3, -3
 1@@ -73,13 +73,13 @@ static bool update(struct view * view)
 2     return true;
 3 }
 4 
 5-static bool attach(struct view * view, struct wld_buffer * buffer)
 6+static int attach(struct view * view, struct wld_buffer * buffer)
 7 {
 8     struct pointer * pointer = wl_container_of(view, pointer, cursor.view);
 9     struct swc_surface * surface = pointer->cursor.surface;
10 
11     if (surface && !pixman_region32_not_empty(&surface->state.damage))
12-        return true;
13+        return 0;
14 
15     wld_set_target_buffer(swc.shm->renderer, pointer->cursor.buffer);
16     wld_fill_rectangle(swc.shm->renderer, 0x00000000, 0, 0, 64, 64);
17@@ -95,7 +95,7 @@ static bool attach(struct view * view, struct wld_buffer * buffer)
18     if (view_set_size_from_buffer(view, buffer))
19         view_update_screens(view);
20 
21-    return true;
22+    return 0;
23 }
24 
25 static bool move(struct view * view, int32_t x, int32_t y)
+6, -5
 1@@ -47,9 +47,11 @@ void view_finalize(struct view * view)
 2         wld_buffer_unreference(view->buffer);
 3 }
 4 
 5-bool view_attach(struct view * view, struct wld_buffer * buffer)
 6+int view_attach(struct view * view, struct wld_buffer * buffer)
 7 {
 8-    if (view->impl->attach(view, buffer))
 9+    int ret;
10+
11+    if ((ret = view->impl->attach(view, buffer)) == 0)
12     {
13         if (view->buffer)
14             wld_buffer_unreference(view->buffer);
15@@ -58,10 +60,9 @@ bool view_attach(struct view * view, struct wld_buffer * buffer)
16             wld_buffer_reference(buffer);
17 
18         view->buffer = buffer;
19-        return true;
20     }
21-    else
22-        return false;
23+
24+    return ret;
25 }
26 
27 bool view_update(struct view * view)
+3, -3
 1@@ -95,7 +95,7 @@ struct view
 2 struct view_impl
 3 {
 4     bool (* update)(struct view * view);
 5-    bool (* attach)(struct view * view, struct wld_buffer * buffer);
 6+    int (* attach)(struct view * view, struct wld_buffer * buffer);
 7     bool (* move)(struct view * view, int32_t x, int32_t y);
 8 };
 9 
10@@ -104,9 +104,9 @@ struct view_impl
11  *
12  * If buffer is NULL, the previous buffer is removed from the view.
13  *
14- * @return Whether or not the buffer was successfully attached to the view.
15+ * @return 0 on success, negative error code otherwise.
16  */
17-bool view_attach(struct view * view, struct wld_buffer * buffer);
18+int view_attach(struct view * view, struct wld_buffer * buffer);
19 
20 /**
21  * Display a new frame consisting of the currently attached buffer.