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

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

Issue 2415633003: blimp: Add mode to use the updated compositing path on the client. (Closed)
Patch Set: gn check Created 4 years, 2 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
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 "blimp/client/core/compositor/blimp_compositor.h" 5 #include "blimp/client/core/compositor/blimp_compositor.h"
6 6
7 #include "base/bind_helpers.h" 7 #include "base/bind_helpers.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
11 #include "base/numerics/safe_conversions.h" 11 #include "base/numerics/safe_conversions.h"
12 #include "base/single_thread_task_runner.h" 12 #include "base/single_thread_task_runner.h"
13 #include "base/threading/thread.h" 13 #include "base/threading/thread.h"
14 #include "base/threading/thread_local.h" 14 #include "base/threading/thread_local.h"
15 #include "base/threading/thread_restrictions.h" 15 #include "base/threading/thread_restrictions.h"
16 #include "base/threading/thread_task_runner_handle.h" 16 #include "base/threading/thread_task_runner_handle.h"
17 #include "blimp/client/core/compositor/blimp_compositor_dependencies.h" 17 #include "blimp/client/core/compositor/blimp_compositor_dependencies.h"
18 #include "blimp/client/core/compositor/blimp_compositor_frame_sink.h" 18 #include "blimp/client/core/compositor/blimp_compositor_frame_sink.h"
19 #include "blimp/client/public/compositor/compositor_dependencies.h" 19 #include "blimp/client/public/compositor/compositor_dependencies.h"
20 #include "blimp/net/blimp_stats.h" 20 #include "blimp/net/blimp_stats.h"
21 #include "cc/animation/animation_host.h" 21 #include "cc/animation/animation_host.h"
22 #include "cc/blimp/client_picture_cache.h"
23 #include "cc/blimp/compositor_state_deserializer.h"
24 #include "cc/blimp/image_serialization_processor.h"
22 #include "cc/layers/layer.h" 25 #include "cc/layers/layer.h"
23 #include "cc/layers/surface_layer.h" 26 #include "cc/layers/surface_layer.h"
24 #include "cc/output/compositor_frame_sink.h" 27 #include "cc/output/compositor_frame_sink.h"
25 #include "cc/proto/compositor_message.pb.h" 28 #include "cc/proto/compositor_message.pb.h"
26 #include "cc/surfaces/surface.h" 29 #include "cc/surfaces/surface.h"
27 #include "cc/surfaces/surface_factory.h" 30 #include "cc/surfaces/surface_factory.h"
28 #include "cc/surfaces/surface_id_allocator.h" 31 #include "cc/surfaces/surface_id_allocator.h"
29 #include "cc/surfaces/surface_manager.h" 32 #include "cc/surfaces/surface_manager.h"
30 #include "cc/trees/layer_tree_host_in_process.h" 33 #include "cc/trees/layer_tree_host_in_process.h"
31 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" 34 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h"
(...skipping 20 matching lines...) Expand all
52 LOG(ERROR) << "Attempting to require callback on nonexistent surface"; 55 LOG(ERROR) << "Attempting to require callback on nonexistent surface";
53 return; 56 return;
54 } 57 }
55 surface->AddDestructionDependency(sequence); 58 surface->AddDestructionDependency(sequence);
56 } 59 }
57 60
58 } // namespace 61 } // namespace
59 62
60 BlimpCompositor::BlimpCompositor( 63 BlimpCompositor::BlimpCompositor(
61 BlimpCompositorDependencies* compositor_dependencies, 64 BlimpCompositorDependencies* compositor_dependencies,
62 BlimpCompositorClient* client) 65 BlimpCompositorClient* client,
63 : client_(client), 66 bool use_threaded_layer_tree_host)
67 : use_threaded_layer_tree_host_(use_threaded_layer_tree_host),
68 client_(client),
64 compositor_dependencies_(compositor_dependencies), 69 compositor_dependencies_(compositor_dependencies),
65 frame_sink_id_(compositor_dependencies_->GetEmbedderDependencies() 70 frame_sink_id_(compositor_dependencies_->GetEmbedderDependencies()
66 ->AllocateFrameSinkId()), 71 ->AllocateFrameSinkId()),
67 proxy_client_(nullptr), 72 proxy_client_(nullptr),
68 compositor_frame_sink_request_pending_(false), 73 compositor_frame_sink_request_pending_(false),
69 layer_(cc::Layer::Create()), 74 layer_(cc::Layer::Create()),
70 remote_proto_channel_receiver_(nullptr), 75 remote_proto_channel_receiver_(nullptr),
71 outstanding_commits_(0U), 76 outstanding_commits_(0U),
72 weak_ptr_factory_(this) { 77 weak_ptr_factory_(this) {
73 DCHECK(thread_checker_.CalledOnValidThread()); 78 DCHECK(thread_checker_.CalledOnValidThread());
74 79
75 surface_id_allocator_ = base::MakeUnique<cc::SurfaceIdAllocator>(); 80 surface_id_allocator_ = base::MakeUnique<cc::SurfaceIdAllocator>();
76 GetEmbedderDeps()->GetSurfaceManager()->RegisterFrameSinkId(frame_sink_id_); 81 GetEmbedderDeps()->GetSurfaceManager()->RegisterFrameSinkId(frame_sink_id_);
77 CreateLayerTreeHost(); 82 CreateLayerTreeHost();
83
84 if (use_threaded_layer_tree_host_) {
85 std::unique_ptr<cc::ClientPictureCache> client_picture_cache =
86 compositor_dependencies_->GetImageSerializationProcessor()
87 ->CreateClientPictureCache();
88 compositor_state_deserializer_ =
89 base::MakeUnique<cc::CompositorStateDeserializer>(
90 host_.get(), std::move(client_picture_cache),
91 base::Bind(&BlimpCompositor::LayerScrolled,
92 weak_ptr_factory_.GetWeakPtr()),
93 this);
94 }
78 } 95 }
79 96
80 BlimpCompositor::~BlimpCompositor() { 97 BlimpCompositor::~BlimpCompositor() {
81 DCHECK(thread_checker_.CalledOnValidThread()); 98 DCHECK(thread_checker_.CalledOnValidThread());
82 99
83 DestroyLayerTreeHost(); 100 DestroyLayerTreeHost();
84 GetEmbedderDeps()->GetSurfaceManager()->InvalidateFrameSinkId(frame_sink_id_); 101 GetEmbedderDeps()->GetSurfaceManager()->InvalidateFrameSinkId(frame_sink_id_);
85 102
86 CheckPendingCommitCounts(true /* flush */); 103 CheckPendingCommitCounts(true /* flush */);
87 } 104 }
88 105
89 void BlimpCompositor::SetVisible(bool visible) { 106 void BlimpCompositor::SetVisible(bool visible) {
90 host_->SetVisible(visible); 107 host_->SetVisible(visible);
91 108
92 if (!visible) 109 if (!visible)
93 CheckPendingCommitCounts(true /* flush */); 110 CheckPendingCommitCounts(true /* flush */);
94 } 111 }
95 112
96 void BlimpCompositor::NotifyWhenDonePendingCommits(base::Closure callback) { 113 void BlimpCompositor::NotifyWhenDonePendingCommits(base::Closure callback) {
97 if (outstanding_commits_ == 0) { 114 if (outstanding_commits_ == 0) {
98 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback); 115 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback);
99 return; 116 return;
100 } 117 }
101 118
102 pending_commit_trackers_.push_back( 119 pending_commit_trackers_.push_back(
103 std::make_pair(outstanding_commits_, callback)); 120 std::make_pair(outstanding_commits_, callback));
104 } 121 }
105 122
123 void BlimpCompositor::UpdateLayerTreeHost() {
124 if (pending_frame_update_) {
125 DCHECK(use_threaded_layer_tree_host_);
126 compositor_state_deserializer_->DeserializeCompositorUpdate(
127 pending_frame_update_->layer_tree_host());
128 pending_frame_update_ = nullptr;
129 cc::proto::CompositorMessage frame_ack;
130 frame_ack.set_frame_ack(true);
131 client_->SendCompositorMessage(frame_ack);
132 }
133 }
134
106 void BlimpCompositor::RequestNewCompositorFrameSink() { 135 void BlimpCompositor::RequestNewCompositorFrameSink() {
107 DCHECK(!surface_factory_); 136 DCHECK(!surface_factory_);
108 DCHECK(!compositor_frame_sink_request_pending_); 137 DCHECK(!compositor_frame_sink_request_pending_);
109 138
110 compositor_frame_sink_request_pending_ = true; 139 compositor_frame_sink_request_pending_ = true;
111 GetEmbedderDeps()->GetContextProviders( 140 GetEmbedderDeps()->GetContextProviders(
112 base::Bind(&BlimpCompositor::OnContextProvidersCreated, 141 base::Bind(&BlimpCompositor::OnContextProvidersCreated,
113 weak_ptr_factory_.GetWeakPtr())); 142 weak_ptr_factory_.GetWeakPtr()));
114 } 143 }
115 144
116 void BlimpCompositor::DidInitializeCompositorFrameSink() { 145 void BlimpCompositor::DidInitializeCompositorFrameSink() {
117 compositor_frame_sink_request_pending_ = false; 146 compositor_frame_sink_request_pending_ = false;
118 } 147 }
119 148
120 void BlimpCompositor::DidCommitAndDrawFrame() { 149 void BlimpCompositor::DidCommitAndDrawFrame() {
121 BlimpStats::GetInstance()->Add(BlimpStats::COMMIT, 1); 150 BlimpStats::GetInstance()->Add(BlimpStats::COMMIT, 1);
122 151
123 DCHECK_GT(outstanding_commits_, 0U); 152 DCHECK_GT(outstanding_commits_, 0U);
124 outstanding_commits_--; 153 outstanding_commits_--;
125 154
126 CheckPendingCommitCounts(false /* flush */); 155 CheckPendingCommitCounts(false /* flush */);
127 } 156 }
128 157
129 void BlimpCompositor::SetProtoReceiver(ProtoReceiver* receiver) { 158 void BlimpCompositor::SetProtoReceiver(ProtoReceiver* receiver) {
159 DCHECK(!use_threaded_layer_tree_host_);
130 remote_proto_channel_receiver_ = receiver; 160 remote_proto_channel_receiver_ = receiver;
131 } 161 }
132 162
133 void BlimpCompositor::SendCompositorProto( 163 void BlimpCompositor::SendCompositorProto(
134 const cc::proto::CompositorMessage& proto) { 164 const cc::proto::CompositorMessage& proto) {
165 DCHECK(!use_threaded_layer_tree_host_);
135 client_->SendCompositorMessage(proto); 166 client_->SendCompositorMessage(proto);
136 } 167 }
137 168
138 void BlimpCompositor::OnCompositorMessageReceived( 169 void BlimpCompositor::OnCompositorMessageReceived(
139 std::unique_ptr<cc::proto::CompositorMessage> message) { 170 std::unique_ptr<cc::proto::CompositorMessage> message) {
171 if (message->has_to_impl()) {
172 HandleCompositorMessageToImpl(std::move(message));
173 return;
174 }
175
176 DCHECK(use_threaded_layer_tree_host_);
177 DCHECK(message->has_layer_tree_host())
178 << "The engine only sends frame updates";
179 DCHECK(!pending_frame_update_)
180 << "We should have only a single frame in flight";
181
182 UMA_HISTOGRAM_MEMORY_KB("Blimp.Compositor.CommitSizeKb",
183 (float)message->ByteSize() / 1024);
184 pending_frame_update_ = std::move(message);
185 outstanding_commits_++;
186 host_->SetNeedsAnimate();
187 }
188
189 void BlimpCompositor::HandleCompositorMessageToImpl(
190 std::unique_ptr<cc::proto::CompositorMessage> message) {
191 DCHECK(!use_threaded_layer_tree_host_);
140 DCHECK(message->has_to_impl()); 192 DCHECK(message->has_to_impl());
141 const cc::proto::CompositorMessageToImpl& to_impl_proto = message->to_impl();
142 193
194 const cc::proto::CompositorMessageToImpl to_impl_proto = message->to_impl();
143 DCHECK(to_impl_proto.has_message_type()); 195 DCHECK(to_impl_proto.has_message_type());
144 196
145 if (to_impl_proto.message_type() == 197 if (to_impl_proto.message_type() ==
146 cc::proto::CompositorMessageToImpl::START_COMMIT) { 198 cc::proto::CompositorMessageToImpl::START_COMMIT) {
147 outstanding_commits_++; 199 outstanding_commits_++;
148 } 200 }
149 201
150 switch (to_impl_proto.message_type()) { 202 switch (to_impl_proto.message_type()) {
151 case cc::proto::CompositorMessageToImpl::UNKNOWN: 203 case cc::proto::CompositorMessageToImpl::UNKNOWN:
152 NOTIMPLEMENTED() << "Ignoring message of UNKNOWN type"; 204 NOTIMPLEMENTED() << "Ignoring message of UNKNOWN type";
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 void BlimpCompositor::ReturnResources( 315 void BlimpCompositor::ReturnResources(
264 const cc::ReturnedResourceArray& resources) { 316 const cc::ReturnedResourceArray& resources) {
265 DCHECK(surface_factory_); 317 DCHECK(surface_factory_);
266 compositor_dependencies_->GetCompositorTaskRunner()->PostTask( 318 compositor_dependencies_->GetCompositorTaskRunner()->PostTask(
267 FROM_HERE, 319 FROM_HERE,
268 base::Bind( 320 base::Bind(
269 &BlimpCompositorFrameSinkProxyClient::ReclaimCompositorResources, 321 &BlimpCompositorFrameSinkProxyClient::ReclaimCompositorResources,
270 proxy_client_, resources)); 322 proxy_client_, resources));
271 } 323 }
272 324
325 bool BlimpCompositor::ShouldRetainClientScroll(
326 int engine_layer_id,
327 const gfx::ScrollOffset& new_offset) {
328 // TODO(khushalsagar): Update when adding scroll/scale sync. See
329 // crbug.com/648442.
330 return true;
331 }
332
333 bool BlimpCompositor::ShouldRetainClientPageScale(float new_page_scale) {
334 // TODO(khushalsagar): Update when adding scroll/scale sync. See
335 // crbug.com/648442.
336 return true;
337 }
338
339 void BlimpCompositor::LayerScrolled(int engine_layer_id) {
340 DCHECK(use_threaded_layer_tree_host_);
341 }
342
273 CompositorDependencies* BlimpCompositor::GetEmbedderDeps() { 343 CompositorDependencies* BlimpCompositor::GetEmbedderDeps() {
274 return compositor_dependencies_->GetEmbedderDependencies(); 344 return compositor_dependencies_->GetEmbedderDependencies();
275 } 345 }
276 346
277 void BlimpCompositor::DestroyDelegatedContent() { 347 void BlimpCompositor::DestroyDelegatedContent() {
278 if (local_frame_id_.is_null()) 348 if (local_frame_id_.is_null())
279 return; 349 return;
280 350
281 // Remove any references for the surface layer that uses this 351 // Remove any references for the surface layer that uses this
282 // |local_frame_id_|. 352 // |local_frame_id_|.
283 layer_->RemoveAllChildren(); 353 layer_->RemoveAllChildren();
284 surface_factory_->Destroy(local_frame_id_); 354 surface_factory_->Destroy(local_frame_id_);
285 local_frame_id_ = cc::LocalFrameId(); 355 local_frame_id_ = cc::LocalFrameId();
286 } 356 }
287 357
288 void BlimpCompositor::CreateLayerTreeHost() { 358 void BlimpCompositor::CreateLayerTreeHost() {
289 DCHECK(!host_); 359 DCHECK(!host_);
290 VLOG(1) << "Creating LayerTreeHost."; 360 VLOG(1) << "Creating LayerTreeHost.";
291 361
292 // Create the LayerTreeHost 362 // Create the LayerTreeHost
293 cc::LayerTreeHostInProcess::InitParams params; 363 cc::LayerTreeHostInProcess::InitParams params;
294 params.client = this; 364 params.client = this;
295 params.task_graph_runner = compositor_dependencies_->GetTaskGraphRunner(); 365 params.task_graph_runner = compositor_dependencies_->GetTaskGraphRunner();
296 params.gpu_memory_buffer_manager = 366 params.gpu_memory_buffer_manager =
297 GetEmbedderDeps()->GetGpuMemoryBufferManager(); 367 GetEmbedderDeps()->GetGpuMemoryBufferManager();
298 params.main_task_runner = base::ThreadTaskRunnerHandle::Get(); 368 params.main_task_runner = base::ThreadTaskRunnerHandle::Get();
299 params.image_serialization_processor = 369 if (!use_threaded_layer_tree_host_)
David Trainor- moved to gerrit 2016/10/13 15:18:41 {} if the line wraps? Would feel cleaner to me.
Khushal 2016/10/13 16:36:36 Done.
300 compositor_dependencies_->GetImageSerializationProcessor(); 370 params.image_serialization_processor =
371 compositor_dependencies_->GetImageSerializationProcessor();
301 372
302 cc::LayerTreeSettings* settings = 373 cc::LayerTreeSettings* settings =
303 compositor_dependencies_->GetLayerTreeSettings(); 374 compositor_dependencies_->GetLayerTreeSettings();
304 // TODO(khushalsagar): This is a hack. Remove when we move the split point
305 // out. For details on why this is needed, see crbug.com/586210.
306 settings->abort_commit_before_compositor_frame_sink_creation = false;
307 params.settings = settings; 375 params.settings = settings;
308 376
309 params.animation_host = cc::AnimationHost::CreateMainInstance(); 377 params.animation_host = cc::AnimationHost::CreateMainInstance();
310 378
311 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner = 379 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner =
312 compositor_dependencies_->GetCompositorTaskRunner(); 380 compositor_dependencies_->GetCompositorTaskRunner();
313 381
314 host_ = cc::LayerTreeHostInProcess::CreateRemoteClient( 382 if (use_threaded_layer_tree_host_)
315 this /* remote_proto_channel */, compositor_task_runner, &params); 383 host_ = cc::LayerTreeHostInProcess::CreateThreaded(compositor_task_runner,
384 &params);
385 else
386 host_ = cc::LayerTreeHostInProcess::CreateRemoteClient(
387 this /* remote_proto_channel */, compositor_task_runner, &params);
316 } 388 }
317 389
318 void BlimpCompositor::DestroyLayerTreeHost() { 390 void BlimpCompositor::DestroyLayerTreeHost() {
319 DCHECK(host_); 391 DCHECK(host_);
320 VLOG(1) << "Destroying LayerTreeHost."; 392 VLOG(1) << "Destroying LayerTreeHost.";
321 393
322 // Tear down the output surface connection with the old LayerTreeHost 394 // Tear down the output surface connection with the old LayerTreeHost
323 // instance. 395 // instance.
324 DestroyDelegatedContent(); 396 DestroyDelegatedContent();
325 surface_factory_.reset(); 397 surface_factory_.reset();
(...skipping 16 matching lines...) Expand all
342 it->second.Run(); 414 it->second.Run();
343 it = pending_commit_trackers_.erase(it); 415 it = pending_commit_trackers_.erase(it);
344 } else { 416 } else {
345 ++it; 417 ++it;
346 } 418 }
347 } 419 }
348 } 420 }
349 421
350 } // namespace client 422 } // namespace client
351 } // namespace blimp 423 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698