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.
5016 lines
133 KiB
5016 lines
133 KiB
16 years ago
|
/*
|
||
13 years ago
|
* Copyright © 2010-2011 Intel Corporation
|
||
|
* Copyright © 2008-2011 Kristian Høgsberg
|
||
10 years ago
|
* Copyright © 2012-2015 Collabora, Ltd.
|
||
16 years ago
|
*
|
||
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:
|
||
16 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.
|
||
16 years ago
|
*/
|
||
|
|
||
14 years ago
|
#include "config.h"
|
||
|
|
||
13 years ago
|
#include <fcntl.h>
|
||
16 years ago
|
#include <stdio.h>
|
||
|
#include <string.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <stdint.h>
|
||
14 years ago
|
#include <limits.h>
|
||
16 years ago
|
#include <stdarg.h>
|
||
14 years ago
|
#include <assert.h>
|
||
16 years ago
|
#include <sys/ioctl.h>
|
||
13 years ago
|
#include <sys/mman.h>
|
||
14 years ago
|
#include <sys/wait.h>
|
||
13 years ago
|
#include <sys/socket.h>
|
||
13 years ago
|
#include <sys/utsname.h>
|
||
13 years ago
|
#include <sys/stat.h>
|
||
16 years ago
|
#include <unistd.h>
|
||
16 years ago
|
#include <math.h>
|
||
15 years ago
|
#include <linux/input.h>
|
||
14 years ago
|
#include <dlfcn.h>
|
||
14 years ago
|
#include <signal.h>
|
||
13 years ago
|
#include <setjmp.h>
|
||
13 years ago
|
#include <sys/time.h>
|
||
|
#include <time.h>
|
||
10 years ago
|
#include <errno.h>
|
||
16 years ago
|
|
||
10 years ago
|
#include "timeline.h"
|
||
|
|
||
15 years ago
|
#include "compositor.h"
|
||
9 years ago
|
#include "viewporter-server-protocol.h"
|
||
9 years ago
|
#include "presentation-time-server-protocol.h"
|
||
10 years ago
|
#include "shared/helpers.h"
|
||
10 years ago
|
#include "shared/os-compatibility.h"
|
||
9 years ago
|
#include "shared/timespec-util.h"
|
||
13 years ago
|
#include "git-version.h"
|
||
12 years ago
|
#include "version.h"
|
||
16 years ago
|
|
||
11 years ago
|
#define DEFAULT_REPAINT_WINDOW 7 /* milliseconds */
|
||
|
|
||
12 years ago
|
static void
|
||
12 years ago
|
weston_output_transform_scale_init(struct weston_output *output,
|
||
|
uint32_t transform, uint32_t scale);
|
||
12 years ago
|
|
||
12 years ago
|
static void
|
||
11 years ago
|
weston_compositor_build_view_list(struct weston_compositor *compositor);
|
||
12 years ago
|
|
||
10 years ago
|
static void weston_mode_switch_finish(struct weston_output *output,
|
||
|
int mode_changed,
|
||
|
int scale_changed)
|
||
13 years ago
|
{
|
||
12 years ago
|
struct weston_seat *seat;
|
||
11 years ago
|
struct wl_resource *resource;
|
||
12 years ago
|
pixman_region32_t old_output_region;
|
||
10 years ago
|
int version;
|
||
12 years ago
|
|
||
12 years ago
|
pixman_region32_init(&old_output_region);
|
||
|
pixman_region32_copy(&old_output_region, &output->region);
|
||
|
|
||
12 years ago
|
/* Update output region and transformation matrix */
|
||
11 years ago
|
weston_output_transform_scale_init(output, output->transform, output->current_scale);
|
||
12 years ago
|
|
||
|
pixman_region32_init(&output->previous_damage);
|
||
|
pixman_region32_init_rect(&output->region, output->x, output->y,
|
||
|
output->width, output->height);
|
||
|
|
||
|
weston_output_update_matrix(output);
|
||
|
|
||
12 years ago
|
/* If a pointer falls outside the outputs new geometry, move it to its
|
||
|
* lower-right corner */
|
||
|
wl_list_for_each(seat, &output->compositor->seat_list, link) {
|
||
9 years ago
|
struct weston_pointer *pointer = weston_seat_get_pointer(seat);
|
||
12 years ago
|
int32_t x, y;
|
||
|
|
||
|
if (!pointer)
|
||
|
continue;
|
||
|
|
||
|
x = wl_fixed_to_int(pointer->x);
|
||
|
y = wl_fixed_to_int(pointer->y);
|
||
|
|
||
|
if (!pixman_region32_contains_point(&old_output_region,
|
||
|
x, y, NULL) ||
|
||
|
pixman_region32_contains_point(&output->region,
|
||
|
x, y, NULL))
|
||
|
continue;
|
||
|
|
||
|
if (x >= output->x + output->width)
|
||
|
x = output->x + output->width - 1;
|
||
|
if (y >= output->y + output->height)
|
||
|
y = output->y + output->height - 1;
|
||
|
|
||
|
pointer->x = wl_fixed_from_int(x);
|
||
|
pointer->y = wl_fixed_from_int(y);
|
||
|
}
|
||
|
|
||
|
pixman_region32_fini(&old_output_region);
|
||
|
|
||
10 years ago
|
if (!mode_changed && !scale_changed)
|
||
|
return;
|
||
|
|
||
11 years ago
|
/* notify clients of the changes */
|
||
10 years ago
|
wl_resource_for_each(resource, &output->resource_list) {
|
||
|
if (mode_changed) {
|
||
|
wl_output_send_mode(resource,
|
||
|
output->current_mode->flags,
|
||
|
output->current_mode->width,
|
||
|
output->current_mode->height,
|
||
|
output->current_mode->refresh);
|
||
|
}
|
||
|
|
||
10 years ago
|
version = wl_resource_get_version(resource);
|
||
|
if (version >= WL_OUTPUT_SCALE_SINCE_VERSION && scale_changed)
|
||
10 years ago
|
wl_output_send_scale(resource, output->current_scale);
|
||
|
|
||
10 years ago
|
if (version >= WL_OUTPUT_DONE_SINCE_VERSION)
|
||
|
wl_output_send_done(resource);
|
||
10 years ago
|
}
|
||
|
}
|
||
|
|
||
9 years ago
|
|
||
|
static void
|
||
|
weston_compositor_reflow_outputs(struct weston_compositor *compositor,
|
||
|
struct weston_output *resized_output, int delta_width);
|
||
|
|
||
10 years ago
|
WL_EXPORT int
|
||
|
weston_output_mode_set_native(struct weston_output *output,
|
||
|
struct weston_mode *mode,
|
||
|
int32_t scale)
|
||
|
{
|
||
|
int ret;
|
||
|
int mode_changed = 0, scale_changed = 0;
|
||
9 years ago
|
int32_t old_width;
|
||
10 years ago
|
|
||
|
if (!output->switch_mode)
|
||
|
return -1;
|
||
|
|
||
|
if (!output->original_mode) {
|
||
|
mode_changed = 1;
|
||
|
ret = output->switch_mode(output, mode);
|
||
|
if (ret < 0)
|
||
|
return ret;
|
||
|
if (output->current_scale != scale) {
|
||
|
scale_changed = 1;
|
||
|
output->current_scale = scale;
|
||
11 years ago
|
}
|
||
|
}
|
||
|
|
||
9 years ago
|
old_width = output->width;
|
||
10 years ago
|
output->native_mode = mode;
|
||
|
output->native_scale = scale;
|
||
|
|
||
|
weston_mode_switch_finish(output, mode_changed, scale_changed);
|
||
|
|
||
9 years ago
|
if (mode_changed || scale_changed) {
|
||
|
weston_compositor_reflow_outputs(output->compositor, output, output->width - old_width);
|
||
|
|
||
|
wl_signal_emit(&output->compositor->output_resized_signal, output);
|
||
|
}
|
||
10 years ago
|
return 0;
|
||
|
}
|
||
|
|
||
|
WL_EXPORT int
|
||
|
weston_output_mode_switch_to_native(struct weston_output *output)
|
||
|
{
|
||
|
int ret;
|
||
|
int mode_changed = 0, scale_changed = 0;
|
||
|
|
||
|
if (!output->switch_mode)
|
||
|
return -1;
|
||
|
|
||
|
if (!output->original_mode) {
|
||
|
weston_log("already in the native mode\n");
|
||
|
return -1;
|
||
|
}
|
||
|
/* the non fullscreen clients haven't seen a mode set since we
|
||
|
* switched into a temporary, so we need to notify them if the
|
||
|
* mode at that time is different from the native mode now.
|
||
|
*/
|
||
|
mode_changed = (output->original_mode != output->native_mode);
|
||
|
scale_changed = (output->original_scale != output->native_scale);
|
||
|
|
||
|
ret = output->switch_mode(output, output->native_mode);
|
||
|
if (ret < 0)
|
||
|
return ret;
|
||
|
|
||
|
output->current_scale = output->native_scale;
|
||
|
|
||
|
output->original_mode = NULL;
|
||
|
output->original_scale = 0;
|
||
|
|
||
|
weston_mode_switch_finish(output, mode_changed, scale_changed);
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
WL_EXPORT int
|
||
|
weston_output_mode_switch_to_temporary(struct weston_output *output,
|
||
|
struct weston_mode *mode,
|
||
|
int32_t scale)
|
||
|
{
|
||
|
int ret;
|
||
|
|
||
|
if (!output->switch_mode)
|
||
|
return -1;
|
||
|
|
||
|
/* original_mode is the last mode non full screen clients have seen,
|
||
|
* so we shouldn't change it if we already have one set.
|
||
|
*/
|
||
|
if (!output->original_mode) {
|
||
|
output->original_mode = output->native_mode;
|
||
|
output->original_scale = output->native_scale;
|
||
|
}
|
||
|
ret = output->switch_mode(output, mode);
|
||
|
if (ret < 0)
|
||
|
return ret;
|
||
|
|
||
|
output->current_scale = scale;
|
||
|
|
||
|
weston_mode_switch_finish(output, 0, 0);
|
||
|
|
||
|
return 0;
|
||
13 years ago
|
}
|
||
|
|
||
13 years ago
|
static void
|
||
12 years ago
|
region_init_infinite(pixman_region32_t *region)
|
||
13 years ago
|
{
|
||
12 years ago
|
pixman_region32_init_rect(region, INT32_MIN, INT32_MIN,
|
||
|
UINT32_MAX, UINT32_MAX);
|
||
13 years ago
|
}
|
||
|
|
||
12 years ago
|
static struct weston_subsurface *
|
||
|
weston_surface_to_subsurface(struct weston_surface *surface);
|
||
|
|
||
11 years ago
|
WL_EXPORT struct weston_view *
|
||
|
weston_view_create(struct weston_surface *surface)
|
||
|
{
|
||
|
struct weston_view *view;
|
||
|
|
||
10 years ago
|
view = zalloc(sizeof *view);
|
||
11 years ago
|
if (view == NULL)
|
||
|
return NULL;
|
||
|
|
||
|
view->surface = surface;
|
||
|
|
||
|
/* Assign to surface */
|
||
|
wl_list_insert(&surface->views, &view->surface_link);
|
||
|
|
||
|
wl_signal_init(&view->destroy_signal);
|
||
|
wl_list_init(&view->link);
|
||
10 years ago
|
wl_list_init(&view->layer_link.link);
|
||
11 years ago
|
|
||
|
pixman_region32_init(&view->clip);
|
||
|
|
||
|
view->alpha = 1.0;
|
||
|
pixman_region32_init(&view->transform.opaque);
|
||
|
|
||
|
wl_list_init(&view->geometry.transformation_list);
|
||
|
wl_list_insert(&view->geometry.transformation_list,
|
||
|
&view->transform.position.link);
|
||
|
weston_matrix_init(&view->transform.position.matrix);
|
||
|
wl_list_init(&view->geometry.child_list);
|
||
10 years ago
|
pixman_region32_init(&view->geometry.scissor);
|
||
11 years ago
|
pixman_region32_init(&view->transform.boundingbox);
|
||
|
view->transform.dirty = 1;
|
||
|
|
||
|
return view;
|
||
|
}
|
||
|
|
||
11 years ago
|
struct weston_frame_callback {
|
||
|
struct wl_resource *resource;
|
||
|
struct wl_list link;
|
||
|
};
|
||
|
|
||
10 years ago
|
struct weston_presentation_feedback {
|
||
|
struct wl_resource *resource;
|
||
|
|
||
|
/* XXX: could use just wl_resource_get_link() instead */
|
||
|
struct wl_list link;
|
||
10 years ago
|
|
||
|
/* The per-surface feedback flags */
|
||
|
uint32_t psf_flags;
|
||
10 years ago
|
};
|
||
|
|
||
|
static void
|
||
|
weston_presentation_feedback_discard(
|
||
|
struct weston_presentation_feedback *feedback)
|
||
|
{
|
||
9 years ago
|
wp_presentation_feedback_send_discarded(feedback->resource);
|
||
10 years ago
|
wl_resource_destroy(feedback->resource);
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
weston_presentation_feedback_discard_list(struct wl_list *list)
|
||
|
{
|
||
|
struct weston_presentation_feedback *feedback, *tmp;
|
||
|
|
||
|
wl_list_for_each_safe(feedback, tmp, list, link)
|
||
|
weston_presentation_feedback_discard(feedback);
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
weston_presentation_feedback_present(
|
||
|
struct weston_presentation_feedback *feedback,
|
||
|
struct weston_output *output,
|
||
|
uint32_t refresh_nsec,
|
||
|
const struct timespec *ts,
|
||
10 years ago
|
uint64_t seq,
|
||
|
uint32_t flags)
|
||
10 years ago
|
{
|
||
|
struct wl_client *client = wl_resource_get_client(feedback->resource);
|
||
|
struct wl_resource *o;
|
||
|
uint64_t secs;
|
||
|
|
||
|
wl_resource_for_each(o, &output->resource_list) {
|
||
|
if (wl_resource_get_client(o) != client)
|
||
|
continue;
|
||
|
|
||
9 years ago
|
wp_presentation_feedback_send_sync_output(feedback->resource, o);
|
||
10 years ago
|
}
|
||
|
|
||
|
secs = ts->tv_sec;
|
||
9 years ago
|
wp_presentation_feedback_send_presented(feedback->resource,
|
||
|
secs >> 32, secs & 0xffffffff,
|
||
|
ts->tv_nsec,
|
||
|
refresh_nsec,
|
||
|
seq >> 32, seq & 0xffffffff,
|
||
|
flags | feedback->psf_flags);
|
||
10 years ago
|
wl_resource_destroy(feedback->resource);
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
weston_presentation_feedback_present_list(struct wl_list *list,
|
||
|
struct weston_output *output,
|
||
|
uint32_t refresh_nsec,
|
||
|
const struct timespec *ts,
|
||
10 years ago
|
uint64_t seq,
|
||
|
uint32_t flags)
|
||
10 years ago
|
{
|
||
|
struct weston_presentation_feedback *feedback, *tmp;
|
||
|
|
||
9 years ago
|
assert(!(flags & WP_PRESENTATION_FEEDBACK_INVALID) ||
|
||
10 years ago
|
wl_list_empty(list));
|
||
|
|
||
10 years ago
|
wl_list_for_each_safe(feedback, tmp, list, link)
|
||
|
weston_presentation_feedback_present(feedback, output,
|
||
10 years ago
|
refresh_nsec, ts, seq,
|
||
|
flags);
|
||
10 years ago
|
}
|
||
|
|
||
11 years ago
|
static void
|
||
|
surface_state_handle_buffer_destroy(struct wl_listener *listener, void *data)
|
||
|
{
|
||
|
struct weston_surface_state *state =
|
||
|
container_of(listener, struct weston_surface_state,
|
||
|
buffer_destroy_listener);
|
||
|
|
||
|
state->buffer = NULL;
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
weston_surface_state_init(struct weston_surface_state *state)
|
||
|
{
|
||
|
state->newly_attached = 0;
|
||
|
state->buffer = NULL;
|
||
|
state->buffer_destroy_listener.notify =
|
||
|
surface_state_handle_buffer_destroy;
|
||
|
state->sx = 0;
|
||
|
state->sy = 0;
|
||
|
|
||
9 years ago
|
pixman_region32_init(&state->damage_surface);
|
||
|
pixman_region32_init(&state->damage_buffer);
|
||
11 years ago
|
pixman_region32_init(&state->opaque);
|
||
|
region_init_infinite(&state->input);
|
||
|
|
||
|
wl_list_init(&state->frame_callback_list);
|
||
10 years ago
|
wl_list_init(&state->feedback_list);
|
||
11 years ago
|
|
||
|
state->buffer_viewport.buffer.transform = WL_OUTPUT_TRANSFORM_NORMAL;
|
||
|
state->buffer_viewport.buffer.scale = 1;
|
||
|
state->buffer_viewport.buffer.src_width = wl_fixed_from_int(-1);
|
||
|
state->buffer_viewport.surface.width = -1;
|
||
|
state->buffer_viewport.changed = 0;
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
weston_surface_state_fini(struct weston_surface_state *state)
|
||
|
{
|
||
|
struct weston_frame_callback *cb, *next;
|
||
|
|
||
|
wl_list_for_each_safe(cb, next,
|
||
|
&state->frame_callback_list, link)
|
||
|
wl_resource_destroy(cb->resource);
|
||
|
|
||
10 years ago
|
weston_presentation_feedback_discard_list(&state->feedback_list);
|
||
|
|
||
11 years ago
|
pixman_region32_fini(&state->input);
|
||
|
pixman_region32_fini(&state->opaque);
|
||
9 years ago
|
pixman_region32_fini(&state->damage_surface);
|
||
|
pixman_region32_fini(&state->damage_buffer);
|
||
11 years ago
|
|
||
|
if (state->buffer)
|
||
|
wl_list_remove(&state->buffer_destroy_listener.link);
|
||
|
state->buffer = NULL;
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
weston_surface_state_set_buffer(struct weston_surface_state *state,
|
||
|
struct weston_buffer *buffer)
|
||
|
{
|
||
|
if (state->buffer == buffer)
|
||
|
return;
|
||
|
|
||
|
if (state->buffer)
|
||
|
wl_list_remove(&state->buffer_destroy_listener.link);
|
||
|
state->buffer = buffer;
|
||
|
if (state->buffer)
|
||
|
wl_signal_add(&state->buffer->destroy_signal,
|
||
|
&state->buffer_destroy_listener);
|
||
|
}
|
||
|
|
||
13 years ago
|
WL_EXPORT struct weston_surface *
|
||
13 years ago
|
weston_surface_create(struct weston_compositor *compositor)
|
||
16 years ago
|
{
|
||
13 years ago
|
struct weston_surface *surface;
|
||
14 years ago
|
|
||
10 years ago
|
surface = zalloc(sizeof *surface);
|
||
14 years ago
|
if (surface == NULL)
|
||
|
return NULL;
|
||
|
|
||
12 years ago
|
wl_signal_init(&surface->destroy_signal);
|
||
|
|
||
16 years ago
|
surface->compositor = compositor;
|
||
11 years ago
|
surface->ref_count = 1;
|
||
15 years ago
|
|
||
11 years ago
|
surface->buffer_viewport.buffer.transform = WL_OUTPUT_TRANSFORM_NORMAL;
|
||
|
surface->buffer_viewport.buffer.scale = 1;
|
||
11 years ago
|
surface->buffer_viewport.buffer.src_width = wl_fixed_from_int(-1);
|
||
|
surface->buffer_viewport.surface.width = -1;
|
||
11 years ago
|
|
||
|
weston_surface_state_init(&surface->pending);
|
||
|
|
||
14 years ago
|
pixman_region32_init(&surface->damage);
|
||
13 years ago
|
pixman_region32_init(&surface->opaque);
|
||
12 years ago
|
region_init_infinite(&surface->input);
|
||
14 years ago
|
|
||
11 years ago
|
wl_list_init(&surface->views);
|
||
|
|
||
|
wl_list_init(&surface->frame_callback_list);
|
||
10 years ago
|
wl_list_init(&surface->feedback_list);
|
||
16 years ago
|
|
||
12 years ago
|
wl_list_init(&surface->subsurface_list);
|
||
|
wl_list_init(&surface->subsurface_list_pending);
|
||
|
|
||
10 years ago
|
weston_matrix_init(&surface->buffer_to_surface_matrix);
|
||
|
weston_matrix_init(&surface->surface_to_buffer_matrix);
|
||
|
|
||
14 years ago
|
return surface;
|
||
16 years ago
|
}
|
||
|
|
||
13 years ago
|
WL_EXPORT void
|
||
13 years ago
|
weston_surface_set_color(struct weston_surface *surface,
|
||
12 years ago
|
float red, float green, float blue, float alpha)
|
||
13 years ago
|
{
|
||
12 years ago
|
surface->compositor->renderer->surface_set_color(surface, red, green, blue, alpha);
|
||
13 years ago
|
}
|
||
|
|
||
13 years ago
|
WL_EXPORT void
|
||
11 years ago
|
weston_view_to_global_float(struct weston_view *view,
|
||
|
float sx, float sy, float *x, float *y)
|
||
13 years ago
|
{
|
||
11 years ago
|
if (view->transform.enabled) {
|
||
13 years ago
|
struct weston_vector v = { { sx, sy, 0.0f, 1.0f } };
|
||
|
|
||
11 years ago
|
weston_matrix_transform(&view->transform.matrix, &v);
|
||
13 years ago
|
|
||
|
if (fabsf(v.f[3]) < 1e-6) {
|
||
13 years ago
|
weston_log("warning: numerical instability in "
|
||
12 years ago
|
"%s(), divisor = %g\n", __func__,
|
||
13 years ago
|
v.f[3]);
|
||
|
*x = 0;
|
||
|
*y = 0;
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
*x = v.f[0] / v.f[3];
|
||
|
*y = v.f[1] / v.f[3];
|
||
|
} else {
|
||
11 years ago
|
*x = sx + view->geometry.x;
|
||
|
*y = sy + view->geometry.y;
|
||
13 years ago
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
WL_EXPORT void
|
||
|
weston_transformed_coord(int width, int height,
|
||
|
enum wl_output_transform transform,
|
||
12 years ago
|
int32_t scale,
|
||
12 years ago
|
float sx, float sy, float *bx, float *by)
|
||
|
{
|
||
|
switch (transform) {
|
||
|
case WL_OUTPUT_TRANSFORM_NORMAL:
|
||
|
default:
|
||
|
*bx = sx;
|
||
|
*by = sy;
|
||
|
break;
|
||
|
case WL_OUTPUT_TRANSFORM_FLIPPED:
|
||
|
*bx = width - sx;
|
||
|
*by = sy;
|
||
|
break;
|
||
|
case WL_OUTPUT_TRANSFORM_90:
|
||
|
*bx = height - sy;
|
||
|
*by = sx;
|
||
|
break;
|
||
|
case WL_OUTPUT_TRANSFORM_FLIPPED_90:
|
||
|
*bx = height - sy;
|
||
|
*by = width - sx;
|
||
|
break;
|
||
|
case WL_OUTPUT_TRANSFORM_180:
|
||
|
*bx = width - sx;
|
||
|
*by = height - sy;
|
||
|
break;
|
||
|
case WL_OUTPUT_TRANSFORM_FLIPPED_180:
|
||
|
*bx = sx;
|
||
|
*by = height - sy;
|
||
|
break;
|
||
|
case WL_OUTPUT_TRANSFORM_270:
|
||
|
*bx = sy;
|
||
|
*by = width - sx;
|
||
|
break;
|
||
|
case WL_OUTPUT_TRANSFORM_FLIPPED_270:
|
||
|
*bx = sy;
|
||
|
*by = sx;
|
||
|
break;
|
||
|
}
|
||
12 years ago
|
|
||
|
*bx *= scale;
|
||
|
*by *= scale;
|
||
12 years ago
|
}
|
||
|
|
||
|
WL_EXPORT pixman_box32_t
|
||
|
weston_transformed_rect(int width, int height,
|
||
|
enum wl_output_transform transform,
|
||
12 years ago
|
int32_t scale,
|
||
12 years ago
|
pixman_box32_t rect)
|
||
|
{
|
||
|
float x1, x2, y1, y2;
|
||
|
|
||
|
pixman_box32_t ret;
|
||
|
|
||
12 years ago
|
weston_transformed_coord(width, height, transform, scale,
|
||
12 years ago
|
rect.x1, rect.y1, &x1, &y1);
|
||
12 years ago
|
weston_transformed_coord(width, height, transform, scale,
|
||
12 years ago
|
rect.x2, rect.y2, &x2, &y2);
|
||
|
|
||
|
if (x1 <= x2) {
|
||
|
ret.x1 = x1;
|
||
|
ret.x2 = x2;
|
||
|
} else {
|
||
|
ret.x1 = x2;
|
||
|
ret.x2 = x1;
|
||
|
}
|
||
|
|
||
|
if (y1 <= y2) {
|
||
|
ret.y1 = y1;
|
||
|
ret.y2 = y2;
|
||
|
} else {
|
||
|
ret.y1 = y2;
|
||
|
ret.y2 = y1;
|
||
|
}
|
||
|
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
9 years ago
|
/** Transform a region by a matrix, restricted to axis-aligned transformations
|
||
|
*
|
||
|
* Warning: This function does not work for projective, affine, or matrices
|
||
|
* that encode arbitrary rotations. Only 90-degree step rotations are
|
||
|
* supported.
|
||
|
*/
|
||
|
WL_EXPORT void
|
||
|
weston_matrix_transform_region(pixman_region32_t *dest,
|
||
|
struct weston_matrix *matrix,
|
||
|
pixman_region32_t *src)
|
||
|
{
|
||
|
pixman_box32_t *src_rects, *dest_rects;
|
||
|
int nrects, i;
|
||
|
|
||
|
src_rects = pixman_region32_rectangles(src, &nrects);
|
||
|
dest_rects = malloc(nrects * sizeof(*dest_rects));
|
||
|
if (!dest_rects)
|
||
|
return;
|
||
|
|
||
|
for (i = 0; i < nrects; i++) {
|
||
|
struct weston_vector vec1 = {{
|
||
|
src_rects[i].x1, src_rects[i].y1, 0, 1
|
||
|
}};
|
||
|
weston_matrix_transform(matrix, &vec1);
|
||
|
vec1.f[0] /= vec1.f[3];
|
||
|
vec1.f[1] /= vec1.f[3];
|
||
|
|
||
|
struct weston_vector vec2 = {{
|
||
|
src_rects[i].x2, src_rects[i].y2, 0, 1
|
||
|
}};
|
||
|
weston_matrix_transform(matrix, &vec2);
|
||
|
vec2.f[0] /= vec2.f[3];
|
||
|
vec2.f[1] /= vec2.f[3];
|
||
|
|
||
|
if (vec1.f[0] < vec2.f[0]) {
|
||
|
dest_rects[i].x1 = floor(vec1.f[0]);
|
||
|
dest_rects[i].x2 = ceil(vec2.f[0]);
|
||
|
} else {
|
||
|
dest_rects[i].x1 = floor(vec2.f[0]);
|
||
|
dest_rects[i].x2 = ceil(vec1.f[0]);
|
||
|
}
|
||
|
|
||
|
if (vec1.f[1] < vec2.f[1]) {
|
||
|
dest_rects[i].y1 = floor(vec1.f[1]);
|
||
|
dest_rects[i].y2 = ceil(vec2.f[1]);
|
||
|
} else {
|
||
|
dest_rects[i].y1 = floor(vec2.f[1]);
|
||
|
dest_rects[i].y2 = ceil(vec1.f[1]);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
pixman_region32_clear(dest);
|
||
|
pixman_region32_init_rects(dest, dest_rects, nrects);
|
||
|
free(dest_rects);
|
||
|
}
|
||
|
|
||
11 years ago
|
WL_EXPORT void
|
||
|
weston_transformed_region(int width, int height,
|
||
|
enum wl_output_transform transform,
|
||
|
int32_t scale,
|
||
|
pixman_region32_t *src, pixman_region32_t *dest)
|
||
|
{
|
||
|
pixman_box32_t *src_rects, *dest_rects;
|
||
|
int nrects, i;
|
||
|
|
||
|
if (transform == WL_OUTPUT_TRANSFORM_NORMAL && scale == 1) {
|
||
|
if (src != dest)
|
||
|
pixman_region32_copy(dest, src);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
src_rects = pixman_region32_rectangles(src, &nrects);
|
||
|
dest_rects = malloc(nrects * sizeof(*dest_rects));
|
||
|
if (!dest_rects)
|
||
|
return;
|
||
|
|
||
|
if (transform == WL_OUTPUT_TRANSFORM_NORMAL) {
|
||
|
memcpy(dest_rects, src_rects, nrects * sizeof(*dest_rects));
|
||
|
} else {
|
||
|
for (i = 0; i < nrects; i++) {
|
||
|
switch (transform) {
|
||
|
default:
|
||
|
case WL_OUTPUT_TRANSFORM_NORMAL:
|
||
|
dest_rects[i].x1 = src_rects[i].x1;
|
||
|
dest_rects[i].y1 = src_rects[i].y1;
|
||
|
dest_rects[i].x2 = src_rects[i].x2;
|
||
|
dest_rects[i].y2 = src_rects[i].y2;
|
||
|
break;
|
||
|
case WL_OUTPUT_TRANSFORM_90:
|
||
|
dest_rects[i].x1 = height - src_rects[i].y2;
|
||
|
dest_rects[i].y1 = src_rects[i].x1;
|
||
|
dest_rects[i].x2 = height - src_rects[i].y1;
|
||
|
dest_rects[i].y2 = src_rects[i].x2;
|
||
|
break;
|
||
|
case WL_OUTPUT_TRANSFORM_180:
|
||
|
dest_rects[i].x1 = width - src_rects[i].x2;
|
||
|
dest_rects[i].y1 = height - src_rects[i].y2;
|
||
|
dest_rects[i].x2 = width - src_rects[i].x1;
|
||
|
dest_rects[i].y2 = height - src_rects[i].y1;
|
||
|
break;
|
||
|
case WL_OUTPUT_TRANSFORM_270:
|
||
|
dest_rects[i].x1 = src_rects[i].y1;
|
||
|
dest_rects[i].y1 = width - src_rects[i].x2;
|
||
|
dest_rects[i].x2 = src_rects[i].y2;
|
||
|
dest_rects[i].y2 = width - src_rects[i].x1;
|
||
|
break;
|
||
|
case WL_OUTPUT_TRANSFORM_FLIPPED:
|
||
|
dest_rects[i].x1 = width - src_rects[i].x2;
|
||
|
dest_rects[i].y1 = src_rects[i].y1;
|
||
|
dest_rects[i].x2 = width - src_rects[i].x1;
|
||
|
dest_rects[i].y2 = src_rects[i].y2;
|
||
|
break;
|
||
|
case WL_OUTPUT_TRANSFORM_FLIPPED_90:
|
||
|
dest_rects[i].x1 = height - src_rects[i].y2;
|
||
|
dest_rects[i].y1 = width - src_rects[i].x2;
|
||
|
dest_rects[i].x2 = height - src_rects[i].y1;
|
||
|
dest_rects[i].y2 = width - src_rects[i].x1;
|
||
|
break;
|
||
|
case WL_OUTPUT_TRANSFORM_FLIPPED_180:
|
||
|
dest_rects[i].x1 = src_rects[i].x1;
|
||
|
dest_rects[i].y1 = height - src_rects[i].y2;
|
||
|
dest_rects[i].x2 = src_rects[i].x2;
|
||
|
dest_rects[i].y2 = height - src_rects[i].y1;
|
||
|
break;
|
||
|
case WL_OUTPUT_TRANSFORM_FLIPPED_270:
|
||
|
dest_rects[i].x1 = src_rects[i].y1;
|
||
|
dest_rects[i].y1 = src_rects[i].x1;
|
||
|
dest_rects[i].x2 = src_rects[i].y2;
|
||
|
dest_rects[i].y2 = src_rects[i].x2;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (scale != 1) {
|
||
|
for (i = 0; i < nrects; i++) {
|
||
|
dest_rects[i].x1 *= scale;
|
||
|
dest_rects[i].x2 *= scale;
|
||
|
dest_rects[i].y1 *= scale;
|
||
|
dest_rects[i].y2 *= scale;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
pixman_region32_clear(dest);
|
||
|
pixman_region32_init_rects(dest, dest_rects, nrects);
|
||
|
free(dest_rects);
|
||
|
}
|
||
|
|
||
11 years ago
|
static void
|
||
9 years ago
|
viewport_surface_to_buffer(struct weston_surface *surface,
|
||
|
float sx, float sy, float *bx, float *by)
|
||
11 years ago
|
{
|
||
11 years ago
|
struct weston_buffer_viewport *vp = &surface->buffer_viewport;
|
||
11 years ago
|
double src_width, src_height;
|
||
|
double src_x, src_y;
|
||
11 years ago
|
|
||
11 years ago
|
if (vp->buffer.src_width == wl_fixed_from_int(-1)) {
|
||
|
if (vp->surface.width == -1) {
|
||
|
*bx = sx;
|
||
|
*by = sy;
|
||
|
return;
|
||
|
}
|
||
11 years ago
|
|
||
11 years ago
|
src_x = 0.0;
|
||
|
src_y = 0.0;
|
||
|
src_width = surface->width_from_buffer;
|
||
|
src_height = surface->height_from_buffer;
|
||
11 years ago
|
} else {
|
||
11 years ago
|
src_x = wl_fixed_to_double(vp->buffer.src_x);
|
||
|
src_y = wl_fixed_to_double(vp->buffer.src_y);
|
||
|
src_width = wl_fixed_to_double(vp->buffer.src_width);
|
||
|
src_height = wl_fixed_to_double(vp->buffer.src_height);
|
||
11 years ago
|
}
|
||
11 years ago
|
|
||
|
*bx = sx * src_width / surface->width + src_x;
|
||
|
*by = sy * src_height / surface->height + src_y;
|
||
11 years ago
|
}
|
||
|
|
||
12 years ago
|
WL_EXPORT void
|
||
|
weston_surface_to_buffer_float(struct weston_surface *surface,
|
||
|
float sx, float sy, float *bx, float *by)
|
||
|
{
|
||
11 years ago
|
struct weston_buffer_viewport *vp = &surface->buffer_viewport;
|
||
|
|
||
9 years ago
|
/* first transform coordinates if the viewport is set */
|
||
|
viewport_surface_to_buffer(surface, sx, sy, bx, by);
|
||
11 years ago
|
|
||
11 years ago
|
weston_transformed_coord(surface->width_from_buffer,
|
||
|
surface->height_from_buffer,
|
||
11 years ago
|
vp->buffer.transform, vp->buffer.scale,
|
||
11 years ago
|
*bx, *by, bx, by);
|
||
12 years ago
|
}
|
||
|
|
||
9 years ago
|
/** Transform a rectangle from surface coordinates to buffer coordinates
|
||
|
*
|
||
9 years ago
|
* \param surface The surface to fetch wp_viewport and buffer transformation
|
||
9 years ago
|
* from.
|
||
|
* \param rect The rectangle to transform.
|
||
|
* \return The transformed rectangle.
|
||
|
*
|
||
|
* Viewport and buffer transformations can only do translation, scaling,
|
||
|
* and rotations in 90-degree steps. Therefore the only loss in the
|
||
|
* conversion is coordinate rounding.
|
||
|
*
|
||
|
* However, some coordinate rounding takes place as an intermediate
|
||
|
* step before the buffer scale factor is applied, so the rectangle
|
||
|
* boundary may not be exactly as expected.
|
||
|
*
|
||
|
* This is OK for damage tracking since a little extra coverage is
|
||
|
* not a problem.
|
||
|
*/
|
||
12 years ago
|
WL_EXPORT pixman_box32_t
|
||
|
weston_surface_to_buffer_rect(struct weston_surface *surface,
|
||
|
pixman_box32_t rect)
|
||
|
{
|
||
11 years ago
|
struct weston_buffer_viewport *vp = &surface->buffer_viewport;
|
||
11 years ago
|
float xf, yf;
|
||
|
|
||
9 years ago
|
/* first transform box coordinates if the viewport is set */
|
||
|
viewport_surface_to_buffer(surface, rect.x1, rect.y1, &xf, &yf);
|
||
11 years ago
|
rect.x1 = floorf(xf);
|
||
|
rect.y1 = floorf(yf);
|
||
|
|
||
9 years ago
|
viewport_surface_to_buffer(surface, rect.x2, rect.y2, &xf, &yf);
|
||
9 years ago
|
rect.x2 = ceilf(xf);
|
||
|
rect.y2 = ceilf(yf);
|
||
11 years ago
|
|
||
11 years ago
|
return weston_transformed_rect(surface->width_from_buffer,
|
||
|
surface->height_from_buffer,
|
||
11 years ago
|
vp->buffer.transform, vp->buffer.scale,
|
||
12 years ago
|
rect);
|
||
12 years ago
|
}
|
||
|
|
||
10 years ago
|
/** Transform a region from surface coordinates to buffer coordinates
|
||
|
*
|
||
9 years ago
|
* \param surface The surface to fetch wp_viewport and buffer transformation
|
||
10 years ago
|
* from.
|
||
|
* \param surface_region[in] The region in surface coordinates.
|
||
|
* \param buffer_region[out] The region converted to buffer coordinates.
|
||
|
*
|
||
|
* Buffer_region must be init'd, but will be completely overwritten.
|
||
|
*
|
||
|
* Viewport and buffer transformations can only do translation, scaling,
|
||
|
* and rotations in 90-degree steps. Therefore the only loss in the
|
||
9 years ago
|
* conversion is from the coordinate rounding that takes place in
|
||
|
* \ref weston_surface_to_buffer_rect.
|
||
10 years ago
|
*/
|
||
|
WL_EXPORT void
|
||
|
weston_surface_to_buffer_region(struct weston_surface *surface,
|
||
|
pixman_region32_t *surface_region,
|
||
|
pixman_region32_t *buffer_region)
|
||
|
{
|
||
|
pixman_box32_t *src_rects, *dest_rects;
|
||
|
int nrects, i;
|
||
|
|
||
|
src_rects = pixman_region32_rectangles(surface_region, &nrects);
|
||
|
dest_rects = malloc(nrects * sizeof(*dest_rects));
|
||
|
if (!dest_rects)
|
||
|
return;
|
||
|
|
||
|
for (i = 0; i < nrects; i++) {
|
||
|
dest_rects[i] = weston_surface_to_buffer_rect(surface,
|
||
|
src_rects[i]);
|
||
|
}
|
||
|
|
||
|
pixman_region32_fini(buffer_region);
|
||
|
pixman_region32_init_rects(buffer_region, dest_rects, nrects);
|
||
|
free(dest_rects);
|
||
|
}
|
||
|
|
||
12 years ago
|
WL_EXPORT void
|
||
11 years ago
|
weston_view_move_to_plane(struct weston_view *view,
|
||
12 years ago
|
struct weston_plane *plane)
|
||
|
{
|
||
11 years ago
|
if (view->plane == plane)
|
||
12 years ago
|
return;
|
||
|
|
||
11 years ago
|
weston_view_damage_below(view);
|
||
|
view->plane = plane;
|
||
|
weston_surface_damage(view->surface);
|
||
12 years ago
|
}
|
||
|
|
||
10 years ago
|
/** Inflict damage on the plane where the view is visible.
|
||
|
*
|
||
|
* \param view The view that causes the damage.
|
||
|
*
|
||
|
* If the view is currently on a plane (including the primary plane),
|
||
|
* take the view's boundingbox, subtract all the opaque views that cover it,
|
||
|
* and add the remaining region as damage to the plane. This corresponds
|
||
|
* to the damage inflicted to the plane if this view disappeared.
|
||
|
*
|
||
|
* A repaint is scheduled for this view.
|
||
|
*
|
||
|
* The region of all opaque views covering this view is stored in
|
||
|
* weston_view::clip and updated by view_accumulate_damage() during
|
||
|
* weston_output_repaint(). Specifically, that region matches the
|
||
|
* scenegraph as it was last painted.
|
||
|
*/
|
||
13 years ago
|
WL_EXPORT void
|
||
11 years ago
|
weston_view_damage_below(struct weston_view *view)
|
||
13 years ago
|
{
|
||
13 years ago
|
pixman_region32_t damage;
|
||
|
|
||
|
pixman_region32_init(&damage);
|
||
10 years ago
|
pixman_region32_subtract(&damage, &view->transform.boundingbox,
|
||
11 years ago
|
&view->clip);
|
||
11 years ago
|
if (view->plane)
|
||
|
pixman_region32_union(&view->plane->damage,
|
||
|
&view->plane->damage, &damage);
|
||
13 years ago
|
pixman_region32_fini(&damage);
|
||
11 years ago
|
weston_view_schedule_repaint(view);
|
||
13 years ago
|
}
|
||
|
|
||
9 years ago
|
/**
|
||
|
* \param es The surface
|
||
|
* \param mask The new set of outputs for the surface
|
||
|
*
|
||
|
* Sets the surface's set of outputs to the ones specified by
|
||
|
* the new output mask provided. Identifies the outputs that
|
||
|
* have changed, the posts enter and leave events for these
|
||
|
* outputs as appropriate.
|
||
|
*/
|
||
12 years ago
|
static void
|
||
|
weston_surface_update_output_mask(struct weston_surface *es, uint32_t mask)
|
||
|
{
|
||
|
uint32_t different = es->output_mask ^ mask;
|
||
|
uint32_t entered = mask & different;
|
||
|
uint32_t left = es->output_mask & different;
|
||
|
struct weston_output *output;
|
||
|
struct wl_resource *resource = NULL;
|
||
12 years ago
|
struct wl_client *client;
|
||
12 years ago
|
|
||
|
es->output_mask = mask;
|
||
12 years ago
|
if (es->resource == NULL)
|
||
12 years ago
|
return;
|
||
|
if (different == 0)
|
||
|
return;
|
||
|
|
||
12 years ago
|
client = wl_resource_get_client(es->resource);
|
||
|
|
||
12 years ago
|
wl_list_for_each(output, &es->compositor->output_list, link) {
|
||
9 years ago
|
if (1u << output->id & different)
|
||
12 years ago
|
resource =
|
||
12 years ago
|
wl_resource_find_for_client(&output->resource_list,
|
||
12 years ago
|
client);
|
||
|
if (resource == NULL)
|
||
|
continue;
|
||
9 years ago
|
if (1u << output->id & entered)
|
||
12 years ago
|
wl_surface_send_enter(es->resource, resource);
|
||
9 years ago
|
if (1u << output->id & left)
|
||
12 years ago
|
wl_surface_send_leave(es->resource, resource);
|
||
12 years ago
|
}
|
||
|
}
|
||
|
|
||
9 years ago
|
/** Recalculate which output(s) the surface has views displayed on
|
||
|
*
|
||
|
* \param es The surface to remap to outputs
|
||
|
*
|
||
|
* Finds the output that is showing the largest amount of one
|
||
|
* of the surface's various views. This output becomes the
|
||
9 years ago
|
* surface's primary output for vsync and frame callback purposes.
|
||
9 years ago
|
*
|
||
9 years ago
|
* Also notes all outputs of all of the surface's views
|
||
9 years ago
|
* in the output_mask for the surface.
|
||
|
*/
|
||
12 years ago
|
static void
|
||
|
weston_surface_assign_output(struct weston_surface *es)
|
||
|
{
|
||
11 years ago
|
struct weston_output *new_output;
|
||
|
struct weston_view *view;
|
||
|
pixman_region32_t region;
|
||
|
uint32_t max, area, mask;
|
||
|
pixman_box32_t *e;
|
||
|
|
||
|
new_output = NULL;
|
||
|
max = 0;
|
||
|
mask = 0;
|
||
|
pixman_region32_init(®ion);
|
||
|
wl_list_for_each(view, &es->views, surface_link) {
|
||
|
if (!view->output)
|
||
|
continue;
|
||
|
|
||
|
pixman_region32_intersect(®ion, &view->transform.boundingbox,
|
||
|
&view->output->region);
|
||
|
|
||
|
e = pixman_region32_extents(®ion);
|
||
|
area = (e->x2 - e->x1) * (e->y2 - e->y1);
|
||
|
|
||
|
mask |= view->output_mask;
|
||
|
|
||
|
if (area >= max) {
|
||
|
new_output = view->output;
|
||
|
max = area;
|
||
|
}
|
||
|
}
|
||
|
pixman_region32_fini(®ion);
|
||
|
|
||
|
es->output = new_output;
|
||
|
weston_surface_update_output_mask(es, mask);
|
||
|
}
|
||
|
|
||
9 years ago
|
/** Recalculate which output(s) the view is displayed on
|
||
|
*
|
||
|
* \param ev The view to remap to outputs
|
||
|
*
|
||
|
* Identifies the set of outputs that the view is visible on,
|
||
|
* noting them into the output_mask. The output that the view
|
||
9 years ago
|
* is most visible on is set as the view's primary output.
|
||
9 years ago
|
*
|
||
|
* Also does the same for the view's surface. See
|
||
|
* weston_surface_assign_output().
|
||
|
*/
|
||
11 years ago
|
static void
|
||
|
weston_view_assign_output(struct weston_view *ev)
|
||
|
{
|
||
|
struct weston_compositor *ec = ev->surface->compositor;
|
||
12 years ago
|
struct weston_output *output, *new_output;
|
||
|
pixman_region32_t region;
|
||
|
uint32_t max, area, mask;
|
||
|
pixman_box32_t *e;
|
||
|
|
||
|
new_output = NULL;
|
||
|
max = 0;
|
||
|
mask = 0;
|
||
|
pixman_region32_init(®ion);
|
||
|
wl_list_for_each(output, &ec->output_list, link) {
|
||
9 years ago
|
if (output->destroying)
|
||
|
continue;
|
||
|
|
||
11 years ago
|
pixman_region32_intersect(®ion, &ev->transform.boundingbox,
|
||
12 years ago
|
&output->region);
|
||
|
|
||
|
e = pixman_region32_extents(®ion);
|
||
|
area = (e->x2 - e->x1) * (e->y2 - e->y1);
|
||
|
|
||
|
if (area > 0)
|
||
9 years ago
|
mask |= 1u << output->id;
|
||
12 years ago
|
|
||
|
if (area >= max) {
|
||
|
new_output = output;
|
||
|
max = area;
|
||
|
}
|
||
|
}
|
||
|
pixman_region32_fini(®ion);
|
||
|
|
||
11 years ago
|
ev->output = new_output;
|
||
|
ev->output_mask = mask;
|
||
|
|
||
|
weston_surface_assign_output(ev->surface);
|
||
12 years ago
|
}
|
||
|
|
||
10 years ago
|
static void
|
||
|
weston_view_to_view_map(struct weston_view *from, struct weston_view *to,
|
||
|
int from_x, int from_y, int *to_x, int *to_y)
|
||
|
{
|
||
|
float x, y;
|
||
|
|
||
|
weston_view_to_global_float(from, from_x, from_y, &x, &y);
|
||
|
weston_view_from_global_float(to, x, y, &x, &y);
|
||
|
|
||
|
*to_x = round(x);
|
||
|
*to_y = round(y);
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
weston_view_transfer_scissor(struct weston_view *from, struct weston_view *to)
|
||
|
{
|
||
|
pixman_box32_t *a;
|
||
|
pixman_box32_t b;
|
||
|
|
||
|
a = pixman_region32_extents(&from->geometry.scissor);
|
||
|
|
||
|
weston_view_to_view_map(from, to, a->x1, a->y1, &b.x1, &b.y1);
|
||
|
weston_view_to_view_map(from, to, a->x2, a->y2, &b.x2, &b.y2);
|
||
|
|
||
|
pixman_region32_fini(&to->geometry.scissor);
|
||
|
pixman_region32_init_with_extents(&to->geometry.scissor, &b);
|
||
|
}
|
||
|
|
||
13 years ago
|
static void
|
||
10 years ago
|
view_compute_bbox(struct weston_view *view, const pixman_box32_t *inbox,
|
||
11 years ago
|
pixman_region32_t *bbox)
|
||
13 years ago
|
{
|
||
12 years ago
|
float min_x = HUGE_VALF, min_y = HUGE_VALF;
|
||
|
float max_x = -HUGE_VALF, max_y = -HUGE_VALF;
|
||
13 years ago
|
int32_t s[4][2] = {
|
||
10 years ago
|
{ inbox->x1, inbox->y1 },
|
||
|
{ inbox->x1, inbox->y2 },
|
||
|
{ inbox->x2, inbox->y1 },
|
||
|
{ inbox->x2, inbox->y2 },
|
||
13 years ago
|
};
|
||
12 years ago
|
float int_x, int_y;
|
||
13 years ago
|
int i;
|
||
|
|
||
10 years ago
|
if (inbox->x1 == inbox->x2 || inbox->y1 == inbox->y2) {
|
||
12 years ago
|
/* avoid rounding empty bbox to 1x1 */
|
||
|
pixman_region32_init(bbox);
|
||
|
return;
|
||
|
}
|
||
|
|
||
13 years ago
|
for (i = 0; i < 4; ++i) {
|
||
12 years ago
|
float x, y;
|
||
11 years ago
|
weston_view_to_global_float(view, s[i][0], s[i][1], &x, &y);
|
||
13 years ago
|
if (x < min_x)
|
||
|
min_x = x;
|
||
|
if (x > max_x)
|
||
|
max_x = x;
|
||
|
if (y < min_y)
|
||
|
min_y = y;
|
||
|
if (y > max_y)
|
||
|
max_y = y;
|
||
|
}
|
||
|
|
||
13 years ago
|
int_x = floorf(min_x);
|
||
|
int_y = floorf(min_y);
|
||
|
pixman_region32_init_rect(bbox, int_x, int_y,
|
||
|
ceilf(max_x) - int_x, ceilf(max_y) - int_y);
|
||
13 years ago
|
}
|
||
|
|
||
13 years ago
|
static void
|
||
11 years ago
|
weston_view_update_transform_disable(struct weston_view *view)
|
||
13 years ago
|
{
|
||
11 years ago
|
view->transform.enabled = 0;
|
||
13 years ago
|
|
||
13 years ago
|
/* round off fractions when not transformed */
|
||
11 years ago
|
view->geometry.x = roundf(view->geometry.x);
|
||
|
view->geometry.y = roundf(view->geometry.y);
|
||
13 years ago
|
|
||
12 years ago
|
/* Otherwise identity matrix, but with x and y translation. */
|
||
11 years ago
|
view->transform.position.matrix.type = WESTON_MATRIX_TRANSFORM_TRANSLATE;
|
||
|
view->transform.position.matrix.d[12] = view->geometry.x;
|
||
|
view->transform.position.matrix.d[13] = view->geometry.y;
|
||
12 years ago
|
|
||
11 years ago
|
view->transform.matrix = view->transform.position.matrix;
|
||
12 years ago
|
|
||
11 years ago
|
view->transform.inverse = view->transform.position.matrix;
|
||
|
view->transform.inverse.d[12] = -view->geometry.x;
|
||
|
view->transform.inverse.d[13] = -view->geometry.y;
|
||
12 years ago
|
|
||
11 years ago
|
pixman_region32_init_rect(&view->transform.boundingbox,
|
||
10 years ago
|
0, 0,
|
||
11 years ago
|
view->surface->width,
|
||
|
view->surface->height);
|
||
10 years ago
|
if (view->geometry.scissor_enabled)
|
||
|
pixman_region32_intersect(&view->transform.boundingbox,
|
||
|
&view->transform.boundingbox,
|
||
|
&view->geometry.scissor);
|
||
|
|
||
|
pixman_region32_translate(&view->transform.boundingbox,
|
||
|
view->geometry.x, view->geometry.y);
|
||
13 years ago
|
|
||
11 years ago
|
if (view->alpha == 1.0) {
|
||
|
pixman_region32_copy(&view->transform.opaque,
|
||
|
&view->surface->opaque);
|
||
|
pixman_region32_translate(&view->transform.opaque,
|
||
|
view->geometry.x,
|
||
|
view->geometry.y);
|
||
13 years ago
|
}
|
||
13 years ago
|
}
|
||
|
|
||
|
static int
|
||
11 years ago
|
weston_view_update_transform_enable(struct weston_view *view)
|
||
13 years ago
|
{
|
||
11 years ago
|
struct weston_view *parent = view->geometry.parent;
|
||
|
struct weston_matrix *matrix = &view->transform.matrix;
|
||
|
struct weston_matrix *inverse = &view->transform.inverse;
|
||
13 years ago
|
struct weston_transform *tform;
|
||
10 years ago
|
pixman_region32_t surfregion;
|
||
|
const pixman_box32_t *surfbox;
|
||
13 years ago
|
|
||
11 years ago
|
view->transform.enabled = 1;
|
||
13 years ago
|
|
||
13 years ago
|
/* Otherwise identity matrix, but with x and y translation. */
|
||
11 years ago
|
view->transform.position.matrix.type = WESTON_MATRIX_TRANSFORM_TRANSLATE;
|
||
|
view->transform.position.matrix.d[12] = view->geometry.x;
|
||
|
view->transform.position.matrix.d[13] = view->geometry.y;
|
||
13 years ago
|
|
||
13 years ago
|
weston_matrix_init(matrix);
|
||
11 years ago
|
wl_list_for_each(tform, &view->geometry.transformation_list, link)
|
||
13 years ago
|
weston_matrix_multiply(matrix, &tform->matrix);
|
||
|
|
||
12 years ago
|
if (parent)
|
||
|
weston_matrix_multiply(matrix, &parent->transform.matrix);
|
||
|
|
||
13 years ago
|
if (weston_matrix_invert(inverse, matrix) < 0) {
|
||
|
/* Oops, bad total transformation, not invertible */
|
||
11 years ago
|
weston_log("error: weston_view %p"
|
||
|
" transformation not invertible.\n", view);
|
||
13 years ago
|
return -1;
|
||
13 years ago
|
}
|
||
13 years ago
|
|
||
10 years ago
|
pixman_region32_init_rect(&surfregion, 0, 0,
|
||
|
view->surface->width, view->surface->height);
|
||
|
if (view->geometry.scissor_enabled)
|
||
|
pixman_region32_intersect(&surfregion, &surfregion,
|
||
|
&view->geometry.scissor);
|
||
|
surfbox = pixman_region32_extents(&surfregion);
|
||
|
|
||
|
view_compute_bbox(view, surfbox, &view->transform.boundingbox);
|
||
|
pixman_region32_fini(&surfregion);
|
||
13 years ago
|
|
||
13 years ago
|
return 0;
|
||
|
}
|
||
|
|
||
10 years ago
|
static struct weston_layer *
|
||
|
get_view_layer(struct weston_view *view)
|
||
|
{
|
||
|
if (view->parent_view)
|
||
|
return get_view_layer(view->parent_view);
|
||
|
return view->layer_link.layer;
|
||
|
}
|
||
|
|
||
13 years ago
|
WL_EXPORT void
|
||
11 years ago
|
weston_view_update_transform(struct weston_view *view)
|
||
13 years ago
|
{
|
||
11 years ago
|
struct weston_view *parent = view->geometry.parent;
|
||
10 years ago
|
struct weston_layer *layer;
|
||
|
pixman_region32_t mask;
|
||
12 years ago
|
|
||
11 years ago
|
if (!view->transform.dirty)
|
||
13 years ago
|
return;
|
||
|
|
||
12 years ago
|
if (parent)
|
||
11 years ago
|
weston_view_update_transform(parent);
|
||
12 years ago
|
|
||
11 years ago
|
view->transform.dirty = 0;
|
||
13 years ago
|
|
||
11 years ago
|
weston_view_damage_below(view);
|
||
13 years ago
|
|
||
11 years ago
|
pixman_region32_fini(&view->transform.boundingbox);
|
||
|
pixman_region32_fini(&view->transform.opaque);
|
||
|
pixman_region32_init(&view->transform.opaque);
|
||
13 years ago
|
|
||
13 years ago
|
/* transform.position is always in transformation_list */
|
||
11 years ago
|
if (view->geometry.transformation_list.next ==
|
||
|
&view->transform.position.link &&
|
||
|
view->geometry.transformation_list.prev ==
|
||
|
&view->transform.position.link &&
|
||
12 years ago
|
!parent) {
|
||
11 years ago
|
weston_view_update_transform_disable(view);
|
||
13 years ago
|
} else {
|
||
11 years ago
|
if (weston_view_update_transform_enable(view) < 0)
|
||
|
weston_view_update_transform_disable(view);
|
||
13 years ago
|
}
|
||
13 years ago
|
|
||
10 years ago
|
layer = get_view_layer(view);
|
||
|
if (layer) {
|
||
|
pixman_region32_init_with_extents(&mask, &layer->mask);
|
||
10 years ago
|
pixman_region32_intersect(&view->transform.boundingbox,
|
||
|
&view->transform.boundingbox, &mask);
|
||
10 years ago
|
pixman_region32_intersect(&view->transform.opaque,
|
||
|
&view->transform.opaque, &mask);
|
||
10 years ago
|
pixman_region32_fini(&mask);
|
||
|
}
|
||
|
|
||
10 years ago
|
if (parent) {
|
||
|
if (parent->geometry.scissor_enabled) {
|
||
|
view->geometry.scissor_enabled = true;
|
||
|
weston_view_transfer_scissor(parent, view);
|
||
|
} else {
|
||
|
view->geometry.scissor_enabled = false;
|
||
|
}
|
||
|
}
|
||
|
|
||
11 years ago
|
weston_view_damage_below(view);
|
||
13 years ago
|
|
||
11 years ago
|
weston_view_assign_output(view);
|
||
12 years ago
|
|
||
11 years ago
|
wl_signal_emit(&view->surface->compositor->transform_signal,
|
||
|
view->surface);
|
||
13 years ago
|
}
|
||
|
|
||
12 years ago
|
WL_EXPORT void
|
||
11 years ago
|
weston_view_geometry_dirty(struct weston_view *view)
|
||
12 years ago
|
{
|
||
11 years ago
|
struct weston_view *child;
|
||
12 years ago
|
|
||
|
/*
|
||
11 years ago
|
* The invariant: if view->geometry.dirty, then all views
|
||
|
* in view->geometry.child_list have geometry.dirty too.
|
||
12 years ago
|
* Corollary: if not parent->geometry.dirty, then all ancestors
|
||
|
* are not dirty.
|
||
|
*/
|
||
|
|
||
11 years ago
|
if (view->transform.dirty)
|
||
12 years ago
|
return;
|
||
|
|
||
11 years ago
|
view->transform.dirty = 1;
|
||
12 years ago
|
|
||
11 years ago
|
wl_list_for_each(child, &view->geometry.child_list,
|
||
12 years ago
|
geometry.parent_link)
|
||
11 years ago
|
weston_view_geometry_dirty(child);
|
||
12 years ago
|
}
|
||
|
|
||
13 years ago
|
WL_EXPORT void
|
||
11 years ago
|
weston_view_to_global_fixed(struct weston_view *view,
|
||
|
wl_fixed_t vx, wl_fixed_t vy,
|
||
|
wl_fixed_t *x, wl_fixed_t *y)
|
||
13 years ago
|
{
|
||
12 years ago
|
float xf, yf;
|
||
13 years ago
|
|
||
11 years ago
|
weston_view_to_global_float(view,
|
||
|
wl_fixed_to_double(vx),
|
||
|
wl_fixed_to_double(vy),
|
||
|
&xf, &yf);
|
||
13 years ago
|
*x = wl_fixed_from_double(xf);
|
||
|
*y = wl_fixed_from_double(yf);
|
||
|
}
|
||
|
|
||
12 years ago
|
WL_EXPORT void
|
||
11 years ago
|
weston_view_from_global_float(struct weston_view *view,
|
||
|
float x, float y, float *vx, float *vy)
|
||
13 years ago
|
{
|
||
11 years ago
|
if (view->transform.enabled) {
|
||
13 years ago
|
struct weston_vector v = { { x, y, 0.0f, 1.0f } };
|
||
|
|
||
11 years ago
|
weston_matrix_transform(&view->transform.inverse, &v);
|
||
13 years ago
|
|
||
|
if (fabsf(v.f[3]) < 1e-6) {
|
||
13 years ago
|
weston_log("warning: numerical instability in "
|
||
11 years ago
|
"weston_view_from_global(), divisor = %g\n",
|
||
13 years ago
|
v.f[3]);
|
||
11 years ago
|
*vx = 0;
|
||
|
*vy = 0;
|
||
13 years ago
|
return;
|
||
|
}
|
||
|
|
||
11 years ago
|
*vx = v.f[0] / v.f[3];
|
||
|
*vy = v.f[1] / v.f[3];
|
||
13 years ago
|
} else {
|
||
11 years ago
|
*vx = x - view->geometry.x;
|
||
|
*vy = y - view->geometry.y;
|
||
13 years ago
|
}
|
||
|
}
|
||
|
|
||
13 years ago
|
WL_EXPORT void
|
||
11 years ago
|
weston_view_from_global_fixed(struct weston_view *view,
|
||
|
wl_fixed_t x, wl_fixed_t y,
|
||
|
wl_fixed_t *vx, wl_fixed_t *vy)
|
||
13 years ago
|
{
|
||
11 years ago
|
float vxf, vyf;
|
||
13 years ago
|
|
||
11 years ago
|
weston_view_from_global_float(view,
|
||
|
wl_fixed_to_double(x),
|
||
|
wl_fixed_to_double(y),
|
||
|
&vxf, &vyf);
|
||
|
*vx = wl_fixed_from_double(vxf);
|
||
|
*vy = wl_fixed_from_double(vyf);
|
||
13 years ago
|
}
|
||
|
|
||
13 years ago
|
WL_EXPORT void
|
||
11 years ago
|
weston_view_from_global(struct weston_view *view,
|
||
|
int32_t x, int32_t y, int32_t *vx, int32_t *vy)
|
||
13 years ago
|
{
|
||
11 years ago
|
float vxf, vyf;
|
||
13 years ago
|
|
||
11 years ago
|
weston_view_from_global_float(view, x, y, &vxf, &vyf);
|
||
|
*vx = floorf(vxf);
|
||
|
*vy = floorf(vyf);
|
||
13 years ago
|
}
|
||
|
|
||
9 years ago
|
/**
|
||
|
* \param surface The surface to be repainted
|
||
|
*
|
||
|
* Marks the output(s) that the surface is shown on as needing to be
|
||
|
* repainted. See weston_output_schedule_repaint().
|
||
|
*/
|
||
12 years ago
|
WL_EXPORT void
|
||
|
weston_surface_schedule_repaint(struct weston_surface *surface)
|
||
|
{
|
||
|
struct weston_output *output;
|
||
|
|
||
|
wl_list_for_each(output, &surface->compositor->output_list, link)
|
||
9 years ago
|
if (surface->output_mask & (1u << output->id))
|
||
12 years ago
|
weston_output_schedule_repaint(output);
|
||
|
}
|
||
|
|
||
9 years ago
|
/**
|
||
|
* \param view The view to be repainted
|
||
|
*
|
||
|
* Marks the output(s) that the view is shown on as needing to be
|
||
|
* repainted. See weston_output_schedule_repaint().
|
||
|
*/
|
||
11 years ago
|
WL_EXPORT void
|
||
|
weston_view_schedule_repaint(struct weston_view *view)
|
||
|
{
|
||
|
struct weston_output *output;
|
||
|
|
||
|
wl_list_for_each(output, &view->surface->compositor->output_list, link)
|
||
9 years ago
|
if (view->output_mask & (1u << output->id))
|
||
11 years ago
|
weston_output_schedule_repaint(output);
|
||
|
}
|
||
|
|
||
10 years ago
|
/**
|
||
|
* XXX: This function does it the wrong way.
|
||
|
* surface->damage is the damage from the client, and causes
|
||
|
* surface_flush_damage() to copy pixels. No window management action can
|
||
|
* cause damage to the client-provided content, warranting re-upload!
|
||
|
*
|
||
|
* Instead of surface->damage, this function should record the damage
|
||
|
* with all the views for this surface to avoid extraneous texture
|
||
|
* uploads.
|
||
|
*/
|
||
14 years ago
|
WL_EXPORT void
|
||
13 years ago
|
weston_surface_damage(struct weston_surface *surface)
|
||
14 years ago
|
{
|
||
13 years ago
|
pixman_region32_union_rect(&surface->damage, &surface->damage,
|
||
11 years ago
|
0, 0, surface->width,
|
||
|
surface->height);
|
||
13 years ago
|
|
||
12 years ago
|
weston_surface_schedule_repaint(surface);
|
||
14 years ago
|
}
|
||
|
|
||
13 years ago
|
WL_EXPORT void
|
||
11 years ago
|
weston_view_set_position(struct weston_view *view, float x, float y)
|
||
13 years ago
|
{
|
||
11 years ago
|
if (view->geometry.x == x && view->geometry.y == y)
|
||
|
return;
|
||
|
|
||
11 years ago
|
view->geometry.x = x;
|
||
|
view->geometry.y = y;
|
||
|
weston_view_geometry_dirty(view);
|
||
13 years ago
|
}
|
||
|
|
||
12 years ago
|
static void
|
||
|
transform_parent_handle_parent_destroy(struct wl_listener *listener,
|
||
|
void *data)
|
||
|
{
|
||
11 years ago
|
struct weston_view *view =
|
||
|
container_of(listener, struct weston_view,
|
||
12 years ago
|
geometry.parent_destroy_listener);
|
||
|
|
||
11 years ago
|
weston_view_set_transform_parent(view, NULL);
|
||
12 years ago
|
}
|
||
|
|
||
|
WL_EXPORT void
|
||
11 years ago
|
weston_view_set_transform_parent(struct weston_view *view,
|
||
10 years ago
|
struct weston_view *parent)
|
||
12 years ago
|
{
|
||
11 years ago
|
if (view->geometry.parent) {
|
||
|
wl_list_remove(&view->geometry.parent_destroy_listener.link);
|
||
|
wl_list_remove(&view->geometry.parent_link);
|
||
10 years ago
|
|
||
|
if (!parent)
|
||
|
view->geometry.scissor_enabled = false;
|
||
12 years ago
|
}
|
||
|
|
||
11 years ago
|
view->geometry.parent = parent;
|
||
12 years ago
|
|
||
11 years ago
|
view->geometry.parent_destroy_listener.notify =
|
||
12 years ago
|
transform_parent_handle_parent_destroy;
|
||
|
if (parent) {
|
||
12 years ago
|
wl_signal_add(&parent->destroy_signal,
|
||
11 years ago
|
&view->geometry.parent_destroy_listener);
|
||
12 years ago
|
wl_list_insert(&parent->geometry.child_list,
|
||
11 years ago
|
&view->geometry.parent_link);
|
||
12 years ago
|
}
|
||
|
|
||
11 years ago
|
weston_view_geometry_dirty(view);
|
||
|
}
|
||
|
|
||
10 years ago
|
/** Set a clip mask rectangle on a view
|
||
|
*
|
||
|
* \param view The view to set the clip mask on.
|
||
|
* \param x Top-left corner X coordinate of the clip rectangle.
|
||
|
* \param y Top-left corner Y coordinate of the clip rectangle.
|
||
|
* \param width Width of the clip rectangle, non-negative.
|
||
|
* \param height Height of the clip rectangle, non-negative.
|
||
|
*
|
||
|
* A shell may set a clip mask rectangle on a view. Everything outside
|
||
|
* the rectangle is cut away for input and output purposes: it is
|
||
|
* not drawn and cannot be hit by hit-test based input like pointer
|
||
|
* motion or touch-downs. Everything inside the rectangle will behave
|
||
|
* normally. Clients are unaware of clipping.
|
||
|
*
|
||
9 years ago
|
* The rectangle is set in surface-local coordinates. Setting a clip
|
||
10 years ago
|
* mask rectangle does not affect the view position, the view is positioned
|
||
|
* as it would be without a clip. The clip also does not change
|
||
|
* weston_surface::width,height.
|
||
|
*
|
||
|
* The clip mask rectangle is part of transformation inheritance
|
||
|
* (weston_view_set_transform_parent()). A clip set in the root of the
|
||
|
* transformation inheritance tree will affect all views in the tree.
|
||
|
* A clip can be set only on the root view. Attempting to set a clip
|
||
|
* on view that has a transformation parent will fail. Assigning a parent
|
||
|
* to a view that has a clip set will cause the clip to be forgotten.
|
||
|
*
|
||
|
* Because the clip mask is an axis-aligned rectangle, it poses restrictions
|
||
|
* on the additional transformations in the child views. These transformations
|
||
|
* may not rotate the coordinate axes, i.e., only translation and scaling
|
||
|
* are allowed. Violating this restriction causes the clipping to malfunction.
|
||
|
* Furthermore, using scaling may cause rounding errors in child clipping.
|
||
|
*
|
||
|
* The clip mask rectangle is not automatically adjusted based on
|
||
|
* wl_surface.attach dx and dy arguments.
|
||
|
*
|
||
|
* A clip mask rectangle can be set only if the compositor capability
|
||
|
* WESTON_CAP_VIEW_CLIP_MASK is present.
|
||
|
*
|
||
|
* This function sets the clip mask rectangle and schedules a repaint for
|
||
|
* the view.
|
||
|
*/
|
||
|
WL_EXPORT void
|
||
|
weston_view_set_mask(struct weston_view *view,
|
||
|
int x, int y, int width, int height)
|
||
|
{
|
||
|
struct weston_compositor *compositor = view->surface->compositor;
|
||
|
|
||
|
if (!(compositor->capabilities & WESTON_CAP_VIEW_CLIP_MASK)) {
|
||
|
weston_log("%s not allowed without capability!\n", __func__);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (view->geometry.parent) {
|
||
|
weston_log("view %p has a parent, clip forbidden!\n", view);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (width < 0 || height < 0) {
|
||
|
weston_log("%s: illegal args %d, %d, %d, %d\n", __func__,
|
||
|
x, y, width, height);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
pixman_region32_fini(&view->geometry.scissor);
|
||
|
pixman_region32_init_rect(&view->geometry.scissor, x, y, width, height);
|
||
|
view->geometry.scissor_enabled = true;
|
||
|
weston_view_geometry_dirty(view);
|
||
|
weston_view_schedule_repaint(view);
|
||
|
}
|
||
|
|
||
|
/** Remove the clip mask from a view
|
||
|
*
|
||
|
* \param view The view to remove the clip mask from.
|
||
|
*
|
||
|
* Removed the clip mask rectangle and schedules a repaint.
|
||
|
*
|
||
|
* \sa weston_view_set_mask
|
||
|
*/
|
||
|
WL_EXPORT void
|
||
|
weston_view_set_mask_infinite(struct weston_view *view)
|
||
|
{
|
||
|
view->geometry.scissor_enabled = false;
|
||
|
weston_view_geometry_dirty(view);
|
||
|
weston_view_schedule_repaint(view);
|
||
|
}
|
||
|
|
||
10 years ago
|
WL_EXPORT bool
|
||
11 years ago
|
weston_view_is_mapped(struct weston_view *view)
|
||
|
{
|
||
|
if (view->output)
|
||
10 years ago
|
return true;
|
||
11 years ago
|
else
|
||
10 years ago
|
return false;
|
||
12 years ago
|
}
|
||
|
|
||
10 years ago
|
WL_EXPORT bool
|
||
13 years ago
|
weston_surface_is_mapped(struct weston_surface *surface)
|
||
|
{
|
||
|
if (surface->output)
|
||
10 years ago
|
return true;
|
||
13 years ago
|
else
|
||
10 years ago
|
return false;
|
||
13 years ago
|
}
|
||
|
|
||
11 years ago
|
static void
|
||
11 years ago
|
surface_set_size(struct weston_surface *surface, int32_t width, int32_t height)
|
||
11 years ago
|
{
|
||
|
struct weston_view *view;
|
||
|
|
||
|
if (surface->width == width && surface->height == height)
|
||
|
return;
|
||
|
|
||
|
surface->width = width;
|
||
|
surface->height = height;
|
||
|
|
||
|
wl_list_for_each(view, &surface->views, surface_link)
|
||
|
weston_view_geometry_dirty(view);
|
||
|
}
|
||
|
|
||
11 years ago
|
WL_EXPORT void
|
||
|
weston_surface_set_size(struct weston_surface *surface,
|
||
|
int32_t width, int32_t height)
|
||
|
{
|
||
|
assert(!surface->resource);
|
||
|
surface_set_size(surface, width, height);
|
||
|
}
|
||
|
|
||
11 years ago
|
static int
|
||
|
fixed_round_up_to_int(wl_fixed_t f)
|
||
|
{
|
||
|
return wl_fixed_to_int(wl_fixed_from_int(1) - 1 + f);
|
||
|
}
|
||
|
|
||
11 years ago
|
static void
|
||
9 years ago
|
convert_size_by_transform_scale(int32_t *width_out, int32_t *height_out,
|
||
|
int32_t width, int32_t height,
|
||
|
uint32_t transform,
|
||
|
int32_t scale)
|
||
12 years ago
|
{
|
||
9 years ago
|
assert(scale > 0);
|
||
11 years ago
|
|
||
9 years ago
|
switch (transform) {
|
||
|
case WL_OUTPUT_TRANSFORM_NORMAL:
|
||
|
case WL_OUTPUT_TRANSFORM_180:
|
||
|
case WL_OUTPUT_TRANSFORM_FLIPPED:
|
||
|
case WL_OUTPUT_TRANSFORM_FLIPPED_180:
|
||
|
*width_out = width / scale;
|
||
|
*height_out = height / scale;
|
||
|
break;
|
||
12 years ago
|
case WL_OUTPUT_TRANSFORM_90:
|
||
|
case WL_OUTPUT_TRANSFORM_270:
|
||
|
case WL_OUTPUT_TRANSFORM_FLIPPED_90:
|
||
|
case WL_OUTPUT_TRANSFORM_FLIPPED_270:
|
||
9 years ago
|
*width_out = height / scale;
|
||
|
*height_out = width / scale;
|
||
11 years ago
|
break;
|
||
12 years ago
|
default:
|
||
9 years ago
|
assert(0 && "invalid transform");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
weston_surface_calculate_size_from_buffer(struct weston_surface *surface)
|
||
|
{
|
||
|
struct weston_buffer_viewport *vp = &surface->buffer_viewport;
|
||
|
|
||
|
if (!surface->buffer_ref.buffer) {
|
||
|
surface->width_from_buffer = 0;
|
||
|
surface->height_from_buffer = 0;
|
||
|
return;
|
||
12 years ago
|
}
|
||
11 years ago
|
|
||
9 years ago
|
convert_size_by_transform_scale(&surface->width_from_buffer,
|
||
|
&surface->height_from_buffer,
|
||
|
surface->buffer_ref.buffer->width,
|
||
|
surface->buffer_ref.buffer->height,
|
||
|
vp->buffer.transform,
|
||
|
vp->buffer.scale);
|
||
11 years ago
|
}
|
||
|
|
||
|
static void
|
||
|
weston_surface_update_size(struct weston_surface *surface)
|
||
|
{
|
||
|
struct weston_buffer_viewport *vp = &surface->buffer_viewport;
|
||
|
int32_t width, height;
|
||
|
|
||
|
width = surface->width_from_buffer;
|
||
|
height = surface->height_from_buffer;
|
||
11 years ago
|
|
||
11 years ago
|
if (width != 0 && vp->surface.width != -1) {
|
||
11 years ago
|
surface_set_size(surface,
|
||
|
vp->surface.width, vp->surface.height);
|
||
|
return;
|
||
|
}
|
||
|
|
||
11 years ago
|
if (width != 0 && vp->buffer.src_width != wl_fixed_from_int(-1)) {
|
||
11 years ago
|
int32_t w = fixed_round_up_to_int(vp->buffer.src_width);
|
||
|
int32_t h = fixed_round_up_to_int(vp->buffer.src_height);
|
||
|
|
||
|
surface_set_size(surface, w ?: 1, h ?: 1);
|
||
11 years ago
|
return;
|
||
|
}
|
||
|
|
||
11 years ago
|
surface_set_size(surface, width, height);
|
||
12 years ago
|
}
|
||
|
|
||
14 years ago
|
WL_EXPORT uint32_t
|
||
13 years ago
|
weston_compositor_get_time(void)
|
||
14 years ago
|
{
|
||
13 years ago
|
struct timeval tv;
|
||
14 years ago
|
|
||
13 years ago
|
gettimeofday(&tv, NULL);
|
||
14 years ago
|
|
||
13 years ago
|
return tv.tv_sec * 1000 + tv.tv_usec / 1000;
|
||
14 years ago
|
}
|
||
|
|
||
11 years ago
|
WL_EXPORT struct weston_view *
|
||
|
weston_compositor_pick_view(struct weston_compositor *compositor,
|
||
|
wl_fixed_t x, wl_fixed_t y,
|
||
|
wl_fixed_t *vx, wl_fixed_t *vy)
|
||
13 years ago
|
{
|
||
11 years ago
|
struct weston_view *view;
|
||
10 years ago
|
wl_fixed_t view_x, view_y;
|
||
|
int view_ix, view_iy;
|
||
|
int ix = wl_fixed_to_int(x);
|
||
|
int iy = wl_fixed_to_int(y);
|
||
13 years ago
|
|
||
11 years ago
|
wl_list_for_each(view, &compositor->view_list, link) {
|
||
10 years ago
|
if (!pixman_region32_contains_point(
|
||
|
&view->transform.boundingbox, ix, iy, NULL))
|
||
|
continue;
|
||
|
|
||
|
weston_view_from_global_fixed(view, x, y, &view_x, &view_y);
|
||
|
view_ix = wl_fixed_to_int(view_x);
|
||
|
view_iy = wl_fixed_to_int(view_y);
|
||
|
|
||
|
if (!pixman_region32_contains_point(&view->surface->input,
|
||
|
view_ix, view_iy, NULL))
|
||
|
continue;
|
||
|
|
||
10 years ago
|
if (view->geometry.scissor_enabled &&
|
||
|
!pixman_region32_contains_point(&view->geometry.scissor,
|
||
|
view_ix, view_iy, NULL))
|
||
|
continue;
|
||
|
|
||
10 years ago
|
*vx = view_x;
|
||
|
*vy = view_y;
|
||
|
return view;
|
||
13 years ago
|
}
|
||
|
|
||
10 years ago
|
*vx = wl_fixed_from_int(-1000000);
|
||
|
*vy = wl_fixed_from_int(-1000000);
|
||
13 years ago
|
return NULL;
|
||
|
}
|
||
|
|
||
13 years ago
|
static void
|
||
13 years ago
|
weston_compositor_repick(struct weston_compositor *compositor)
|
||
13 years ago
|
{
|
||
13 years ago
|
struct weston_seat *seat;
|
||
13 years ago
|
|
||
11 years ago
|
if (!compositor->session_active)
|
||
13 years ago
|
return;
|
||
|
|
||
13 years ago
|
wl_list_for_each(seat, &compositor->seat_list, link)
|
||
12 years ago
|
weston_seat_repick(seat);
|
||
13 years ago
|
}
|
||
|
|
||
13 years ago
|
WL_EXPORT void
|
||
11 years ago
|
weston_view_unmap(struct weston_view *view)
|
||
13 years ago
|
{
|
||
13 years ago
|
struct weston_seat *seat;
|
||
13 years ago
|
|
||
11 years ago
|
if (!weston_view_is_mapped(view))
|
||
|
return;
|
||
|
|
||
|
weston_view_damage_below(view);
|
||
|
view->output = NULL;
|
||
11 years ago
|
view->plane = NULL;
|
||
10 years ago
|
weston_layer_entry_remove(&view->layer_link);
|
||
11 years ago
|
wl_list_remove(&view->link);
|
||
|
wl_list_init(&view->link);
|
||
|
view->output_mask = 0;
|
||
|
weston_surface_assign_output(view->surface);
|
||
|
|
||
|
if (weston_surface_is_mapped(view->surface))
|
||
|
return;
|
||
13 years ago
|
|
||
11 years ago
|
wl_list_for_each(seat, &view->surface->compositor->seat_list, link) {
|
||
9 years ago
|
struct weston_touch *touch = weston_seat_get_touch(seat);
|
||
|
struct weston_pointer *pointer = weston_seat_get_pointer(seat);
|
||
|
struct weston_keyboard *keyboard =
|
||
|
weston_seat_get_keyboard(seat);
|
||
|
|
||
|
if (keyboard && keyboard->focus == view->surface)
|
||
|
weston_keyboard_set_focus(keyboard, NULL);
|
||
|
if (pointer && pointer->focus == view)
|
||
10 years ago
|
weston_pointer_clear_focus(pointer);
|
||
9 years ago
|
if (touch && touch->focus == view)
|
||
|
weston_touch_set_focus(touch, NULL);
|
||
13 years ago
|
}
|
||
11 years ago
|
}
|
||
13 years ago
|
|
||
11 years ago
|
WL_EXPORT void
|
||
|
weston_surface_unmap(struct weston_surface *surface)
|
||
|
{
|
||
|
struct weston_view *view;
|
||
|
|
||
|
wl_list_for_each(view, &surface->views, surface_link)
|
||
|
weston_view_unmap(view);
|
||
|
surface->output = NULL;
|
||
13 years ago
|
}
|
||
|
|
||
11 years ago
|
static void
|
||
|
weston_surface_reset_pending_buffer(struct weston_surface *surface)
|
||
|
{
|
||
11 years ago
|
weston_surface_state_set_buffer(&surface->pending, NULL);
|
||
11 years ago
|
surface->pending.sx = 0;
|
||
|
surface->pending.sy = 0;
|
||
|
surface->pending.newly_attached = 0;
|
||
11 years ago
|
surface->pending.buffer_viewport.changed = 0;
|
||
11 years ago
|
}
|
||
|
|
||
11 years ago
|
WL_EXPORT void
|
||
|
weston_view_destroy(struct weston_view *view)
|
||
|
{
|
||
|
wl_signal_emit(&view->destroy_signal, view);
|
||
|
|
||
|
assert(wl_list_empty(&view->geometry.child_list));
|
||
|
|
||
|
if (weston_view_is_mapped(view)) {
|
||
|
weston_view_unmap(view);
|
||
|
weston_compositor_build_view_list(view->surface->compositor);
|
||
|
}
|
||
|
|
||
|
wl_list_remove(&view->link);
|
||
10 years ago
|
weston_layer_entry_remove(&view->layer_link);
|
||
11 years ago
|
|
||
|
pixman_region32_fini(&view->clip);
|
||
10 years ago
|
pixman_region32_fini(&view->geometry.scissor);
|
||
11 years ago
|
pixman_region32_fini(&view->transform.boundingbox);
|
||
10 years ago
|
pixman_region32_fini(&view->transform.opaque);
|
||
11 years ago
|
|
||
|
weston_view_set_transform_parent(view, NULL);
|
||
|
|
||
|
wl_list_remove(&view->surface_link);
|
||
|
|
||
|
free(view);
|
||
|
}
|
||
12 years ago
|
|
||
|
WL_EXPORT void
|
||
|
weston_surface_destroy(struct weston_surface *surface)
|
||
16 years ago
|
{
|
||
12 years ago
|
struct weston_frame_callback *cb, *next;
|
||
11 years ago
|
struct weston_view *ev, *nv;
|
||
16 years ago
|
|
||
11 years ago
|
if (--surface->ref_count > 0)
|
||
|
return;
|
||
|
|
||
10 years ago
|
assert(surface->resource == NULL);
|
||
|
|
||
10 years ago
|
wl_signal_emit(&surface->destroy_signal, surface);
|
||
11 years ago
|
|
||
12 years ago
|
assert(wl_list_empty(&surface->subsurface_list_pending));
|
||
|
assert(wl_list_empty(&surface->subsurface_list));
|
||
12 years ago
|
|
||
11 years ago
|
wl_list_for_each_safe(ev, nv, &surface->views, surface_link)
|
||
|
weston_view_destroy(ev);
|
||
13 years ago
|
|
||
11 years ago
|
weston_surface_state_fini(&surface->pending);
|
||
12 years ago
|
|
||
12 years ago
|
weston_buffer_reference(&surface->buffer_ref, NULL);
|
||
15 years ago
|
|
||
13 years ago
|
pixman_region32_fini(&surface->damage);
|
||
13 years ago
|
pixman_region32_fini(&surface->opaque);
|
||
12 years ago
|
pixman_region32_fini(&surface->input);
|
||
13 years ago
|
|
||
12 years ago
|
wl_list_for_each_safe(cb, next, &surface->frame_callback_list, link)
|
||
12 years ago
|
wl_resource_destroy(cb->resource);
|
||
12 years ago
|
|
||
10 years ago
|
weston_presentation_feedback_discard_list(&surface->feedback_list);
|
||
|
|
||
16 years ago
|
free(surface);
|
||
16 years ago
|
}
|
||
|
|
||
12 years ago
|
static void
|
||
|
destroy_surface(struct wl_resource *resource)
|
||
13 years ago
|
{
|
||
12 years ago
|
struct weston_surface *surface = wl_resource_get_user_data(resource);
|
||
13 years ago
|
|
||
10 years ago
|
assert(surface);
|
||
|
|
||
11 years ago
|
/* Set the resource to NULL, since we don't want to leave a
|
||
|
* dangling pointer if the surface was refcounted and survives
|
||
|
* the weston_surface_destroy() call. */
|
||
|
surface->resource = NULL;
|
||
9 years ago
|
|
||
|
if (surface->viewport_resource)
|
||
|
wl_resource_set_user_data(surface->viewport_resource, NULL);
|
||
|
|
||
12 years ago
|
weston_surface_destroy(surface);
|
||
13 years ago
|
}
|
||
|
|
||
12 years ago
|
static void
|
||
|
weston_buffer_destroy_handler(struct wl_listener *listener, void *data)
|
||
|
{
|
||
|
struct weston_buffer *buffer =
|
||
|
container_of(listener, struct weston_buffer, destroy_listener);
|
||
|
|
||
|
wl_signal_emit(&buffer->destroy_signal, buffer);
|
||
|
free(buffer);
|
||
|
}
|
||
|
|
||
11 years ago
|
WL_EXPORT struct weston_buffer *
|
||
12 years ago
|
weston_buffer_from_resource(struct wl_resource *resource)
|
||
|
{
|
||
|
struct weston_buffer *buffer;
|
||
|
struct wl_listener *listener;
|
||
11 years ago
|
|
||
12 years ago
|
listener = wl_resource_get_destroy_listener(resource,
|
||
|
weston_buffer_destroy_handler);
|
||
|
|
||
11 years ago
|
if (listener)
|
||
|
return container_of(listener, struct weston_buffer,
|
||
|
destroy_listener);
|
||
|
|
||
|
buffer = zalloc(sizeof *buffer);
|
||
|
if (buffer == NULL)
|
||
|
return NULL;
|
||
|
|
||
|
buffer->resource = resource;
|
||
|
wl_signal_init(&buffer->destroy_signal);
|
||
|
buffer->destroy_listener.notify = weston_buffer_destroy_handler;
|
||
11 years ago
|
buffer->y_inverted = 1;
|
||
11 years ago
|
wl_resource_add_destroy_listener(resource, &buffer->destroy_listener);
|
||
11 years ago
|
|
||
12 years ago
|
return buffer;
|
||
|
}
|
||
|
|
||
14 years ago
|
static void
|
||
12 years ago
|
weston_buffer_reference_handle_destroy(struct wl_listener *listener,
|
||
|
void *data)
|
||
|
{
|
||
|
struct weston_buffer_reference *ref =
|
||
|
container_of(listener, struct weston_buffer_reference,
|
||
|
destroy_listener);
|
||
|
|
||
12 years ago
|
assert((struct weston_buffer *)data == ref->buffer);
|
||
12 years ago
|
ref->buffer = NULL;
|
||
|
}
|
||
|
|
||
|
WL_EXPORT void
|
||
|
weston_buffer_reference(struct weston_buffer_reference *ref,
|
||
12 years ago
|
struct weston_buffer *buffer)
|
||
14 years ago
|
{
|
||
12 years ago
|
if (ref->buffer && buffer != ref->buffer) {
|
||
12 years ago
|
ref->buffer->busy_count--;
|
||
|
if (ref->buffer->busy_count == 0) {
|
||
12 years ago
|
assert(wl_resource_get_client(ref->buffer->resource));
|
||
|
wl_resource_queue_event(ref->buffer->resource,
|
||
12 years ago
|
WL_BUFFER_RELEASE);
|
||
|
}
|
||
12 years ago
|
wl_list_remove(&ref->destroy_listener.link);
|
||
13 years ago
|
}
|
||
|
|
||
12 years ago
|
if (buffer && buffer != ref->buffer) {
|
||
12 years ago
|
buffer->busy_count++;
|
||
12 years ago
|
wl_signal_add(&buffer->destroy_signal,
|
||
12 years ago
|
&ref->destroy_listener);
|
||
12 years ago
|
}
|
||
|
|
||
12 years ago
|
ref->buffer = buffer;
|
||
|
ref->destroy_listener.notify = weston_buffer_reference_handle_destroy;
|
||
|
}
|
||
|
|
||
|
static void
|
||
12 years ago
|
weston_surface_attach(struct weston_surface *surface,
|
||
|
struct weston_buffer *buffer)
|
||
12 years ago
|
{
|
||
|
weston_buffer_reference(&surface->buffer_ref, buffer);
|
||
|
|
||
12 years ago
|
if (!buffer) {
|
||
12 years ago
|
if (weston_surface_is_mapped(surface))
|
||
|
weston_surface_unmap(surface);
|
||
13 years ago
|
}
|
||
|
|
||
12 years ago
|
surface->compositor->renderer->attach(surface, buffer);
|
||
11 years ago
|
|
||
11 years ago
|
weston_surface_calculate_size_from_buffer(surface);
|
||
10 years ago
|
weston_presentation_feedback_discard_list(&surface->feedback_list);
|
||
14 years ago
|
}
|
||
|
|
||
14 years ago
|
WL_EXPORT void
|
||
13 years ago
|
weston_compositor_damage_all(struct weston_compositor *compositor)
|
||
14 years ago
|
{
|
||
13 years ago
|
struct weston_output *output;
|
||
14 years ago
|
|
||
|
wl_list_for_each(output, &compositor->output_list, link)
|
||
13 years ago
|
weston_output_damage(output);
|
||
14 years ago
|
}
|
||
|
|
||
14 years ago
|
WL_EXPORT void
|
||
13 years ago
|
weston_output_damage(struct weston_output *output)
|
||
14 years ago
|
{
|
||
13 years ago
|
struct weston_compositor *compositor = output->compositor;
|
||
13 years ago
|
|
||
12 years ago
|
pixman_region32_union(&compositor->primary_plane.damage,
|
||
|
&compositor->primary_plane.damage,
|
||
|
&output->region);
|
||
13 years ago
|
weston_output_schedule_repaint(output);
|
||
14 years ago
|
}
|
||
|
|
||
13 years ago
|
static void
|
||
11 years ago
|
surface_flush_damage(struct weston_surface *surface)
|
||
13 years ago
|
{
|
||
12 years ago
|
if (surface->buffer_ref.buffer &&
|
||
12 years ago
|
wl_shm_buffer_get(surface->buffer_ref.buffer->resource))
|
||
12 years ago
|
surface->compositor->renderer->flush_damage(surface);
|
||
13 years ago
|
|
||
10 years ago
|
if (weston_timeline_enabled_ &&
|
||
|
pixman_region32_not_empty(&surface->damage))
|
||
|
TL_POINT("core_flush_damage", TLP_SURFACE(surface),
|
||
|
TLP_OUTPUT(surface->output), TLP_END);
|
||
|
|
||
11 years ago
|
pixman_region32_clear(&surface->damage);
|
||
11 years ago
|
}
|
||
|
|
||
|
static void
|
||
|
view_accumulate_damage(struct weston_view *view,
|
||
|
pixman_region32_t *opaque)
|
||
|
{
|
||
|
pixman_region32_t damage;
|
||
|
|
||
|
pixman_region32_init(&damage);
|
||
|
if (view->transform.enabled) {
|
||
13 years ago
|
pixman_box32_t *extents;
|
||
|
|
||
11 years ago
|
extents = pixman_region32_extents(&view->surface->damage);
|
||
10 years ago
|
view_compute_bbox(view, extents, &damage);
|
||
13 years ago
|
} else {
|
||
11 years ago
|
pixman_region32_copy(&damage, &view->surface->damage);
|
||
|
pixman_region32_translate(&damage,
|
||
10 years ago
|
view->geometry.x, view->geometry.y);
|
||
13 years ago
|
}
|
||
|
|
||
10 years ago
|
pixman_region32_intersect(&damage, &damage,
|
||
|
&view->transform.boundingbox);
|
||
11 years ago
|
pixman_region32_subtract(&damage, &damage, opaque);
|
||
|
pixman_region32_union(&view->plane->damage,
|
||
|
&view->plane->damage, &damage);
|
||
|
pixman_region32_fini(&damage);
|
||
|
pixman_region32_copy(&view->clip, opaque);
|
||
10 years ago
|
pixman_region32_union(opaque, opaque, &view->transform.opaque);
|
||
13 years ago
|
}
|
||
|
|
||
12 years ago
|
static void
|
||
|
compositor_accumulate_damage(struct weston_compositor *ec)
|
||
|
{
|
||
|
struct weston_plane *plane;
|
||
11 years ago
|
struct weston_view *ev;
|
||
12 years ago
|
pixman_region32_t opaque, clip;
|
||
12 years ago
|
|
||
12 years ago
|
pixman_region32_init(&clip);
|
||
12 years ago
|
|
||
|
wl_list_for_each(plane, &ec->plane_list, link) {
|
||
12 years ago
|
pixman_region32_copy(&plane->clip, &clip);
|
||
|
|
||
|
pixman_region32_init(&opaque);
|
||
|
|
||
11 years ago
|
wl_list_for_each(ev, &ec->view_list, link) {
|
||
|
if (ev->plane != plane)
|
||
12 years ago
|
continue;
|
||
|
|
||
11 years ago
|
view_accumulate_damage(ev, &opaque);
|
||
12 years ago
|
}
|
||
|
|
||
|
pixman_region32_union(&clip, &clip, &opaque);
|
||
|
pixman_region32_fini(&opaque);
|
||
12 years ago
|
}
|
||
|
|
||
12 years ago
|
pixman_region32_fini(&clip);
|
||
12 years ago
|
|
||
11 years ago
|
wl_list_for_each(ev, &ec->view_list, link)
|
||
9 years ago
|
ev->surface->touched = false;
|
||
11 years ago
|
|
||
|
wl_list_for_each(ev, &ec->view_list, link) {
|
||
|
if (ev->surface->touched)
|
||
|
continue;
|
||
9 years ago
|
ev->surface->touched = true;
|
||
11 years ago
|
|
||
|
surface_flush_damage(ev->surface);
|
||
|
|
||
12 years ago
|
/* Both the renderer and the backend have seen the buffer
|
||
|
* by now. If renderer needs the buffer, it has its own
|
||
|
* reference set. If the backend wants to keep the buffer
|
||
|
* around for migrating the surface into a non-primary plane
|
||
|
* later, keep_buffer is true. Otherwise, drop the core
|
||
|
* reference now, and allow early buffer release. This enables
|
||
|
* clients to use single-buffering.
|
||
|
*/
|
||
11 years ago
|
if (!ev->surface->keep_buffer)
|
||
|
weston_buffer_reference(&ev->surface->buffer_ref, NULL);
|
||
12 years ago
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
static void
|
||
11 years ago
|
surface_stash_subsurface_views(struct weston_surface *surface)
|
||
12 years ago
|
{
|
||
|
struct weston_subsurface *sub;
|
||
|
|
||
11 years ago
|
wl_list_for_each(sub, &surface->subsurface_list, parent_link) {
|
||
|
if (sub->surface == surface)
|
||
|
continue;
|
||
|
|
||
|
wl_list_insert_list(&sub->unused_views, &sub->surface->views);
|
||
|
wl_list_init(&sub->surface->views);
|
||
|
|
||
|
surface_stash_subsurface_views(sub->surface);
|
||
12 years ago
|
}
|
||
11 years ago
|
}
|
||
|
|
||
|
static void
|
||
|
surface_free_unused_subsurface_views(struct weston_surface *surface)
|
||
|
{
|
||
|
struct weston_subsurface *sub;
|
||
|
struct weston_view *view, *nv;
|
||
12 years ago
|
|
||
|
wl_list_for_each(sub, &surface->subsurface_list, parent_link) {
|
||
11 years ago
|
if (sub->surface == surface)
|
||
12 years ago
|
continue;
|
||
|
|
||
11 years ago
|
wl_list_for_each_safe(view, nv, &sub->unused_views, surface_link) {
|
||
|
weston_view_unmap (view);
|
||
11 years ago
|
weston_view_destroy(view);
|
||
11 years ago
|
}
|
||
11 years ago
|
|
||
|
surface_free_unused_subsurface_views(sub->surface);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
view_list_add_subsurface_view(struct weston_compositor *compositor,
|
||
|
struct weston_subsurface *sub,
|
||
|
struct weston_view *parent)
|
||
|
{
|
||
|
struct weston_subsurface *child;
|
||
|
struct weston_view *view = NULL, *iv;
|
||
|
|
||
10 years ago
|
if (!weston_surface_is_mapped(sub->surface))
|
||
|
return;
|
||
|
|
||
11 years ago
|
wl_list_for_each(iv, &sub->unused_views, surface_link) {
|
||
|
if (iv->geometry.parent == parent) {
|
||
|
view = iv;
|
||
|
break;
|
||
12 years ago
|
}
|
||
|
}
|
||
11 years ago
|
|
||
|
if (view) {
|
||
|
/* Put it back in the surface's list of views */
|
||
|
wl_list_remove(&view->surface_link);
|
||
|
wl_list_insert(&sub->surface->views, &view->surface_link);
|
||
|
} else {
|
||
|
view = weston_view_create(sub->surface);
|
||
11 years ago
|
weston_view_set_position(view,
|
||
|
sub->position.x,
|
||
|
sub->position.y);
|
||
11 years ago
|
weston_view_set_transform_parent(view, parent);
|
||
|
}
|
||
|
|
||
10 years ago
|
view->parent_view = parent;
|
||
11 years ago
|
weston_view_update_transform(view);
|
||
|
|
||
11 years ago
|
if (wl_list_empty(&sub->surface->subsurface_list)) {
|
||
|
wl_list_insert(compositor->view_list.prev, &view->link);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
wl_list_for_each(child, &sub->surface->subsurface_list, parent_link) {
|
||
|
if (child->surface == sub->surface)
|
||
|
wl_list_insert(compositor->view_list.prev, &view->link);
|
||
|
else
|
||
11 years ago
|
view_list_add_subsurface_view(compositor, child, view);
|
||
11 years ago
|
}
|
||
12 years ago
|
}
|
||
|
|
||
|
static void
|
||
11 years ago
|
view_list_add(struct weston_compositor *compositor,
|
||
|
struct weston_view *view)
|
||
12 years ago
|
{
|
||
11 years ago
|
struct weston_subsurface *sub;
|
||
|
|
||
|
weston_view_update_transform(view);
|
||
|
|
||
11 years ago
|
if (wl_list_empty(&view->surface->subsurface_list)) {
|
||
|
wl_list_insert(compositor->view_list.prev, &view->link);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
wl_list_for_each(sub, &view->surface->subsurface_list, parent_link) {
|
||
|
if (sub->surface == view->surface)
|
||
|
wl_list_insert(compositor->view_list.prev, &view->link);
|
||
|
else
|
||
11 years ago
|
view_list_add_subsurface_view(compositor, sub, view);
|
||
11 years ago
|
}
|
||
11 years ago
|
}
|
||
|
|
||
|
static void
|
||
|
weston_compositor_build_view_list(struct weston_compositor *compositor)
|
||
|
{
|
||
|
struct weston_view *view;
|
||
12 years ago
|
struct weston_layer *layer;
|
||
|
|
||
11 years ago
|
wl_list_for_each(layer, &compositor->layer_list, link)
|
||
10 years ago
|
wl_list_for_each(view, &layer->view_list.link, layer_link.link)
|
||
11 years ago
|
surface_stash_subsurface_views(view->surface);
|
||
|
|
||
|
wl_list_init(&compositor->view_list);
|
||
12 years ago
|
wl_list_for_each(layer, &compositor->layer_list, link) {
|
||
10 years ago
|
wl_list_for_each(view, &layer->view_list.link, layer_link.link) {
|
||
11 years ago
|
view_list_add(compositor, view);
|
||
12 years ago
|
}
|
||
|
}
|
||
11 years ago
|
|
||
|
wl_list_for_each(layer, &compositor->layer_list, link)
|
||
10 years ago
|
wl_list_for_each(view, &layer->view_list.link, layer_link.link)
|
||
11 years ago
|
surface_free_unused_subsurface_views(view->surface);
|
||
12 years ago
|
}
|
||
|
|
||
10 years ago
|
static void
|
||
|
weston_output_take_feedback_list(struct weston_output *output,
|
||
|
struct weston_surface *surface)
|
||
|
{
|
||
|
struct weston_view *view;
|
||
|
struct weston_presentation_feedback *feedback;
|
||
|
uint32_t flags = 0xffffffff;
|
||
|
|
||
|
if (wl_list_empty(&surface->feedback_list))
|
||
|
return;
|
||
|
|
||
|
/* All views must have the flag for the flag to survive. */
|
||
|
wl_list_for_each(view, &surface->views, surface_link) {
|
||
|
/* ignore views that are not on this output at all */
|
||
|
if (view->output_mask & (1u << output->id))
|
||
|
flags &= view->psf_flags;
|
||
|
}
|
||
|
|
||
|
wl_list_for_each(feedback, &surface->feedback_list, link)
|
||
|
feedback->psf_flags = flags;
|
||
|
|
||
|
wl_list_insert_list(&output->feedback_list, &surface->feedback_list);
|
||
|
wl_list_init(&surface->feedback_list);
|
||
|
}
|
||
|
|
||
11 years ago
|
static int
|
||
10 years ago
|
weston_output_repaint(struct weston_output *output)
|
||
16 years ago
|
{
|
||
13 years ago
|
struct weston_compositor *ec = output->compositor;
|
||
11 years ago
|
struct weston_view *ev;
|
||
13 years ago
|
struct weston_animation *animation, *next;
|
||
|
struct weston_frame_callback *cb, *cnext;
|
||
13 years ago
|
struct wl_list frame_callback_list;
|
||
12 years ago
|
pixman_region32_t output_damage;
|
||
11 years ago
|
int r;
|
||
16 years ago
|
|
||
11 years ago
|
if (output->destroying)
|
||
|
return 0;
|
||
|
|
||
10 years ago
|
TL_POINT("core_repaint_begin", TLP_OUTPUT(output), TLP_END);
|
||
|
|
||
13 years ago
|
/* Rebuild the surface list and update surface transforms up front. */
|
||
11 years ago
|
weston_compositor_build_view_list(ec);
|
||
13 years ago
|
|
||
10 years ago
|
if (output->assign_planes && !output->disable_planes) {
|
||
13 years ago
|
output->assign_planes(output);
|
||
10 years ago
|
} else {
|
||
|
wl_list_for_each(ev, &ec->view_list, link) {
|
||
11 years ago
|
weston_view_move_to_plane(ev, &ec->primary_plane);
|
||
10 years ago
|
ev->psf_flags = 0;
|
||
|
}
|
||
|
}
|
||
12 years ago
|
|
||
12 years ago
|
wl_list_init(&frame_callback_list);
|
||
11 years ago
|
wl_list_for_each(ev, &ec->view_list, link) {
|
||
|
/* Note: This operation is safe to do multiple times on the
|
||
|
* same surface.
|
||
|
*/
|
||
|
if (ev->surface->output == output) {
|
||
12 years ago
|
wl_list_insert_list(&frame_callback_list,
|
||
11 years ago
|
&ev->surface->frame_callback_list);
|
||
|
wl_list_init(&ev->surface->frame_callback_list);
|
||
10 years ago
|
|
||
10 years ago
|
weston_output_take_feedback_list(output, ev->surface);
|
||
12 years ago
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
compositor_accumulate_damage(ec);
|
||
12 years ago
|
|
||
13 years ago
|
pixman_region32_init(&output_damage);
|
||
|
pixman_region32_intersect(&output_damage,
|
||
12 years ago
|
&ec->primary_plane.damage, &output->region);
|
||
12 years ago
|
pixman_region32_subtract(&output_damage,
|
||
|
&output_damage, &ec->primary_plane.clip);
|
||
14 years ago
|
|
||
13 years ago
|
if (output->dirty)
|
||
|
weston_output_update_matrix(output);
|
||
|
|
||
11 years ago
|
r = output->repaint(output, &output_damage);
|
||
16 years ago
|
|
||
13 years ago
|
pixman_region32_fini(&output_damage);
|
||
16 years ago
|
|
||
14 years ago
|
output->repaint_needed = 0;
|
||
14 years ago
|
|
||
13 years ago
|
weston_compositor_repick(ec);
|
||
|
|
||
13 years ago
|
wl_list_for_each_safe(cb, cnext, &frame_callback_list, link) {
|
||
10 years ago
|
wl_callback_send_done(cb->resource, output->frame_time);
|
||
12 years ago
|
wl_resource_destroy(cb->resource);
|
||
14 years ago
|
}
|
||
15 years ago
|
|
||
13 years ago
|
wl_list_for_each_safe(animation, next, &output->animation_list, link) {
|
||
|
animation->frame_counter++;
|
||
10 years ago
|
animation->frame(animation, output, output->frame_time);
|
||
13 years ago
|
}
|
||
11 years ago
|
|
||
10 years ago
|
TL_POINT("core_repaint_posted", TLP_OUTPUT(output), TLP_END);
|
||
|
|
||
11 years ago
|
return r;
|
||
14 years ago
|
}
|
||
14 years ago
|
|
||
11 years ago
|
static void
|
||
|
weston_output_schedule_repaint_reset(struct weston_output *output)
|
||
|
{
|
||
|
output->repaint_scheduled = 0;
|
||
|
TL_POINT("core_repaint_exit_loop", TLP_OUTPUT(output), TLP_END);
|
||
|
}
|
||
|
|
||
11 years ago
|
static int
|
||
|
output_repaint_timer_handler(void *data)
|
||
|
{
|
||
|
struct weston_output *output = data;
|
||
|
struct weston_compositor *compositor = output->compositor;
|
||
|
|
||
|
if (output->repaint_needed &&
|
||
|
compositor->state != WESTON_COMPOSITOR_SLEEPING &&
|
||
|
compositor->state != WESTON_COMPOSITOR_OFFSCREEN &&
|
||
|
weston_output_repaint(output) == 0)
|
||
|
return 0;
|
||
|
|
||
|
weston_output_schedule_repaint_reset(output);
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
14 years ago
|
WL_EXPORT void
|
||
10 years ago
|
weston_output_finish_frame(struct weston_output *output,
|
||
10 years ago
|
const struct timespec *stamp,
|
||
|
uint32_t presented_flags)
|
||
14 years ago
|
{
|
||
13 years ago
|
struct weston_compositor *compositor = output->compositor;
|
||
11 years ago
|
int32_t refresh_nsec;
|
||
|
struct timespec now;
|
||
|
struct timespec gone;
|
||
|
int msec;
|
||
10 years ago
|
|
||
10 years ago
|
TL_POINT("core_repaint_finished", TLP_OUTPUT(output),
|
||
|
TLP_VBLANK(stamp), TLP_END);
|
||
|
|
||
9 years ago
|
refresh_nsec = millihz_to_nsec(output->current_mode->refresh);
|
||
10 years ago
|
weston_presentation_feedback_present_list(&output->feedback_list,
|
||
|
output, refresh_nsec, stamp,
|
||
10 years ago
|
output->msc,
|
||
|
presented_flags);
|
||
13 years ago
|
|
||
10 years ago
|
output->frame_time = stamp->tv_sec * 1000 + stamp->tv_nsec / 1000000;
|
||
11 years ago
|
|
||
11 years ago
|
weston_compositor_read_presentation_clock(compositor, &now);
|
||
|
timespec_sub(&gone, &now, stamp);
|
||
|
msec = (refresh_nsec - timespec_to_nsec(&gone)) / 1000000; /* floor */
|
||
|
msec -= compositor->repaint_msec;
|
||
13 years ago
|
|
||
10 years ago
|
if (msec < -1000 || msec > 1000) {
|
||
|
static bool warned;
|
||
|
|
||
|
if (!warned)
|
||
|
weston_log("Warning: computed repaint delay is "
|
||
|
"insane: %d msec\n", msec);
|
||
|
warned = true;
|
||
|
|
||
|
msec = 0;
|
||
|
}
|
||
|
|
||
10 years ago
|
/* Called from restart_repaint_loop and restart happens already after
|
||
|
* the deadline given by repaint_msec? In that case we delay until
|
||
|
* the deadline of the next frame, to give clients a more predictable
|
||
|
* timing of the repaint cycle to lock on. */
|
||
9 years ago
|
if (presented_flags == WP_PRESENTATION_FEEDBACK_INVALID && msec < 0)
|
||
10 years ago
|
msec += refresh_nsec / 1000000;
|
||
|
|
||
10 years ago
|
if (msec < 1)
|
||
11 years ago
|
output_repaint_timer_handler(output);
|
||
|
else
|
||
|
wl_event_source_timer_update(output->repaint_timer, msec);
|
||
13 years ago
|
}
|
||
|
|
||
|
static void
|
||
|
idle_repaint(void *data)
|
||
|
{
|
||
|
struct weston_output *output = data;
|
||
|
|
||
12 years ago
|
output->start_repaint_loop(output);
|
||
16 years ago
|
}
|
||
|
|
||
10 years ago
|
WL_EXPORT void
|
||
|
weston_layer_entry_insert(struct weston_layer_entry *list,
|
||
|
struct weston_layer_entry *entry)
|
||
|
{
|
||
|
wl_list_insert(&list->link, &entry->link);
|
||
|
entry->layer = list->layer;
|
||
|
}
|
||
|
|
||
|
WL_EXPORT void
|
||
|
weston_layer_entry_remove(struct weston_layer_entry *entry)
|
||
|
{
|
||
|
wl_list_remove(&entry->link);
|
||
|
wl_list_init(&entry->link);
|
||
|
entry->layer = NULL;
|
||
|
}
|
||
|
|
||
13 years ago
|
WL_EXPORT void
|
||
|
weston_layer_init(struct weston_layer *layer, struct wl_list *below)
|
||
|
{
|
||
10 years ago
|
wl_list_init(&layer->view_list.link);
|
||
|
layer->view_list.layer = layer;
|
||
10 years ago
|
weston_layer_set_mask_infinite(layer);
|
||
13 years ago
|
if (below != NULL)
|
||
|
wl_list_insert(below, &layer->link);
|
||
13 years ago
|
}
|
||
|
|
||
10 years ago
|
WL_EXPORT void
|
||
|
weston_layer_set_mask(struct weston_layer *layer,
|
||
|
int x, int y, int width, int height)
|
||
|
{
|
||
|
struct weston_view *view;
|
||
|
|
||
|
layer->mask.x1 = x;
|
||
|
layer->mask.x2 = x + width;
|
||
|
layer->mask.y1 = y;
|
||
|
layer->mask.y2 = y + height;
|
||
|
|
||
|
wl_list_for_each(view, &layer->view_list.link, layer_link.link) {
|
||
|
weston_view_geometry_dirty(view);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
WL_EXPORT void
|
||
|
weston_layer_set_mask_infinite(struct weston_layer *layer)
|
||
|
{
|
||
|
weston_layer_set_mask(layer, INT32_MIN, INT32_MIN,
|
||
|
UINT32_MAX, UINT32_MAX);
|
||
|
}
|
||
|
|
||
14 years ago
|
WL_EXPORT void
|
||
13 years ago
|
weston_output_schedule_repaint(struct weston_output *output)
|
||
16 years ago
|
{
|
||
13 years ago
|
struct weston_compositor *compositor = output->compositor;
|
||
14 years ago
|
struct wl_event_loop *loop;
|
||
14 years ago
|
|
||
12 years ago
|
if (compositor->state == WESTON_COMPOSITOR_SLEEPING ||
|
||
|
compositor->state == WESTON_COMPOSITOR_OFFSCREEN)
|
||
14 years ago
|
return;
|
||
|
|
||
10 years ago
|
if (!output->repaint_needed)
|
||
|
TL_POINT("core_repaint_req", TLP_OUTPUT(output), TLP_END);
|
||
|
|
||
14 years ago
|
loop = wl_display_get_event_loop(compositor->wl_display);
|
||
13 years ago
|
output->repaint_needed = 1;
|
||
|
if (output->repaint_scheduled)
|
||
|
return;
|
||
14 years ago
|
|
||
13 years ago
|
wl_event_loop_add_idle(loop, idle_repaint, output);
|
||
|
output->repaint_scheduled = 1;
|
||
10 years ago
|
TL_POINT("core_repaint_enter_loop", TLP_OUTPUT(output), TLP_END);
|
||
16 years ago
|
}
|
||
16 years ago
|
|
||
13 years ago
|
WL_EXPORT void
|
||
|
weston_compositor_schedule_repaint(struct weston_compositor *compositor)
|
||
|
{
|
||
|
struct weston_output *output;
|
||
|
|
||
|
wl_list_for_each(output, &compositor->output_list, link)
|
||
|
weston_output_schedule_repaint(output);
|
||
|
}
|
||
|
|
||
16 years ago
|
static void
|
||
13 years ago
|
surface_destroy(struct wl_client *client, struct wl_resource *resource)
|
||
16 years ago
|
{
|
||
13 years ago
|
wl_resource_destroy(resource);
|
||
16 years ago
|
}
|
||
|
|
||
13 years ago
|
static void
|
||
|
surface_attach(struct wl_client *client,
|
||
|
struct wl_resource *resource,
|
||
|
struct wl_resource *buffer_resource, int32_t sx, int32_t sy)
|
||
|
{
|
||
12 years ago
|
struct weston_surface *surface = wl_resource_get_user_data(resource);
|
||
12 years ago
|
struct weston_buffer *buffer = NULL;
|
||
13 years ago
|
|
||
11 years ago
|
if (buffer_resource) {
|
||
12 years ago
|
buffer = weston_buffer_from_resource(buffer_resource);
|
||
11 years ago
|
if (buffer == NULL) {
|
||
|
wl_client_post_no_memory(client);
|
||
|
return;
|
||
|
}
|
||
11 years ago
|
}
|
||
14 years ago
|
|
||
12 years ago
|
/* Attach, attach, without commit in between does not send
|
||
|
* wl_buffer.release. */
|
||
11 years ago
|
weston_surface_state_set_buffer(&surface->pending, buffer);
|
||
13 years ago
|
|
||
12 years ago
|
surface->pending.sx = sx;
|
||
|
surface->pending.sy = sy;
|
||
12 years ago
|
surface->pending.newly_attached = 1;
|
||
16 years ago
|
}
|
||
|
|
||
13 years ago
|
static void
|
||
|
surface_damage(struct wl_client *client,
|
||
|
struct wl_resource *resource,
|
||
|
int32_t x, int32_t y, int32_t width, int32_t height)
|
||
|
{
|
||
12 years ago
|
struct weston_surface *surface = wl_resource_get_user_data(resource);
|
||
13 years ago
|
|
||
9 years ago
|
if (width <= 0 || height <= 0)
|
||
|
return;
|
||
|
|
||
9 years ago
|
pixman_region32_union_rect(&surface->pending.damage_surface,
|
||
|
&surface->pending.damage_surface,
|
||
|
x, y, width, height);
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
surface_damage_buffer(struct wl_client *client,
|
||
|
struct wl_resource *resource,
|
||
|
int32_t x, int32_t y, int32_t width, int32_t height)
|
||
|
{
|
||
|
struct weston_surface *surface = wl_resource_get_user_data(resource);
|
||
|
|
||
|
if (width <= 0 || height <= 0)
|
||
|
return;
|
||
|
|
||
|
pixman_region32_union_rect(&surface->pending.damage_buffer,
|
||
|
&surface->pending.damage_buffer,
|
||
13 years ago
|
x, y, width, height);
|
||
16 years ago
|
}
|
||
|
|
||
13 years ago
|
static void
|
||
13 years ago
|
destroy_frame_callback(struct wl_resource *resource)
|
||
13 years ago
|
{
|
||
12 years ago
|
struct weston_frame_callback *cb = wl_resource_get_user_data(resource);
|
||
13 years ago
|
|
||
|
wl_list_remove(&cb->link);
|
||
13 years ago
|
free(cb);
|
||
13 years ago
|
}
|
||
|
|
||
|
static void
|
||
|
surface_frame(struct wl_client *client,
|
||
13 years ago
|
struct wl_resource *resource, uint32_t callback)
|
||
13 years ago
|
{
|
||
13 years ago
|
struct weston_frame_callback *cb;
|
||
12 years ago
|
struct weston_surface *surface = wl_resource_get_user_data(resource);
|
||
13 years ago
|
|
||
|
cb = malloc(sizeof *cb);
|
||
|
if (cb == NULL) {
|
||
13 years ago
|
wl_resource_post_no_memory(resource);
|
||
13 years ago
|
return;
|
||
|
}
|
||
12 years ago
|
|
||
11 years ago
|
cb->resource = wl_resource_create(client, &wl_callback_interface, 1,
|
||
|
callback);
|
||
|
if (cb->resource == NULL) {
|
||
|
free(cb);
|
||
|
wl_resource_post_no_memory(resource);
|
||
|
return;
|
||
|
}
|
||
|
|
||
12 years ago
|
wl_resource_set_implementation(cb->resource, NULL, cb,
|
||
|
destroy_frame_callback);
|
||
13 years ago
|
|
||
12 years ago
|
wl_list_insert(surface->pending.frame_callback_list.prev, &cb->link);
|
||
13 years ago
|
}
|
||
|
|
||
13 years ago
|
static void
|
||
|
surface_set_opaque_region(struct wl_client *client,
|
||
|
struct wl_resource *resource,
|
||
|
struct wl_resource *region_resource)
|
||
|
{
|
||
12 years ago
|
struct weston_surface *surface = wl_resource_get_user_data(resource);
|
||
13 years ago
|
struct weston_region *region;
|
||
|
|
||
|
if (region_resource) {
|
||
12 years ago
|
region = wl_resource_get_user_data(region_resource);
|
||
12 years ago
|
pixman_region32_copy(&surface->pending.opaque,
|
||
|
®ion->region);
|
||
13 years ago
|
} else {
|
||
11 years ago
|
pixman_region32_clear(&surface->pending.opaque);
|
||
13 years ago
|
}
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
surface_set_input_region(struct wl_client *client,
|
||
|
struct wl_resource *resource,
|
||
|
struct wl_resource *region_resource)
|
||
|
{
|
||
12 years ago
|
struct weston_surface *surface = wl_resource_get_user_data(resource);
|
||
13 years ago
|
struct weston_region *region;
|
||
13 years ago
|
|
||
|
if (region_resource) {
|
||
12 years ago
|
region = wl_resource_get_user_data(region_resource);
|
||
12 years ago
|
pixman_region32_copy(&surface->pending.input,
|
||
|
®ion->region);
|
||
13 years ago
|
} else {
|
||
12 years ago
|
pixman_region32_fini(&surface->pending.input);
|
||
|
region_init_infinite(&surface->pending.input);
|
||
13 years ago
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
static void
|
||
12 years ago
|
weston_surface_commit_subsurface_order(struct weston_surface *surface)
|
||
|
{
|
||
|
struct weston_subsurface *sub;
|
||
|
|
||
|
wl_list_for_each_reverse(sub, &surface->subsurface_list_pending,
|
||
|
parent_link_pending) {
|
||
|
wl_list_remove(&sub->parent_link);
|
||
|
wl_list_insert(&surface->subsurface_list, &sub->parent_link);
|
||
|
}
|
||
|
}
|
||
|
|
||
10 years ago
|
static void
|
||
9 years ago
|
weston_surface_build_buffer_matrix(const struct weston_surface *surface,
|
||
10 years ago
|
struct weston_matrix *matrix)
|
||
|
{
|
||
9 years ago
|
const struct weston_buffer_viewport *vp = &surface->buffer_viewport;
|
||
10 years ago
|
double src_width, src_height, dest_width, dest_height;
|
||
|
|
||
|
weston_matrix_init(matrix);
|
||
|
|
||
|
if (vp->buffer.src_width == wl_fixed_from_int(-1)) {
|
||
|
src_width = surface->width_from_buffer;
|
||
|
src_height = surface->height_from_buffer;
|
||
|
} else {
|
||
|
src_width = wl_fixed_to_double(vp->buffer.src_width);
|
||
|
src_height = wl_fixed_to_double(vp->buffer.src_height);
|
||
|
}
|
||
|
|
||
|
if (vp->surface.width == -1) {
|
||
|
dest_width = src_width;
|
||
|
dest_height = src_height;
|
||
|
} else {
|
||
|
dest_width = vp->surface.width;
|
||
|
dest_height = vp->surface.height;
|
||
|
}
|
||
|
|
||
|
if (src_width != dest_width || src_height != dest_height)
|
||
|
weston_matrix_scale(matrix,
|
||
|
src_width / dest_width,
|
||
|
src_height / dest_height, 1);
|
||
|
|
||
|
if (vp->buffer.src_width != wl_fixed_from_int(-1))
|
||
|
weston_matrix_translate(matrix,
|
||
|
wl_fixed_to_double(vp->buffer.src_x),
|
||
|
wl_fixed_to_double(vp->buffer.src_y),
|
||
|
0);
|
||
|
|
||
|
switch (vp->buffer.transform) {
|
||
|
case WL_OUTPUT_TRANSFORM_FLIPPED:
|
||
|
case WL_OUTPUT_TRANSFORM_FLIPPED_90:
|
||
|
case WL_OUTPUT_TRANSFORM_FLIPPED_180:
|
||
|
case WL_OUTPUT_TRANSFORM_FLIPPED_270:
|
||
|
weston_matrix_scale(matrix, -1, 1, 1);
|
||
|
weston_matrix_translate(matrix,
|
||
|
surface->width_from_buffer, 0, 0);
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
switch (vp->buffer.transform) {
|
||
|
default:
|
||
|
case WL_OUTPUT_TRANSFORM_NORMAL:
|
||
|
case WL_OUTPUT_TRANSFORM_FLIPPED:
|
||
|
break;
|
||
|
case WL_OUTPUT_TRANSFORM_90:
|
||
|
case WL_OUTPUT_TRANSFORM_FLIPPED_90:
|
||
|
weston_matrix_rotate_xy(matrix, 0, 1);
|
||
|
weston_matrix_translate(matrix,
|
||
|
surface->height_from_buffer, 0, 0);
|
||
|
break;
|
||
|
case WL_OUTPUT_TRANSFORM_180:
|
||
|
case WL_OUTPUT_TRANSFORM_FLIPPED_180:
|
||
|
weston_matrix_rotate_xy(matrix, -1, 0);
|
||
|
weston_matrix_translate(matrix,
|
||
|
surface->width_from_buffer,
|
||
|
surface->height_from_buffer, 0);
|
||
|
break;
|
||
|
case WL_OUTPUT_TRANSFORM_270:
|
||
|
case WL_OUTPUT_TRANSFORM_FLIPPED_270:
|
||
|
weston_matrix_rotate_xy(matrix, 0, -1);
|
||
|
weston_matrix_translate(matrix,
|
||
|
0, surface->width_from_buffer, 0);
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
weston_matrix_scale(matrix, vp->buffer.scale, vp->buffer.scale, 1);
|
||
|
}
|
||
|
|
||
9 years ago
|
/**
|
||
|
* Compute a + b > c while being safe to overflows.
|
||
|
*/
|
||
|
static bool
|
||
|
fixed_sum_gt(wl_fixed_t a, wl_fixed_t b, wl_fixed_t c)
|
||
|
{
|
||
|
return (int64_t)a + (int64_t)b > (int64_t)c;
|
||
|
}
|
||
|
|
||
|
static bool
|
||
|
weston_surface_is_pending_viewport_source_valid(
|
||
|
const struct weston_surface *surface)
|
||
|
{
|
||
|
const struct weston_surface_state *pend = &surface->pending;
|
||
|
const struct weston_buffer_viewport *vp = &pend->buffer_viewport;
|
||
|
int width_from_buffer = 0;
|
||
|
int height_from_buffer = 0;
|
||
|
wl_fixed_t w;
|
||
|
wl_fixed_t h;
|
||
|
|
||
|
/* If viewport source rect is not set, it is always ok. */
|
||
|
if (vp->buffer.src_width == wl_fixed_from_int(-1))
|
||
|
return true;
|
||
|
|
||
|
if (pend->newly_attached) {
|
||
|
if (pend->buffer) {
|
||
|
convert_size_by_transform_scale(&width_from_buffer,
|
||
|
&height_from_buffer,
|
||
|
pend->buffer->width,
|
||
|
pend->buffer->height,
|
||
|
vp->buffer.transform,
|
||
|
vp->buffer.scale);
|
||
|
} else {
|
||
|
/* No buffer: viewport is irrelevant. */
|
||
|
return true;
|
||
|
}
|
||
|
} else {
|
||
|
width_from_buffer = surface->width_from_buffer;
|
||
|
height_from_buffer = surface->height_from_buffer;
|
||
|
}
|
||
|
|
||
|
assert((width_from_buffer == 0) == (height_from_buffer == 0));
|
||
|
assert(width_from_buffer >= 0 && height_from_buffer >= 0);
|
||
|
|
||
|
/* No buffer: viewport is irrelevant. */
|
||
|
if (width_from_buffer == 0 || height_from_buffer == 0)
|
||
|
return true;
|
||
|
|
||
|
/* overflow checks for wl_fixed_from_int() */
|
||
|
if (width_from_buffer > wl_fixed_to_int(INT32_MAX))
|
||
|
return false;
|
||
|
if (height_from_buffer > wl_fixed_to_int(INT32_MAX))
|
||
|
return false;
|
||
|
|
||
|
w = wl_fixed_from_int(width_from_buffer);
|
||
|
h = wl_fixed_from_int(height_from_buffer);
|
||
|
|
||
|
if (fixed_sum_gt(vp->buffer.src_x, vp->buffer.src_width, w))
|
||
|
return false;
|
||
|
if (fixed_sum_gt(vp->buffer.src_y, vp->buffer.src_height, h))
|
||
|
return false;
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
9 years ago
|
static bool
|
||
|
fixed_is_integer(wl_fixed_t v)
|
||
|
{
|
||
|
return (v & 0xff) == 0;
|
||
|
}
|
||
|
|
||
|
static bool
|
||
|
weston_surface_is_pending_viewport_dst_size_int(
|
||
|
const struct weston_surface *surface)
|
||
|
{
|
||
|
const struct weston_buffer_viewport *vp =
|
||
|
&surface->pending.buffer_viewport;
|
||
|
|
||
|
if (vp->surface.width != -1) {
|
||
|
assert(vp->surface.width > 0 && vp->surface.height > 0);
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
return fixed_is_integer(vp->buffer.src_width) &&
|
||
|
fixed_is_integer(vp->buffer.src_height);
|
||
|
}
|
||
|
|
||
9 years ago
|
/* Translate pending damage in buffer co-ordinates to surface
|
||
|
* co-ordinates and union it with a pixman_region32_t.
|
||
|
* This should only be called after the buffer is attached.
|
||
|
*/
|
||
|
static void
|
||
|
apply_damage_buffer(pixman_region32_t *dest,
|
||
|
struct weston_surface *surface,
|
||
|
struct weston_surface_state *state)
|
||
|
{
|
||
|
struct weston_buffer *buffer = surface->buffer_ref.buffer;
|
||
|
|
||
|
/* wl_surface.damage_buffer needs to be clipped to the buffer,
|
||
|
* translated into surface co-ordinates and unioned with
|
||
|
* any other surface damage.
|
||
|
* None of this makes sense if there is no buffer though.
|
||
|
*/
|
||
|
if (buffer && pixman_region32_not_empty(&state->damage_buffer)) {
|
||
|
pixman_region32_t buffer_damage;
|
||
|
|
||
|
pixman_region32_intersect_rect(&state->damage_buffer,
|
||
|
&state->damage_buffer,
|
||
|
0, 0, buffer->width,
|
||
|
buffer->height);
|
||
|
pixman_region32_init(&buffer_damage);
|
||
|
weston_matrix_transform_region(&buffer_damage,
|
||
|
&surface->buffer_to_surface_matrix,
|
||
|
&state->damage_buffer);
|
||
|
pixman_region32_union(dest, dest, &buffer_damage);
|
||
|
pixman_region32_fini(&buffer_damage);
|
||
|
}
|
||
|
/* We should clear this on commit even if there was no buffer */
|
||
|
pixman_region32_clear(&state->damage_buffer);
|
||
|
}
|
||
|
|
||
12 years ago
|
static void
|
||
11 years ago
|
weston_surface_commit_state(struct weston_surface *surface,
|
||
|
struct weston_surface_state *state)
|
||
12 years ago
|
{
|
||
11 years ago
|
struct weston_view *view;
|
||
12 years ago
|
pixman_region32_t opaque;
|
||
|
|
||
12 years ago
|
/* wl_surface.set_buffer_transform */
|
||
|
/* wl_surface.set_buffer_scale */
|
||
9 years ago
|
/* wp_viewport.set_source */
|
||
|
/* wp_viewport.set_destination */
|
||
11 years ago
|
surface->buffer_viewport = state->buffer_viewport;
|
||
12 years ago
|
|
||
12 years ago
|
/* wl_surface.attach */
|
||
11 years ago
|
if (state->newly_attached)
|
||
|
weston_surface_attach(surface, state->buffer);
|
||
|
weston_surface_state_set_buffer(state, NULL);
|
||
12 years ago
|
|
||
10 years ago
|
weston_surface_build_buffer_matrix(surface,
|
||
|
&surface->surface_to_buffer_matrix);
|
||
|
weston_matrix_invert(&surface->buffer_to_surface_matrix,
|
||
|
&surface->surface_to_buffer_matrix);
|
||
|
|
||
11 years ago
|
if (state->newly_attached || state->buffer_viewport.changed) {
|
||
11 years ago
|
weston_surface_update_size(surface);
|
||
|
if (surface->configure)
|
||
11 years ago
|
surface->configure(surface, state->sx, state->sy);
|
||
11 years ago
|
}
|
||
12 years ago
|
|
||
11 years ago
|
state->sx = 0;
|
||
|
state->sy = 0;
|
||
|
state->newly_attached = 0;
|
||
|
state->buffer_viewport.changed = 0;
|
||
12 years ago
|
|
||
9 years ago
|
/* wl_surface.damage and wl_surface.damage_buffer */
|
||
10 years ago
|
if (weston_timeline_enabled_ &&
|
||
9 years ago
|
(pixman_region32_not_empty(&state->damage_surface) ||
|
||
|
pixman_region32_not_empty(&state->damage_buffer)))
|
||
10 years ago
|
TL_POINT("core_commit_damage", TLP_SURFACE(surface), TLP_END);
|
||
9 years ago
|
|
||
12 years ago
|
pixman_region32_union(&surface->damage, &surface->damage,
|
||
9 years ago
|
&state->damage_surface);
|
||
|
|
||
|
apply_damage_buffer(&surface->damage, surface, state);
|
||
|
|
||
12 years ago
|
pixman_region32_intersect_rect(&surface->damage, &surface->damage,
|
||
11 years ago
|
0, 0, surface->width, surface->height);
|
||
9 years ago
|
pixman_region32_clear(&state->damage_surface);
|
||
12 years ago
|
|
||
|
/* wl_surface.set_opaque_region */
|
||
11 years ago
|
pixman_region32_init(&opaque);
|
||
|
pixman_region32_intersect_rect(&opaque, &state->opaque,
|
||
|
0, 0, surface->width, surface->height);
|
||
12 years ago
|
|
||
|
if (!pixman_region32_equal(&opaque, &surface->opaque)) {
|
||
|
pixman_region32_copy(&surface->opaque, &opaque);
|
||
11 years ago
|
wl_list_for_each(view, &surface->views, surface_link)
|
||
|
weston_view_geometry_dirty(view);
|
||
12 years ago
|
}
|
||
|
|
||
|
pixman_region32_fini(&opaque);
|
||
12 years ago
|
|
||
|
/* wl_surface.set_input_region */
|
||
11 years ago
|
pixman_region32_intersect_rect(&surface->input, &state->input,
|
||
|
0, 0, surface->width, surface->height);
|
||
12 years ago
|
|
||
12 years ago
|
/* wl_surface.frame */
|
||
|
wl_list_insert_list(&surface->frame_callback_list,
|
||
11 years ago
|
&state->frame_callback_list);
|
||
|
wl_list_init(&state->frame_callback_list);
|
||
10 years ago
|
|
||
|
/* XXX:
|
||
|
* What should happen with a feedback request, if there
|
||
|
* is no wl_buffer attached for this commit?
|
||
|
*/
|
||
|
|
||
|
/* presentation.feedback */
|
||
|
wl_list_insert_list(&surface->feedback_list,
|
||
|
&state->feedback_list);
|
||
|
wl_list_init(&state->feedback_list);
|
||
11 years ago
|
}
|
||
|
|
||
|
static void
|
||
|
weston_surface_commit(struct weston_surface *surface)
|
||
|
{
|
||
|
weston_surface_commit_state(surface, &surface->pending);
|
||
12 years ago
|
|
||
12 years ago
|
weston_surface_commit_subsurface_order(surface);
|
||
|
|
||
12 years ago
|
weston_surface_schedule_repaint(surface);
|
||
12 years ago
|
}
|
||
|
|
||
12 years ago
|
static void
|
||
|
weston_subsurface_commit(struct weston_subsurface *sub);
|
||
|
|
||
|
static void
|
||
|
weston_subsurface_parent_commit(struct weston_subsurface *sub,
|
||
|
int parent_is_synchronized);
|
||
|
|
||
|
static void
|
||
|
surface_commit(struct wl_client *client, struct wl_resource *resource)
|
||
|
{
|
||
12 years ago
|
struct weston_surface *surface = wl_resource_get_user_data(resource);
|
||
12 years ago
|
struct weston_subsurface *sub = weston_surface_to_subsurface(surface);
|
||
|
|
||
9 years ago
|
if (!weston_surface_is_pending_viewport_source_valid(surface)) {
|
||
|
assert(surface->viewport_resource);
|
||
|
|
||
|
wl_resource_post_error(surface->viewport_resource,
|
||
|
WP_VIEWPORT_ERROR_OUT_OF_BUFFER,
|
||
|
"wl_surface@%d has viewport source outside buffer",
|
||
|
wl_resource_get_id(resource));
|
||
|
return;
|
||
|
}
|
||
|
|
||
9 years ago
|
if (!weston_surface_is_pending_viewport_dst_size_int(surface)) {
|
||
|
assert(surface->viewport_resource);
|
||
|
|
||
|
wl_resource_post_error(surface->viewport_resource,
|
||
|
WP_VIEWPORT_ERROR_BAD_SIZE,
|
||
|
"wl_surface@%d viewport dst size not integer",
|
||
|
wl_resource_get_id(resource));
|
||
|
return;
|
||
|
}
|
||
|
|
||
12 years ago
|
if (sub) {
|
||
|
weston_subsurface_commit(sub);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
weston_surface_commit(surface);
|
||
|
|
||
|
wl_list_for_each(sub, &surface->subsurface_list, parent_link) {
|
||
|
if (sub->surface != surface)
|
||
|
weston_subsurface_parent_commit(sub, 0);
|
||
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
static void
|
||
|
surface_set_buffer_transform(struct wl_client *client,
|
||
|
struct wl_resource *resource, int transform)
|
||
|
{
|
||
12 years ago
|
struct weston_surface *surface = wl_resource_get_user_data(resource);
|
||
12 years ago
|
|
||
11 years ago
|
/* if wl_output.transform grows more members this will need to be updated. */
|
||
|
if (transform < 0 ||
|
||
|
transform > WL_OUTPUT_TRANSFORM_FLIPPED_270) {
|
||
|
wl_resource_post_error(resource,
|
||
|
WL_SURFACE_ERROR_INVALID_TRANSFORM,
|
||
|
"buffer transform must be a valid transform "
|
||
|
"('%d' specified)", transform);
|
||
|
return;
|
||
|
}
|
||
|
|
||
11 years ago
|
surface->pending.buffer_viewport.buffer.transform = transform;
|
||
11 years ago
|
surface->pending.buffer_viewport.changed = 1;
|
||
12 years ago
|
}
|
||
|
|
||
12 years ago
|
static void
|
||
|
surface_set_buffer_scale(struct wl_client *client,
|
||
|
struct wl_resource *resource,
|
||
12 years ago
|
int32_t scale)
|
||
12 years ago
|
{
|
||
12 years ago
|
struct weston_surface *surface = wl_resource_get_user_data(resource);
|
||
12 years ago
|
|
||
11 years ago
|
if (scale < 1) {
|
||
|
wl_resource_post_error(resource,
|
||
|
WL_SURFACE_ERROR_INVALID_SCALE,
|
||
|
"buffer scale must be at least one "
|
||
|
"('%d' specified)", scale);
|
||
|
return;
|
||
|
}
|
||
|
|
||
11 years ago
|
surface->pending.buffer_viewport.buffer.scale = scale;
|
||
11 years ago
|
surface->pending.buffer_viewport.changed = 1;
|
||
12 years ago
|
}
|
||
|
|
||
13 years ago
|
static const struct wl_surface_interface surface_interface = {
|
||
16 years ago
|
surface_destroy,
|
||
|
surface_attach,
|
||
13 years ago
|
surface_damage,
|
||
13 years ago
|
surface_frame,
|
||
|
surface_set_opaque_region,
|
||
12 years ago
|
surface_set_input_region,
|
||
12 years ago
|
surface_commit,
|
||
12 years ago
|
surface_set_buffer_transform,
|
||
9 years ago
|
surface_set_buffer_scale,
|
||
|
surface_damage_buffer
|
||
16 years ago
|
};
|
||
|
|
||
|
static void
|
||
|
compositor_create_surface(struct wl_client *client,
|
||
13 years ago
|
struct wl_resource *resource, uint32_t id)
|
||
16 years ago
|
{
|
||
12 years ago
|
struct weston_compositor *ec = wl_resource_get_user_data(resource);
|
||
13 years ago
|
struct weston_surface *surface;
|
||
16 years ago
|
|
||
13 years ago
|
surface = weston_surface_create(ec);
|
||
14 years ago
|
if (surface == NULL) {
|
||
13 years ago
|
wl_resource_post_no_memory(resource);
|
||
16 years ago
|
return;
|
||
14 years ago
|
}
|
||
16 years ago
|
|
||
12 years ago
|
surface->resource =
|
||
|
wl_resource_create(client, &wl_surface_interface,
|
||
|
wl_resource_get_version(resource), id);
|
||
11 years ago
|
if (surface->resource == NULL) {
|
||
|
weston_surface_destroy(surface);
|
||
|
wl_resource_post_no_memory(resource);
|
||
|
return;
|
||
|
}
|
||
12 years ago
|
wl_resource_set_implementation(surface->resource, &surface_interface,
|
||
|
surface, destroy_surface);
|
||
11 years ago
|
|
||
|
wl_signal_emit(&ec->create_surface_signal, surface);
|
||
16 years ago
|
}
|
||
|
|
||
13 years ago
|
static void
|
||
|
destroy_region(struct wl_resource *resource)
|
||
|
{
|
||
12 years ago
|
struct weston_region *region = wl_resource_get_user_data(resource);
|
||
13 years ago
|
|
||
|
pixman_region32_fini(®ion->region);
|
||
|
free(region);
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
region_destroy(struct wl_client *client, struct wl_resource *resource)
|
||
|
{
|
||
13 years ago
|
wl_resource_destroy(resource);
|
||
13 years ago
|
}
|
||
|
|
||
|
static void
|
||
|
region_add(struct wl_client *client, struct wl_resource *resource,
|
||
|
int32_t x, int32_t y, int32_t width, int32_t height)
|
||
|
{
|
||
12 years ago
|
struct weston_region *region = wl_resource_get_user_data(resource);
|
||
13 years ago
|
|
||
|
pixman_region32_union_rect(®ion->region, ®ion->region,
|
||
|
x, y, width, height);
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
region_subtract(struct wl_client *client, struct wl_resource *resource,
|
||
|
int32_t x, int32_t y, int32_t width, int32_t height)
|
||
|
{
|
||
12 years ago
|
struct weston_region *region = wl_resource_get_user_data(resource);
|
||
13 years ago
|
pixman_region32_t rect;
|
||
|
|
||
|
pixman_region32_init_rect(&rect, x, y, width, height);
|
||
|
pixman_region32_subtract(®ion->region, ®ion->region, &rect);
|
||
|
pixman_region32_fini(&rect);
|
||
|
}
|
||
|
|
||
|
static const struct wl_region_interface region_interface = {
|
||
|
region_destroy,
|
||
|
region_add,
|
||
|
region_subtract
|
||
|
};
|
||
|
|
||
|
static void
|
||
|
compositor_create_region(struct wl_client *client,
|
||
|
struct wl_resource *resource, uint32_t id)
|
||
|
{
|
||
|
struct weston_region *region;
|
||
|
|
||
|
region = malloc(sizeof *region);
|
||
|
if (region == NULL) {
|
||
|
wl_resource_post_no_memory(resource);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
pixman_region32_init(®ion->region);
|
||
|
|
||
12 years ago
|
region->resource =
|
||
|
wl_resource_create(client, &wl_region_interface, 1, id);
|
||
11 years ago
|
if (region->resource == NULL) {
|
||
|
free(region);
|
||
|
wl_resource_post_no_memory(resource);
|
||
|
return;
|
||
|
}
|
||
12 years ago
|
wl_resource_set_implementation(region->resource, ®ion_interface,
|
||
|
region, destroy_region);
|
||
13 years ago
|
}
|
||
|
|
||
13 years ago
|
static const struct wl_compositor_interface compositor_interface = {
|
||
16 years ago
|
compositor_create_surface,
|
||
13 years ago
|
compositor_create_region
|
||
16 years ago
|
};
|
||
|
|
||
12 years ago
|
static void
|
||
|
weston_subsurface_commit_from_cache(struct weston_subsurface *sub)
|
||
|
{
|
||
|
struct weston_surface *surface = sub->surface;
|
||
11 years ago
|
|
||
11 years ago
|
weston_surface_commit_state(surface, &sub->cached);
|
||
|
weston_buffer_reference(&sub->cached_buffer_ref, NULL);
|
||
12 years ago
|
|
||
|
weston_surface_commit_subsurface_order(surface);
|
||
|
|
||
|
weston_surface_schedule_repaint(surface);
|
||
|
|
||
11 years ago
|
sub->has_cached_data = 0;
|
||
12 years ago
|
}
|
||
|
|
||
|
static void
|
||
|
weston_subsurface_commit_to_cache(struct weston_subsurface *sub)
|
||
|
{
|
||
|
struct weston_surface *surface = sub->surface;
|
||
|
|
||
|
/*
|
||
|
* If this commit would cause the surface to move by the
|
||
|
* attach(dx, dy) parameters, the old damage region must be
|
||
|
* translated to correspond to the new surface coordinate system
|
||
9 years ago
|
* origin.
|
||
12 years ago
|
*/
|
||
9 years ago
|
pixman_region32_translate(&sub->cached.damage_surface,
|
||
12 years ago
|
-surface->pending.sx, -surface->pending.sy);
|
||
9 years ago
|
pixman_region32_union(&sub->cached.damage_surface,
|
||
|
&sub->cached.damage_surface,
|
||
|
&surface->pending.damage_surface);
|
||
|
pixman_region32_clear(&surface->pending.damage_surface);
|
||
12 years ago
|
|
||
|
if (surface->pending.newly_attached) {
|
||
|
sub->cached.newly_attached = 1;
|
||
11 years ago
|
weston_surface_state_set_buffer(&sub->cached,
|
||
|
surface->pending.buffer);
|
||
|
weston_buffer_reference(&sub->cached_buffer_ref,
|
||
12 years ago
|
surface->pending.buffer);
|
||
10 years ago
|
weston_presentation_feedback_discard_list(
|
||
|
&sub->cached.feedback_list);
|
||
12 years ago
|
}
|
||
|
sub->cached.sx += surface->pending.sx;
|
||
|
sub->cached.sy += surface->pending.sy;
|
||
11 years ago
|
|
||
9 years ago
|
apply_damage_buffer(&sub->cached.damage_surface, surface, &surface->pending);
|
||
|
|
||
11 years ago
|
sub->cached.buffer_viewport.changed |=
|
||
|
surface->pending.buffer_viewport.changed;
|
||
|
sub->cached.buffer_viewport.buffer =
|
||
|
surface->pending.buffer_viewport.buffer;
|
||
|
sub->cached.buffer_viewport.surface =
|
||
|
surface->pending.buffer_viewport.surface;
|
||
12 years ago
|
|
||
11 years ago
|
weston_surface_reset_pending_buffer(surface);
|
||
12 years ago
|
|
||
|
pixman_region32_copy(&sub->cached.opaque, &surface->pending.opaque);
|
||
|
|
||
|
pixman_region32_copy(&sub->cached.input, &surface->pending.input);
|
||
|
|
||
|
wl_list_insert_list(&sub->cached.frame_callback_list,
|
||
|
&surface->pending.frame_callback_list);
|
||
|
wl_list_init(&surface->pending.frame_callback_list);
|
||
|
|
||
10 years ago
|
wl_list_insert_list(&sub->cached.feedback_list,
|
||
|
&surface->pending.feedback_list);
|
||
|
wl_list_init(&surface->pending.feedback_list);
|
||
|
|
||
11 years ago
|
sub->has_cached_data = 1;
|
||
12 years ago
|
}
|
||
|
|
||
10 years ago
|
static bool
|
||
12 years ago
|
weston_subsurface_is_synchronized(struct weston_subsurface *sub)
|
||
|
{
|
||
|
while (sub) {
|
||
|
if (sub->synchronized)
|
||
10 years ago
|
return true;
|
||
12 years ago
|
|
||
|
if (!sub->parent)
|
||
10 years ago
|
return false;
|
||
12 years ago
|
|
||
|
sub = weston_surface_to_subsurface(sub->parent);
|
||
|
}
|
||
|
|
||
10 years ago
|
return false;
|
||
12 years ago
|
}
|
||
|
|
||
|
static void
|
||
|
weston_subsurface_commit(struct weston_subsurface *sub)
|
||
|
{
|
||
|
struct weston_surface *surface = sub->surface;
|
||
|
struct weston_subsurface *tmp;
|
||
|
|
||
|
/* Recursive check for effectively synchronized. */
|
||
|
if (weston_subsurface_is_synchronized(sub)) {
|
||
|
weston_subsurface_commit_to_cache(sub);
|
||
|
} else {
|
||
11 years ago
|
if (sub->has_cached_data) {
|
||
12 years ago
|
/* flush accumulated state from cache */
|
||
|
weston_subsurface_commit_to_cache(sub);
|
||
|
weston_subsurface_commit_from_cache(sub);
|
||
|
} else {
|
||
|
weston_surface_commit(surface);
|
||
|
}
|
||
|
|
||
|
wl_list_for_each(tmp, &surface->subsurface_list, parent_link) {
|
||
|
if (tmp->surface != surface)
|
||
|
weston_subsurface_parent_commit(tmp, 0);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
static void
|
||
12 years ago
|
weston_subsurface_synchronized_commit(struct weston_subsurface *sub)
|
||
12 years ago
|
{
|
||
|
struct weston_surface *surface = sub->surface;
|
||
|
struct weston_subsurface *tmp;
|
||
|
|
||
|
/* From now on, commit_from_cache the whole sub-tree, regardless of
|
||
|
* the synchronized mode of each child. This sub-surface or some
|
||
|
* of its ancestors were synchronized, so we are synchronized
|
||
|
* all the way down.
|
||
|
*/
|
||
|
|
||
11 years ago
|
if (sub->has_cached_data)
|
||
12 years ago
|
weston_subsurface_commit_from_cache(sub);
|
||
|
|
||
|
wl_list_for_each(tmp, &surface->subsurface_list, parent_link) {
|
||
|
if (tmp->surface != surface)
|
||
|
weston_subsurface_parent_commit(tmp, 1);
|
||
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
static void
|
||
|
weston_subsurface_parent_commit(struct weston_subsurface *sub,
|
||
|
int parent_is_synchronized)
|
||
|
{
|
||
11 years ago
|
struct weston_view *view;
|
||
12 years ago
|
if (sub->position.set) {
|
||
11 years ago
|
wl_list_for_each(view, &sub->surface->views, surface_link)
|
||
|
weston_view_set_position(view,
|
||
|
sub->position.x,
|
||
|
sub->position.y);
|
||
|
|
||
12 years ago
|
sub->position.set = 0;
|
||
|
}
|
||
|
|
||
|
if (parent_is_synchronized || sub->synchronized)
|
||
|
weston_subsurface_synchronized_commit(sub);
|
||
|
}
|
||
|
|
||
10 years ago
|
static int
|
||
|
subsurface_get_label(struct weston_surface *surface, char *buf, size_t len)
|
||
|
{
|
||
|
return snprintf(buf, len, "sub-surface");
|
||
|
}
|
||
|
|
||
12 years ago
|
static void
|
||
11 years ago
|
subsurface_configure(struct weston_surface *surface, int32_t dx, int32_t dy)
|
||
12 years ago
|
{
|
||
|
struct weston_compositor *compositor = surface->compositor;
|
||
11 years ago
|
struct weston_view *view;
|
||
12 years ago
|
|
||
11 years ago
|
wl_list_for_each(view, &surface->views, surface_link)
|
||
11 years ago
|
weston_view_set_position(view,
|
||
|
view->geometry.x + dx,
|
||
|
view->geometry.y + dy);
|
||
12 years ago
|
|
||
|
/* No need to check parent mappedness, because if parent is not
|
||
|
* mapped, parent is not in a visible layer, so this sub-surface
|
||
|
* will not be drawn either.
|
||
|
*/
|
||
|
if (!weston_surface_is_mapped(surface)) {
|
||
11 years ago
|
struct weston_output *output;
|
||
|
|
||
10 years ago
|
/* Cannot call weston_view_update_transform(),
|
||
12 years ago
|
* because that would call it also for the parent surface,
|
||
|
* which might not be mapped yet. That would lead to
|
||
|
* inconsistent state, where the window could never be
|
||
|
* mapped.
|
||
|
*
|
||
10 years ago
|
* Instead just assign any output, to make
|
||
12 years ago
|
* weston_surface_is_mapped() return true, so that when the
|
||
|
* parent surface does get mapped, this one will get
|
||
11 years ago
|
* included, too. See view_list_add().
|
||
12 years ago
|
*/
|
||
|
assert(!wl_list_empty(&compositor->output_list));
|
||
11 years ago
|
output = container_of(compositor->output_list.next,
|
||
|
struct weston_output, link);
|
||
|
|
||
|
surface->output = output;
|
||
9 years ago
|
weston_surface_update_output_mask(surface, 1u << output->id);
|
||
12 years ago
|
}
|
||
|
}
|
||
|
|
||
|
static struct weston_subsurface *
|
||
|
weston_surface_to_subsurface(struct weston_surface *surface)
|
||
|
{
|
||
|
if (surface->configure == subsurface_configure)
|
||
|
return surface->configure_private;
|
||
|
|
||
|
return NULL;
|
||
|
}
|
||
|
|
||
12 years ago
|
WL_EXPORT struct weston_surface *
|
||
|
weston_surface_get_main_surface(struct weston_surface *surface)
|
||
|
{
|
||
|
struct weston_subsurface *sub;
|
||
|
|
||
|
while (surface && (sub = weston_surface_to_subsurface(surface)))
|
||
|
surface = sub->parent;
|
||
|
|
||
|
return surface;
|
||
|
}
|
||
|
|
||
10 years ago
|
WL_EXPORT int
|
||
|
weston_surface_set_role(struct weston_surface *surface,
|
||
|
const char *role_name,
|
||
|
struct wl_resource *error_resource,
|
||
|
uint32_t error_code)
|
||
|
{
|
||
|
assert(role_name);
|
||
|
|
||
|
if (surface->role_name == NULL ||
|
||
|
surface->role_name == role_name ||
|
||
|
strcmp(surface->role_name, role_name) == 0) {
|
||
|
surface->role_name = role_name;
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
wl_resource_post_error(error_resource, error_code,
|
||
|
"Cannot assign role %s to wl_surface@%d,"
|
||
|
" already has role %s\n",
|
||
|
role_name,
|
||
|
wl_resource_get_id(surface->resource),
|
||
|
surface->role_name);
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
10 years ago
|
WL_EXPORT void
|
||
|
weston_surface_set_label_func(struct weston_surface *surface,
|
||
|
int (*desc)(struct weston_surface *,
|
||
|
char *, size_t))
|
||
|
{
|
||
|
surface->get_label = desc;
|
||
10 years ago
|
surface->timeline.force_refresh = 1;
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
/** Get the size of surface contents
|
||
|
*
|
||
|
* \param surface The surface to query.
|
||
|
* \param width Returns the width of raw contents.
|
||
|
* \param height Returns the height of raw contents.
|
||
|
*
|
||
|
* Retrieves the raw surface content size in pixels for the given surface.
|
||
|
* This is the whole content size in buffer pixels. If the surface
|
||
|
* has no content or the renderer does not implement this feature,
|
||
|
* zeroes are returned.
|
||
|
*
|
||
|
* This function is used to determine the buffer size needed for
|
||
|
* a weston_surface_copy_content() call.
|
||
|
*/
|
||
|
WL_EXPORT void
|
||
|
weston_surface_get_content_size(struct weston_surface *surface,
|
||
|
int *width, int *height)
|
||
|
{
|
||
|
struct weston_renderer *rer = surface->compositor->renderer;
|
||
|
|
||
|
if (!rer->surface_get_content_size) {
|
||
|
*width = 0;
|
||
|
*height = 0;
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
rer->surface_get_content_size(surface, width, height);
|
||
|
}
|
||
|
|
||
|
/** Copy surface contents to system memory.
|
||
|
*
|
||
|
* \param surface The surface to copy from.
|
||
|
* \param target Pointer to the target memory buffer.
|
||
|
* \param size Size of the target buffer in bytes.
|
||
|
* \param src_x X location on contents to copy from.
|
||
|
* \param src_y Y location on contents to copy from.
|
||
|
* \param width Width in pixels of the area to copy.
|
||
|
* \param height Height in pixels of the area to copy.
|
||
|
* \return 0 for success, -1 for failure.
|
||
|
*
|
||
|
* Surface contents are maintained by the renderer. They can be in a
|
||
|
* reserved weston_buffer or as a copy, e.g. a GL texture, or something
|
||
|
* else.
|
||
|
*
|
||
|
* Surface contents are copied into memory pointed to by target,
|
||
|
* which has size bytes of space available. The target memory
|
||
|
* may be larger than needed, but being smaller returns an error.
|
||
|
* The extra bytes in target may or may not be written; their content is
|
||
|
* unspecified. Size must be large enough to hold the image.
|
||
|
*
|
||
|
* The image in the target memory will be arranged in rows from
|
||
|
* top to bottom, and pixels on a row from left to right. The pixel
|
||
|
* format is PIXMAN_a8b8g8r8, 4 bytes per pixel, and stride is exactly
|
||
|
* width * 4.
|
||
|
*
|
||
|
* Parameters src_x and src_y define the upper-left corner in buffer
|
||
|
* coordinates (pixels) to copy from. Parameters width and height
|
||
|
* define the size of the area to copy in pixels.
|
||
|
*
|
||
|
* The rectangle defined by src_x, src_y, width, height must fit in
|
||
|
* the surface contents. Otherwise an error is returned.
|
||
|
*
|
||
|
* Use surface_get_data_size to determine the content size; the
|
||
|
* needed target buffer size and rectangle limits.
|
||
|
*
|
||
|
* CURRENT IMPLEMENTATION RESTRICTIONS:
|
||
|
* - the machine must be little-endian due to Pixman formats.
|
||
|
*
|
||
|
* NOTE: Pixman formats are premultiplied.
|
||
|
*/
|
||
|
WL_EXPORT int
|
||
|
weston_surface_copy_content(struct weston_surface *surface,
|
||
|
void *target, size_t size,
|
||
|
int src_x, int src_y,
|
||
|
int width, int height)
|
||
|
{
|
||
|
struct weston_renderer *rer = surface->compositor->renderer;
|
||
|
int cw, ch;
|
||
|
const size_t bytespp = 4; /* PIXMAN_a8b8g8r8 */
|
||
|
|
||
|
if (!rer->surface_copy_content)
|
||
|
return -1;
|
||
|
|
||
|
weston_surface_get_content_size(surface, &cw, &ch);
|
||
|
|
||
|
if (src_x < 0 || src_y < 0)
|
||
|
return -1;
|
||
|
|
||
|
if (width <= 0 || height <= 0)
|
||
|
return -1;
|
||
|
|
||
|
if (src_x + width > cw || src_y + height > ch)
|
||
|
return -1;
|
||
|
|
||
|
if (width * bytespp * height > size)
|
||
|
return -1;
|
||
|
|
||
|
return rer->surface_copy_content(surface, target, size,
|
||
|
src_x, src_y, width, height);
|
||
|
}
|
||
|
|
||
12 years ago
|
static void
|
||
|
subsurface_set_position(struct wl_client *client,
|
||
|
struct wl_resource *resource, int32_t x, int32_t y)
|
||
|
{
|
||
12 years ago
|
struct weston_subsurface *sub = wl_resource_get_user_data(resource);
|
||
12 years ago
|
|
||
|
if (!sub)
|
||
|
return;
|
||
|
|
||
|
sub->position.x = x;
|
||
|
sub->position.y = y;
|
||
|
sub->position.set = 1;
|
||
|
}
|
||
|
|
||
|
static struct weston_subsurface *
|
||
|
subsurface_from_surface(struct weston_surface *surface)
|
||
|
{
|
||
|
struct weston_subsurface *sub;
|
||
|
|
||
|
sub = weston_surface_to_subsurface(surface);
|
||
|
if (sub)
|
||
|
return sub;
|
||
|
|
||
|
wl_list_for_each(sub, &surface->subsurface_list, parent_link)
|
||
|
if (sub->surface == surface)
|
||
|
return sub;
|
||
|
|
||
|
return NULL;
|
||
|
}
|
||
|
|
||
|
static struct weston_subsurface *
|
||
|
subsurface_sibling_check(struct weston_subsurface *sub,
|
||
|
struct weston_surface *surface,
|
||
|
const char *request)
|
||
|
{
|
||
|
struct weston_subsurface *sibling;
|
||
|
|
||
|
sibling = subsurface_from_surface(surface);
|
||
|
|
||
|
if (!sibling) {
|
||
|
wl_resource_post_error(sub->resource,
|
||
|
WL_SUBSURFACE_ERROR_BAD_SURFACE,
|
||
|
"%s: wl_surface@%d is not a parent or sibling",
|
||
12 years ago
|
request, wl_resource_get_id(surface->resource));
|
||
12 years ago
|
return NULL;
|
||
|
}
|
||
|
|
||
|
if (sibling->parent != sub->parent) {
|
||
|
wl_resource_post_error(sub->resource,
|
||
|
WL_SUBSURFACE_ERROR_BAD_SURFACE,
|
||
|
"%s: wl_surface@%d has a different parent",
|
||
12 years ago
|
request, wl_resource_get_id(surface->resource));
|
||
12 years ago
|
return NULL;
|
||
|
}
|
||
|
|
||
|
return sibling;
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
subsurface_place_above(struct wl_client *client,
|
||
|
struct wl_resource *resource,
|
||
|
struct wl_resource *sibling_resource)
|
||
|
{
|
||
12 years ago
|
struct weston_subsurface *sub = wl_resource_get_user_data(resource);
|
||
12 years ago
|
struct weston_surface *surface =
|
||
|
wl_resource_get_user_data(sibling_resource);
|
||
12 years ago
|
struct weston_subsurface *sibling;
|
||
|
|
||
|
if (!sub)
|
||
|
return;
|
||
|
|
||
|
sibling = subsurface_sibling_check(sub, surface, "place_above");
|
||
|
if (!sibling)
|
||
|
return;
|
||
|
|
||
|
wl_list_remove(&sub->parent_link_pending);
|
||
|
wl_list_insert(sibling->parent_link_pending.prev,
|
||
|
&sub->parent_link_pending);
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
subsurface_place_below(struct wl_client *client,
|
||
|
struct wl_resource *resource,
|
||
|
struct wl_resource *sibling_resource)
|
||
|
{
|
||
12 years ago
|
struct weston_subsurface *sub = wl_resource_get_user_data(resource);
|
||
12 years ago
|
struct weston_surface *surface =
|
||
|
wl_resource_get_user_data(sibling_resource);
|
||
12 years ago
|
struct weston_subsurface *sibling;
|
||
|
|
||
|
if (!sub)
|
||
|
return;
|
||
|
|
||
|
sibling = subsurface_sibling_check(sub, surface, "place_below");
|
||
|
if (!sibling)
|
||
|
return;
|
||
|
|
||
|
wl_list_remove(&sub->parent_link_pending);
|
||
|
wl_list_insert(&sibling->parent_link_pending,
|
||
|
&sub->parent_link_pending);
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
subsurface_set_sync(struct wl_client *client, struct wl_resource *resource)
|
||
|
{
|
||
12 years ago
|
struct weston_subsurface *sub = wl_resource_get_user_data(resource);
|
||
12 years ago
|
|
||
|
if (sub)
|
||
|
sub->synchronized = 1;
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
subsurface_set_desync(struct wl_client *client, struct wl_resource *resource)
|
||
|
{
|
||
12 years ago
|
struct weston_subsurface *sub = wl_resource_get_user_data(resource);
|
||
12 years ago
|
|
||
12 years ago
|
if (sub && sub->synchronized) {
|
||
12 years ago
|
sub->synchronized = 0;
|
||
12 years ago
|
|
||
|
/* If sub became effectively desynchronized, flush. */
|
||
|
if (!weston_subsurface_is_synchronized(sub))
|
||
|
weston_subsurface_synchronized_commit(sub);
|
||
|
}
|
||
12 years ago
|
}
|
||
|
|
||
|
static void
|
||
|
weston_subsurface_unlink_parent(struct weston_subsurface *sub)
|
||
|
{
|
||
|
wl_list_remove(&sub->parent_link);
|
||
|
wl_list_remove(&sub->parent_link_pending);
|
||
|
wl_list_remove(&sub->parent_destroy_listener.link);
|
||
|
sub->parent = NULL;
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
weston_subsurface_destroy(struct weston_subsurface *sub);
|
||
|
|
||
|
static void
|
||
|
subsurface_handle_surface_destroy(struct wl_listener *listener, void *data)
|
||
|
{
|
||
|
struct weston_subsurface *sub =
|
||
|
container_of(listener, struct weston_subsurface,
|
||
|
surface_destroy_listener);
|
||
10 years ago
|
assert(data == sub->surface);
|
||
12 years ago
|
|
||
|
/* The protocol object (wl_resource) is left inert. */
|
||
|
if (sub->resource)
|
||
12 years ago
|
wl_resource_set_user_data(sub->resource, NULL);
|
||
12 years ago
|
|
||
|
weston_subsurface_destroy(sub);
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
subsurface_handle_parent_destroy(struct wl_listener *listener, void *data)
|
||
|
{
|
||
|
struct weston_subsurface *sub =
|
||
|
container_of(listener, struct weston_subsurface,
|
||
|
parent_destroy_listener);
|
||
10 years ago
|
assert(data == sub->parent);
|
||
12 years ago
|
assert(sub->surface != sub->parent);
|
||
|
|
||
|
if (weston_surface_is_mapped(sub->surface))
|
||
|
weston_surface_unmap(sub->surface);
|
||
|
|
||
|
weston_subsurface_unlink_parent(sub);
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
subsurface_resource_destroy(struct wl_resource *resource)
|
||
|
{
|
||
12 years ago
|
struct weston_subsurface *sub = wl_resource_get_user_data(resource);
|
||
12 years ago
|
|
||
|
if (sub)
|
||
|
weston_subsurface_destroy(sub);
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
subsurface_destroy(struct wl_client *client, struct wl_resource *resource)
|
||
|
{
|
||
|
wl_resource_destroy(resource);
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
weston_subsurface_link_parent(struct weston_subsurface *sub,
|
||
|
struct weston_surface *parent)
|
||
|
{
|
||
|
sub->parent = parent;
|
||
|
sub->parent_destroy_listener.notify = subsurface_handle_parent_destroy;
|
||
12 years ago
|
wl_signal_add(&parent->destroy_signal,
|
||
12 years ago
|
&sub->parent_destroy_listener);
|
||
|
|
||
|
wl_list_insert(&parent->subsurface_list, &sub->parent_link);
|
||
|
wl_list_insert(&parent->subsurface_list_pending,
|
||
|
&sub->parent_link_pending);
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
weston_subsurface_link_surface(struct weston_subsurface *sub,
|
||
|
struct weston_surface *surface)
|
||
|
{
|
||
|
sub->surface = surface;
|
||
|
sub->surface_destroy_listener.notify =
|
||
|
subsurface_handle_surface_destroy;
|
||
12 years ago
|
wl_signal_add(&surface->destroy_signal,
|
||
12 years ago
|
&sub->surface_destroy_listener);
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
weston_subsurface_destroy(struct weston_subsurface *sub)
|
||
|
{
|
||
11 years ago
|
struct weston_view *view, *next;
|
||
|
|
||
12 years ago
|
assert(sub->surface);
|
||
|
|
||
|
if (sub->resource) {
|
||
|
assert(weston_surface_to_subsurface(sub->surface) == sub);
|
||
|
assert(sub->parent_destroy_listener.notify ==
|
||
|
subsurface_handle_parent_destroy);
|
||
|
|
||
11 years ago
|
wl_list_for_each_safe(view, next, &sub->surface->views, surface_link) {
|
||
|
weston_view_unmap(view);
|
||
11 years ago
|
weston_view_destroy(view);
|
||
11 years ago
|
}
|
||
11 years ago
|
|
||
12 years ago
|
if (sub->parent)
|
||
|
weston_subsurface_unlink_parent(sub);
|
||
|
|
||
11 years ago
|
weston_surface_state_fini(&sub->cached);
|
||
|
weston_buffer_reference(&sub->cached_buffer_ref, NULL);
|
||
12 years ago
|
|
||
|
sub->surface->configure = NULL;
|
||
|
sub->surface->configure_private = NULL;
|
||
10 years ago
|
weston_surface_set_label_func(sub->surface, NULL);
|
||
12 years ago
|
} else {
|
||
|
/* the dummy weston_subsurface for the parent itself */
|
||
|
assert(sub->parent_destroy_listener.notify == NULL);
|
||
|
wl_list_remove(&sub->parent_link);
|
||
|
wl_list_remove(&sub->parent_link_pending);
|
||
|
}
|
||
|
|
||
|
wl_list_remove(&sub->surface_destroy_listener.link);
|
||
|
free(sub);
|
||
|
}
|
||
|
|
||
|
static const struct wl_subsurface_interface subsurface_implementation = {
|
||
|
subsurface_destroy,
|
||
|
subsurface_set_position,
|
||
|
subsurface_place_above,
|
||
|
subsurface_place_below,
|
||
|
subsurface_set_sync,
|
||
|
subsurface_set_desync
|
||
|
};
|
||
|
|
||
|
static struct weston_subsurface *
|
||
|
weston_subsurface_create(uint32_t id, struct weston_surface *surface,
|
||
|
struct weston_surface *parent)
|
||
|
{
|
||
|
struct weston_subsurface *sub;
|
||
12 years ago
|
struct wl_client *client = wl_resource_get_client(surface->resource);
|
||
12 years ago
|
|
||
10 years ago
|
sub = zalloc(sizeof *sub);
|
||
|
if (sub == NULL)
|
||
12 years ago
|
return NULL;
|
||
|
|
||
11 years ago
|
wl_list_init(&sub->unused_views);
|
||
|
|
||
12 years ago
|
sub->resource =
|
||
|
wl_resource_create(client, &wl_subsurface_interface, 1, id);
|
||
12 years ago
|
if (!sub->resource) {
|
||
|
free(sub);
|
||
|
return NULL;
|
||
|
}
|
||
|
|
||
12 years ago
|
wl_resource_set_implementation(sub->resource,
|
||
|
&subsurface_implementation,
|
||
|
sub, subsurface_resource_destroy);
|
||
12 years ago
|
weston_subsurface_link_surface(sub, surface);
|
||
|
weston_subsurface_link_parent(sub, parent);
|
||
11 years ago
|
weston_surface_state_init(&sub->cached);
|
||
|
sub->cached_buffer_ref.buffer = NULL;
|
||
12 years ago
|
sub->synchronized = 1;
|
||
|
|
||
|
return sub;
|
||
|
}
|
||
|
|
||
|
/* Create a dummy subsurface for having the parent itself in its
|
||
|
* sub-surface lists. Makes stacking order manipulation easy.
|
||
|
*/
|
||
|
static struct weston_subsurface *
|
||
|
weston_subsurface_create_for_parent(struct weston_surface *parent)
|
||
|
{
|
||
|
struct weston_subsurface *sub;
|
||
|
|
||
10 years ago
|
sub = zalloc(sizeof *sub);
|
||
|
if (sub == NULL)
|
||
12 years ago
|
return NULL;
|
||
|
|
||
|
weston_subsurface_link_surface(sub, parent);
|
||
|
sub->parent = parent;
|
||
|
wl_list_insert(&parent->subsurface_list, &sub->parent_link);
|
||
|
wl_list_insert(&parent->subsurface_list_pending,
|
||
|
&sub->parent_link_pending);
|
||
|
|
||
|
return sub;
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
subcompositor_get_subsurface(struct wl_client *client,
|
||
|
struct wl_resource *resource,
|
||
|
uint32_t id,
|
||
|
struct wl_resource *surface_resource,
|
||
|
struct wl_resource *parent_resource)
|
||
|
{
|
||
12 years ago
|
struct weston_surface *surface =
|
||
|
wl_resource_get_user_data(surface_resource);
|
||
|
struct weston_surface *parent =
|
||
|
wl_resource_get_user_data(parent_resource);
|
||
12 years ago
|
struct weston_subsurface *sub;
|
||
|
static const char where[] = "get_subsurface: wl_subsurface@";
|
||
|
|
||
|
if (surface == parent) {
|
||
|
wl_resource_post_error(resource,
|
||
|
WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE,
|
||
|
"%s%d: wl_surface@%d cannot be its own parent",
|
||
12 years ago
|
where, id, wl_resource_get_id(surface_resource));
|
||
12 years ago
|
return;
|
||
|
}
|
||
|
|
||
|
if (weston_surface_to_subsurface(surface)) {
|
||
|
wl_resource_post_error(resource,
|
||
|
WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE,
|
||
|
"%s%d: wl_surface@%d is already a sub-surface",
|
||
12 years ago
|
where, id, wl_resource_get_id(surface_resource));
|
||
12 years ago
|
return;
|
||
|
}
|
||
|
|
||
10 years ago
|
if (weston_surface_set_role(surface, "wl_subsurface", resource,
|
||
|
WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE) < 0)
|
||
12 years ago
|
return;
|
||
|
|
||
12 years ago
|
if (weston_surface_get_main_surface(parent) == surface) {
|
||
|
wl_resource_post_error(resource,
|
||
|
WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE,
|
||
|
"%s%d: wl_surface@%d is an ancestor of parent",
|
||
12 years ago
|
where, id, wl_resource_get_id(surface_resource));
|
||
12 years ago
|
return;
|
||
|
}
|
||
|
|
||
12 years ago
|
/* make sure the parent is in its own list */
|
||
|
if (wl_list_empty(&parent->subsurface_list)) {
|
||
|
if (!weston_subsurface_create_for_parent(parent)) {
|
||
|
wl_resource_post_no_memory(resource);
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
sub = weston_subsurface_create(id, surface, parent);
|
||
|
if (!sub) {
|
||
|
wl_resource_post_no_memory(resource);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
surface->configure = subsurface_configure;
|
||
|
surface->configure_private = sub;
|
||
10 years ago
|
weston_surface_set_label_func(surface, subsurface_get_label);
|
||
12 years ago
|
}
|
||
|
|
||
|
static void
|
||
|
subcompositor_destroy(struct wl_client *client, struct wl_resource *resource)
|
||
|
{
|
||
|
wl_resource_destroy(resource);
|
||
|
}
|
||
|
|
||
|
static const struct wl_subcompositor_interface subcompositor_interface = {
|
||
|
subcompositor_destroy,
|
||
|
subcompositor_get_subsurface
|
||
|
};
|
||
|
|
||
|
static void
|
||
|
bind_subcompositor(struct wl_client *client,
|
||
|
void *data, uint32_t version, uint32_t id)
|
||
|
{
|
||
|
struct weston_compositor *compositor = data;
|
||
12 years ago
|
struct wl_resource *resource;
|
||
12 years ago
|
|
||
12 years ago
|
resource =
|
||
|
wl_resource_create(client, &wl_subcompositor_interface, 1, id);
|
||
11 years ago
|
if (resource == NULL) {
|
||
|
wl_client_post_no_memory(client);
|
||
|
return;
|
||
|
}
|
||
|
wl_resource_set_implementation(resource, &subcompositor_interface,
|
||
|
compositor, NULL);
|
||
12 years ago
|
}
|
||
|
|
||
9 years ago
|
/** Set a DPMS mode on all of the compositor's outputs
|
||
|
*
|
||
|
* \param compositor The compositor instance
|
||
|
* \param state The DPMS state the outputs will be set to
|
||
|
*/
|
||
13 years ago
|
static void
|
||
12 years ago
|
weston_compositor_dpms(struct weston_compositor *compositor,
|
||
|
enum dpms_enum state)
|
||
13 years ago
|
{
|
||
|
struct weston_output *output;
|
||
|
|
||
|
wl_list_for_each(output, &compositor->output_list, link)
|
||
|
if (output->set_dpms)
|
||
12 years ago
|
output->set_dpms(output, state);
|
||
13 years ago
|
}
|
||
|
|
||
9 years ago
|
/** Restores the compositor to active status
|
||
|
*
|
||
|
* \param compositor The compositor instance
|
||
|
*
|
||
|
* If the compositor was in a sleeping mode, all outputs are powered
|
||
|
* back on via DPMS. Otherwise if the compositor was inactive
|
||
|
* (idle/locked, offscreen, or sleeping) then the compositor's wake
|
||
|
* signal will fire.
|
||
|
*
|
||
|
* Restarts the idle timer.
|
||
|
*/
|
||
13 years ago
|
WL_EXPORT void
|
||
12 years ago
|
weston_compositor_wake(struct weston_compositor *compositor)
|
||
13 years ago
|
{
|
||
11 years ago
|
uint32_t old_state = compositor->state;
|
||
|
|
||
|
/* The state needs to be changed before emitting the wake
|
||
|
* signal because that may try to schedule a repaint which
|
||
|
* will not work if the compositor is still sleeping */
|
||
|
compositor->state = WESTON_COMPOSITOR_ACTIVE;
|
||
|
|
||
|
switch (old_state) {
|
||
12 years ago
|
case WESTON_COMPOSITOR_SLEEPING:
|
||
|
weston_compositor_dpms(compositor, WESTON_DPMS_ON);
|
||
|
/* fall through */
|
||
|
case WESTON_COMPOSITOR_IDLE:
|
||
12 years ago
|
case WESTON_COMPOSITOR_OFFSCREEN:
|
||
12 years ago
|
wl_signal_emit(&compositor->wake_signal, compositor);
|
||
12 years ago
|
/* fall through */
|
||
|
default:
|
||
|
wl_event_source_timer_update(compositor->idle_source,
|
||
|
compositor->idle_time * 1000);
|
||
13 years ago
|
}
|
||
|
}
|
||
|
|
||
9 years ago
|
/** Turns off rendering and frame events for the compositor.
|
||
|
*
|
||
|
* \param compositor The compositor instance
|
||
|
*
|
||
|
* This is used for example to prevent further rendering while the
|
||
|
* compositor is shutting down.
|
||
|
*
|
||
|
* \note When offscreen state is entered, outputs will be powered
|
||
|
* back on if they were sleeping (in DPMS off mode), even though
|
||
|
* no rendering will be performed.
|
||
|
*
|
||
|
* Stops the idle timer.
|
||
|
*/
|
||
12 years ago
|
WL_EXPORT void
|
||
|
weston_compositor_offscreen(struct weston_compositor *compositor)
|
||
|
{
|
||
|
switch (compositor->state) {
|
||
|
case WESTON_COMPOSITOR_OFFSCREEN:
|
||
|
return;
|
||
|
case WESTON_COMPOSITOR_SLEEPING:
|
||
|
weston_compositor_dpms(compositor, WESTON_DPMS_ON);
|
||
|
/* fall through */
|
||
|
default:
|
||
|
compositor->state = WESTON_COMPOSITOR_OFFSCREEN;
|
||
|
wl_event_source_timer_update(compositor->idle_source, 0);
|
||
|
}
|
||
|
}
|
||
|
|
||
9 years ago
|
/** Powers down all attached output devices
|
||
|
*
|
||
|
* \param compositor The compositor instance
|
||
|
*
|
||
|
* Causes rendering to the outputs to cease, and no frame events to be
|
||
|
* sent. Only powers down the outputs if the compositor is not already
|
||
|
* in sleep mode.
|
||
|
*
|
||
|
* Stops the idle timer.
|
||
|
*/
|
||
12 years ago
|
WL_EXPORT void
|
||
|
weston_compositor_sleep(struct weston_compositor *compositor)
|
||
|
{
|
||
|
if (compositor->state == WESTON_COMPOSITOR_SLEEPING)
|
||
|
return;
|
||
|
|
||
12 years ago
|
wl_event_source_timer_update(compositor->idle_source, 0);
|
||
12 years ago
|
compositor->state = WESTON_COMPOSITOR_SLEEPING;
|
||
|
weston_compositor_dpms(compositor, WESTON_DPMS_OFF);
|
||
|
}
|
||
|
|
||
9 years ago
|
/** Sets compositor to idle mode
|
||
|
*
|
||
|
* \param data The compositor instance
|
||
|
*
|
||
|
* This is called when the idle timer fires. Once the compositor is in
|
||
|
* idle mode it requires a wake action (e.g. via
|
||
|
* weston_compositor_wake()) to restore it. The compositor's
|
||
|
* idle_signal will be triggered when the idle event occurs.
|
||
|
*
|
||
|
* Idleness can be inhibited by setting the compositor's idle_inhibit
|
||
|
* property.
|
||
|
*/
|
||
14 years ago
|
static int
|
||
|
idle_handler(void *data)
|
||
|
{
|
||
13 years ago
|
struct weston_compositor *compositor = data;
|
||
14 years ago
|
|
||
|
if (compositor->idle_inhibit)
|
||
|
return 1;
|
||
|
|
||
12 years ago
|
compositor->state = WESTON_COMPOSITOR_IDLE;
|
||
12 years ago
|
wl_signal_emit(&compositor->idle_signal, compositor);
|
||
14 years ago
|
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
12 years ago
|
WL_EXPORT void
|
||
11 years ago
|
weston_plane_init(struct weston_plane *plane,
|
||
|
struct weston_compositor *ec,
|
||
|
int32_t x, int32_t y)
|
||
12 years ago
|
{
|
||
|
pixman_region32_init(&plane->damage);
|
||
12 years ago
|
pixman_region32_init(&plane->clip);
|
||
12 years ago
|
plane->x = x;
|
||
|
plane->y = y;
|
||
11 years ago
|
plane->compositor = ec;
|
||
12 years ago
|
|
||
|
/* Init the link so that the call to wl_list_remove() when releasing
|
||
|
* the plane without ever stacking doesn't lead to a crash */
|
||
|
wl_list_init(&plane->link);
|
||
12 years ago
|
}
|
||
|
|
||
|
WL_EXPORT void
|
||
|
weston_plane_release(struct weston_plane *plane)
|
||
|
{
|
||
11 years ago
|
struct weston_view *view;
|
||
|
|
||
12 years ago
|
pixman_region32_fini(&plane->damage);
|
||
12 years ago
|
pixman_region32_fini(&plane->clip);
|
||
12 years ago
|
|
||
11 years ago
|
wl_list_for_each(view, &plane->compositor->view_list, link) {
|
||
|
if (view->plane == plane)
|
||
|
view->plane = NULL;
|
||
|
}
|
||
|
|
||
12 years ago
|
wl_list_remove(&plane->link);
|
||
12 years ago
|
}
|
||
|
|
||
12 years ago
|
WL_EXPORT void
|
||
|
weston_compositor_stack_plane(struct weston_compositor *ec,
|
||
|
struct weston_plane *plane,
|
||
|
struct weston_plane *above)
|
||
|
{
|
||
|
if (above)
|
||
|
wl_list_insert(above->link.prev, &plane->link);
|
||
|
else
|
||
|
wl_list_insert(&ec->plane_list, &plane->link);
|
||
|
}
|
||
|
|
||
13 years ago
|
static void unbind_resource(struct wl_resource *resource)
|
||
13 years ago
|
{
|
||
12 years ago
|
wl_list_remove(wl_resource_get_link(resource));
|
||
13 years ago
|
}
|
||
|
|
||
16 years ago
|
static void
|
||
13 years ago
|
bind_output(struct wl_client *client,
|
||
|
void *data, uint32_t version, uint32_t id)
|
||
16 years ago
|
{
|
||
13 years ago
|
struct weston_output *output = data;
|
||
|
struct weston_mode *mode;
|
||
13 years ago
|
struct wl_resource *resource;
|
||
|
|
||
12 years ago
|
resource = wl_resource_create(client, &wl_output_interface,
|
||
9 years ago
|
version, id);
|
||
11 years ago
|
if (resource == NULL) {
|
||
|
wl_client_post_no_memory(client);
|
||
|
return;
|
||
|
}
|
||
16 years ago
|
|
||
12 years ago
|
wl_list_insert(&output->resource_list, wl_resource_get_link(resource));
|
||
12 years ago
|
wl_resource_set_implementation(resource, NULL, data, unbind_resource);
|
||
13 years ago
|
|
||
13 years ago
|
wl_output_send_geometry(resource,
|
||
|
output->x,
|
||
|
output->y,
|
||
|
output->mm_width,
|
||
|
output->mm_height,
|
||
|
output->subpixel,
|
||
12 years ago
|
output->make, output->model,
|
||
12 years ago
|
output->transform);
|
||
10 years ago
|
if (version >= WL_OUTPUT_SCALE_SINCE_VERSION)
|
||
12 years ago
|
wl_output_send_scale(resource,
|
||
11 years ago
|
output->current_scale);
|
||
14 years ago
|
|
||
|
wl_list_for_each (mode, &output->mode_list, link) {
|
||
13 years ago
|
wl_output_send_mode(resource,
|
||
|
mode->flags,
|
||
|
mode->width,
|
||
|
mode->height,
|
||
|
mode->refresh);
|
||
14 years ago
|
}
|
||
12 years ago
|
|
||
10 years ago
|
if (version >= WL_OUTPUT_DONE_SINCE_VERSION)
|
||
12 years ago
|
wl_output_send_done(resource);
|
||
16 years ago
|
}
|
||
|
|
||
9 years ago
|
/* Move other outputs when one is resized so the space remains contiguous. */
|
||
11 years ago
|
static void
|
||
9 years ago
|
weston_compositor_reflow_outputs(struct weston_compositor *compositor,
|
||
|
struct weston_output *resized_output, int delta_width)
|
||
11 years ago
|
{
|
||
|
struct weston_output *output;
|
||
9 years ago
|
bool start_resizing = false;
|
||
|
|
||
|
if (!delta_width)
|
||
|
return;
|
||
11 years ago
|
|
||
|
wl_list_for_each(output, &compositor->output_list, link) {
|
||
9 years ago
|
if (output == resized_output) {
|
||
|
start_resizing = true;
|
||
11 years ago
|
continue;
|
||
|
}
|
||
|
|
||
9 years ago
|
if (start_resizing) {
|
||
|
weston_output_move(output, output->x + delta_width, output->y);
|
||
11 years ago
|
output->dirty = 1;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
WL_EXPORT void
|
||
13 years ago
|
weston_output_destroy(struct weston_output *output)
|
||
16 years ago
|
{
|
||
10 years ago
|
struct wl_resource *resource;
|
||
9 years ago
|
struct weston_view *view;
|
||
10 years ago
|
|
||
11 years ago
|
output->destroying = 1;
|
||
|
|
||
9 years ago
|
wl_list_for_each(view, &output->compositor->view_list, link) {
|
||
9 years ago
|
if (view->output_mask & (1u << output->id))
|
||
9 years ago
|
weston_view_assign_output(view);
|
||
|
}
|
||
|
|
||
11 years ago
|
wl_event_source_remove(output->repaint_timer);
|
||
|
|
||
10 years ago
|
weston_presentation_feedback_discard_list(&output->feedback_list);
|
||
|
|
||
9 years ago
|
weston_compositor_reflow_outputs(output->compositor, output, output->width);
|
||
11 years ago
|
wl_list_remove(&output->link);
|
||
|
|
||
11 years ago
|
wl_signal_emit(&output->compositor->output_destroyed_signal, output);
|
||
12 years ago
|
wl_signal_emit(&output->destroy_signal, output);
|
||
|
|
||
12 years ago
|
free(output->name);
|
||
14 years ago
|
pixman_region32_fini(&output->region);
|
||
12 years ago
|
pixman_region32_fini(&output->previous_damage);
|
||
9 years ago
|
output->compositor->output_id_pool &= ~(1u << output->id);
|
||
13 years ago
|
|
||
10 years ago
|
wl_resource_for_each(resource, &output->resource_list) {
|
||
|
wl_resource_set_destructor(resource, NULL);
|
||
|
}
|
||
|
|
||
12 years ago
|
wl_global_destroy(output->global);
|
||
14 years ago
|
}
|
||
|
|
||
13 years ago
|
WL_EXPORT void
|
||
|
weston_output_update_matrix(struct weston_output *output)
|
||
|
{
|
||
13 years ago
|
float magnification;
|
||
15 years ago
|
|
||
13 years ago
|
weston_matrix_init(&output->matrix);
|
||
10 years ago
|
weston_matrix_translate(&output->matrix, -output->x, -output->y, 0);
|
||
12 years ago
|
|
||
13 years ago
|
if (output->zoom.active) {
|
||
13 years ago
|
magnification = 1 / (1 - output->zoom.spring_z.current);
|
||
11 years ago
|
weston_output_update_zoom(output);
|
||
11 years ago
|
weston_matrix_translate(&output->matrix, -output->zoom.trans_x,
|
||
10 years ago
|
-output->zoom.trans_y, 0);
|
||
11 years ago
|
weston_matrix_scale(&output->matrix, magnification,
|
||
|
magnification, 1.0);
|
||
13 years ago
|
}
|
||
15 years ago
|
|
||
10 years ago
|
switch (output->transform) {
|
||
|
case WL_OUTPUT_TRANSFORM_FLIPPED:
|
||
|
case WL_OUTPUT_TRANSFORM_FLIPPED_90:
|
||
|
case WL_OUTPUT_TRANSFORM_FLIPPED_180:
|
||
|
case WL_OUTPUT_TRANSFORM_FLIPPED_270:
|
||
|
weston_matrix_translate(&output->matrix, -output->width, 0, 0);
|
||
|
weston_matrix_scale(&output->matrix, -1, 1, 1);
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
switch (output->transform) {
|
||
|
default:
|
||
|
case WL_OUTPUT_TRANSFORM_NORMAL:
|
||
|
case WL_OUTPUT_TRANSFORM_FLIPPED:
|
||
|
break;
|
||
|
case WL_OUTPUT_TRANSFORM_90:
|
||
|
case WL_OUTPUT_TRANSFORM_FLIPPED_90:
|
||
|
weston_matrix_translate(&output->matrix, 0, -output->height, 0);
|
||
|
weston_matrix_rotate_xy(&output->matrix, 0, 1);
|
||
|
break;
|
||
|
case WL_OUTPUT_TRANSFORM_180:
|
||
|
case WL_OUTPUT_TRANSFORM_FLIPPED_180:
|
||
|
weston_matrix_translate(&output->matrix,
|
||
|
-output->width, -output->height, 0);
|
||
|
weston_matrix_rotate_xy(&output->matrix, -1, 0);
|
||
|
break;
|
||
|
case WL_OUTPUT_TRANSFORM_270:
|
||
|
case WL_OUTPUT_TRANSFORM_FLIPPED_270:
|
||
|
weston_matrix_translate(&output->matrix, -output->width, 0, 0);
|
||
|
weston_matrix_rotate_xy(&output->matrix, 0, -1);
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
if (output->current_scale != 1)
|
||
|
weston_matrix_scale(&output->matrix,
|
||
|
output->current_scale,
|
||
|
output->current_scale, 1);
|
||
11 years ago
|
|
||
13 years ago
|
output->dirty = 0;
|
||
10 years ago
|
|
||
|
weston_matrix_invert(&output->inverse_matrix, &output->matrix);
|
||
13 years ago
|
}
|
||
|
|
||
12 years ago
|
static void
|
||
12 years ago
|
weston_output_transform_scale_init(struct weston_output *output, uint32_t transform, uint32_t scale)
|
||
12 years ago
|
{
|
||
|
output->transform = transform;
|
||
9 years ago
|
output->native_scale = scale;
|
||
|
output->current_scale = scale;
|
||
12 years ago
|
|
||
9 years ago
|
convert_size_by_transform_scale(&output->width, &output->height,
|
||
|
output->current_mode->width,
|
||
|
output->current_mode->height,
|
||
|
transform, scale);
|
||
12 years ago
|
}
|
||
|
|
||
11 years ago
|
static void
|
||
|
weston_output_init_geometry(struct weston_output *output, int x, int y)
|
||
13 years ago
|
{
|
||
|
output->x = x;
|
||
|
output->y = y;
|
||
|
|
||
12 years ago
|
pixman_region32_init(&output->previous_damage);
|
||
13 years ago
|
pixman_region32_init_rect(&output->region, x, y,
|
||
12 years ago
|
output->width,
|
||
|
output->height);
|
||
14 years ago
|
}
|
||
|
|
||
11 years ago
|
WL_EXPORT void
|
||
|
weston_output_move(struct weston_output *output, int x, int y)
|
||
|
{
|
||
|
struct wl_resource *resource;
|
||
|
|
||
|
output->move_x = x - output->x;
|
||
|
output->move_y = y - output->y;
|
||
|
|
||
|
if (output->move_x == 0 && output->move_y == 0)
|
||
|
return;
|
||
|
|
||
|
weston_output_init_geometry(output, x, y);
|
||
|
|
||
|
output->dirty = 1;
|
||
|
|
||
|
/* Move views on this output. */
|
||
11 years ago
|
wl_signal_emit(&output->compositor->output_moved_signal, output);
|
||
11 years ago
|
|
||
|
/* Notify clients of the change for output position. */
|
||
11 years ago
|
wl_resource_for_each(resource, &output->resource_list) {
|
||
11 years ago
|
wl_output_send_geometry(resource,
|
||
|
output->x,
|
||
|
output->y,
|
||
|
output->mm_width,
|
||
|
output->mm_height,
|
||
|
output->subpixel,
|
||
|
output->make,
|
||
|
output->model,
|
||
|
output->transform);
|
||
11 years ago
|
|
||
9 years ago
|
if (wl_resource_get_version(resource) >= WL_OUTPUT_DONE_SINCE_VERSION)
|
||
11 years ago
|
wl_output_send_done(resource);
|
||
|
}
|
||
11 years ago
|
}
|
||
|
|
||
9 years ago
|
/** Initialize a weston_output object's parameters
|
||
|
*
|
||
|
* \param output The weston_output object to initialize
|
||
|
* \param c The output's compositor
|
||
|
* \param x x coordinate for the output in global coordinate space
|
||
|
* \param y y coordinate for the output in global coordinate space
|
||
|
* \param mm_width Physical width of the output as reported by the backend
|
||
|
* \param mm_height Physical height of the output as reported by the backend
|
||
|
* \param transform Rotation of the output
|
||
|
* \param scale Native scaling factor for the output
|
||
|
*
|
||
|
* Sets up the transformation, zoom, and geometry of the output using
|
||
|
* the input properties.
|
||
|
*
|
||
|
* Establishes a repaint timer for the output with the relevant display
|
||
|
* object's event loop. See output_repaint_timer_handler().
|
||
|
*
|
||
|
* The output is assigned an ID. Weston can support up to 32 distinct
|
||
|
* outputs, with IDs numbered from 0-31; the compositor's output_id_pool
|
||
|
* is referred to and used to find the first available ID number, and
|
||
|
* then this ID is marked as used in output_id_pool.
|
||
|
*
|
||
|
* The output is also assigned a Wayland global with the wl_output
|
||
|
* external interface.
|
||
|
*/
|
||
14 years ago
|
WL_EXPORT void
|
||
13 years ago
|
weston_output_init(struct weston_output *output, struct weston_compositor *c,
|
||
12 years ago
|
int x, int y, int mm_width, int mm_height, uint32_t transform,
|
||
12 years ago
|
int32_t scale)
|
||
14 years ago
|
{
|
||
11 years ago
|
struct wl_event_loop *loop;
|
||
|
|
||
9 years ago
|
/* Verify we haven't reached the limit of 32 available output IDs */
|
||
|
assert(ffs(~c->output_id_pool) > 0);
|
||
|
|
||
14 years ago
|
output->compositor = c;
|
||
|
output->x = x;
|
||
|
output->y = y;
|
||
12 years ago
|
output->mm_width = mm_width;
|
||
|
output->mm_height = mm_height;
|
||
13 years ago
|
output->dirty = 1;
|
||
11 years ago
|
output->original_scale = scale;
|
||
13 years ago
|
|
||
12 years ago
|
weston_output_transform_scale_init(output, transform, scale);
|
||
13 years ago
|
weston_output_init_zoom(output);
|
||
14 years ago
|
|
||
11 years ago
|
weston_output_init_geometry(output, x, y);
|
||
13 years ago
|
weston_output_damage(output);
|
||
14 years ago
|
|
||
13 years ago
|
wl_signal_init(&output->frame_signal);
|
||
12 years ago
|
wl_signal_init(&output->destroy_signal);
|
||
13 years ago
|
wl_list_init(&output->animation_list);
|
||
13 years ago
|
wl_list_init(&output->resource_list);
|
||
10 years ago
|
wl_list_init(&output->feedback_list);
|
||
9 years ago
|
wl_list_init(&output->link);
|
||
14 years ago
|
|
||
11 years ago
|
loop = wl_display_get_event_loop(c->wl_display);
|
||
|
output->repaint_timer = wl_event_loop_add_timer(loop,
|
||
|
output_repaint_timer_handler, output);
|
||
|
|
||
9 years ago
|
/* Invert the output id pool and look for the lowest numbered
|
||
|
* switch (the least significant bit). Take that bit's position
|
||
|
* as our ID, and mark it used in the compositor's output_id_pool.
|
||
|
*/
|
||
13 years ago
|
output->id = ffs(~output->compositor->output_id_pool) - 1;
|
||
9 years ago
|
output->compositor->output_id_pool |= 1u << output->id;
|
||
13 years ago
|
|
||
13 years ago
|
output->global =
|
||
12 years ago
|
wl_global_create(c->wl_display, &wl_output_interface, 2,
|
||
|
output, bind_output);
|
||
10 years ago
|
}
|
||
|
|
||
|
/** Adds an output to the compositor's output list and
|
||
|
* send the compositor's output_created signal.
|
||
|
*
|
||
|
* \param compositor The compositor instance.
|
||
|
* \param output The output to be added.
|
||
|
*/
|
||
|
WL_EXPORT void
|
||
|
weston_compositor_add_output(struct weston_compositor *compositor,
|
||
|
struct weston_output *output)
|
||
|
{
|
||
|
wl_list_insert(compositor->output_list.prev, &output->link);
|
||
|
wl_signal_emit(&compositor->output_created_signal, output);
|
||
15 years ago
|
}
|
||
|
|
||
11 years ago
|
WL_EXPORT void
|
||
|
weston_output_transform_coordinate(struct weston_output *output,
|
||
9 years ago
|
double device_x, double device_y,
|
||
|
double *x, double *y)
|
||
11 years ago
|
{
|
||
10 years ago
|
struct weston_vector p = { {
|
||
9 years ago
|
device_x,
|
||
|
device_y,
|
||
10 years ago
|
0.0,
|
||
|
1.0 } };
|
||
11 years ago
|
|
||
10 years ago
|
weston_matrix_transform(&output->inverse_matrix, &p);
|
||
11 years ago
|
|
||
9 years ago
|
*x = p.f[0] / p.f[3];
|
||
|
*y = p.f[1] / p.f[3];
|
||
11 years ago
|
}
|
||
|
|
||
11 years ago
|
static void
|
||
11 years ago
|
destroy_viewport(struct wl_resource *resource)
|
||
11 years ago
|
{
|
||
11 years ago
|
struct weston_surface *surface =
|
||
|
wl_resource_get_user_data(resource);
|
||
|
|
||
9 years ago
|
if (!surface)
|
||
|
return;
|
||
|
|
||
11 years ago
|
surface->viewport_resource = NULL;
|
||
11 years ago
|
surface->pending.buffer_viewport.buffer.src_width =
|
||
|
wl_fixed_from_int(-1);
|
||
|
surface->pending.buffer_viewport.surface.width = -1;
|
||
11 years ago
|
surface->pending.buffer_viewport.changed = 1;
|
||
11 years ago
|
}
|
||
|
|
||
|
static void
|
||
11 years ago
|
viewport_destroy(struct wl_client *client,
|
||
|
struct wl_resource *resource)
|
||
11 years ago
|
{
|
||
|
wl_resource_destroy(resource);
|
||
|
}
|
||
|
|
||
11 years ago
|
static void
|
||
|
viewport_set_source(struct wl_client *client,
|
||
|
struct wl_resource *resource,
|
||
|
wl_fixed_t src_x,
|
||
|
wl_fixed_t src_y,
|
||
|
wl_fixed_t src_width,
|
||
|
wl_fixed_t src_height)
|
||
|
{
|
||
|
struct weston_surface *surface =
|
||
|
wl_resource_get_user_data(resource);
|
||
|
|
||
9 years ago
|
if (!surface) {
|
||
|
wl_resource_post_error(resource,
|
||
|
WP_VIEWPORT_ERROR_NO_SURFACE,
|
||
|
"wl_surface for this viewport is no longer exists");
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
assert(surface->viewport_resource == resource);
|
||
9 years ago
|
assert(surface->resource);
|
||
11 years ago
|
|
||
11 years ago
|
if (src_width == wl_fixed_from_int(-1) &&
|
||
9 years ago
|
src_height == wl_fixed_from_int(-1) &&
|
||
|
src_x == wl_fixed_from_int(-1) &&
|
||
|
src_y == wl_fixed_from_int(-1)) {
|
||
|
/* unset source rect */
|
||
11 years ago
|
surface->pending.buffer_viewport.buffer.src_width =
|
||
|
wl_fixed_from_int(-1);
|
||
11 years ago
|
surface->pending.buffer_viewport.changed = 1;
|
||
11 years ago
|
return;
|
||
11 years ago
|
}
|
||
11 years ago
|
|
||
9 years ago
|
if (src_width <= 0 || src_height <= 0 || src_x < 0 || src_y < 0) {
|
||
11 years ago
|
wl_resource_post_error(resource,
|
||
9 years ago
|
WP_VIEWPORT_ERROR_BAD_VALUE,
|
||
9 years ago
|
"wl_surface@%d viewport source "
|
||
|
"w=%f <= 0, h=%f <= 0, x=%f < 0, or y=%f < 0",
|
||
|
wl_resource_get_id(surface->resource),
|
||
11 years ago
|
wl_fixed_to_double(src_width),
|
||
9 years ago
|
wl_fixed_to_double(src_height),
|
||
|
wl_fixed_to_double(src_x),
|
||
|
wl_fixed_to_double(src_y));
|
||
11 years ago
|
return;
|
||
|
}
|
||
|
|
||
|
surface->pending.buffer_viewport.buffer.src_x = src_x;
|
||
|
surface->pending.buffer_viewport.buffer.src_y = src_y;
|
||
|
surface->pending.buffer_viewport.buffer.src_width = src_width;
|
||
|
surface->pending.buffer_viewport.buffer.src_height = src_height;
|
||
11 years ago
|
surface->pending.buffer_viewport.changed = 1;
|
||
11 years ago
|
}
|
||
|
|
||
|
static void
|
||
|
viewport_set_destination(struct wl_client *client,
|
||
|
struct wl_resource *resource,
|
||
|
int32_t dst_width,
|
||
|
int32_t dst_height)
|
||
|
{
|
||
|
struct weston_surface *surface =
|
||
|
wl_resource_get_user_data(resource);
|
||
|
|
||
9 years ago
|
if (!surface) {
|
||
|
wl_resource_post_error(resource,
|
||
|
WP_VIEWPORT_ERROR_NO_SURFACE,
|
||
|
"wl_surface for this viewport no longer exists");
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
assert(surface->viewport_resource == resource);
|
||
11 years ago
|
|
||
11 years ago
|
if (dst_width == -1 && dst_height == -1) {
|
||
|
/* unset destination size */
|
||
11 years ago
|
surface->pending.buffer_viewport.surface.width = -1;
|
||
11 years ago
|
surface->pending.buffer_viewport.changed = 1;
|
||
11 years ago
|
return;
|
||
|
}
|
||
|
|
||
|
if (dst_width <= 0 || dst_height <= 0) {
|
||
|
wl_resource_post_error(resource,
|
||
9 years ago
|
WP_VIEWPORT_ERROR_BAD_VALUE,
|
||
11 years ago
|
"destination size must be positive (%dx%d)",
|
||
|
dst_width, dst_height);
|
||
|
return;
|
||
11 years ago
|
}
|
||
11 years ago
|
|
||
|
surface->pending.buffer_viewport.surface.width = dst_width;
|
||
|
surface->pending.buffer_viewport.surface.height = dst_height;
|
||
11 years ago
|
surface->pending.buffer_viewport.changed = 1;
|
||
11 years ago
|
}
|
||
|
|
||
9 years ago
|
static const struct wp_viewport_interface viewport_interface = {
|
||
11 years ago
|
viewport_destroy,
|
||
11 years ago
|
viewport_set_source,
|
||
|
viewport_set_destination
|
||
11 years ago
|
};
|
||
|
|
||
|
static void
|
||
9 years ago
|
viewporter_destroy(struct wl_client *client,
|
||
|
struct wl_resource *resource)
|
||
11 years ago
|
{
|
||
|
wl_resource_destroy(resource);
|
||
|
}
|
||
|
|
||
|
static void
|
||
9 years ago
|
viewporter_get_viewport(struct wl_client *client,
|
||
|
struct wl_resource *viewporter,
|
||
|
uint32_t id,
|
||
|
struct wl_resource *surface_resource)
|
||
11 years ago
|
{
|
||
9 years ago
|
int version = wl_resource_get_version(viewporter);
|
||
11 years ago
|
struct weston_surface *surface =
|
||
|
wl_resource_get_user_data(surface_resource);
|
||
11 years ago
|
struct wl_resource *resource;
|
||
|
|
||
11 years ago
|
if (surface->viewport_resource) {
|
||
9 years ago
|
wl_resource_post_error(viewporter,
|
||
9 years ago
|
WP_VIEWPORTER_ERROR_VIEWPORT_EXISTS,
|
||
11 years ago
|
"a viewport for that surface already exists");
|
||
11 years ago
|
return;
|
||
|
}
|
||
|
|
||
9 years ago
|
resource = wl_resource_create(client, &wp_viewport_interface,
|
||
11 years ago
|
version, id);
|
||
11 years ago
|
if (resource == NULL) {
|
||
|
wl_client_post_no_memory(client);
|
||
|
return;
|
||
|
}
|
||
|
|
||
11 years ago
|
wl_resource_set_implementation(resource, &viewport_interface,
|
||
|
surface, destroy_viewport);
|
||
11 years ago
|
|
||
11 years ago
|
surface->viewport_resource = resource;
|
||
11 years ago
|
}
|
||
|
|
||
9 years ago
|
static const struct wp_viewporter_interface viewporter_interface = {
|
||
|
viewporter_destroy,
|
||
|
viewporter_get_viewport
|
||
11 years ago
|
};
|
||
|
|
||
|
static void
|
||
9 years ago
|
bind_viewporter(struct wl_client *client,
|
||
|
void *data, uint32_t version, uint32_t id)
|
||
11 years ago
|
{
|
||
|
struct wl_resource *resource;
|
||
|
|
||
9 years ago
|
resource = wl_resource_create(client, &wp_viewporter_interface,
|
||
9 years ago
|
version, id);
|
||
11 years ago
|
if (resource == NULL) {
|
||
|
wl_client_post_no_memory(client);
|
||
|
return;
|
||
|
}
|
||
|
|
||
9 years ago
|
wl_resource_set_implementation(resource, &viewporter_interface,
|
||
11 years ago
|
NULL, NULL);
|
||
|
}
|
||
|
|
||
10 years ago
|
static void
|
||
|
destroy_presentation_feedback(struct wl_resource *feedback_resource)
|
||
|
{
|
||
|
struct weston_presentation_feedback *feedback;
|
||
|
|
||
|
feedback = wl_resource_get_user_data(feedback_resource);
|
||
|
|
||
|
wl_list_remove(&feedback->link);
|
||
|
free(feedback);
|
||
|
}
|
||
|
|
||
10 years ago
|
static void
|
||
|
presentation_destroy(struct wl_client *client, struct wl_resource *resource)
|
||
|
{
|
||
|
wl_resource_destroy(resource);
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
presentation_feedback(struct wl_client *client,
|
||
10 years ago
|
struct wl_resource *presentation_resource,
|
||
|
struct wl_resource *surface_resource,
|
||
10 years ago
|
uint32_t callback)
|
||
|
{
|
||
10 years ago
|
struct weston_surface *surface;
|
||
|
struct weston_presentation_feedback *feedback;
|
||
|
|
||
|
surface = wl_resource_get_user_data(surface_resource);
|
||
|
|
||
10 years ago
|
feedback = zalloc(sizeof *feedback);
|
||
|
if (feedback == NULL)
|
||
10 years ago
|
goto err_calloc;
|
||
|
|
||
|
feedback->resource = wl_resource_create(client,
|
||
9 years ago
|
&wp_presentation_feedback_interface,
|
||
10 years ago
|
1, callback);
|
||
|
if (!feedback->resource)
|
||
|
goto err_create;
|
||
|
|
||
|
wl_resource_set_implementation(feedback->resource, NULL, feedback,
|
||
|
destroy_presentation_feedback);
|
||
|
|
||
|
wl_list_insert(&surface->pending.feedback_list, &feedback->link);
|
||
|
|
||
|
return;
|
||
|
|
||
|
err_create:
|
||
|
free(feedback);
|
||
|
|
||
|
err_calloc:
|
||
|
wl_client_post_no_memory(client);
|
||
10 years ago
|
}
|
||
|
|
||
9 years ago
|
static const struct wp_presentation_interface presentation_implementation = {
|
||
10 years ago
|
presentation_destroy,
|
||
|
presentation_feedback
|
||
|
};
|
||
|
|
||
|
static void
|
||
|
bind_presentation(struct wl_client *client,
|
||
|
void *data, uint32_t version, uint32_t id)
|
||
|
{
|
||
|
struct weston_compositor *compositor = data;
|
||
|
struct wl_resource *resource;
|
||
|
|
||
9 years ago
|
resource = wl_resource_create(client, &wp_presentation_interface,
|
||
9 years ago
|
version, id);
|
||
10 years ago
|
if (resource == NULL) {
|
||
|
wl_client_post_no_memory(client);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
wl_resource_set_implementation(resource, &presentation_implementation,
|
||
|
compositor, NULL);
|
||
9 years ago
|
wp_presentation_send_clock_id(resource, compositor->presentation_clock);
|
||
10 years ago
|
}
|
||
|
|
||
13 years ago
|
static void
|
||
|
compositor_bind(struct wl_client *client,
|
||
|
void *data, uint32_t version, uint32_t id)
|
||
|
{
|
||
13 years ago
|
struct weston_compositor *compositor = data;
|
||
12 years ago
|
struct wl_resource *resource;
|
||
13 years ago
|
|
||
12 years ago
|
resource = wl_resource_create(client, &wl_compositor_interface,
|
||
9 years ago
|
version, id);
|
||
11 years ago
|
if (resource == NULL) {
|
||
|
wl_client_post_no_memory(client);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
wl_resource_set_implementation(resource, &compositor_interface,
|
||
|
compositor, NULL);
|
||
13 years ago
|
}
|
||
|
|
||
12 years ago
|
WL_EXPORT int
|
||
|
weston_environment_get_fd(const char *env)
|
||
|
{
|
||
|
char *e, *end;
|
||
|
int fd, flags;
|
||
|
|
||
|
e = getenv(env);
|
||
|
if (!e)
|
||
|
return -1;
|
||
|
fd = strtol(e, &end, 0);
|
||
|
if (*end != '\0')
|
||
|
return -1;
|
||
|
|
||
|
flags = fcntl(fd, F_GETFD);
|
||
|
if (flags == -1)
|
||
|
return -1;
|
||
|
|
||
|
fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
|
||
|
unsetenv(env);
|
||
|
|
||
|
return fd;
|
||
|
}
|
||
|
|
||
10 years ago
|
static void
|
||
9 years ago
|
timeline_key_binding_handler(struct weston_keyboard *keyboard, uint32_t time,
|
||
10 years ago
|
uint32_t key, void *data)
|
||
|
{
|
||
|
struct weston_compositor *compositor = data;
|
||
|
|
||
|
if (weston_timeline_enabled_)
|
||
|
weston_timeline_close();
|
||
|
else
|
||
|
weston_timeline_open(compositor);
|
||
|
}
|
||
|
|
||
10 years ago
|
/** Create the compositor.
|
||
|
*
|
||
|
* This functions creates and initializes a compositor instance.
|
||
|
*
|
||
|
* \param display The Wayland display to be used.
|
||
|
* \param user_data A pointer to an object that can later be retrieved
|
||
|
* using the \ref weston_compositor_get_user_data function.
|
||
|
* \return The compositor instance on success or NULL on failure.
|
||
|
*/
|
||
|
WL_EXPORT struct weston_compositor *
|
||
|
weston_compositor_create(struct wl_display *display, void *user_data)
|
||
15 years ago
|
{
|
||
10 years ago
|
struct weston_compositor *ec;
|
||
15 years ago
|
struct wl_event_loop *loop;
|
||
12 years ago
|
|
||
10 years ago
|
ec = zalloc(sizeof *ec);
|
||
|
if (!ec)
|
||
|
return NULL;
|
||
|
|
||
|
ec->wl_display = display;
|
||
|
ec->user_data = user_data;
|
||
13 years ago
|
wl_signal_init(&ec->destroy_signal);
|
||
11 years ago
|
wl_signal_init(&ec->create_surface_signal);
|
||
13 years ago
|
wl_signal_init(&ec->activate_signal);
|
||
12 years ago
|
wl_signal_init(&ec->transform_signal);
|
||
12 years ago
|
wl_signal_init(&ec->kill_signal);
|
||
12 years ago
|
wl_signal_init(&ec->idle_signal);
|
||
|
wl_signal_init(&ec->wake_signal);
|
||
13 years ago
|
wl_signal_init(&ec->show_input_panel_signal);
|
||
|
wl_signal_init(&ec->hide_input_panel_signal);
|
||
12 years ago
|
wl_signal_init(&ec->update_input_panel_signal);
|
||
12 years ago
|
wl_signal_init(&ec->seat_created_signal);
|
||
12 years ago
|
wl_signal_init(&ec->output_created_signal);
|
||
11 years ago
|
wl_signal_init(&ec->output_destroyed_signal);
|
||
11 years ago
|
wl_signal_init(&ec->output_moved_signal);
|
||
9 years ago
|
wl_signal_init(&ec->output_resized_signal);
|
||
11 years ago
|
wl_signal_init(&ec->session_signal);
|
||
|
ec->session_active = 1;
|
||
16 years ago
|
|
||
13 years ago
|
ec->output_id_pool = 0;
|
||
10 years ago
|
ec->repaint_msec = DEFAULT_REPAINT_WINDOW;
|
||
13 years ago
|
|
||
9 years ago
|
if (!wl_global_create(ec->wl_display, &wl_compositor_interface, 4,
|
||
12 years ago
|
ec, compositor_bind))
|
||
10 years ago
|
goto fail;
|
||
16 years ago
|
|
||
10 years ago
|
if (!wl_global_create(ec->wl_display, &wl_subcompositor_interface, 1,
|
||
12 years ago
|
ec, bind_subcompositor))
|
||
10 years ago
|
goto fail;
|
||
12 years ago
|
|
||
9 years ago
|
if (!wl_global_create(ec->wl_display, &wp_viewporter_interface, 1,
|
||
9 years ago
|
ec, bind_viewporter))
|
||
10 years ago
|
goto fail;
|
||
11 years ago
|
|
||
9 years ago
|
if (!wl_global_create(ec->wl_display, &wp_presentation_interface, 1,
|
||
10 years ago
|
ec, bind_presentation))
|
||
10 years ago
|
goto fail;
|
||
10 years ago
|
|
||
11 years ago
|
wl_list_init(&ec->view_list);
|
||
12 years ago
|
wl_list_init(&ec->plane_list);
|
||
13 years ago
|
wl_list_init(&ec->layer_list);
|
||
|
wl_list_init(&ec->seat_list);
|
||
|
wl_list_init(&ec->output_list);
|
||
|
wl_list_init(&ec->key_binding_list);
|
||
11 years ago
|
wl_list_init(&ec->modifier_binding_list);
|
||
13 years ago
|
wl_list_init(&ec->button_binding_list);
|
||
11 years ago
|
wl_list_init(&ec->touch_binding_list);
|
||
13 years ago
|
wl_list_init(&ec->axis_binding_list);
|
||
12 years ago
|
wl_list_init(&ec->debug_binding_list);
|
||
13 years ago
|
|
||
11 years ago
|
weston_plane_init(&ec->primary_plane, ec, 0, 0);
|
||
12 years ago
|
weston_compositor_stack_plane(ec, &ec->primary_plane, NULL);
|
||
12 years ago
|
|
||
10 years ago
|
wl_data_device_manager_init(ec->wl_display);
|
||
|
|
||
|
wl_display_init_shm(ec->wl_display);
|
||
|
|
||
|
loop = wl_display_get_event_loop(ec->wl_display);
|
||
|
ec->idle_source = wl_event_loop_add_timer(loop, idle_handler, ec);
|
||
|
|
||
|
weston_layer_init(&ec->fade_layer, &ec->layer_list);
|
||
|
weston_layer_init(&ec->cursor_layer, &ec->fade_layer.link);
|
||
|
|
||
|
weston_compositor_add_debug_binding(ec, KEY_T,
|
||
|
timeline_key_binding_handler, ec);
|
||
|
|
||
|
return ec;
|
||
|
|
||
|
fail:
|
||
|
free(ec);
|
||
|
return NULL;
|
||
|
}
|
||
|
|
||
13 years ago
|
WL_EXPORT void
|
||
13 years ago
|
weston_compositor_shutdown(struct weston_compositor *ec)
|
||
13 years ago
|
{
|
||
13 years ago
|
struct weston_output *output, *next;
|
||
13 years ago
|
|
||
13 years ago
|
wl_event_source_remove(ec->idle_source);
|
||
|
|
||
13 years ago
|
/* Destroy all outputs associated with this compositor */
|
||
13 years ago
|
wl_list_for_each_safe(output, next, &ec->output_list, link)
|
||
13 years ago
|
output->destroy(output);
|
||
13 years ago
|
|
||
11 years ago
|
if (ec->renderer)
|
||
|
ec->renderer->destroy(ec);
|
||
|
|
||
13 years ago
|
weston_binding_list_destroy_all(&ec->key_binding_list);
|
||
9 years ago
|
weston_binding_list_destroy_all(&ec->modifier_binding_list);
|
||
13 years ago
|
weston_binding_list_destroy_all(&ec->button_binding_list);
|
||
11 years ago
|
weston_binding_list_destroy_all(&ec->touch_binding_list);
|
||
13 years ago
|
weston_binding_list_destroy_all(&ec->axis_binding_list);
|
||
12 years ago
|
weston_binding_list_destroy_all(&ec->debug_binding_list);
|
||
13 years ago
|
|
||
12 years ago
|
weston_plane_release(&ec->primary_plane);
|
||
13 years ago
|
}
|
||
|
|
||
10 years ago
|
WL_EXPORT void
|
||
|
weston_compositor_exit_with_code(struct weston_compositor *compositor,
|
||
|
int exit_code)
|
||
|
{
|
||
10 years ago
|
if (compositor->exit_code == EXIT_SUCCESS)
|
||
|
compositor->exit_code = exit_code;
|
||
|
|
||
10 years ago
|
weston_compositor_exit(compositor);
|
||
10 years ago
|
}
|
||
|
|
||
11 years ago
|
WL_EXPORT void
|
||
|
weston_compositor_set_default_pointer_grab(struct weston_compositor *ec,
|
||
|
const struct weston_pointer_grab_interface *interface)
|
||
|
{
|
||
|
struct weston_seat *seat;
|
||
|
|
||
|
ec->default_pointer_grab = interface;
|
||
|
wl_list_for_each(seat, &ec->seat_list, link) {
|
||
9 years ago
|
struct weston_pointer *pointer = weston_seat_get_pointer(seat);
|
||
|
|
||
|
if (pointer)
|
||
|
weston_pointer_set_default_grab(pointer, interface);
|
||
11 years ago
|
}
|
||
|
}
|
||
|
|
||
10 years ago
|
WL_EXPORT int
|
||
|
weston_compositor_set_presentation_clock(struct weston_compositor *compositor,
|
||
|
clockid_t clk_id)
|
||
|
{
|
||
|
struct timespec ts;
|
||
|
|
||
|
if (clock_gettime(clk_id, &ts) < 0)
|
||
|
return -1;
|
||
|
|
||
|
compositor->presentation_clock = clk_id;
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
* For choosing the software clock, when the display hardware or API
|
||
|
* does not expose a compatible presentation timestamp.
|
||
|
*/
|
||
|
WL_EXPORT int
|
||
|
weston_compositor_set_presentation_clock_software(
|
||
|
struct weston_compositor *compositor)
|
||
|
{
|
||
|
/* In order of preference */
|
||
|
static const clockid_t clocks[] = {
|
||
|
CLOCK_MONOTONIC_RAW, /* no jumps, no crawling */
|
||
|
CLOCK_MONOTONIC_COARSE, /* no jumps, may crawl, fast & coarse */
|
||
|
CLOCK_MONOTONIC, /* no jumps, may crawl */
|
||
|
CLOCK_REALTIME_COARSE, /* may jump and crawl, fast & coarse */
|
||
|
CLOCK_REALTIME /* may jump and crawl */
|
||
|
};
|
||
|
unsigned i;
|
||
|
|
||
|
for (i = 0; i < ARRAY_LENGTH(clocks); i++)
|
||
|
if (weston_compositor_set_presentation_clock(compositor,
|
||
|
clocks[i]) == 0)
|
||
|
return 0;
|
||
|
|
||
|
weston_log("Error: no suitable presentation clock available.\n");
|
||
|
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
10 years ago
|
/** Read the current time from the Presentation clock
|
||
|
*
|
||
|
* \param compositor
|
||
|
* \param ts[out] The current time.
|
||
|
*
|
||
|
* \note Reading the current time in user space is always imprecise to some
|
||
|
* degree.
|
||
|
*
|
||
|
* This function is never meant to fail. If reading the clock does fail,
|
||
|
* an error message is logged and a zero time is returned. Callers are not
|
||
|
* supposed to detect or react to failures.
|
||
|
*/
|
||
|
WL_EXPORT void
|
||
|
weston_compositor_read_presentation_clock(
|
||
|
const struct weston_compositor *compositor,
|
||
|
struct timespec *ts)
|
||
|
{
|
||
|
static bool warned;
|
||
|
int ret;
|
||
|
|
||
|
ret = clock_gettime(compositor->presentation_clock, ts);
|
||
|
if (ret < 0) {
|
||
|
ts->tv_sec = 0;
|
||
|
ts->tv_nsec = 0;
|
||
|
|
||
|
if (!warned)
|
||
|
weston_log("Error: failure to read "
|
||
|
"the presentation clock %#x: '%m' (%d)\n",
|
||
|
compositor->presentation_clock, errno);
|
||
|
warned = true;
|
||
|
}
|
||
|
}
|
||
|
|
||
10 years ago
|
/** Import dmabuf buffer into current renderer
|
||
|
*
|
||
|
* \param compositor
|
||
|
* \param buffer the dmabuf buffer to import
|
||
|
* \return true on usable buffers, false otherwise
|
||
|
*
|
||
|
* This function tests that the linux_dmabuf_buffer is usable
|
||
|
* for the current renderer. Returns false on unusable buffers. Usually
|
||
|
* usability is tested by importing the dmabufs for composition.
|
||
|
*
|
||
|
* This hook is also used for detecting if the renderer supports
|
||
|
* dmabufs at all. If the renderer hook is NULL, dmabufs are not
|
||
|
* supported.
|
||
|
* */
|
||
|
WL_EXPORT bool
|
||
|
weston_compositor_import_dmabuf(struct weston_compositor *compositor,
|
||
|
struct linux_dmabuf_buffer *buffer)
|
||
|
{
|
||
|
struct weston_renderer *renderer;
|
||
|
|
||
|
renderer = compositor->renderer;
|
||
|
|
||
|
if (renderer->import_dmabuf == NULL)
|
||
|
return false;
|
||
|
|
||
|
return renderer->import_dmabuf(compositor, buffer);
|
||
|
}
|
||
|
|
||
12 years ago
|
WL_EXPORT void
|
||
|
weston_version(int *major, int *minor, int *micro)
|
||
|
{
|
||
|
*major = WESTON_VERSION_MAJOR;
|
||
|
*minor = WESTON_VERSION_MINOR;
|
||
|
*micro = WESTON_VERSION_MICRO;
|
||
|
}
|
||
|
|
||
11 years ago
|
WL_EXPORT void *
|
||
|
weston_load_module(const char *name, const char *entrypoint)
|
||
14 years ago
|
{
|
||
10 years ago
|
const char *builddir = getenv("WESTON_BUILD_DIR");
|
||
14 years ago
|
char path[PATH_MAX];
|
||
|
void *module, *init;
|
||
|
|
||
11 years ago
|
if (name == NULL)
|
||
|
return NULL;
|
||
|
|
||
10 years ago
|
if (name[0] != '/') {
|
||
|
if (builddir)
|
||
|
snprintf(path, sizeof path, "%s/.libs/%s", builddir, name);
|
||
|
else
|
||
9 years ago
|
snprintf(path, sizeof path, "%s/%s", LIBWESTON_MODULEDIR, name);
|
||
10 years ago
|
} else {
|
||
14 years ago
|
snprintf(path, sizeof path, "%s", name);
|
||
10 years ago
|
}
|
||
14 years ago
|
|
||
12 years ago
|
module = dlopen(path, RTLD_NOW | RTLD_NOLOAD);
|
||
|
if (module) {
|
||
|
weston_log("Module '%s' already loaded\n", path);
|
||
|
dlclose(module);
|
||
|
return NULL;
|
||
|
}
|
||
|
|
||
13 years ago
|
weston_log("Loading module '%s'\n", path);
|
||
12 years ago
|
module = dlopen(path, RTLD_NOW);
|
||
14 years ago
|
if (!module) {
|
||
13 years ago
|
weston_log("Failed to load module: %s\n", dlerror());
|
||
14 years ago
|
return NULL;
|
||
|
}
|
||
|
|
||
|
init = dlsym(module, entrypoint);
|
||
|
if (!init) {
|
||
13 years ago
|
weston_log("Failed to lookup init function: %s\n", dlerror());
|
||
12 years ago
|
dlclose(module);
|
||
14 years ago
|
return NULL;
|
||
|
}
|
||
|
|
||
|
return init;
|
||
|
}
|
||
|
|
||
10 years ago
|
|
||
|
/** Destroys the compositor.
|
||
|
*
|
||
|
* This function cleans up the compositor state and destroys it.
|
||
|
*
|
||
|
* \param compositor The compositor to be destroyed.
|
||
|
*/
|
||
|
WL_EXPORT void
|
||
|
weston_compositor_destroy(struct weston_compositor *compositor)
|
||
|
{
|
||
|
/* prevent further rendering while shutting down */
|
||
|
compositor->state = WESTON_COMPOSITOR_OFFSCREEN;
|
||
|
|
||
|
wl_signal_emit(&compositor->destroy_signal, compositor);
|
||
|
|
||
|
weston_compositor_xkb_destroy(compositor);
|
||
|
|
||
9 years ago
|
if (compositor->backend)
|
||
|
compositor->backend->destroy(compositor);
|
||
10 years ago
|
free(compositor);
|
||
|
}
|
||
|
|
||
|
/** Instruct the compositor to exit.
|
||
|
*
|
||
|
* This functions does not directly destroy the compositor object, it merely
|
||
|
* command it to start the tear down process. It is not guaranteed that the
|
||
|
* tear down will happen immediately.
|
||
|
*
|
||
|
* \param compositor The compositor to tear down.
|
||
|
*/
|
||
|
WL_EXPORT void
|
||
|
weston_compositor_exit(struct weston_compositor *compositor)
|
||
|
{
|
||
|
compositor->exit(compositor);
|
||
|
}
|
||
|
|
||
|
/** Return the user data stored in the compositor.
|
||
|
*
|
||
|
* This function returns the user data pointer set with user_data parameter
|
||
|
* to the \ref weston_compositor_create function.
|
||
|
*/
|
||
|
WL_EXPORT void *
|
||
|
weston_compositor_get_user_data(struct weston_compositor *compositor)
|
||
|
{
|
||
|
return compositor->user_data;
|
||
|
}
|
||
9 years ago
|
|
||
9 years ago
|
static const char * const backend_map[] = {
|
||
|
[WESTON_BACKEND_DRM] = "drm-backend.so",
|
||
|
[WESTON_BACKEND_FBDEV] = "fbdev-backend.so",
|
||
|
[WESTON_BACKEND_HEADLESS] = "headless-backend.so",
|
||
|
[WESTON_BACKEND_RDP] = "rdp-backend.so",
|
||
|
[WESTON_BACKEND_WAYLAND] = "wayland-backend.so",
|
||
|
[WESTON_BACKEND_X11] = "x11-backend.so",
|
||
|
};
|
||
|
|
||
9 years ago
|
/** Load a backend into a weston_compositor
|
||
|
*
|
||
|
* A backend must be loaded to make a weston_compositor work. A backend
|
||
|
* provides input and output capabilities, and determines the renderer to use.
|
||
|
*
|
||
|
* \param compositor A compositor that has not had a backend loaded yet.
|
||
|
* \param backend Name of the backend file.
|
||
|
* \param config_base A pointer to a backend-specific configuration
|
||
|
* structure's 'base' member.
|
||
|
*
|
||
|
* \return 0 on success, or -1 on error.
|
||
|
*/
|
||
|
WL_EXPORT int
|
||
|
weston_compositor_load_backend(struct weston_compositor *compositor,
|
||
9 years ago
|
enum weston_compositor_backend backend,
|
||
9 years ago
|
struct weston_backend_config *config_base)
|
||
|
{
|
||
|
int (*backend_init)(struct weston_compositor *c,
|
||
|
struct weston_backend_config *config_base);
|
||
|
|
||
9 years ago
|
if (backend < 0 || backend >= ARRAY_LENGTH(backend_map))
|
||
|
return -1;
|
||
|
|
||
|
backend_init = weston_load_module(backend_map[backend], "backend_init");
|
||
9 years ago
|
if (!backend_init)
|
||
|
return -1;
|
||
|
|
||
9 years ago
|
return backend_init(compositor, config_base);
|
||
9 years ago
|
}
|