OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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 "cc/trees/thread_proxy.h" | 5 #include "cc/trees/thread_proxy.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 void ThreadProxy::UpdateBackgroundAnimateTicking() { | 187 void ThreadProxy::UpdateBackgroundAnimateTicking() { |
188 bool should_background_tick = | 188 bool should_background_tick = |
189 !impl().scheduler->WillDrawIfNeeded() && | 189 !impl().scheduler->WillDrawIfNeeded() && |
190 impl().layer_tree_host_impl->active_tree()->root_layer(); | 190 impl().layer_tree_host_impl->active_tree()->root_layer(); |
191 impl().layer_tree_host_impl->UpdateBackgroundAnimateTicking( | 191 impl().layer_tree_host_impl->UpdateBackgroundAnimateTicking( |
192 should_background_tick); | 192 should_background_tick); |
193 if (should_background_tick) | 193 if (should_background_tick) |
194 impl().animations_frozen_until_next_draw = false; | 194 impl().animations_frozen_until_next_draw = false; |
195 } | 195 } |
196 | 196 |
197 void ThreadProxy::DidLoseOutputSurface() { | 197 void ThreadProxy::DoCreateAndInitializeOutputSurface() { |
198 TRACE_EVENT0("cc", "ThreadProxy::DidLoseOutputSurface"); | |
199 DCHECK(IsMainThread()); | |
200 layer_tree_host()->DidLoseOutputSurface(); | |
201 | |
202 { | |
203 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | |
204 | |
205 // Return lost resources to their owners immediately. | |
206 BlockingTaskRunner::CapturePostTasks blocked; | |
207 | |
208 CompletionEvent completion; | |
209 Proxy::ImplThreadTaskRunner()->PostTask( | |
210 FROM_HERE, | |
211 base::Bind(&ThreadProxy::DeleteContentsTexturesOnImplThread, | |
212 impl_thread_weak_ptr_, | |
213 &completion)); | |
214 completion.Wait(); | |
215 } | |
216 } | |
217 | |
218 void ThreadProxy::CreateAndInitializeOutputSurface() { | |
219 TRACE_EVENT0("cc", "ThreadProxy::DoCreateAndInitializeOutputSurface"); | 198 TRACE_EVENT0("cc", "ThreadProxy::DoCreateAndInitializeOutputSurface"); |
220 DCHECK(IsMainThread()); | 199 DCHECK(IsMainThread()); |
221 | 200 |
222 scoped_ptr<OutputSurface> output_surface = | 201 scoped_ptr<OutputSurface> output_surface = |
223 layer_tree_host()->CreateOutputSurface(); | 202 layer_tree_host()->CreateOutputSurface(); |
224 | 203 |
225 if (output_surface) { | 204 RendererCapabilities capabilities; |
| 205 bool success = !!output_surface; |
| 206 if (success) { |
| 207 // Make a blocking call to InitializeOutputSurfaceOnImplThread. The results |
| 208 // of that call are pushed into the success and capabilities local |
| 209 // variables. |
| 210 CompletionEvent completion; |
| 211 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
| 212 |
226 Proxy::ImplThreadTaskRunner()->PostTask( | 213 Proxy::ImplThreadTaskRunner()->PostTask( |
227 FROM_HERE, | 214 FROM_HERE, |
228 base::Bind(&ThreadProxy::InitializeOutputSurfaceOnImplThread, | 215 base::Bind(&ThreadProxy::InitializeOutputSurfaceOnImplThread, |
229 impl_thread_weak_ptr_, | 216 impl_thread_weak_ptr_, |
230 base::Passed(&output_surface))); | 217 &completion, |
231 return; | 218 base::Passed(&output_surface), |
| 219 &success, |
| 220 &capabilities)); |
| 221 completion.Wait(); |
232 } | 222 } |
233 | |
234 DidInitializeOutputSurface(false, RendererCapabilities()); | |
235 } | |
236 | |
237 void ThreadProxy::DidInitializeOutputSurface( | |
238 bool success, | |
239 const RendererCapabilities& capabilities) { | |
240 TRACE_EVENT0("cc", "ThreadProxy::DidInitializeOutputSurface"); | |
241 DCHECK(IsMainThread()); | |
242 main().renderer_capabilities_main_thread_copy = capabilities; | 223 main().renderer_capabilities_main_thread_copy = capabilities; |
243 layer_tree_host()->OnCreateAndInitializeOutputSurfaceAttempted(success); | 224 layer_tree_host()->OnCreateAndInitializeOutputSurfaceAttempted(success); |
244 | 225 |
245 if (!success) { | 226 if (success) { |
| 227 main().output_surface_creation_callback.Cancel(); |
| 228 } else if (!main().output_surface_creation_callback.IsCancelled()) { |
246 Proxy::MainThreadTaskRunner()->PostTask( | 229 Proxy::MainThreadTaskRunner()->PostTask( |
247 FROM_HERE, | 230 FROM_HERE, main().output_surface_creation_callback.callback()); |
248 base::Bind(&ThreadProxy::CreateAndInitializeOutputSurface, | |
249 main_thread_weak_ptr_)); | |
250 } | 231 } |
251 } | 232 } |
252 | 233 |
253 void ThreadProxy::SetRendererCapabilitiesMainThreadCopy( | 234 void ThreadProxy::SetRendererCapabilitiesMainThreadCopy( |
254 const RendererCapabilities& capabilities) { | 235 const RendererCapabilities& capabilities) { |
255 main().renderer_capabilities_main_thread_copy = capabilities; | 236 main().renderer_capabilities_main_thread_copy = capabilities; |
256 } | 237 } |
257 | 238 |
258 void ThreadProxy::SendCommitRequestToImplThreadIfNeeded() { | 239 void ThreadProxy::SendCommitRequestToImplThreadIfNeeded() { |
259 DCHECK(IsMainThread()); | 240 DCHECK(IsMainThread()); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 TRACE_EVENT0("cc", "ThreadProxy::DidLoseOutputSurfaceOnImplThread"); | 301 TRACE_EVENT0("cc", "ThreadProxy::DidLoseOutputSurfaceOnImplThread"); |
321 DCHECK(IsImplThread()); | 302 DCHECK(IsImplThread()); |
322 CheckOutputSurfaceStatusOnImplThread(); | 303 CheckOutputSurfaceStatusOnImplThread(); |
323 } | 304 } |
324 | 305 |
325 void ThreadProxy::CheckOutputSurfaceStatusOnImplThread() { | 306 void ThreadProxy::CheckOutputSurfaceStatusOnImplThread() { |
326 TRACE_EVENT0("cc", "ThreadProxy::CheckOutputSurfaceStatusOnImplThread"); | 307 TRACE_EVENT0("cc", "ThreadProxy::CheckOutputSurfaceStatusOnImplThread"); |
327 DCHECK(IsImplThread()); | 308 DCHECK(IsImplThread()); |
328 if (!impl().layer_tree_host_impl->IsContextLost()) | 309 if (!impl().layer_tree_host_impl->IsContextLost()) |
329 return; | 310 return; |
330 Proxy::MainThreadTaskRunner()->PostTask( | |
331 FROM_HERE, | |
332 base::Bind(&ThreadProxy::DidLoseOutputSurface, main_thread_weak_ptr_)); | |
333 impl().scheduler->DidLoseOutputSurface(); | 311 impl().scheduler->DidLoseOutputSurface(); |
334 } | 312 } |
335 | 313 |
336 void ThreadProxy::CommitVSyncParameters(base::TimeTicks timebase, | 314 void ThreadProxy::CommitVSyncParameters(base::TimeTicks timebase, |
337 base::TimeDelta interval) { | 315 base::TimeDelta interval) { |
338 impl().scheduler->CommitVSyncParameters(timebase, interval); | 316 impl().scheduler->CommitVSyncParameters(timebase, interval); |
339 } | 317 } |
340 | 318 |
341 void ThreadProxy::SetEstimatedParentDrawTime(base::TimeDelta draw_time) { | 319 void ThreadProxy::SetEstimatedParentDrawTime(base::TimeDelta draw_time) { |
342 impl().scheduler->SetEstimatedParentDrawTime(draw_time); | 320 impl().scheduler->SetEstimatedParentDrawTime(draw_time); |
(...skipping 863 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1206 DCHECK(IsMainThread()); | 1184 DCHECK(IsMainThread()); |
1207 layer_tree_host()->DidCompleteSwapBuffers(); | 1185 layer_tree_host()->DidCompleteSwapBuffers(); |
1208 } | 1186 } |
1209 | 1187 |
1210 void ThreadProxy::SetAnimationEvents(scoped_ptr<AnimationEventsVector> events) { | 1188 void ThreadProxy::SetAnimationEvents(scoped_ptr<AnimationEventsVector> events) { |
1211 TRACE_EVENT0("cc", "ThreadProxy::SetAnimationEvents"); | 1189 TRACE_EVENT0("cc", "ThreadProxy::SetAnimationEvents"); |
1212 DCHECK(IsMainThread()); | 1190 DCHECK(IsMainThread()); |
1213 layer_tree_host()->SetAnimationEvents(events.Pass()); | 1191 layer_tree_host()->SetAnimationEvents(events.Pass()); |
1214 } | 1192 } |
1215 | 1193 |
| 1194 void ThreadProxy::CreateAndInitializeOutputSurface() { |
| 1195 TRACE_EVENT0("cc", "ThreadProxy::CreateAndInitializeOutputSurface"); |
| 1196 DCHECK(IsMainThread()); |
| 1197 |
| 1198 // Check that output surface has not been recreated by CompositeAndReadback |
| 1199 // after this task is posted but before it is run. |
| 1200 bool has_initialized_output_surface = true; |
| 1201 { |
| 1202 CompletionEvent completion; |
| 1203 Proxy::ImplThreadTaskRunner()->PostTask( |
| 1204 FROM_HERE, |
| 1205 base::Bind(&ThreadProxy::HasInitializedOutputSurfaceOnImplThread, |
| 1206 impl_thread_weak_ptr_, |
| 1207 &completion, |
| 1208 &has_initialized_output_surface)); |
| 1209 completion.Wait(); |
| 1210 } |
| 1211 if (has_initialized_output_surface) |
| 1212 return; |
| 1213 |
| 1214 layer_tree_host()->DidLoseOutputSurface(); |
| 1215 main().output_surface_creation_callback.Reset( |
| 1216 base::Bind(&ThreadProxy::DoCreateAndInitializeOutputSurface, |
| 1217 base::Unretained(this))); |
| 1218 main().output_surface_creation_callback.callback().Run(); |
| 1219 } |
| 1220 |
| 1221 void ThreadProxy::HasInitializedOutputSurfaceOnImplThread( |
| 1222 CompletionEvent* completion, |
| 1223 bool* has_initialized_output_surface) { |
| 1224 DCHECK(IsImplThread()); |
| 1225 *has_initialized_output_surface = |
| 1226 impl().scheduler->HasInitializedOutputSurface(); |
| 1227 completion->Signal(); |
| 1228 } |
| 1229 |
1216 void ThreadProxy::InitializeImplOnImplThread(CompletionEvent* completion) { | 1230 void ThreadProxy::InitializeImplOnImplThread(CompletionEvent* completion) { |
1217 TRACE_EVENT0("cc", "ThreadProxy::InitializeImplOnImplThread"); | 1231 TRACE_EVENT0("cc", "ThreadProxy::InitializeImplOnImplThread"); |
1218 DCHECK(IsImplThread()); | 1232 DCHECK(IsImplThread()); |
1219 impl().layer_tree_host_impl = | 1233 impl().layer_tree_host_impl = |
1220 layer_tree_host()->CreateLayerTreeHostImpl(this); | 1234 layer_tree_host()->CreateLayerTreeHostImpl(this); |
1221 const LayerTreeSettings& settings = layer_tree_host()->settings(); | 1235 const LayerTreeSettings& settings = layer_tree_host()->settings(); |
1222 SchedulerSettings scheduler_settings; | 1236 SchedulerSettings scheduler_settings; |
1223 scheduler_settings.begin_frame_scheduling_enabled = | 1237 scheduler_settings.begin_frame_scheduling_enabled = |
1224 settings.begin_frame_scheduling_enabled; | 1238 settings.begin_frame_scheduling_enabled; |
1225 scheduler_settings.main_frame_before_draw_enabled = | 1239 scheduler_settings.main_frame_before_draw_enabled = |
(...skipping 12 matching lines...) Expand all Loading... |
1238 impl().scheduler = Scheduler::Create(this, | 1252 impl().scheduler = Scheduler::Create(this, |
1239 scheduler_settings, | 1253 scheduler_settings, |
1240 impl().layer_tree_host_id, | 1254 impl().layer_tree_host_id, |
1241 ImplThreadTaskRunner()); | 1255 ImplThreadTaskRunner()); |
1242 impl().scheduler->SetVisible(impl().layer_tree_host_impl->visible()); | 1256 impl().scheduler->SetVisible(impl().layer_tree_host_impl->visible()); |
1243 | 1257 |
1244 impl_thread_weak_ptr_ = impl().weak_factory.GetWeakPtr(); | 1258 impl_thread_weak_ptr_ = impl().weak_factory.GetWeakPtr(); |
1245 completion->Signal(); | 1259 completion->Signal(); |
1246 } | 1260 } |
1247 | 1261 |
1248 void ThreadProxy::DeleteContentsTexturesOnImplThread( | |
1249 CompletionEvent* completion) { | |
1250 TRACE_EVENT0("cc", "ThreadProxy::DeleteContentsTexturesOnImplThread"); | |
1251 DCHECK(IsImplThread()); | |
1252 DCHECK(IsMainThreadBlocked()); | |
1253 layer_tree_host()->DeleteContentsTexturesOnImplThread( | |
1254 impl().layer_tree_host_impl->resource_provider()); | |
1255 completion->Signal(); | |
1256 } | |
1257 | |
1258 void ThreadProxy::InitializeOutputSurfaceOnImplThread( | 1262 void ThreadProxy::InitializeOutputSurfaceOnImplThread( |
1259 scoped_ptr<OutputSurface> output_surface) { | 1263 CompletionEvent* completion, |
| 1264 scoped_ptr<OutputSurface> output_surface, |
| 1265 bool* success, |
| 1266 RendererCapabilities* capabilities) { |
1260 TRACE_EVENT0("cc", "ThreadProxy::InitializeOutputSurfaceOnImplThread"); | 1267 TRACE_EVENT0("cc", "ThreadProxy::InitializeOutputSurfaceOnImplThread"); |
1261 DCHECK(IsImplThread()); | 1268 DCHECK(IsImplThread()); |
| 1269 DCHECK(IsMainThreadBlocked()); |
| 1270 DCHECK(success); |
| 1271 DCHECK(capabilities); |
1262 | 1272 |
1263 LayerTreeHostImpl* host_impl = impl().layer_tree_host_impl.get(); | 1273 layer_tree_host()->DeleteContentsTexturesOnImplThread( |
1264 bool success = host_impl->InitializeRenderer(output_surface.Pass()); | 1274 impl().layer_tree_host_impl->resource_provider()); |
1265 RendererCapabilities capabilities; | 1275 |
1266 if (success) { | 1276 *success = |
1267 capabilities = | 1277 impl().layer_tree_host_impl->InitializeRenderer(output_surface.Pass()); |
1268 host_impl->GetRendererCapabilities().MainThreadCapabilities(); | 1278 |
| 1279 if (*success) { |
| 1280 *capabilities = impl() |
| 1281 .layer_tree_host_impl->GetRendererCapabilities() |
| 1282 .MainThreadCapabilities(); |
| 1283 impl().scheduler->DidCreateAndInitializeOutputSurface(); |
1269 } | 1284 } |
1270 | 1285 |
1271 Proxy::MainThreadTaskRunner()->PostTask( | 1286 completion->Signal(); |
1272 FROM_HERE, | |
1273 base::Bind(&ThreadProxy::DidInitializeOutputSurface, | |
1274 main_thread_weak_ptr_, | |
1275 success, | |
1276 capabilities)); | |
1277 | |
1278 if (success) | |
1279 impl().scheduler->DidCreateAndInitializeOutputSurface(); | |
1280 } | 1287 } |
1281 | 1288 |
1282 void ThreadProxy::FinishGLOnImplThread(CompletionEvent* completion) { | 1289 void ThreadProxy::FinishGLOnImplThread(CompletionEvent* completion) { |
1283 TRACE_EVENT0("cc", "ThreadProxy::FinishGLOnImplThread"); | 1290 TRACE_EVENT0("cc", "ThreadProxy::FinishGLOnImplThread"); |
1284 DCHECK(IsImplThread()); | 1291 DCHECK(IsImplThread()); |
1285 if (impl().layer_tree_host_impl->resource_provider()) | 1292 if (impl().layer_tree_host_impl->resource_provider()) |
1286 impl().layer_tree_host_impl->resource_provider()->Finish(); | 1293 impl().layer_tree_host_impl->resource_provider()->Finish(); |
1287 completion->Signal(); | 1294 completion->Signal(); |
1288 } | 1295 } |
1289 | 1296 |
1290 void ThreadProxy::LayerTreeHostClosedOnImplThread(CompletionEvent* completion) { | 1297 void ThreadProxy::LayerTreeHostClosedOnImplThread(CompletionEvent* completion) { |
1291 TRACE_EVENT0("cc", "ThreadProxy::LayerTreeHostClosedOnImplThread"); | 1298 TRACE_EVENT0("cc", "ThreadProxy::LayerTreeHostClosedOnImplThread"); |
1292 DCHECK(IsImplThread()); | 1299 DCHECK(IsImplThread()); |
1293 DCHECK(IsMainThreadBlocked()); | |
1294 layer_tree_host()->DeleteContentsTexturesOnImplThread( | 1300 layer_tree_host()->DeleteContentsTexturesOnImplThread( |
1295 impl().layer_tree_host_impl->resource_provider()); | 1301 impl().layer_tree_host_impl->resource_provider()); |
1296 impl().current_resource_update_controller.reset(); | 1302 impl().current_resource_update_controller.reset(); |
1297 impl().layer_tree_host_impl->SetNeedsBeginFrame(false); | 1303 impl().layer_tree_host_impl->SetNeedsBeginFrame(false); |
1298 impl().scheduler.reset(); | 1304 impl().scheduler.reset(); |
1299 impl().layer_tree_host_impl.reset(); | 1305 impl().layer_tree_host_impl.reset(); |
1300 impl().weak_factory.InvalidateWeakPtrs(); | 1306 impl().weak_factory.InvalidateWeakPtrs(); |
1301 impl().contents_texture_manager = NULL; | 1307 impl().contents_texture_manager = NULL; |
1302 completion->Signal(); | 1308 completion->Signal(); |
1303 } | 1309 } |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1486 | 1492 |
1487 impl().timing_history.DidActivatePendingTree(); | 1493 impl().timing_history.DidActivatePendingTree(); |
1488 } | 1494 } |
1489 | 1495 |
1490 void ThreadProxy::DidManageTiles() { | 1496 void ThreadProxy::DidManageTiles() { |
1491 DCHECK(IsImplThread()); | 1497 DCHECK(IsImplThread()); |
1492 impl().scheduler->DidManageTiles(); | 1498 impl().scheduler->DidManageTiles(); |
1493 } | 1499 } |
1494 | 1500 |
1495 } // namespace cc | 1501 } // namespace cc |
OLD | NEW |