| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 // Implementation of a client that produces output in the form of RGBA | 5 // Implementation of a client that produces output in the form of RGBA |
| 6 // buffers when receiving pointer/touch events. RGB contains the lower | 6 // buffers when receiving pointer/touch events. RGB contains the lower |
| 7 // 24 bits of the event timestamp and A is 0xff. | 7 // 24 bits of the event timestamp and A is 0xff. |
| 8 | 8 |
| 9 #include <wayland-client-core.h> | 9 #include <wayland-client-core.h> |
| 10 #include <wayland-client-protocol.h> | 10 #include <wayland-client-protocol.h> |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 DEFAULT_DELETER(wl_shm, wl_shm_destroy) | 27 DEFAULT_DELETER(wl_shm, wl_shm_destroy) |
| 28 DEFAULT_DELETER(wl_shm_pool, wl_shm_pool_destroy) | 28 DEFAULT_DELETER(wl_shm_pool, wl_shm_pool_destroy) |
| 29 DEFAULT_DELETER(wl_buffer, wl_buffer_destroy) | 29 DEFAULT_DELETER(wl_buffer, wl_buffer_destroy) |
| 30 DEFAULT_DELETER(wl_surface, wl_surface_destroy) | 30 DEFAULT_DELETER(wl_surface, wl_surface_destroy) |
| 31 DEFAULT_DELETER(wl_region, wl_region_destroy) | 31 DEFAULT_DELETER(wl_region, wl_region_destroy) |
| 32 DEFAULT_DELETER(wl_shell, wl_shell_destroy) | 32 DEFAULT_DELETER(wl_shell, wl_shell_destroy) |
| 33 DEFAULT_DELETER(wl_shell_surface, wl_shell_surface_destroy) | 33 DEFAULT_DELETER(wl_shell_surface, wl_shell_surface_destroy) |
| 34 DEFAULT_DELETER(wl_seat, wl_seat_destroy) | 34 DEFAULT_DELETER(wl_seat, wl_seat_destroy) |
| 35 DEFAULT_DELETER(wl_pointer, wl_pointer_destroy) | 35 DEFAULT_DELETER(wl_pointer, wl_pointer_destroy) |
| 36 DEFAULT_DELETER(wl_touch, wl_touch_destroy) | 36 DEFAULT_DELETER(wl_touch, wl_touch_destroy) |
| 37 DEFAULT_DELETER(wl_callback, wl_callback_destroy) |
| 37 | 38 |
| 38 namespace exo { | 39 namespace exo { |
| 39 namespace wayland { | 40 namespace wayland { |
| 40 namespace clients { | 41 namespace clients { |
| 41 namespace { | 42 namespace { |
| 42 | 43 |
| 43 // Window size. | 44 // Window size. |
| 44 const size_t kWidth = 256; | 45 const size_t kWidth = 256; |
| 45 const size_t kHeight = 256; | 46 const size_t kHeight = 256; |
| 46 | 47 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 void BufferRelease(void* data, wl_buffer* buffer) { | 99 void BufferRelease(void* data, wl_buffer* buffer) { |
| 99 BufferState* state = static_cast<BufferState*>(data); | 100 BufferState* state = static_cast<BufferState*>(data); |
| 100 | 101 |
| 101 state->busy = false; | 102 state->busy = false; |
| 102 } | 103 } |
| 103 | 104 |
| 104 struct MainLoopContext { | 105 struct MainLoopContext { |
| 105 uint32_t color = 0xffffffff; | 106 uint32_t color = 0xffffffff; |
| 106 bool needs_redraw = true; | 107 bool needs_redraw = true; |
| 107 bool shutdown = false; | 108 bool shutdown = false; |
| 109 bool throttled = false; |
| 108 }; | 110 }; |
| 109 | 111 |
| 110 void PointerEnter(void* data, | 112 void PointerEnter(void* data, |
| 111 wl_pointer* pointer, | 113 wl_pointer* pointer, |
| 112 uint32_t serial, | 114 uint32_t serial, |
| 113 wl_surface* surface, | 115 wl_surface* surface, |
| 114 wl_fixed_t x, | 116 wl_fixed_t x, |
| 115 wl_fixed_t y) {} | 117 wl_fixed_t y) {} |
| 116 | 118 |
| 117 void PointerLeave(void* data, | 119 void PointerLeave(void* data, |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 MainLoopContext* context = static_cast<MainLoopContext*>(data); | 190 MainLoopContext* context = static_cast<MainLoopContext*>(data); |
| 189 | 191 |
| 190 context->color = 0xff000000 | time; | 192 context->color = 0xff000000 | time; |
| 191 context->needs_redraw = true; | 193 context->needs_redraw = true; |
| 192 } | 194 } |
| 193 | 195 |
| 194 void TouchFrame(void* data, wl_touch* touch) {} | 196 void TouchFrame(void* data, wl_touch* touch) {} |
| 195 | 197 |
| 196 void TouchCancel(void* data, wl_touch* touch) {} | 198 void TouchCancel(void* data, wl_touch* touch) {} |
| 197 | 199 |
| 200 void FrameCallback(void* data, wl_callback* callback, uint32_t time) { |
| 201 MainLoopContext* context = static_cast<MainLoopContext*>(data); |
| 202 |
| 203 context->throttled = false; |
| 204 } |
| 205 |
| 198 } // namespace | 206 } // namespace |
| 199 | 207 |
| 200 int MotionEventsMain() { | 208 int MotionEventsMain() { |
| 201 std::unique_ptr<wl_display> display(wl_display_connect(nullptr)); | 209 std::unique_ptr<wl_display> display(wl_display_connect(nullptr)); |
| 202 if (!display) { | 210 if (!display) { |
| 203 LOG(ERROR) << "wl_display_connect failed"; | 211 LOG(ERROR) << "wl_display_connect failed"; |
| 204 return 1; | 212 return 1; |
| 205 } | 213 } |
| 206 | 214 |
| 207 wl_registry_listener registry_listener = {RegistryHandler, RegistryRemover}; | 215 wl_registry_listener registry_listener = {RegistryHandler, RegistryRemover}; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 static_cast<wl_touch*>(wl_seat_get_touch(globals.seat.get()))); | 306 static_cast<wl_touch*>(wl_seat_get_touch(globals.seat.get()))); |
| 299 if (!touch) { | 307 if (!touch) { |
| 300 LOG(ERROR) << "Can't get touch"; | 308 LOG(ERROR) << "Can't get touch"; |
| 301 return 1; | 309 return 1; |
| 302 } | 310 } |
| 303 | 311 |
| 304 wl_touch_listener touch_listener = {TouchDown, TouchUp, TouchMotion, | 312 wl_touch_listener touch_listener = {TouchDown, TouchUp, TouchMotion, |
| 305 TouchFrame, TouchCancel}; | 313 TouchFrame, TouchCancel}; |
| 306 wl_touch_add_listener(touch.get(), &touch_listener, &context); | 314 wl_touch_add_listener(touch.get(), &touch_listener, &context); |
| 307 | 315 |
| 316 std::unique_ptr<wl_callback> frame_callback; |
| 317 wl_callback_listener frame_listener = {FrameCallback}; |
| 318 |
| 308 do { | 319 do { |
| 309 if (context.shutdown) | 320 if (context.shutdown) |
| 310 break; | 321 break; |
| 311 | 322 |
| 312 if (!context.needs_redraw) | 323 if (!context.needs_redraw) |
| 313 continue; | 324 continue; |
| 314 | 325 |
| 326 if (context.throttled) |
| 327 continue; |
| 328 |
| 315 BufferState* buffer = | 329 BufferState* buffer = |
| 316 std::find_if(std::begin(buffers), std::end(buffers), | 330 std::find_if(std::begin(buffers), std::end(buffers), |
| 317 [](const BufferState& buffer) { return !buffer.busy; }); | 331 [](const BufferState& buffer) { return !buffer.busy; }); |
| 318 if (buffer == std::end(buffers)) | 332 if (buffer == std::end(buffers)) |
| 319 continue; | 333 continue; |
| 320 | 334 |
| 321 context.needs_redraw = false; | 335 context.needs_redraw = false; |
| 322 | 336 |
| 323 static_assert(sizeof(uint32_t) == kBytesPerPixel, | 337 static_assert(sizeof(uint32_t) == kBytesPerPixel, |
| 324 "uint32_t must be same size as kBytesPerPixel"); | 338 "uint32_t must be same size as kBytesPerPixel"); |
| 325 for (size_t y = 0; y < kHeight; y++) { | 339 for (size_t y = 0; y < kHeight; y++) { |
| 326 uint32_t* pixel = reinterpret_cast<uint32_t*>(buffer->data + y * kStride); | 340 uint32_t* pixel = reinterpret_cast<uint32_t*>(buffer->data + y * kStride); |
| 327 for (size_t x = 0; x < kWidth; x++) | 341 for (size_t x = 0; x < kWidth; x++) |
| 328 *pixel++ = context.color; | 342 *pixel++ = context.color; |
| 329 } | 343 } |
| 330 | 344 |
| 331 wl_surface_attach(surface.get(), buffer->buffer.get(), 0, 0); | 345 wl_surface_attach(surface.get(), buffer->buffer.get(), 0, 0); |
| 332 buffer->busy = true; | 346 buffer->busy = true; |
| 333 | 347 |
| 348 frame_callback.reset(wl_surface_frame(surface.get())); |
| 349 wl_callback_add_listener(frame_callback.get(), &frame_listener, &context); |
| 350 context.throttled = true; |
| 351 |
| 334 wl_surface_commit(surface.get()); | 352 wl_surface_commit(surface.get()); |
| 335 wl_display_flush(display.get()); | 353 wl_display_flush(display.get()); |
| 336 } while (wl_display_dispatch(display.get()) != -1); | 354 } while (wl_display_dispatch(display.get()) != -1); |
| 337 | 355 |
| 338 return 0; | 356 return 0; |
| 339 } | 357 } |
| 340 | 358 |
| 341 } // namespace clients | 359 } // namespace clients |
| 342 } // namespace wayland | 360 } // namespace wayland |
| 343 } // namespace exo | 361 } // namespace exo |
| 344 | 362 |
| 345 int main() { | 363 int main() { |
| 346 return exo::wayland::clients::MotionEventsMain(); | 364 return exo::wayland::clients::MotionEventsMain(); |
| 347 } | 365 } |
| OLD | NEW |