Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(286)

Side by Side Diff: third_party/WebKit/Source/core/layout/compositing/PaintLayerCompositor.cpp

Issue 2795263002: Add a new document lifecycle; CompositingInputsClean (Closed)
Patch Set: Address reviewer comments Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009, 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2009, 2010 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 fullscreen_element = 177 fullscreen_element =
178 Fullscreen::CurrentFullScreenElementFrom(*content_document); 178 Fullscreen::CurrentFullScreenElementFrom(*content_document);
179 if (!isHTMLVideoElement(fullscreen_element)) 179 if (!isHTMLVideoElement(fullscreen_element))
180 return nullptr; 180 return nullptr;
181 LayoutObject* layout_object = fullscreen_element->GetLayoutObject(); 181 LayoutObject* layout_object = fullscreen_element->GetLayoutObject();
182 if (!layout_object) 182 if (!layout_object)
183 return nullptr; 183 return nullptr;
184 return ToLayoutVideo(layout_object); 184 return ToLayoutVideo(layout_object);
185 } 185 }
186 186
187 void PaintLayerCompositor::UpdateIfNeededRecursive() { 187 void PaintLayerCompositor::UpdateIfNeededRecursive(
188 DocumentLifecycle::LifecycleState target_state) {
188 SCOPED_BLINK_UMA_HISTOGRAM_TIMER("Blink.Compositing.UpdateTime"); 189 SCOPED_BLINK_UMA_HISTOGRAM_TIMER("Blink.Compositing.UpdateTime");
189 UpdateIfNeededRecursiveInternal(); 190 UpdateIfNeededRecursiveInternal(target_state);
190 } 191 }
191 192
192 void PaintLayerCompositor::UpdateIfNeededRecursiveInternal() { 193 void PaintLayerCompositor::UpdateIfNeededRecursiveInternal(
194 DocumentLifecycle::LifecycleState target_state) {
195 DCHECK(target_state >= DocumentLifecycle::kCompositingInputsClean);
196
193 FrameView* view = layout_view_.GetFrameView(); 197 FrameView* view = layout_view_.GetFrameView();
194 if (view->ShouldThrottleRendering()) 198 if (view->ShouldThrottleRendering())
195 return; 199 return;
196 200
197 for (Frame* child = 201 for (Frame* child =
198 layout_view_.GetFrameView()->GetFrame().Tree().FirstChild(); 202 layout_view_.GetFrameView()->GetFrame().Tree().FirstChild();
199 child; child = child->Tree().NextSibling()) { 203 child; child = child->Tree().NextSibling()) {
200 if (!child->IsLocalFrame()) 204 if (!child->IsLocalFrame())
201 continue; 205 continue;
202 LocalFrame* local_frame = ToLocalFrame(child); 206 LocalFrame* local_frame = ToLocalFrame(child);
203 // It's possible for trusted Pepper plugins to force hit testing in 207 // It's possible for trusted Pepper plugins to force hit testing in
204 // situations where the frame tree is in an inconsistent state, such as in 208 // situations where the frame tree is in an inconsistent state, such as in
205 // the middle of frame detach. 209 // the middle of frame detach.
206 // TODO(bbudge) Remove this check when trusted Pepper plugins are gone. 210 // TODO(bbudge) Remove this check when trusted Pepper plugins are gone.
207 if (local_frame->GetDocument()->IsActive() && 211 if (local_frame->GetDocument()->IsActive() &&
208 !local_frame->ContentLayoutItem().IsNull()) 212 !local_frame->ContentLayoutItem().IsNull()) {
209 local_frame->ContentLayoutItem() 213 local_frame->ContentLayoutItem()
210 .Compositor() 214 .Compositor()
211 ->UpdateIfNeededRecursiveInternal(); 215 ->UpdateIfNeededRecursiveInternal(target_state);
216 }
212 } 217 }
213 218
214 TRACE_EVENT0("blink", "PaintLayerCompositor::updateIfNeededRecursive"); 219 TRACE_EVENT0("blink", "PaintLayerCompositor::updateIfNeededRecursive");
215 220
216 DCHECK(!layout_view_.NeedsLayout()); 221 DCHECK(!layout_view_.NeedsLayout());
217 222
218 ScriptForbiddenScope forbid_script; 223 ScriptForbiddenScope forbid_script;
219 224
220 // FIXME: enableCompositingModeIfNeeded can trigger a 225 // FIXME: enableCompositingModeIfNeeded can trigger a
221 // CompositingUpdateRebuildTree, which asserts that it's not 226 // CompositingUpdateRebuildTree, which asserts that it's not
222 // InCompositingUpdate. 227 // InCompositingUpdate.
223 EnableCompositingModeIfNeeded(); 228 EnableCompositingModeIfNeeded();
224 229
225 RootLayer()->UpdateDescendantDependentFlags(); 230 RootLayer()->UpdateDescendantDependentFlags();
226 231
227 layout_view_.CommitPendingSelection(); 232 layout_view_.CommitPendingSelection();
228 233
229 Lifecycle().AdvanceTo(DocumentLifecycle::kInCompositingUpdate); 234 UpdateIfNeeded(target_state);
230 UpdateIfNeeded(); 235 DCHECK(Lifecycle().GetState() == DocumentLifecycle::kCompositingInputsClean ||
231 Lifecycle().AdvanceTo(DocumentLifecycle::kCompositingClean); 236 Lifecycle().GetState() == DocumentLifecycle::kCompositingClean);
237 if (target_state == DocumentLifecycle::kCompositingInputsClean)
238 return;
232 239
233 Optional<CompositorElementIdSet> composited_element_ids; 240 Optional<CompositorElementIdSet> composited_element_ids;
234 DocumentAnimations::UpdateAnimations(layout_view_.GetDocument(), 241 DocumentAnimations::UpdateAnimations(layout_view_.GetDocument(),
235 DocumentLifecycle::kCompositingClean, 242 DocumentLifecycle::kCompositingClean,
236 composited_element_ids); 243 composited_element_ids);
237 244
238 layout_view_.GetFrameView() 245 layout_view_.GetFrameView()
239 ->GetScrollableArea() 246 ->GetScrollableArea()
240 ->UpdateCompositorScrollAnimations(); 247 ->UpdateCompositorScrollAnimations();
241 if (const FrameView::ScrollableAreaSet* animating_scrollable_areas = 248 if (const FrameView::ScrollableAreaSet* animating_scrollable_areas =
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 GraphicsLayer* PaintLayerCompositor::ParentForContentLayers() const { 371 GraphicsLayer* PaintLayerCompositor::ParentForContentLayers() const {
365 if (root_content_layer_) 372 if (root_content_layer_)
366 return root_content_layer_.get(); 373 return root_content_layer_.get();
367 374
368 DCHECK(RuntimeEnabledFeatures::rootLayerScrollingEnabled()); 375 DCHECK(RuntimeEnabledFeatures::rootLayerScrollingEnabled());
369 // Iframe content layers will be connected by the parent frame using 376 // Iframe content layers will be connected by the parent frame using
370 // attachFrameContentLayersToIframeLayer. 377 // attachFrameContentLayersToIframeLayer.
371 return IsMainFrame() ? GetVisualViewport().ScrollLayer() : nullptr; 378 return IsMainFrame() ? GetVisualViewport().ScrollLayer() : nullptr;
372 } 379 }
373 380
374 void PaintLayerCompositor::UpdateIfNeeded() { 381 void PaintLayerCompositor::UpdateIfNeeded(
382 DocumentLifecycle::LifecycleState target_state) {
383 DCHECK(target_state >= DocumentLifecycle::kCompositingInputsClean);
384
385 Lifecycle().AdvanceTo(DocumentLifecycle::kInCompositingUpdate);
386
375 CompositingUpdateType update_type = pending_update_type_; 387 CompositingUpdateType update_type = pending_update_type_;
376 pending_update_type_ = kCompositingUpdateNone; 388 pending_update_type_ = kCompositingUpdateNone;
377 389
378 if (!HasAcceleratedCompositing()) { 390 if (!HasAcceleratedCompositing()) {
379 UpdateWithoutAcceleratedCompositing(update_type); 391 UpdateWithoutAcceleratedCompositing(update_type);
392 Lifecycle().AdvanceTo(
393 std::min(DocumentLifecycle::kCompositingClean, target_state));
380 return; 394 return;
381 } 395 }
382 396
383 if (update_type == kCompositingUpdateNone) 397 if (update_type == kCompositingUpdateNone) {
398 Lifecycle().AdvanceTo(
399 std::min(DocumentLifecycle::kCompositingClean, target_state));
384 return; 400 return;
401 }
385 402
386 PaintLayer* update_root = RootLayer(); 403 PaintLayer* update_root = RootLayer();
387 404
388 Vector<PaintLayer*> layers_needing_paint_invalidation; 405 Vector<PaintLayer*> layers_needing_paint_invalidation;
389 406
390 if (update_type >= kCompositingUpdateAfterCompositingInputChange) { 407 if (update_type >= kCompositingUpdateAfterCompositingInputChange) {
391 CompositingInputsUpdater(update_root).Update(); 408 CompositingInputsUpdater(update_root).Update();
392 409
393 #if DCHECK_IS_ON() 410 #if DCHECK_IS_ON()
394 // FIXME: Move this check to the end of the compositing update. 411 // FIXME: Move this check to the end of the compositing update.
395 CompositingInputsUpdater::AssertNeedsCompositingInputsUpdateBitsCleared( 412 CompositingInputsUpdater::AssertNeedsCompositingInputsUpdateBitsCleared(
396 update_root); 413 update_root);
397 #endif 414 #endif
398 415
416 // In the case where we only want to make compositing inputs clean, we
417 // early-exit here. Because we have not handled the other implications of
418 // |pending_update_type_| > kCompositingUpdateNone, we must restore the
419 // pending update type for a future call.
420 if (target_state == DocumentLifecycle::kCompositingInputsClean) {
421 pending_update_type_ = update_type;
422 Lifecycle().AdvanceTo(DocumentLifecycle::kCompositingInputsClean);
423 return;
424 }
425
399 CompositingRequirementsUpdater(layout_view_, compositing_reason_finder_) 426 CompositingRequirementsUpdater(layout_view_, compositing_reason_finder_)
400 .Update(update_root); 427 .Update(update_root);
401 428
402 CompositingLayerAssigner layer_assigner(this); 429 CompositingLayerAssigner layer_assigner(this);
403 layer_assigner.Assign(update_root, layers_needing_paint_invalidation); 430 layer_assigner.Assign(update_root, layers_needing_paint_invalidation);
404 431
405 bool layers_changed = layer_assigner.LayersChanged(); 432 bool layers_changed = layer_assigner.LayersChanged();
406 433
407 { 434 {
408 TRACE_EVENT0("blink", 435 TRACE_EVENT0("blink",
409 "PaintLayerCompositor::updateAfterCompositingChange"); 436 "PaintLayerCompositor::updateAfterCompositingChange");
410 if (const FrameView::ScrollableAreaSet* scrollable_areas = 437 if (const FrameView::ScrollableAreaSet* scrollable_areas =
411 layout_view_.GetFrameView()->ScrollableAreas()) { 438 layout_view_.GetFrameView()->ScrollableAreas()) {
412 for (ScrollableArea* scrollable_area : *scrollable_areas) 439 for (ScrollableArea* scrollable_area : *scrollable_areas)
413 layers_changed |= scrollable_area->UpdateAfterCompositingChange(); 440 layers_changed |= scrollable_area->UpdateAfterCompositingChange();
414 } 441 }
415 } 442 }
416 443
417 if (layers_changed) { 444 if (layers_changed) {
418 update_type = std::max(update_type, kCompositingUpdateRebuildTree); 445 update_type = std::max(update_type, kCompositingUpdateRebuildTree);
419 if (ScrollingCoordinator* scrolling_coordinator = 446 if (ScrollingCoordinator* scrolling_coordinator =
420 this->GetScrollingCoordinator()) 447 this->GetScrollingCoordinator())
421 scrolling_coordinator->NotifyGeometryChanged(); 448 scrolling_coordinator->NotifyGeometryChanged();
422 } 449 }
423 } 450 }
424 451
452 // If we hit this check then we were asked to only make compositing inputs
453 // clean but they were already clean. Therefore the correct behavior is to
454 // just restore the pending state and exit.
455 if (target_state == DocumentLifecycle::kCompositingInputsClean) {
flackr 2017/04/12 15:50:15 I think this early exit would be cleaner at the to
smcgruer 2017/04/12 17:18:44 Done.
456 pending_update_type_ = update_type;
457 Lifecycle().AdvanceTo(DocumentLifecycle::kCompositingInputsClean);
458 return;
459 }
460
425 if (RuntimeEnabledFeatures::compositorWorkerEnabled() && scroll_layer_) { 461 if (RuntimeEnabledFeatures::compositorWorkerEnabled() && scroll_layer_) {
426 // If rootLayerScrolls is enabled, these properties are applied in 462 // If rootLayerScrolls is enabled, these properties are applied in
427 // CompositedLayerMapping::updateElementIdAndCompositorMutableProperties. 463 // CompositedLayerMapping::updateElementIdAndCompositorMutableProperties.
428 if (!RuntimeEnabledFeatures::rootLayerScrollingEnabled()) { 464 if (!RuntimeEnabledFeatures::rootLayerScrollingEnabled()) {
429 if (Element* scrolling_element = 465 if (Element* scrolling_element =
430 layout_view_.GetDocument().scrollingElement()) { 466 layout_view_.GetDocument().scrollingElement()) {
431 uint32_t mutable_properties = CompositorMutableProperty::kNone; 467 uint32_t mutable_properties = CompositorMutableProperty::kNone;
432 if (scrolling_element->HasCompositorProxy()) { 468 if (scrolling_element->HasCompositorProxy()) {
433 mutable_properties = (CompositorMutableProperty::kScrollLeft | 469 mutable_properties = (CompositorMutableProperty::kScrollLeft |
434 CompositorMutableProperty::kScrollTop) & 470 CompositorMutableProperty::kScrollTop) &
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 if (Page* page = layout_view_.GetFrame()->GetPage()) { 517 if (Page* page = layout_view_.GetFrame()->GetPage()) {
482 page->GetChromeClient().AttachRootGraphicsLayer(RootGraphicsLayer(), 518 page->GetChromeClient().AttachRootGraphicsLayer(RootGraphicsLayer(),
483 layout_view_.GetFrame()); 519 layout_view_.GetFrame());
484 root_layer_attachment_ = kRootLayerAttachedViaChromeClient; 520 root_layer_attachment_ = kRootLayerAttachedViaChromeClient;
485 } 521 }
486 } 522 }
487 523
488 // Inform the inspector that the layer tree has changed. 524 // Inform the inspector that the layer tree has changed.
489 if (IsMainFrame()) 525 if (IsMainFrame())
490 probe::layerTreeDidChange(layout_view_.GetFrame()); 526 probe::layerTreeDidChange(layout_view_.GetFrame());
527
528 Lifecycle().AdvanceTo(DocumentLifecycle::kCompositingClean);
491 } 529 }
492 530
493 static void RestartAnimationOnCompositor(const LayoutObject& layout_object) { 531 static void RestartAnimationOnCompositor(const LayoutObject& layout_object) {
494 Node* node = layout_object.GetNode(); 532 Node* node = layout_object.GetNode();
495 ElementAnimations* element_animations = 533 ElementAnimations* element_animations =
496 (node && node->IsElementNode()) ? ToElement(node)->GetElementAnimations() 534 (node && node->IsElementNode()) ? ToElement(node)->GetElementAnimations()
497 : nullptr; 535 : nullptr;
498 if (element_animations) 536 if (element_animations)
499 element_animations->RestartAnimationOnCompositor(); 537 element_animations->RestartAnimationOnCompositor();
500 } 538 }
(...skipping 832 matching lines...) Expand 10 before | Expand all | Expand 10 after
1333 } else if (graphics_layer == scroll_layer_.get()) { 1371 } else if (graphics_layer == scroll_layer_.get()) {
1334 name = "Frame Scrolling Layer"; 1372 name = "Frame Scrolling Layer";
1335 } else { 1373 } else {
1336 NOTREACHED(); 1374 NOTREACHED();
1337 } 1375 }
1338 1376
1339 return name; 1377 return name;
1340 } 1378 }
1341 1379
1342 } // namespace blink 1380 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698