2023-01-26 15:40:13 -05:00
|
|
|
// Copyright 2018 The ChromiumOS Authors
|
2019-09-20 18:57:28 -04:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2023-01-26 15:40:13 -05:00
|
|
|
#include "sommelier.h" // NOLINT(build/include_directory)
|
|
|
|
#include "sommelier-tracing.h" // NOLINT(build/include_directory)
|
2019-09-20 18:57:28 -04:00
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2023-01-26 15:40:13 -05:00
|
|
|
#include "viewporter-client-protocol.h" // NOLINT(build/include_directory)
|
|
|
|
#include "viewporter-server-protocol.h" // NOLINT(build/include_directory)
|
2019-09-20 18:57:28 -04:00
|
|
|
|
|
|
|
struct sl_host_viewporter {
|
|
|
|
struct sl_viewporter* viewporter;
|
|
|
|
struct wl_resource* resource;
|
|
|
|
struct wp_viewporter* proxy;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct sl_host_viewport {
|
|
|
|
struct wl_resource* resource;
|
|
|
|
struct sl_viewport viewport;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void sl_viewport_destroy(struct wl_client* client,
|
|
|
|
struct wl_resource* resource) {
|
|
|
|
wl_resource_destroy(resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sl_viewport_set_source(struct wl_client* client,
|
|
|
|
struct wl_resource* resource,
|
|
|
|
wl_fixed_t x,
|
|
|
|
wl_fixed_t y,
|
|
|
|
wl_fixed_t width,
|
|
|
|
wl_fixed_t height) {
|
2023-01-26 15:40:13 -05:00
|
|
|
struct sl_host_viewport* host =
|
|
|
|
static_cast<sl_host_viewport*>(wl_resource_get_user_data(resource));
|
2019-09-20 18:57:28 -04:00
|
|
|
|
|
|
|
host->viewport.src_x = x;
|
|
|
|
host->viewport.src_y = y;
|
|
|
|
host->viewport.src_width = width;
|
|
|
|
host->viewport.src_height = height;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sl_viewport_set_destination(struct wl_client* client,
|
|
|
|
struct wl_resource* resource,
|
|
|
|
int32_t width,
|
|
|
|
int32_t height) {
|
2023-01-26 15:40:13 -05:00
|
|
|
TRACE_EVENT("viewport", "sl_viewport_set_destination", "resource_id",
|
|
|
|
wl_resource_get_id(resource));
|
|
|
|
struct sl_host_viewport* host =
|
|
|
|
static_cast<sl_host_viewport*>(wl_resource_get_user_data(resource));
|
2019-09-20 18:57:28 -04:00
|
|
|
|
|
|
|
host->viewport.dst_width = width;
|
|
|
|
host->viewport.dst_height = height;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wp_viewport_interface sl_viewport_implementation = {
|
|
|
|
sl_viewport_destroy, sl_viewport_set_source, sl_viewport_set_destination};
|
|
|
|
|
|
|
|
static void sl_destroy_host_viewport(struct wl_resource* resource) {
|
2023-01-26 15:40:13 -05:00
|
|
|
struct sl_host_viewport* host =
|
|
|
|
static_cast<sl_host_viewport*>(wl_resource_get_user_data(resource));
|
2019-09-20 18:57:28 -04:00
|
|
|
|
|
|
|
wl_resource_set_user_data(resource, NULL);
|
|
|
|
wl_list_remove(&host->viewport.link);
|
2023-01-26 15:40:13 -05:00
|
|
|
delete host;
|
2019-09-20 18:57:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void sl_viewporter_destroy(struct wl_client* client,
|
|
|
|
struct wl_resource* resource) {
|
|
|
|
wl_resource_destroy(resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sl_viewporter_get_viewport(struct wl_client* client,
|
|
|
|
struct wl_resource* resource,
|
|
|
|
uint32_t id,
|
|
|
|
struct wl_resource* surface_resource) {
|
2023-01-26 15:40:13 -05:00
|
|
|
struct sl_host_surface* host_surface = static_cast<sl_host_surface*>(
|
|
|
|
wl_resource_get_user_data(surface_resource));
|
|
|
|
struct sl_host_viewport* host_viewport = new sl_host_viewport();
|
2019-09-20 18:57:28 -04:00
|
|
|
|
|
|
|
host_viewport->viewport.src_x = -1;
|
|
|
|
host_viewport->viewport.src_y = -1;
|
|
|
|
host_viewport->viewport.src_width = -1;
|
|
|
|
host_viewport->viewport.src_height = -1;
|
|
|
|
host_viewport->viewport.dst_width = -1;
|
|
|
|
host_viewport->viewport.dst_height = -1;
|
|
|
|
wl_list_insert(&host_surface->contents_viewport,
|
|
|
|
&host_viewport->viewport.link);
|
|
|
|
host_viewport->resource =
|
|
|
|
wl_resource_create(client, &wp_viewport_interface, 1, id);
|
|
|
|
wl_resource_set_implementation(host_viewport->resource,
|
|
|
|
&sl_viewport_implementation, host_viewport,
|
|
|
|
sl_destroy_host_viewport);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wp_viewporter_interface sl_viewporter_implementation = {
|
|
|
|
sl_viewporter_destroy, sl_viewporter_get_viewport};
|
|
|
|
|
|
|
|
static void sl_destroy_host_viewporter(struct wl_resource* resource) {
|
2023-01-26 15:40:13 -05:00
|
|
|
struct sl_host_viewporter* host =
|
|
|
|
static_cast<sl_host_viewporter*>(wl_resource_get_user_data(resource));
|
2019-09-20 18:57:28 -04:00
|
|
|
|
|
|
|
wp_viewporter_destroy(host->proxy);
|
|
|
|
wl_resource_set_user_data(resource, NULL);
|
2023-01-26 15:40:13 -05:00
|
|
|
delete host;
|
2019-09-20 18:57:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void sl_bind_host_viewporter(struct wl_client* client,
|
|
|
|
void* data,
|
|
|
|
uint32_t version,
|
|
|
|
uint32_t id) {
|
|
|
|
struct sl_context* ctx = (struct sl_context*)data;
|
2023-01-26 15:40:13 -05:00
|
|
|
struct sl_host_viewporter* host = new sl_host_viewporter();
|
2019-09-20 18:57:28 -04:00
|
|
|
host->viewporter = ctx->viewporter;
|
|
|
|
host->resource = wl_resource_create(client, &wp_viewporter_interface, 1, id);
|
|
|
|
wl_resource_set_implementation(host->resource, &sl_viewporter_implementation,
|
|
|
|
host, sl_destroy_host_viewporter);
|
2023-01-26 15:40:13 -05:00
|
|
|
host->proxy = static_cast<wp_viewporter*>(
|
2019-09-20 18:57:28 -04:00
|
|
|
wl_registry_bind(wl_display_get_registry(ctx->display),
|
2023-01-26 15:40:13 -05:00
|
|
|
ctx->viewporter->id, &wp_viewporter_interface, 1));
|
2019-09-20 18:57:28 -04:00
|
|
|
wp_viewporter_set_user_data(host->proxy, host);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct sl_global* sl_viewporter_global_create(struct sl_context* ctx) {
|
|
|
|
return sl_global_create(ctx, &wp_viewporter_interface, 1, ctx,
|
|
|
|
sl_bind_host_viewporter);
|
2023-01-26 15:40:13 -05:00
|
|
|
}
|