commit 97b3ef8fafd1a248e1bae3026751aca9011dd7f5
parent 3d0a76b52cdc067c43094b2d4ac3935e3e3dc704
Author: Michael Forney <mforney@mforney.org>
Date: Sun, 1 May 2016 00:39:07 -0700
Rename framebuffer_plane to primary_plane to match DRM terminology
Diffstat:
9 files changed, 278 insertions(+), 278 deletions(-)
diff --git a/libswc/compositor.c b/libswc/compositor.c
@@ -157,7 +157,7 @@ target_new(struct screen *screen)
if (!target->surface)
goto error1;
- target->view = &screen->planes.framebuffer.view;
+ target->view = &screen->planes.primary.view;
target->view_handler.impl = &screen_view_handler;
wl_list_insert(&target->view->handlers, &target->view_handler.link);
target->current_buffer = NULL;
diff --git a/libswc/framebuffer_plane.c b/libswc/framebuffer_plane.c
@@ -1,218 +0,0 @@
-/* swc: framebuffer_plane.c
- *
- * Copyright (c) 2013, 2014 Michael Forney
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-#include "framebuffer_plane.h"
-#include "drm.h"
-#include "event.h"
-#include "internal.h"
-#include "launch.h"
-#include "util.h"
-
-#include <errno.h>
-#include <wld/wld.h>
-#include <wld/drm.h>
-#include <xf86drm.h>
-#include <xf86drmMode.h>
-
-enum {
- WLD_USER_OBJECT_FRAMEBUFFER = WLD_USER_ID
-};
-
-struct framebuffer {
- struct wld_exporter exporter;
- struct wld_destructor destructor;
- uint32_t id;
-};
-
-static bool
-framebuffer_export(struct wld_exporter *exporter, struct wld_buffer *buffer, uint32_t type, union wld_object *object)
-{
- struct framebuffer *framebuffer = wl_container_of(exporter, framebuffer, exporter);
-
- switch (type) {
- case WLD_USER_OBJECT_FRAMEBUFFER:
- object->u32 = framebuffer->id;
- break;
- default:
- return false;
- }
-
- return true;
-}
-
-static void
-framebuffer_destroy(struct wld_destructor *destructor)
-{
- struct framebuffer *framebuffer = wl_container_of(destructor, framebuffer, destructor);
-
- drmModeRmFB(swc.drm->fd, framebuffer->id);
- free(framebuffer);
-}
-
-static bool
-update(struct view *view)
-{
- return true;
-}
-
-static void
-send_frame(void *data)
-{
- struct framebuffer_plane *plane = data;
-
- view_frame(&plane->view, get_time());
-}
-
-static int
-attach(struct view *view, struct wld_buffer *buffer)
-{
- struct framebuffer_plane *plane = wl_container_of(view, plane, view);
- union wld_object object;
- int ret;
-
- if (!wld_export(buffer, WLD_USER_OBJECT_FRAMEBUFFER, &object)) {
- struct framebuffer *framebuffer;
-
- if (!wld_export(buffer, WLD_DRM_OBJECT_HANDLE, &object)) {
- ERROR("Could not get buffer handle\n");
- return -EINVAL;
- }
-
- if (!(framebuffer = malloc(sizeof *framebuffer)))
- return -ENOMEM;
-
- ret = drmModeAddFB(swc.drm->fd, buffer->width, buffer->height, 24, 32, buffer->pitch, object.u32, &framebuffer->id);
-
- if (ret < 0) {
- free(framebuffer);
- return ret;
- }
-
- framebuffer->exporter.export = &framebuffer_export;
- wld_buffer_add_exporter(buffer, &framebuffer->exporter);
- framebuffer->destructor.destroy = &framebuffer_destroy;
- wld_buffer_add_destructor(buffer, &framebuffer->destructor);
-
- object.u32 = framebuffer->id;
- }
-
- if (plane->need_modeset) {
- ret = drmModeSetCrtc(swc.drm->fd, plane->crtc, object.u32, 0, 0, plane->connectors.data, plane->connectors.size / 4, &plane->mode.info);
-
- if (ret == 0) {
- wl_event_loop_add_idle(swc.event_loop, &send_frame, plane);
- plane->need_modeset = false;
- } else {
- ERROR("Could not set CRTC to next framebuffer: %s\n", strerror(-ret));
- return ret;
- }
- } else {
- ret = drmModePageFlip(swc.drm->fd, plane->crtc, object.u32, DRM_MODE_PAGE_FLIP_EVENT, &plane->drm_handler);
-
- if (ret < 0) {
- ERROR("Page flip failed: %s\n", strerror(errno));
- return ret;
- }
- }
-
- return 0;
-}
-
-static bool
-move(struct view *view, int32_t x, int32_t y)
-{
- view_set_position(view, x, y);
- return true;
-}
-
-const static struct view_impl view_impl = {
- .update = update,
- .attach = attach,
- .move = move,
-};
-
-static void
-handle_page_flip(struct drm_handler *handler, uint32_t time)
-{
- struct framebuffer_plane *plane = wl_container_of(handler, plane, drm_handler);
- view_frame(&plane->view, time);
-}
-
-static void
-handle_swc_event(struct wl_listener *listener, void *data)
-{
- struct event *event = data;
- struct framebuffer_plane *plane = wl_container_of(listener, plane, swc_listener);
-
- switch (event->type) {
- case SWC_EVENT_ACTIVATED:
- plane->need_modeset = true;
- break;
- }
-}
-
-bool
-framebuffer_plane_initialize(struct framebuffer_plane *plane, uint32_t crtc, struct mode *mode, uint32_t *connectors, uint32_t num_connectors)
-{
- uint32_t *plane_connectors;
-
- if (!(plane->original_crtc_state = drmModeGetCrtc(swc.drm->fd, crtc))) {
- ERROR("Failed to get CRTC state for CRTC %u: %s\n", crtc, strerror(errno));
- goto error0;
- }
-
- wl_array_init(&plane->connectors);
- plane_connectors = wl_array_add(&plane->connectors, num_connectors * sizeof connectors[0]);
-
- if (!plane_connectors) {
- ERROR("Failed to allocate connector array\n");
- goto error1;
- }
-
- memcpy(plane_connectors, connectors, num_connectors * sizeof connectors[0]);
- plane->crtc = crtc;
- plane->need_modeset = true;
- view_initialize(&plane->view, &view_impl);
- plane->view.geometry.width = mode->width;
- plane->view.geometry.height = mode->height;
- plane->drm_handler.page_flip = &handle_page_flip;
- plane->swc_listener.notify = &handle_swc_event;
- plane->mode = *mode;
- wl_signal_add(&swc.event_signal, &plane->swc_listener);
-
- return true;
-
-error1:
- drmModeFreeCrtc(plane->original_crtc_state);
-error0:
- return false;
-}
-
-void
-framebuffer_plane_finalize(struct framebuffer_plane *plane)
-{
- wl_array_release(&plane->connectors);
- drmModeCrtcPtr crtc = plane->original_crtc_state;
- drmModeSetCrtc(swc.drm->fd, crtc->crtc_id, crtc->buffer_id, crtc->x, crtc->y, NULL, 0, &crtc->mode);
- drmModeFreeCrtc(crtc);
-}
diff --git a/libswc/framebuffer_plane.h b/libswc/framebuffer_plane.h
@@ -1,49 +0,0 @@
-/* swc: libswc/framebuffer_plane.h
- *
- * Copyright (c) 2013 Michael Forney
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-#ifndef SWC_FRAMEBUFFER_PLANE_H
-#define SWC_FRAMEBUFFER_PLANE_H
-
-#include "drm.h"
-#include "mode.h"
-#include "view.h"
-
-#include <stdint.h>
-#include <stdbool.h>
-#include <wayland-server.h>
-
-struct framebuffer_plane {
- uint32_t crtc;
- drmModeCrtcPtr original_crtc_state;
- struct mode mode;
- struct view view;
- struct wl_array connectors;
- bool need_modeset;
- struct drm_handler drm_handler;
- struct wl_listener swc_listener;
-};
-
-bool framebuffer_plane_initialize(struct framebuffer_plane *plane, uint32_t crtc, struct mode *mode, uint32_t *connectors, uint32_t num_connectors);
-void framebuffer_plane_finalize(struct framebuffer_plane *plane);
-
-#endif
diff --git a/libswc/local.mk b/libswc/local.mk
@@ -28,7 +28,6 @@ SWC_SOURCES = \
libswc/data_device.c \
libswc/data_device_manager.c \
libswc/drm.c \
- libswc/framebuffer_plane.c \
libswc/input.c \
libswc/keyboard.c \
libswc/launch.c \
@@ -37,6 +36,7 @@ SWC_SOURCES = \
libswc/panel.c \
libswc/panel_manager.c \
libswc/pointer.c \
+ libswc/primary_plane.c \
libswc/region.c \
libswc/screen.c \
libswc/seat.c \
diff --git a/libswc/output.c b/libswc/output.c
@@ -41,7 +41,7 @@ bind_output(struct wl_client *client, void *data, uint32_t version, uint32_t id)
flags = 0;
if (mode->preferred)
flags |= WL_OUTPUT_MODE_PREFERRED;
- if (mode_equal(&screen->planes.framebuffer.mode, mode))
+ if (mode_equal(&screen->planes.primary.mode, mode))
flags |= WL_OUTPUT_MODE_CURRENT;
wl_output_send_mode(resource, flags, mode->width, mode->height, mode->refresh);
diff --git a/libswc/primary_plane.c b/libswc/primary_plane.c
@@ -0,0 +1,218 @@
+/* swc: primary_plane.c
+ *
+ * Copyright (c) 2013, 2014, 2016 Michael Forney
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include "primary_plane.h"
+#include "drm.h"
+#include "event.h"
+#include "internal.h"
+#include "launch.h"
+#include "util.h"
+
+#include <errno.h>
+#include <wld/wld.h>
+#include <wld/drm.h>
+#include <xf86drm.h>
+#include <xf86drmMode.h>
+
+enum {
+ WLD_USER_OBJECT_FRAMEBUFFER = WLD_USER_ID
+};
+
+struct framebuffer {
+ struct wld_exporter exporter;
+ struct wld_destructor destructor;
+ uint32_t id;
+};
+
+static bool
+framebuffer_export(struct wld_exporter *exporter, struct wld_buffer *buffer, uint32_t type, union wld_object *object)
+{
+ struct framebuffer *framebuffer = wl_container_of(exporter, framebuffer, exporter);
+
+ switch (type) {
+ case WLD_USER_OBJECT_FRAMEBUFFER:
+ object->u32 = framebuffer->id;
+ break;
+ default:
+ return false;
+ }
+
+ return true;
+}
+
+static void
+framebuffer_destroy(struct wld_destructor *destructor)
+{
+ struct framebuffer *framebuffer = wl_container_of(destructor, framebuffer, destructor);
+
+ drmModeRmFB(swc.drm->fd, framebuffer->id);
+ free(framebuffer);
+}
+
+static bool
+update(struct view *view)
+{
+ return true;
+}
+
+static void
+send_frame(void *data)
+{
+ struct primary_plane *plane = data;
+
+ view_frame(&plane->view, get_time());
+}
+
+static int
+attach(struct view *view, struct wld_buffer *buffer)
+{
+ struct primary_plane *plane = wl_container_of(view, plane, view);
+ union wld_object object;
+ int ret;
+
+ if (!wld_export(buffer, WLD_USER_OBJECT_FRAMEBUFFER, &object)) {
+ struct framebuffer *framebuffer;
+
+ if (!wld_export(buffer, WLD_DRM_OBJECT_HANDLE, &object)) {
+ ERROR("Could not get buffer handle\n");
+ return -EINVAL;
+ }
+
+ if (!(framebuffer = malloc(sizeof *framebuffer)))
+ return -ENOMEM;
+
+ ret = drmModeAddFB(swc.drm->fd, buffer->width, buffer->height, 24, 32, buffer->pitch, object.u32, &framebuffer->id);
+
+ if (ret < 0) {
+ free(framebuffer);
+ return ret;
+ }
+
+ framebuffer->exporter.export = &framebuffer_export;
+ wld_buffer_add_exporter(buffer, &framebuffer->exporter);
+ framebuffer->destructor.destroy = &framebuffer_destroy;
+ wld_buffer_add_destructor(buffer, &framebuffer->destructor);
+
+ object.u32 = framebuffer->id;
+ }
+
+ if (plane->need_modeset) {
+ ret = drmModeSetCrtc(swc.drm->fd, plane->crtc, object.u32, 0, 0, plane->connectors.data, plane->connectors.size / 4, &plane->mode.info);
+
+ if (ret == 0) {
+ wl_event_loop_add_idle(swc.event_loop, &send_frame, plane);
+ plane->need_modeset = false;
+ } else {
+ ERROR("Could not set CRTC to next framebuffer: %s\n", strerror(-ret));
+ return ret;
+ }
+ } else {
+ ret = drmModePageFlip(swc.drm->fd, plane->crtc, object.u32, DRM_MODE_PAGE_FLIP_EVENT, &plane->drm_handler);
+
+ if (ret < 0) {
+ ERROR("Page flip failed: %s\n", strerror(errno));
+ return ret;
+ }
+ }
+
+ return 0;
+}
+
+static bool
+move(struct view *view, int32_t x, int32_t y)
+{
+ view_set_position(view, x, y);
+ return true;
+}
+
+const static struct view_impl view_impl = {
+ .update = update,
+ .attach = attach,
+ .move = move,
+};
+
+static void
+handle_page_flip(struct drm_handler *handler, uint32_t time)
+{
+ struct primary_plane *plane = wl_container_of(handler, plane, drm_handler);
+ view_frame(&plane->view, time);
+}
+
+static void
+handle_swc_event(struct wl_listener *listener, void *data)
+{
+ struct event *event = data;
+ struct primary_plane *plane = wl_container_of(listener, plane, swc_listener);
+
+ switch (event->type) {
+ case SWC_EVENT_ACTIVATED:
+ plane->need_modeset = true;
+ break;
+ }
+}
+
+bool
+primary_plane_initialize(struct primary_plane *plane, uint32_t crtc, struct mode *mode, uint32_t *connectors, uint32_t num_connectors)
+{
+ uint32_t *plane_connectors;
+
+ if (!(plane->original_crtc_state = drmModeGetCrtc(swc.drm->fd, crtc))) {
+ ERROR("Failed to get CRTC state for CRTC %u: %s\n", crtc, strerror(errno));
+ goto error0;
+ }
+
+ wl_array_init(&plane->connectors);
+ plane_connectors = wl_array_add(&plane->connectors, num_connectors * sizeof connectors[0]);
+
+ if (!plane_connectors) {
+ ERROR("Failed to allocate connector array\n");
+ goto error1;
+ }
+
+ memcpy(plane_connectors, connectors, num_connectors * sizeof connectors[0]);
+ plane->crtc = crtc;
+ plane->need_modeset = true;
+ view_initialize(&plane->view, &view_impl);
+ plane->view.geometry.width = mode->width;
+ plane->view.geometry.height = mode->height;
+ plane->drm_handler.page_flip = &handle_page_flip;
+ plane->swc_listener.notify = &handle_swc_event;
+ plane->mode = *mode;
+ wl_signal_add(&swc.event_signal, &plane->swc_listener);
+
+ return true;
+
+error1:
+ drmModeFreeCrtc(plane->original_crtc_state);
+error0:
+ return false;
+}
+
+void
+primary_plane_finalize(struct primary_plane *plane)
+{
+ wl_array_release(&plane->connectors);
+ drmModeCrtcPtr crtc = plane->original_crtc_state;
+ drmModeSetCrtc(swc.drm->fd, crtc->crtc_id, crtc->buffer_id, crtc->x, crtc->y, NULL, 0, &crtc->mode);
+ drmModeFreeCrtc(crtc);
+}
diff --git a/libswc/primary_plane.h b/libswc/primary_plane.h
@@ -0,0 +1,49 @@
+/* swc: libswc/primary_plane.h
+ *
+ * Copyright (c) 2013, 2016 Michael Forney
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef SWC_PRIMARY_PLANE_H
+#define SWC_PRIMARY_PLANE_H
+
+#include "drm.h"
+#include "mode.h"
+#include "view.h"
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <wayland-server.h>
+
+struct primary_plane {
+ uint32_t crtc;
+ drmModeCrtcPtr original_crtc_state;
+ struct mode mode;
+ struct view view;
+ struct wl_array connectors;
+ bool need_modeset;
+ struct drm_handler drm_handler;
+ struct wl_listener swc_listener;
+};
+
+bool primary_plane_initialize(struct primary_plane *plane, uint32_t crtc, struct mode *mode, uint32_t *connectors, uint32_t num_connectors);
+void primary_plane_finalize(struct primary_plane *plane);
+
+#endif
diff --git a/libswc/screen.c b/libswc/screen.c
@@ -117,8 +117,8 @@ screen_new(uint32_t crtc, struct output *output)
goto error1;
}
- if (!framebuffer_plane_initialize(&screen->planes.framebuffer, crtc, output->preferred_mode, &output->connector, 1)) {
- ERROR("Failed to initialize framebuffer plane\n");
+ if (!primary_plane_initialize(&screen->planes.primary, crtc, output->preferred_mode, &output->connector, 1)) {
+ ERROR("Failed to initialize primary plane\n");
goto error2;
}
@@ -134,8 +134,8 @@ screen_new(uint32_t crtc, struct output *output)
wl_list_insert(&screen->outputs, &output->link);
wl_list_init(&screen->modifiers);
- view_move(&screen->planes.framebuffer.view, x, 0);
- screen->base.geometry = screen->planes.framebuffer.view.geometry;
+ view_move(&screen->planes.primary.view, x, 0);
+ screen->base.geometry = screen->planes.primary.view.geometry;
screen->base.usable_geometry = screen->base.geometry;
swc.manager->new_screen(&screen->base);
@@ -143,7 +143,7 @@ screen_new(uint32_t crtc, struct output *output)
return screen;
error3:
- framebuffer_plane_finalize(&screen->planes.framebuffer);
+ primary_plane_finalize(&screen->planes.primary);
error2:
wl_global_destroy(screen->global);
error1:
@@ -164,7 +164,7 @@ screen_destroy(struct screen *screen)
wl_signal_emit(&screen->destroy_signal, NULL);
wl_list_for_each_safe (output, next, &screen->outputs, link)
output_destroy(output);
- framebuffer_plane_finalize(&screen->planes.framebuffer);
+ primary_plane_finalize(&screen->planes.primary);
cursor_plane_finalize(&screen->planes.cursor);
free(screen);
}
diff --git a/libswc/screen.h b/libswc/screen.h
@@ -26,7 +26,7 @@
#include "swc.h"
#include "cursor_plane.h"
-#include "framebuffer_plane.h"
+#include "primary_plane.h"
#include <wayland-util.h>
@@ -52,7 +52,7 @@ struct screen {
uint8_t id;
struct {
- struct framebuffer_plane framebuffer;
+ struct primary_plane primary;
struct cursor_plane cursor;
} planes;