| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 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 "components/display_compositor/gpu_root_compositor_frame_sink.h" |
| 6 |
| 7 namespace display_compositor { |
| 8 |
| 9 GpuRootCompositorFrameSink::GpuRootCompositorFrameSink( |
| 10 GpuCompositorFrameSinkDelegate* delegate, |
| 11 cc::SurfaceManager* surface_manager, |
| 12 const cc::FrameSinkId& frame_sink_id, |
| 13 std::unique_ptr<cc::Display> display, |
| 14 std::unique_ptr<cc::BeginFrameSource> begin_frame_source, |
| 15 cc::mojom::MojoCompositorFrameSinkAssociatedRequest request, |
| 16 cc::mojom::MojoCompositorFrameSinkPrivateRequest |
| 17 compositor_frame_sink_private_request, |
| 18 cc::mojom::MojoCompositorFrameSinkClientPtr client, |
| 19 cc::mojom::DisplayPrivateAssociatedRequest display_private_request) |
| 20 : delegate_(delegate), |
| 21 support_(base::MakeUnique<cc::CompositorFrameSinkSupport>( |
| 22 this, |
| 23 surface_manager, |
| 24 frame_sink_id, |
| 25 true /* is_root */, |
| 26 true /* handles_frame_sink_id_invalidation */, |
| 27 true /* needs_sync_points */)), |
| 28 display_begin_frame_source_(std::move(begin_frame_source)), |
| 29 display_(std::move(display)), |
| 30 client_(std::move(client)), |
| 31 compositor_frame_sink_binding_(this, std::move(request)), |
| 32 compositor_frame_sink_private_binding_( |
| 33 this, |
| 34 std::move(compositor_frame_sink_private_request)), |
| 35 display_private_binding_(this, std::move(display_private_request)) { |
| 36 compositor_frame_sink_binding_.set_connection_error_handler( |
| 37 base::Bind(&GpuRootCompositorFrameSink::OnClientConnectionLost, |
| 38 base::Unretained(this))); |
| 39 compositor_frame_sink_private_binding_.set_connection_error_handler( |
| 40 base::Bind(&GpuRootCompositorFrameSink::OnPrivateConnectionLost, |
| 41 base::Unretained(this))); |
| 42 display_->Initialize(this, surface_manager); |
| 43 display_->SetVisible(true); |
| 44 } |
| 45 |
| 46 GpuRootCompositorFrameSink::~GpuRootCompositorFrameSink() = default; |
| 47 |
| 48 void GpuRootCompositorFrameSink::SetDisplayVisible(bool visible) { |
| 49 DCHECK(display_); |
| 50 display_->SetVisible(visible); |
| 51 } |
| 52 |
| 53 void GpuRootCompositorFrameSink::ResizeDisplay(const gfx::Size& size) { |
| 54 DCHECK(display_); |
| 55 display_->Resize(size); |
| 56 } |
| 57 |
| 58 void GpuRootCompositorFrameSink::SetDisplayColorSpace( |
| 59 const gfx::ColorSpace& color_space) { |
| 60 DCHECK(display_); |
| 61 display_->SetColorSpace(color_space); |
| 62 } |
| 63 |
| 64 void GpuRootCompositorFrameSink::SetOutputIsSecure(bool secure) { |
| 65 DCHECK(display_); |
| 66 display_->SetOutputIsSecure(secure); |
| 67 } |
| 68 |
| 69 void GpuRootCompositorFrameSink::SetLocalSurfaceId( |
| 70 const cc::LocalSurfaceId& local_surface_id, |
| 71 float scale_factor) { |
| 72 display_->SetLocalSurfaceId(local_surface_id, scale_factor); |
| 73 } |
| 74 |
| 75 void GpuRootCompositorFrameSink::EvictFrame() { |
| 76 support_->EvictFrame(); |
| 77 } |
| 78 |
| 79 void GpuRootCompositorFrameSink::SetNeedsBeginFrame(bool needs_begin_frame) { |
| 80 support_->SetNeedsBeginFrame(needs_begin_frame); |
| 81 } |
| 82 |
| 83 void GpuRootCompositorFrameSink::SubmitCompositorFrame( |
| 84 const cc::LocalSurfaceId& local_surface_id, |
| 85 cc::CompositorFrame frame) { |
| 86 support_->SubmitCompositorFrame(local_surface_id, std::move(frame)); |
| 87 } |
| 88 |
| 89 void GpuRootCompositorFrameSink::Require( |
| 90 const cc::LocalSurfaceId& local_surface_id, |
| 91 const cc::SurfaceSequence& sequence) { |
| 92 support_->Require(local_surface_id, sequence); |
| 93 } |
| 94 |
| 95 void GpuRootCompositorFrameSink::Satisfy(const cc::SurfaceSequence& sequence) { |
| 96 support_->Satisfy(sequence); |
| 97 } |
| 98 |
| 99 void GpuRootCompositorFrameSink::AddChildFrameSink( |
| 100 const cc::FrameSinkId& child_frame_sink_id) { |
| 101 support_->AddChildFrameSink(child_frame_sink_id); |
| 102 } |
| 103 |
| 104 void GpuRootCompositorFrameSink::RemoveChildFrameSink( |
| 105 const cc::FrameSinkId& child_frame_sink_id) { |
| 106 support_->RemoveChildFrameSink(child_frame_sink_id); |
| 107 } |
| 108 |
| 109 void GpuRootCompositorFrameSink::RequestCopyOfSurface( |
| 110 std::unique_ptr<cc::CopyOutputRequest> request) { |
| 111 support_->RequestCopyOfSurface(std::move(request)); |
| 112 } |
| 113 |
| 114 void GpuRootCompositorFrameSink::DisplayOutputSurfaceLost() { |
| 115 // TODO(staraz): Implement this. Client should hear about context/output |
| 116 // surface lost. |
| 117 } |
| 118 |
| 119 void GpuRootCompositorFrameSink::DisplayWillDrawAndSwap( |
| 120 bool will_draw_and_swap, |
| 121 const cc::RenderPassList& render_pass) {} |
| 122 |
| 123 void GpuRootCompositorFrameSink::DisplayDidDrawAndSwap() {} |
| 124 |
| 125 void GpuRootCompositorFrameSink::DidReceiveCompositorFrameAck() { |
| 126 if (client_) |
| 127 client_->DidReceiveCompositorFrameAck(); |
| 128 } |
| 129 |
| 130 void GpuRootCompositorFrameSink::OnBeginFrame(const cc::BeginFrameArgs& args) { |
| 131 if (client_) |
| 132 client_->OnBeginFrame(args); |
| 133 } |
| 134 |
| 135 void GpuRootCompositorFrameSink::ReclaimResources( |
| 136 const cc::ReturnedResourceArray& resources) { |
| 137 if (client_) |
| 138 client_->ReclaimResources(resources); |
| 139 } |
| 140 |
| 141 void GpuRootCompositorFrameSink::WillDrawSurface( |
| 142 const cc::LocalSurfaceId& local_surface_id, |
| 143 const gfx::Rect& damage_rect) { |
| 144 if (client_) |
| 145 client_->WillDrawSurface(local_surface_id, damage_rect); |
| 146 } |
| 147 |
| 148 void GpuRootCompositorFrameSink::OnClientConnectionLost() { |
| 149 client_connection_lost_ = true; |
| 150 // Request destruction of |this| only if both connections are lost. |
| 151 delegate_->OnClientConnectionLost(support_->frame_sink_id(), |
| 152 private_connection_lost_); |
| 153 } |
| 154 |
| 155 void GpuRootCompositorFrameSink::OnPrivateConnectionLost() { |
| 156 private_connection_lost_ = true; |
| 157 // Request destruction of |this| only if both connections are lost. |
| 158 delegate_->OnPrivateConnectionLost(support_->frame_sink_id(), |
| 159 client_connection_lost_); |
| 160 } |
| 161 |
| 162 } // namespace display_compositor |
| OLD | NEW |