blob: 912fb873dbd6537054b7587dafe00addaaf3c108 [file] [log] [blame]
From 79d48c68d79e7436a045bb875e18f7e8c6829392 Mon Sep 17 00:00:00 2001
From: Qian Hu <Qian.Hu@mediatek.com>
Date: Tue, 24 Sep 2019 14:25:47 +0800
Subject: [PATCH 6/8] [PATCH 7/9] weston-screen-shot: add screen shot
add screen shot
Signed-off-by: Qian Hu <Qian.Hu@mediatek.com>
---
Makefile.am | 26 +++-
clients/simple-screenshooter-mtk.c | 259 +++++++++++++++++++++++++++++++++++
libweston/compositor.c | 3 +
libweston/compositor.h | 3 +
libweston/pixel-formats.c | 2 +
libweston/weston-screenshooter-mtk.c | 129 +++++++++++++++++
protocol/weston-configure-mtk.xml | 67 +++++++++
7 files changed, 486 insertions(+), 3 deletions(-)
create mode 100644 clients/simple-screenshooter-mtk.c
create mode 100644 libweston/weston-screenshooter-mtk.c
create mode 100644 protocol/weston-configure-mtk.xml
diff --git a/Makefile.am b/Makefile.am
index 769e103..a9e48f8 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -96,6 +96,7 @@ libweston_@LIBWESTON_MAJOR@_la_SOURCES = \
libweston/linux-dmabuf.h \
libweston/pixel-formats.c \
libweston/pixel-formats.h \
+ libweston/weston-screenshooter-mtk.c \
shared/helpers.h \
shared/matrix.c \
shared/matrix.h \
@@ -169,7 +170,10 @@ nodist_libweston_@LIBWESTON_MAJOR@_la_SOURCES = \
protocol/input-timestamps-unstable-v1-protocol.c \
protocol/input-timestamps-unstable-v1-server-protocol.h \
protocol/weston-touch-calibration-protocol.c \
- protocol/weston-touch-calibration-server-protocol.h
+ protocol/weston-touch-calibration-server-protocol.h \
+ protocol/pointer-constraints-unstable-v1-server-protocol.h \
+ protocol/weston-configure-mtk-protocol.c \
+ protocol/weston-configure-mtk-server-protocol.h
BUILT_SOURCES += $(nodist_libweston_@LIBWESTON_MAJOR@_la_SOURCES)
@@ -652,6 +656,19 @@ weston_simple_dmabuf_v4l_CFLAGS = $(AM_CFLAGS) $(SIMPLE_DMABUF_V4L_CLIENT_CFLAGS
weston_simple_dmabuf_v4l_LDADD = $(SIMPLE_DMABUF_V4L_CLIENT_LIBS) libshared.la
endif
+demo_clients += weston-simple-screenshooter-mtk
+weston_simple_screenshooter_mtk_SOURCES = clients/simple-screenshooter-mtk.c
+nodist_weston_simple_screenshooter_mtk_SOURCES = \
+ protocol/xdg-shell-unstable-v6-protocol.c \
+ protocol/xdg-shell-unstable-v6-client-protocol.h \
+ protocol/fullscreen-shell-unstable-v1-protocol.c \
+ protocol/fullscreen-shell-unstable-v1-client-protocol.h \
+ protocol/weston-configure-mtk-protocol.c \
+ protocol/weston-configure-mtk-client-protocol.h
+weston_simple_screenshooter_mtk_CFLAGS = $(AM_CFLAGS) $(CLIENT_CFLAGS)
+weston_simple_screenshooter_mtk_LDADD = $(EGL_LIBS) $(LIBDRM_LIBS) libtoytoolkit.la
+
+
noinst_LTLIBRARIES += libtoytoolkit.la
libtoytoolkit_la_SOURCES = \
@@ -911,7 +928,9 @@ BUILT_SOURCES += \
protocol/tablet-unstable-v2-protocol.c \
protocol/tablet-unstable-v2-client-protocol.h \
protocol/input-timestamps-unstable-v1-protocol.c \
- protocol/input-timestamps-unstable-v1-client-protocol.h
+ protocol/input-timestamps-unstable-v1-client-protocol.h \
+ protocol/weston-configure-mtk-protocol.c \
+ protocol/weston-configure-mtk-client-protocol.h
westondatadir = $(datadir)/weston
dist_westondata_DATA = \
@@ -1564,7 +1583,8 @@ EXTRA_DIST += \
protocol/weston-test.xml \
protocol/weston-touch-calibration.xml \
protocol/ivi-application.xml \
- protocol/ivi-hmi-controller.xml
+ protocol/ivi-hmi-controller.xml \
+ protocol/weston-configure-mtk.xml
#
# manual test modules in tests subdirectory
diff --git a/clients/simple-screenshooter-mtk.c b/clients/simple-screenshooter-mtk.c
new file mode 100644
index 0000000..cbca18b
--- /dev/null
+++ b/clients/simple-screenshooter-mtk.c
@@ -0,0 +1,259 @@
+/*
+ * Copyright © 2008 Kristian Høgsberg
+ *
+ * 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 (including the next
+ * paragraph) 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 "config.h"
+
+#include <stdint.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <limits.h>
+#include <sys/param.h>
+#include <sys/mman.h>
+#include <cairo.h>
+
+#include <wayland-client.h>
+#include "weston-configure-mtk-client-protocol.h"
+#include "shared/os-compatibility.h"
+#include "shared/xalloc.h"
+
+/* The screenshooter is a good example of a custom object exposed by
+ * the compositor and serves as a test bed for implementing client
+ * side marshalling outside libwayland.so */
+
+static struct wl_shm *shm;
+static struct weston_screenshooter_mtk *mtk_screenshooter;
+static struct wl_list output_list;
+int min_x, min_y, max_x, max_y;
+int buffer_copy_done;
+
+struct screenshooter_output {
+ struct wl_output *output;
+ struct wl_buffer *buffer;
+ int width, height, offset_x, offset_y;
+ void *data;
+ struct wl_list link;
+};
+
+static void
+display_handle_geometry(void *data,
+ struct wl_output *wl_output,
+ int x,
+ int y,
+ int physical_width,
+ int physical_height,
+ int subpixel,
+ const char *make,
+ const char *model,
+ int transform)
+{
+ struct screenshooter_output *output;
+
+ output = wl_output_get_user_data(wl_output);
+
+ if (wl_output == output->output) {
+ output->offset_x = x;
+ output->offset_y = y;
+ }
+}
+
+static void
+display_handle_mode(void *data,
+ struct wl_output *wl_output,
+ uint32_t flags,
+ int width,
+ int height,
+ int refresh)
+{
+ struct screenshooter_output *output;
+
+ output = wl_output_get_user_data(wl_output);
+
+ if (wl_output == output->output && (flags & WL_OUTPUT_MODE_CURRENT)) {
+ output->width = width;
+ output->height = height;
+ }
+}
+
+static const struct wl_output_listener output_listener = {
+ display_handle_geometry,
+ display_handle_mode
+};
+
+static void
+screenshooter_done(void *data, struct weston_screenshooter_mtk *mtk_screenshooter)
+{
+ fprintf(stderr, "screenshooter_done\n");
+ buffer_copy_done = 1;
+}
+
+static const struct weston_screenshooter_mtk_listener screenshooter_mtk_listener =
+{
+ screenshooter_done
+};
+
+static void
+handle_global(void *data, struct wl_registry *registry,
+ uint32_t name, const char *interface, uint32_t version)
+{
+ static struct screenshooter_output *output;
+
+ if (strcmp(interface, "wl_output") == 0) {
+ output = xmalloc(sizeof *output);
+ output->output = wl_registry_bind(registry, name,
+ &wl_output_interface, 1);
+ wl_list_insert(&output_list, &output->link);
+ wl_output_add_listener(output->output, &output_listener, output);
+ } else if (strcmp(interface, "wl_shm") == 0) {
+ shm = wl_registry_bind(registry, name, &wl_shm_interface, 1);
+ } else if (strcmp(interface, "weston_screenshooter_mtk") == 0) {
+ mtk_screenshooter = wl_registry_bind(registry, name,
+ &weston_screenshooter_mtk_interface,
+ 1);
+ }
+}
+
+static void
+handle_global_remove(void *data, struct wl_registry *registry, uint32_t name)
+{
+ /* XXX: unimplemented */
+}
+
+static const struct wl_registry_listener registry_listener = {
+ handle_global,
+ handle_global_remove
+};
+
+static struct wl_buffer *
+create_shm_buffer(int width, int height, void **data_out)
+{
+ struct wl_shm_pool *pool;
+ struct wl_buffer *buffer;
+ int fd, size, stride;
+ void *data;
+
+ stride = width * 4;
+ size = stride * height;
+
+ fd = os_create_anonymous_file(size);
+ if (fd < 0) {
+ fprintf(stderr, "creating a buffer file for %d B failed: %m\n",
+ size);
+ return NULL;
+ }
+
+ data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+ if (data == MAP_FAILED) {
+ fprintf(stderr, "mmap failed: %m\n");
+ close(fd);
+ return NULL;
+ }
+
+ pool = wl_shm_create_pool(shm, fd, size);
+ close(fd);
+ buffer = wl_shm_pool_create_buffer(pool, 0, width, height, stride,
+ WL_SHM_FORMAT_XRGB8888);
+ wl_shm_pool_destroy(pool);
+
+ *data_out = data;
+ fprintf(stderr,"create_shm_buffer\n");
+ return buffer;
+}
+
+static void
+usage(int error_code)
+{
+ fprintf(stderr, "Usage: simple-screenshooter-mtk [OPTIONS]\n\n"
+ " -m dump mainscreen\n"
+ " -s dump subscreen\n"
+ " -h This help text! default dump all screens\n\n");
+
+ exit(error_code);
+}
+
+int main(int argc, char *argv[])
+{
+ struct wl_display *display;
+ struct wl_registry *registry;
+ struct screenshooter_output *output;
+ int i, width, height;
+ int mainscreen=0;
+ int subscreen=0;
+ for (i = 1; i < argc; i++) {
+ if (strcmp("-m", argv[i]) == 0)
+ mainscreen = 1;
+ else if (strcmp("-s", argv[i]) == 0)
+ subscreen = 1;
+ else if (strcmp("-h", argv[i]) == 0)
+ usage(EXIT_SUCCESS);
+ else
+ usage(EXIT_SUCCESS);
+ }
+
+ display = wl_display_connect(NULL);
+ if (display == NULL) {
+ fprintf(stderr, "failed to create display: %m\n");
+ return -1;
+ }
+
+ wl_list_init(&output_list);
+ registry = wl_display_get_registry(display);
+ wl_registry_add_listener(registry, &registry_listener, NULL);
+ wl_display_dispatch(display);
+ wl_display_roundtrip(display);
+ if (mtk_screenshooter == NULL) {
+ fprintf(stderr, "display doesn't support screenshooter\n");
+ return -1;
+ }
+
+ weston_screenshooter_mtk_add_listener(mtk_screenshooter,
+ &screenshooter_mtk_listener,
+ NULL);
+
+ wl_list_for_each_reverse(output, &output_list, link) {
+ if(mainscreen == 1) {
+ output->buffer = create_shm_buffer(1920, 1080, &output->data);
+ weston_screenshooter_mtk_shoot(mtk_screenshooter,output->output,output->buffer);
+ buffer_copy_done = 0;
+ while (!buffer_copy_done)
+ wl_display_roundtrip(display);
+
+ break;
+ }
+ else if(subscreen == 1) {
+ subscreen = 0;
+ }
+ else {
+ output->buffer = create_shm_buffer(1920, 1080, &output->data);
+ weston_screenshooter_mtk_shoot(mtk_screenshooter,output->output,output->buffer);
+ buffer_copy_done = 0;
+ while (!buffer_copy_done)
+ wl_display_roundtrip(display);
+ }
+ }
+ fprintf(stderr,"end!!!!!\n");
+ return 0;
+}
diff --git a/libweston/compositor.c b/libweston/compositor.c
index 9deb781..fdf5d25 100644
--- a/libweston/compositor.c
+++ b/libweston/compositor.c
@@ -2756,6 +2756,9 @@ weston_output_schedule_repaint(struct weston_output *output)
compositor->state == WESTON_COMPOSITOR_OFFSCREEN)
return;
+ if(output->screenshoot_needed)
+ output->screenshoot_dump = 1;
+
if (!output->repaint_needed)
TL_POINT("core_repaint_req", TLP_OUTPUT(output), TLP_END);
diff --git a/libweston/compositor.h b/libweston/compositor.h
index 8b7a102..8736691 100644
--- a/libweston/compositor.h
+++ b/libweston/compositor.h
@@ -238,6 +238,9 @@ struct weston_output {
REPAINT_AWAITING_COMPLETION, /**< last repaint not yet finished */
} repaint_status;
+ int screenshoot_needed;
+ int screenshoot_dump;
+
/** If repaint_status is REPAINT_SCHEDULED, contains the time the
* next repaint should be run */
struct timespec next_repaint;
diff --git a/libweston/pixel-formats.c b/libweston/pixel-formats.c
index df84a9f..b45db93 100644
--- a/libweston/pixel-formats.c
+++ b/libweston/pixel-formats.c
@@ -145,6 +145,8 @@ static const struct pixel_format_info pixel_format_table[] = {
},
{
.format = DRM_FORMAT_RGB888,
+ .depth = 24,
+ .bpp = 24,
},
{
.format = DRM_FORMAT_BGR888,
diff --git a/libweston/weston-screenshooter-mtk.c b/libweston/weston-screenshooter-mtk.c
new file mode 100644
index 0000000..7ad8f97
--- /dev/null
+++ b/libweston/weston-screenshooter-mtk.c
@@ -0,0 +1,129 @@
+/*
+ * Copyright © 2008-2011 Kristian Høgsberg
+ *
+ * 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 (including the
+ * next paragraph) 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 "config.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <linux/input.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/uio.h>
+
+#include "compositor.h"
+#include "weston-configure-mtk-server-protocol.h"
+#include "shared/helpers.h"
+
+#include "wcap/wcap-decode.h"
+
+struct screenshooter {
+ struct weston_compositor *ec;
+ struct wl_global *global;
+ struct wl_client *client;
+ //struct weston_process process;
+ struct wl_listener destroy_listener;
+};
+
+struct screenshooter_frame_listener {
+ struct wl_listener listener;
+ struct weston_buffer *buffer;
+ weston_screenshooter_done_func_t done;
+ void *data;
+};
+
+static void
+weston_screenshooter_mtk_shoot(struct wl_client *client,
+ struct wl_resource *resource,
+ struct wl_resource *output_resource,
+ struct wl_resource *buffer_resource)
+{
+ struct weston_output *output =
+ wl_resource_get_user_data(output_resource);
+ struct weston_buffer *buffer =
+ weston_buffer_from_resource(buffer_resource);
+ weston_log("weston_screenshooter_mtk_shoot.\n");
+ output->screenshoot_needed = 1;
+ weston_output_schedule_repaint(output);
+ if (buffer == NULL) {
+ wl_resource_post_no_memory(resource);
+ return;
+ }
+
+ weston_screenshooter_mtk_send_done(resource);
+}
+
+static const struct weston_screenshooter_mtk_interface screenshooter_mtk_implementation = {
+ weston_screenshooter_mtk_shoot
+};
+
+static void
+bind_screenshooter_mtk(struct wl_client *client,
+ void *data, uint32_t version, uint32_t id)
+{
+ struct screenshooter *shooter = data;
+ struct wl_resource *resource;
+
+ resource = wl_resource_create(client,
+ &weston_screenshooter_mtk_interface, 1, id);
+
+ if (resource == NULL) {
+ wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
+ "screenshooter failed: permission denied");
+ wl_client_post_no_memory(client);
+ return;
+ }
+
+ wl_resource_set_implementation(resource, &screenshooter_mtk_implementation,
+ data, NULL);
+}
+
+static void
+screenshooter_destroy(struct wl_listener *listener, void *data)
+{
+ struct screenshooter *shooter =
+ container_of(listener, struct screenshooter, destroy_listener);
+
+ wl_global_destroy(shooter->global);
+ free(shooter);
+}
+
+WL_EXPORT void
+screenshooter_mtk_create(struct weston_compositor *ec)
+{
+ struct screenshooter *shooter;
+
+ shooter = malloc(sizeof *shooter);
+ if (shooter == NULL)
+ return;
+
+ shooter->ec = ec;
+ shooter->global = wl_global_create(ec->wl_display,
+ &weston_screenshooter_mtk_interface, 1,
+ shooter, bind_screenshooter_mtk);
+
+ shooter->destroy_listener.notify = screenshooter_destroy;
+ wl_signal_add(&ec->destroy_signal, &shooter->destroy_listener);
+}
diff --git a/protocol/weston-configure-mtk.xml b/protocol/weston-configure-mtk.xml
new file mode 100644
index 0000000..120e904
--- /dev/null
+++ b/protocol/weston-configure-mtk.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<protocol name="weston_configure_mtk">
+
+ <copyright>
+ Copyright (C) 2016 MediaTek
+
+ 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 (including the next
+ paragraph) 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.
+ </copyright>
+
+ <interface name="weston_screenshooter_mtk" version="1">
+ <request name="shoot">
+ <arg name="output" type="object" interface="wl_output"/>
+ <arg name="buffer" type="object" interface="wl_buffer"/>
+ </request>
+ <event name="done">
+ </event>
+ </interface>
+
+ <interface name="config_switch_set" version="1">
+ <description summary="app interface for setting configure for the surface"/>
+
+ <request name="sprite_switch">
+ <description summary="setting the surface configure">
+ This set view matched with the surface to show in overlay plane if
+ overlay planes are available.Otherwise, it walk primary plane to
+ render, and then send to drm to show.
+ </description>
+ <arg name="sprite_switch" type="int"/>
+ </request>
+ </interface>
+
+ <interface name="config_switch" version="1">
+ <description summary="create app configure path for setting parameter">
+ This interface is exposed as a global singleton.
+ This interface is implemented by server, it mainly provide channel to allow
+ client to control some properties.
+ </description>
+
+ <request name="connect">
+ <description summary="connect to server for setting parameter">
+ This request gives client way to connect server.In fact, parameters set by
+ app all through wl_surface because this is only way can be transmit by app.
+ </description>
+ <arg name="surface" type="object" interface="wl_surface" allow-null="true"/>
+ <arg name="id" type="new_id" interface="config_switch_set"/>
+ </request>
+ </interface>
+
+</protocol>
--
2.6.4