OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "cc/surfaces/compositor_frame_sink_support.h" |
| 6 |
| 7 #include "cc/output/compositor_frame.h" |
| 8 #include "cc/scheduler/begin_frame_source.h" |
| 9 #include "cc/surfaces/compositor_frame_sink_support_client.h" |
| 10 #include "cc/surfaces/display.h" |
| 11 #include "cc/surfaces/surface_manager.h" |
| 12 |
| 13 namespace cc { |
| 14 |
| 15 CompositorFrameSinkSupport::CompositorFrameSinkSupport( |
| 16 CompositorFrameSinkSupportClient* client, |
| 17 SurfaceManager* surface_manager, |
| 18 const FrameSinkId& frame_sink_id, |
| 19 std::unique_ptr<Display> display) |
| 20 : client_(client), |
| 21 surface_manager_(surface_manager), |
| 22 frame_sink_id_(frame_sink_id), |
| 23 display_(std::move(display)), |
| 24 surface_factory_(frame_sink_id_, surface_manager_, this), |
| 25 weak_factory_(this) { |
| 26 surface_manager_->RegisterFrameSinkId(frame_sink_id_); |
| 27 surface_manager_->RegisterSurfaceFactoryClient(frame_sink_id_, this); |
| 28 |
| 29 if (display_) { |
| 30 display_->Initialize(this, surface_manager_); |
| 31 display_->SetVisible(true); |
| 32 } |
| 33 } |
| 34 |
| 35 CompositorFrameSinkSupport::~CompositorFrameSinkSupport() { |
| 36 // SurfaceFactory's destructor will attempt to return resources which will |
| 37 // call back into here and access |client_| so we should destroy |
| 38 // |surface_factory_|'s resources early on. |
| 39 surface_factory_.EvictSurface(); |
| 40 surface_manager_->UnregisterSurfaceFactoryClient(frame_sink_id_); |
| 41 surface_manager_->InvalidateFrameSinkId(frame_sink_id_); |
| 42 } |
| 43 |
| 44 void CompositorFrameSinkSupport::EvictFrame() { |
| 45 surface_factory_.EvictSurface(); |
| 46 } |
| 47 |
| 48 void CompositorFrameSinkSupport::SetNeedsBeginFrame(bool needs_begin_frame) { |
| 49 needs_begin_frame_ = needs_begin_frame; |
| 50 UpdateNeedsBeginFramesInternal(); |
| 51 } |
| 52 |
| 53 void CompositorFrameSinkSupport::SubmitCompositorFrame( |
| 54 const LocalFrameId& local_frame_id, |
| 55 CompositorFrame frame) { |
| 56 if (local_frame_id_ != local_frame_id) { |
| 57 local_frame_id_ = local_frame_id; |
| 58 if (display_ && !frame.render_pass_list.empty()) { |
| 59 gfx::Size frame_size = frame.render_pass_list[0]->output_rect.size(); |
| 60 // TODO(piman, fsamuel): We will likely want to revisit this because some |
| 61 // clients may want finer control over the Display sizing - since it |
| 62 // really means the actual size of the native window (Linux/Win Aura) or |
| 63 // display (Ozone). We may need to either prevent or gutter Display frames |
| 64 // until there is a correctly-sized top-level CompositorFrame available |
| 65 // (see ui::Compositor::DisableSwapUntilResize). We might want to resize |
| 66 // Display earlier. |
| 67 display_->Resize(frame_size); |
| 68 } |
| 69 } |
| 70 ++ack_pending_count_; |
| 71 surface_factory_.SubmitCompositorFrame( |
| 72 local_frame_id_, std::move(frame), |
| 73 base::Bind(&CompositorFrameSinkSupport::DidReceiveCompositorFrameAck, |
| 74 weak_factory_.GetWeakPtr())); |
| 75 if (display_) { |
| 76 display_->SetLocalFrameId(local_frame_id_, |
| 77 frame.metadata.device_scale_factor); |
| 78 } |
| 79 } |
| 80 |
| 81 void CompositorFrameSinkSupport::DidReceiveCompositorFrameAck() { |
| 82 DCHECK_GT(ack_pending_count_, 0); |
| 83 ack_pending_count_--; |
| 84 |
| 85 if (!client_) |
| 86 return; |
| 87 client_->DidReceiveCompositorFrameAck(); |
| 88 if (!surface_returned_resources_.empty()) { |
| 89 client_->ReclaimResources(surface_returned_resources_); |
| 90 surface_returned_resources_.clear(); |
| 91 } |
| 92 } |
| 93 |
| 94 void CompositorFrameSinkSupport::AddChildFrameSink( |
| 95 const FrameSinkId& child_frame_sink_id) { |
| 96 surface_manager_->RegisterFrameSinkHierarchy(frame_sink_id_, |
| 97 child_frame_sink_id); |
| 98 } |
| 99 |
| 100 void CompositorFrameSinkSupport::RemoveChildFrameSink( |
| 101 const FrameSinkId& child_frame_sink_id) { |
| 102 surface_manager_->UnregisterFrameSinkHierarchy(frame_sink_id_, |
| 103 child_frame_sink_id); |
| 104 } |
| 105 |
| 106 void CompositorFrameSinkSupport::DisplayOutputSurfaceLost() {} |
| 107 |
| 108 void CompositorFrameSinkSupport::DisplayWillDrawAndSwap( |
| 109 bool will_draw_and_swap, |
| 110 const RenderPassList& render_passes) {} |
| 111 |
| 112 void CompositorFrameSinkSupport::DisplayDidDrawAndSwap() {} |
| 113 |
| 114 void CompositorFrameSinkSupport::ReturnResources( |
| 115 const ReturnedResourceArray& resources) { |
| 116 if (resources.empty()) |
| 117 return; |
| 118 |
| 119 if (!ack_pending_count_ && client_) { |
| 120 client_->ReclaimResources(resources); |
| 121 return; |
| 122 } |
| 123 |
| 124 std::copy(resources.begin(), resources.end(), |
| 125 std::back_inserter(surface_returned_resources_)); |
| 126 } |
| 127 |
| 128 void CompositorFrameSinkSupport::SetBeginFrameSource( |
| 129 BeginFrameSource* begin_frame_source) { |
| 130 if (begin_frame_source_ && added_frame_observer_) { |
| 131 begin_frame_source_->RemoveObserver(this); |
| 132 added_frame_observer_ = false; |
| 133 } |
| 134 begin_frame_source_ = begin_frame_source; |
| 135 UpdateNeedsBeginFramesInternal(); |
| 136 } |
| 137 |
| 138 void CompositorFrameSinkSupport::WillDrawSurface( |
| 139 const LocalFrameId& local_frame_id, |
| 140 const gfx::Rect& damage_rect) { |
| 141 if (client_) |
| 142 client_->WillDrawSurface(); |
| 143 } |
| 144 |
| 145 void CompositorFrameSinkSupport::OnBeginFrame(const BeginFrameArgs& args) { |
| 146 UpdateNeedsBeginFramesInternal(); |
| 147 last_begin_frame_args_ = args; |
| 148 if (client_) |
| 149 client_->OnBeginFrame(args); |
| 150 } |
| 151 |
| 152 const BeginFrameArgs& CompositorFrameSinkSupport::LastUsedBeginFrameArgs() |
| 153 const { |
| 154 return last_begin_frame_args_; |
| 155 } |
| 156 |
| 157 void CompositorFrameSinkSupport::OnBeginFrameSourcePausedChanged(bool paused) {} |
| 158 |
| 159 void CompositorFrameSinkSupport::UpdateNeedsBeginFramesInternal() { |
| 160 if (!begin_frame_source_) |
| 161 return; |
| 162 |
| 163 if (needs_begin_frame_ == added_frame_observer_) |
| 164 return; |
| 165 |
| 166 added_frame_observer_ = needs_begin_frame_; |
| 167 if (needs_begin_frame_) |
| 168 begin_frame_source_->AddObserver(this); |
| 169 else |
| 170 begin_frame_source_->RemoveObserver(this); |
| 171 } |
| 172 |
| 173 } // namespace cc |
OLD | NEW |