| 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 "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/message_loop_proxy.h" | 8 #include "base/message_loop_proxy.h" |
| 9 #include "cc/output/compositor_frame.h" | 9 #include "cc/output/compositor_frame.h" |
| 10 #include "cc/output/compositor_frame_ack.h" | 10 #include "cc/output/compositor_frame_ack.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 }; | 43 }; |
| 44 | 44 |
| 45 return new IPC::ForwardingMessageFilter( | 45 return new IPC::ForwardingMessageFilter( |
| 46 messages_to_filter, arraysize(messages_to_filter), | 46 messages_to_filter, arraysize(messages_to_filter), |
| 47 target_task_runner); | 47 target_task_runner); |
| 48 } | 48 } |
| 49 | 49 |
| 50 CompositorOutputSurface::CompositorOutputSurface( | 50 CompositorOutputSurface::CompositorOutputSurface( |
| 51 int32 routing_id, | 51 int32 routing_id, |
| 52 WebGraphicsContext3DCommandBufferImpl* context3D, | 52 WebGraphicsContext3DCommandBufferImpl* context3D, |
| 53 cc::SoftwareOutputDevice* software_device) | 53 cc::SoftwareOutputDevice* software_device, |
| 54 bool swap_buffers_via_ipc) |
| 54 : OutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D>(context3D), | 55 : OutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D>(context3D), |
| 55 make_scoped_ptr(software_device)), | 56 make_scoped_ptr(software_device)), |
| 57 use_swap_compositor_frame_message_(swap_buffers_via_ipc), |
| 56 output_surface_filter_( | 58 output_surface_filter_( |
| 57 RenderThreadImpl::current()->compositor_output_surface_filter()), | 59 RenderThreadImpl::current()->compositor_output_surface_filter()), |
| 58 routing_id_(routing_id), | 60 routing_id_(routing_id), |
| 59 prefers_smoothness_(false), | 61 prefers_smoothness_(false), |
| 60 main_thread_handle_(base::PlatformThread::CurrentHandle()) { | 62 main_thread_handle_(base::PlatformThread::CurrentHandle()) { |
| 61 DCHECK(output_surface_filter_.get()); | 63 DCHECK(output_surface_filter_.get()); |
| 62 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
| 63 capabilities_.has_parent_compositor = command_line->HasSwitch( | |
| 64 switches::kEnableDelegatedRenderer); | |
| 65 DetachFromThread(); | 64 DetachFromThread(); |
| 66 message_sender_ = RenderThreadImpl::current()->sync_message_filter(); | 65 message_sender_ = RenderThreadImpl::current()->sync_message_filter(); |
| 67 DCHECK(message_sender_.get()); | 66 DCHECK(message_sender_.get()); |
| 68 } | 67 } |
| 69 | 68 |
| 70 CompositorOutputSurface::~CompositorOutputSurface() { | 69 CompositorOutputSurface::~CompositorOutputSurface() { |
| 71 DCHECK(CalledOnValidThread()); | 70 DCHECK(CalledOnValidThread()); |
| 72 if (!client_) | 71 if (!client_) |
| 73 return; | 72 return; |
| 74 UpdateSmoothnessTakesPriority(false); | 73 UpdateSmoothnessTakesPriority(false); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 86 | 85 |
| 87 output_surface_proxy_ = new CompositorOutputSurfaceProxy(this); | 86 output_surface_proxy_ = new CompositorOutputSurfaceProxy(this); |
| 88 output_surface_filter_->AddRoute( | 87 output_surface_filter_->AddRoute( |
| 89 routing_id_, | 88 routing_id_, |
| 90 base::Bind(&CompositorOutputSurfaceProxy::OnMessageReceived, | 89 base::Bind(&CompositorOutputSurfaceProxy::OnMessageReceived, |
| 91 output_surface_proxy_)); | 90 output_surface_proxy_)); |
| 92 | 91 |
| 93 return true; | 92 return true; |
| 94 } | 93 } |
| 95 | 94 |
| 96 void CompositorOutputSurface::SendFrameToParentCompositor( | 95 void CompositorOutputSurface::SwapBuffers(cc::CompositorFrame* frame) { |
| 97 cc::CompositorFrame* frame) { | 96 if (use_swap_compositor_frame_message_) { |
| 98 DCHECK(CalledOnValidThread()); | 97 Send(new ViewHostMsg_SwapCompositorFrame(routing_id_, *frame)); |
| 99 Send(new ViewHostMsg_SwapCompositorFrame(routing_id_, *frame)); | 98 return; |
| 100 } | 99 } |
| 101 | 100 |
| 102 void CompositorOutputSurface::SwapBuffers( | 101 if (frame->software_frame_data) { |
| 103 const ui::LatencyInfo& latency_info) { | 102 PostSwapBuffersComplete(); |
| 103 return; |
| 104 } |
| 105 |
| 106 DCHECK(frame->gl_frame_data); |
| 107 |
| 104 WebGraphicsContext3DCommandBufferImpl* command_buffer = | 108 WebGraphicsContext3DCommandBufferImpl* command_buffer = |
| 105 static_cast<WebGraphicsContext3DCommandBufferImpl*>(context3d()); | 109 static_cast<WebGraphicsContext3DCommandBufferImpl*>(context3d()); |
| 106 CommandBufferProxyImpl* command_buffer_proxy = | 110 CommandBufferProxyImpl* command_buffer_proxy = |
| 107 command_buffer->GetCommandBufferProxy(); | 111 command_buffer->GetCommandBufferProxy(); |
| 108 DCHECK(command_buffer_proxy); | 112 DCHECK(command_buffer_proxy); |
| 109 context3d()->shallowFlushCHROMIUM(); | 113 context3d()->shallowFlushCHROMIUM(); |
| 110 command_buffer_proxy->SetLatencyInfo(latency_info); | 114 command_buffer_proxy->SetLatencyInfo(frame->metadata.latency_info); |
| 111 OutputSurface::SwapBuffers(latency_info); | |
| 112 } | |
| 113 | 115 |
| 114 void CompositorOutputSurface::PostSubBuffer( | 116 OutputSurface::SwapBuffers(frame); |
| 115 gfx::Rect rect, const ui::LatencyInfo& latency_info) { | |
| 116 WebGraphicsContext3DCommandBufferImpl* command_buffer = | |
| 117 static_cast<WebGraphicsContext3DCommandBufferImpl*>(context3d()); | |
| 118 CommandBufferProxyImpl* command_buffer_proxy = | |
| 119 command_buffer->GetCommandBufferProxy(); | |
| 120 DCHECK(command_buffer_proxy); | |
| 121 context3d()->shallowFlushCHROMIUM(); | |
| 122 command_buffer_proxy->SetLatencyInfo(latency_info); | |
| 123 OutputSurface::PostSubBuffer(rect, latency_info); | |
| 124 } | 117 } |
| 125 | 118 |
| 126 void CompositorOutputSurface::OnMessageReceived(const IPC::Message& message) { | 119 void CompositorOutputSurface::OnMessageReceived(const IPC::Message& message) { |
| 127 DCHECK(CalledOnValidThread()); | 120 DCHECK(CalledOnValidThread()); |
| 128 if (!client_) | 121 if (!client_) |
| 129 return; | 122 return; |
| 130 IPC_BEGIN_MESSAGE_MAP(CompositorOutputSurface, message) | 123 IPC_BEGIN_MESSAGE_MAP(CompositorOutputSurface, message) |
| 131 IPC_MESSAGE_HANDLER(ViewMsg_UpdateVSyncParameters, OnUpdateVSyncParameters); | 124 IPC_MESSAGE_HANDLER(ViewMsg_UpdateVSyncParameters, OnUpdateVSyncParameters); |
| 132 IPC_MESSAGE_HANDLER(ViewMsg_SwapCompositorFrameAck, OnSwapAck); | 125 IPC_MESSAGE_HANDLER(ViewMsg_SwapCompositorFrameAck, OnSwapAck); |
| 133 #if defined(OS_ANDROID) | 126 #if defined(OS_ANDROID) |
| (...skipping 14 matching lines...) Expand all Loading... |
| 148 Send(new ViewHostMsg_SetNeedsBeginFrame(routing_id_, enable)); | 141 Send(new ViewHostMsg_SetNeedsBeginFrame(routing_id_, enable)); |
| 149 } | 142 } |
| 150 | 143 |
| 151 void CompositorOutputSurface::OnBeginFrame(base::TimeTicks frame_time) { | 144 void CompositorOutputSurface::OnBeginFrame(base::TimeTicks frame_time) { |
| 152 DCHECK(CalledOnValidThread()); | 145 DCHECK(CalledOnValidThread()); |
| 153 client_->BeginFrame(frame_time); | 146 client_->BeginFrame(frame_time); |
| 154 } | 147 } |
| 155 #endif // defined(OS_ANDROID) | 148 #endif // defined(OS_ANDROID) |
| 156 | 149 |
| 157 void CompositorOutputSurface::OnSwapAck(const cc::CompositorFrameAck& ack) { | 150 void CompositorOutputSurface::OnSwapAck(const cc::CompositorFrameAck& ack) { |
| 158 client_->OnSendFrameToParentCompositorAck(ack); | 151 client_->OnSwapBuffersComplete(&ack); |
| 159 } | 152 } |
| 160 | 153 |
| 161 bool CompositorOutputSurface::Send(IPC::Message* message) { | 154 bool CompositorOutputSurface::Send(IPC::Message* message) { |
| 162 return message_sender_->Send(message); | 155 return message_sender_->Send(message); |
| 163 } | 156 } |
| 164 | 157 |
| 165 namespace { | 158 namespace { |
| 166 #if defined(OS_ANDROID) | 159 #if defined(OS_ANDROID) |
| 167 void SetThreadPriorityToIdle(base::PlatformThreadHandle handle) { | 160 void SetThreadPriorityToIdle(base::PlatformThreadHandle handle) { |
| 168 base::PlatformThread::SetThreadPriority( | 161 base::PlatformThread::SetThreadPriority( |
| (...skipping 28 matching lines...) Expand all Loading... |
| 197 // If this is the last surface to stop preferring smoothness, | 190 // If this is the last surface to stop preferring smoothness, |
| 198 // Reset the main thread's priority to the default. | 191 // Reset the main thread's priority to the default. |
| 199 if (prefers_smoothness_ == true && | 192 if (prefers_smoothness_ == true && |
| 200 --g_prefer_smoothness_count == 0) { | 193 --g_prefer_smoothness_count == 0) { |
| 201 SetThreadPriorityToDefault(main_thread_handle_); | 194 SetThreadPriorityToDefault(main_thread_handle_); |
| 202 } | 195 } |
| 203 prefers_smoothness_ = prefers_smoothness; | 196 prefers_smoothness_ = prefers_smoothness; |
| 204 } | 197 } |
| 205 | 198 |
| 206 } // namespace content | 199 } // namespace content |
| OLD | NEW |