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/single_thread_proxy.h" | 5 #include "cc/trees/single_thread_proxy.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "cc/output/context_provider.h" | 9 #include "cc/output/context_provider.h" |
10 #include "cc/output/output_surface.h" | 10 #include "cc/output/output_surface.h" |
11 #include "cc/quads/draw_quad.h" | 11 #include "cc/quads/draw_quad.h" |
12 #include "cc/resources/prioritized_resource_manager.h" | 12 #include "cc/resources/prioritized_resource_manager.h" |
13 #include "cc/resources/resource_update_controller.h" | 13 #include "cc/resources/resource_update_controller.h" |
14 #include "cc/trees/layer_tree_host.h" | 14 #include "cc/trees/layer_tree_host.h" |
15 #include "cc/trees/layer_tree_impl.h" | 15 #include "cc/trees/layer_tree_impl.h" |
16 | 16 |
17 namespace cc { | 17 namespace cc { |
18 | 18 |
19 scoped_ptr<Proxy> SingleThreadProxy::Create(LayerTreeHost* layer_tree_host) { | 19 scoped_ptr<Proxy> SingleThreadProxy::Create(LayerTreeHost* layer_tree_host) { |
20 return make_scoped_ptr( | 20 return make_scoped_ptr( |
21 new SingleThreadProxy(layer_tree_host)).PassAs<Proxy>(); | 21 new SingleThreadProxy(layer_tree_host)).PassAs<Proxy>(); |
22 } | 22 } |
23 | 23 |
24 SingleThreadProxy::SingleThreadProxy(LayerTreeHost* layer_tree_host) | 24 SingleThreadProxy::SingleThreadProxy(LayerTreeHost* layer_tree_host) |
25 : Proxy(NULL), | 25 : Proxy(NULL), |
26 layer_tree_host_(layer_tree_host), | 26 layer_tree_host_(layer_tree_host), |
27 created_offscreen_context_provider_(false), | 27 created_offscreen_context_provider_(false), |
28 next_frame_is_newly_committed_frame_(false), | 28 next_frame_is_newly_committed_frame_(false), |
29 inside_draw_(false) { | 29 inside_draw_(false), |
30 can_cancel_commit_(false) { | |
danakj
2013/07/17 20:53:24
Init this to true? (We start without a SNC schedul
enne (OOO)
2013/07/18 17:36:37
Done.
| |
30 TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy"); | 31 TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy"); |
31 DCHECK(Proxy::IsMainThread()); | 32 DCHECK(Proxy::IsMainThread()); |
32 DCHECK(layer_tree_host); | 33 DCHECK(layer_tree_host); |
33 | 34 |
34 // Impl-side painting not supported without threaded compositing. | 35 // Impl-side painting not supported without threaded compositing. |
35 CHECK(!layer_tree_host->settings().impl_side_painting) | 36 CHECK(!layer_tree_host->settings().impl_side_painting) |
36 << "Threaded compositing must be enabled to use impl-side painting."; | 37 << "Threaded compositing must be enabled to use impl-side painting."; |
37 } | 38 } |
38 | 39 |
39 void SingleThreadProxy::Start(scoped_ptr<OutputSurface> first_output_surface) { | 40 void SingleThreadProxy::Start(scoped_ptr<OutputSurface> first_output_surface) { |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
164 DCHECK(Proxy::IsMainThread()); | 165 DCHECK(Proxy::IsMainThread()); |
165 DCHECK(!layer_tree_host_->output_surface_lost()); | 166 DCHECK(!layer_tree_host_->output_surface_lost()); |
166 return renderer_capabilities_for_main_thread_; | 167 return renderer_capabilities_for_main_thread_; |
167 } | 168 } |
168 | 169 |
169 void SingleThreadProxy::SetNeedsAnimate() { | 170 void SingleThreadProxy::SetNeedsAnimate() { |
170 // Thread-only feature. | 171 // Thread-only feature. |
171 NOTREACHED(); | 172 NOTREACHED(); |
172 } | 173 } |
173 | 174 |
175 void SingleThreadProxy::SetNeedsUpdateLayers() { | |
176 DCHECK(Proxy::IsMainThread()); | |
177 layer_tree_host_->ScheduleComposite(); | |
178 } | |
179 | |
174 void SingleThreadProxy::DoCommit(scoped_ptr<ResourceUpdateQueue> queue) { | 180 void SingleThreadProxy::DoCommit(scoped_ptr<ResourceUpdateQueue> queue) { |
175 DCHECK(Proxy::IsMainThread()); | 181 DCHECK(Proxy::IsMainThread()); |
176 // Commit immediately. | 182 // Commit immediately. |
177 { | 183 { |
178 DebugScopedSetMainThreadBlocked mainThreadBlocked(this); | 184 DebugScopedSetMainThreadBlocked mainThreadBlocked(this); |
179 DebugScopedSetImplThread impl(this); | 185 DebugScopedSetImplThread impl(this); |
180 | 186 |
181 RenderingStatsInstrumentation* stats_instrumentation = | 187 RenderingStatsInstrumentation* stats_instrumentation = |
182 layer_tree_host_->rendering_stats_instrumentation(); | 188 layer_tree_host_->rendering_stats_instrumentation(); |
183 base::TimeTicks start_time = stats_instrumentation->StartRecording(); | 189 base::TimeTicks start_time = stats_instrumentation->StartRecording(); |
(...skipping 12 matching lines...) Expand all Loading... | |
196 Proxy::MainThreadTaskRunner(), | 202 Proxy::MainThreadTaskRunner(), |
197 queue.Pass(), | 203 queue.Pass(), |
198 layer_tree_host_impl_->resource_provider()); | 204 layer_tree_host_impl_->resource_provider()); |
199 update_controller->Finalize(); | 205 update_controller->Finalize(); |
200 | 206 |
201 layer_tree_host_->FinishCommitOnImplThread(layer_tree_host_impl_.get()); | 207 layer_tree_host_->FinishCommitOnImplThread(layer_tree_host_impl_.get()); |
202 | 208 |
203 layer_tree_host_impl_->CommitComplete(); | 209 layer_tree_host_impl_->CommitComplete(); |
204 | 210 |
205 #ifndef NDEBUG | 211 #ifndef NDEBUG |
206 // In the single-threaded case, the scroll deltas should never be | 212 // In the single-threaded case, the scroll deltas should never be |
danakj
2013/07/17 20:53:24
nit: scale and scroll deltas
enne (OOO)
2013/07/18 17:36:37
Done.
| |
207 // touched on the impl layer tree. | 213 // touched on the impl layer tree. |
208 scoped_ptr<ScrollAndScaleSet> scroll_info = | 214 scoped_ptr<ScrollAndScaleSet> scroll_info = |
209 layer_tree_host_impl_->ProcessScrollDeltas(); | 215 layer_tree_host_impl_->ProcessScrollDeltas(); |
210 DCHECK(!scroll_info->scrolls.size()); | 216 DCHECK(!scroll_info->scrolls.size()); |
217 DCHECK_EQ(1.f, scroll_info->page_scale_delta); | |
211 #endif | 218 #endif |
212 | 219 |
213 base::TimeDelta duration = stats_instrumentation->EndRecording(start_time); | 220 base::TimeDelta duration = stats_instrumentation->EndRecording(start_time); |
214 stats_instrumentation->AddCommit(duration); | 221 stats_instrumentation->AddCommit(duration); |
215 } | 222 } |
216 layer_tree_host_->CommitComplete(); | 223 layer_tree_host_->CommitComplete(); |
217 next_frame_is_newly_committed_frame_ = true; | 224 next_frame_is_newly_committed_frame_ = true; |
218 } | 225 } |
219 | 226 |
220 void SingleThreadProxy::SetNeedsCommit() { | 227 void SingleThreadProxy::SetNeedsCommit() { |
221 DCHECK(Proxy::IsMainThread()); | 228 DCHECK(Proxy::IsMainThread()); |
229 can_cancel_commit_ = false; | |
222 layer_tree_host_->ScheduleComposite(); | 230 layer_tree_host_->ScheduleComposite(); |
223 } | 231 } |
224 | 232 |
225 void SingleThreadProxy::SetNeedsRedraw(gfx::Rect damage_rect) { | 233 void SingleThreadProxy::SetNeedsRedraw(gfx::Rect damage_rect) { |
226 SetNeedsRedrawRectOnImplThread(damage_rect); | 234 SetNeedsRedrawRectOnImplThread(damage_rect); |
227 } | 235 } |
228 | 236 |
229 void SingleThreadProxy::OnHasPendingTreeStateChanged(bool have_pending_tree) { | 237 void SingleThreadProxy::OnHasPendingTreeStateChanged(bool have_pending_tree) { |
230 // Thread-only feature. | 238 // Thread-only feature. |
231 NOTREACHED(); | 239 NOTREACHED(); |
(...skipping 23 matching lines...) Expand all Loading... | |
255 } | 263 } |
256 layer_tree_host_ = NULL; | 264 layer_tree_host_ = NULL; |
257 } | 265 } |
258 | 266 |
259 void SingleThreadProxy::OnCanDrawStateChanged(bool can_draw) { | 267 void SingleThreadProxy::OnCanDrawStateChanged(bool can_draw) { |
260 DCHECK(Proxy::IsImplThread()); | 268 DCHECK(Proxy::IsImplThread()); |
261 layer_tree_host_impl_->UpdateBackgroundAnimateTicking(!ShouldComposite()); | 269 layer_tree_host_impl_->UpdateBackgroundAnimateTicking(!ShouldComposite()); |
262 } | 270 } |
263 | 271 |
264 void SingleThreadProxy::SetNeedsRedrawOnImplThread() { | 272 void SingleThreadProxy::SetNeedsRedrawOnImplThread() { |
273 // Since commit+draw happens in a single pass for this proxy, | |
274 // this also prevents cancelling a commit. | |
275 can_cancel_commit_ = false; | |
265 layer_tree_host_->ScheduleComposite(); | 276 layer_tree_host_->ScheduleComposite(); |
266 } | 277 } |
267 | 278 |
268 void SingleThreadProxy::SetNeedsRedrawRectOnImplThread(gfx::Rect damage_rect) { | 279 void SingleThreadProxy::SetNeedsRedrawRectOnImplThread(gfx::Rect damage_rect) { |
269 // TODO(brianderson): Once we move render_widget scheduling into this class, | 280 // TODO(brianderson): Once we move render_widget scheduling into this class, |
270 // we can treat redraw requests more efficiently than CommitAndRedraw | 281 // we can treat redraw requests more efficiently than CommitAndRedraw |
271 // requests. | 282 // requests. |
272 layer_tree_host_impl_->SetViewportDamage(damage_rect); | 283 layer_tree_host_impl_->SetViewportDamage(damage_rect); |
273 SetNeedsCommit(); | 284 SetNeedsCommit(); |
274 } | 285 } |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
393 layer_tree_host_->client()->OffscreenContextProviderForMainThread(); | 404 layer_tree_host_->client()->OffscreenContextProviderForMainThread(); |
394 if (offscreen_context_provider.get()) | 405 if (offscreen_context_provider.get()) |
395 created_offscreen_context_provider_ = true; | 406 created_offscreen_context_provider_ = true; |
396 } | 407 } |
397 | 408 |
398 if (layer_tree_host_->contents_texture_manager()) { | 409 if (layer_tree_host_->contents_texture_manager()) { |
399 layer_tree_host_->contents_texture_manager() | 410 layer_tree_host_->contents_texture_manager() |
400 ->UnlinkAndClearEvictedBackings(); | 411 ->UnlinkAndClearEvictedBackings(); |
401 } | 412 } |
402 | 413 |
414 // Reset this flag for the next commit. It's possible that UpdateLayers | |
415 // will force another commit, so record this flag. | |
416 bool can_cancel_this_commit = can_cancel_commit_ && !for_readback; | |
417 can_cancel_commit_ = true; | |
418 | |
403 scoped_ptr<ResourceUpdateQueue> queue = | 419 scoped_ptr<ResourceUpdateQueue> queue = |
404 make_scoped_ptr(new ResourceUpdateQueue); | 420 make_scoped_ptr(new ResourceUpdateQueue); |
405 layer_tree_host_->UpdateLayers( | 421 bool updated = layer_tree_host_->UpdateLayers( |
406 queue.get(), layer_tree_host_impl_->memory_allocation_limit_bytes()); | 422 queue.get(), layer_tree_host_impl_->memory_allocation_limit_bytes()); |
407 | 423 |
408 layer_tree_host_->WillCommit(); | 424 layer_tree_host_->WillCommit(); |
425 | |
426 if (!updated && can_cancel_this_commit) { | |
427 TRACE_EVENT0("cc", "EarlyOut_NoUpdates"); | |
danakj
2013/07/17 20:53:24
nit: SingleThreadProxy::CommitAndComposite::EarlyO
enne (OOO)
2013/07/18 17:36:37
Removed with the rest of the changes to single thr
| |
428 // From the perspective of the embedder, this commit still occurred. | |
429 layer_tree_host_->CommitComplete(); | |
430 layer_tree_host_->DidBeginFrame(); | |
431 return false; | |
432 } | |
433 | |
409 DoCommit(queue.Pass()); | 434 DoCommit(queue.Pass()); |
410 bool result = DoComposite(offscreen_context_provider, | 435 bool result = DoComposite(offscreen_context_provider, |
411 frame_begin_time, | 436 frame_begin_time, |
412 device_viewport_damage_rect, | 437 device_viewport_damage_rect, |
413 for_readback, | 438 for_readback, |
414 frame); | 439 frame); |
415 layer_tree_host_->DidBeginFrame(); | 440 layer_tree_host_->DidBeginFrame(); |
441 | |
416 return result; | 442 return result; |
417 } | 443 } |
418 | 444 |
419 bool SingleThreadProxy::ShouldComposite() const { | 445 bool SingleThreadProxy::ShouldComposite() const { |
420 DCHECK(Proxy::IsImplThread()); | 446 DCHECK(Proxy::IsImplThread()); |
421 return layer_tree_host_impl_->visible() && | 447 return layer_tree_host_impl_->visible() && |
422 layer_tree_host_impl_->CanDraw(); | 448 layer_tree_host_impl_->CanDraw(); |
423 } | 449 } |
424 | 450 |
425 bool SingleThreadProxy::DoComposite( | 451 bool SingleThreadProxy::DoComposite( |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
486 | 512 |
487 bool SingleThreadProxy::CommitPendingForTesting() { return false; } | 513 bool SingleThreadProxy::CommitPendingForTesting() { return false; } |
488 | 514 |
489 skia::RefPtr<SkPicture> SingleThreadProxy::CapturePicture() { | 515 skia::RefPtr<SkPicture> SingleThreadProxy::CapturePicture() { |
490 // Impl-side painting only. | 516 // Impl-side painting only. |
491 NOTREACHED(); | 517 NOTREACHED(); |
492 return skia::RefPtr<SkPicture>(); | 518 return skia::RefPtr<SkPicture>(); |
493 } | 519 } |
494 | 520 |
495 } // namespace cc | 521 } // namespace cc |
OLD | NEW |