Chromium Code Reviews| 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 "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 const 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(&RenderViewImpl::TransferActiveWheelFlingAnimation, | |
| 41 render_view_impl_, params)); | |
| 42 } | |
| 43 | |
| 30 virtual ~InputHandlerWrapper() { | 44 virtual ~InputHandlerWrapper() { |
| 31 input_handler_->setClient(NULL); | 45 input_handler_->setClient(NULL); |
| 32 } | 46 } |
| 33 | 47 |
| 34 int routing_id() const { return routing_id_; } | 48 int routing_id() const { return routing_id_; } |
| 35 WebKit::WebCompositorInputHandler* input_handler() const { | 49 WebKit::WebCompositorInputHandler* input_handler() const { |
| 36 return input_handler_; | 50 return input_handler_; |
| 37 } | 51 } |
| 38 | 52 |
| 39 // WebCompositorClient methods: | 53 // WebCompositorInputHandlerClient methods: |
| 40 | 54 |
| 41 virtual void willShutdown() { | 55 virtual void willShutdown() { |
| 42 compositor_thread_->RemoveInputHandler(routing_id_); | 56 compositor_thread_->RemoveInputHandler(routing_id_); |
| 43 } | 57 } |
| 44 | 58 |
| 45 virtual void didHandleInputEvent() { | 59 virtual void didHandleInputEvent() { |
| 46 compositor_thread_->filter_->DidHandleInputEvent(); | 60 compositor_thread_->filter_->DidHandleInputEvent(); |
| 47 } | 61 } |
| 48 | 62 |
| 49 virtual void didNotHandleInputEvent(bool send_to_widget) { | 63 virtual void didNotHandleInputEvent(bool send_to_widget) { |
| 50 compositor_thread_->filter_->DidNotHandleInputEvent(send_to_widget); | 64 compositor_thread_->filter_->DidNotHandleInputEvent(send_to_widget); |
| 51 } | 65 } |
| 52 | 66 |
| 53 private: | 67 private: |
| 54 CompositorThread* compositor_thread_; | 68 CompositorThread* compositor_thread_; |
| 55 int routing_id_; | 69 int routing_id_; |
| 56 WebKit::WebCompositorInputHandler* input_handler_; | 70 WebKit::WebCompositorInputHandler* input_handler_; |
| 71 scoped_refptr<base::MessageLoopProxy> main_loop_; | |
| 72 | |
| 73 // Can only be accessed on the main thread. | |
| 74 base::WeakPtr<RenderViewImpl> render_view_impl_; | |
| 57 | 75 |
| 58 DISALLOW_COPY_AND_ASSIGN(InputHandlerWrapper); | 76 DISALLOW_COPY_AND_ASSIGN(InputHandlerWrapper); |
| 59 }; | 77 }; |
| 60 | 78 |
| 61 //------------------------------------------------------------------------------ | 79 //------------------------------------------------------------------------------ |
| 62 | 80 |
| 63 CompositorThread::CompositorThread(IPC::Channel::Listener* main_listener) | 81 CompositorThread::CompositorThread(IPC::Channel::Listener* main_listener) |
| 64 : thread_("Compositor") { | 82 : thread_("Compositor") { |
| 65 filter_ = | 83 filter_ = |
| 66 new InputEventFilter(main_listener, | 84 new InputEventFilter(main_listener, |
| 67 thread_.message_loop()->message_loop_proxy(), | 85 thread_.message_loop()->message_loop_proxy(), |
| 68 base::Bind(&CompositorThread::HandleInputEvent, | 86 base::Bind(&CompositorThread::HandleInputEvent, |
| 69 base::Unretained(this))); | 87 base::Unretained(this))); |
| 70 } | 88 } |
| 71 | 89 |
| 72 CompositorThread::~CompositorThread() { | 90 CompositorThread::~CompositorThread() { |
| 73 } | 91 } |
| 74 | 92 |
| 75 IPC::ChannelProxy::MessageFilter* CompositorThread::GetMessageFilter() const { | 93 IPC::ChannelProxy::MessageFilter* CompositorThread::GetMessageFilter() const { |
| 76 return filter_; | 94 return filter_; |
| 77 } | 95 } |
| 78 | 96 |
| 79 void CompositorThread::AddInputHandler(int routing_id, int input_handler_id) { | 97 void CompositorThread::AddInputHandler( |
| 80 if (thread_.message_loop() != MessageLoop::current()) { | 98 int routing_id, int input_handler_id, |
| 81 thread_.message_loop()->PostTask( | 99 const base::WeakPtr<RenderViewImpl>& render_view_impl) { |
| 82 FROM_HERE, | 100 DCHECK_NE(thread_.message_loop(), MessageLoop::current()); |
| 83 base::Bind(&CompositorThread::AddInputHandler, base::Unretained(this), | 101 |
| 84 routing_id, input_handler_id)); | 102 thread_.message_loop()->PostTask( |
| 85 return; | 103 FROM_HERE, |
| 86 } | 104 base::Bind(&CompositorThread::AddInputHandlerOnCompositorThread, |
| 105 base::Unretained(this), | |
| 106 routing_id, | |
| 107 input_handler_id, | |
| 108 base::MessageLoopProxy::current(), | |
| 109 render_view_impl)); | |
|
jamesr
2012/03/27 17:38:57
Since you asked for const ref on the WeakPtr I'm a
| |
| 110 } | |
| 111 | |
| 112 void CompositorThread::AddInputHandlerOnCompositorThread( | |
| 113 int routing_id, int input_handler_id, | |
| 114 scoped_refptr<base::MessageLoopProxy> main_loop, | |
| 115 const base::WeakPtr<RenderViewImpl>& render_view_impl) { | |
| 116 | |
| 117 DCHECK_EQ(thread_.message_loop(), MessageLoop::current()); | |
| 87 | 118 |
| 88 WebCompositorInputHandler* input_handler = | 119 WebCompositorInputHandler* input_handler = |
| 89 WebCompositorInputHandler::fromIdentifier(input_handler_id); | 120 WebCompositorInputHandler::fromIdentifier(input_handler_id); |
| 90 if (!input_handler) | 121 if (!input_handler) |
| 91 return; | 122 return; |
| 92 | 123 |
| 93 if (input_handlers_.count(routing_id) != 0) { | 124 if (input_handlers_.count(routing_id) != 0) { |
| 94 // It's valid to call AddInputHandler() for the same routing id with the | 125 // 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 | 126 // same input_handler many times, but it's not valid to change the |
| 96 // input_handler for a route. | 127 // input_handler for a route. |
| 97 DCHECK_EQ(input_handlers_[routing_id]->input_handler(), input_handler); | 128 DCHECK_EQ(input_handlers_[routing_id]->input_handler(), input_handler); |
| 98 return; | 129 return; |
| 99 } | 130 } |
| 100 | 131 |
| 101 filter_->AddRoute(routing_id); | 132 filter_->AddRoute(routing_id); |
| 102 input_handlers_[routing_id] = | 133 input_handlers_[routing_id] = |
| 103 make_linked_ptr(new InputHandlerWrapper(this, routing_id, input_handler)); | 134 make_scoped_refptr(new InputHandlerWrapper(this, |
| 135 routing_id, input_handler, main_loop, render_view_impl)); | |
| 104 } | 136 } |
| 105 | 137 |
| 106 void CompositorThread::RemoveInputHandler(int routing_id) { | 138 void CompositorThread::RemoveInputHandler(int routing_id) { |
| 107 DCHECK(thread_.message_loop() == MessageLoop::current()); | 139 DCHECK_EQ(MessageLoop::current(), thread_.message_loop()); |
| 108 | 140 |
| 109 filter_->RemoveRoute(routing_id); | 141 filter_->RemoveRoute(routing_id); |
| 110 input_handlers_.erase(routing_id); | 142 input_handlers_.erase(routing_id); |
| 111 } | 143 } |
| 112 | 144 |
| 113 void CompositorThread::HandleInputEvent( | 145 void CompositorThread::HandleInputEvent( |
| 114 int routing_id, | 146 int routing_id, |
| 115 const WebInputEvent* input_event) { | 147 const WebInputEvent* input_event) { |
| 116 DCHECK_EQ(MessageLoop::current(), thread_.message_loop()); | 148 DCHECK_EQ(MessageLoop::current(), thread_.message_loop()); |
| 117 | 149 |
| 118 InputHandlerMap::iterator it = input_handlers_.find(routing_id); | 150 InputHandlerMap::iterator it = input_handlers_.find(routing_id); |
| 119 if (it == input_handlers_.end()) { | 151 if (it == input_handlers_.end()) { |
| 120 // Oops, we no longer have an interested input handler.. | 152 // Oops, we no longer have an interested input handler.. |
| 121 filter_->DidNotHandleInputEvent(true); | 153 filter_->DidNotHandleInputEvent(true); |
| 122 return; | 154 return; |
| 123 } | 155 } |
| 124 | 156 |
| 125 it->second->input_handler()->handleInputEvent(*input_event); | 157 it->second->input_handler()->handleInputEvent(*input_event); |
| 126 } | 158 } |
| OLD | NEW |