Chromium Code Reviews| 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 11 matching lines...) Expand all Loading... | |
| 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, | 31 uint32_t compositor_frame_sink_id, |
| 32 std::unique_ptr<cc::BeginFrameSource> begin_frame_source, | 32 std::unique_ptr<cc::SyntheticBeginFrameSource> synthetic_begin_frame_source, |
| 33 scoped_refptr<cc::ContextProvider> context_provider, | 33 scoped_refptr<cc::ContextProvider> context_provider, |
| 34 scoped_refptr<cc::ContextProvider> worker_context_provider, | 34 scoped_refptr<cc::ContextProvider> worker_context_provider, |
| 35 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 35 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
| 36 cc::SharedBitmapManager* shared_bitmap_manager, | 36 cc::SharedBitmapManager* shared_bitmap_manager, |
| 37 scoped_refptr<FrameSwapMessageQueue> swap_frame_message_queue) | 37 scoped_refptr<FrameSwapMessageQueue> swap_frame_message_queue) |
| 38 : CompositorFrameSink(std::move(context_provider), | 38 : CompositorFrameSink(std::move(context_provider), |
| 39 std::move(worker_context_provider), | 39 std::move(worker_context_provider), |
| 40 gpu_memory_buffer_manager, | 40 gpu_memory_buffer_manager, |
| 41 shared_bitmap_manager), | 41 shared_bitmap_manager), |
| 42 compositor_frame_sink_id_(compositor_frame_sink_id), | 42 compositor_frame_sink_id_(compositor_frame_sink_id), |
| 43 compositor_frame_sink_filter_( | 43 compositor_frame_sink_filter_( |
| 44 RenderThreadImpl::current()->compositor_message_filter()), | 44 RenderThreadImpl::current()->compositor_message_filter()), |
| 45 message_sender_(RenderThreadImpl::current()->sync_message_filter()), | 45 message_sender_(RenderThreadImpl::current()->sync_message_filter()), |
| 46 frame_swap_message_queue_(swap_frame_message_queue), | 46 frame_swap_message_queue_(swap_frame_message_queue), |
| 47 begin_frame_source_(std::move(begin_frame_source)), | 47 synthetic_begin_frame_source_(std::move(synthetic_begin_frame_source)), |
| 48 external_begin_frame_source_( | |
| 49 synthetic_begin_frame_source_ | |
| 50 ? nullptr | |
| 51 : base::MakeUnique<cc::ExternalBeginFrameSource>(this)), | |
| 48 routing_id_(routing_id) { | 52 routing_id_(routing_id) { |
| 49 DCHECK(compositor_frame_sink_filter_); | 53 DCHECK(compositor_frame_sink_filter_); |
| 50 DCHECK(frame_swap_message_queue_); | 54 DCHECK(frame_swap_message_queue_); |
| 51 DCHECK(message_sender_); | 55 DCHECK(message_sender_); |
| 52 DCHECK(begin_frame_source_); | |
| 53 thread_checker_.DetachFromThread(); | 56 thread_checker_.DetachFromThread(); |
| 54 } | 57 } |
| 55 | 58 |
| 56 RendererCompositorFrameSink::RendererCompositorFrameSink( | 59 RendererCompositorFrameSink::RendererCompositorFrameSink( |
| 57 int32_t routing_id, | 60 int32_t routing_id, |
| 58 uint32_t compositor_frame_sink_id, | 61 uint32_t compositor_frame_sink_id, |
| 59 std::unique_ptr<cc::BeginFrameSource> begin_frame_source, | 62 std::unique_ptr<cc::SyntheticBeginFrameSource> synthetic_begin_frame_source, |
| 60 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider, | 63 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider, |
| 61 scoped_refptr<FrameSwapMessageQueue> swap_frame_message_queue) | 64 scoped_refptr<FrameSwapMessageQueue> swap_frame_message_queue) |
| 62 : CompositorFrameSink(std::move(vulkan_context_provider)), | 65 : CompositorFrameSink(std::move(vulkan_context_provider)), |
| 63 compositor_frame_sink_id_(compositor_frame_sink_id), | 66 compositor_frame_sink_id_(compositor_frame_sink_id), |
| 64 compositor_frame_sink_filter_( | 67 compositor_frame_sink_filter_( |
| 65 RenderThreadImpl::current()->compositor_message_filter()), | 68 RenderThreadImpl::current()->compositor_message_filter()), |
| 66 message_sender_(RenderThreadImpl::current()->sync_message_filter()), | 69 message_sender_(RenderThreadImpl::current()->sync_message_filter()), |
| 67 frame_swap_message_queue_(swap_frame_message_queue), | 70 frame_swap_message_queue_(swap_frame_message_queue), |
| 68 begin_frame_source_(std::move(begin_frame_source)), | 71 synthetic_begin_frame_source_(std::move(synthetic_begin_frame_source)), |
| 72 external_begin_frame_source_( | |
| 73 synthetic_begin_frame_source_ | |
| 74 ? nullptr | |
| 75 : base::MakeUnique<cc::ExternalBeginFrameSource>(this)), | |
| 69 routing_id_(routing_id) { | 76 routing_id_(routing_id) { |
| 70 DCHECK(compositor_frame_sink_filter_); | 77 DCHECK(compositor_frame_sink_filter_); |
| 71 DCHECK(frame_swap_message_queue_); | 78 DCHECK(frame_swap_message_queue_); |
| 72 DCHECK(message_sender_); | 79 DCHECK(message_sender_); |
| 73 DCHECK(begin_frame_source_); | |
| 74 thread_checker_.DetachFromThread(); | 80 thread_checker_.DetachFromThread(); |
| 75 } | 81 } |
| 76 | 82 |
| 77 RendererCompositorFrameSink::~RendererCompositorFrameSink() { | 83 RendererCompositorFrameSink::~RendererCompositorFrameSink() { |
| 78 // TODO(crbug.com/702764): If not detached then IPC messages would crash | 84 // TODO(crbug.com/702764): If not detached then IPC messages would crash |
| 79 // after this class is destroyed. | 85 // after this class is destroyed. |
| 80 CHECK(!bound_); | 86 CHECK(!bound_); |
| 81 } | 87 } |
| 82 | 88 |
| 83 bool RendererCompositorFrameSink::BindToClient( | 89 bool RendererCompositorFrameSink::BindToClient( |
| 84 cc::CompositorFrameSinkClient* client) { | 90 cc::CompositorFrameSinkClient* client) { |
| 85 DCHECK(thread_checker_.CalledOnValidThread()); | 91 DCHECK(thread_checker_.CalledOnValidThread()); |
| 86 if (!cc::CompositorFrameSink::BindToClient(client)) | 92 if (!cc::CompositorFrameSink::BindToClient(client)) |
| 87 return false; | 93 return false; |
| 88 | 94 |
| 89 DCHECK(begin_frame_source_); | 95 if (synthetic_begin_frame_source_) |
| 90 client_->SetBeginFrameSource(begin_frame_source_.get()); | 96 client_->SetBeginFrameSource(synthetic_begin_frame_source_.get()); |
| 97 else | |
| 98 client_->SetBeginFrameSource(external_begin_frame_source_.get()); | |
| 91 | 99 |
| 92 compositor_frame_sink_proxy_ = new RendererCompositorFrameSinkProxy(this); | 100 compositor_frame_sink_proxy_ = new RendererCompositorFrameSinkProxy(this); |
| 93 compositor_frame_sink_filter_handler_ = | 101 compositor_frame_sink_filter_handler_ = |
| 94 base::Bind(&RendererCompositorFrameSinkProxy::OnMessageReceived, | 102 base::Bind(&RendererCompositorFrameSinkProxy::OnMessageReceived, |
| 95 compositor_frame_sink_proxy_); | 103 compositor_frame_sink_proxy_); |
| 96 compositor_frame_sink_filter_->AddHandlerOnCompositorThread( | 104 compositor_frame_sink_filter_->AddHandlerOnCompositorThread( |
| 97 routing_id_, compositor_frame_sink_filter_handler_); | 105 routing_id_, compositor_frame_sink_filter_handler_); |
| 98 bound_ = true; | 106 bound_ = true; |
| 99 return true; | 107 return true; |
| 100 } | 108 } |
| 101 | 109 |
| 102 void RendererCompositorFrameSink::DetachFromClient() { | 110 void RendererCompositorFrameSink::DetachFromClient() { |
| 103 DCHECK(thread_checker_.CalledOnValidThread()); | 111 DCHECK(thread_checker_.CalledOnValidThread()); |
| 104 client_->SetBeginFrameSource(nullptr); | 112 client_->SetBeginFrameSource(nullptr); |
| 105 // Destroy the begin frame source on the same thread it was bound on. | 113 // Destroy the begin frame source on the same thread it was bound on. |
| 106 // The CompositorFrameSink itself is destroyed on the main thread. | 114 // The CompositorFrameSink itself is destroyed on the main thread. |
| 107 begin_frame_source_ = nullptr; | 115 external_begin_frame_source_ = nullptr; |
| 116 synthetic_begin_frame_source_ = nullptr; | |
| 108 compositor_frame_sink_proxy_->ClearCompositorFrameSink(); | 117 compositor_frame_sink_proxy_->ClearCompositorFrameSink(); |
| 109 compositor_frame_sink_filter_->RemoveHandlerOnCompositorThread( | 118 compositor_frame_sink_filter_->RemoveHandlerOnCompositorThread( |
| 110 routing_id_, compositor_frame_sink_filter_handler_); | 119 routing_id_, compositor_frame_sink_filter_handler_); |
| 111 | 120 |
| 112 cc::CompositorFrameSink::DetachFromClient(); | 121 cc::CompositorFrameSink::DetachFromClient(); |
| 113 bound_ = false; | 122 bound_ = false; |
| 114 } | 123 } |
| 115 | 124 |
| 116 void RendererCompositorFrameSink::SubmitCompositorFrame( | 125 void RendererCompositorFrameSink::SubmitCompositorFrame( |
| 117 cc::CompositorFrame frame) { | 126 cc::CompositorFrame frame) { |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 135 messages_to_deliver_with_frame)); | 144 messages_to_deliver_with_frame)); |
| 136 // ~send_message_scope. | 145 // ~send_message_scope. |
| 137 } | 146 } |
| 138 } | 147 } |
| 139 | 148 |
| 140 void RendererCompositorFrameSink::OnMessageReceived( | 149 void RendererCompositorFrameSink::OnMessageReceived( |
| 141 const IPC::Message& message) { | 150 const IPC::Message& message) { |
| 142 DCHECK(thread_checker_.CalledOnValidThread()); | 151 DCHECK(thread_checker_.CalledOnValidThread()); |
| 143 IPC_BEGIN_MESSAGE_MAP(RendererCompositorFrameSink, message) | 152 IPC_BEGIN_MESSAGE_MAP(RendererCompositorFrameSink, message) |
| 144 IPC_MESSAGE_HANDLER(ViewMsg_ReclaimCompositorResources, | 153 IPC_MESSAGE_HANDLER(ViewMsg_ReclaimCompositorResources, |
| 145 OnReclaimCompositorResources); | 154 OnReclaimCompositorResources) |
| 155 IPC_MESSAGE_HANDLER(ViewMsg_SetBeginFramePaused, | |
| 156 OnSetBeginFrameSourcePaused) | |
| 157 IPC_MESSAGE_HANDLER(ViewMsg_BeginFrame, OnBeginFrame) | |
|
Fady Samuel
2017/03/24 21:30:31
Where was this handled previously?
Saman Sami
2017/03/24 21:37:16
Here https://cs.chromium.org/chromium/src/content/
| |
| 146 IPC_END_MESSAGE_MAP() | 158 IPC_END_MESSAGE_MAP() |
| 147 } | 159 } |
| 148 | 160 |
| 149 void RendererCompositorFrameSink::OnReclaimCompositorResources( | 161 void RendererCompositorFrameSink::OnReclaimCompositorResources( |
| 150 uint32_t compositor_frame_sink_id, | 162 uint32_t compositor_frame_sink_id, |
| 151 bool is_swap_ack, | 163 bool is_swap_ack, |
| 152 const cc::ReturnedResourceArray& resources) { | 164 const cc::ReturnedResourceArray& resources) { |
| 153 // Ignore message if it's a stale one coming from a different output surface | 165 // Ignore message if it's a stale one coming from a different output surface |
| 154 // (e.g. after a lost context). | 166 // (e.g. after a lost context). |
| 155 if (compositor_frame_sink_id != compositor_frame_sink_id_) | 167 if (compositor_frame_sink_id != compositor_frame_sink_id_) |
| 156 return; | 168 return; |
| 157 client_->ReclaimResources(resources); | 169 client_->ReclaimResources(resources); |
| 158 if (is_swap_ack) | 170 if (is_swap_ack) |
| 159 client_->DidReceiveCompositorFrameAck(); | 171 client_->DidReceiveCompositorFrameAck(); |
| 160 } | 172 } |
| 161 | 173 |
| 174 void RendererCompositorFrameSink::OnSetBeginFrameSourcePaused(bool paused) { | |
| 175 if (external_begin_frame_source_) | |
| 176 external_begin_frame_source_->OnSetBeginFrameSourcePaused(paused); | |
| 177 } | |
| 178 | |
| 179 void RendererCompositorFrameSink::OnBeginFrame(const cc::BeginFrameArgs& args) { | |
| 180 if (external_begin_frame_source_) | |
| 181 external_begin_frame_source_->OnBeginFrame(args); | |
| 182 } | |
| 183 | |
| 162 bool RendererCompositorFrameSink::Send(IPC::Message* message) { | 184 bool RendererCompositorFrameSink::Send(IPC::Message* message) { |
| 163 return message_sender_->Send(message); | 185 return message_sender_->Send(message); |
| 164 } | 186 } |
| 165 | 187 |
| 166 bool RendererCompositorFrameSink::ShouldAllocateNewLocalSurfaceId( | 188 bool RendererCompositorFrameSink::ShouldAllocateNewLocalSurfaceId( |
| 167 const cc::CompositorFrame& frame) { | 189 const cc::CompositorFrame& frame) { |
| 168 cc::RenderPass* root_pass = frame.render_pass_list.back().get(); | 190 cc::RenderPass* root_pass = frame.render_pass_list.back().get(); |
| 169 gfx::Size frame_size = root_pass->output_rect.size(); | 191 gfx::Size frame_size = root_pass->output_rect.size(); |
| 170 | 192 |
| 171 // Once the proposal in crbug.com/689754 is implemented, the LocalSurfaceId | 193 // Once the proposal in crbug.com/689754 is implemented, the LocalSurfaceId |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 203 current_frame_data_.bottom_controls_height = | 225 current_frame_data_.bottom_controls_height = |
| 204 frame.metadata.bottom_controls_height; | 226 frame.metadata.bottom_controls_height; |
| 205 current_frame_data_.bottom_controls_shown_ratio = | 227 current_frame_data_.bottom_controls_shown_ratio = |
| 206 frame.metadata.bottom_controls_shown_ratio; | 228 frame.metadata.bottom_controls_shown_ratio; |
| 207 current_frame_data_.viewport_selection = frame.metadata.selection; | 229 current_frame_data_.viewport_selection = frame.metadata.selection; |
| 208 current_frame_data_.has_transparent_background = | 230 current_frame_data_.has_transparent_background = |
| 209 root_pass->has_transparent_background; | 231 root_pass->has_transparent_background; |
| 210 #endif | 232 #endif |
| 211 } | 233 } |
| 212 | 234 |
| 235 void RendererCompositorFrameSink::OnNeedsBeginFrames(bool needs_begin_frames) { | |
| 236 Send(new ViewHostMsg_SetNeedsBeginFrames(routing_id_, needs_begin_frames)); | |
| 237 } | |
| 238 | |
| 239 void RendererCompositorFrameSink::OnDidFinishFrame( | |
| 240 const cc::BeginFrameAck& ack) { | |
| 241 DCHECK_LE(cc::BeginFrameArgs::kStartingFrameNumber, ack.sequence_number); | |
| 242 // If there was damage, ViewHostMsg_SwapCompositorFrame includes the ack. | |
| 243 if (!ack.has_damage) | |
| 244 Send(new ViewHostMsg_BeginFrameDidNotSwap(routing_id_, ack)); | |
| 245 } | |
| 246 | |
| 213 } // namespace content | 247 } // namespace content |
| OLD | NEW |