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

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

Issue 9802006: Implement active wheel fling transfer via WebCompositorInputHandlerClient (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cut unnecessary includes 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
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 "third_party/WebKit/Source/WebKit/chromium/public/WebActiveWheelFlingPa rameters.h"
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositorClient.h " 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositorInputHan dlerClient.h"
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositorInputHan dler.h" 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositorInputHan dler.h"
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
12 13
13 using WebKit::WebCompositorInputHandler; 14 using WebKit::WebCompositorInputHandler;
14 using WebKit::WebInputEvent; 15 using WebKit::WebInputEvent;
15 16
16 //------------------------------------------------------------------------------ 17 //------------------------------------------------------------------------------
17 18
18 class CompositorThread::InputHandlerWrapper 19 class CompositorThread::InputHandlerWrapper
19 : public WebKit::WebCompositorClient { 20 : public WebKit::WebCompositorInputHandlerClient,
21 public base::RefCountedThreadSafe<InputHandlerWrapper> {
20 public: 22 public:
21 InputHandlerWrapper(CompositorThread* compositor_thread, 23 InputHandlerWrapper(CompositorThread* compositor_thread,
22 int routing_id, 24 int routing_id,
23 WebKit::WebCompositorInputHandler* input_handler) 25 WebKit::WebCompositorInputHandler* input_handler,
26 scoped_refptr<base::MessageLoopProxy> main_loop,
27 base::WeakPtr<RenderViewImpl> render_view_impl)
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_impl_(render_view_impl) {
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 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 void TransferActiveWheelFlingAnimation(
darin (slow to review) 2012/03/27 03:47:54 Another approach would be to define this as a publ
70 WebKit::WebActiveWheelFlingParameters params) {
71 DCHECK(main_loop_->BelongsToCurrentThread());
72 if (render_view_impl_.get() && render_view_impl_->webview())
73 render_view_impl_->webview()->transferActiveWheelFlingAnimation(params);
darin (slow to review) 2012/03/27 03:47:54 nit: indentation
74 }
75
54 CompositorThread* compositor_thread_; 76 CompositorThread* compositor_thread_;
55 int routing_id_; 77 int routing_id_;
56 WebKit::WebCompositorInputHandler* input_handler_; 78 WebKit::WebCompositorInputHandler* input_handler_;
79 scoped_refptr<base::MessageLoopProxy> main_loop_;
80
81 // Can only be accessed on the main thread.
82 base::WeakPtr<RenderViewImpl> render_view_impl_;
57 83
58 DISALLOW_COPY_AND_ASSIGN(InputHandlerWrapper); 84 DISALLOW_COPY_AND_ASSIGN(InputHandlerWrapper);
59 }; 85 };
60 86
61 //------------------------------------------------------------------------------ 87 //------------------------------------------------------------------------------
62 88
63 CompositorThread::CompositorThread(IPC::Channel::Listener* main_listener) 89 CompositorThread::CompositorThread(IPC::Channel::Listener* main_listener)
64 : thread_("Compositor") { 90 : thread_("Compositor") {
65 filter_ = 91 filter_ =
66 new InputEventFilter(main_listener, 92 new InputEventFilter(main_listener,
67 thread_.message_loop()->message_loop_proxy(), 93 thread_.message_loop()->message_loop_proxy(),
68 base::Bind(&CompositorThread::HandleInputEvent, 94 base::Bind(&CompositorThread::HandleInputEvent,
69 base::Unretained(this))); 95 base::Unretained(this)));
70 } 96 }
71 97
72 CompositorThread::~CompositorThread() { 98 CompositorThread::~CompositorThread() {
73 } 99 }
74 100
75 IPC::ChannelProxy::MessageFilter* CompositorThread::GetMessageFilter() const { 101 IPC::ChannelProxy::MessageFilter* CompositorThread::GetMessageFilter() const {
76 return filter_; 102 return filter_;
77 } 103 }
78 104
79 void CompositorThread::AddInputHandler(int routing_id, int input_handler_id) { 105 void CompositorThread::AddInputHandler(
80 if (thread_.message_loop() != MessageLoop::current()) { 106 int routing_id, int input_handler_id,
81 thread_.message_loop()->PostTask( 107 base::WeakPtr<RenderViewImpl> render_view_impl) {
darin (slow to review) 2012/03/27 03:47:54 nit: pass WeakPtr by const ref
82 FROM_HERE, 108 DCHECK_NE(thread_.message_loop(), MessageLoop::current());
83 base::Bind(&CompositorThread::AddInputHandler, base::Unretained(this), 109
84 routing_id, input_handler_id)); 110 thread_.message_loop()->PostTask(
85 return; 111 FROM_HERE,
86 } 112 base::Bind(&CompositorThread::AddInputHandlerOnCompositorThread,
113 base::Unretained(this),
114 routing_id,
115 input_handler_id,
116 base::MessageLoopProxy::current(),
117 render_view_impl));
118 }
119
120 void CompositorThread::AddInputHandlerOnCompositorThread(
121 int routing_id, int input_handler_id,
122 scoped_refptr<base::MessageLoopProxy> main_loop,
123 base::WeakPtr<RenderViewImpl> render_view_impl) {
darin (slow to review) 2012/03/27 03:47:54 nit: pass WeakPtr by const ref
124
125 DCHECK_EQ(thread_.message_loop(), MessageLoop::current());
87 126
88 WebCompositorInputHandler* input_handler = 127 WebCompositorInputHandler* input_handler =
89 WebCompositorInputHandler::fromIdentifier(input_handler_id); 128 WebCompositorInputHandler::fromIdentifier(input_handler_id);
90 if (!input_handler) 129 if (!input_handler)
91 return; 130 return;
92 131
93 if (input_handlers_.count(routing_id) != 0) { 132 if (input_handlers_.count(routing_id) != 0) {
94 // It's valid to call AddInputHandler() for the same routing id with the 133 // 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 134 // same input_handler many times, but it's not valid to change the
96 // input_handler for a route. 135 // input_handler for a route.
97 DCHECK_EQ(input_handlers_[routing_id]->input_handler(), input_handler); 136 DCHECK_EQ(input_handlers_[routing_id]->input_handler(), input_handler);
98 return; 137 return;
99 } 138 }
100 139
101 filter_->AddRoute(routing_id); 140 filter_->AddRoute(routing_id);
102 input_handlers_[routing_id] = 141 input_handlers_[routing_id] =
103 make_linked_ptr(new InputHandlerWrapper(this, routing_id, input_handler)); 142 make_scoped_refptr(new InputHandlerWrapper(this,
143 routing_id, input_handler, main_loop, render_view_impl));
104 } 144 }
105 145
106 void CompositorThread::RemoveInputHandler(int routing_id) { 146 void CompositorThread::RemoveInputHandler(int routing_id) {
107 DCHECK(thread_.message_loop() == MessageLoop::current()); 147 DCHECK_EQ(MessageLoop::current(), thread_.message_loop());
108 148
109 filter_->RemoveRoute(routing_id); 149 filter_->RemoveRoute(routing_id);
110 input_handlers_.erase(routing_id); 150 input_handlers_.erase(routing_id);
111 } 151 }
112 152
113 void CompositorThread::HandleInputEvent( 153 void CompositorThread::HandleInputEvent(
114 int routing_id, 154 int routing_id,
115 const WebInputEvent* input_event) { 155 const WebInputEvent* input_event) {
116 DCHECK_EQ(MessageLoop::current(), thread_.message_loop()); 156 DCHECK_EQ(MessageLoop::current(), thread_.message_loop());
117 157
118 InputHandlerMap::iterator it = input_handlers_.find(routing_id); 158 InputHandlerMap::iterator it = input_handlers_.find(routing_id);
119 if (it == input_handlers_.end()) { 159 if (it == input_handlers_.end()) {
120 // Oops, we no longer have an interested input handler.. 160 // Oops, we no longer have an interested input handler..
121 filter_->DidNotHandleInputEvent(true); 161 filter_->DidNotHandleInputEvent(true);
122 return; 162 return;
123 } 163 }
124 164
125 it->second->input_handler()->handleInputEvent(*input_event); 165 it->second->input_handler()->handleInputEvent(*input_event);
126 } 166 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698