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