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