OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef UI_WAYLAND_WAYLAND_MESSAGE_PUMP_H_ |
| 6 #define UI_WAYLAND_WAYLAND_MESSAGE_PUMP_H_ |
| 7 |
| 8 #include <glib.h> |
| 9 #include <stdint.h> |
| 10 |
| 11 #include "base/basictypes.h" |
| 12 |
| 13 namespace ui { |
| 14 |
| 15 class WaylandDisplay; |
| 16 |
| 17 // The message pump handles Wayland specific event delivery. This message |
| 18 // pump uses the default glib context, so running a glib main loop with the |
| 19 // default context will allow looping through Wayland events. |
| 20 class WaylandMessagePump { |
| 21 public: |
| 22 explicit WaylandMessagePump(WaylandDisplay* display); |
| 23 virtual ~WaylandMessagePump(); |
| 24 |
| 25 protected: |
| 26 // These are used to process the pump callbacks. |
| 27 // HandlePrepare: is called during glib's prepare step and returns a timeout |
| 28 // that will be passed to the poll. |
| 29 // HandleCheck: called after HandlePrepare and returns whether |
| 30 // HandleDispatch should be called. |
| 31 // HandleDispatch:is called after HandleCheck returns true and it will |
| 32 // dispatch a Wayland event. |
| 33 virtual int HandlePrepare(); |
| 34 virtual bool HandleCheck(); |
| 35 virtual void HandleDispatch(); |
| 36 |
| 37 private: |
| 38 struct WorkSource : public GSource { |
| 39 WaylandMessagePump* pump; |
| 40 }; |
| 41 |
| 42 // Actual callbacks for glib. These functions will just call the appropriate |
| 43 // Handle* functions in a WaylandMessagePump object. |
| 44 static gboolean SourcePrepare(GSource* source, gint* timeout); |
| 45 static gboolean SourceCheck(GSource* source); |
| 46 static gboolean SourceDispatch(GSource* source, |
| 47 GSourceFunc callback, |
| 48 gpointer data); |
| 49 // Handles updates to the Wayland mask. This is used to signal when the |
| 50 // compositor is done processing writable events. |
| 51 static int SourceUpdate(uint32_t mask, void* data); |
| 52 |
| 53 WaylandDisplay* display_; |
| 54 WorkSource* source_; |
| 55 GPollFD pfd_; |
| 56 uint32_t mask_; |
| 57 |
| 58 DISALLOW_COPY_AND_ASSIGN(WaylandMessagePump); |
| 59 }; |
| 60 |
| 61 } // namespace ui |
| 62 |
| 63 #endif // UI_WAYLAND_WAYLAND_MESSAGE_PUMP_H_ |
OLD | NEW |