Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(320)

Side by Side Diff: ui/events/platform/x11/x11_event_source.h

Issue 2177823002: X11: Add window cache Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix test compilation Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #ifndef UI_EVENTS_PLATFORM_X11_X11_EVENT_SOURCE_H_ 5 #ifndef UI_EVENTS_PLATFORM_X11_X11_EVENT_SOURCE_H_
6 #define UI_EVENTS_PLATFORM_X11_X11_EVENT_SOURCE_H_ 6 #define UI_EVENTS_PLATFORM_X11_X11_EVENT_SOURCE_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <xcb/xcb.h>
9 10
11 #include <list>
10 #include <memory> 12 #include <memory>
11 13
12 #include "base/macros.h" 14 #include "base/macros.h"
13 #include "ui/events/events_export.h" 15 #include "ui/events/events_export.h"
14 #include "ui/gfx/x/x11_types.h" 16 #include "ui/gfx/x/x11_types.h"
15 17
16 using Time = unsigned long; 18 using Time = unsigned long;
17 using XEvent = union _XEvent; 19 using XEvent = union _XEvent;
18 using XID = unsigned long; 20 using XID = unsigned long;
19 using XWindow = unsigned long; 21 using XWindow = unsigned long;
(...skipping 13 matching lines...) Expand all
33 virtual void ProcessXEvent(XEvent* xevent) = 0; 35 virtual void ProcessXEvent(XEvent* xevent) = 0;
34 36
35 private: 37 private:
36 DISALLOW_COPY_AND_ASSIGN(X11EventSourceDelegate); 38 DISALLOW_COPY_AND_ASSIGN(X11EventSourceDelegate);
37 }; 39 };
38 40
39 // Receives X11 events and sends them to X11EventSourceDelegate. Handles 41 // Receives X11 events and sends them to X11EventSourceDelegate. Handles
40 // receiving, pre-process and post-processing XEvents. 42 // receiving, pre-process and post-processing XEvents.
41 class EVENTS_EXPORT X11EventSource { 43 class EVENTS_EXPORT X11EventSource {
42 public: 44 public:
45 class EVENTS_EXPORT Request {
46 public:
47 ~Request();
48
49 virtual void OnReply(xcb_generic_reply_t* reply,
50 xcb_generic_error_t* error) = 0;
51
52 uint32_t sequence() { return sequence_; }
53
54 protected:
55 Request(uint32_t sequence);
56
57 uint32_t sequence_;
58
59 // State necessary for discarding. Set during
60 // X11EventSource::EnqueueRequest.
61 std::list<std::unique_ptr<Request>>::iterator it_;
62
63 private:
64 friend class X11EventSource;
65 };
66
43 X11EventSource(X11EventSourceDelegate* delegate, XDisplay* display); 67 X11EventSource(X11EventSourceDelegate* delegate, XDisplay* display);
44 ~X11EventSource(); 68 ~X11EventSource();
45 69
46 static bool HasInstance(); 70 static bool HasInstance();
47 71
48 static X11EventSource* GetInstance(); 72 static X11EventSource* GetInstance();
49 73
50 // Called when there is a new XEvent available. Processes all (if any) 74 // Called when there is a new XEvent available. Processes all (if any)
51 // available X events. 75 // available X events.
52 void DispatchXEvents(); 76 void DispatchXEvents();
(...skipping 16 matching lines...) Expand all
69 93
70 void BlockUntilWindowUnmapped(XID window); 94 void BlockUntilWindowUnmapped(XID window);
71 95
72 XDisplay* display() { return display_; } 96 XDisplay* display() { return display_; }
73 97
74 // Returns the timestamp of the event currently being dispatched. Falls back 98 // Returns the timestamp of the event currently being dispatched. Falls back
75 // on GetCurrentServerTime() if there's no event being dispatched, or if the 99 // on GetCurrentServerTime() if there's no event being dispatched, or if the
76 // current event does not have a timestamp. 100 // current event does not have a timestamp.
77 Time GetTimestamp(); 101 Time GetTimestamp();
78 102
103 // Takes ownership of |request|.
104 void EnqueueRequest(Request* request);
105
106 void DiscardRequest(Request* request);
107
79 void StopCurrentEventStream(); 108 void StopCurrentEventStream();
80 void OnDispatcherListChanged(); 109 void OnDispatcherListChanged();
81 110
82 protected: 111 protected:
83 // Extracts cookie data from |xevent| if it's of GenericType, and dispatches 112 // Extracts cookie data from |xevent| if it's of GenericType, and dispatches
84 // the event. This function also frees up the cookie data after dispatch is 113 // the event. This function also frees up the cookie data after dispatch is
85 // complete. 114 // complete.
86 void ExtractCookieDataDispatchEvent(XEvent* xevent); 115 void ExtractCookieDataDispatchEvent(XEvent* xevent);
87 116
88 // Handles updates after event has been dispatched. 117 // Handles updates after event has been dispatched.
89 void PostDispatchEvent(XEvent* xevent); 118 void PostDispatchEvent(XEvent* xevent);
90 119
91 // Block until receiving a structure notify event of |type| on |window|. 120 // Block until receiving a structure notify event of |type| on |window|.
92 // Dispatch all encountered events prior to the one we're blocking on. 121 // Dispatch all encountered events prior to the one we're blocking on.
93 void BlockOnWindowStructureEvent(XID window, int type); 122 void BlockOnWindowStructureEvent(XID window, int type);
94 123
95 // Explicitly asks the X11 server for the current timestamp, and updates 124 // Explicitly asks the X11 server for the current timestamp, and updates
96 // |last_seen_server_time_| with this value. 125 // |last_seen_server_time_| with this value.
97 Time GetCurrentServerTime(); 126 Time GetCurrentServerTime();
98 127
128 bool HasNextReply();
129 bool HasNextEvent();
130 uint32_t NextReplySequence();
131 uint32_t NextEventSequence();
132 void ProcessNextReply();
133 void ProcessNextEvent();
134
99 private: 135 private:
136 friend class TestX11EventSource;
100 static X11EventSource* instance_; 137 static X11EventSource* instance_;
101 138
102 X11EventSourceDelegate* delegate_; 139 X11EventSourceDelegate* delegate_;
103 140
104 // The connection to the X11 server used to receive the events. 141 // The connection to the X11 server used to receive the events.
105 XDisplay* display_; 142 XDisplay* display_;
143 xcb_connection_t* connection_;
106 144
107 // The timestamp of the event being dispatched. 145 // The timestamp of the event being dispatched.
108 Time event_timestamp_; 146 Time event_timestamp_;
109 147
110 // State necessary for UpdateLastSeenServerTime 148 // State necessary for UpdateLastSeenServerTime
111 bool dummy_initialized_; 149 bool dummy_initialized_;
112 XWindow dummy_window_; 150 XWindow dummy_window_;
113 XAtom dummy_atom_; 151 XAtom dummy_atom_;
114 152
153 // Outstanding requests that should be serviced.
154 std::list<std::unique_ptr<Request>> request_queue_;
155
156 // For HasNextReply();
157 void* next_reply_;
158 xcb_generic_error_t* next_error_;
159
115 // Keeps track of whether this source should continue to dispatch all the 160 // Keeps track of whether this source should continue to dispatch all the
116 // available events. 161 // available events.
117 bool continue_stream_ = true; 162 bool continue_stream_ = true;
118 163
119 std::unique_ptr<X11HotplugEventHandler> hotplug_event_handler_; 164 std::unique_ptr<X11HotplugEventHandler> hotplug_event_handler_;
120 165
121 DISALLOW_COPY_AND_ASSIGN(X11EventSource); 166 DISALLOW_COPY_AND_ASSIGN(X11EventSource);
122 }; 167 };
123 168
124 } // namespace ui 169 } // namespace ui
125 170
126 #endif // UI_EVENTS_PLATFORM_X11_X11_EVENT_SOURCE_H_ 171 #endif // UI_EVENTS_PLATFORM_X11_X11_EVENT_SOURCE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698