OLD | NEW |
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 #include "content/renderer/gpu/compositor_thread.h" | 5 #include "content/renderer/gpu/compositor_thread.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 9 #include "base/message_loop.h" |
9 #include "content/renderer/gpu/input_event_filter.h" | 10 #include "content/renderer/gpu/input_event_filter.h" |
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebActiveWheelFlingPa
rameters.h" | 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebActiveWheelFlingPa
rameters.h" |
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositorInputHan
dlerClient.h" | 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositorInputHan
dlerClient.h" |
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositorInputHan
dler.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositorInputHan
dler.h" |
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
14 | 15 |
15 #if defined(OS_ANDROID) | 16 #if defined(OS_ANDROID) |
16 // TODO(epenner): Move thread priorities to base. (crbug.com/170549) | 17 // TODO(epenner): Move thread priorities to base. (crbug.com/170549) |
17 #include <sys/resource.h> | 18 #include <sys/resource.h> |
18 #endif | 19 #endif |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 #if defined(OS_ANDROID) | 92 #if defined(OS_ANDROID) |
92 // TODO(epenner): Move thread priorities to base. (crbug.com/170549) | 93 // TODO(epenner): Move thread priorities to base. (crbug.com/170549) |
93 namespace { | 94 namespace { |
94 void SetHighThreadPriority() { | 95 void SetHighThreadPriority() { |
95 int nice_value = -6; // High priority. | 96 int nice_value = -6; // High priority. |
96 setpriority(PRIO_PROCESS, base::PlatformThread::CurrentId(), nice_value); | 97 setpriority(PRIO_PROCESS, base::PlatformThread::CurrentId(), nice_value); |
97 } | 98 } |
98 } | 99 } |
99 #endif | 100 #endif |
100 | 101 |
101 CompositorThread::CompositorThread(IPC::Listener* main_listener) | 102 CompositorThread::CompositorThread(IPC::Listener* main_listener, MessageLoop* me
ssage_loop) |
102 : thread_("Compositor") { | 103 : message_loop_(message_loop), |
| 104 thread_(message_loop->message_loop_proxy()) { |
103 filter_ = | 105 filter_ = |
104 new InputEventFilter(main_listener, | 106 new InputEventFilter(main_listener, |
105 thread_.message_loop()->message_loop_proxy(), | 107 message_loop->message_loop_proxy(), |
106 base::Bind(&CompositorThread::HandleInputEvent, | 108 base::Bind(&CompositorThread::HandleInputEvent, |
107 base::Unretained(this))); | 109 base::Unretained(this))); |
108 #if defined(OS_ANDROID) | 110 #if defined(OS_ANDROID) |
109 // TODO(epenner): Move thread priorities to base. (crbug.com/170549) | 111 // TODO(epenner): Move thread priorities to base. (crbug.com/170549) |
110 thread_.message_loop()->PostTask(FROM_HERE, | 112 message_loop->PostTask(FROM_HERE, base::Bind(&SetHighThreadPriority)); |
111 base::Bind(&SetHighThreadPriority)); | |
112 #endif | 113 #endif |
113 } | 114 } |
114 | 115 |
115 CompositorThread::~CompositorThread() { | 116 CompositorThread::~CompositorThread() { |
116 } | 117 } |
117 | 118 |
118 IPC::ChannelProxy::MessageFilter* CompositorThread::GetMessageFilter() const { | 119 IPC::ChannelProxy::MessageFilter* CompositorThread::GetMessageFilter() const { |
119 return filter_; | 120 return filter_; |
120 } | 121 } |
121 | 122 |
122 void CompositorThread::AddInputHandler( | 123 void CompositorThread::AddInputHandler( |
123 int routing_id, int input_handler_id, | 124 int routing_id, int input_handler_id, |
124 const base::WeakPtr<RenderViewImpl>& render_view_impl) { | 125 const base::WeakPtr<RenderViewImpl>& render_view_impl) { |
125 DCHECK_NE(thread_.message_loop(), MessageLoop::current()); | 126 DCHECK_NE(message_loop_, MessageLoop::current()); |
126 | 127 |
127 thread_.message_loop()->PostTask( | 128 message_loop_->PostTask( |
128 FROM_HERE, | 129 FROM_HERE, |
129 base::Bind(&CompositorThread::AddInputHandlerOnCompositorThread, | 130 base::Bind(&CompositorThread::AddInputHandlerOnCompositorThread, |
130 base::Unretained(this), | 131 base::Unretained(this), |
131 routing_id, | 132 routing_id, |
132 input_handler_id, | 133 input_handler_id, |
133 base::MessageLoopProxy::current(), | 134 base::MessageLoopProxy::current(), |
134 render_view_impl)); | 135 render_view_impl)); |
135 } | 136 } |
136 | 137 |
137 void CompositorThread::AddInputHandlerOnCompositorThread( | 138 void CompositorThread::AddInputHandlerOnCompositorThread( |
138 int routing_id, int input_handler_id, | 139 int routing_id, int input_handler_id, |
139 scoped_refptr<base::MessageLoopProxy> main_loop, | 140 scoped_refptr<base::MessageLoopProxy> main_loop, |
140 const base::WeakPtr<RenderViewImpl>& render_view_impl) { | 141 const base::WeakPtr<RenderViewImpl>& render_view_impl) { |
141 | 142 |
142 DCHECK_EQ(thread_.message_loop(), MessageLoop::current()); | 143 DCHECK_EQ(message_loop_, MessageLoop::current()); |
143 | 144 |
144 WebCompositorInputHandler* input_handler = | 145 WebCompositorInputHandler* input_handler = |
145 WebCompositorInputHandler::fromIdentifier(input_handler_id); | 146 WebCompositorInputHandler::fromIdentifier(input_handler_id); |
146 if (!input_handler) | 147 if (!input_handler) |
147 return; | 148 return; |
148 | 149 |
149 if (input_handlers_.count(routing_id) != 0) { | 150 if (input_handlers_.count(routing_id) != 0) { |
150 // It's valid to call AddInputHandler() for the same routing id with the | 151 // It's valid to call AddInputHandler() for the same routing id with the |
151 // same input_handler many times, but it's not valid to change the | 152 // same input_handler many times, but it's not valid to change the |
152 // input_handler for a route. | 153 // input_handler for a route. |
153 DCHECK_EQ(input_handlers_[routing_id]->input_handler(), input_handler); | 154 DCHECK_EQ(input_handlers_[routing_id]->input_handler(), input_handler); |
154 return; | 155 return; |
155 } | 156 } |
156 | 157 |
157 TRACE_EVENT0("CompositorThread::AddInputHandler", "AddingRoute"); | 158 TRACE_EVENT0("CompositorThread::AddInputHandler", "AddingRoute"); |
158 filter_->AddRoute(routing_id); | 159 filter_->AddRoute(routing_id); |
159 input_handlers_[routing_id] = | 160 input_handlers_[routing_id] = |
160 make_scoped_refptr(new InputHandlerWrapper(this, | 161 make_scoped_refptr(new InputHandlerWrapper(this, |
161 routing_id, input_handler, main_loop, render_view_impl)); | 162 routing_id, input_handler, main_loop, render_view_impl)); |
162 } | 163 } |
163 | 164 |
164 void CompositorThread::RemoveInputHandler(int routing_id) { | 165 void CompositorThread::RemoveInputHandler(int routing_id) { |
165 DCHECK_EQ(MessageLoop::current(), thread_.message_loop()); | 166 DCHECK_EQ(MessageLoop::current(), message_loop_); |
166 | 167 |
167 TRACE_EVENT0("CompositorThread::RemoveInputHandler", "RemovingRoute"); | 168 TRACE_EVENT0("CompositorThread::RemoveInputHandler", "RemovingRoute"); |
168 | 169 |
169 filter_->RemoveRoute(routing_id); | 170 filter_->RemoveRoute(routing_id); |
170 input_handlers_.erase(routing_id); | 171 input_handlers_.erase(routing_id); |
171 } | 172 } |
172 | 173 |
173 void CompositorThread::HandleInputEvent( | 174 void CompositorThread::HandleInputEvent( |
174 int routing_id, | 175 int routing_id, |
175 const WebInputEvent* input_event) { | 176 const WebInputEvent* input_event) { |
176 DCHECK_EQ(MessageLoop::current(), thread_.message_loop()); | 177 DCHECK_EQ(MessageLoop::current(), message_loop_); |
177 | 178 |
178 InputHandlerMap::iterator it = input_handlers_.find(routing_id); | 179 InputHandlerMap::iterator it = input_handlers_.find(routing_id); |
179 if (it == input_handlers_.end()) { | 180 if (it == input_handlers_.end()) { |
180 TRACE_EVENT0("CompositorThread::HandleInputEvent", "NoInputHandlerFound"); | 181 TRACE_EVENT0("CompositorThread::HandleInputEvent", "NoInputHandlerFound"); |
181 // Oops, we no longer have an interested input handler.. | 182 // Oops, we no longer have an interested input handler.. |
182 filter_->DidNotHandleInputEvent(true); | 183 filter_->DidNotHandleInputEvent(true); |
183 return; | 184 return; |
184 } | 185 } |
185 | 186 |
186 it->second->input_handler()->handleInputEvent(*input_event); | 187 it->second->input_handler()->handleInputEvent(*input_event); |
187 } | 188 } |
188 | 189 |
189 } // namespace content | 190 } // namespace content |
OLD | NEW |