| 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 "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" | 22 #include "cc/blimp/client_picture_cache.h" |
| 23 #include "cc/blimp/compositor_state_deserializer.h" | 23 #include "cc/blimp/compositor_state_deserializer.h" |
| 24 #include "cc/blimp/image_serialization_processor.h" | 24 #include "cc/blimp/image_serialization_processor.h" |
| 25 #include "cc/layers/layer.h" | 25 #include "cc/layers/layer.h" |
| 26 #include "cc/layers/surface_layer.h" | 26 #include "cc/layers/surface_layer.h" |
| 27 #include "cc/output/compositor_frame_sink.h" | 27 #include "cc/output/compositor_frame_sink.h" |
| 28 #include "cc/proto/compositor_message.pb.h" | 28 #include "cc/proto/compositor_message.pb.h" |
| 29 #include "cc/surfaces/direct_surface_embedding.h" |
| 29 #include "cc/surfaces/surface.h" | 30 #include "cc/surfaces/surface.h" |
| 30 #include "cc/surfaces/surface_factory.h" | 31 #include "cc/surfaces/surface_factory.h" |
| 31 #include "cc/surfaces/surface_id_allocator.h" | 32 #include "cc/surfaces/surface_id_allocator.h" |
| 32 #include "cc/surfaces/surface_manager.h" | 33 #include "cc/surfaces/surface_manager.h" |
| 33 #include "cc/trees/layer_tree_host_in_process.h" | 34 #include "cc/trees/layer_tree_host_in_process.h" |
| 34 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" | 35 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" |
| 35 #include "net/base/net_errors.h" | 36 #include "net/base/net_errors.h" |
| 36 #include "ui/gl/gl_surface.h" | 37 #include "ui/gl/gl_surface.h" |
| 37 | 38 |
| 38 namespace blimp { | 39 namespace blimp { |
| 39 namespace client { | 40 namespace client { |
| 40 | 41 |
| 41 namespace { | |
| 42 | |
| 43 void SatisfyCallback(cc::SurfaceManager* manager, | |
| 44 const cc::SurfaceSequence& sequence) { | |
| 45 std::vector<uint32_t> sequences; | |
| 46 sequences.push_back(sequence.sequence); | |
| 47 manager->DidSatisfySequences(sequence.frame_sink_id, &sequences); | |
| 48 } | |
| 49 | |
| 50 void RequireCallback(cc::SurfaceManager* manager, | |
| 51 const cc::SurfaceId& id, | |
| 52 const cc::SurfaceSequence& sequence) { | |
| 53 cc::Surface* surface = manager->GetSurfaceForId(id); | |
| 54 if (!surface) { | |
| 55 LOG(ERROR) << "Attempting to require callback on nonexistent surface"; | |
| 56 return; | |
| 57 } | |
| 58 surface->AddDestructionDependency(sequence); | |
| 59 } | |
| 60 | |
| 61 } // namespace | |
| 62 | |
| 63 class BlimpCompositor::FrameTrackingSwapPromise : public cc::SwapPromise { | 42 class BlimpCompositor::FrameTrackingSwapPromise : public cc::SwapPromise { |
| 64 public: | 43 public: |
| 65 FrameTrackingSwapPromise( | 44 FrameTrackingSwapPromise( |
| 66 std::unique_ptr<cc::CopyOutputRequest> copy_request, | 45 std::unique_ptr<cc::CopyOutputRequest> copy_request, |
| 67 base::WeakPtr<BlimpCompositor> compositor, | 46 base::WeakPtr<BlimpCompositor> compositor, |
| 68 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner) | 47 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner) |
| 69 : copy_request_(std::move(copy_request)), | 48 : copy_request_(std::move(copy_request)), |
| 70 compositor_weak_ptr_(compositor), | 49 compositor_weak_ptr_(compositor), |
| 71 main_task_runner_(std::move(main_task_runner)) {} | 50 main_task_runner_(std::move(main_task_runner)) {} |
| 72 ~FrameTrackingSwapPromise() override = default; | 51 ~FrameTrackingSwapPromise() override = default; |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 gfx::Size surface_size = root_pass->output_rect.size(); | 299 gfx::Size surface_size = root_pass->output_rect.size(); |
| 321 | 300 |
| 322 if (!local_frame_id_.is_valid() || current_surface_size_ != surface_size) { | 301 if (!local_frame_id_.is_valid() || current_surface_size_ != surface_size) { |
| 323 DestroyDelegatedContent(); | 302 DestroyDelegatedContent(); |
| 324 DCHECK(layer_->children().empty()); | 303 DCHECK(layer_->children().empty()); |
| 325 | 304 |
| 326 local_frame_id_ = surface_id_allocator_->GenerateId(); | 305 local_frame_id_ = surface_id_allocator_->GenerateId(); |
| 327 current_surface_size_ = surface_size; | 306 current_surface_size_ = surface_size; |
| 328 | 307 |
| 329 // manager must outlive compositors using it. | 308 // manager must outlive compositors using it. |
| 309 cc::SurfaceId surface_id(surface_factory_->frame_sink_id(), |
| 310 local_frame_id_); |
| 330 cc::SurfaceManager* surface_manager = | 311 cc::SurfaceManager* surface_manager = |
| 331 GetEmbedderDeps()->GetSurfaceManager(); | 312 GetEmbedderDeps()->GetSurfaceManager(); |
| 332 scoped_refptr<cc::SurfaceLayer> content_layer = cc::SurfaceLayer::Create( | 313 auto surface_embedding = base::MakeUnique<cc::DirectSurfaceEmbedding>( |
| 333 base::Bind(&SatisfyCallback, base::Unretained(surface_manager)), | 314 cc::SurfaceInfo(surface_id, 1.f, surface_size), surface_manager); |
| 334 base::Bind(&RequireCallback, base::Unretained(surface_manager))); | 315 scoped_refptr<cc::SurfaceLayer> content_layer = cc::SurfaceLayer::Create(); |
| 335 content_layer->SetSurfaceId( | 316 content_layer->SetSurfaceEmbedding(std::move(surface_embedding)); |
| 336 cc::SurfaceId(surface_factory_->frame_sink_id(), local_frame_id_), 1.f, | |
| 337 surface_size); | |
| 338 content_layer->SetBounds(current_surface_size_); | 317 content_layer->SetBounds(current_surface_size_); |
| 339 content_layer->SetIsDrawable(true); | 318 content_layer->SetIsDrawable(true); |
| 340 content_layer->SetContentsOpaque(true); | 319 content_layer->SetContentsOpaque(true); |
| 341 | 320 |
| 342 layer_->AddChild(content_layer); | 321 layer_->AddChild(content_layer); |
| 343 } | 322 } |
| 344 | 323 |
| 345 surface_factory_->SubmitCompositorFrame( | 324 surface_factory_->SubmitCompositorFrame( |
| 346 local_frame_id_, std::move(frame), | 325 local_frame_id_, std::move(frame), |
| 347 base::Bind(&BlimpCompositor::SubmitCompositorFrameAck, | 326 base::Bind(&BlimpCompositor::SubmitCompositorFrameAck, |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 // Destroy the old LayerTreeHost state. | 439 // Destroy the old LayerTreeHost state. |
| 461 host_.reset(); | 440 host_.reset(); |
| 462 | 441 |
| 463 // Cancel any outstanding CompositorFrameSink requests. That way if we get an | 442 // Cancel any outstanding CompositorFrameSink requests. That way if we get an |
| 464 // async callback related to the old request we know to drop it. | 443 // async callback related to the old request we know to drop it. |
| 465 compositor_frame_sink_request_pending_ = false; | 444 compositor_frame_sink_request_pending_ = false; |
| 466 } | 445 } |
| 467 | 446 |
| 468 } // namespace client | 447 } // namespace client |
| 469 } // namespace blimp | 448 } // namespace blimp |
| OLD | NEW |