Index: content/renderer/compositor_mus_connection.cc |
diff --git a/content/renderer/compositor_mus_connection.cc b/content/renderer/compositor_mus_connection.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8323260508e0cd9bf735a5851c6205ee0f733a1d |
--- /dev/null |
+++ b/content/renderer/compositor_mus_connection.cc |
@@ -0,0 +1,136 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "content/renderer/compositor_mus_connection.h" |
+ |
+#include "base/single_thread_task_runner.h" |
+#include "content/common/input/web_input_event_traits.h" |
+#include "content/renderer/blink_input_events_type_converters.h" |
+#include "content/renderer/input/input_handler_manager.h" |
+#include "content/renderer/render_widget_mus_connection.h" |
+#include "ui/events/latency_info.h" |
+ |
+namespace content { |
+ |
+CompositorMusConnection::CompositorMusConnection( |
+ int routing_id, |
+ const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner, |
+ const scoped_refptr<base::SingleThreadTaskRunner>& compositor_task_runner, |
+ mojo::InterfaceRequest<mus::mojom::WindowTreeClient> request, |
+ InputHandlerManager* input_handler_manager) |
+ : routing_id_(routing_id), |
+ root_(nullptr), |
+ main_task_runner_(main_task_runner), |
+ compositor_task_runner_(compositor_task_runner), |
+ input_handler_manager_(input_handler_manager) { |
+ DCHECK(main_task_runner_->BelongsToCurrentThread()); |
+ compositor_task_runner_->PostTask( |
+ FROM_HERE, base::Bind(&CompositorMusConnection:: |
+ CreateWindowTreeConnectionOnCompositorThread, |
+ this, base::Passed(request.PassMessagePipe()))); |
+} |
+ |
+void CompositorMusConnection::AttachSurfaceOnMainThread( |
+ scoped_ptr<mus::WindowSurfaceBinding> surface_binding) { |
+ DCHECK(main_task_runner_->BelongsToCurrentThread()); |
+ compositor_task_runner_->PostTask( |
+ FROM_HERE, |
+ base::Bind(&CompositorMusConnection::AttachSurfaceOnCompositorThread, |
+ this, base::Passed(surface_binding.Pass()))); |
sadrul
2015/12/02 18:20:57
Can a WindowSurfaceBinding be safely moved to a di
Fady Samuel
2015/12/02 21:30:28
Technically yes, but I'll make that more explicit
|
+} |
+ |
+CompositorMusConnection::~CompositorMusConnection() {} |
+ |
+void CompositorMusConnection::AttachSurfaceOnCompositorThread( |
+ scoped_ptr<mus::WindowSurfaceBinding> surface_binding) { |
+ DCHECK(compositor_task_runner_->BelongsToCurrentThread()); |
+ window_surface_binding_ = surface_binding.Pass(); |
+ if (root_) { |
+ root_->AttachSurface(mus::mojom::SURFACE_TYPE_DEFAULT, |
+ window_surface_binding_.Pass()); |
+ } |
+} |
+ |
+void CompositorMusConnection::CreateWindowTreeConnectionOnCompositorThread( |
+ mojo::ScopedMessagePipeHandle window_tree_client_pipe) { |
+ DCHECK(compositor_task_runner_->BelongsToCurrentThread()); |
+ mus::WindowTreeConnection::Create( |
+ this, mojo::MakeRequest<mus::mojom::WindowTreeClient>( |
+ window_tree_client_pipe.Pass()), |
+ mus::WindowTreeConnection::CreateType::DONT_WAIT_FOR_EMBED); |
+} |
+ |
+void CompositorMusConnection::OnConnectionLostOnMainThread() { |
+ DCHECK(main_task_runner_->BelongsToCurrentThread()); |
+ RenderWidgetMusConnection* connection = |
+ RenderWidgetMusConnection::Get(routing_id_); |
+ if (!connection) |
+ return; |
+ connection->OnConnectionLost(); |
+} |
+ |
+void CompositorMusConnection::OnWindowInputEventOnMainThread( |
+ scoped_ptr<blink::WebInputEvent> web_event, |
+ const base::Closure& ack) { |
+ DCHECK(main_task_runner_->BelongsToCurrentThread()); |
+ RenderWidgetMusConnection* connection = |
+ RenderWidgetMusConnection::Get(routing_id_); |
+ if (!connection) { |
+ ack.Run(); |
+ return; |
+ } |
+ connection->OnWindowInputEvent(web_event.Pass()); |
+ ack.Run(); |
sadrul
2015/12/02 18:20:57
This could directly call OnWindowInputEventAckOnMa
Fady Samuel
2015/12/02 21:30:28
Well, this ACK was for handling by RenderWidgetMus
|
+} |
+ |
+void CompositorMusConnection::OnWindowInputEventAckOnMainThread( |
+ const base::Closure& ack) { |
+ DCHECK(main_task_runner_->BelongsToCurrentThread()); |
+ compositor_task_runner_->PostTask(FROM_HERE, ack); |
+} |
+ |
+void CompositorMusConnection::OnConnectionLost( |
+ mus::WindowTreeConnection* connection) { |
+ DCHECK(compositor_task_runner_->BelongsToCurrentThread()); |
+ main_task_runner_->PostTask( |
+ FROM_HERE, |
+ base::Bind(&CompositorMusConnection::OnConnectionLostOnMainThread, this)); |
+} |
+ |
+void CompositorMusConnection::OnEmbed(mus::Window* root) { |
+ DCHECK(compositor_task_runner_->BelongsToCurrentThread()); |
+ root_ = root; |
+ root_->AddObserver(this); |
+ if (window_surface_binding_) { |
+ root->AttachSurface(mus::mojom::SURFACE_TYPE_DEFAULT, |
+ window_surface_binding_.Pass()); |
+ } |
+} |
+ |
+void CompositorMusConnection::OnWindowInputEvent( |
+ mus::Window* window, |
+ const mus::mojom::EventPtr& event) { |
+ DCHECK(compositor_task_runner_->BelongsToCurrentThread()); |
+ scoped_ptr<blink::WebInputEvent> web_event = |
+ event.To<scoped_ptr<blink::WebInputEvent>>(); |
+ ui::LatencyInfo info; |
+ InputEventAckState ack_state = input_handler_manager_->HandleInputEvent( |
+ routing_id_, web_event.get(), &info); |
+ if (ack_state != INPUT_EVENT_ACK_STATE_NOT_CONSUMED) |
+ return; |
+ base::Closure ack = base::Bind(&base::DoNothing); |
sadrul
2015/12/02 18:20:57
Add a TODO(sad) here to do something more useful o
Fady Samuel
2015/12/02 21:30:28
Done.
|
+ const bool send_ack = |
+ WebInputEventTraits::WillReceiveAckFromRenderer(*web_event); |
+ if (send_ack) { |
+ // The ACK starts in the main thread and gets sent to the compositor thread. |
+ ack = base::Bind( |
+ &CompositorMusConnection::OnWindowInputEventAckOnMainThread, this, ack); |
+ } |
+ main_task_runner_->PostTask( |
+ FROM_HERE, |
+ base::Bind(&CompositorMusConnection::OnWindowInputEventOnMainThread, this, |
+ base::Passed(web_event.Pass()), ack)); |
+} |
+ |
+} // namespace content |