OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/WebCompositor.h" |
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositorClient.h
" | 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositorClient.h
" |
| 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositorInputHan
dler.h" |
11 | 12 |
12 using WebKit::WebCompositor; | 13 using WebKit::WebCompositorInputHandler; |
13 using WebKit::WebInputEvent; | 14 using WebKit::WebInputEvent; |
14 | 15 |
15 //------------------------------------------------------------------------------ | 16 //------------------------------------------------------------------------------ |
16 | 17 |
17 class CompositorThread::CompositorWrapper : public WebKit::WebCompositorClient { | 18 class CompositorThread::InputHandlerWrapper |
| 19 : public WebKit::WebCompositorClient { |
18 public: | 20 public: |
19 CompositorWrapper(CompositorThread* compositor_thread, | 21 InputHandlerWrapper(CompositorThread* compositor_thread, |
20 int routing_id, | 22 int routing_id, |
21 WebKit::WebCompositor* compositor) | 23 WebKit::WebCompositorInputHandler* input_handler) |
22 : compositor_thread_(compositor_thread), | 24 : compositor_thread_(compositor_thread), |
23 routing_id_(routing_id), | 25 routing_id_(routing_id), |
24 compositor_(compositor) { | 26 input_handler_(input_handler) { |
25 compositor_->setClient(this); | 27 input_handler_->setClient(this); |
26 } | 28 } |
27 | 29 |
28 virtual ~CompositorWrapper() { | 30 virtual ~InputHandlerWrapper() { |
29 compositor_->setClient(NULL); | 31 input_handler_->setClient(NULL); |
30 } | 32 } |
31 | 33 |
32 int routing_id() const { return routing_id_; } | 34 int routing_id() const { return routing_id_; } |
33 WebKit::WebCompositor* compositor() const { return compositor_; } | 35 WebKit::WebCompositorInputHandler* input_handler() const { |
| 36 return input_handler_; |
| 37 } |
34 | 38 |
35 // WebCompositorClient methods: | 39 // WebCompositorClient methods: |
36 | 40 |
37 virtual void willShutdown() { | 41 virtual void willShutdown() { |
38 compositor_thread_->RemoveCompositor(routing_id_); | 42 compositor_thread_->RemoveInputHandler(routing_id_); |
39 } | 43 } |
40 | 44 |
41 virtual void didHandleInputEvent() { | 45 virtual void didHandleInputEvent() { |
42 compositor_thread_->filter_->DidHandleInputEvent(); | 46 compositor_thread_->filter_->DidHandleInputEvent(); |
43 } | 47 } |
44 | 48 |
45 virtual void didNotHandleInputEvent(bool send_to_widget) { | 49 virtual void didNotHandleInputEvent(bool send_to_widget) { |
46 compositor_thread_->filter_->DidNotHandleInputEvent(send_to_widget); | 50 compositor_thread_->filter_->DidNotHandleInputEvent(send_to_widget); |
47 } | 51 } |
48 | 52 |
49 private: | 53 private: |
50 CompositorThread* compositor_thread_; | 54 CompositorThread* compositor_thread_; |
51 int routing_id_; | 55 int routing_id_; |
52 WebKit::WebCompositor* compositor_; | 56 WebKit::WebCompositorInputHandler* input_handler_; |
53 | 57 |
54 DISALLOW_COPY_AND_ASSIGN(CompositorWrapper); | 58 DISALLOW_COPY_AND_ASSIGN(InputHandlerWrapper); |
55 }; | 59 }; |
56 | 60 |
57 //------------------------------------------------------------------------------ | 61 //------------------------------------------------------------------------------ |
58 | 62 |
59 CompositorThread::CompositorThread(IPC::Channel::Listener* main_listener) | 63 CompositorThread::CompositorThread(IPC::Channel::Listener* main_listener) |
60 : thread_("Compositor") { | 64 : thread_("Compositor") { |
61 filter_ = | 65 filter_ = |
62 new InputEventFilter(main_listener, | 66 new InputEventFilter(main_listener, |
63 thread_.message_loop()->message_loop_proxy(), | 67 thread_.message_loop()->message_loop_proxy(), |
64 base::Bind(&CompositorThread::HandleInputEvent, | 68 base::Bind(&CompositorThread::HandleInputEvent, |
65 base::Unretained(this))); | 69 base::Unretained(this))); |
66 } | 70 } |
67 | 71 |
68 CompositorThread::~CompositorThread() { | 72 CompositorThread::~CompositorThread() { |
69 } | 73 } |
70 | 74 |
71 IPC::ChannelProxy::MessageFilter* CompositorThread::GetMessageFilter() const { | 75 IPC::ChannelProxy::MessageFilter* CompositorThread::GetMessageFilter() const { |
72 return filter_; | 76 return filter_; |
73 } | 77 } |
74 | 78 |
75 void CompositorThread::AddCompositor(int routing_id, int compositor_id) { | 79 void CompositorThread::AddInputHandler(int routing_id, int input_handler_id) { |
76 if (thread_.message_loop() != MessageLoop::current()) { | 80 if (thread_.message_loop() != MessageLoop::current()) { |
77 thread_.message_loop()->PostTask( | 81 thread_.message_loop()->PostTask( |
78 FROM_HERE, | 82 FROM_HERE, |
79 base::Bind(&CompositorThread::AddCompositor, base::Unretained(this), | 83 base::Bind(&CompositorThread::AddInputHandler, base::Unretained(this), |
80 routing_id, compositor_id)); | 84 routing_id, input_handler_id)); |
81 return; | 85 return; |
82 } | 86 } |
83 | 87 |
84 WebCompositor* compositor = WebCompositor::fromIdentifier(compositor_id); | 88 WebCompositorInputHandler* input_handler = |
85 if (!compositor) | 89 WebCompositorInputHandler::fromIdentifier(input_handler_id); |
| 90 if (!input_handler) |
86 return; | 91 return; |
87 | 92 |
88 if (compositors_.count(routing_id) != 0) { | 93 if (input_handlers_.count(routing_id) != 0) { |
89 // It's valid to call AddCompositor() for the same routing id with the same | 94 // It's valid to call AddInputHandler() for the same routing id with the |
90 // compositor many times, but it's not valid to change the compositor for | 95 // same input_handler many times, but it's not valid to change the |
91 // a route. | 96 // input_handler for a route. |
92 DCHECK_EQ(compositors_[routing_id]->compositor(), compositor); | 97 DCHECK_EQ(input_handlers_[routing_id]->input_handler(), input_handler); |
93 return; | 98 return; |
94 } | 99 } |
95 | 100 |
96 filter_->AddRoute(routing_id); | 101 filter_->AddRoute(routing_id); |
97 compositors_[routing_id] = | 102 input_handlers_[routing_id] = |
98 make_linked_ptr(new CompositorWrapper(this, routing_id, compositor)); | 103 make_linked_ptr(new InputHandlerWrapper(this, routing_id, input_handler)); |
99 } | 104 } |
100 | 105 |
101 void CompositorThread::RemoveCompositor(int routing_id) { | 106 void CompositorThread::RemoveInputHandler(int routing_id) { |
102 DCHECK(thread_.message_loop() == MessageLoop::current()); | 107 DCHECK(thread_.message_loop() == MessageLoop::current()); |
103 | 108 |
104 filter_->RemoveRoute(routing_id); | 109 filter_->RemoveRoute(routing_id); |
105 compositors_.erase(routing_id); | 110 input_handlers_.erase(routing_id); |
106 } | 111 } |
107 | 112 |
108 void CompositorThread::HandleInputEvent( | 113 void CompositorThread::HandleInputEvent( |
109 int routing_id, | 114 int routing_id, |
110 const WebInputEvent* input_event) { | 115 const WebInputEvent* input_event) { |
111 DCHECK_EQ(MessageLoop::current(), thread_.message_loop()); | 116 DCHECK_EQ(MessageLoop::current(), thread_.message_loop()); |
112 | 117 |
113 CompositorMap::iterator it = compositors_.find(routing_id); | 118 InputHandlerMap::iterator it = input_handlers_.find(routing_id); |
114 if (it == compositors_.end()) { | 119 if (it == input_handlers_.end()) { |
115 // Oops, we no longer have an interested compositor. | 120 // Oops, we no longer have an interested input handler.. |
116 filter_->DidNotHandleInputEvent(true); | 121 filter_->DidNotHandleInputEvent(true); |
117 return; | 122 return; |
118 } | 123 } |
119 | 124 |
120 it->second->compositor()->handleInputEvent(*input_event); | 125 it->second->input_handler()->handleInputEvent(*input_event); |
121 } | 126 } |
OLD | NEW |