OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/gpu/renderer_compositor_frame_sink.h" | 5 #include "content/renderer/gpu/renderer_compositor_frame_sink.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 : base::MakeUnique<cc::ExternalBeginFrameSource>(this)), | 73 : base::MakeUnique<cc::ExternalBeginFrameSource>(this)), |
74 routing_id_(routing_id), | 74 routing_id_(routing_id), |
75 sink_client_binding_(this) { | 75 sink_client_binding_(this) { |
76 DCHECK(compositor_frame_sink_filter_); | 76 DCHECK(compositor_frame_sink_filter_); |
77 DCHECK(frame_swap_message_queue_); | 77 DCHECK(frame_swap_message_queue_); |
78 DCHECK(message_sender_); | 78 DCHECK(message_sender_); |
79 thread_checker_.DetachFromThread(); | 79 thread_checker_.DetachFromThread(); |
80 EstablishMojoConnection(); | 80 EstablishMojoConnection(); |
81 } | 81 } |
82 | 82 |
83 RendererCompositorFrameSink::~RendererCompositorFrameSink() { | 83 RendererCompositorFrameSink::~RendererCompositorFrameSink() = default; |
84 // TODO(crbug.com/702764): If not detached then IPC messages would crash | |
85 // after this class is destroyed. | |
86 CHECK(!bound_); | |
87 } | |
88 | 84 |
89 bool RendererCompositorFrameSink::BindToClient( | 85 bool RendererCompositorFrameSink::BindToClient( |
90 cc::CompositorFrameSinkClient* client) { | 86 cc::CompositorFrameSinkClient* client) { |
91 DCHECK(thread_checker_.CalledOnValidThread()); | 87 DCHECK(thread_checker_.CalledOnValidThread()); |
92 if (!cc::CompositorFrameSink::BindToClient(client)) | 88 if (!cc::CompositorFrameSink::BindToClient(client)) |
93 return false; | 89 return false; |
94 | 90 |
95 sink_.Bind(std::move(sink_ptr_info_)); | 91 sink_.Bind(std::move(sink_ptr_info_)); |
96 sink_client_binding_.Bind(std::move(sink_client_request_)); | 92 sink_client_binding_.Bind(std::move(sink_client_request_)); |
97 | 93 |
98 if (synthetic_begin_frame_source_) | 94 if (synthetic_begin_frame_source_) |
99 client_->SetBeginFrameSource(synthetic_begin_frame_source_.get()); | 95 client_->SetBeginFrameSource(synthetic_begin_frame_source_.get()); |
100 else | 96 else |
101 client_->SetBeginFrameSource(external_begin_frame_source_.get()); | 97 client_->SetBeginFrameSource(external_begin_frame_source_.get()); |
102 | 98 |
103 compositor_frame_sink_proxy_ = new RendererCompositorFrameSinkProxy(this); | 99 compositor_frame_sink_proxy_ = new RendererCompositorFrameSinkProxy(this); |
104 compositor_frame_sink_filter_handler_ = | 100 compositor_frame_sink_filter_handler_ = |
105 base::Bind(&RendererCompositorFrameSinkProxy::OnMessageReceived, | 101 base::Bind(&RendererCompositorFrameSinkProxy::OnMessageReceived, |
106 compositor_frame_sink_proxy_); | 102 compositor_frame_sink_proxy_); |
107 compositor_frame_sink_filter_->AddHandlerOnCompositorThread( | 103 compositor_frame_sink_filter_->AddHandlerOnCompositorThread( |
108 routing_id_, compositor_frame_sink_filter_handler_); | 104 routing_id_, compositor_frame_sink_filter_handler_); |
109 | |
110 bound_ = true; | |
111 return true; | 105 return true; |
112 } | 106 } |
113 | 107 |
114 void RendererCompositorFrameSink::DetachFromClient() { | 108 void RendererCompositorFrameSink::DetachFromClient() { |
115 DCHECK(thread_checker_.CalledOnValidThread()); | 109 DCHECK(thread_checker_.CalledOnValidThread()); |
116 client_->SetBeginFrameSource(nullptr); | 110 client_->SetBeginFrameSource(nullptr); |
117 // Destroy the begin frame source on the same thread it was bound on. | 111 // Destroy the begin frame source on the same thread it was bound on. |
118 // The CompositorFrameSink itself is destroyed on the main thread. | 112 // The CompositorFrameSink itself is destroyed on the main thread. |
119 external_begin_frame_source_ = nullptr; | 113 external_begin_frame_source_ = nullptr; |
120 synthetic_begin_frame_source_ = nullptr; | 114 synthetic_begin_frame_source_ = nullptr; |
121 compositor_frame_sink_proxy_->ClearCompositorFrameSink(); | 115 compositor_frame_sink_proxy_->ClearCompositorFrameSink(); |
122 compositor_frame_sink_filter_->RemoveHandlerOnCompositorThread( | 116 compositor_frame_sink_filter_->RemoveHandlerOnCompositorThread( |
123 routing_id_, compositor_frame_sink_filter_handler_); | 117 routing_id_, compositor_frame_sink_filter_handler_); |
124 sink_.reset(); | 118 sink_.reset(); |
125 sink_client_binding_.Close(); | 119 sink_client_binding_.Close(); |
126 cc::CompositorFrameSink::DetachFromClient(); | 120 cc::CompositorFrameSink::DetachFromClient(); |
127 bound_ = false; | |
128 } | 121 } |
129 | 122 |
130 void RendererCompositorFrameSink::SubmitCompositorFrame( | 123 void RendererCompositorFrameSink::SubmitCompositorFrame( |
131 cc::CompositorFrame frame) { | 124 cc::CompositorFrame frame) { |
132 // We should only submit CompositorFrames with valid BeginFrameAcks. | 125 // We should only submit CompositorFrames with valid BeginFrameAcks. |
133 DCHECK_LE(cc::BeginFrameArgs::kStartingFrameNumber, | 126 DCHECK_LE(cc::BeginFrameArgs::kStartingFrameNumber, |
134 frame.metadata.begin_frame_ack.sequence_number); | 127 frame.metadata.begin_frame_ack.sequence_number); |
135 if (ShouldAllocateNewLocalSurfaceId(frame)) | 128 if (ShouldAllocateNewLocalSurfaceId(frame)) |
136 local_surface_id_ = id_allocator_.GenerateId(); | 129 local_surface_id_ = id_allocator_.GenerateId(); |
137 UpdateFrameData(frame); | 130 UpdateFrameData(frame); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 cc::mojom::MojoCompositorFrameSinkRequest sink_request = | 244 cc::mojom::MojoCompositorFrameSinkRequest sink_request = |
252 mojo::MakeRequest(&sink); | 245 mojo::MakeRequest(&sink); |
253 cc::mojom::MojoCompositorFrameSinkClientPtr sink_client; | 246 cc::mojom::MojoCompositorFrameSinkClientPtr sink_client; |
254 sink_client_request_ = mojo::MakeRequest(&sink_client); | 247 sink_client_request_ = mojo::MakeRequest(&sink_client); |
255 RenderThreadImpl::current()->GetFrameSinkProvider()->CreateForWidget( | 248 RenderThreadImpl::current()->GetFrameSinkProvider()->CreateForWidget( |
256 routing_id_, std::move(sink_request), std::move(sink_client)); | 249 routing_id_, std::move(sink_request), std::move(sink_client)); |
257 sink_ptr_info_ = sink.PassInterface(); | 250 sink_ptr_info_ = sink.PassInterface(); |
258 } | 251 } |
259 | 252 |
260 } // namespace content | 253 } // namespace content |
OLD | NEW |