Chromium Code Reviews| 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 1913 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2038 void* data, | 2043 void* data, |
| 2039 uint32_t version, | 2044 uint32_t version, |
| 2040 uint32_t id) { | 2045 uint32_t id) { |
| 2041 wl_resource* resource = | 2046 wl_resource* resource = |
| 2042 wl_resource_create(client, &zwp_secure_output_v1_interface, 1, id); | 2047 wl_resource_create(client, &zwp_secure_output_v1_interface, 1, id); |
| 2043 | 2048 |
| 2044 wl_resource_set_implementation(resource, &secure_output_implementation, data, | 2049 wl_resource_set_implementation(resource, &secure_output_implementation, data, |
| 2045 nullptr); | 2050 nullptr); |
| 2046 } | 2051 } |
| 2047 | 2052 |
| 2053 //////////////////////////////////////////////////////////////////////////////// | |
| 2054 // blending_interface: | |
| 2055 | |
| 2056 class Blending : public SurfaceObserver { | |
|
Daniele Castagna
2016/05/09 23:34:19
nit: comment before class declaration (https://goo
reveman
2016/05/10 14:05:19
Done. There are 2 other classed (Viewport, Securit
| |
| 2057 public: | |
| 2058 explicit Blending(Surface* surface) : surface_(surface) { | |
| 2059 surface_->AddSurfaceObserver(this); | |
| 2060 surface_->SetProperty(kSurfaceHasBlendingKey, true); | |
| 2061 } | |
| 2062 ~Blending() override { | |
| 2063 if (surface_) { | |
| 2064 surface_->RemoveSurfaceObserver(this); | |
| 2065 surface_->SetBlendMode(SkXfermode::kSrcOver_Mode); | |
| 2066 surface_->SetAlpha(1.0f); | |
| 2067 surface_->SetProperty(kSurfaceHasBlendingKey, false); | |
| 2068 } | |
| 2069 } | |
| 2070 | |
| 2071 void SetBlendMode(SkXfermode::Mode blend_mode) { | |
| 2072 surface_->SetBlendMode(blend_mode); | |
|
Daniele Castagna
2016/05/09 23:34:20
Why don't you need to check the surface_ in this c
reveman
2016/05/10 14:05:19
Good catch. Fixed in latest patch.
| |
| 2073 } | |
| 2074 | |
| 2075 void SetAlpha(float value) { | |
| 2076 if (surface_) | |
| 2077 surface_->SetAlpha(value); | |
| 2078 } | |
| 2079 | |
| 2080 // Overridden from SurfaceObserver: | |
| 2081 void OnSurfaceDestroying(Surface* surface) override { | |
| 2082 surface->RemoveSurfaceObserver(this); | |
| 2083 surface_ = nullptr; | |
| 2084 } | |
| 2085 | |
| 2086 private: | |
| 2087 Surface* surface_; | |
| 2088 | |
| 2089 DISALLOW_COPY_AND_ASSIGN(Blending); | |
| 2090 }; | |
| 2091 | |
| 2092 void blending_destroy(wl_client* client, wl_resource* resource) { | |
| 2093 wl_resource_destroy(resource); | |
| 2094 } | |
| 2095 | |
| 2096 void blending_set_blending(wl_client* client, | |
| 2097 wl_resource* resource, | |
| 2098 uint32_t equation) { | |
| 2099 switch (equation) { | |
| 2100 case ZWP_BLENDING_V1_BLENDING_EQUATION_NONE: | |
| 2101 GetUserDataAs<Blending>(resource)->SetBlendMode(SkXfermode::kSrc_Mode); | |
| 2102 break; | |
| 2103 case ZWP_BLENDING_V1_BLENDING_EQUATION_PREMULT: | |
| 2104 GetUserDataAs<Blending>(resource)->SetBlendMode( | |
| 2105 SkXfermode::kSrcOver_Mode); | |
| 2106 break; | |
| 2107 case ZWP_BLENDING_V1_BLENDING_EQUATION_COVERAGE: | |
| 2108 NOTIMPLEMENTED(); | |
| 2109 break; | |
| 2110 default: | |
| 2111 DLOG(WARNING) << "Unsupported blending equation: " << equation; | |
|
Daniele Castagna
2016/05/09 23:34:20
If you're asserting with NOTIMPLEMENTED in case of
reveman
2016/05/10 14:05:19
The default case would be incorrect usage by the c
| |
| 2112 break; | |
| 2113 } | |
| 2114 } | |
| 2115 | |
| 2116 void blending_set_alpha(wl_client* client, | |
| 2117 wl_resource* resource, | |
| 2118 wl_fixed_t alpha) { | |
| 2119 GetUserDataAs<Blending>(resource)->SetAlpha(wl_fixed_to_double(alpha)); | |
| 2120 } | |
| 2121 | |
| 2122 const struct zwp_blending_v1_interface blending_implementation = { | |
| 2123 blending_destroy, blending_set_blending, blending_set_alpha}; | |
| 2124 | |
| 2125 //////////////////////////////////////////////////////////////////////////////// | |
| 2126 // alpha_compositing_interface: | |
| 2127 | |
| 2128 void alpha_compositing_destroy(wl_client* client, wl_resource* resource) { | |
| 2129 wl_resource_destroy(resource); | |
| 2130 } | |
| 2131 | |
| 2132 void alpha_compositing_get_blending(wl_client* client, | |
| 2133 wl_resource* resource, | |
| 2134 uint32_t id, | |
| 2135 wl_resource* surface_resource) { | |
| 2136 Surface* surface = GetUserDataAs<Surface>(surface_resource); | |
| 2137 if (surface->GetProperty(kSurfaceHasBlendingKey)) { | |
| 2138 wl_resource_post_error(resource, | |
| 2139 ZWP_ALPHA_COMPOSITING_V1_ERROR_BLENDING_EXISTS, | |
| 2140 "a blending object for that surface already exists"); | |
| 2141 return; | |
| 2142 } | |
| 2143 | |
| 2144 wl_resource* blending_resource = | |
| 2145 wl_resource_create(client, &zwp_blending_v1_interface, 1, id); | |
| 2146 | |
| 2147 SetImplementation(blending_resource, &blending_implementation, | |
| 2148 base::WrapUnique(new Blending(surface))); | |
| 2149 } | |
| 2150 | |
| 2151 const struct zwp_alpha_compositing_v1_interface | |
| 2152 alpha_compositing_implementation = {alpha_compositing_destroy, | |
| 2153 alpha_compositing_get_blending}; | |
| 2154 | |
| 2155 void bind_alpha_compositing(wl_client* client, | |
| 2156 void* data, | |
| 2157 uint32_t version, | |
| 2158 uint32_t id) { | |
| 2159 wl_resource* resource = | |
| 2160 wl_resource_create(client, &zwp_alpha_compositing_v1_interface, 1, id); | |
| 2161 | |
| 2162 wl_resource_set_implementation(resource, &alpha_compositing_implementation, | |
| 2163 data, nullptr); | |
| 2164 } | |
| 2165 | |
| 2048 } // namespace | 2166 } // namespace |
| 2049 | 2167 |
| 2050 //////////////////////////////////////////////////////////////////////////////// | 2168 //////////////////////////////////////////////////////////////////////////////// |
| 2051 // Server, public: | 2169 // Server, public: |
| 2052 | 2170 |
| 2053 Server::Server(Display* display) | 2171 Server::Server(Display* display) |
| 2054 : display_(display), wl_display_(wl_display_create()) { | 2172 : display_(display), wl_display_(wl_display_create()) { |
| 2055 wl_global_create(wl_display_.get(), &wl_compositor_interface, | 2173 wl_global_create(wl_display_.get(), &wl_compositor_interface, |
| 2056 compositor_version, display_, bind_compositor); | 2174 compositor_version, display_, bind_compositor); |
| 2057 wl_global_create(wl_display_.get(), &wl_shm_interface, 1, display_, bind_shm); | 2175 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_, | 2188 wl_global_create(wl_display_.get(), &xdg_shell_interface, 1, display_, |
| 2071 bind_xdg_shell); | 2189 bind_xdg_shell); |
| 2072 wl_global_create(wl_display_.get(), &wl_data_device_manager_interface, 1, | 2190 wl_global_create(wl_display_.get(), &wl_data_device_manager_interface, 1, |
| 2073 display_, bind_data_device_manager); | 2191 display_, bind_data_device_manager); |
| 2074 wl_global_create(wl_display_.get(), &wl_seat_interface, seat_version, | 2192 wl_global_create(wl_display_.get(), &wl_seat_interface, seat_version, |
| 2075 display_, bind_seat); | 2193 display_, bind_seat); |
| 2076 wl_global_create(wl_display_.get(), &wl_scaler_interface, scaler_version, | 2194 wl_global_create(wl_display_.get(), &wl_scaler_interface, scaler_version, |
| 2077 display_, bind_scaler); | 2195 display_, bind_scaler); |
| 2078 wl_global_create(wl_display_.get(), &zwp_secure_output_v1_interface, 1, | 2196 wl_global_create(wl_display_.get(), &zwp_secure_output_v1_interface, 1, |
| 2079 display_, bind_secure_output); | 2197 display_, bind_secure_output); |
| 2198 wl_global_create(wl_display_.get(), &zwp_alpha_compositing_v1_interface, 1, | |
| 2199 display_, bind_alpha_compositing); | |
| 2080 } | 2200 } |
| 2081 | 2201 |
| 2082 Server::~Server() {} | 2202 Server::~Server() {} |
| 2083 | 2203 |
| 2084 // static | 2204 // static |
| 2085 std::unique_ptr<Server> Server::Create(Display* display) { | 2205 std::unique_ptr<Server> Server::Create(Display* display) { |
| 2086 std::unique_ptr<Server> server(new Server(display)); | 2206 std::unique_ptr<Server> server(new Server(display)); |
| 2087 | 2207 |
| 2088 char* runtime_dir = getenv("XDG_RUNTIME_DIR"); | 2208 char* runtime_dir = getenv("XDG_RUNTIME_DIR"); |
| 2089 if (!runtime_dir) { | 2209 if (!runtime_dir) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2141 DCHECK(event_loop); | 2261 DCHECK(event_loop); |
| 2142 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); | 2262 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); |
| 2143 } | 2263 } |
| 2144 | 2264 |
| 2145 void Server::Flush() { | 2265 void Server::Flush() { |
| 2146 wl_display_flush_clients(wl_display_.get()); | 2266 wl_display_flush_clients(wl_display_.get()); |
| 2147 } | 2267 } |
| 2148 | 2268 |
| 2149 } // namespace wayland | 2269 } // namespace wayland |
| 2150 } // namespace exo | 2270 } // namespace exo |
| OLD | NEW |