OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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/mus/render_widget_mus_connection.h" | 5 #include "content/renderer/mus/render_widget_mus_connection.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "content/renderer/mus/compositor_mus_connection.h" | |
12 #include "content/renderer/render_thread_impl.h" | 11 #include "content/renderer/render_thread_impl.h" |
13 #include "content/renderer/render_view_impl.h" | 12 #include "content/renderer/render_view_impl.h" |
14 #include "services/ui/public/cpp/window_compositor_frame_sink.h" | 13 #include "services/ui/public/cpp/window_compositor_frame_sink.h" |
15 #include "services/ui/public/interfaces/window_tree.mojom.h" | 14 #include "services/ui/public/interfaces/window_tree.mojom.h" |
16 | 15 |
17 namespace content { | 16 namespace content { |
18 | 17 |
19 namespace { | 18 namespace { |
20 | 19 |
21 typedef std::map<int, RenderWidgetMusConnection*> ConnectionMap; | 20 typedef std::map<int, RenderWidgetMusConnection*> ConnectionMap; |
22 base::LazyInstance<ConnectionMap>::Leaky g_connections = | 21 base::LazyInstance<ConnectionMap>::Leaky g_connections = |
23 LAZY_INSTANCE_INITIALIZER; | 22 LAZY_INSTANCE_INITIALIZER; |
24 } | 23 } |
25 | 24 |
26 void RenderWidgetMusConnection::Bind( | 25 void RenderWidgetMusConnection::Bind( |
27 mojo::InterfaceRequest<ui::mojom::WindowTreeClient> request) { | 26 mojo::InterfaceRequest<ui::mojom::WindowTreeClient> request) { |
28 DCHECK(thread_checker_.CalledOnValidThread()); | 27 // TODO(sad): crbug.com/672913 |
29 RenderThreadImpl* render_thread = RenderThreadImpl::current(); | |
30 compositor_mus_connection_ = new CompositorMusConnection( | |
31 routing_id_, render_thread->GetCompositorMainThreadTaskRunner(), | |
32 render_thread->compositor_task_runner(), std::move(request), | |
33 render_thread->input_handler_manager()); | |
34 if (window_compositor_frame_sink_binding_) { | |
35 compositor_mus_connection_->AttachCompositorFrameSinkOnMainThread( | |
36 std::move(window_compositor_frame_sink_binding_)); | |
37 } | |
38 } | 28 } |
39 | 29 |
40 std::unique_ptr<cc::CompositorFrameSink> | 30 std::unique_ptr<cc::CompositorFrameSink> |
41 RenderWidgetMusConnection::CreateCompositorFrameSink( | 31 RenderWidgetMusConnection::CreateCompositorFrameSink( |
42 const cc::FrameSinkId& frame_sink_id, | 32 const cc::FrameSinkId& frame_sink_id, |
43 scoped_refptr<cc::ContextProvider> context_provider, | 33 scoped_refptr<cc::ContextProvider> context_provider, |
44 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager) { | 34 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager) { |
45 DCHECK(thread_checker_.CalledOnValidThread()); | 35 // TODO(sad): crbug.com/672913 |
46 DCHECK(!window_compositor_frame_sink_binding_); | 36 return nullptr; |
47 | |
48 std::unique_ptr<cc::CompositorFrameSink> compositor_frame_sink( | |
49 ui::WindowCompositorFrameSink::Create( | |
50 frame_sink_id, std::move(context_provider), gpu_memory_buffer_manager, | |
51 &window_compositor_frame_sink_binding_)); | |
52 if (compositor_mus_connection_) { | |
53 compositor_mus_connection_->AttachCompositorFrameSinkOnMainThread( | |
54 std::move(window_compositor_frame_sink_binding_)); | |
55 } | |
56 return compositor_frame_sink; | |
57 } | 37 } |
58 | 38 |
59 // static | 39 // static |
60 RenderWidgetMusConnection* RenderWidgetMusConnection::Get(int routing_id) { | 40 RenderWidgetMusConnection* RenderWidgetMusConnection::Get(int routing_id) { |
61 auto it = g_connections.Get().find(routing_id); | 41 auto it = g_connections.Get().find(routing_id); |
62 if (it != g_connections.Get().end()) | 42 if (it != g_connections.Get().end()) |
63 return it->second; | 43 return it->second; |
64 return nullptr; | 44 return nullptr; |
65 } | 45 } |
66 | 46 |
67 // static | 47 // static |
68 RenderWidgetMusConnection* RenderWidgetMusConnection::GetOrCreate( | 48 RenderWidgetMusConnection* RenderWidgetMusConnection::GetOrCreate( |
69 int routing_id) { | 49 int routing_id) { |
70 RenderWidgetMusConnection* connection = Get(routing_id); | 50 RenderWidgetMusConnection* connection = Get(routing_id); |
71 if (!connection) { | 51 if (!connection) { |
72 connection = new RenderWidgetMusConnection(routing_id); | 52 connection = new RenderWidgetMusConnection(routing_id); |
73 g_connections.Get().insert(std::make_pair(routing_id, connection)); | 53 g_connections.Get().insert(std::make_pair(routing_id, connection)); |
74 } | 54 } |
75 return connection; | 55 return connection; |
76 } | 56 } |
77 | 57 |
78 RenderWidgetMusConnection::RenderWidgetMusConnection(int routing_id) | 58 RenderWidgetMusConnection::RenderWidgetMusConnection(int routing_id) |
79 : routing_id_(routing_id), input_handler_(nullptr) { | 59 : routing_id_(routing_id) { |
80 DCHECK(routing_id); | 60 DCHECK(routing_id); |
81 } | 61 } |
82 | 62 |
83 RenderWidgetMusConnection::~RenderWidgetMusConnection() {} | 63 RenderWidgetMusConnection::~RenderWidgetMusConnection() {} |
84 | 64 |
85 void RenderWidgetMusConnection::FocusChangeComplete() { | |
86 NOTIMPLEMENTED(); | |
87 } | |
88 | |
89 bool RenderWidgetMusConnection::HasTouchEventHandlersAt( | |
90 const gfx::Point& point) const { | |
91 return true; | |
92 } | |
93 | |
94 void RenderWidgetMusConnection::ObserveGestureEventAndResult( | |
95 const blink::WebGestureEvent& gesture_event, | |
96 const gfx::Vector2dF& wheel_unused_delta, | |
97 bool event_processed) { | |
98 NOTIMPLEMENTED(); | |
99 } | |
100 | |
101 void RenderWidgetMusConnection::OnDidHandleKeyEvent() { | |
102 NOTIMPLEMENTED(); | |
103 } | |
104 | |
105 void RenderWidgetMusConnection::OnDidOverscroll( | |
106 const ui::DidOverscrollParams& params) { | |
107 NOTIMPLEMENTED(); | |
108 } | |
109 | |
110 void RenderWidgetMusConnection::OnInputEventAck( | |
111 std::unique_ptr<InputEventAck> input_event_ack) { | |
112 DCHECK(!pending_ack_.is_null()); | |
113 pending_ack_.Run(input_event_ack->state == | |
114 InputEventAckState::INPUT_EVENT_ACK_STATE_CONSUMED | |
115 ? ui::mojom::EventResult::HANDLED | |
116 : ui::mojom::EventResult::UNHANDLED); | |
117 pending_ack_.Reset(); | |
118 } | |
119 | |
120 void RenderWidgetMusConnection::NotifyInputEventHandled( | |
121 blink::WebInputEvent::Type handled_type, | |
122 InputEventAckState ack_result) { | |
123 NOTIMPLEMENTED(); | |
124 } | |
125 | |
126 void RenderWidgetMusConnection::SetInputHandler( | |
127 RenderWidgetInputHandler* input_handler) { | |
128 DCHECK(!input_handler_); | |
129 input_handler_ = input_handler; | |
130 } | |
131 | |
132 void RenderWidgetMusConnection::ShowVirtualKeyboard() { | |
133 NOTIMPLEMENTED(); | |
134 } | |
135 | |
136 void RenderWidgetMusConnection::UpdateTextInputState() { | |
137 NOTIMPLEMENTED(); | |
138 } | |
139 | |
140 bool RenderWidgetMusConnection::WillHandleGestureEvent( | |
141 const blink::WebGestureEvent& event) { | |
142 NOTIMPLEMENTED(); | |
143 return false; | |
144 } | |
145 | |
146 bool RenderWidgetMusConnection::WillHandleMouseEvent( | |
147 const blink::WebMouseEvent& event) { | |
148 // TODO(fsamuel): NOTIMPLEMENTED() is too noisy. | |
149 // NOTIMPLEMENTED(); | |
150 return false; | |
151 } | |
152 | |
153 void RenderWidgetMusConnection::OnConnectionLost() { | |
154 DCHECK(thread_checker_.CalledOnValidThread()); | |
155 g_connections.Get().erase(routing_id_); | |
156 delete this; | |
157 } | |
158 | |
159 void RenderWidgetMusConnection::OnWindowInputEvent( | |
160 blink::WebScopedInputEvent input_event, | |
161 const base::Callback<void(ui::mojom::EventResult)>& ack) { | |
162 DCHECK(thread_checker_.CalledOnValidThread()); | |
163 // If we don't yet have a RenderWidgetInputHandler then we don't yet have | |
164 // an initialized RenderWidget. | |
165 if (!input_handler_) { | |
166 ack.Run(ui::mojom::EventResult::UNHANDLED); | |
167 return; | |
168 } | |
169 // TODO(fsamuel): It would be nice to add this DCHECK but the reality is an | |
170 // event could timeout and we could receive the next event before we ack the | |
171 // previous event. | |
172 // DCHECK(pending_ack_.is_null()); | |
173 pending_ack_ = ack; | |
174 // TODO(fsamuel, sadrul): Track real latency info. | |
175 ui::LatencyInfo latency_info; | |
176 input_handler_->HandleInputEvent(*input_event, latency_info, | |
177 DISPATCH_TYPE_BLOCKING); | |
178 } | |
179 | |
180 } // namespace content | 65 } // namespace content |
OLD | NEW |