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

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

Issue 1714263002: Version of MessagePumpForUI optimized for GPU process (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added CallMsgFilter call Created 4 years, 8 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/observer_list.h" 15 #include "base/observer_list.h"
15 #include "base/time/time.h" 16 #include "base/time/time.h"
16 #include "base/win/scoped_handle.h" 17 #include "base/win/scoped_handle.h"
17 18
18 namespace base { 19 namespace base {
19 20
20 // MessagePumpWin serves as the base for specialized versions of the MessagePump 21 // MessagePumpWin serves as the base for specialized versions of the MessagePump
21 // for Windows. It provides basic functionality like handling of observers and 22 // for Windows. It provides basic functionality like handling of observers and
22 // controlling the lifetime of the message pump. 23 // controlling the lifetime of the message pump.
23 class BASE_EXPORT MessagePumpWin : public MessagePump { 24 class BASE_EXPORT MessagePumpWin : public MessagePump {
24 public: 25 public:
25 MessagePumpWin() : have_work_(0), state_(NULL) {} 26 MessagePumpWin() : work_state_(READY), state_(NULL) {}
26 27
27 // MessagePump methods: 28 // MessagePump methods:
28 void Run(Delegate* delegate) override; 29 void Run(Delegate* delegate) override;
29 void Quit() override; 30 void Quit() override;
30 31
31 protected: 32 protected:
32 struct RunState { 33 struct RunState {
33 Delegate* delegate; 34 Delegate* delegate;
34 35
35 // Used to flag that the current Run() invocation should return ASAP. 36 // Used to flag that the current Run() invocation should return ASAP.
36 bool should_quit; 37 bool should_quit;
37 38
38 // Used to count how many Run() invocations are on the stack. 39 // Used to count how many Run() invocations are on the stack.
39 int run_depth; 40 int run_depth;
40 }; 41 };
41 42
43 // State used with |work_state_| variable.
44 enum WorkState {
45 READY = 0, // Ready to accept new work.
46 HAVE_WORK = 1, // New work has been signalled.
47 WORKING = 2 // Handling the work.
48 };
49
42 virtual void DoRunLoop() = 0; 50 virtual void DoRunLoop() = 0;
43 int GetCurrentDelay() const; 51 int GetCurrentDelay() const;
44 52
45 // The time at which delayed work should run. 53 // The time at which delayed work should run.
46 TimeTicks delayed_work_time_; 54 TimeTicks delayed_work_time_;
47 55
48 // A boolean value used to indicate if there is a kMsgDoWork message pending 56 // A value used to indicate if there is a kMsgDoWork message pending
49 // in the Windows Message queue. There is at most one such message, and it 57 // in the Windows Message queue. There is at most one such message, and it
50 // can drive execution of tasks when a native message pump is running. 58 // can drive execution of tasks when a native message pump is running.
51 LONG have_work_; 59 LONG work_state_;
52 60
53 // State for the current invocation of Run. 61 // State for the current invocation of Run.
54 RunState* state_; 62 RunState* state_;
55 }; 63 };
56 64
57 //----------------------------------------------------------------------------- 65 //-----------------------------------------------------------------------------
58 // MessagePumpForUI extends MessagePumpWin with methods that are particular to a 66 // MessagePumpForUI extends MessagePumpWin with methods that are particular to a
59 // MessageLoop instantiated with TYPE_UI. 67 // MessageLoop instantiated with TYPE_UI.
60 // 68 //
61 // MessagePumpForUI implements a "traditional" Windows message pump. It contains 69 // MessagePumpForUI implements a "traditional" Windows message pump. It contains
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 // is peeked, and before a replacement kMsgHaveWork is posted). 105 // is peeked, and before a replacement kMsgHaveWork is posted).
98 // 106 //
99 // NOTE: Although it may seem odd that messages are used to start and stop this 107 // NOTE: Although it may seem odd that messages are used to start and stop this
100 // flow (as opposed to signaling objects, etc.), it should be understood that 108 // flow (as opposed to signaling objects, etc.), it should be understood that
101 // the native message pump will *only* respond to messages. As a result, it is 109 // the native message pump will *only* respond to messages. As a result, it is
102 // an excellent choice. It is also helpful that the starter messages that are 110 // an excellent choice. It is also helpful that the starter messages that are
103 // placed in the queue when new task arrive also awakens DoRunLoop. 111 // placed in the queue when new task arrive also awakens DoRunLoop.
104 // 112 //
105 class BASE_EXPORT MessagePumpForUI : public MessagePumpWin { 113 class BASE_EXPORT MessagePumpForUI : public MessagePumpWin {
106 public: 114 public:
107 // The application-defined code passed to the hook procedure.
108 static const int kMessageFilterCode = 0x5001;
109
110 MessagePumpForUI(); 115 MessagePumpForUI();
111 ~MessagePumpForUI() override; 116 ~MessagePumpForUI() override;
112 117
113 // MessagePump methods: 118 // MessagePump methods:
114 void ScheduleWork() override; 119 void ScheduleWork() override;
115 void ScheduleDelayedWork(const TimeTicks& delayed_work_time) override; 120 void ScheduleDelayedWork(const TimeTicks& delayed_work_time) override;
116 121
117 private: 122 private:
118 static LRESULT CALLBACK WndProcThunk(HWND window_handle, 123 static LRESULT CALLBACK WndProcThunk(HWND window_handle,
119 UINT message, 124 UINT message,
(...skipping 10 matching lines...) Expand all
130 bool ProcessPumpReplacementMessage(); 135 bool ProcessPumpReplacementMessage();
131 136
132 // Atom representing the registered window class. 137 // Atom representing the registered window class.
133 ATOM atom_; 138 ATOM atom_;
134 139
135 // A hidden message-only window. 140 // A hidden message-only window.
136 HWND message_hwnd_; 141 HWND message_hwnd_;
137 }; 142 };
138 143
139 //----------------------------------------------------------------------------- 144 //-----------------------------------------------------------------------------
145 // MessagePumpForGpu is a simplified version of UI message pump that is
146 // optimized for the GPU process. Unlike MessagePumpForUI it doesn't have a
147 // hidden window and doesn't handle a situation where a native message pump
148 // might take over message processing.
149 //
150 class BASE_EXPORT MessagePumpForGpu : public MessagePumpWin {
151 public:
152 MessagePumpForGpu();
153 ~MessagePumpForGpu() override;
154
155 // Factory methods.
156 static void InitFactory();
157 static std::unique_ptr<MessagePump> CreateMessagePumpForGpu();
158
159 // MessagePump methods:
160 void ScheduleWork() override;
161 void ScheduleDelayedWork(const TimeTicks& delayed_work_time) override;
162
163 private:
164 // MessagePumpWin methods:
165 void DoRunLoop() override;
166
167 void WaitForWork();
168 bool ProcessMessages();
169
170 const DWORD thread_id_;
171 };
172
173 //-----------------------------------------------------------------------------
140 // MessagePumpForIO extends MessagePumpWin with methods that are particular to a 174 // MessagePumpForIO extends MessagePumpWin with methods that are particular to a
141 // MessageLoop instantiated with TYPE_IO. This version of MessagePump does not 175 // MessageLoop instantiated with TYPE_IO. This version of MessagePump does not
142 // deal with Windows mesagges, and instead has a Run loop based on Completion 176 // deal with Windows mesagges, and instead has a Run loop based on Completion
143 // Ports so it is better suited for IO operations. 177 // Ports so it is better suited for IO operations.
144 // 178 //
145 class BASE_EXPORT MessagePumpForIO : public MessagePumpWin { 179 class BASE_EXPORT MessagePumpForIO : public MessagePumpWin {
146 public: 180 public:
147 struct IOContext; 181 struct IOContext;
148 182
149 // Clients interested in receiving OS notifications when asynchronous IO 183 // Clients interested in receiving OS notifications when asynchronous IO
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 // This list will be empty almost always. It stores IO completions that have 360 // This list will be empty almost always. It stores IO completions that have
327 // not been delivered yet because somebody was doing cleanup. 361 // not been delivered yet because somebody was doing cleanup.
328 std::list<IOItem> completed_io_; 362 std::list<IOItem> completed_io_;
329 363
330 ObserverList<IOObserver> io_observers_; 364 ObserverList<IOObserver> io_observers_;
331 }; 365 };
332 366
333 } // namespace base 367 } // namespace base
334 368
335 #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_WIN_H_ 369 #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