OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/renderer/compositor_mus_connection.h" | |
6 | |
7 #include "base/single_thread_task_runner.h" | |
8 #include "content/common/input/web_input_event_traits.h" | |
9 #include "content/renderer/input/input_handler_manager.h" | |
10 #include "content/renderer/render_widget_mus_connection.h" | |
11 #include "mojo/converters/blink/blink_input_events_type_converters.h" | |
12 #include "ui/events/latency_info.h" | |
13 | |
14 namespace content { | |
15 | |
16 CompositorMusConnection::CompositorMusConnection( | |
17 int routing_id, | |
18 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner, | |
19 const scoped_refptr<base::SingleThreadTaskRunner>& compositor_task_runner, | |
20 mojo::InterfaceRequest<mus::mojom::WindowTreeClient> request, | |
21 InputHandlerManager* input_handler_manager) | |
22 : routing_id_(routing_id), | |
23 root_(nullptr), | |
24 main_task_runner_(main_task_runner), | |
25 compositor_task_runner_(compositor_task_runner), | |
26 input_handler_manager_(input_handler_manager) { | |
27 DCHECK(main_task_runner_->BelongsToCurrentThread()); | |
28 compositor_task_runner_->PostTask( | |
29 FROM_HERE, base::Bind(&CompositorMusConnection:: | |
30 CreateWindowTreeConnectionOnCompositorThread, | |
31 this, base::Passed(request.PassMessagePipe()))); | |
Ben Goodger (Google)
2015/12/03 06:35:53
is there no typesafe way to pass an interface requ
Fady Samuel
2015/12/03 16:42:12
Nope, I don't see a way to do this unfortunately.
| |
32 } | |
33 | |
34 void CompositorMusConnection::AttachSurfaceOnMainThread( | |
35 scoped_ptr<mus::WindowSurfaceBinding> surface_binding) { | |
36 DCHECK(main_task_runner_->BelongsToCurrentThread()); | |
37 compositor_task_runner_->PostTask( | |
38 FROM_HERE, | |
39 base::Bind(&CompositorMusConnection::AttachSurfaceOnCompositorThread, | |
40 this, base::Passed(surface_binding.Pass()))); | |
41 } | |
42 | |
43 CompositorMusConnection::~CompositorMusConnection() {} | |
44 | |
45 void CompositorMusConnection::AttachSurfaceOnCompositorThread( | |
46 scoped_ptr<mus::WindowSurfaceBinding> surface_binding) { | |
47 DCHECK(compositor_task_runner_->BelongsToCurrentThread()); | |
48 window_surface_binding_ = surface_binding.Pass(); | |
49 if (root_) { | |
50 root_->AttachSurface(mus::mojom::SURFACE_TYPE_DEFAULT, | |
51 window_surface_binding_.Pass()); | |
52 } | |
53 } | |
54 | |
55 void CompositorMusConnection::CreateWindowTreeConnectionOnCompositorThread( | |
56 mojo::ScopedMessagePipeHandle window_tree_client_pipe) { | |
57 DCHECK(compositor_task_runner_->BelongsToCurrentThread()); | |
58 mus::WindowTreeConnection::Create( | |
59 this, mojo::MakeRequest<mus::mojom::WindowTreeClient>( | |
60 window_tree_client_pipe.Pass()), | |
61 mus::WindowTreeConnection::CreateType::DONT_WAIT_FOR_EMBED); | |
62 } | |
63 | |
64 void CompositorMusConnection::OnConnectionLostOnMainThread() { | |
65 DCHECK(main_task_runner_->BelongsToCurrentThread()); | |
66 RenderWidgetMusConnection* connection = | |
67 RenderWidgetMusConnection::Get(routing_id_); | |
68 if (!connection) | |
69 return; | |
70 connection->OnConnectionLost(); | |
71 } | |
72 | |
73 void CompositorMusConnection::OnWindowInputEventOnMainThread( | |
74 scoped_ptr<blink::WebInputEvent> web_event, | |
75 const base::Closure& ack) { | |
76 DCHECK(main_task_runner_->BelongsToCurrentThread()); | |
77 RenderWidgetMusConnection* connection = | |
78 RenderWidgetMusConnection::Get(routing_id_); | |
79 if (!connection) { | |
80 ack.Run(); | |
81 return; | |
82 } | |
83 connection->OnWindowInputEvent(web_event.Pass(), ack); | |
84 } | |
85 | |
86 void CompositorMusConnection::OnWindowInputEventAckOnMainThread( | |
87 const base::Closure& ack) { | |
88 DCHECK(main_task_runner_->BelongsToCurrentThread()); | |
89 compositor_task_runner_->PostTask(FROM_HERE, ack); | |
90 } | |
91 | |
92 void CompositorMusConnection::OnConnectionLost( | |
93 mus::WindowTreeConnection* connection) { | |
94 DCHECK(compositor_task_runner_->BelongsToCurrentThread()); | |
95 main_task_runner_->PostTask( | |
96 FROM_HERE, | |
97 base::Bind(&CompositorMusConnection::OnConnectionLostOnMainThread, this)); | |
98 } | |
99 | |
100 void CompositorMusConnection::OnEmbed(mus::Window* root) { | |
101 DCHECK(compositor_task_runner_->BelongsToCurrentThread()); | |
102 root_ = root; | |
103 root_->AddObserver(this); | |
104 if (window_surface_binding_) { | |
105 root->AttachSurface(mus::mojom::SURFACE_TYPE_DEFAULT, | |
106 window_surface_binding_.Pass()); | |
107 } | |
108 } | |
109 | |
110 void CompositorMusConnection::OnWindowInputEvent( | |
111 mus::Window* window, | |
112 const mus::mojom::EventPtr& event) { | |
113 DCHECK(compositor_task_runner_->BelongsToCurrentThread()); | |
114 scoped_ptr<blink::WebInputEvent> web_event = | |
115 event.To<scoped_ptr<blink::WebInputEvent>>(); | |
116 // TODO(sad): We probably need to plumb LatencyInfo through Mus. | |
117 ui::LatencyInfo info; | |
118 InputEventAckState ack_state = input_handler_manager_->HandleInputEvent( | |
119 routing_id_, web_event.get(), &info); | |
120 if (ack_state != INPUT_EVENT_ACK_STATE_NOT_CONSUMED) | |
121 return; | |
122 // TODO(sad): Do something more useful once we can do async acks. | |
123 base::Closure ack = base::Bind(&base::DoNothing); | |
124 const bool send_ack = | |
125 WebInputEventTraits::WillReceiveAckFromRenderer(*web_event); | |
126 if (send_ack) { | |
127 // The ACK starts in the main thread and gets sent to the compositor thread. | |
128 ack = base::Bind( | |
129 &CompositorMusConnection::OnWindowInputEventAckOnMainThread, this, ack); | |
Ben Goodger (Google)
2015/12/03 06:35:53
why does it have to bounce thru main thread like t
Fady Samuel
2015/12/03 16:42:12
Once Sadrul completes manual/explicit event ACKing
| |
130 } | |
131 main_task_runner_->PostTask( | |
132 FROM_HERE, | |
133 base::Bind(&CompositorMusConnection::OnWindowInputEventOnMainThread, this, | |
134 base::Passed(web_event.Pass()), ack)); | |
135 } | |
136 | |
137 } // namespace content | |
OLD | NEW |