| 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 } |
| 37 | 35 |
| 38 CompositorFrameSinkSupport::~CompositorFrameSinkSupport() { | 36 CompositorFrameSinkSupport::~CompositorFrameSinkSupport() { |
| 39 for (auto& child_frame_sink_id : child_frame_sinks_) { | 37 for (auto& child_frame_sink_id : child_frame_sinks_) { |
| 40 DCHECK(child_frame_sink_id.is_valid()); | 38 DCHECK(child_frame_sink_id.is_valid()); |
| 41 surface_manager_->UnregisterFrameSinkHierarchy(frame_sink_id_, | 39 surface_manager_->UnregisterFrameSinkHierarchy(frame_sink_id_, |
| 42 child_frame_sink_id); | 40 child_frame_sink_id); |
| 43 } | 41 } |
| 44 // SurfaceFactory's destructor will attempt to return resources which will | 42 // SurfaceFactory's destructor will attempt to return resources which will |
| 45 // call back into here and access |client_| so we should destroy | 43 // call back into here and access |client_| so we should destroy |
| 46 // |surface_factory_|'s resources early on. | 44 // |surface_factory_|'s resources early on. |
| 47 surface_factory_.EvictSurface(); | 45 surface_factory_.EvictSurface(); |
| 48 surface_manager_->UnregisterSurfaceFactoryClient(frame_sink_id_); | 46 surface_manager_->UnregisterSurfaceFactoryClient(frame_sink_id_); |
| 47 } |
| 48 |
| 49 void CompositorFrameSinkSupport::InvalidateFrameSinkId() { |
| 49 surface_manager_->InvalidateFrameSinkId(frame_sink_id_); | 50 surface_manager_->InvalidateFrameSinkId(frame_sink_id_); |
| 50 } | 51 } |
| 51 | 52 |
| 52 void CompositorFrameSinkSupport::EvictFrame() { | 53 void CompositorFrameSinkSupport::EvictFrame() { |
| 53 surface_factory_.EvictSurface(); | 54 surface_factory_.EvictSurface(); |
| 54 } | 55 } |
| 55 | 56 |
| 56 void CompositorFrameSinkSupport::SetNeedsBeginFrame(bool needs_begin_frame) { | 57 void CompositorFrameSinkSupport::SetNeedsBeginFrame(bool needs_begin_frame) { |
| 57 needs_begin_frame_ = needs_begin_frame; | 58 needs_begin_frame_ = needs_begin_frame; |
| 58 UpdateNeedsBeginFramesInternal(); | 59 UpdateNeedsBeginFramesInternal(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 69 // clients may want finer control over the Display sizing - since it | 70 // clients may want finer control over the Display sizing - since it |
| 70 // really means the actual size of the native window (Linux/Win Aura) or | 71 // really means the actual size of the native window (Linux/Win Aura) or |
| 71 // display (Ozone). We may need to either prevent or gutter Display frames | 72 // display (Ozone). We may need to either prevent or gutter Display frames |
| 72 // until there is a correctly-sized top-level CompositorFrame available | 73 // until there is a correctly-sized top-level CompositorFrame available |
| 73 // (see ui::Compositor::DisableSwapUntilResize). We might want to resize | 74 // (see ui::Compositor::DisableSwapUntilResize). We might want to resize |
| 74 // Display earlier. | 75 // Display earlier. |
| 75 display_->Resize(frame_size); | 76 display_->Resize(frame_size); |
| 76 } | 77 } |
| 77 } | 78 } |
| 78 ++ack_pending_count_; | 79 ++ack_pending_count_; |
| 80 if (display_) { |
| 81 display_->SetLocalFrameId(local_frame_id_, |
| 82 frame.metadata.device_scale_factor); |
| 83 } |
| 79 surface_factory_.SubmitCompositorFrame( | 84 surface_factory_.SubmitCompositorFrame( |
| 80 local_frame_id_, std::move(frame), | 85 local_frame_id_, std::move(frame), |
| 81 base::Bind(&CompositorFrameSinkSupport::DidReceiveCompositorFrameAck, | 86 base::Bind(&CompositorFrameSinkSupport::DidReceiveCompositorFrameAck, |
| 82 weak_factory_.GetWeakPtr())); | 87 weak_factory_.GetWeakPtr())); |
| 83 if (display_) { | |
| 84 display_->SetLocalFrameId(local_frame_id_, | |
| 85 frame.metadata.device_scale_factor); | |
| 86 } | |
| 87 } | 88 } |
| 88 | 89 |
| 89 void CompositorFrameSinkSupport::Require(const LocalFrameId& local_frame_id, | 90 void CompositorFrameSinkSupport::Require(const LocalFrameId& local_frame_id, |
| 90 const SurfaceSequence& sequence) { | 91 const SurfaceSequence& sequence) { |
| 91 surface_manager_->RequireSequence(SurfaceId(frame_sink_id_, local_frame_id), | 92 surface_manager_->RequireSequence(SurfaceId(frame_sink_id_, local_frame_id), |
| 92 sequence); | 93 sequence); |
| 93 } | 94 } |
| 94 | 95 |
| 95 void CompositorFrameSinkSupport::Satisfy(const SurfaceSequence& sequence) { | 96 void CompositorFrameSinkSupport::Satisfy(const SurfaceSequence& sequence) { |
| 96 surface_manager_->SatisfySequence(sequence); | 97 surface_manager_->SatisfySequence(sequence); |
| 97 } | 98 } |
| 98 | 99 |
| 99 void CompositorFrameSinkSupport::DidReceiveCompositorFrameAck() { | 100 void CompositorFrameSinkSupport::DidReceiveCompositorFrameAck() { |
| 100 DCHECK_GT(ack_pending_count_, 0); | 101 DCHECK_GT(ack_pending_count_, 0); |
| 101 ack_pending_count_--; | 102 ack_pending_count_--; |
| 102 | 103 |
| 103 if (!client_) | 104 if (!client_) |
| 104 return; | 105 return; |
| 106 |
| 105 client_->DidReceiveCompositorFrameAck(); | 107 client_->DidReceiveCompositorFrameAck(); |
| 106 if (!surface_returned_resources_.empty()) { | 108 if (!surface_returned_resources_.empty()) { |
| 107 client_->ReclaimResources(surface_returned_resources_); | 109 client_->ReclaimResources(surface_returned_resources_); |
| 108 surface_returned_resources_.clear(); | 110 surface_returned_resources_.clear(); |
| 109 } | 111 } |
| 110 } | 112 } |
| 111 | 113 |
| 112 void CompositorFrameSinkSupport::AddChildFrameSink( | 114 void CompositorFrameSinkSupport::AddChildFrameSink( |
| 113 const FrameSinkId& child_frame_sink_id) { | 115 const FrameSinkId& child_frame_sink_id) { |
| 114 child_frame_sinks_.insert(child_frame_sink_id); | 116 child_frame_sinks_.insert(child_frame_sink_id); |
| 115 surface_manager_->RegisterFrameSinkHierarchy(frame_sink_id_, | 117 surface_manager_->RegisterFrameSinkHierarchy(frame_sink_id_, |
| 116 child_frame_sink_id); | 118 child_frame_sink_id); |
| 117 } | 119 } |
| 118 | 120 |
| 119 void CompositorFrameSinkSupport::RemoveChildFrameSink( | 121 void CompositorFrameSinkSupport::RemoveChildFrameSink( |
| 120 const FrameSinkId& child_frame_sink_id) { | 122 const FrameSinkId& child_frame_sink_id) { |
| 121 auto it = child_frame_sinks_.find(child_frame_sink_id); | 123 auto it = child_frame_sinks_.find(child_frame_sink_id); |
| 122 DCHECK(it != child_frame_sinks_.end()); | 124 DCHECK(it != child_frame_sinks_.end()); |
| 123 DCHECK(it->is_valid()); | 125 DCHECK(it->is_valid()); |
| 124 surface_manager_->UnregisterFrameSinkHierarchy(frame_sink_id_, | 126 surface_manager_->UnregisterFrameSinkHierarchy(frame_sink_id_, |
| 125 child_frame_sink_id); | 127 child_frame_sink_id); |
| 126 child_frame_sinks_.erase(it); | 128 child_frame_sinks_.erase(it); |
| 127 } | 129 } |
| 128 | 130 |
| 131 void CompositorFrameSinkSupport::SetNeedsSyncPoints(bool needs_sync_points) { |
| 132 surface_factory_.set_needs_sync_points(needs_sync_points); |
| 133 } |
| 134 |
| 135 void CompositorFrameSinkSupport::ForceReclaimResources() { |
| 136 if (local_frame_id_.is_valid()) |
| 137 surface_factory_.ClearSurface(); |
| 138 } |
| 139 |
| 129 void CompositorFrameSinkSupport::DisplayOutputSurfaceLost() {} | 140 void CompositorFrameSinkSupport::DisplayOutputSurfaceLost() {} |
| 130 | 141 |
| 131 void CompositorFrameSinkSupport::DisplayWillDrawAndSwap( | 142 void CompositorFrameSinkSupport::DisplayWillDrawAndSwap( |
| 132 bool will_draw_and_swap, | 143 bool will_draw_and_swap, |
| 133 const RenderPassList& render_passes) {} | 144 const RenderPassList& render_passes) {} |
| 134 | 145 |
| 135 void CompositorFrameSinkSupport::DisplayDidDrawAndSwap() {} | 146 void CompositorFrameSinkSupport::DisplayDidDrawAndSwap() {} |
| 136 | 147 |
| 137 void CompositorFrameSinkSupport::ReturnResources( | 148 void CompositorFrameSinkSupport::ReturnResources( |
| 138 const ReturnedResourceArray& resources) { | 149 const ReturnedResourceArray& resources) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 return; | 198 return; |
| 188 | 199 |
| 189 added_frame_observer_ = needs_begin_frame_; | 200 added_frame_observer_ = needs_begin_frame_; |
| 190 if (needs_begin_frame_) | 201 if (needs_begin_frame_) |
| 191 begin_frame_source_->AddObserver(this); | 202 begin_frame_source_->AddObserver(this); |
| 192 else | 203 else |
| 193 begin_frame_source_->RemoveObserver(this); | 204 begin_frame_source_->RemoveObserver(this); |
| 194 } | 205 } |
| 195 | 206 |
| 196 } // namespace cc | 207 } // namespace cc |
| OLD | NEW |