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

Side by Side Diff: content/renderer/gpu/input_handler_manager.cc

Issue 13844021: Move compositor thread input handling logic into content (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 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 | Annotate | Revision Log
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 #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 "content/renderer/gpu/input_event_filter.h" 10 #include "content/renderer/gpu/input_event_filter.h"
11 #include "content/renderer/gpu/input_handler_wrapper.h"
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebActiveWheelFlingPa rameters.h" 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebActiveWheelFlingPa rameters.h"
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositorInputHan dler.h" 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositorInputHan dler.h"
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositorInputHan dlerClient.h" 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositorInputHan dlerClient.h"
15 #include "webkit/compositor_bindings/web_to_ccinput_handler_adapter.h"
danakj 2013/05/01 19:20:43 Needed?
13 16
14 #if defined(OS_ANDROID) 17 #if defined(OS_ANDROID)
15 // TODO(epenner): Move thread priorities to base. (crbug.com/170549) 18 // TODO(epenner): Move thread priorities to base. (crbug.com/170549)
16 #include <sys/resource.h> 19 #include <sys/resource.h>
17 #endif 20 #endif
18 21
19 using WebKit::WebCompositorInputHandler; 22 using WebKit::WebCompositorInputHandler;
20 using WebKit::WebInputEvent; 23 using WebKit::WebInputEvent;
21 24
22 namespace content { 25 namespace content {
23 26
24 //------------------------------------------------------------------------------
25
26 class InputHandlerManager::InputHandlerWrapper
27 : public WebKit::WebCompositorInputHandlerClient,
28 public base::RefCountedThreadSafe<InputHandlerWrapper> {
29 public:
30 InputHandlerWrapper(InputHandlerManager* input_handler_manager,
31 int routing_id,
32 WebKit::WebCompositorInputHandler* input_handler,
33 const scoped_refptr<base::MessageLoopProxy>& main_loop,
34 const base::WeakPtr<RenderViewImpl>& render_view_impl)
35 : input_handler_manager_(input_handler_manager),
36 routing_id_(routing_id),
37 input_handler_(input_handler),
38 main_loop_(main_loop),
39 render_view_impl_(render_view_impl) {
40 input_handler_->setClient(this);
41 }
42
43 virtual void transferActiveWheelFlingAnimation(
44 const WebKit::WebActiveWheelFlingParameters& params) {
45 main_loop_->PostTask(
46 FROM_HERE,
47 base::Bind(&RenderViewImpl::TransferActiveWheelFlingAnimation,
48 render_view_impl_, params));
49 }
50
51 int routing_id() const { return routing_id_; }
52 WebKit::WebCompositorInputHandler* input_handler() const {
53 return input_handler_;
54 }
55
56 // WebCompositorInputHandlerClient methods:
57
58 virtual void willShutdown() {
59 input_handler_manager_->RemoveInputHandler(routing_id_);
60 }
61
62 virtual void didHandleInputEvent() {
63 input_handler_manager_->filter_->DidHandleInputEvent();
64 }
65
66 virtual void didNotHandleInputEvent(bool send_to_widget) {
67 input_handler_manager_->filter_->DidNotHandleInputEvent(send_to_widget);
68 }
69
70 private:
71 friend class base::RefCountedThreadSafe<InputHandlerWrapper>;
72
73 virtual ~InputHandlerWrapper() {
74 input_handler_->setClient(NULL);
75 }
76
77 InputHandlerManager* input_handler_manager_;
78 int routing_id_;
79 WebKit::WebCompositorInputHandler* input_handler_;
80 scoped_refptr<base::MessageLoopProxy> main_loop_;
81
82 // Can only be accessed on the main thread.
83 base::WeakPtr<RenderViewImpl> render_view_impl_;
84
85 DISALLOW_COPY_AND_ASSIGN(InputHandlerWrapper);
86 };
87
88 //------------------------------------------------------------------------------
89
90 #if defined(OS_ANDROID) 27 #if defined(OS_ANDROID)
91 // TODO(epenner): Move thread priorities to base. (crbug.com/170549) 28 // TODO(epenner): Move thread priorities to base. (crbug.com/170549)
92 namespace { 29 namespace {
93 void SetHighThreadPriority() { 30 void SetHighThreadPriority() {
94 int nice_value = -6; // High priority. 31 int nice_value = -6; // High priority.
95 setpriority(PRIO_PROCESS, base::PlatformThread::CurrentId(), nice_value); 32 setpriority(PRIO_PROCESS, base::PlatformThread::CurrentId(), nice_value);
96 } 33 }
97 } 34 }
98 #endif 35 #endif
99 36
(...skipping 14 matching lines...) Expand all
114 51
115 InputHandlerManager::~InputHandlerManager() { 52 InputHandlerManager::~InputHandlerManager() {
116 } 53 }
117 54
118 IPC::ChannelProxy::MessageFilter* 55 IPC::ChannelProxy::MessageFilter*
119 InputHandlerManager::GetMessageFilter() const { 56 InputHandlerManager::GetMessageFilter() const {
120 return filter_; 57 return filter_;
121 } 58 }
122 59
123 void InputHandlerManager::AddInputHandler( 60 void InputHandlerManager::AddInputHandler(
124 int routing_id, int input_handler_id, 61 int routing_id,
62 const base::WeakPtr<cc::InputHandler>& input_handler,
125 const base::WeakPtr<RenderViewImpl>& render_view_impl) { 63 const base::WeakPtr<RenderViewImpl>& render_view_impl) {
126 DCHECK(!message_loop_proxy_->BelongsToCurrentThread()); 64 DCHECK(!message_loop_proxy_->BelongsToCurrentThread());
127 65
128 message_loop_proxy_->PostTask( 66 message_loop_proxy_->PostTask(
129 FROM_HERE, 67 FROM_HERE,
130 base::Bind(&InputHandlerManager::AddInputHandlerOnCompositorThread, 68 base::Bind(&InputHandlerManager::AddInputHandlerOnCompositorThread,
131 base::Unretained(this), 69 base::Unretained(this),
132 routing_id, 70 routing_id,
133 input_handler_id,
134 base::MessageLoopProxy::current(), 71 base::MessageLoopProxy::current(),
72 input_handler,
135 render_view_impl)); 73 render_view_impl));
136 } 74 }
137 75
138 void InputHandlerManager::AddInputHandlerOnCompositorThread( 76 void InputHandlerManager::AddInputHandlerOnCompositorThread(
139 int routing_id, int input_handler_id, 77 int routing_id,
140 const scoped_refptr<base::MessageLoopProxy>& main_loop, 78 const scoped_refptr<base::MessageLoopProxy>& main_loop,
79 const base::WeakPtr<cc::InputHandler>& input_handler,
141 const base::WeakPtr<RenderViewImpl>& render_view_impl) { 80 const base::WeakPtr<RenderViewImpl>& render_view_impl) {
142 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); 81 DCHECK(message_loop_proxy_->BelongsToCurrentThread());
143 82
144 WebCompositorInputHandler* input_handler = 83 // The handler could be gone by this point if the compositor has shut down.
145 WebCompositorInputHandler::fromIdentifier(input_handler_id);
146 if (!input_handler) 84 if (!input_handler)
147 return; 85 return;
148 86
149 if (input_handlers_.count(routing_id) != 0) { 87 if (input_handlers_.count(routing_id) != 0) {
150 // It's valid to call AddInputHandler() for the same routing id with the 88 // 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 89 // same input_handler many times, but it's not valid to change the
152 // input_handler for a route. 90 // input_handler for a route.
153 DCHECK_EQ(input_handlers_[routing_id]->input_handler(), input_handler); 91 //DCHECK_EQ(input_handlers_[routing_id]->input_handler(), input_handler);
danakj 2013/05/01 19:20:43 ?
154 return; 92 return;
155 } 93 }
156 94
157 TRACE_EVENT0("InputHandlerManager::AddInputHandler", "AddingRoute"); 95 TRACE_EVENT0("InputHandlerManager::AddInputHandler", "AddingRoute");
158 filter_->AddRoute(routing_id); 96 filter_->AddRoute(routing_id);
159 input_handlers_[routing_id] = 97 input_handlers_[routing_id] =
160 make_scoped_refptr(new InputHandlerWrapper(this, 98 make_scoped_refptr(new InputHandlerWrapper(this,
161 routing_id, input_handler, main_loop, render_view_impl)); 99 routing_id, main_loop, input_handler, render_view_impl));
162 } 100 }
163 101
164 void InputHandlerManager::RemoveInputHandler(int routing_id) { 102 void InputHandlerManager::RemoveInputHandler(int routing_id) {
165 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); 103 DCHECK(message_loop_proxy_->BelongsToCurrentThread());
166 104
167 TRACE_EVENT0("InputHandlerManager::RemoveInputHandler", "RemovingRoute"); 105 TRACE_EVENT0("InputHandlerManager::RemoveInputHandler", "RemovingRoute");
168 106
169 filter_->RemoveRoute(routing_id); 107 filter_->RemoveRoute(routing_id);
170 input_handlers_.erase(routing_id); 108 input_handlers_.erase(routing_id);
171 } 109 }
172 110
173 void InputHandlerManager::HandleInputEvent( 111 void InputHandlerManager::HandleInputEvent(
174 int routing_id, 112 int routing_id,
175 const WebInputEvent* input_event) { 113 const WebInputEvent* input_event) {
176 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); 114 DCHECK(message_loop_proxy_->BelongsToCurrentThread());
177 115
178 InputHandlerMap::iterator it = input_handlers_.find(routing_id); 116 InputHandlerMap::iterator it = input_handlers_.find(routing_id);
179 if (it == input_handlers_.end()) { 117 if (it == input_handlers_.end()) {
180 TRACE_EVENT0("InputHandlerManager::HandleInputEvent", 118 TRACE_EVENT0("InputHandlerManager::HandleInputEvent",
181 "NoInputHandlerFound"); 119 "NoInputHandlerFound");
182 // Oops, we no longer have an interested input handler.. 120 // Oops, we no longer have an interested input handler..
183 filter_->DidNotHandleInputEvent(true); 121 filter_->DidNotHandleInputEvent(true);
184 return; 122 return;
185 } 123 }
186 124
187 it->second->input_handler()->handleInputEvent(*input_event); 125 it->second->input_handler()->HandleInputEvent(*input_event);
danakj 2013/05/01 19:39:04 This will be null deref once the LTHI is gone righ
188 } 126 }
189 127
190 } // namespace content 128 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698