Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: content/renderer/gpu/renderer_compositor_frame_sink.cc

Issue 2774373002: Use MojoCompositorFrameSink in RendererCompositorFrameSink (Closed)
Patch Set: Fixed mac Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 10 matching lines...) Expand all
21 #include "gpu/command_buffer/client/context_support.h" 21 #include "gpu/command_buffer/client/context_support.h"
22 #include "gpu/command_buffer/client/gles2_interface.h" 22 #include "gpu/command_buffer/client/gles2_interface.h"
23 #include "gpu/ipc/client/command_buffer_proxy_impl.h" 23 #include "gpu/ipc/client/command_buffer_proxy_impl.h"
24 #include "ipc/ipc_sync_channel.h" 24 #include "ipc/ipc_sync_channel.h"
25 #include "services/ui/public/cpp/gpu/context_provider_command_buffer.h" 25 #include "services/ui/public/cpp/gpu/context_provider_command_buffer.h"
26 26
27 namespace content { 27 namespace content {
28 28
29 RendererCompositorFrameSink::RendererCompositorFrameSink( 29 RendererCompositorFrameSink::RendererCompositorFrameSink(
30 int32_t routing_id, 30 int32_t routing_id,
31 uint32_t compositor_frame_sink_id,
32 std::unique_ptr<cc::SyntheticBeginFrameSource> synthetic_begin_frame_source, 31 std::unique_ptr<cc::SyntheticBeginFrameSource> synthetic_begin_frame_source,
33 scoped_refptr<cc::ContextProvider> context_provider, 32 scoped_refptr<cc::ContextProvider> context_provider,
34 scoped_refptr<cc::ContextProvider> worker_context_provider, 33 scoped_refptr<cc::ContextProvider> worker_context_provider,
35 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, 34 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
36 cc::SharedBitmapManager* shared_bitmap_manager, 35 cc::SharedBitmapManager* shared_bitmap_manager,
37 scoped_refptr<FrameSwapMessageQueue> swap_frame_message_queue) 36 scoped_refptr<FrameSwapMessageQueue> swap_frame_message_queue)
38 : CompositorFrameSink(std::move(context_provider), 37 : CompositorFrameSink(std::move(context_provider),
39 std::move(worker_context_provider), 38 std::move(worker_context_provider),
40 gpu_memory_buffer_manager, 39 gpu_memory_buffer_manager,
41 shared_bitmap_manager), 40 shared_bitmap_manager),
42 compositor_frame_sink_id_(compositor_frame_sink_id),
43 compositor_frame_sink_filter_(
44 RenderThreadImpl::current()->compositor_message_filter()),
45 message_sender_(RenderThreadImpl::current()->sync_message_filter()), 41 message_sender_(RenderThreadImpl::current()->sync_message_filter()),
46 frame_swap_message_queue_(swap_frame_message_queue), 42 frame_swap_message_queue_(swap_frame_message_queue),
47 synthetic_begin_frame_source_(std::move(synthetic_begin_frame_source)), 43 synthetic_begin_frame_source_(std::move(synthetic_begin_frame_source)),
48 external_begin_frame_source_( 44 external_begin_frame_source_(
49 synthetic_begin_frame_source_ 45 synthetic_begin_frame_source_
50 ? nullptr 46 ? nullptr
51 : base::MakeUnique<cc::ExternalBeginFrameSource>(this)), 47 : base::MakeUnique<cc::ExternalBeginFrameSource>(this)),
52 routing_id_(routing_id) { 48 routing_id_(routing_id),
53 DCHECK(compositor_frame_sink_filter_); 49 sink_client_binding_(this) {
54 DCHECK(frame_swap_message_queue_); 50 DCHECK(frame_swap_message_queue_);
55 DCHECK(message_sender_); 51 DCHECK(message_sender_);
56 thread_checker_.DetachFromThread(); 52 thread_checker_.DetachFromThread();
53 EstablishMojoConnection();
57 } 54 }
58 55
59 RendererCompositorFrameSink::RendererCompositorFrameSink( 56 RendererCompositorFrameSink::RendererCompositorFrameSink(
60 int32_t routing_id, 57 int32_t routing_id,
61 uint32_t compositor_frame_sink_id,
62 std::unique_ptr<cc::SyntheticBeginFrameSource> synthetic_begin_frame_source, 58 std::unique_ptr<cc::SyntheticBeginFrameSource> synthetic_begin_frame_source,
63 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider, 59 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider,
64 scoped_refptr<FrameSwapMessageQueue> swap_frame_message_queue) 60 scoped_refptr<FrameSwapMessageQueue> swap_frame_message_queue)
65 : CompositorFrameSink(std::move(vulkan_context_provider)), 61 : CompositorFrameSink(std::move(vulkan_context_provider)),
66 compositor_frame_sink_id_(compositor_frame_sink_id),
67 compositor_frame_sink_filter_(
68 RenderThreadImpl::current()->compositor_message_filter()),
69 message_sender_(RenderThreadImpl::current()->sync_message_filter()), 62 message_sender_(RenderThreadImpl::current()->sync_message_filter()),
70 frame_swap_message_queue_(swap_frame_message_queue), 63 frame_swap_message_queue_(swap_frame_message_queue),
71 synthetic_begin_frame_source_(std::move(synthetic_begin_frame_source)), 64 synthetic_begin_frame_source_(std::move(synthetic_begin_frame_source)),
72 external_begin_frame_source_( 65 external_begin_frame_source_(
73 synthetic_begin_frame_source_ 66 synthetic_begin_frame_source_
74 ? nullptr 67 ? nullptr
75 : base::MakeUnique<cc::ExternalBeginFrameSource>(this)), 68 : base::MakeUnique<cc::ExternalBeginFrameSource>(this)),
76 routing_id_(routing_id) { 69 routing_id_(routing_id),
77 DCHECK(compositor_frame_sink_filter_); 70 sink_client_binding_(this) {
78 DCHECK(frame_swap_message_queue_); 71 DCHECK(frame_swap_message_queue_);
79 DCHECK(message_sender_); 72 DCHECK(message_sender_);
80 thread_checker_.DetachFromThread(); 73 thread_checker_.DetachFromThread();
74 EstablishMojoConnection();
81 } 75 }
82 76
83 RendererCompositorFrameSink::~RendererCompositorFrameSink() { 77 RendererCompositorFrameSink::~RendererCompositorFrameSink() {
84 // TODO(crbug.com/702764): If not detached then IPC messages would crash 78 // TODO(crbug.com/702764): If not detached then IPC messages would crash
85 // after this class is destroyed. 79 // after this class is destroyed.
86 CHECK(!bound_); 80 CHECK(!bound_);
87 } 81 }
88 82
89 bool RendererCompositorFrameSink::BindToClient( 83 bool RendererCompositorFrameSink::BindToClient(
90 cc::CompositorFrameSinkClient* client) { 84 cc::CompositorFrameSinkClient* client) {
91 DCHECK(thread_checker_.CalledOnValidThread()); 85 DCHECK(thread_checker_.CalledOnValidThread());
92 if (!cc::CompositorFrameSink::BindToClient(client)) 86 if (!cc::CompositorFrameSink::BindToClient(client))
93 return false; 87 return false;
94 88
89 sink_.Bind(std::move(sink_ptr_info_));
90 sink_client_binding_.Bind(std::move(sink_client_request_));
91
95 if (synthetic_begin_frame_source_) 92 if (synthetic_begin_frame_source_)
96 client_->SetBeginFrameSource(synthetic_begin_frame_source_.get()); 93 client_->SetBeginFrameSource(synthetic_begin_frame_source_.get());
97 else 94 else
98 client_->SetBeginFrameSource(external_begin_frame_source_.get()); 95 client_->SetBeginFrameSource(external_begin_frame_source_.get());
99 96
100 compositor_frame_sink_proxy_ = new RendererCompositorFrameSinkProxy(this);
101 compositor_frame_sink_filter_handler_ =
102 base::Bind(&RendererCompositorFrameSinkProxy::OnMessageReceived,
103 compositor_frame_sink_proxy_);
104 compositor_frame_sink_filter_->AddHandlerOnCompositorThread(
105 routing_id_, compositor_frame_sink_filter_handler_);
106 bound_ = true; 97 bound_ = true;
107 return true; 98 return true;
108 } 99 }
109 100
110 void RendererCompositorFrameSink::DetachFromClient() { 101 void RendererCompositorFrameSink::DetachFromClient() {
111 DCHECK(thread_checker_.CalledOnValidThread()); 102 DCHECK(thread_checker_.CalledOnValidThread());
112 client_->SetBeginFrameSource(nullptr); 103 client_->SetBeginFrameSource(nullptr);
113 // Destroy the begin frame source on the same thread it was bound on. 104 // Destroy the begin frame source on the same thread it was bound on.
114 // The CompositorFrameSink itself is destroyed on the main thread. 105 // The CompositorFrameSink itself is destroyed on the main thread.
115 external_begin_frame_source_ = nullptr; 106 external_begin_frame_source_ = nullptr;
116 synthetic_begin_frame_source_ = nullptr; 107 synthetic_begin_frame_source_ = nullptr;
117 compositor_frame_sink_proxy_->ClearCompositorFrameSink(); 108 sink_.reset();
118 compositor_frame_sink_filter_->RemoveHandlerOnCompositorThread( 109 sink_client_binding_.Close();
119 routing_id_, compositor_frame_sink_filter_handler_);
120
121 cc::CompositorFrameSink::DetachFromClient(); 110 cc::CompositorFrameSink::DetachFromClient();
122 bound_ = false; 111 bound_ = false;
123 } 112 }
124 113
125 void RendererCompositorFrameSink::SubmitCompositorFrame( 114 void RendererCompositorFrameSink::SubmitCompositorFrame(
126 cc::CompositorFrame frame) { 115 cc::CompositorFrame frame) {
127 // We should only submit CompositorFrames with valid BeginFrameAcks. 116 // We should only submit CompositorFrames with valid BeginFrameAcks.
128 DCHECK_LE(cc::BeginFrameArgs::kStartingFrameNumber, 117 DCHECK_LE(cc::BeginFrameArgs::kStartingFrameNumber,
129 frame.metadata.begin_frame_ack.sequence_number); 118 frame.metadata.begin_frame_ack.sequence_number);
130 if (ShouldAllocateNewLocalSurfaceId(frame)) 119 if (ShouldAllocateNewLocalSurfaceId(frame))
131 local_surface_id_ = id_allocator_.GenerateId(); 120 local_surface_id_ = id_allocator_.GenerateId();
132 UpdateFrameData(frame); 121 UpdateFrameData(frame);
133 122
134 { 123 {
135 std::unique_ptr<FrameSwapMessageQueue::SendMessageScope> 124 std::unique_ptr<FrameSwapMessageQueue::SendMessageScope>
136 send_message_scope = 125 send_message_scope =
137 frame_swap_message_queue_->AcquireSendMessageScope(); 126 frame_swap_message_queue_->AcquireSendMessageScope();
138 std::vector<std::unique_ptr<IPC::Message>> messages; 127 std::vector<std::unique_ptr<IPC::Message>> messages;
139 frame_swap_message_queue_->DrainMessages(&messages); 128 frame_swap_message_queue_->DrainMessages(&messages);
140 std::vector<IPC::Message> messages_to_send; 129 std::vector<IPC::Message> messages_to_send;
141 FrameSwapMessageQueue::TransferMessages(&messages, &messages_to_send); 130 FrameSwapMessageQueue::TransferMessages(&messages, &messages_to_send);
142 uint32_t frame_token = 0; 131 uint32_t frame_token = 0;
143 if (!messages_to_send.empty()) 132 if (!messages_to_send.empty())
144 frame_token = frame_swap_message_queue_->AllocateFrameToken(); 133 frame_token = frame_swap_message_queue_->AllocateFrameToken();
145 frame.metadata.frame_token = frame_token; 134 frame.metadata.frame_token = frame_token;
146 Send(new ViewHostMsg_SwapCompositorFrame( 135 sink_->SubmitCompositorFrame(local_surface_id_, std::move(frame));
147 routing_id_, compositor_frame_sink_id_, local_surface_id_, frame));
148 if (frame_token) { 136 if (frame_token) {
149 Send(new ViewHostMsg_FrameSwapMessages(routing_id_, frame_token, 137 message_sender_->Send(new ViewHostMsg_FrameSwapMessages(
150 messages_to_send)); 138 routing_id_, frame_token, messages_to_send));
151 } 139 }
152 // ~send_message_scope. 140 // ~send_message_scope.
153 } 141 }
154 } 142 }
155 143
156 void RendererCompositorFrameSink::OnMessageReceived(
157 const IPC::Message& message) {
158 DCHECK(thread_checker_.CalledOnValidThread());
159 IPC_BEGIN_MESSAGE_MAP(RendererCompositorFrameSink, message)
160 IPC_MESSAGE_HANDLER(ViewMsg_ReclaimCompositorResources,
161 OnReclaimCompositorResources)
162 IPC_MESSAGE_HANDLER(ViewMsg_SetBeginFramePaused,
163 OnSetBeginFrameSourcePaused)
164 IPC_MESSAGE_HANDLER(ViewMsg_BeginFrame, OnBeginFrame)
165 IPC_END_MESSAGE_MAP()
166 }
167
168 void RendererCompositorFrameSink::OnReclaimCompositorResources(
169 uint32_t compositor_frame_sink_id,
170 bool is_swap_ack,
171 const cc::ReturnedResourceArray& resources) {
172 // Ignore message if it's a stale one coming from a different output surface
173 // (e.g. after a lost context).
174 if (compositor_frame_sink_id != compositor_frame_sink_id_)
175 return;
176 client_->ReclaimResources(resources);
177 if (is_swap_ack)
178 client_->DidReceiveCompositorFrameAck();
179 }
180
181 void RendererCompositorFrameSink::OnSetBeginFrameSourcePaused(bool paused) {
182 if (external_begin_frame_source_)
183 external_begin_frame_source_->OnSetBeginFrameSourcePaused(paused);
184 }
185
186 void RendererCompositorFrameSink::OnBeginFrame(const cc::BeginFrameArgs& args) {
187 if (external_begin_frame_source_)
188 external_begin_frame_source_->OnBeginFrame(args);
189 }
190
191 bool RendererCompositorFrameSink::Send(IPC::Message* message) {
192 return message_sender_->Send(message);
193 }
194
195 bool RendererCompositorFrameSink::ShouldAllocateNewLocalSurfaceId( 144 bool RendererCompositorFrameSink::ShouldAllocateNewLocalSurfaceId(
196 const cc::CompositorFrame& frame) { 145 const cc::CompositorFrame& frame) {
197 cc::RenderPass* root_pass = frame.render_pass_list.back().get(); 146 cc::RenderPass* root_pass = frame.render_pass_list.back().get();
198 gfx::Size frame_size = root_pass->output_rect.size(); 147 gfx::Size frame_size = root_pass->output_rect.size();
199 148
200 // Once the proposal in crbug.com/689754 is implemented, the LocalSurfaceId 149 // Once the proposal in crbug.com/689754 is implemented, the LocalSurfaceId
201 // allocation logic will be unified across all platforms. 150 // allocation logic will be unified across all platforms.
202 return !local_surface_id_.is_valid() || 151 return !local_surface_id_.is_valid() ||
203 current_frame_data_.device_scale_factor != 152 current_frame_data_.device_scale_factor !=
204 frame.metadata.device_scale_factor || 153 frame.metadata.device_scale_factor ||
(...skipping 27 matching lines...) Expand all
232 current_frame_data_.bottom_controls_height = 181 current_frame_data_.bottom_controls_height =
233 frame.metadata.bottom_controls_height; 182 frame.metadata.bottom_controls_height;
234 current_frame_data_.bottom_controls_shown_ratio = 183 current_frame_data_.bottom_controls_shown_ratio =
235 frame.metadata.bottom_controls_shown_ratio; 184 frame.metadata.bottom_controls_shown_ratio;
236 current_frame_data_.viewport_selection = frame.metadata.selection; 185 current_frame_data_.viewport_selection = frame.metadata.selection;
237 current_frame_data_.has_transparent_background = 186 current_frame_data_.has_transparent_background =
238 root_pass->has_transparent_background; 187 root_pass->has_transparent_background;
239 #endif 188 #endif
240 } 189 }
241 190
191 void RendererCompositorFrameSink::DidReceiveCompositorFrameAck() {
192 client_->DidReceiveCompositorFrameAck();
193 }
194
195 void RendererCompositorFrameSink::OnBeginFrame(const cc::BeginFrameArgs& args) {
196 if (external_begin_frame_source_)
197 external_begin_frame_source_->OnBeginFrame(args);
198 }
199
200 void RendererCompositorFrameSink::ReclaimResources(
201 const cc::ReturnedResourceArray& resources) {
202 client_->ReclaimResources(resources);
203 }
204
242 void RendererCompositorFrameSink::OnNeedsBeginFrames(bool needs_begin_frames) { 205 void RendererCompositorFrameSink::OnNeedsBeginFrames(bool needs_begin_frames) {
243 Send(new ViewHostMsg_SetNeedsBeginFrames(routing_id_, needs_begin_frames)); 206 sink_->SetNeedsBeginFrame(needs_begin_frames);
244 } 207 }
245 208
246 void RendererCompositorFrameSink::OnDidFinishFrame( 209 void RendererCompositorFrameSink::OnDidFinishFrame(
247 const cc::BeginFrameAck& ack) { 210 const cc::BeginFrameAck& ack) {
248 DCHECK_LE(cc::BeginFrameArgs::kStartingFrameNumber, ack.sequence_number); 211 DCHECK_LE(cc::BeginFrameArgs::kStartingFrameNumber, ack.sequence_number);
249 // If there was damage, ViewHostMsg_SwapCompositorFrame includes the ack. 212 // If there was damage, ViewHostMsg_SwapCompositorFrame includes the ack.
250 if (!ack.has_damage) 213 if (!ack.has_damage)
251 Send(new ViewHostMsg_BeginFrameDidNotSwap(routing_id_, ack)); 214 sink_->BeginFrameDidNotSwap(ack);
215 }
216
217 void RendererCompositorFrameSink::EstablishMojoConnection() {
218 cc::mojom::MojoCompositorFrameSinkPtr sink;
219 cc::mojom::MojoCompositorFrameSinkRequest sink_request =
220 mojo::MakeRequest(&sink);
221 cc::mojom::MojoCompositorFrameSinkClientPtr sink_client;
222 sink_client_request_ = mojo::MakeRequest(&sink_client);
223 RenderThreadImpl::current()->GetFrameSinkProvider()->CreateForWidget(
224 routing_id_, std::move(sink_request), std::move(sink_client));
225 sink_ptr_info_ = sink.PassInterface();
252 } 226 }
253 227
254 } // namespace content 228 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698