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

Side by Side Diff: base/message_loop/message_pump_win.h

Issue 1943063002: Version of MessagePumpForUI optimized for GPU (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed CR feedback Created 4 years, 6 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
« no previous file with comments | « base/message_loop/message_loop_unittest.cc ('k') | base/message_loop/message_pump_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 BASE_MESSAGE_LOOP_MESSAGE_PUMP_WIN_H_ 5 #ifndef BASE_MESSAGE_LOOP_MESSAGE_PUMP_WIN_H_
6 #define BASE_MESSAGE_LOOP_MESSAGE_PUMP_WIN_H_ 6 #define BASE_MESSAGE_LOOP_MESSAGE_PUMP_WIN_H_
7 7
8 #include <windows.h> 8 #include <windows.h>
9 9
10 #include <list> 10 #include <list>
11 #include <memory>
11 12
12 #include "base/base_export.h" 13 #include "base/base_export.h"
13 #include "base/message_loop/message_pump.h" 14 #include "base/message_loop/message_pump.h"
14 #include "base/time/time.h" 15 #include "base/time/time.h"
15 #include "base/win/scoped_handle.h" 16 #include "base/win/scoped_handle.h"
16 17
17 namespace base { 18 namespace base {
18 19
19 // MessagePumpWin serves as the base for specialized versions of the MessagePump 20 // MessagePumpWin serves as the base for specialized versions of the MessagePump
20 // for Windows. It provides basic functionality like handling of observers and 21 // for Windows. It provides basic functionality like handling of observers and
21 // controlling the lifetime of the message pump. 22 // controlling the lifetime of the message pump.
22 class BASE_EXPORT MessagePumpWin : public MessagePump { 23 class BASE_EXPORT MessagePumpWin : public MessagePump {
23 public: 24 public:
24 MessagePumpWin() : have_work_(0), state_(NULL) {} 25 MessagePumpWin() : work_state_(READY), state_(NULL) {}
25 26
26 // MessagePump methods: 27 // MessagePump methods:
27 void Run(Delegate* delegate) override; 28 void Run(Delegate* delegate) override;
28 void Quit() override; 29 void Quit() override;
29 30
30 protected: 31 protected:
31 struct RunState { 32 struct RunState {
32 Delegate* delegate; 33 Delegate* delegate;
33 34
34 // Used to flag that the current Run() invocation should return ASAP. 35 // Used to flag that the current Run() invocation should return ASAP.
35 bool should_quit; 36 bool should_quit;
36 37
37 // Used to count how many Run() invocations are on the stack. 38 // Used to count how many Run() invocations are on the stack.
38 int run_depth; 39 int run_depth;
39 40
40 // Used to help diagnose hangs. 41 // Used to help diagnose hangs.
41 // TODO(stanisc): crbug.com/596190: Remove these once the bug is fixed. 42 // TODO(stanisc): crbug.com/596190: Remove these once the bug is fixed.
42 int schedule_work_error_count; 43 int schedule_work_error_count;
43 Time last_schedule_work_error_time; 44 Time last_schedule_work_error_time;
44 }; 45 };
45 46
47 // State used with |work_state_| variable.
48 enum WorkState {
49 READY = 0, // Ready to accept new work.
50 HAVE_WORK = 1, // New work has been signalled.
51 WORKING = 2 // Handling the work.
52 };
53
46 virtual void DoRunLoop() = 0; 54 virtual void DoRunLoop() = 0;
47 int GetCurrentDelay() const; 55 int GetCurrentDelay() const;
48 56
49 // The time at which delayed work should run. 57 // The time at which delayed work should run.
50 TimeTicks delayed_work_time_; 58 TimeTicks delayed_work_time_;
51 59
52 // A boolean value used to indicate if there is a kMsgDoWork message pending 60 // A value used to indicate if there is a kMsgDoWork message pending
53 // in the Windows Message queue. There is at most one such message, and it 61 // in the Windows Message queue. There is at most one such message, and it
54 // can drive execution of tasks when a native message pump is running. 62 // can drive execution of tasks when a native message pump is running.
55 LONG have_work_; 63 LONG work_state_;
56 64
57 // State for the current invocation of Run. 65 // State for the current invocation of Run.
58 RunState* state_; 66 RunState* state_;
59 }; 67 };
60 68
61 //----------------------------------------------------------------------------- 69 //-----------------------------------------------------------------------------
62 // MessagePumpForUI extends MessagePumpWin with methods that are particular to a 70 // MessagePumpForUI extends MessagePumpWin with methods that are particular to a
63 // MessageLoop instantiated with TYPE_UI. 71 // MessageLoop instantiated with TYPE_UI.
64 // 72 //
65 // MessagePumpForUI implements a "traditional" Windows message pump. It contains 73 // MessagePumpForUI implements a "traditional" Windows message pump. It contains
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 // is peeked, and before a replacement kMsgHaveWork is posted). 109 // is peeked, and before a replacement kMsgHaveWork is posted).
102 // 110 //
103 // NOTE: Although it may seem odd that messages are used to start and stop this 111 // NOTE: Although it may seem odd that messages are used to start and stop this
104 // flow (as opposed to signaling objects, etc.), it should be understood that 112 // flow (as opposed to signaling objects, etc.), it should be understood that
105 // the native message pump will *only* respond to messages. As a result, it is 113 // the native message pump will *only* respond to messages. As a result, it is
106 // an excellent choice. It is also helpful that the starter messages that are 114 // an excellent choice. It is also helpful that the starter messages that are
107 // placed in the queue when new task arrive also awakens DoRunLoop. 115 // placed in the queue when new task arrive also awakens DoRunLoop.
108 // 116 //
109 class BASE_EXPORT MessagePumpForUI : public MessagePumpWin { 117 class BASE_EXPORT MessagePumpForUI : public MessagePumpWin {
110 public: 118 public:
111 // The application-defined code passed to the hook procedure.
112 static const int kMessageFilterCode = 0x5001;
113
114 MessagePumpForUI(); 119 MessagePumpForUI();
115 ~MessagePumpForUI() override; 120 ~MessagePumpForUI() override;
116 121
117 // MessagePump methods: 122 // MessagePump methods:
118 void ScheduleWork() override; 123 void ScheduleWork() override;
119 void ScheduleDelayedWork(const TimeTicks& delayed_work_time) override; 124 void ScheduleDelayedWork(const TimeTicks& delayed_work_time) override;
120 125
121 private: 126 private:
122 static LRESULT CALLBACK WndProcThunk(HWND window_handle, 127 static LRESULT CALLBACK WndProcThunk(HWND window_handle,
123 UINT message, 128 UINT message,
(...skipping 10 matching lines...) Expand all
134 bool ProcessPumpReplacementMessage(); 139 bool ProcessPumpReplacementMessage();
135 140
136 // Atom representing the registered window class. 141 // Atom representing the registered window class.
137 ATOM atom_; 142 ATOM atom_;
138 143
139 // A hidden message-only window. 144 // A hidden message-only window.
140 HWND message_hwnd_; 145 HWND message_hwnd_;
141 }; 146 };
142 147
143 //----------------------------------------------------------------------------- 148 //-----------------------------------------------------------------------------
149 // MessagePumpForGpu is a simplified version of UI message pump that is
150 // optimized for the GPU process. Unlike MessagePumpForUI it doesn't have a
151 // hidden window and doesn't handle a situation where a native message pump
152 // might take over message processing.
153 //
154 class BASE_EXPORT MessagePumpForGpu : public MessagePumpWin {
155 public:
156 MessagePumpForGpu();
157 ~MessagePumpForGpu() override;
158
159 // Factory methods.
160 static void InitFactory();
161 static std::unique_ptr<MessagePump> CreateMessagePumpForGpu();
162
163 // MessagePump methods:
164 void ScheduleWork() override;
165 void ScheduleDelayedWork(const TimeTicks& delayed_work_time) override;
166
167 private:
168 // MessagePumpWin methods:
169 void DoRunLoop() override;
170
171 void WaitForWork();
172 bool ProcessNextMessage();
173
174 const HANDLE event_;
175 };
176
177 //-----------------------------------------------------------------------------
144 // MessagePumpForIO extends MessagePumpWin with methods that are particular to a 178 // MessagePumpForIO extends MessagePumpWin with methods that are particular to a
145 // MessageLoop instantiated with TYPE_IO. This version of MessagePump does not 179 // MessageLoop instantiated with TYPE_IO. This version of MessagePump does not
146 // deal with Windows mesagges, and instead has a Run loop based on Completion 180 // deal with Windows mesagges, and instead has a Run loop based on Completion
147 // Ports so it is better suited for IO operations. 181 // Ports so it is better suited for IO operations.
148 // 182 //
149 class BASE_EXPORT MessagePumpForIO : public MessagePumpWin { 183 class BASE_EXPORT MessagePumpForIO : public MessagePumpWin {
150 public: 184 public:
151 struct BASE_EXPORT IOContext { 185 struct BASE_EXPORT IOContext {
152 IOContext(); 186 IOContext();
153 OVERLAPPED overlapped; 187 OVERLAPPED overlapped;
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 // The completion port associated with this thread. 280 // The completion port associated with this thread.
247 win::ScopedHandle port_; 281 win::ScopedHandle port_;
248 // This list will be empty almost always. It stores IO completions that have 282 // This list will be empty almost always. It stores IO completions that have
249 // not been delivered yet because somebody was doing cleanup. 283 // not been delivered yet because somebody was doing cleanup.
250 std::list<IOItem> completed_io_; 284 std::list<IOItem> completed_io_;
251 }; 285 };
252 286
253 } // namespace base 287 } // namespace base
254 288
255 #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_WIN_H_ 289 #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_WIN_H_
OLDNEW
« no previous file with comments | « base/message_loop/message_loop_unittest.cc ('k') | base/message_loop/message_pump_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698