OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/exo/wayland/server.h" | 5 #include "components/exo/wayland/server.h" |
6 | 6 |
7 #include <grp.h> | 7 #include <grp.h> |
8 #include <linux/input.h> | 8 #include <linux/input.h> |
9 #include <stddef.h> | 9 #include <stddef.h> |
10 #include <stdint.h> | 10 #include <stdint.h> |
11 #include <viewporter-server-protocol.h> | 11 #include <viewporter-server-protocol.h> |
12 #include <wayland-server-core.h> | 12 #include <wayland-server-core.h> |
13 #include <wayland-server-protocol-core.h> | 13 #include <wayland-server-protocol-core.h> |
14 | 14 |
15 // Note: core wayland headers need to be included before protocol headers. | 15 // Note: core wayland headers need to be included before protocol headers. |
16 #include <alpha-compositing-unstable-v1-server-protocol.h> // NOLINT | 16 #include <alpha-compositing-unstable-v1-server-protocol.h> // NOLINT |
17 #include <remote-shell-unstable-v1-server-protocol.h> // NOLINT | 17 #include <remote-shell-unstable-v1-server-protocol.h> // NOLINT |
18 #include <scaler-server-protocol.h> // NOLINT | |
19 #include <secure-output-unstable-v1-server-protocol.h> // NOLINT | 18 #include <secure-output-unstable-v1-server-protocol.h> // NOLINT |
20 #include <xdg-shell-unstable-v5-server-protocol.h> // NOLINT | 19 #include <xdg-shell-unstable-v5-server-protocol.h> // NOLINT |
21 | 20 |
22 #include <algorithm> | 21 #include <algorithm> |
23 #include <iterator> | 22 #include <iterator> |
24 #include <string> | 23 #include <string> |
25 #include <utility> | 24 #include <utility> |
26 | 25 |
27 #include "ash/common/shell_window_ids.h" | 26 #include "ash/common/shell_window_ids.h" |
28 #include "ash/display/display_info.h" | 27 #include "ash/display/display_info.h" |
(...skipping 2159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2188 uint32_t version, | 2187 uint32_t version, |
2189 uint32_t id) { | 2188 uint32_t id) { |
2190 wl_resource* resource = | 2189 wl_resource* resource = |
2191 wl_resource_create(client, &wp_viewporter_interface, 1, id); | 2190 wl_resource_create(client, &wp_viewporter_interface, 1, id); |
2192 | 2191 |
2193 wl_resource_set_implementation(resource, &viewporter_implementation, data, | 2192 wl_resource_set_implementation(resource, &viewporter_implementation, data, |
2194 nullptr); | 2193 nullptr); |
2195 } | 2194 } |
2196 | 2195 |
2197 //////////////////////////////////////////////////////////////////////////////// | 2196 //////////////////////////////////////////////////////////////////////////////// |
2198 // wl_viewport_interface: | |
2199 | |
2200 void viewport_destroy_DEPRECATED(wl_client* client, wl_resource* resource) { | |
2201 wl_resource_destroy(resource); | |
2202 } | |
2203 | |
2204 void viewport_set_DEPRECATED(wl_client* client, | |
2205 wl_resource* resource, | |
2206 wl_fixed_t src_x, | |
2207 wl_fixed_t src_y, | |
2208 wl_fixed_t src_width, | |
2209 wl_fixed_t src_height, | |
2210 int32_t dst_width, | |
2211 int32_t dst_height) { | |
2212 NOTIMPLEMENTED(); | |
2213 } | |
2214 | |
2215 void viewport_set_source_DEPRECATED(wl_client* client, | |
2216 wl_resource* resource, | |
2217 wl_fixed_t x, | |
2218 wl_fixed_t y, | |
2219 wl_fixed_t width, | |
2220 wl_fixed_t height) { | |
2221 if (x == wl_fixed_from_int(-1) && y == wl_fixed_from_int(-1) && | |
2222 width == wl_fixed_from_int(-1) && height == wl_fixed_from_int(-1)) { | |
2223 GetUserDataAs<Viewport>(resource)->SetSource(gfx::RectF()); | |
2224 return; | |
2225 } | |
2226 | |
2227 if (x < 0 || y < 0 || width <= 0 || height <= 0) { | |
2228 wl_resource_post_error(resource, WL_VIEWPORT_ERROR_BAD_VALUE, | |
2229 "source rectangle must be non-empty (%dx%d) and" | |
2230 "have positive origin (%d,%d)", | |
2231 width, height, x, y); | |
2232 return; | |
2233 } | |
2234 | |
2235 GetUserDataAs<Viewport>(resource)->SetSource( | |
2236 gfx::RectF(wl_fixed_to_double(x), wl_fixed_to_double(y), | |
2237 wl_fixed_to_double(width), wl_fixed_to_double(height))); | |
2238 } | |
2239 | |
2240 void viewport_set_destination_DEPRECATED(wl_client* client, | |
2241 wl_resource* resource, | |
2242 int32_t width, | |
2243 int32_t height) { | |
2244 if (width == -1 && height == -1) { | |
2245 GetUserDataAs<Viewport>(resource)->SetDestination(gfx::Size()); | |
2246 return; | |
2247 } | |
2248 | |
2249 if (width <= 0 || height <= 0) { | |
2250 wl_resource_post_error(resource, WL_VIEWPORT_ERROR_BAD_VALUE, | |
2251 "destination size must be positive (%dx%d)", width, | |
2252 height); | |
2253 return; | |
2254 } | |
2255 | |
2256 GetUserDataAs<Viewport>(resource)->SetDestination(gfx::Size(width, height)); | |
2257 } | |
2258 | |
2259 const struct wl_viewport_interface viewport_implementation_DEPRECATED = { | |
2260 viewport_destroy_DEPRECATED, viewport_set_DEPRECATED, | |
2261 viewport_set_source_DEPRECATED, viewport_set_destination_DEPRECATED}; | |
2262 | |
2263 //////////////////////////////////////////////////////////////////////////////// | |
2264 // wl_scaler_interface: | |
2265 | |
2266 void scaler_destroy(wl_client* client, wl_resource* resource) { | |
2267 wl_resource_destroy(resource); | |
2268 } | |
2269 | |
2270 void scaler_get_viewport(wl_client* client, | |
2271 wl_resource* resource, | |
2272 uint32_t id, | |
2273 wl_resource* surface_resource) { | |
2274 Surface* surface = GetUserDataAs<Surface>(surface_resource); | |
2275 if (surface->GetProperty(kSurfaceHasViewportKey)) { | |
2276 wl_resource_post_error(resource, WL_SCALER_ERROR_VIEWPORT_EXISTS, | |
2277 "a viewport for that surface already exists"); | |
2278 return; | |
2279 } | |
2280 | |
2281 wl_resource* viewport_resource = wl_resource_create( | |
2282 client, &wl_viewport_interface, wl_resource_get_version(resource), id); | |
2283 | |
2284 SetImplementation(viewport_resource, &viewport_implementation_DEPRECATED, | |
2285 base::WrapUnique(new Viewport(surface))); | |
2286 } | |
2287 | |
2288 const struct wl_scaler_interface scaler_implementation = {scaler_destroy, | |
2289 scaler_get_viewport}; | |
2290 | |
2291 const uint32_t scaler_version = 2; | |
2292 | |
2293 void bind_scaler(wl_client* client, void* data, uint32_t version, uint32_t id) { | |
2294 wl_resource* resource = wl_resource_create( | |
2295 client, &wl_scaler_interface, std::min(version, scaler_version), id); | |
2296 | |
2297 wl_resource_set_implementation(resource, &scaler_implementation, data, | |
2298 nullptr); | |
2299 } | |
2300 | |
2301 //////////////////////////////////////////////////////////////////////////////// | |
2302 // security_interface: | 2197 // security_interface: |
2303 | 2198 |
2304 // Implements the security interface to a Surface. The "only visible on secure | 2199 // Implements the security interface to a Surface. The "only visible on secure |
2305 // output"-state is set to false upon destruction. A window property will be set | 2200 // output"-state is set to false upon destruction. A window property will be set |
2306 // during the lifetime of this class to prevent multiple instances from being | 2201 // during the lifetime of this class to prevent multiple instances from being |
2307 // created for the same Surface. | 2202 // created for the same Surface. |
2308 class Security : public SurfaceObserver { | 2203 class Security : public SurfaceObserver { |
2309 public: | 2204 public: |
2310 explicit Security(Surface* surface) : surface_(surface) { | 2205 explicit Security(Surface* surface) : surface_(surface) { |
2311 surface_->AddSurfaceObserver(this); | 2206 surface_->AddSurfaceObserver(this); |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2528 wl_global_create(wl_display_.get(), &wl_output_interface, output_version, | 2423 wl_global_create(wl_display_.get(), &wl_output_interface, output_version, |
2529 display_, bind_output); | 2424 display_, bind_output); |
2530 wl_global_create(wl_display_.get(), &xdg_shell_interface, 1, display_, | 2425 wl_global_create(wl_display_.get(), &xdg_shell_interface, 1, display_, |
2531 bind_xdg_shell); | 2426 bind_xdg_shell); |
2532 wl_global_create(wl_display_.get(), &wl_data_device_manager_interface, 1, | 2427 wl_global_create(wl_display_.get(), &wl_data_device_manager_interface, 1, |
2533 display_, bind_data_device_manager); | 2428 display_, bind_data_device_manager); |
2534 wl_global_create(wl_display_.get(), &wl_seat_interface, seat_version, | 2429 wl_global_create(wl_display_.get(), &wl_seat_interface, seat_version, |
2535 display_, bind_seat); | 2430 display_, bind_seat); |
2536 wl_global_create(wl_display_.get(), &wp_viewporter_interface, 1, display_, | 2431 wl_global_create(wl_display_.get(), &wp_viewporter_interface, 1, display_, |
2537 bind_viewporter); | 2432 bind_viewporter); |
2538 wl_global_create(wl_display_.get(), &wl_scaler_interface, scaler_version, | |
2539 display_, bind_scaler); | |
2540 wl_global_create(wl_display_.get(), &zwp_secure_output_v1_interface, 1, | 2433 wl_global_create(wl_display_.get(), &zwp_secure_output_v1_interface, 1, |
2541 display_, bind_secure_output); | 2434 display_, bind_secure_output); |
2542 wl_global_create(wl_display_.get(), &zwp_alpha_compositing_v1_interface, 1, | 2435 wl_global_create(wl_display_.get(), &zwp_alpha_compositing_v1_interface, 1, |
2543 display_, bind_alpha_compositing); | 2436 display_, bind_alpha_compositing); |
2544 wl_global_create(wl_display_.get(), &zwp_remote_shell_v1_interface, 1, | 2437 wl_global_create(wl_display_.get(), &zwp_remote_shell_v1_interface, 1, |
2545 display_, bind_remote_shell); | 2438 display_, bind_remote_shell); |
2546 } | 2439 } |
2547 | 2440 |
2548 Server::~Server() {} | 2441 Server::~Server() {} |
2549 | 2442 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2607 DCHECK(event_loop); | 2500 DCHECK(event_loop); |
2608 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); | 2501 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); |
2609 } | 2502 } |
2610 | 2503 |
2611 void Server::Flush() { | 2504 void Server::Flush() { |
2612 wl_display_flush_clients(wl_display_.get()); | 2505 wl_display_flush_clients(wl_display_.get()); |
2613 } | 2506 } |
2614 | 2507 |
2615 } // namespace wayland | 2508 } // namespace wayland |
2616 } // namespace exo | 2509 } // namespace exo |
OLD | NEW |