2 * Copyright © 2020 Collabora, Ltd.
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial
14 * portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 #include "ivi-compositor.h"
27 #include "shared/helpers.h"
29 #include <libweston/libweston.h>
30 #include "agl-screenshooter-server-protocol.h"
31 #include <libweston/weston-log.h>
33 struct screenshooter {
34 struct ivi_compositor *ivi;
35 struct wl_global *global;
36 struct wl_client *client;
37 struct wl_listener destroy_listener;
41 screenshooter_done(void *data, enum weston_screenshooter_outcome outcome)
43 struct wl_resource *resource = data;
45 if (outcome == WESTON_SCREENSHOOTER_NO_MEMORY) {
46 wl_resource_post_no_memory(resource);
50 agl_screenshooter_send_done(resource, outcome);
54 screenshooter_shoot(struct wl_client *client,
55 struct wl_resource *resource,
56 struct wl_resource *output_resource,
57 struct wl_resource *buffer_resource)
59 struct weston_output *output =
60 weston_head_from_resource(output_resource)->output;
61 struct weston_buffer *buffer =
62 weston_buffer_from_resource(buffer_resource);
65 wl_resource_post_no_memory(resource);
69 weston_screenshooter_shoot(output, buffer, screenshooter_done, resource);
73 screenshooter_destructor_destroy(struct wl_client *client,
74 struct wl_resource *global_resource)
76 wl_resource_destroy(global_resource);
79 struct agl_screenshooter_interface screenshooter_implementation = {
81 screenshooter_destructor_destroy
85 bind_shooter(struct wl_client *client,
86 void *data, uint32_t version, uint32_t id)
88 struct screenshooter *shooter = data;
89 struct wl_resource *resource;
90 bool debug_enabled = true;
92 resource = wl_resource_create(client,
93 &agl_screenshooter_interface, 1, id);
95 if (!debug_enabled && !shooter->client) {
96 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
97 "screenshooter failed: permission denied. "\
98 "Debug must be enabled");
102 wl_resource_set_implementation(resource, &screenshooter_implementation,
107 screenshooter_destroy(struct wl_listener *listener, void *data)
109 struct screenshooter *shooter =
110 container_of(listener, struct screenshooter, destroy_listener);
112 wl_list_remove(&shooter->destroy_listener.link);
114 wl_global_destroy(shooter->global);
119 ivi_screenshooter_create(struct ivi_compositor *ivi)
121 struct weston_compositor *ec = ivi->compositor;
122 struct screenshooter *shooter;
124 shooter = zalloc(sizeof(*shooter));
129 shooter->global = wl_global_create(ec->wl_display,
130 &agl_screenshooter_interface, 1,
131 shooter, bind_shooter);
133 shooter->destroy_listener.notify = screenshooter_destroy;
134 wl_signal_add(&ec->destroy_signal, &shooter->destroy_listener);
136 weston_log("Screenshooter interface created\n");