forked from colemickens/platform2-sommelier
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsommelier-viewporter.c
128 lines (105 loc) · 4.59 KB
/
sommelier-viewporter.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// Copyright 2018 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sommelier.h"
#include <assert.h>
#include <stdlib.h>
#include "viewporter-client-protocol.h"
#include "viewporter-server-protocol.h"
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) {
struct sl_host_viewport* host = wl_resource_get_user_data(resource);
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) {
struct sl_host_viewport* host = wl_resource_get_user_data(resource);
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) {
struct sl_host_viewport* host = wl_resource_get_user_data(resource);
wl_resource_set_user_data(resource, NULL);
wl_list_remove(&host->viewport.link);
free(host);
}
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) {
struct sl_host_surface* host_surface =
wl_resource_get_user_data(surface_resource);
struct sl_host_viewport* host_viewport;
host_viewport = malloc(sizeof(*host_viewport));
assert(host_viewport);
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) {
struct sl_host_viewporter* host = wl_resource_get_user_data(resource);
wp_viewporter_destroy(host->proxy);
wl_resource_set_user_data(resource, NULL);
free(host);
}
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;
struct sl_host_viewporter* host;
host = malloc(sizeof(*host));
assert(host);
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);
host->proxy =
wl_registry_bind(wl_display_get_registry(ctx->display),
ctx->viewporter->id, &wp_viewporter_interface, 1);
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);
}