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

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

Issue 9817001: Implement active wheel fling transfer via WebCompositorInputHandlerClient (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Really builds Created 8 years, 9 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
« no previous file with comments | « content/renderer/gpu/compositor_thread.h ('k') | no next file » | 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 #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 "content/renderer/gpu/input_event_filter.h" 8 #include "content/renderer/gpu/input_event_filter.h"
9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositor.h" 9 #include "content/public/renderer/render_view.h"
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositorClient.h " 10 #include "content/public/renderer/render_view_visitor.h"
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebActiveWheelFlingPa rameters.h"
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositorInputHan dlerClient.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"
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
12 15
13 using WebKit::WebCompositorInputHandler; 16 using WebKit::WebCompositorInputHandler;
14 using WebKit::WebInputEvent; 17 using WebKit::WebInputEvent;
15 18
16 //------------------------------------------------------------------------------ 19 //------------------------------------------------------------------------------
17 20
18 class CompositorThread::InputHandlerWrapper 21 class CompositorThread::InputHandlerWrapper
19 : public WebKit::WebCompositorClient { 22 : public WebKit::WebCompositorInputHandlerClient {
20 public: 23 public:
21 InputHandlerWrapper(CompositorThread* compositor_thread, 24 InputHandlerWrapper(CompositorThread* compositor_thread,
22 int routing_id, 25 int routing_id,
23 WebKit::WebCompositorInputHandler* input_handler) 26 WebKit::WebCompositorInputHandler* input_handler,
27 scoped_refptr<base::MessageLoopProxy> main_loop)
24 : compositor_thread_(compositor_thread), 28 : compositor_thread_(compositor_thread),
25 routing_id_(routing_id), 29 routing_id_(routing_id),
26 input_handler_(input_handler) { 30 input_handler_(input_handler),
31 main_loop_(main_loop),
32 render_view_finder_(routing_id) {
27 input_handler_->setClient(this); 33 input_handler_->setClient(this);
28 } 34 }
29 35
36 virtual void transferActiveWheelFlingAnimation(
37 const WebKit::WebActiveWheelFlingParameters& params) {
38 main_loop_->PostTask(
39 FROM_HERE,
40 base::Bind(&CompositorThread::InputHandlerWrapper
41 ::TransferActiveWheelFlingAnimation,
42 base::Unretained(this), params));
43 }
44
30 virtual ~InputHandlerWrapper() { 45 virtual ~InputHandlerWrapper() {
31 input_handler_->setClient(NULL); 46 input_handler_->setClient(NULL);
32 } 47 }
33 48
34 int routing_id() const { return routing_id_; } 49 int routing_id() const { return routing_id_; }
35 WebKit::WebCompositorInputHandler* input_handler() const { 50 WebKit::WebCompositorInputHandler* input_handler() const {
36 return input_handler_; 51 return input_handler_;
37 } 52 }
38 53
39 // WebCompositorClient methods: 54 // WebCompositorInputHandlerClient methods:
40 55
41 virtual void willShutdown() { 56 virtual void willShutdown() {
42 compositor_thread_->RemoveInputHandler(routing_id_); 57 compositor_thread_->RemoveInputHandler(routing_id_);
43 } 58 }
44 59
45 virtual void didHandleInputEvent() { 60 virtual void didHandleInputEvent() {
46 compositor_thread_->filter_->DidHandleInputEvent(); 61 compositor_thread_->filter_->DidHandleInputEvent();
47 } 62 }
48 63
49 virtual void didNotHandleInputEvent(bool send_to_widget) { 64 virtual void didNotHandleInputEvent(bool send_to_widget) {
50 compositor_thread_->filter_->DidNotHandleInputEvent(send_to_widget); 65 compositor_thread_->filter_->DidNotHandleInputEvent(send_to_widget);
51 } 66 }
52 67
53 private: 68 private:
69 // TODO(jamesr): There's got to be a better way to do this. Do we have a map
70 // from routing_id -> RenderView / RenderViewImpl somewhere?
71 class FindRenderViewByRoutingIDVisitor : public content::RenderViewVisitor {
72 public:
73 explicit FindRenderViewByRoutingIDVisitor(int routing_id)
74 : routing_id_(routing_id) ,
75 render_view_(NULL) {
76 }
77
78 content::RenderView* FindRenderView() {
79 if (!render_view_)
80 content::RenderView::ForEach(this);
81 return render_view_;
82 }
83
84 virtual bool Visit(content::RenderView* render_view) OVERRIDE {
85 if (render_view->GetRoutingID() == routing_id_)
86 return false;
87 return true;
88 }
89
90 private:
91 int routing_id_;
92 // We will always destroy the CompositorWrapper through
jamesr 2012/03/21 14:38:31 note: I haven't fully convinced myself that this i
93 // CompositorThread::RemoveCompositor before the view goes away, so it's
94 // safe to stash a raw pointer here.
95 content::RenderView* render_view_;
96 };
97
98 void TransferActiveWheelFlingAnimation(
99 WebKit::WebActiveWheelFlingParameters params) {
100 render_view_finder_.FindRenderView()->
101 GetWebView()->transferActiveWheelFlingAnimation(params);
102 }
103
54 CompositorThread* compositor_thread_; 104 CompositorThread* compositor_thread_;
55 int routing_id_; 105 int routing_id_;
56 WebKit::WebCompositorInputHandler* input_handler_; 106 WebKit::WebCompositorInputHandler* input_handler_;
107 scoped_refptr<base::MessageLoopProxy> main_loop_;
108 FindRenderViewByRoutingIDVisitor render_view_finder_;
57 109
58 DISALLOW_COPY_AND_ASSIGN(InputHandlerWrapper); 110 DISALLOW_COPY_AND_ASSIGN(InputHandlerWrapper);
59 }; 111 };
60 112
61 //------------------------------------------------------------------------------ 113 //------------------------------------------------------------------------------
62 114
63 CompositorThread::CompositorThread(IPC::Channel::Listener* main_listener) 115 CompositorThread::CompositorThread(IPC::Channel::Listener* main_listener)
64 : thread_("Compositor") { 116 : thread_("Compositor") {
65 filter_ = 117 filter_ =
66 new InputEventFilter(main_listener, 118 new InputEventFilter(main_listener,
67 thread_.message_loop()->message_loop_proxy(), 119 thread_.message_loop()->message_loop_proxy(),
68 base::Bind(&CompositorThread::HandleInputEvent, 120 base::Bind(&CompositorThread::HandleInputEvent,
69 base::Unretained(this))); 121 base::Unretained(this)));
70 } 122 }
71 123
72 CompositorThread::~CompositorThread() { 124 CompositorThread::~CompositorThread() {
73 } 125 }
74 126
75 IPC::ChannelProxy::MessageFilter* CompositorThread::GetMessageFilter() const { 127 IPC::ChannelProxy::MessageFilter* CompositorThread::GetMessageFilter() const {
76 return filter_; 128 return filter_;
77 } 129 }
78 130
79 void CompositorThread::AddInputHandler(int routing_id, int input_handler_id) { 131 void CompositorThread::AddInputHandler(int routing_id, int input_handler_id) {
80 if (thread_.message_loop() != MessageLoop::current()) { 132 DCHECK_NE(thread_.message_loop(), MessageLoop::current());
81 thread_.message_loop()->PostTask( 133
82 FROM_HERE, 134 thread_.message_loop()->PostTask(
83 base::Bind(&CompositorThread::AddInputHandler, base::Unretained(this), 135 FROM_HERE,
84 routing_id, input_handler_id)); 136 base::Bind(&CompositorThread::AddInputHandlerOnCompositorThread,
85 return; 137 base::Unretained(this),
86 } 138 routing_id,
139 input_handler_id,
140 base::MessageLoopProxy::current()));
141 }
142
143 void CompositorThread::AddInputHandlerOnCompositorThread(
144 int routing_id, int input_handler_id,
145 scoped_refptr<base::MessageLoopProxy> main_loop) {
146
147 DCHECK_EQ(thread_.message_loop(), MessageLoop::current());
87 148
88 WebCompositorInputHandler* input_handler = 149 WebCompositorInputHandler* input_handler =
89 WebCompositorInputHandler::fromIdentifier(input_handler_id); 150 WebCompositorInputHandler::fromIdentifier(input_handler_id);
90 if (!input_handler) 151 if (!input_handler)
91 return; 152 return;
92 153
93 if (input_handlers_.count(routing_id) != 0) { 154 if (input_handlers_.count(routing_id) != 0) {
94 // It's valid to call AddInputHandler() for the same routing id with the 155 // It's valid to call AddInputHandler() for the same routing id with the
95 // same input_handler many times, but it's not valid to change the 156 // same input_handler many times, but it's not valid to change the
96 // input_handler for a route. 157 // input_handler for a route.
97 DCHECK_EQ(input_handlers_[routing_id]->input_handler(), input_handler); 158 DCHECK_EQ(input_handlers_[routing_id]->input_handler(), input_handler);
98 return; 159 return;
99 } 160 }
100 161
101 filter_->AddRoute(routing_id); 162 filter_->AddRoute(routing_id);
102 input_handlers_[routing_id] = 163 input_handlers_[routing_id] =
103 make_linked_ptr(new InputHandlerWrapper(this, routing_id, input_handler)); 164 make_linked_ptr(new InputHandlerWrapper(this,
165 routing_id, input_handler, main_loop));
104 } 166 }
105 167
106 void CompositorThread::RemoveInputHandler(int routing_id) { 168 void CompositorThread::RemoveInputHandler(int routing_id) {
107 DCHECK(thread_.message_loop() == MessageLoop::current()); 169 DCHECK_EQ(MessageLoop::current(), thread_.message_loop());
108 170
109 filter_->RemoveRoute(routing_id); 171 filter_->RemoveRoute(routing_id);
110 input_handlers_.erase(routing_id); 172 input_handlers_.erase(routing_id);
111 } 173 }
112 174
113 void CompositorThread::HandleInputEvent( 175 void CompositorThread::HandleInputEvent(
114 int routing_id, 176 int routing_id,
115 const WebInputEvent* input_event) { 177 const WebInputEvent* input_event) {
116 DCHECK_EQ(MessageLoop::current(), thread_.message_loop()); 178 DCHECK_EQ(MessageLoop::current(), thread_.message_loop());
117 179
118 InputHandlerMap::iterator it = input_handlers_.find(routing_id); 180 InputHandlerMap::iterator it = input_handlers_.find(routing_id);
119 if (it == input_handlers_.end()) { 181 if (it == input_handlers_.end()) {
120 // Oops, we no longer have an interested input handler.. 182 // Oops, we no longer have an interested input handler..
121 filter_->DidNotHandleInputEvent(true); 183 filter_->DidNotHandleInputEvent(true);
122 return; 184 return;
123 } 185 }
124 186
125 it->second->input_handler()->handleInputEvent(*input_event); 187 it->second->input_handler()->handleInputEvent(*input_event);
126 } 188 }
OLDNEW
« no previous file with comments | « content/renderer/gpu/compositor_thread.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698