| 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, 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::BeginFrameDidNotSwap( | |
| 93 const cc::BeginFrameAck& begin_frame_ack) { | |
| 94 support_->BeginFrameDidNotSwap(begin_frame_ack); | |
| 95 } | |
| 96 | |
| 97 void GpuRootCompositorFrameSink::ClaimTemporaryReference( | |
| 98 const cc::SurfaceId& surface_id) { | |
| 99 support_->ClaimTemporaryReference(surface_id); | |
| 100 } | |
| 101 | |
| 102 void GpuRootCompositorFrameSink::RequestCopyOfSurface( | |
| 103 std::unique_ptr<cc::CopyOutputRequest> request) { | |
| 104 support_->RequestCopyOfSurface(std::move(request)); | |
| 105 } | |
| 106 | |
| 107 void GpuRootCompositorFrameSink::DisplayOutputSurfaceLost() { | |
| 108 // TODO(staraz): Implement this. Client should hear about context/output | |
| 109 // surface lost. | |
| 110 } | |
| 111 | |
| 112 void GpuRootCompositorFrameSink::DisplayWillDrawAndSwap( | |
| 113 bool will_draw_and_swap, | |
| 114 const cc::RenderPassList& render_pass) {} | |
| 115 | |
| 116 void GpuRootCompositorFrameSink::DisplayDidDrawAndSwap() {} | |
| 117 | |
| 118 void GpuRootCompositorFrameSink::DidReceiveCompositorFrameAck() { | |
| 119 if (client_) | |
| 120 client_->DidReceiveCompositorFrameAck(); | |
| 121 } | |
| 122 | |
| 123 void GpuRootCompositorFrameSink::OnBeginFrame(const cc::BeginFrameArgs& args) { | |
| 124 if (client_) | |
| 125 client_->OnBeginFrame(args); | |
| 126 } | |
| 127 | |
| 128 void GpuRootCompositorFrameSink::ReclaimResources( | |
| 129 const cc::ReturnedResourceArray& resources) { | |
| 130 if (client_) | |
| 131 client_->ReclaimResources(resources); | |
| 132 } | |
| 133 | |
| 134 void GpuRootCompositorFrameSink::WillDrawSurface( | |
| 135 const cc::LocalSurfaceId& local_surface_id, | |
| 136 const gfx::Rect& damage_rect) { | |
| 137 if (client_) | |
| 138 client_->WillDrawSurface(local_surface_id, damage_rect); | |
| 139 } | |
| 140 | |
| 141 void GpuRootCompositorFrameSink::OnClientConnectionLost() { | |
| 142 client_connection_lost_ = true; | |
| 143 // Request destruction of |this| only if both connections are lost. | |
| 144 delegate_->OnClientConnectionLost(support_->frame_sink_id(), | |
| 145 private_connection_lost_); | |
| 146 } | |
| 147 | |
| 148 void GpuRootCompositorFrameSink::OnPrivateConnectionLost() { | |
| 149 private_connection_lost_ = true; | |
| 150 // Request destruction of |this| only if both connections are lost. | |
| 151 delegate_->OnPrivateConnectionLost(support_->frame_sink_id(), | |
| 152 client_connection_lost_); | |
| 153 } | |
| 154 | |
| 155 } // namespace display_compositor | |
| OLD | NEW |