| 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/message_loop_proxy.h" | 8 #include "base/message_loop/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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 prefers_smoothness_(false), | 61 prefers_smoothness_(false), |
| 62 main_thread_handle_(base::PlatformThread::CurrentHandle()) { | 62 main_thread_handle_(base::PlatformThread::CurrentHandle()) { |
| 63 DCHECK(output_surface_filter_.get()); | 63 DCHECK(output_surface_filter_.get()); |
| 64 DetachFromThread(); | 64 DetachFromThread(); |
| 65 message_sender_ = RenderThreadImpl::current()->sync_message_filter(); | 65 message_sender_ = RenderThreadImpl::current()->sync_message_filter(); |
| 66 DCHECK(message_sender_.get()); | 66 DCHECK(message_sender_.get()); |
| 67 } | 67 } |
| 68 | 68 |
| 69 CompositorOutputSurface::~CompositorOutputSurface() { | 69 CompositorOutputSurface::~CompositorOutputSurface() { |
| 70 DCHECK(CalledOnValidThread()); | 70 DCHECK(CalledOnValidThread()); |
| 71 if (!HasClient()) | 71 if (!client_) |
| 72 return; | 72 return; |
| 73 UpdateSmoothnessTakesPriority(false); | 73 UpdateSmoothnessTakesPriority(false); |
| 74 if (output_surface_proxy_.get()) | 74 if (output_surface_proxy_.get()) |
| 75 output_surface_proxy_->ClearOutputSurface(); | 75 output_surface_proxy_->ClearOutputSurface(); |
| 76 output_surface_filter_->RemoveRoute(routing_id_); | 76 output_surface_filter_->RemoveRoute(routing_id_); |
| 77 } | 77 } |
| 78 | 78 |
| 79 bool CompositorOutputSurface::BindToClient( | 79 bool CompositorOutputSurface::BindToClient( |
| 80 cc::OutputSurfaceClient* client) { | 80 cc::OutputSurfaceClient* client) { |
| 81 DCHECK(CalledOnValidThread()); | 81 DCHECK(CalledOnValidThread()); |
| 82 | 82 |
| 83 if (!cc::OutputSurface::BindToClient(client)) | 83 if (!cc::OutputSurface::BindToClient(client)) |
| 84 return false; | 84 return false; |
| 85 | 85 |
| 86 output_surface_proxy_ = new CompositorOutputSurfaceProxy(this); | 86 output_surface_proxy_ = new CompositorOutputSurfaceProxy(this); |
| 87 output_surface_filter_->AddRoute( | 87 output_surface_filter_->AddRoute( |
| 88 routing_id_, | 88 routing_id_, |
| 89 base::Bind(&CompositorOutputSurfaceProxy::OnMessageReceived, | 89 base::Bind(&CompositorOutputSurfaceProxy::OnMessageReceived, |
| 90 output_surface_proxy_)); | 90 output_surface_proxy_)); |
| 91 | 91 |
| 92 return true; | 92 return true; |
| 93 } | 93 } |
| 94 | 94 |
| 95 void CompositorOutputSurface::SwapBuffers(cc::CompositorFrame* frame) { | 95 void CompositorOutputSurface::SwapBuffers(cc::CompositorFrame* frame) { |
| 96 if (use_swap_compositor_frame_message_) { | 96 if (use_swap_compositor_frame_message_) { |
| 97 Send(new ViewHostMsg_SwapCompositorFrame(routing_id_, *frame)); | 97 Send(new ViewHostMsg_SwapCompositorFrame(routing_id_, *frame)); |
| 98 DidSwapBuffers(); | |
| 99 return; | 98 return; |
| 100 } | 99 } |
| 101 | 100 |
| 102 if (frame->gl_frame_data) { | 101 if (frame->gl_frame_data) { |
| 103 WebGraphicsContext3DCommandBufferImpl* command_buffer = | 102 WebGraphicsContext3DCommandBufferImpl* command_buffer = |
| 104 static_cast<WebGraphicsContext3DCommandBufferImpl*>(context3d()); | 103 static_cast<WebGraphicsContext3DCommandBufferImpl*>(context3d()); |
| 105 CommandBufferProxyImpl* command_buffer_proxy = | 104 CommandBufferProxyImpl* command_buffer_proxy = |
| 106 command_buffer->GetCommandBufferProxy(); | 105 command_buffer->GetCommandBufferProxy(); |
| 107 DCHECK(command_buffer_proxy); | 106 DCHECK(command_buffer_proxy); |
| 108 context3d()->shallowFlushCHROMIUM(); | 107 context3d()->shallowFlushCHROMIUM(); |
| 109 command_buffer_proxy->SetLatencyInfo(frame->metadata.latency_info); | 108 command_buffer_proxy->SetLatencyInfo(frame->metadata.latency_info); |
| 110 } | 109 } |
| 111 | 110 |
| 112 OutputSurface::SwapBuffers(frame); | 111 OutputSurface::SwapBuffers(frame); |
| 113 } | 112 } |
| 114 | 113 |
| 115 void CompositorOutputSurface::OnMessageReceived(const IPC::Message& message) { | 114 void CompositorOutputSurface::OnMessageReceived(const IPC::Message& message) { |
| 116 DCHECK(CalledOnValidThread()); | 115 DCHECK(CalledOnValidThread()); |
| 117 if (!HasClient()) | 116 if (!client_) |
| 118 return; | 117 return; |
| 119 IPC_BEGIN_MESSAGE_MAP(CompositorOutputSurface, message) | 118 IPC_BEGIN_MESSAGE_MAP(CompositorOutputSurface, message) |
| 120 IPC_MESSAGE_HANDLER(ViewMsg_UpdateVSyncParameters, OnUpdateVSyncParameters); | 119 IPC_MESSAGE_HANDLER(ViewMsg_UpdateVSyncParameters, OnUpdateVSyncParameters); |
| 121 IPC_MESSAGE_HANDLER(ViewMsg_SwapCompositorFrameAck, OnSwapAck); | 120 IPC_MESSAGE_HANDLER(ViewMsg_SwapCompositorFrameAck, OnSwapAck); |
| 122 #if defined(OS_ANDROID) | 121 #if defined(OS_ANDROID) |
| 123 IPC_MESSAGE_HANDLER(ViewMsg_BeginFrame, OnBeginFrame); | 122 IPC_MESSAGE_HANDLER(ViewMsg_BeginFrame, OnBeginFrame); |
| 124 #endif | 123 #endif |
| 125 IPC_END_MESSAGE_MAP() | 124 IPC_END_MESSAGE_MAP() |
| 126 } | 125 } |
| 127 | 126 |
| 128 void CompositorOutputSurface::OnUpdateVSyncParameters( | 127 void CompositorOutputSurface::OnUpdateVSyncParameters( |
| 129 base::TimeTicks timebase, base::TimeDelta interval) { | 128 base::TimeTicks timebase, base::TimeDelta interval) { |
| 130 DCHECK(CalledOnValidThread()); | 129 DCHECK(CalledOnValidThread()); |
| 131 OnVSyncParametersChanged(timebase, interval); | 130 client_->OnVSyncParametersChanged(timebase, interval); |
| 132 } | 131 } |
| 133 | 132 |
| 134 #if defined(OS_ANDROID) | 133 #if defined(OS_ANDROID) |
| 135 void CompositorOutputSurface::SetNeedsBeginFrame(bool enable) { | 134 void CompositorOutputSurface::SetNeedsBeginFrame(bool enable) { |
| 136 DCHECK(CalledOnValidThread()); | 135 DCHECK(CalledOnValidThread()); |
| 137 Send(new ViewHostMsg_SetNeedsBeginFrame(routing_id_, enable)); | 136 Send(new ViewHostMsg_SetNeedsBeginFrame(routing_id_, enable)); |
| 138 OutputSurface::SetNeedsBeginFrame(enable); | |
| 139 } | 137 } |
| 140 | 138 |
| 141 void CompositorOutputSurface::OnBeginFrame(base::TimeTicks frame_time) { | 139 void CompositorOutputSurface::OnBeginFrame(base::TimeTicks frame_time) { |
| 142 DCHECK(CalledOnValidThread()); | 140 DCHECK(CalledOnValidThread()); |
| 143 BeginFrame(frame_time); | 141 client_->BeginFrame(frame_time); |
| 144 } | 142 } |
| 145 #endif // defined(OS_ANDROID) | 143 #endif // defined(OS_ANDROID) |
| 146 | 144 |
| 147 void CompositorOutputSurface::OnSwapAck(const cc::CompositorFrameAck& ack) { | 145 void CompositorOutputSurface::OnSwapAck(const cc::CompositorFrameAck& ack) { |
| 148 OnSwapBuffersComplete(&ack); | 146 client_->OnSwapBuffersComplete(&ack); |
| 149 } | 147 } |
| 150 | 148 |
| 151 bool CompositorOutputSurface::Send(IPC::Message* message) { | 149 bool CompositorOutputSurface::Send(IPC::Message* message) { |
| 152 return message_sender_->Send(message); | 150 return message_sender_->Send(message); |
| 153 } | 151 } |
| 154 | 152 |
| 155 namespace { | 153 namespace { |
| 156 #if defined(OS_ANDROID) | 154 #if defined(OS_ANDROID) |
| 157 void SetThreadPriorityToIdle(base::PlatformThreadHandle handle) { | 155 void SetThreadPriorityToIdle(base::PlatformThreadHandle handle) { |
| 158 base::PlatformThread::SetThreadPriority( | 156 base::PlatformThread::SetThreadPriority( |
| (...skipping 28 matching lines...) Expand all Loading... |
| 187 // If this is the last surface to stop preferring smoothness, | 185 // If this is the last surface to stop preferring smoothness, |
| 188 // Reset the main thread's priority to the default. | 186 // Reset the main thread's priority to the default. |
| 189 if (prefers_smoothness_ == true && | 187 if (prefers_smoothness_ == true && |
| 190 --g_prefer_smoothness_count == 0) { | 188 --g_prefer_smoothness_count == 0) { |
| 191 SetThreadPriorityToDefault(main_thread_handle_); | 189 SetThreadPriorityToDefault(main_thread_handle_); |
| 192 } | 190 } |
| 193 prefers_smoothness_ = prefers_smoothness; | 191 prefers_smoothness_ = prefers_smoothness; |
| 194 } | 192 } |
| 195 | 193 |
| 196 } // namespace content | 194 } // namespace content |
| OLD | NEW |