blob: ee1ccf652d3545520cf73d09fe595f147ea8df47 [file] [log] [blame]
Kristian Høgsbergfc783d42010-06-11 12:56:24 -04001/*
2 * Copyright © 2008 Kristian Høgsberg
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19#include <stdlib.h>
Kristian Høgsbergfc783d42010-06-11 12:56:24 -040020
21#include "compositor.h"
Kristian Høgsbergc5dcb902010-09-14 15:53:32 -040022#include "screenshooter-server-protocol.h"
Kristian Høgsbergfc783d42010-06-11 12:56:24 -040023
Kristian Høgsbergcf57dc52011-04-18 10:33:25 -040024struct screenshooter {
Kristian Høgsbergfc783d42010-06-11 12:56:24 -040025 struct wl_object base;
26 struct wlsc_compositor *ec;
27};
28
Kristian Høgsbergfc783d42010-06-11 12:56:24 -040029static void
Kristian Høgsberg85449032011-05-02 12:11:07 -040030screenshooter_shoot(struct wl_client *client,
31 struct screenshooter *shooter,
32 struct wl_output *output_base, struct wl_buffer *buffer)
Kristian Høgsbergfc783d42010-06-11 12:56:24 -040033{
Kristian Høgsberg85449032011-05-02 12:11:07 -040034 struct wlsc_output *output = (struct wlsc_output *) output_base;
Kristian Høgsbergfc783d42010-06-11 12:56:24 -040035
Kristian Høgsberg85449032011-05-02 12:11:07 -040036 if (!wl_buffer_is_shm(buffer))
37 return;
Kristian Høgsbergfc783d42010-06-11 12:56:24 -040038
Kristian Høgsberg85449032011-05-02 12:11:07 -040039 if (buffer->width < output->width || buffer->height < output->height)
40 return;
Kristian Høgsbergfc783d42010-06-11 12:56:24 -040041
Kristian Høgsberg85449032011-05-02 12:11:07 -040042 glPixelStorei(GL_PACK_ALIGNMENT, 1);
43 glReadPixels(0, 0, output->width, output->height,
44 GL_RGBA, GL_UNSIGNED_BYTE,
45 wl_shm_buffer_get_data(buffer));
Kristian Høgsbergfc783d42010-06-11 12:56:24 -040046}
47
Kristian Høgsbergcf57dc52011-04-18 10:33:25 -040048struct screenshooter_interface screenshooter_implementation = {
Kristian Høgsbergfc783d42010-06-11 12:56:24 -040049 screenshooter_shoot
50};
51
52void
53screenshooter_create(struct wlsc_compositor *ec)
54{
Kristian Høgsbergcf57dc52011-04-18 10:33:25 -040055 struct screenshooter *shooter;
Kristian Høgsbergfc783d42010-06-11 12:56:24 -040056
57 shooter = malloc(sizeof *shooter);
58 if (shooter == NULL)
59 return;
60
Kristian Høgsbergcf57dc52011-04-18 10:33:25 -040061 shooter->base.interface = &screenshooter_interface;
Kristian Høgsbergfc783d42010-06-11 12:56:24 -040062 shooter->base.implementation =
63 (void(**)(void)) &screenshooter_implementation;
64 shooter->ec = ec;
65
66 wl_display_add_object(ec->wl_display, &shooter->base);
67 wl_display_add_global(ec->wl_display, &shooter->base, NULL);
68};