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 <alpha-compositing-unstable-v1-server-protocol.h> |
7 #include <grp.h> | 8 #include <grp.h> |
8 #include <linux/input.h> | 9 #include <linux/input.h> |
9 #include <scaler-server-protocol.h> | 10 #include <scaler-server-protocol.h> |
10 #include <secure-output-unstable-v1-server-protocol.h> | 11 #include <secure-output-unstable-v1-server-protocol.h> |
11 #include <stddef.h> | 12 #include <stddef.h> |
12 #include <stdint.h> | 13 #include <stdint.h> |
13 #include <wayland-server-core.h> | 14 #include <wayland-server-core.h> |
14 #include <wayland-server-protocol-core.h> | 15 #include <wayland-server-protocol-core.h> |
15 #include <xdg-shell-unstable-v5-server-protocol.h> | 16 #include <xdg-shell-unstable-v5-server-protocol.h> |
16 | 17 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 DEFINE_WINDOW_PROPERTY_KEY(wl_resource*, kSurfaceResourceKey, nullptr); | 106 DEFINE_WINDOW_PROPERTY_KEY(wl_resource*, kSurfaceResourceKey, nullptr); |
106 | 107 |
107 // A property key containing a boolean set to true if a viewport is associated | 108 // A property key containing a boolean set to true if a viewport is associated |
108 // with window. | 109 // with window. |
109 DEFINE_WINDOW_PROPERTY_KEY(bool, kSurfaceHasViewportKey, false); | 110 DEFINE_WINDOW_PROPERTY_KEY(bool, kSurfaceHasViewportKey, false); |
110 | 111 |
111 // A property key containing a boolean set to true if a security object is | 112 // A property key containing a boolean set to true if a security object is |
112 // associated with window. | 113 // associated with window. |
113 DEFINE_WINDOW_PROPERTY_KEY(bool, kSurfaceHasSecurityKey, false); | 114 DEFINE_WINDOW_PROPERTY_KEY(bool, kSurfaceHasSecurityKey, false); |
114 | 115 |
| 116 // A property key containing a boolean set to true if a blending object is |
| 117 // associated with window. |
| 118 DEFINE_WINDOW_PROPERTY_KEY(bool, kSurfaceHasBlendingKey, false); |
| 119 |
115 //////////////////////////////////////////////////////////////////////////////// | 120 //////////////////////////////////////////////////////////////////////////////// |
116 // wl_buffer_interface: | 121 // wl_buffer_interface: |
117 | 122 |
118 void buffer_destroy(wl_client* client, wl_resource* resource) { | 123 void buffer_destroy(wl_client* client, wl_resource* resource) { |
119 wl_resource_destroy(resource); | 124 wl_resource_destroy(resource); |
120 } | 125 } |
121 | 126 |
122 const struct wl_buffer_interface buffer_implementation = {buffer_destroy}; | 127 const struct wl_buffer_interface buffer_implementation = {buffer_destroy}; |
123 | 128 |
124 void HandleBufferReleaseCallback(wl_resource* resource) { | 129 void HandleBufferReleaseCallback(wl_resource* resource) { |
(...skipping 1712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1837 uint32_t capabilities = WL_SEAT_CAPABILITY_POINTER | WL_SEAT_CAPABILITY_TOUCH; | 1842 uint32_t capabilities = WL_SEAT_CAPABILITY_POINTER | WL_SEAT_CAPABILITY_TOUCH; |
1838 #if defined(USE_XKBCOMMON) | 1843 #if defined(USE_XKBCOMMON) |
1839 capabilities |= WL_SEAT_CAPABILITY_KEYBOARD; | 1844 capabilities |= WL_SEAT_CAPABILITY_KEYBOARD; |
1840 #endif | 1845 #endif |
1841 wl_seat_send_capabilities(resource, capabilities); | 1846 wl_seat_send_capabilities(resource, capabilities); |
1842 } | 1847 } |
1843 | 1848 |
1844 //////////////////////////////////////////////////////////////////////////////// | 1849 //////////////////////////////////////////////////////////////////////////////// |
1845 // wl_viewport_interface: | 1850 // wl_viewport_interface: |
1846 | 1851 |
| 1852 // Implements the viewport interface to a Surface. The "viewport"-state is set |
| 1853 // to null upon destruction. A window property will be set during the lifetime |
| 1854 // of this class to prevent multiple instances from being created for the same |
| 1855 // Surface. |
1847 class Viewport : public SurfaceObserver { | 1856 class Viewport : public SurfaceObserver { |
1848 public: | 1857 public: |
1849 explicit Viewport(Surface* surface) : surface_(surface) { | 1858 explicit Viewport(Surface* surface) : surface_(surface) { |
1850 surface_->AddSurfaceObserver(this); | 1859 surface_->AddSurfaceObserver(this); |
1851 surface_->SetProperty(kSurfaceHasViewportKey, true); | 1860 surface_->SetProperty(kSurfaceHasViewportKey, true); |
1852 } | 1861 } |
1853 ~Viewport() override { | 1862 ~Viewport() override { |
1854 if (surface_) { | 1863 if (surface_) { |
1855 surface_->RemoveSurfaceObserver(this); | 1864 surface_->RemoveSurfaceObserver(this); |
1856 surface_->SetViewport(gfx::Size()); | 1865 surface_->SetViewport(gfx::Size()); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1956 wl_resource* resource = wl_resource_create( | 1965 wl_resource* resource = wl_resource_create( |
1957 client, &wl_scaler_interface, std::min(version, scaler_version), id); | 1966 client, &wl_scaler_interface, std::min(version, scaler_version), id); |
1958 | 1967 |
1959 wl_resource_set_implementation(resource, &scaler_implementation, data, | 1968 wl_resource_set_implementation(resource, &scaler_implementation, data, |
1960 nullptr); | 1969 nullptr); |
1961 } | 1970 } |
1962 | 1971 |
1963 //////////////////////////////////////////////////////////////////////////////// | 1972 //////////////////////////////////////////////////////////////////////////////// |
1964 // security_interface: | 1973 // security_interface: |
1965 | 1974 |
| 1975 // Implements the security interface to a Surface. The "only visible on secure |
| 1976 // output"-state is set to false upon destruction. A window property will be set |
| 1977 // during the lifetime of this class to prevent multiple instances from being |
| 1978 // created for the same Surface. |
1966 class Security : public SurfaceObserver { | 1979 class Security : public SurfaceObserver { |
1967 public: | 1980 public: |
1968 explicit Security(Surface* surface) : surface_(surface) { | 1981 explicit Security(Surface* surface) : surface_(surface) { |
1969 surface_->AddSurfaceObserver(this); | 1982 surface_->AddSurfaceObserver(this); |
1970 surface_->SetProperty(kSurfaceHasSecurityKey, true); | 1983 surface_->SetProperty(kSurfaceHasSecurityKey, true); |
1971 } | 1984 } |
1972 ~Security() override { | 1985 ~Security() override { |
1973 if (surface_) { | 1986 if (surface_) { |
1974 surface_->RemoveSurfaceObserver(this); | 1987 surface_->RemoveSurfaceObserver(this); |
1975 surface_->SetOnlyVisibleOnSecureOutput(false); | 1988 surface_->SetOnlyVisibleOnSecureOutput(false); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2038 void* data, | 2051 void* data, |
2039 uint32_t version, | 2052 uint32_t version, |
2040 uint32_t id) { | 2053 uint32_t id) { |
2041 wl_resource* resource = | 2054 wl_resource* resource = |
2042 wl_resource_create(client, &zwp_secure_output_v1_interface, 1, id); | 2055 wl_resource_create(client, &zwp_secure_output_v1_interface, 1, id); |
2043 | 2056 |
2044 wl_resource_set_implementation(resource, &secure_output_implementation, data, | 2057 wl_resource_set_implementation(resource, &secure_output_implementation, data, |
2045 nullptr); | 2058 nullptr); |
2046 } | 2059 } |
2047 | 2060 |
| 2061 //////////////////////////////////////////////////////////////////////////////// |
| 2062 // blending_interface: |
| 2063 |
| 2064 // Implements the blending interface to a Surface. The "blend mode" and |
| 2065 // "alpha"-state is set to SrcOver and 1 upon destruction. A window property |
| 2066 // will be set during the lifetime of this class to prevent multiple instances |
| 2067 // from being created for the same Surface. |
| 2068 class Blending : public SurfaceObserver { |
| 2069 public: |
| 2070 explicit Blending(Surface* surface) : surface_(surface) { |
| 2071 surface_->AddSurfaceObserver(this); |
| 2072 surface_->SetProperty(kSurfaceHasBlendingKey, true); |
| 2073 } |
| 2074 ~Blending() override { |
| 2075 if (surface_) { |
| 2076 surface_->RemoveSurfaceObserver(this); |
| 2077 surface_->SetBlendMode(SkXfermode::kSrcOver_Mode); |
| 2078 surface_->SetAlpha(1.0f); |
| 2079 surface_->SetProperty(kSurfaceHasBlendingKey, false); |
| 2080 } |
| 2081 } |
| 2082 |
| 2083 void SetBlendMode(SkXfermode::Mode blend_mode) { |
| 2084 if (surface_) |
| 2085 surface_->SetBlendMode(blend_mode); |
| 2086 } |
| 2087 |
| 2088 void SetAlpha(float value) { |
| 2089 if (surface_) |
| 2090 surface_->SetAlpha(value); |
| 2091 } |
| 2092 |
| 2093 // Overridden from SurfaceObserver: |
| 2094 void OnSurfaceDestroying(Surface* surface) override { |
| 2095 surface->RemoveSurfaceObserver(this); |
| 2096 surface_ = nullptr; |
| 2097 } |
| 2098 |
| 2099 private: |
| 2100 Surface* surface_; |
| 2101 |
| 2102 DISALLOW_COPY_AND_ASSIGN(Blending); |
| 2103 }; |
| 2104 |
| 2105 void blending_destroy(wl_client* client, wl_resource* resource) { |
| 2106 wl_resource_destroy(resource); |
| 2107 } |
| 2108 |
| 2109 void blending_set_blending(wl_client* client, |
| 2110 wl_resource* resource, |
| 2111 uint32_t equation) { |
| 2112 switch (equation) { |
| 2113 case ZWP_BLENDING_V1_BLENDING_EQUATION_NONE: |
| 2114 GetUserDataAs<Blending>(resource)->SetBlendMode(SkXfermode::kSrc_Mode); |
| 2115 break; |
| 2116 case ZWP_BLENDING_V1_BLENDING_EQUATION_PREMULT: |
| 2117 GetUserDataAs<Blending>(resource)->SetBlendMode( |
| 2118 SkXfermode::kSrcOver_Mode); |
| 2119 break; |
| 2120 case ZWP_BLENDING_V1_BLENDING_EQUATION_COVERAGE: |
| 2121 NOTIMPLEMENTED(); |
| 2122 break; |
| 2123 default: |
| 2124 DLOG(WARNING) << "Unsupported blending equation: " << equation; |
| 2125 break; |
| 2126 } |
| 2127 } |
| 2128 |
| 2129 void blending_set_alpha(wl_client* client, |
| 2130 wl_resource* resource, |
| 2131 wl_fixed_t alpha) { |
| 2132 GetUserDataAs<Blending>(resource)->SetAlpha(wl_fixed_to_double(alpha)); |
| 2133 } |
| 2134 |
| 2135 const struct zwp_blending_v1_interface blending_implementation = { |
| 2136 blending_destroy, blending_set_blending, blending_set_alpha}; |
| 2137 |
| 2138 //////////////////////////////////////////////////////////////////////////////// |
| 2139 // alpha_compositing_interface: |
| 2140 |
| 2141 void alpha_compositing_destroy(wl_client* client, wl_resource* resource) { |
| 2142 wl_resource_destroy(resource); |
| 2143 } |
| 2144 |
| 2145 void alpha_compositing_get_blending(wl_client* client, |
| 2146 wl_resource* resource, |
| 2147 uint32_t id, |
| 2148 wl_resource* surface_resource) { |
| 2149 Surface* surface = GetUserDataAs<Surface>(surface_resource); |
| 2150 if (surface->GetProperty(kSurfaceHasBlendingKey)) { |
| 2151 wl_resource_post_error(resource, |
| 2152 ZWP_ALPHA_COMPOSITING_V1_ERROR_BLENDING_EXISTS, |
| 2153 "a blending object for that surface already exists"); |
| 2154 return; |
| 2155 } |
| 2156 |
| 2157 wl_resource* blending_resource = |
| 2158 wl_resource_create(client, &zwp_blending_v1_interface, 1, id); |
| 2159 |
| 2160 SetImplementation(blending_resource, &blending_implementation, |
| 2161 base::WrapUnique(new Blending(surface))); |
| 2162 } |
| 2163 |
| 2164 const struct zwp_alpha_compositing_v1_interface |
| 2165 alpha_compositing_implementation = {alpha_compositing_destroy, |
| 2166 alpha_compositing_get_blending}; |
| 2167 |
| 2168 void bind_alpha_compositing(wl_client* client, |
| 2169 void* data, |
| 2170 uint32_t version, |
| 2171 uint32_t id) { |
| 2172 wl_resource* resource = |
| 2173 wl_resource_create(client, &zwp_alpha_compositing_v1_interface, 1, id); |
| 2174 |
| 2175 wl_resource_set_implementation(resource, &alpha_compositing_implementation, |
| 2176 data, nullptr); |
| 2177 } |
| 2178 |
2048 } // namespace | 2179 } // namespace |
2049 | 2180 |
2050 //////////////////////////////////////////////////////////////////////////////// | 2181 //////////////////////////////////////////////////////////////////////////////// |
2051 // Server, public: | 2182 // Server, public: |
2052 | 2183 |
2053 Server::Server(Display* display) | 2184 Server::Server(Display* display) |
2054 : display_(display), wl_display_(wl_display_create()) { | 2185 : display_(display), wl_display_(wl_display_create()) { |
2055 wl_global_create(wl_display_.get(), &wl_compositor_interface, | 2186 wl_global_create(wl_display_.get(), &wl_compositor_interface, |
2056 compositor_version, display_, bind_compositor); | 2187 compositor_version, display_, bind_compositor); |
2057 wl_global_create(wl_display_.get(), &wl_shm_interface, 1, display_, bind_shm); | 2188 wl_global_create(wl_display_.get(), &wl_shm_interface, 1, display_, bind_shm); |
(...skipping 12 matching lines...) Expand all Loading... |
2070 wl_global_create(wl_display_.get(), &xdg_shell_interface, 1, display_, | 2201 wl_global_create(wl_display_.get(), &xdg_shell_interface, 1, display_, |
2071 bind_xdg_shell); | 2202 bind_xdg_shell); |
2072 wl_global_create(wl_display_.get(), &wl_data_device_manager_interface, 1, | 2203 wl_global_create(wl_display_.get(), &wl_data_device_manager_interface, 1, |
2073 display_, bind_data_device_manager); | 2204 display_, bind_data_device_manager); |
2074 wl_global_create(wl_display_.get(), &wl_seat_interface, seat_version, | 2205 wl_global_create(wl_display_.get(), &wl_seat_interface, seat_version, |
2075 display_, bind_seat); | 2206 display_, bind_seat); |
2076 wl_global_create(wl_display_.get(), &wl_scaler_interface, scaler_version, | 2207 wl_global_create(wl_display_.get(), &wl_scaler_interface, scaler_version, |
2077 display_, bind_scaler); | 2208 display_, bind_scaler); |
2078 wl_global_create(wl_display_.get(), &zwp_secure_output_v1_interface, 1, | 2209 wl_global_create(wl_display_.get(), &zwp_secure_output_v1_interface, 1, |
2079 display_, bind_secure_output); | 2210 display_, bind_secure_output); |
| 2211 wl_global_create(wl_display_.get(), &zwp_alpha_compositing_v1_interface, 1, |
| 2212 display_, bind_alpha_compositing); |
2080 } | 2213 } |
2081 | 2214 |
2082 Server::~Server() {} | 2215 Server::~Server() {} |
2083 | 2216 |
2084 // static | 2217 // static |
2085 std::unique_ptr<Server> Server::Create(Display* display) { | 2218 std::unique_ptr<Server> Server::Create(Display* display) { |
2086 std::unique_ptr<Server> server(new Server(display)); | 2219 std::unique_ptr<Server> server(new Server(display)); |
2087 | 2220 |
2088 char* runtime_dir = getenv("XDG_RUNTIME_DIR"); | 2221 char* runtime_dir = getenv("XDG_RUNTIME_DIR"); |
2089 if (!runtime_dir) { | 2222 if (!runtime_dir) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2141 DCHECK(event_loop); | 2274 DCHECK(event_loop); |
2142 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); | 2275 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); |
2143 } | 2276 } |
2144 | 2277 |
2145 void Server::Flush() { | 2278 void Server::Flush() { |
2146 wl_display_flush_clients(wl_display_.get()); | 2279 wl_display_flush_clients(wl_display_.get()); |
2147 } | 2280 } |
2148 | 2281 |
2149 } // namespace wayland | 2282 } // namespace wayland |
2150 } // namespace exo | 2283 } // namespace exo |
OLD | NEW |