You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
393 lines
9.8 KiB
393 lines
9.8 KiB
12 years ago
|
/*
|
||
|
* Copyright © 2010-2011 Benjamin Franzke
|
||
|
* Copyright © 2012 Intel Corporation
|
||
|
*
|
||
10 years ago
|
* 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:
|
||
12 years ago
|
*
|
||
10 years ago
|
* 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.
|
||
12 years ago
|
*/
|
||
|
|
||
12 years ago
|
#include "config.h"
|
||
12 years ago
|
|
||
8 years ago
|
#include <assert.h>
|
||
9 years ago
|
#include <stdint.h>
|
||
12 years ago
|
#include <stdlib.h>
|
||
|
#include <string.h>
|
||
|
#include <sys/time.h>
|
||
10 years ago
|
#include <stdbool.h>
|
||
12 years ago
|
|
||
6 years ago
|
#include <libweston/libweston.h>
|
||
6 years ago
|
#include <libweston/backend-headless.h>
|
||
9 years ago
|
#include "shared/helpers.h"
|
||
6 years ago
|
#include "linux-explicit-synchronization.h"
|
||
10 years ago
|
#include "pixman-renderer.h"
|
||
9 years ago
|
#include "presentation-time-server-protocol.h"
|
||
6 years ago
|
#include <libweston/windowed-output-api.h>
|
||
12 years ago
|
|
||
10 years ago
|
struct headless_backend {
|
||
|
struct weston_backend base;
|
||
|
struct weston_compositor *compositor;
|
||
9 years ago
|
|
||
12 years ago
|
struct weston_seat fake_seat;
|
||
10 years ago
|
bool use_pixman;
|
||
12 years ago
|
};
|
||
|
|
||
7 years ago
|
struct headless_head {
|
||
|
struct weston_head base;
|
||
|
};
|
||
|
|
||
12 years ago
|
struct headless_output {
|
||
|
struct weston_output base;
|
||
9 years ago
|
|
||
12 years ago
|
struct weston_mode mode;
|
||
|
struct wl_event_source *finish_frame_timer;
|
||
10 years ago
|
uint32_t *image_buf;
|
||
|
pixman_image_t *image;
|
||
12 years ago
|
};
|
||
|
|
||
7 years ago
|
static inline struct headless_head *
|
||
|
to_headless_head(struct weston_head *base)
|
||
|
{
|
||
|
return container_of(base, struct headless_head, base);
|
||
|
}
|
||
|
|
||
9 years ago
|
static inline struct headless_output *
|
||
|
to_headless_output(struct weston_output *base)
|
||
|
{
|
||
|
return container_of(base, struct headless_output, base);
|
||
|
}
|
||
|
|
||
|
static inline struct headless_backend *
|
||
|
to_headless_backend(struct weston_compositor *base)
|
||
|
{
|
||
|
return container_of(base->backend, struct headless_backend, base);
|
||
|
}
|
||
|
|
||
12 years ago
|
static void
|
||
|
headless_output_start_repaint_loop(struct weston_output *output)
|
||
12 years ago
|
{
|
||
10 years ago
|
struct timespec ts;
|
||
12 years ago
|
|
||
10 years ago
|
weston_compositor_read_presentation_clock(output->compositor, &ts);
|
||
9 years ago
|
weston_output_finish_frame(output, &ts, WP_PRESENTATION_FEEDBACK_INVALID);
|
||
12 years ago
|
}
|
||
|
|
||
|
static int
|
||
|
finish_frame_handler(void *data)
|
||
|
{
|
||
10 years ago
|
struct headless_output *output = data;
|
||
|
struct timespec ts;
|
||
|
|
||
10 years ago
|
weston_compositor_read_presentation_clock(output->base.compositor, &ts);
|
||
10 years ago
|
weston_output_finish_frame(&output->base, &ts, 0);
|
||
12 years ago
|
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
11 years ago
|
static int
|
||
12 years ago
|
headless_output_repaint(struct weston_output *output_base,
|
||
8 years ago
|
pixman_region32_t *damage,
|
||
|
void *repaint_data)
|
||
12 years ago
|
{
|
||
9 years ago
|
struct headless_output *output = to_headless_output(output_base);
|
||
12 years ago
|
struct weston_compositor *ec = output->base.compositor;
|
||
|
|
||
|
ec->renderer->repaint_output(&output->base, damage);
|
||
|
|
||
12 years ago
|
pixman_region32_subtract(&ec->primary_plane.damage,
|
||
|
&ec->primary_plane.damage, damage);
|
||
|
|
||
12 years ago
|
wl_event_source_timer_update(output->finish_frame_timer, 16);
|
||
|
|
||
11 years ago
|
return 0;
|
||
12 years ago
|
}
|
||
|
|
||
8 years ago
|
static int
|
||
|
headless_output_disable(struct weston_output *base)
|
||
12 years ago
|
{
|
||
8 years ago
|
struct headless_output *output = to_headless_output(base);
|
||
|
struct headless_backend *b = to_headless_backend(base->compositor);
|
||
|
|
||
|
if (!output->base.enabled)
|
||
|
return 0;
|
||
12 years ago
|
|
||
|
wl_event_source_remove(output->finish_frame_timer);
|
||
10 years ago
|
|
||
10 years ago
|
if (b->use_pixman) {
|
||
10 years ago
|
pixman_renderer_output_destroy(&output->base);
|
||
|
pixman_image_unref(output->image);
|
||
|
free(output->image_buf);
|
||
|
}
|
||
|
|
||
8 years ago
|
return 0;
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
headless_output_destroy(struct weston_output *base)
|
||
|
{
|
||
|
struct headless_output *output = to_headless_output(base);
|
||
|
|
||
|
headless_output_disable(&output->base);
|
||
7 years ago
|
weston_output_release(&output->base);
|
||
10 years ago
|
|
||
12 years ago
|
free(output);
|
||
|
}
|
||
|
|
||
|
static int
|
||
8 years ago
|
headless_output_enable(struct weston_output *base)
|
||
12 years ago
|
{
|
||
8 years ago
|
struct headless_output *output = to_headless_output(base);
|
||
|
struct headless_backend *b = to_headless_backend(base->compositor);
|
||
12 years ago
|
struct wl_event_loop *loop;
|
||
|
|
||
8 years ago
|
loop = wl_display_get_event_loop(b->compositor->wl_display);
|
||
|
output->finish_frame_timer =
|
||
|
wl_event_loop_add_timer(loop, finish_frame_handler, output);
|
||
|
|
||
|
if (b->use_pixman) {
|
||
|
output->image_buf = malloc(output->base.current_mode->width *
|
||
|
output->base.current_mode->height * 4);
|
||
|
if (!output->image_buf)
|
||
|
goto err_malloc;
|
||
|
|
||
|
output->image = pixman_image_create_bits(PIXMAN_x8r8g8b8,
|
||
|
output->base.current_mode->width,
|
||
|
output->base.current_mode->height,
|
||
|
output->image_buf,
|
||
|
output->base.current_mode->width * 4);
|
||
|
|
||
7 years ago
|
if (pixman_renderer_output_create(&output->base,
|
||
|
PIXMAN_RENDERER_OUTPUT_USE_SHADOW) < 0)
|
||
8 years ago
|
goto err_renderer;
|
||
|
|
||
|
pixman_renderer_output_set_buffer(&output->base,
|
||
|
output->image);
|
||
|
}
|
||
|
|
||
|
return 0;
|
||
|
|
||
|
err_renderer:
|
||
|
pixman_image_unref(output->image);
|
||
|
free(output->image_buf);
|
||
|
err_malloc:
|
||
|
wl_event_source_remove(output->finish_frame_timer);
|
||
|
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
static int
|
||
|
headless_output_set_size(struct weston_output *base,
|
||
|
int width, int height)
|
||
|
{
|
||
|
struct headless_output *output = to_headless_output(base);
|
||
7 years ago
|
struct weston_head *head;
|
||
8 years ago
|
int output_width, output_height;
|
||
|
|
||
|
/* We can only be called once. */
|
||
|
assert(!output->base.current_mode);
|
||
|
|
||
|
/* Make sure we have scale set. */
|
||
|
assert(output->base.scale);
|
||
|
|
||
7 years ago
|
wl_list_for_each(head, &output->base.head_list, output_link) {
|
||
|
weston_head_set_monitor_strings(head, "weston", "headless",
|
||
|
NULL);
|
||
|
|
||
|
/* XXX: Calculate proper size. */
|
||
|
weston_head_set_physical_size(head, width, height);
|
||
|
}
|
||
|
|
||
8 years ago
|
output_width = width * output->base.scale;
|
||
|
output_height = height * output->base.scale;
|
||
12 years ago
|
|
||
|
output->mode.flags =
|
||
|
WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED;
|
||
8 years ago
|
output->mode.width = output_width;
|
||
|
output->mode.height = output_height;
|
||
11 years ago
|
output->mode.refresh = 60000;
|
||
12 years ago
|
wl_list_insert(&output->base.mode_list, &output->mode.link);
|
||
|
|
||
11 years ago
|
output->base.current_mode = &output->mode;
|
||
8 years ago
|
|
||
12 years ago
|
output->base.start_repaint_loop = headless_output_start_repaint_loop;
|
||
12 years ago
|
output->base.repaint = headless_output_repaint;
|
||
|
output->base.assign_planes = NULL;
|
||
|
output->base.set_backlight = NULL;
|
||
|
output->base.set_dpms = NULL;
|
||
|
output->base.switch_mode = NULL;
|
||
|
|
||
8 years ago
|
return 0;
|
||
|
}
|
||
10 years ago
|
|
||
7 years ago
|
static struct weston_output *
|
||
|
headless_output_create(struct weston_compositor *compositor, const char *name)
|
||
8 years ago
|
{
|
||
|
struct headless_output *output;
|
||
10 years ago
|
|
||
8 years ago
|
/* name can't be NULL. */
|
||
|
assert(name);
|
||
10 years ago
|
|
||
8 years ago
|
output = zalloc(sizeof *output);
|
||
7 years ago
|
if (!output)
|
||
|
return NULL;
|
||
8 years ago
|
|
||
8 years ago
|
weston_output_init(&output->base, compositor, name);
|
||
|
|
||
8 years ago
|
output->base.destroy = headless_output_destroy;
|
||
|
output->base.disable = headless_output_disable;
|
||
|
output->base.enable = headless_output_enable;
|
||
7 years ago
|
output->base.attach_head = NULL;
|
||
10 years ago
|
|
||
8 years ago
|
weston_compositor_add_pending_output(&output->base, compositor);
|
||
12 years ago
|
|
||
7 years ago
|
return &output->base;
|
||
|
}
|
||
|
|
||
|
static int
|
||
|
headless_head_create(struct weston_compositor *compositor,
|
||
|
const char *name)
|
||
|
{
|
||
|
struct headless_head *head;
|
||
|
|
||
|
/* name can't be NULL. */
|
||
|
assert(name);
|
||
|
|
||
|
head = zalloc(sizeof *head);
|
||
|
if (head == NULL)
|
||
|
return -1;
|
||
|
|
||
|
weston_head_init(&head->base, name);
|
||
|
weston_head_set_connection_status(&head->base, true);
|
||
|
|
||
|
/* Ideally all attributes of the head would be set here, so that the
|
||
|
* user has all the information when deciding to create outputs.
|
||
|
* We do not have those until set_size() time through.
|
||
|
*/
|
||
|
|
||
|
weston_compositor_add_head(compositor, &head->base);
|
||
|
|
||
12 years ago
|
return 0;
|
||
|
}
|
||
|
|
||
7 years ago
|
static void
|
||
|
headless_head_destroy(struct headless_head *head)
|
||
|
{
|
||
|
weston_head_release(&head->base);
|
||
|
free(head);
|
||
|
}
|
||
|
|
||
12 years ago
|
static void
|
||
|
headless_destroy(struct weston_compositor *ec)
|
||
|
{
|
||
9 years ago
|
struct headless_backend *b = to_headless_backend(ec);
|
||
7 years ago
|
struct weston_head *base, *next;
|
||
12 years ago
|
|
||
|
weston_compositor_shutdown(ec);
|
||
|
|
||
7 years ago
|
wl_list_for_each_safe(base, next, &ec->head_list, compositor_link)
|
||
|
headless_head_destroy(to_headless_head(base));
|
||
|
|
||
10 years ago
|
free(b);
|
||
12 years ago
|
}
|
||
|
|
||
8 years ago
|
static const struct weston_windowed_output_api api = {
|
||
|
headless_output_set_size,
|
||
7 years ago
|
headless_head_create,
|
||
8 years ago
|
};
|
||
|
|
||
10 years ago
|
static struct headless_backend *
|
||
|
headless_backend_create(struct weston_compositor *compositor,
|
||
9 years ago
|
struct weston_headless_backend_config *config)
|
||
12 years ago
|
{
|
||
10 years ago
|
struct headless_backend *b;
|
||
8 years ago
|
int ret;
|
||
12 years ago
|
|
||
10 years ago
|
b = zalloc(sizeof *b);
|
||
|
if (b == NULL)
|
||
12 years ago
|
return NULL;
|
||
|
|
||
10 years ago
|
b->compositor = compositor;
|
||
7 years ago
|
compositor->backend = &b->base;
|
||
|
|
||
10 years ago
|
if (weston_compositor_set_presentation_clock_software(compositor) < 0)
|
||
|
goto err_free;
|
||
10 years ago
|
|
||
10 years ago
|
b->base.destroy = headless_destroy;
|
||
7 years ago
|
b->base.create_output = headless_output_create;
|
||
12 years ago
|
|
||
9 years ago
|
b->use_pixman = config->use_pixman;
|
||
10 years ago
|
if (b->use_pixman) {
|
||
|
pixman_renderer_init(compositor);
|
||
10 years ago
|
}
|
||
9 years ago
|
|
||
10 years ago
|
if (!b->use_pixman && noop_renderer_init(compositor) < 0)
|
||
11 years ago
|
goto err_input;
|
||
12 years ago
|
|
||
6 years ago
|
/* Support zwp_linux_explicit_synchronization_unstable_v1 to enable
|
||
|
* testing. */
|
||
|
if (linux_explicit_synchronization_setup(compositor) < 0)
|
||
|
goto err_input;
|
||
|
|
||
8 years ago
|
ret = weston_plugin_api_register(compositor, WESTON_WINDOWED_OUTPUT_API_NAME,
|
||
|
&api, sizeof(api));
|
||
|
|
||
|
if (ret < 0) {
|
||
|
weston_log("Failed to register output API.\n");
|
||
|
goto err_input;
|
||
|
}
|
||
|
|
||
10 years ago
|
return b;
|
||
12 years ago
|
|
||
11 years ago
|
err_input:
|
||
10 years ago
|
weston_compositor_shutdown(compositor);
|
||
12 years ago
|
err_free:
|
||
10 years ago
|
free(b);
|
||
12 years ago
|
return NULL;
|
||
|
}
|
||
|
|
||
9 years ago
|
static void
|
||
|
config_init_to_defaults(struct weston_headless_backend_config *config)
|
||
|
{
|
||
|
}
|
||
|
|
||
10 years ago
|
WL_EXPORT int
|
||
8 years ago
|
weston_backend_init(struct weston_compositor *compositor,
|
||
|
struct weston_backend_config *config_base)
|
||
12 years ago
|
{
|
||
10 years ago
|
struct headless_backend *b;
|
||
9 years ago
|
struct weston_headless_backend_config config = {{ 0, }};
|
||
12 years ago
|
|
||
9 years ago
|
if (config_base == NULL ||
|
||
|
config_base->struct_version != WESTON_HEADLESS_BACKEND_CONFIG_VERSION ||
|
||
|
config_base->struct_size > sizeof(struct weston_headless_backend_config)) {
|
||
|
weston_log("headless backend config structure is invalid\n");
|
||
|
return -1;
|
||
|
}
|
||
10 years ago
|
|
||
9 years ago
|
config_init_to_defaults(&config);
|
||
|
memcpy(&config, config_base, config_base->struct_size);
|
||
10 years ago
|
|
||
9 years ago
|
b = headless_backend_create(compositor, &config);
|
||
10 years ago
|
if (b == NULL)
|
||
|
return -1;
|
||
9 years ago
|
|
||
10 years ago
|
return 0;
|
||
12 years ago
|
}
|