| 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/input_handler_manager.h" | 5 #include "content/renderer/gpu/input_handler_manager.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 "cc/input/input_handler.h" | 9 #include "cc/input/input_handler.h" |
| 10 #include "content/common/gpu/input_handler_manager_client.h" |
| 10 #include "content/renderer/gpu/input_event_filter.h" | 11 #include "content/renderer/gpu/input_event_filter.h" |
| 11 #include "content/renderer/gpu/input_handler_wrapper.h" | 12 #include "content/renderer/gpu/input_handler_wrapper.h" |
| 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebActiveWheelFlingPa
rameters.h" | |
| 13 | |
| 14 #if defined(OS_ANDROID) | |
| 15 // TODO(epenner): Move thread priorities to base. (crbug.com/170549) | |
| 16 #include <sys/resource.h> | |
| 17 #endif | |
| 18 | 13 |
| 19 using WebKit::WebInputEvent; | 14 using WebKit::WebInputEvent; |
| 20 | 15 |
| 21 namespace content { | 16 namespace content { |
| 22 | 17 |
| 23 #if defined(OS_ANDROID) | |
| 24 // TODO(epenner): Move thread priorities to base. (crbug.com/170549) | |
| 25 namespace { | |
| 26 void SetHighThreadPriority() { | |
| 27 int nice_value = -6; // High priority. | |
| 28 setpriority(PRIO_PROCESS, base::PlatformThread::CurrentId(), nice_value); | |
| 29 } | |
| 30 } | |
| 31 #endif | |
| 32 | |
| 33 InputHandlerManager::InputHandlerManager( | 18 InputHandlerManager::InputHandlerManager( |
| 34 IPC::Listener* main_listener, | |
| 35 const scoped_refptr<base::MessageLoopProxy>& message_loop_proxy) | 19 const scoped_refptr<base::MessageLoopProxy>& message_loop_proxy) |
| 36 : message_loop_proxy_(message_loop_proxy) { | 20 : message_loop_proxy_(message_loop_proxy), |
| 37 filter_ = | 21 client_(NULL) { |
| 38 new InputEventFilter(main_listener, | |
| 39 message_loop_proxy, | |
| 40 base::Bind(&InputHandlerManager::HandleInputEvent, | |
| 41 base::Unretained(this))); | |
| 42 #if defined(OS_ANDROID) | |
| 43 // TODO(epenner): Move thread priorities to base. (crbug.com/170549) | |
| 44 message_loop_proxy->PostTask(FROM_HERE, base::Bind(&SetHighThreadPriority)); | |
| 45 #endif | |
| 46 } | 22 } |
| 47 | 23 |
| 48 InputHandlerManager::~InputHandlerManager() { | 24 InputHandlerManager::~InputHandlerManager() { |
| 49 } | 25 } |
| 50 | 26 |
| 51 IPC::ChannelProxy::MessageFilter* | 27 void InputHandlerManager::BindToClient(InputHandlerManagerClient* client) { |
| 52 InputHandlerManager::GetMessageFilter() const { | 28 DCHECK(!client_ || !client); |
| 53 return filter_; | 29 client_ = client; |
| 54 } | 30 } |
| 55 | 31 |
| 56 void InputHandlerManager::AddInputHandler( | 32 void InputHandlerManager::AddInputHandler( |
| 57 int routing_id, | 33 int routing_id, |
| 58 const base::WeakPtr<cc::InputHandler>& input_handler, | 34 const base::WeakPtr<cc::InputHandler>& input_handler, |
| 59 const base::WeakPtr<RenderViewImpl>& render_view_impl) { | 35 const base::WeakPtr<RenderViewImpl>& render_view_impl) { |
| 60 DCHECK(!message_loop_proxy_->BelongsToCurrentThread()); | 36 if (message_loop_proxy_->BelongsToCurrentThread()) { |
| 61 | 37 AddInputHandlerOnCompositorThread(routing_id, |
| 62 message_loop_proxy_->PostTask( | 38 base::MessageLoopProxy::current(), |
| 63 FROM_HERE, | 39 input_handler, |
| 64 base::Bind(&InputHandlerManager::AddInputHandlerOnCompositorThread, | 40 render_view_impl); |
| 65 base::Unretained(this), | 41 } else { |
| 66 routing_id, | 42 message_loop_proxy_->PostTask( |
| 67 base::MessageLoopProxy::current(), | 43 FROM_HERE, |
| 68 input_handler, | 44 base::Bind(&InputHandlerManager::AddInputHandlerOnCompositorThread, |
| 69 render_view_impl)); | 45 base::Unretained(this), |
| 46 routing_id, |
| 47 base::MessageLoopProxy::current(), |
| 48 input_handler, |
| 49 render_view_impl)); |
| 50 } |
| 70 } | 51 } |
| 71 | 52 |
| 72 void InputHandlerManager::AddInputHandlerOnCompositorThread( | 53 void InputHandlerManager::AddInputHandlerOnCompositorThread( |
| 73 int routing_id, | 54 int routing_id, |
| 74 const scoped_refptr<base::MessageLoopProxy>& main_loop, | 55 const scoped_refptr<base::MessageLoopProxy>& main_loop, |
| 75 const base::WeakPtr<cc::InputHandler>& input_handler, | 56 const base::WeakPtr<cc::InputHandler>& input_handler, |
| 76 const base::WeakPtr<RenderViewImpl>& render_view_impl) { | 57 const base::WeakPtr<RenderViewImpl>& render_view_impl) { |
| 58 DCHECK(client_); |
| 77 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); | 59 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); |
| 78 | 60 |
| 79 // The handler could be gone by this point if the compositor has shut down. | 61 // The handler could be gone by this point if the compositor has shut down. |
| 80 if (!input_handler) | 62 if (!input_handler) |
| 81 return; | 63 return; |
| 82 | 64 |
| 83 // The same handler may be registered for a route multiple times. | 65 // The same handler may be registered for a route multiple times. |
| 84 if (input_handlers_.count(routing_id) != 0) | 66 if (input_handlers_.count(routing_id) != 0) |
| 85 return; | 67 return; |
| 86 | 68 |
| 87 TRACE_EVENT0("InputHandlerManager::AddInputHandler", "AddingRoute"); | 69 TRACE_EVENT0("InputHandlerManager::AddInputHandler", "AddingRoute"); |
| 88 filter_->AddRoute(routing_id); | 70 client_->DidAddInputHandler(routing_id); |
| 89 input_handlers_[routing_id] = | 71 input_handlers_[routing_id] = |
| 90 make_scoped_refptr(new InputHandlerWrapper(this, | 72 make_scoped_refptr(new InputHandlerWrapper(this, |
| 91 routing_id, main_loop, input_handler, render_view_impl)); | 73 routing_id, main_loop, input_handler, render_view_impl)); |
| 92 } | 74 } |
| 93 | 75 |
| 94 void InputHandlerManager::RemoveInputHandler(int routing_id) { | 76 void InputHandlerManager::RemoveInputHandler(int routing_id) { |
| 77 DCHECK(client_); |
| 95 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); | 78 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); |
| 96 | 79 |
| 97 TRACE_EVENT0("InputHandlerManager::RemoveInputHandler", "RemovingRoute"); | 80 TRACE_EVENT0("InputHandlerManager::RemoveInputHandler", "RemovingRoute"); |
| 98 | 81 |
| 99 filter_->RemoveRoute(routing_id); | 82 client_->DidRemoveInputHandler(routing_id); |
| 100 input_handlers_.erase(routing_id); | 83 input_handlers_.erase(routing_id); |
| 101 } | 84 } |
| 102 | 85 |
| 103 void InputHandlerManager::HandleInputEvent( | 86 void InputHandlerManager::HandleInputEvent( |
| 104 int routing_id, | 87 int routing_id, |
| 105 const WebInputEvent* input_event) { | 88 const WebInputEvent* input_event) { |
| 89 DCHECK(client_); |
| 106 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); | 90 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); |
| 107 | 91 |
| 108 InputHandlerMap::iterator it = input_handlers_.find(routing_id); | 92 InputHandlerMap::iterator it = input_handlers_.find(routing_id); |
| 109 if (it == input_handlers_.end()) { | 93 if (it == input_handlers_.end()) { |
| 110 TRACE_EVENT0("InputHandlerManager::HandleInputEvent", | 94 TRACE_EVENT0("InputHandlerManager::HandleInputEvent", |
| 111 "NoInputHandlerFound"); | 95 "NoInputHandlerFound"); |
| 112 // Oops, we no longer have an interested input handler.. | 96 // Oops, we no longer have an interested input handler.. |
| 113 filter_->DidNotHandleInputEvent(true); | 97 client_->DidNotHandleInputEvent(true); |
| 114 return; | 98 return; |
| 115 } | 99 } |
| 116 | 100 |
| 117 it->second->input_handler_proxy()->HandleInputEvent(*input_event); | 101 it->second->input_handler_proxy()->HandleInputEvent(*input_event); |
| 118 } | 102 } |
| 119 | 103 |
| 120 } // namespace content | 104 } // namespace content |
| OLD | NEW |