2 * Copyright © 2008-2011 Kristian Høgsberg
4 * Permission to use, copy, modify, distribute, and sell this software and
5 * its documentation for any purpose is hereby granted without fee, provided
6 * that the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of the copyright holders not be used in
9 * advertising or publicity pertaining to distribution of the software
10 * without specific, written prior permission. The copyright holders make
11 * no representations about the suitability of this software for any
12 * purpose. It is provided "as is" without express or implied warranty.
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
15 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
17 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
18 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
19 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
25 #include "compositor.h"
26 #include "screenshooter-server-protocol.h"
28 struct screenshooter {
29 struct wl_object base;
30 struct weston_compositor *ec;
34 screenshooter_shoot(struct wl_client *client,
35 struct wl_resource *resource,
36 struct wl_resource *output_resource,
37 struct wl_resource *buffer_resource)
39 struct weston_output *output = output_resource->data;
40 struct wl_buffer *buffer = buffer_resource->data;
42 if (!wl_buffer_is_shm(buffer))
45 if (buffer->width < output->current->width ||
46 buffer->height < output->current->height)
49 glPixelStorei(GL_PACK_ALIGNMENT, 1);
50 glReadPixels(0, 0, output->current->width, output->current->height,
51 GL_RGBA, GL_UNSIGNED_BYTE,
52 wl_shm_buffer_get_data(buffer));
55 struct screenshooter_interface screenshooter_implementation = {
60 bind_shooter(struct wl_client *client,
61 void *data, uint32_t version, uint32_t id)
63 wl_client_add_object(client, &screenshooter_interface,
64 &screenshooter_implementation, id, data);
68 screenshooter_create(struct weston_compositor *ec)
70 struct screenshooter *shooter;
72 shooter = malloc(sizeof *shooter);
76 shooter->base.interface = &screenshooter_interface;
77 shooter->base.implementation =
78 (void(**)(void)) &screenshooter_implementation;
81 wl_display_add_global(ec->wl_display,
82 &screenshooter_interface, shooter, bind_shooter);