1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "host/libs/wayland/wayland_subcompositor.h"
18 
19 #include <android-base/logging.h>
20 
21 #include <wayland-server-core.h>
22 #include <wayland-server-protocol.h>
23 
24 namespace wayland {
25 namespace {
26 
subsurface_destroy(wl_client *,wl_resource * subsurface)27 void subsurface_destroy(wl_client*, wl_resource* subsurface) {
28   LOG(VERBOSE) << " subsurface=" << subsurface;
29 
30   wl_resource_destroy(subsurface);
31 }
32 
subsurface_set_position(wl_client *,wl_resource * subsurface,int32_t x,int32_t y)33 void subsurface_set_position(wl_client*,
34                              wl_resource* subsurface,
35                              int32_t x,
36                              int32_t y) {
37   LOG(VERBOSE) << __FUNCTION__
38                << " subsurface=" << subsurface
39                << " x=" << x
40                << " y=" << y;
41 }
42 
subsurface_place_above(wl_client *,wl_resource * subsurface,wl_resource * surface)43 void subsurface_place_above(wl_client*,
44                             wl_resource* subsurface,
45                             wl_resource* surface) {
46   LOG(VERBOSE) << __FUNCTION__
47                << " subsurface=" << subsurface
48                << " surface=" << surface;
49 }
50 
subsurface_place_below(wl_client *,wl_resource * subsurface,wl_resource * surface)51 void subsurface_place_below(wl_client*,
52                             wl_resource* subsurface,
53                             wl_resource* surface) {
54   LOG(VERBOSE) << __FUNCTION__
55                << " subsurface=" << subsurface
56                << " surface=" << surface;
57 }
58 
subsurface_set_sync(wl_client *,wl_resource * subsurface)59 void subsurface_set_sync(wl_client*, wl_resource* subsurface) {
60   LOG(VERBOSE) << __FUNCTION__
61                << " subsurface=" << subsurface;
62 }
63 
subsurface_set_desync(wl_client *,wl_resource * subsurface)64 void subsurface_set_desync(wl_client*, wl_resource* subsurface) {
65   LOG(VERBOSE) << __FUNCTION__
66                << " subsurface=" << subsurface;
67 }
68 
subsurface_destroy_resource_callback(struct wl_resource *)69 void subsurface_destroy_resource_callback(struct wl_resource*) {}
70 
71 const struct wl_subsurface_interface subsurface_implementation = {
72     .destroy = subsurface_destroy,
73     .set_position = subsurface_set_position,
74     .place_above = subsurface_place_above,
75     .place_below = subsurface_place_below,
76     .set_sync = subsurface_set_sync,
77     .set_desync = subsurface_set_desync,
78 };
79 
subcompositor_destroy(wl_client *,wl_resource * subcompositor)80 void subcompositor_destroy(wl_client*, wl_resource* subcompositor) {
81   LOG(VERBOSE) << __FUNCTION__
82                << " subcompositor=" << subcompositor;
83 
84   wl_resource_destroy(subcompositor);
85 }
86 
subcompositor_get_subsurface(wl_client * client,wl_resource * display,uint32_t id,wl_resource * surface,wl_resource * parent_surface)87 void subcompositor_get_subsurface(wl_client* client,
88                                   wl_resource* display,
89                                   uint32_t id,
90                                   wl_resource* surface,
91                                   wl_resource* parent_surface) {
92   LOG(VERBOSE) << __FUNCTION__
93                << " display=" << display
94                << " surface=" << surface
95                << " parent_surface=" << parent_surface;
96 
97   wl_resource* subsurface_resource =
98       wl_resource_create(client, &wl_subsurface_interface, 1, id);
99 
100   wl_resource_set_implementation(subsurface_resource,
101                                  &subsurface_implementation, nullptr,
102                                  subsurface_destroy_resource_callback);
103 }
104 
105 const struct wl_subcompositor_interface subcompositor_implementation = {
106     .destroy = subcompositor_destroy,
107     .get_subsurface = subcompositor_get_subsurface,
108 };
109 
subcompositor_destroy_resource_callback(struct wl_resource *)110 void subcompositor_destroy_resource_callback(struct wl_resource*) {}
111 
bind_subcompositor(wl_client * client,void * data,uint32_t version,uint32_t id)112 void bind_subcompositor(wl_client* client,
113                         void* data,
114                         uint32_t version,
115                         uint32_t id) {
116   wl_resource* resource =
117       wl_resource_create(client, &wl_subcompositor_interface, version, id);
118 
119   wl_resource_set_implementation(resource, &subcompositor_implementation, data,
120                                  subcompositor_destroy_resource_callback);
121 }
122 
123 }  // namespace
124 
BindSubcompositorInterface(wl_display * display)125 void BindSubcompositorInterface(wl_display* display) {
126   wl_global_create(display, &wl_subcompositor_interface, 1, nullptr,
127                    bind_subcompositor);
128 }
129 
130 }  // namespace wayland