| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "cc/surfaces/compositor_frame_sink_support.h" | 5 #include "cc/surfaces/compositor_frame_sink_support.h" |
| 6 | 6 |
| 7 #include "cc/output/compositor_frame.h" | 7 #include "cc/output/compositor_frame.h" |
| 8 #include "cc/scheduler/begin_frame_source.h" | 8 #include "cc/scheduler/begin_frame_source.h" |
| 9 #include "cc/surfaces/compositor_frame_sink_support_client.h" | 9 #include "cc/surfaces/compositor_frame_sink_support_client.h" |
| 10 #include "cc/surfaces/display.h" | 10 #include "cc/surfaces/display.h" |
| 11 #include "cc/surfaces/surface.h" | 11 #include "cc/surfaces/surface.h" |
| 12 #include "cc/surfaces/surface_manager.h" | 12 #include "cc/surfaces/surface_manager.h" |
| 13 | 13 |
| 14 namespace cc { | 14 namespace cc { |
| 15 | 15 |
| 16 CompositorFrameSinkSupport::CompositorFrameSinkSupport( | 16 CompositorFrameSinkSupport::CompositorFrameSinkSupport( |
| 17 CompositorFrameSinkSupportClient* client, | 17 CompositorFrameSinkSupportClient* client, |
| 18 SurfaceManager* surface_manager, | 18 SurfaceManager* surface_manager, |
| 19 const FrameSinkId& frame_sink_id, | 19 const FrameSinkId& frame_sink_id, |
| 20 std::unique_ptr<Display> display, | 20 Display* display) |
| 21 std::unique_ptr<BeginFrameSource> display_begin_frame_source) | |
| 22 : client_(client), | 21 : client_(client), |
| 23 surface_manager_(surface_manager), | 22 surface_manager_(surface_manager), |
| 24 frame_sink_id_(frame_sink_id), | 23 frame_sink_id_(frame_sink_id), |
| 25 display_begin_frame_source_(std::move(display_begin_frame_source)), | 24 display_(display), |
| 26 display_(std::move(display)), | |
| 27 surface_factory_(frame_sink_id_, surface_manager_, this), | 25 surface_factory_(frame_sink_id_, surface_manager_, this), |
| 28 weak_factory_(this) { | 26 weak_factory_(this) { |
| 29 surface_manager_->RegisterFrameSinkId(frame_sink_id_); | 27 surface_manager_->RegisterFrameSinkId(frame_sink_id_); |
| 30 surface_manager_->RegisterSurfaceFactoryClient(frame_sink_id_, this); | 28 surface_manager_->RegisterSurfaceFactoryClient(frame_sink_id_, this); |
| 31 | 29 |
| 32 if (display_) { | 30 if (display_) { |
| 33 display_->Initialize(this, surface_manager_); | 31 display_->Initialize(this, surface_manager_); |
| 34 display_->SetVisible(true); | 32 display_->SetVisible(true); |
| 35 } | 33 } |
| 36 } | 34 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 55 | 53 |
| 56 void CompositorFrameSinkSupport::SetNeedsBeginFrame(bool needs_begin_frame) { | 54 void CompositorFrameSinkSupport::SetNeedsBeginFrame(bool needs_begin_frame) { |
| 57 needs_begin_frame_ = needs_begin_frame; | 55 needs_begin_frame_ = needs_begin_frame; |
| 58 UpdateNeedsBeginFramesInternal(); | 56 UpdateNeedsBeginFramesInternal(); |
| 59 } | 57 } |
| 60 | 58 |
| 61 void CompositorFrameSinkSupport::SubmitCompositorFrame( | 59 void CompositorFrameSinkSupport::SubmitCompositorFrame( |
| 62 const LocalFrameId& local_frame_id, | 60 const LocalFrameId& local_frame_id, |
| 63 CompositorFrame frame) { | 61 CompositorFrame frame) { |
| 64 ++ack_pending_count_; | 62 ++ack_pending_count_; |
| 63 if (display_) { |
| 64 display_->SetLocalFrameId(local_frame_id, |
| 65 frame.metadata.device_scale_factor); |
| 66 } |
| 65 surface_factory_.SubmitCompositorFrame( | 67 surface_factory_.SubmitCompositorFrame( |
| 66 local_frame_id, std::move(frame), | 68 local_frame_id, std::move(frame), |
| 67 base::Bind(&CompositorFrameSinkSupport::DidReceiveCompositorFrameAck, | 69 base::Bind(&CompositorFrameSinkSupport::DidReceiveCompositorFrameAck, |
| 68 weak_factory_.GetWeakPtr())); | 70 weak_factory_.GetWeakPtr())); |
| 69 if (display_) { | |
| 70 display_->SetLocalFrameId(local_frame_id, | |
| 71 frame.metadata.device_scale_factor); | |
| 72 } | |
| 73 } | 71 } |
| 74 | 72 |
| 75 void CompositorFrameSinkSupport::Require(const LocalFrameId& local_frame_id, | 73 void CompositorFrameSinkSupport::Require(const LocalFrameId& local_frame_id, |
| 76 const SurfaceSequence& sequence) { | 74 const SurfaceSequence& sequence) { |
| 77 surface_manager_->RequireSequence(SurfaceId(frame_sink_id_, local_frame_id), | 75 surface_manager_->RequireSequence(SurfaceId(frame_sink_id_, local_frame_id), |
| 78 sequence); | 76 sequence); |
| 79 } | 77 } |
| 80 | 78 |
| 81 void CompositorFrameSinkSupport::Satisfy(const SurfaceSequence& sequence) { | 79 void CompositorFrameSinkSupport::Satisfy(const SurfaceSequence& sequence) { |
| 82 surface_manager_->SatisfySequence(sequence); | 80 surface_manager_->SatisfySequence(sequence); |
| 83 } | 81 } |
| 84 | 82 |
| 85 void CompositorFrameSinkSupport::DidReceiveCompositorFrameAck() { | 83 void CompositorFrameSinkSupport::DidReceiveCompositorFrameAck() { |
| 86 DCHECK_GT(ack_pending_count_, 0); | 84 DCHECK_GT(ack_pending_count_, 0); |
| 87 ack_pending_count_--; | 85 ack_pending_count_--; |
| 88 | 86 |
| 89 if (!client_) | 87 if (!client_) |
| 90 return; | 88 return; |
| 89 |
| 91 client_->DidReceiveCompositorFrameAck(); | 90 client_->DidReceiveCompositorFrameAck(); |
| 92 if (!surface_returned_resources_.empty()) { | 91 if (!surface_returned_resources_.empty()) { |
| 93 client_->ReclaimResources(surface_returned_resources_); | 92 client_->ReclaimResources(surface_returned_resources_); |
| 94 surface_returned_resources_.clear(); | 93 surface_returned_resources_.clear(); |
| 95 } | 94 } |
| 96 } | 95 } |
| 97 | 96 |
| 98 void CompositorFrameSinkSupport::AddChildFrameSink( | 97 void CompositorFrameSinkSupport::AddChildFrameSink( |
| 99 const FrameSinkId& child_frame_sink_id) { | 98 const FrameSinkId& child_frame_sink_id) { |
| 100 child_frame_sinks_.insert(child_frame_sink_id); | 99 child_frame_sinks_.insert(child_frame_sink_id); |
| 101 surface_manager_->RegisterFrameSinkHierarchy(frame_sink_id_, | 100 surface_manager_->RegisterFrameSinkHierarchy(frame_sink_id_, |
| 102 child_frame_sink_id); | 101 child_frame_sink_id); |
| 103 } | 102 } |
| 104 | 103 |
| 105 void CompositorFrameSinkSupport::RemoveChildFrameSink( | 104 void CompositorFrameSinkSupport::RemoveChildFrameSink( |
| 106 const FrameSinkId& child_frame_sink_id) { | 105 const FrameSinkId& child_frame_sink_id) { |
| 107 auto it = child_frame_sinks_.find(child_frame_sink_id); | 106 auto it = child_frame_sinks_.find(child_frame_sink_id); |
| 108 DCHECK(it != child_frame_sinks_.end()); | 107 DCHECK(it != child_frame_sinks_.end()); |
| 109 DCHECK(it->is_valid()); | 108 DCHECK(it->is_valid()); |
| 110 surface_manager_->UnregisterFrameSinkHierarchy(frame_sink_id_, | 109 surface_manager_->UnregisterFrameSinkHierarchy(frame_sink_id_, |
| 111 child_frame_sink_id); | 110 child_frame_sink_id); |
| 112 child_frame_sinks_.erase(it); | 111 child_frame_sinks_.erase(it); |
| 113 } | 112 } |
| 114 | 113 |
| 114 void CompositorFrameSinkSupport::SetNeedsSyncPoints(bool needs_sync_points) { |
| 115 surface_factory_.set_needs_sync_points(needs_sync_points); |
| 116 } |
| 117 |
| 118 void CompositorFrameSinkSupport::ForceReclaimResources() { |
| 119 surface_factory_.ClearSurface(); |
| 120 } |
| 121 |
| 115 void CompositorFrameSinkSupport::DisplayOutputSurfaceLost() {} | 122 void CompositorFrameSinkSupport::DisplayOutputSurfaceLost() {} |
| 116 | 123 |
| 117 void CompositorFrameSinkSupport::DisplayWillDrawAndSwap( | 124 void CompositorFrameSinkSupport::DisplayWillDrawAndSwap( |
| 118 bool will_draw_and_swap, | 125 bool will_draw_and_swap, |
| 119 const RenderPassList& render_passes) {} | 126 const RenderPassList& render_passes) {} |
| 120 | 127 |
| 121 void CompositorFrameSinkSupport::DisplayDidDrawAndSwap() {} | 128 void CompositorFrameSinkSupport::DisplayDidDrawAndSwap() {} |
| 122 | 129 |
| 123 void CompositorFrameSinkSupport::ReturnResources( | 130 void CompositorFrameSinkSupport::ReturnResources( |
| 124 const ReturnedResourceArray& resources) { | 131 const ReturnedResourceArray& resources) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 return; | 180 return; |
| 174 | 181 |
| 175 added_frame_observer_ = needs_begin_frame_; | 182 added_frame_observer_ = needs_begin_frame_; |
| 176 if (needs_begin_frame_) | 183 if (needs_begin_frame_) |
| 177 begin_frame_source_->AddObserver(this); | 184 begin_frame_source_->AddObserver(this); |
| 178 else | 185 else |
| 179 begin_frame_source_->RemoveObserver(this); | 186 begin_frame_source_->RemoveObserver(this); |
| 180 } | 187 } |
| 181 | 188 |
| 182 } // namespace cc | 189 } // namespace cc |
| OLD | NEW |