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

Side by Side Diff: blimp/client/feature/compositor/blimp_compositor.cc

Issue 2241623002: blimp: Move compositing, input and render widget feature to client/core. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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
OLDNEW
(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 "blimp/client/feature/compositor/blimp_compositor.h"
6
7 #include "base/bind_helpers.h"
8 #include "base/command_line.h"
9 #include "base/memory/ptr_util.h"
10 #include "base/numerics/safe_conversions.h"
11 #include "base/single_thread_task_runner.h"
12 #include "base/threading/thread.h"
13 #include "base/threading/thread_local.h"
14 #include "base/threading/thread_restrictions.h"
15 #include "base/threading/thread_task_runner_handle.h"
16 #include "blimp/client/feature/compositor/blimp_context_provider.h"
17 #include "blimp/client/feature/compositor/blimp_output_surface.h"
18 #include "cc/animation/animation_host.h"
19 #include "cc/layers/layer.h"
20 #include "cc/output/output_surface.h"
21 #include "cc/proto/compositor_message.pb.h"
22 #include "cc/trees/layer_tree_host.h"
23 #include "net/base/net_errors.h"
24 #include "ui/gl/gl_surface.h"
25
26 namespace blimp {
27 namespace client {
28
29 BlimpCompositor::BlimpCompositor(int render_widget_id,
30 BlimpCompositorClient* client)
31 : render_widget_id_(render_widget_id),
32 client_(client),
33 window_(gfx::kNullAcceleratedWidget),
34 host_should_be_visible_(false),
35 output_surface_request_pending_(false),
36 remote_proto_channel_receiver_(nullptr) {}
37
38 BlimpCompositor::~BlimpCompositor() {
39 if (host_)
40 DestroyLayerTreeHost();
41 }
42
43 void BlimpCompositor::SetVisible(bool visible) {
44 host_should_be_visible_ = visible;
45 SetVisibleInternal(host_should_be_visible_);
46 }
47
48 void BlimpCompositor::SetAcceleratedWidget(gfx::AcceleratedWidget widget) {
49 if (widget == window_)
50 return;
51
52 DCHECK(window_ == gfx::kNullAcceleratedWidget);
53 window_ = widget;
54
55 // The compositor should not be visible if there is no output surface.
56 DCHECK(!host_ || !host_->visible());
57
58 // This will properly set visibility and will build the output surface if
59 // necessary.
60 SetVisibleInternal(host_should_be_visible_);
61 }
62
63 void BlimpCompositor::ReleaseAcceleratedWidget() {
64 if (window_ == gfx::kNullAcceleratedWidget)
65 return;
66
67 // Hide the compositor and drop the output surface if necessary.
68 SetVisibleInternal(false);
69
70 window_ = gfx::kNullAcceleratedWidget;
71 }
72
73 bool BlimpCompositor::OnTouchEvent(const ui::MotionEvent& motion_event) {
74 if (input_manager_)
75 return input_manager_->OnTouchEvent(motion_event);
76 return false;
77 }
78
79 void BlimpCompositor::WillBeginMainFrame() {}
80
81 void BlimpCompositor::DidBeginMainFrame() {}
82
83 void BlimpCompositor::BeginMainFrame(const cc::BeginFrameArgs& args) {}
84
85 void BlimpCompositor::BeginMainFrameNotExpectedSoon() {}
86
87 void BlimpCompositor::UpdateLayerTreeHost() {}
88
89 void BlimpCompositor::ApplyViewportDeltas(
90 const gfx::Vector2dF& inner_delta,
91 const gfx::Vector2dF& outer_delta,
92 const gfx::Vector2dF& elastic_overscroll_delta,
93 float page_scale,
94 float top_controls_delta) {}
95
96 void BlimpCompositor::RequestNewOutputSurface() {
97 output_surface_request_pending_ = true;
98 HandlePendingOutputSurfaceRequest();
99 }
100
101 void BlimpCompositor::DidInitializeOutputSurface() {
102 }
103
104 void BlimpCompositor::DidFailToInitializeOutputSurface() {}
105
106 void BlimpCompositor::WillCommit() {}
107
108 void BlimpCompositor::DidCommit() {}
109
110 void BlimpCompositor::DidCommitAndDrawFrame() {
111 client_->DidCommitAndDrawFrame();
112 }
113
114 void BlimpCompositor::DidCompleteSwapBuffers() {
115 client_->DidCompleteSwapBuffers();
116 }
117
118 void BlimpCompositor::DidCompletePageScaleAnimation() {}
119
120 void BlimpCompositor::SetProtoReceiver(ProtoReceiver* receiver) {
121 remote_proto_channel_receiver_ = receiver;
122 }
123
124 void BlimpCompositor::SendCompositorProto(
125 const cc::proto::CompositorMessage& proto) {
126 client_->SendCompositorMessage(render_widget_id_, proto);
127 }
128
129 void BlimpCompositor::OnCompositorMessageReceived(
130 std::unique_ptr<cc::proto::CompositorMessage> message) {
131 DCHECK(message->has_to_impl());
132 const cc::proto::CompositorMessageToImpl& to_impl_proto =
133 message->to_impl();
134
135 DCHECK(to_impl_proto.has_message_type());
136 switch (to_impl_proto.message_type()) {
137 case cc::proto::CompositorMessageToImpl::UNKNOWN:
138 NOTIMPLEMENTED() << "Ignoring message of UNKNOWN type";
139 break;
140 case cc::proto::CompositorMessageToImpl::INITIALIZE_IMPL:
141 DCHECK(!host_);
142 DCHECK(to_impl_proto.has_initialize_impl_message());
143
144 // Create the remote client LayerTreeHost for the compositor.
145 CreateLayerTreeHost(to_impl_proto.initialize_impl_message());
146 break;
147 case cc::proto::CompositorMessageToImpl::CLOSE_IMPL:
148 DCHECK(host_);
149
150 // Destroy the remote client LayerTreeHost for the compositor.
151 DestroyLayerTreeHost();
152 break;
153 default:
154 // We should have a receiver if we're getting compositor messages that
155 // are not INITIALIZE_IMPL or CLOSE_IMPL.
156 DCHECK(remote_proto_channel_receiver_);
157 remote_proto_channel_receiver_->OnProtoReceived(std::move(message));
158 }
159 }
160
161 void BlimpCompositor::SendWebGestureEvent(
162 const blink::WebGestureEvent& gesture_event) {
163 client_->SendWebGestureEvent(render_widget_id_, gesture_event);
164 }
165
166 void BlimpCompositor::SetVisibleInternal(bool visible) {
167 if (!host_)
168 return;
169
170 VLOG(1) << "Setting visibility to: " << visible
171 << " for render widget: " << render_widget_id_;
172
173 if (visible && window_ != gfx::kNullAcceleratedWidget) {
174 // If we're supposed to be visible and we have a valid
175 // gfx::AcceleratedWidget make our compositor visible. If the compositor
176 // had an outstanding output surface request, trigger the request again so
177 // we build the output surface.
178 host_->SetVisible(true);
179 if (output_surface_request_pending_)
180 HandlePendingOutputSurfaceRequest();
181 } else if (!visible) {
182 // If not visible, hide the compositor and have it drop it's output
183 // surface.
184 host_->SetVisible(false);
185 if (!host_->output_surface_lost()) {
186 host_->ReleaseOutputSurface();
187 }
188 }
189 }
190
191 void BlimpCompositor::CreateLayerTreeHost(
192 const cc::proto::InitializeImpl& initialize_message) {
193 DCHECK(!host_);
194 VLOG(1) << "Creating LayerTreeHost for render widget: " << render_widget_id_;
195
196 // Create the LayerTreeHost
197 cc::LayerTreeHost::InitParams params;
198 params.client = this;
199 params.task_graph_runner = client_->GetTaskGraphRunner();
200 params.gpu_memory_buffer_manager = client_->GetGpuMemoryBufferManager();
201 params.main_task_runner = base::ThreadTaskRunnerHandle::Get();
202 params.image_serialization_processor =
203 client_->GetImageSerializationProcessor();
204 params.settings = client_->GetLayerTreeSettings();
205 params.animation_host = cc::AnimationHost::CreateMainInstance();
206
207 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner =
208 client_->GetCompositorTaskRunner();
209
210 host_ =
211 cc::LayerTreeHost::CreateRemoteClient(this /* remote_proto_channel */,
212 compositor_task_runner, &params);
213
214 // Now that we have a host, set the visiblity on it correctly.
215 SetVisibleInternal(host_should_be_visible_);
216
217 DCHECK(!input_manager_);
218 input_manager_ =
219 BlimpInputManager::Create(this,
220 base::ThreadTaskRunnerHandle::Get(),
221 compositor_task_runner,
222 host_->GetInputHandler());
223 }
224
225 void BlimpCompositor::DestroyLayerTreeHost() {
226 DCHECK(host_);
227 VLOG(1) << "Destroying LayerTreeHost for render widget: "
228 << render_widget_id_;
229 // Tear down the output surface connection with the old LayerTreeHost
230 // instance.
231 SetVisibleInternal(false);
232
233 // Destroy the old LayerTreeHost state.
234 host_.reset();
235
236 // Destroy the old input manager state.
237 // It is important to destroy the LayerTreeHost before destroying the input
238 // manager as it has a reference to the cc::InputHandlerClient owned by the
239 // BlimpInputManager.
240 input_manager_.reset();
241
242 // Reset other state.
243 output_surface_request_pending_ = false;
244
245 // Make sure we don't have a receiver at this point.
246 DCHECK(!remote_proto_channel_receiver_);
247 }
248
249 void BlimpCompositor::HandlePendingOutputSurfaceRequest() {
250 DCHECK(output_surface_request_pending_);
251
252 // We might have had a request from a LayerTreeHost that was then
253 // hidden (and hidden means we don't have a native surface).
254 // Also make sure we only handle this once.
255 if (!host_->visible() || window_ == gfx::kNullAcceleratedWidget)
256 return;
257
258 scoped_refptr<BlimpContextProvider> context_provider =
259 BlimpContextProvider::Create(window_,
260 client_->GetGpuMemoryBufferManager());
261
262 host_->SetOutputSurface(
263 base::WrapUnique(new BlimpOutputSurface(context_provider)));
264 output_surface_request_pending_ = false;
265 }
266
267 } // namespace client
268 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698