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

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

Issue 10798006: Implement WebCompositorOutputSurface (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nit fixes Created 8 years, 5 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 "base/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
9 #include "content/common/view_messages.h"
9 #include "content/renderer/gpu/input_event_filter.h" 10 #include "content/renderer/gpu/input_event_filter.h"
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebActiveWheelFlingPa rameters.h" 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebActiveWheelFlingPa rameters.h"
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositorInputHan dlerClient.h" 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositorInputHan dlerClient.h"
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositorInputHan dler.h" 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositorInputHan dler.h"
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
14 15
15 using WebKit::WebCompositorInputHandler; 16 using WebKit::WebCompositorInputHandler;
16 using WebKit::WebInputEvent; 17 using WebKit::WebInputEvent;
17 18
18 //------------------------------------------------------------------------------ 19 //------------------------------------------------------------------------------
(...skipping 28 matching lines...) Expand all
47 return input_handler_; 48 return input_handler_;
48 } 49 }
49 50
50 // WebCompositorInputHandlerClient methods: 51 // WebCompositorInputHandlerClient methods:
51 52
52 virtual void willShutdown() { 53 virtual void willShutdown() {
53 compositor_thread_->RemoveInputHandler(routing_id_); 54 compositor_thread_->RemoveInputHandler(routing_id_);
54 } 55 }
55 56
56 virtual void didHandleInputEvent() { 57 virtual void didHandleInputEvent() {
57 compositor_thread_->filter_->DidHandleInputEvent(); 58 compositor_thread_->input_filter_->DidHandleInputEvent();
58 } 59 }
59 60
60 virtual void didNotHandleInputEvent(bool send_to_widget) { 61 virtual void didNotHandleInputEvent(bool send_to_widget) {
61 compositor_thread_->filter_->DidNotHandleInputEvent(send_to_widget); 62 compositor_thread_->input_filter_->DidNotHandleInputEvent(send_to_widget);
62 } 63 }
63 64
64 private: 65 private:
65 friend class base::RefCountedThreadSafe<InputHandlerWrapper>; 66 friend class base::RefCountedThreadSafe<InputHandlerWrapper>;
66 67
67 virtual ~InputHandlerWrapper() { 68 virtual ~InputHandlerWrapper() {
68 input_handler_->setClient(NULL); 69 input_handler_->setClient(NULL);
69 } 70 }
70 71
71 CompositorThread* compositor_thread_; 72 CompositorThread* compositor_thread_;
72 int routing_id_; 73 int routing_id_;
73 WebKit::WebCompositorInputHandler* input_handler_; 74 WebKit::WebCompositorInputHandler* input_handler_;
74 scoped_refptr<base::MessageLoopProxy> main_loop_; 75 scoped_refptr<base::MessageLoopProxy> main_loop_;
75 76
76 // Can only be accessed on the main thread. 77 // Can only be accessed on the main thread.
77 base::WeakPtr<RenderViewImpl> render_view_impl_; 78 base::WeakPtr<RenderViewImpl> render_view_impl_;
78 79
79 DISALLOW_COPY_AND_ASSIGN(InputHandlerWrapper); 80 DISALLOW_COPY_AND_ASSIGN(InputHandlerWrapper);
80 }; 81 };
81 82
82 //------------------------------------------------------------------------------ 83 //------------------------------------------------------------------------------
83 84
84 CompositorThread::CompositorThread(IPC::Listener* main_listener) 85 CompositorThread::CompositorThread(IPC::Listener* main_listener)
85 : thread_("Compositor") { 86 : thread_("Compositor") {
86 filter_ = 87 input_filter_ =
87 new InputEventFilter(main_listener, 88 new InputEventFilter(main_listener,
88 thread_.message_loop()->message_loop_proxy(), 89 thread_.message_loop()->message_loop_proxy(),
89 base::Bind(&CompositorThread::HandleInputEvent, 90 base::Bind(&CompositorThread::HandleInputEvent,
90 base::Unretained(this))); 91 base::Unretained(this)));
92
93 uint32 messages[] = {ViewMsg_UpdateVSyncParameters::ID};
darin (slow to review) 2012/07/24 23:56:43 nit: const uint32 kMessages[] = { ViewMsg_...::ID
94 compositor_filter_ =
95 new IPC::ForwardingMessageFilter(
96 messages, arraysize(messages),
97 thread_.message_loop()->message_loop_proxy(),
98 base::Bind(&CompositorThread::OnCompositorMessageReceived,
99 base::Unretained(this)));
91 } 100 }
92 101
93 CompositorThread::~CompositorThread() { 102 CompositorThread::~CompositorThread() {
94 } 103 }
95 104
96 IPC::ChannelProxy::MessageFilter* CompositorThread::GetMessageFilter() const { 105 IPC::ChannelProxy::MessageFilter* CompositorThread::GetInputFilter() const {
97 return filter_; 106 return input_filter_;
98 } 107 }
99 108
100 void CompositorThread::AddInputHandler( 109 IPC::ChannelProxy::MessageFilter*
110 CompositorThread::GetCompositorFilter() const {
111 return compositor_filter_;
112 }
113
darin (slow to review) 2012/07/24 23:56:43 nit: extra new line
114
115 void CompositorThread::AddHandlers(
101 int routing_id, int input_handler_id, 116 int routing_id, int input_handler_id,
102 const base::WeakPtr<RenderViewImpl>& render_view_impl) { 117 const base::WeakPtr<RenderViewImpl>& render_view_impl) {
103 DCHECK_NE(thread_.message_loop(), MessageLoop::current()); 118 DCHECK_NE(thread_.message_loop(), MessageLoop::current());
104 119
105 thread_.message_loop()->PostTask( 120 thread_.message_loop()->PostTask(
106 FROM_HERE, 121 FROM_HERE,
107 base::Bind(&CompositorThread::AddInputHandlerOnCompositorThread, 122 base::Bind(&CompositorThread::AddHandlersOnCompositorThread,
108 base::Unretained(this), 123 base::Unretained(this),
109 routing_id, 124 routing_id,
110 input_handler_id, 125 input_handler_id,
111 base::MessageLoopProxy::current(), 126 base::MessageLoopProxy::current(),
112 render_view_impl)); 127 render_view_impl));
113 } 128 }
114 129
115 void CompositorThread::AddInputHandlerOnCompositorThread( 130 void CompositorThread::AddHandlersOnCompositorThread(
116 int routing_id, int input_handler_id, 131 int routing_id, int input_handler_id,
117 scoped_refptr<base::MessageLoopProxy> main_loop, 132 scoped_refptr<base::MessageLoopProxy> main_loop,
118 const base::WeakPtr<RenderViewImpl>& render_view_impl) { 133 const base::WeakPtr<RenderViewImpl>& render_view_impl) {
119 134
120 DCHECK_EQ(thread_.message_loop(), MessageLoop::current()); 135 DCHECK_EQ(thread_.message_loop(), MessageLoop::current());
121 136
122 WebCompositorInputHandler* input_handler = 137 WebCompositorInputHandler* input_handler =
123 WebCompositorInputHandler::fromIdentifier(input_handler_id); 138 WebCompositorInputHandler::fromIdentifier(input_handler_id);
124 if (!input_handler) 139 if (!input_handler)
125 return; 140 return;
126 141
127 if (input_handlers_.count(routing_id) != 0) { 142 if (input_handlers_.count(routing_id) != 0) {
128 // It's valid to call AddInputHandler() for the same routing id with the 143 // It's valid to call AddInputHandler() for the same routing id with the
129 // same input_handler many times, but it's not valid to change the 144 // same input_handler many times, but it's not valid to change the
130 // input_handler for a route. 145 // input_handler for a route.
131 DCHECK_EQ(input_handlers_[routing_id]->input_handler(), input_handler); 146 DCHECK_EQ(input_handlers_[routing_id]->input_handler(), input_handler);
132 return; 147 return;
133 } 148 }
134 149
135 TRACE_EVENT0("CompositorThread::AddInputHandler", "AddingRoute"); 150 TRACE_EVENT0("renderer", "CompositorThread::AddHandlersOnCompositorThread");
136 filter_->AddRoute(routing_id); 151 input_filter_->AddRoute(routing_id);
152 compositor_filter_->AddRoute(routing_id);
137 input_handlers_[routing_id] = 153 input_handlers_[routing_id] =
138 make_scoped_refptr(new InputHandlerWrapper(this, 154 make_scoped_refptr(new InputHandlerWrapper(this,
139 routing_id, input_handler, main_loop, render_view_impl)); 155 routing_id, input_handler, main_loop, render_view_impl));
140 } 156 }
141 157
142 void CompositorThread::RemoveInputHandler(int routing_id) { 158 void CompositorThread::RemoveInputHandler(int routing_id) {
143 DCHECK_EQ(MessageLoop::current(), thread_.message_loop()); 159 DCHECK_EQ(MessageLoop::current(), thread_.message_loop());
144 160
145 TRACE_EVENT0("CompositorThread::RemoveInputHandler", "RemovingRoute"); 161 TRACE_EVENT0("renderer", "CompositorThread::RemoveInputHandler");
146 162
147 filter_->RemoveRoute(routing_id); 163 input_filter_->RemoveRoute(routing_id);
164 compositor_filter_->RemoveRoute(routing_id);
148 input_handlers_.erase(routing_id); 165 input_handlers_.erase(routing_id);
149 } 166 }
150 167
151 void CompositorThread::HandleInputEvent( 168 void CompositorThread::HandleInputEvent(
152 int routing_id, 169 int routing_id,
153 const WebInputEvent* input_event) { 170 const WebInputEvent* input_event) {
171 TRACE_EVENT0("renderer", "CompositorThread::HandleInputEvent");
154 DCHECK_EQ(MessageLoop::current(), thread_.message_loop()); 172 DCHECK_EQ(MessageLoop::current(), thread_.message_loop());
155 173
156 InputHandlerMap::iterator it = input_handlers_.find(routing_id); 174 InputHandlerMap::iterator it = input_handlers_.find(routing_id);
157 if (it == input_handlers_.end()) { 175 if (it == input_handlers_.end()) {
158 TRACE_EVENT0("CompositorThread::HandleInputEvent", "NoInputHandlerFound"); 176 TRACE_EVENT0("renderer", "NoInputHandlerFound");
159 // Oops, we no longer have an interested input handler.. 177 // Oops, we no longer have an interested input handler..
160 filter_->DidNotHandleInputEvent(true); 178 input_filter_->DidNotHandleInputEvent(true);
161 return; 179 return;
162 } 180 }
163 181
164 it->second->input_handler()->handleInputEvent(*input_event); 182 it->second->input_handler()->handleInputEvent(*input_event);
165 } 183 }
184
185 void CompositorThread::OnCompositorMessageReceived(
186 const IPC::Message& message) {
187 TRACE_EVENT0("renderer", "CompositorThread::OnCompositorMessageReceived");
188 DCHECK_EQ(message.type(), ViewMsg_UpdateVSyncParameters::ID);
189
190 InputHandlerMap::iterator it = input_handlers_.find(message.routing_id());
darin (slow to review) 2012/07/24 23:56:43 on the webkit side, perhaps we should be pushing t
191 if (it == input_handlers_.end())
192 return;
193
194 // TODO(nduca): Push the updated vsync paramters to the compositor.
195 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698