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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 } | 123 } |
124 | 124 |
125 OnSwapAck(output_surface_id, *layout_test_previous_frame_ack_); | 125 OnSwapAck(output_surface_id, *layout_test_previous_frame_ack_); |
126 | 126 |
127 layout_test_previous_frame_ack_->gl_frame_data = gl_frame_data.Pass(); | 127 layout_test_previous_frame_ack_->gl_frame_data = gl_frame_data.Pass(); |
128 layout_test_previous_frame_ack_->last_software_frame_id = | 128 layout_test_previous_frame_ack_->last_software_frame_id = |
129 software_frame_data ? software_frame_data->id : 0; | 129 software_frame_data ? software_frame_data->id : 0; |
130 } | 130 } |
131 | 131 |
132 void CompositorOutputSurface::SwapBuffers(cc::CompositorFrame* frame) { | 132 void CompositorOutputSurface::SwapBuffers(cc::CompositorFrame* frame) { |
| 133 if (is_lost_) |
| 134 return; |
| 135 |
133 if (layout_test_mode_ && use_swap_compositor_frame_message_) { | 136 if (layout_test_mode_ && use_swap_compositor_frame_message_) { |
134 // This code path is here to support layout tests that are currently | 137 // This code path is here to support layout tests that are currently |
135 // doing a readback in the renderer instead of the browser. So they | 138 // doing a readback in the renderer instead of the browser. So they |
136 // are using deprecated code paths in the renderer and don't need to | 139 // are using deprecated code paths in the renderer and don't need to |
137 // actually swap anything to the browser. We shortcut the swap to the | 140 // actually swap anything to the browser. We shortcut the swap to the |
138 // browser here and just ack directly within the renderer process. | 141 // browser here and just ack directly within the renderer process. |
139 // Once crbug.com/311404 is fixed, this can be removed. | 142 // Once crbug.com/311404 is fixed, this can be removed. |
140 | 143 |
141 // This would indicate that crbug.com/311404 is being fixed, and this | 144 // This would indicate that crbug.com/311404 is being fixed, and this |
142 // block needs to be removed. | 145 // block needs to be removed. |
143 DCHECK(!frame->delegated_frame_data); | 146 DCHECK(!frame->delegated_frame_data); |
144 | 147 |
145 base::Closure closure = | 148 base::Closure closure = |
146 base::Bind(&CompositorOutputSurface::ShortcutSwapAck, | 149 base::Bind(&CompositorOutputSurface::ShortcutSwapAck, |
147 weak_ptrs_.GetWeakPtr(), | 150 weak_ptrs_.GetWeakPtr(), |
148 output_surface_id_, | 151 output_surface_id_, |
149 base::Passed(&frame->gl_frame_data), | 152 base::Passed(&frame->gl_frame_data), |
150 base::Passed(&frame->software_frame_data)); | 153 base::Passed(&frame->software_frame_data)); |
151 | 154 |
152 if (context_provider_) { | 155 if (context_provider_) { |
153 gpu::gles2::GLES2Interface* context = context_provider_->ContextGL(); | 156 gpu::gles2::GLES2Interface* context = context_provider_->ContextGL(); |
154 context->Flush(); | 157 context->Flush(); |
155 uint32 sync_point = context->InsertSyncPointCHROMIUM(); | 158 uint32 sync_point = context->InsertSyncPointCHROMIUM(); |
156 context_provider_->ContextSupport()->SignalSyncPoint(sync_point, closure); | 159 context_provider_->ContextSupport()->SignalSyncPoint(sync_point, closure); |
157 } else { | 160 } else { |
158 base::MessageLoopProxy::current()->PostTask(FROM_HERE, closure); | 161 base::MessageLoopProxy::current()->PostTask(FROM_HERE, closure); |
159 } | 162 } |
160 DidSwapBuffers(); | 163 client_->DidSwapBuffers(); |
161 return; | 164 return; |
162 } | 165 } |
163 | 166 |
164 if (use_swap_compositor_frame_message_) { | 167 if (use_swap_compositor_frame_message_) { |
165 Send(new ViewHostMsg_SwapCompositorFrame(routing_id_, | 168 Send(new ViewHostMsg_SwapCompositorFrame(routing_id_, |
166 output_surface_id_, | 169 output_surface_id_, |
167 *frame)); | 170 *frame)); |
168 DidSwapBuffers(); | 171 client_->DidSwapBuffers(); |
169 return; | 172 return; |
170 } | 173 } |
171 | 174 |
172 if (frame->gl_frame_data) { | 175 if (frame->gl_frame_data) { |
173 context_provider_->ContextGL()->ShallowFlushCHROMIUM(); | 176 context_provider_->ContextGL()->ShallowFlushCHROMIUM(); |
174 ContextProviderCommandBuffer* provider_command_buffer = | 177 ContextProviderCommandBuffer* provider_command_buffer = |
175 static_cast<ContextProviderCommandBuffer*>(context_provider_.get()); | 178 static_cast<ContextProviderCommandBuffer*>(context_provider_.get()); |
176 CommandBufferProxyImpl* command_buffer_proxy = | 179 CommandBufferProxyImpl* command_buffer_proxy = |
177 provider_command_buffer->GetCommandBufferProxy(); | 180 provider_command_buffer->GetCommandBufferProxy(); |
178 DCHECK(command_buffer_proxy); | 181 DCHECK(command_buffer_proxy); |
179 command_buffer_proxy->SetLatencyInfo(frame->metadata.latency_info); | 182 command_buffer_proxy->SetLatencyInfo(frame->metadata.latency_info); |
180 } | 183 } |
181 | |
182 OutputSurface::SwapBuffers(frame); | |
183 } | 184 } |
184 | 185 |
185 void CompositorOutputSurface::OnMessageReceived(const IPC::Message& message) { | 186 void CompositorOutputSurface::OnMessageReceived(const IPC::Message& message) { |
186 DCHECK(CalledOnValidThread()); | 187 DCHECK(CalledOnValidThread()); |
187 if (!HasClient()) | 188 if (!HasClient()) |
188 return; | 189 return; |
189 IPC_BEGIN_MESSAGE_MAP(CompositorOutputSurface, message) | 190 IPC_BEGIN_MESSAGE_MAP(CompositorOutputSurface, message) |
190 IPC_MESSAGE_HANDLER(ViewMsg_UpdateVSyncParameters, | 191 IPC_MESSAGE_HANDLER(ViewMsg_UpdateVSyncParameters, |
191 OnUpdateVSyncParametersFromBrowser); | 192 OnUpdateVSyncParametersFromBrowser); |
192 IPC_MESSAGE_HANDLER(ViewMsg_SwapCompositorFrameAck, OnSwapAck); | 193 IPC_MESSAGE_HANDLER(ViewMsg_SwapCompositorFrameAck, OnSwapAck); |
193 IPC_MESSAGE_HANDLER(ViewMsg_ReclaimCompositorResources, OnReclaimResources); | 194 IPC_MESSAGE_HANDLER(ViewMsg_ReclaimCompositorResources, OnReclaimResources); |
194 #if defined(OS_ANDROID) | 195 #if defined(OS_ANDROID) |
195 IPC_MESSAGE_HANDLER(ViewMsg_BeginFrame, OnBeginFrame); | 196 IPC_MESSAGE_HANDLER(ViewMsg_BeginFrame, OnBeginFrame); |
196 #endif | 197 #endif |
197 IPC_END_MESSAGE_MAP() | 198 IPC_END_MESSAGE_MAP() |
198 } | 199 } |
199 | 200 |
200 void CompositorOutputSurface::OnUpdateVSyncParametersFromBrowser( | 201 void CompositorOutputSurface::OnUpdateVSyncParametersFromBrowser( |
201 base::TimeTicks timebase, | 202 base::TimeTicks timebase, |
202 base::TimeDelta interval) { | 203 base::TimeDelta interval) { |
203 DCHECK(CalledOnValidThread()); | 204 DCHECK(CalledOnValidThread()); |
204 CommitVSyncParameters(timebase, interval); | 205 CommitVSyncParameters(timebase, interval); |
205 } | 206 } |
206 | 207 |
207 #if defined(OS_ANDROID) | 208 #if defined(OS_ANDROID) |
208 void CompositorOutputSurface::SetNeedsBeginFrame(bool enable) { | 209 void CompositorOutputSurface::SetNeedsBeginFrame(bool enable) { |
209 DCHECK(CalledOnValidThread()); | 210 DCHECK(CalledOnValidThread()); |
210 if (needs_begin_frame_ != enable) | 211 if (needs_begin_frame_ != enable) |
211 Send(new ViewHostMsg_SetNeedsBeginFrame(routing_id_, enable)); | 212 Send(new ViewHostMsg_SetNeedsBeginFrame(routing_id_, enable)); |
212 OutputSurface::SetNeedsBeginFrame(enable); | |
213 } | 213 } |
214 | 214 |
215 void CompositorOutputSurface::OnBeginFrame(const cc::BeginFrameArgs& args) { | 215 void CompositorOutputSurface::OnBeginFrame(const cc::BeginFrameArgs& args) { |
216 DCHECK(CalledOnValidThread()); | 216 DCHECK(CalledOnValidThread()); |
217 BeginFrame(args); | 217 client->BeginFrame(args); |
218 } | 218 } |
219 #endif // defined(OS_ANDROID) | 219 #endif // defined(OS_ANDROID) |
220 | 220 |
221 void CompositorOutputSurface::OnSwapAck(uint32 output_surface_id, | 221 void CompositorOutputSurface::OnSwapAck(uint32 output_surface_id, |
222 const cc::CompositorFrameAck& ack) { | 222 const cc::CompositorFrameAck& ack) { |
223 // Ignore message if it's a stale one coming from a different output surface | 223 // Ignore message if it's a stale one coming from a different output surface |
224 // (e.g. after a lost context). | 224 // (e.g. after a lost context). |
225 if (output_surface_id != output_surface_id_) | 225 if (output_surface_id != output_surface_id_) |
226 return; | 226 return; |
| 227 // Also ignore message if the current output surface's context is lost. |
| 228 if (is_lost_) |
| 229 return; |
227 ReclaimResources(&ack); | 230 ReclaimResources(&ack); |
228 OnSwapBuffersComplete(); | 231 client_->DidSwapBuffersComplete(); |
229 } | 232 } |
230 | 233 |
231 void CompositorOutputSurface::OnReclaimResources( | 234 void CompositorOutputSurface::OnReclaimResources( |
232 uint32 output_surface_id, | 235 uint32 output_surface_id, |
233 const cc::CompositorFrameAck& ack) { | 236 const cc::CompositorFrameAck& ack) { |
234 // Ignore message if it's a stale one coming from a different output surface | 237 // Ignore message if it's a stale one coming from a different output surface |
235 // (e.g. after a lost context). | 238 // (e.g. after a lost context). |
236 if (output_surface_id != output_surface_id_) | 239 if (output_surface_id != output_surface_id_) |
237 return; | 240 return; |
238 ReclaimResources(&ack); | 241 ReclaimResources(&ack); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 // If this is the last surface to stop preferring smoothness, | 280 // If this is the last surface to stop preferring smoothness, |
278 // Reset the main thread's priority to the default. | 281 // Reset the main thread's priority to the default. |
279 if (prefers_smoothness_ == true && | 282 if (prefers_smoothness_ == true && |
280 --g_prefer_smoothness_count == 0) { | 283 --g_prefer_smoothness_count == 0) { |
281 SetThreadPriorityToDefault(main_thread_handle_); | 284 SetThreadPriorityToDefault(main_thread_handle_); |
282 } | 285 } |
283 prefers_smoothness_ = prefers_smoothness; | 286 prefers_smoothness_ = prefers_smoothness; |
284 } | 287 } |
285 | 288 |
286 } // namespace content | 289 } // namespace content |
OLD | NEW |