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