| 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/compositor_output_surface.h" | 5 #include "content/renderer/gpu/compositor_output_surface.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 12 matching lines...) Expand all Loading... |
| 23 #include "gpu/command_buffer/client/context_support.h" | 23 #include "gpu/command_buffer/client/context_support.h" |
| 24 #include "gpu/command_buffer/client/gles2_interface.h" | 24 #include "gpu/command_buffer/client/gles2_interface.h" |
| 25 #include "gpu/ipc/client/command_buffer_proxy_impl.h" | 25 #include "gpu/ipc/client/command_buffer_proxy_impl.h" |
| 26 #include "ipc/ipc_sync_channel.h" | 26 #include "ipc/ipc_sync_channel.h" |
| 27 | 27 |
| 28 namespace content { | 28 namespace content { |
| 29 | 29 |
| 30 CompositorOutputSurface::CompositorOutputSurface( | 30 CompositorOutputSurface::CompositorOutputSurface( |
| 31 int32_t routing_id, | 31 int32_t routing_id, |
| 32 uint32_t output_surface_id, | 32 uint32_t output_surface_id, |
| 33 const scoped_refptr<ContextProviderCommandBuffer>& context_provider, | 33 scoped_refptr<cc::ContextProvider> context_provider, |
| 34 const scoped_refptr<ContextProviderCommandBuffer>& worker_context_provider, | 34 scoped_refptr<cc::ContextProvider> worker_context_provider, |
| 35 const scoped_refptr<cc::VulkanContextProvider>& vulkan_context_provider, | 35 scoped_refptr<FrameSwapMessageQueue> swap_frame_message_queue) |
| 36 std::unique_ptr<cc::SoftwareOutputDevice> software_device, | 36 : OutputSurface(std::move(context_provider), |
| 37 scoped_refptr<FrameSwapMessageQueue> swap_frame_message_queue, | 37 std::move(worker_context_provider), |
| 38 bool use_swap_compositor_frame_message) | 38 nullptr), |
| 39 : OutputSurface(context_provider, | |
| 40 worker_context_provider, | |
| 41 vulkan_context_provider, | |
| 42 std::move(software_device)), | |
| 43 output_surface_id_(output_surface_id), | 39 output_surface_id_(output_surface_id), |
| 44 use_swap_compositor_frame_message_(use_swap_compositor_frame_message), | |
| 45 output_surface_filter_( | 40 output_surface_filter_( |
| 46 RenderThreadImpl::current()->compositor_message_filter()), | 41 RenderThreadImpl::current()->compositor_message_filter()), |
| 42 message_sender_(RenderThreadImpl::current()->sync_message_filter()), |
| 47 frame_swap_message_queue_(swap_frame_message_queue), | 43 frame_swap_message_queue_(swap_frame_message_queue), |
| 48 routing_id_(routing_id), | 44 routing_id_(routing_id) { |
| 49 layout_test_mode_(RenderThreadImpl::current()->layout_test_mode()), | 45 DCHECK(output_surface_filter_); |
| 50 weak_ptrs_(this) { | 46 DCHECK(frame_swap_message_queue_); |
| 51 DCHECK(output_surface_filter_.get()); | 47 DCHECK(message_sender_); |
| 52 DCHECK(frame_swap_message_queue_.get()); | 48 capabilities_.delegated_rendering = true; |
| 53 message_sender_ = RenderThreadImpl::current()->sync_message_filter(); | |
| 54 DCHECK(message_sender_.get()); | |
| 55 } | 49 } |
| 56 | 50 |
| 57 CompositorOutputSurface::~CompositorOutputSurface() {} | 51 CompositorOutputSurface::CompositorOutputSurface( |
| 52 int32_t routing_id, |
| 53 uint32_t output_surface_id, |
| 54 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider, |
| 55 scoped_refptr<FrameSwapMessageQueue> swap_frame_message_queue) |
| 56 : OutputSurface(std::move(vulkan_context_provider)), |
| 57 output_surface_id_(output_surface_id), |
| 58 output_surface_filter_( |
| 59 RenderThreadImpl::current()->compositor_message_filter()), |
| 60 message_sender_(RenderThreadImpl::current()->sync_message_filter()), |
| 61 frame_swap_message_queue_(swap_frame_message_queue), |
| 62 routing_id_(routing_id) { |
| 63 DCHECK(output_surface_filter_); |
| 64 DCHECK(frame_swap_message_queue_); |
| 65 DCHECK(message_sender_); |
| 66 capabilities_.delegated_rendering = true; |
| 67 } |
| 68 |
| 69 CompositorOutputSurface::~CompositorOutputSurface() = default; |
| 58 | 70 |
| 59 bool CompositorOutputSurface::BindToClient( | 71 bool CompositorOutputSurface::BindToClient( |
| 60 cc::OutputSurfaceClient* client) { | 72 cc::OutputSurfaceClient* client) { |
| 61 if (!cc::OutputSurface::BindToClient(client)) | 73 if (!cc::OutputSurface::BindToClient(client)) |
| 62 return false; | 74 return false; |
| 63 | 75 |
| 64 output_surface_proxy_ = new CompositorOutputSurfaceProxy(this); | 76 output_surface_proxy_ = new CompositorOutputSurfaceProxy(this); |
| 65 output_surface_filter_handler_ = | 77 output_surface_filter_handler_ = |
| 66 base::Bind(&CompositorOutputSurfaceProxy::OnMessageReceived, | 78 base::Bind(&CompositorOutputSurfaceProxy::OnMessageReceived, |
| 67 output_surface_proxy_); | 79 output_surface_proxy_); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 84 if (!HasClient()) | 96 if (!HasClient()) |
| 85 return; | 97 return; |
| 86 if (output_surface_proxy_) { | 98 if (output_surface_proxy_) { |
| 87 output_surface_proxy_->ClearOutputSurface(); | 99 output_surface_proxy_->ClearOutputSurface(); |
| 88 output_surface_filter_->RemoveHandlerOnCompositorThread( | 100 output_surface_filter_->RemoveHandlerOnCompositorThread( |
| 89 routing_id_, output_surface_filter_handler_); | 101 routing_id_, output_surface_filter_handler_); |
| 90 } | 102 } |
| 91 cc::OutputSurface::DetachFromClient(); | 103 cc::OutputSurface::DetachFromClient(); |
| 92 } | 104 } |
| 93 | 105 |
| 94 void CompositorOutputSurface::ShortcutSwapAck( | 106 void CompositorOutputSurface::SwapBuffers(cc::CompositorFrame* frame) { |
| 95 uint32_t output_surface_id, | 107 { |
| 96 std::unique_ptr<cc::GLFrameData> gl_frame_data) { | 108 std::unique_ptr<FrameSwapMessageQueue::SendMessageScope> |
| 97 if (!layout_test_previous_frame_ack_) { | 109 send_message_scope = |
| 98 layout_test_previous_frame_ack_.reset(new cc::CompositorFrameAck); | 110 frame_swap_message_queue_->AcquireSendMessageScope(); |
| 99 layout_test_previous_frame_ack_->gl_frame_data.reset(new cc::GLFrameData); | 111 std::vector<std::unique_ptr<IPC::Message>> messages; |
| 112 std::vector<IPC::Message> messages_to_deliver_with_frame; |
| 113 frame_swap_message_queue_->DrainMessages(&messages); |
| 114 FrameSwapMessageQueue::TransferMessages(&messages, |
| 115 &messages_to_deliver_with_frame); |
| 116 Send(new ViewHostMsg_SwapCompositorFrame(routing_id_, output_surface_id_, |
| 117 *frame, |
| 118 messages_to_deliver_with_frame)); |
| 119 // ~send_message_scope. |
| 100 } | 120 } |
| 101 | 121 client_->DidSwapBuffers(); |
| 102 OnSwapAck(output_surface_id, *layout_test_previous_frame_ack_); | |
| 103 | |
| 104 layout_test_previous_frame_ack_->gl_frame_data = std::move(gl_frame_data); | |
| 105 } | |
| 106 | |
| 107 void CompositorOutputSurface::SwapBuffers(cc::CompositorFrame* frame) { | |
| 108 DCHECK(use_swap_compositor_frame_message_); | |
| 109 if (layout_test_mode_) { | |
| 110 // This code path is here to support layout tests that are currently | |
| 111 // doing a readback in the renderer instead of the browser. So they | |
| 112 // are using deprecated code paths in the renderer and don't need to | |
| 113 // actually swap anything to the browser. We shortcut the swap to the | |
| 114 // browser here and just ack directly within the renderer process. | |
| 115 // Once crbug.com/311404 is fixed, this can be removed. | |
| 116 | |
| 117 // This would indicate that crbug.com/311404 is being fixed, and this | |
| 118 // block needs to be removed. | |
| 119 DCHECK(!frame->delegated_frame_data); | |
| 120 | |
| 121 base::Closure closure = base::Bind( | |
| 122 &CompositorOutputSurface::ShortcutSwapAck, weak_ptrs_.GetWeakPtr(), | |
| 123 output_surface_id_, base::Passed(&frame->gl_frame_data)); | |
| 124 | |
| 125 if (context_provider()) { | |
| 126 gpu::gles2::GLES2Interface* context = context_provider()->ContextGL(); | |
| 127 const uint64_t fence_sync = context->InsertFenceSyncCHROMIUM(); | |
| 128 context->Flush(); | |
| 129 | |
| 130 gpu::SyncToken sync_token; | |
| 131 context->GenUnverifiedSyncTokenCHROMIUM(fence_sync, sync_token.GetData()); | |
| 132 | |
| 133 context_provider()->ContextSupport()->SignalSyncToken(sync_token, | |
| 134 closure); | |
| 135 } else { | |
| 136 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, closure); | |
| 137 } | |
| 138 client_->DidSwapBuffers(); | |
| 139 return; | |
| 140 } else { | |
| 141 { | |
| 142 std::vector<std::unique_ptr<IPC::Message>> messages; | |
| 143 std::vector<IPC::Message> messages_to_deliver_with_frame; | |
| 144 std::unique_ptr<FrameSwapMessageQueue::SendMessageScope> | |
| 145 send_message_scope = | |
| 146 frame_swap_message_queue_->AcquireSendMessageScope(); | |
| 147 frame_swap_message_queue_->DrainMessages(&messages); | |
| 148 FrameSwapMessageQueue::TransferMessages(&messages, | |
| 149 &messages_to_deliver_with_frame); | |
| 150 Send(new ViewHostMsg_SwapCompositorFrame(routing_id_, | |
| 151 output_surface_id_, | |
| 152 *frame, | |
| 153 messages_to_deliver_with_frame)); | |
| 154 // ~send_message_scope. | |
| 155 } | |
| 156 client_->DidSwapBuffers(); | |
| 157 } | |
| 158 } | 122 } |
| 159 | 123 |
| 160 void CompositorOutputSurface::OnMessageReceived(const IPC::Message& message) { | 124 void CompositorOutputSurface::OnMessageReceived(const IPC::Message& message) { |
| 161 DCHECK(client_thread_checker_.CalledOnValidThread()); | 125 DCHECK(client_thread_checker_.CalledOnValidThread()); |
| 162 if (!HasClient()) | 126 if (!HasClient()) |
| 163 return; | 127 return; |
| 164 IPC_BEGIN_MESSAGE_MAP(CompositorOutputSurface, message) | 128 IPC_BEGIN_MESSAGE_MAP(CompositorOutputSurface, message) |
| 165 IPC_MESSAGE_HANDLER(ViewMsg_UpdateVSyncParameters, | 129 IPC_MESSAGE_HANDLER(ViewMsg_UpdateVSyncParameters, |
| 166 OnUpdateVSyncParametersFromBrowser); | 130 OnUpdateVSyncParametersFromBrowser); |
| 167 IPC_MESSAGE_HANDLER(ViewMsg_SwapCompositorFrameAck, OnSwapAck); | 131 IPC_MESSAGE_HANDLER(ViewMsg_SwapCompositorFrameAck, OnSwapAck); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 198 if (output_surface_id != output_surface_id_) | 162 if (output_surface_id != output_surface_id_) |
| 199 return; | 163 return; |
| 200 ReclaimResources(&ack); | 164 ReclaimResources(&ack); |
| 201 } | 165 } |
| 202 | 166 |
| 203 bool CompositorOutputSurface::Send(IPC::Message* message) { | 167 bool CompositorOutputSurface::Send(IPC::Message* message) { |
| 204 return message_sender_->Send(message); | 168 return message_sender_->Send(message); |
| 205 } | 169 } |
| 206 | 170 |
| 207 } // namespace content | 171 } // namespace content |
| OLD | NEW |