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

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

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