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

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

Issue 2692853016: Change PaintLayer::m_layoutObject to a reference. (Closed)
Patch Set: Added TODO Created 3 years, 10 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, 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2009, 2010, 2011 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 #include "platform/graphics/paint/PaintRecordBuilder.h" 77 #include "platform/graphics/paint/PaintRecordBuilder.h"
78 #include "platform/graphics/paint/TransformDisplayItem.h" 78 #include "platform/graphics/paint/TransformDisplayItem.h"
79 #include "public/platform/WebLayerStickyPositionConstraint.h" 79 #include "public/platform/WebLayerStickyPositionConstraint.h"
80 #include "wtf/CurrentTime.h" 80 #include "wtf/CurrentTime.h"
81 #include "wtf/text/StringBuilder.h" 81 #include "wtf/text/StringBuilder.h"
82 82
83 namespace blink { 83 namespace blink {
84 84
85 using namespace HTMLNames; 85 using namespace HTMLNames;
86 86
87 static IntRect clipBox(LayoutBox* layoutObject); 87 static IntRect clipBox(LayoutBox& layoutObject);
88 88
89 static IntRect contentsRect(const LayoutObject* layoutObject) { 89 static IntRect contentsRect(const LayoutObject& layoutObject) {
90 if (!layoutObject->isBox()) 90 if (!layoutObject.isBox())
91 return IntRect(); 91 return IntRect();
92 if (layoutObject->isCanvas()) 92 if (layoutObject.isCanvas()) {
93 return pixelSnappedIntRect( 93 return pixelSnappedIntRect(
94 toLayoutHTMLCanvas(layoutObject)->replacedContentRect()); 94 toLayoutHTMLCanvas(layoutObject).replacedContentRect());
95 if (layoutObject->isVideo()) 95 }
96 if (layoutObject.isVideo()) {
96 return pixelSnappedIntRect( 97 return pixelSnappedIntRect(
97 toLayoutVideo(layoutObject)->replacedContentRect()); 98 toLayoutVideo(layoutObject).replacedContentRect());
99 }
98 100
99 return pixelSnappedIntRect(toLayoutBox(layoutObject)->contentBoxRect()); 101 return pixelSnappedIntRect(toLayoutBox(layoutObject).contentBoxRect());
100 } 102 }
101 103
102 static IntRect backgroundRect(const LayoutObject* layoutObject) { 104 static IntRect backgroundRect(const LayoutObject& layoutObject) {
103 if (!layoutObject->isBox()) 105 if (!layoutObject.isBox())
104 return IntRect(); 106 return IntRect();
105 107
106 LayoutRect rect; 108 LayoutRect rect;
107 const LayoutBox* box = toLayoutBox(layoutObject); 109 const LayoutBox& box = toLayoutBox(layoutObject);
108 return pixelSnappedIntRect(box->backgroundRect(BackgroundClipRect)); 110 return pixelSnappedIntRect(box.backgroundRect(BackgroundClipRect));
109 } 111 }
110 112
111 static inline bool isAcceleratedCanvas(const LayoutObject* layoutObject) { 113 static inline bool isAcceleratedCanvas(const LayoutObject& layoutObject) {
112 if (layoutObject->isCanvas()) { 114 if (layoutObject.isCanvas()) {
113 HTMLCanvasElement* canvas = toHTMLCanvasElement(layoutObject->node()); 115 HTMLCanvasElement* canvas = toHTMLCanvasElement(layoutObject.node());
114 if (CanvasRenderingContext* context = canvas->renderingContext()) 116 if (CanvasRenderingContext* context = canvas->renderingContext())
115 return context->isAccelerated(); 117 return context->isAccelerated();
116 } 118 }
117 return false; 119 return false;
118 } 120 }
119 121
120 static inline bool isCanvasControlledByOffscreen( 122 static inline bool isCanvasControlledByOffscreen(
121 const LayoutObject* layoutObject) { 123 const LayoutObject& layoutObject) {
122 if (layoutObject->isCanvas()) { 124 if (layoutObject.isCanvas()) {
123 HTMLCanvasElement* canvas = toHTMLCanvasElement(layoutObject->node()); 125 HTMLCanvasElement* canvas = toHTMLCanvasElement(layoutObject.node());
124 if (canvas->surfaceLayerBridge()) 126 if (canvas->surfaceLayerBridge())
125 return true; 127 return true;
126 } 128 }
127 return false; 129 return false;
128 } 130 }
129 131
130 static bool hasBoxDecorationsOrBackgroundImage(const ComputedStyle& style) { 132 static bool hasBoxDecorationsOrBackgroundImage(const ComputedStyle& style) {
131 return style.hasBoxDecorations() || style.hasBackgroundImage(); 133 return style.hasBoxDecorations() || style.hasBackgroundImage();
132 } 134 }
133 135
134 static bool contentLayerSupportsDirectBackgroundComposition( 136 static bool contentLayerSupportsDirectBackgroundComposition(
135 const LayoutObject* layoutObject) { 137 const LayoutObject& layoutObject) {
136 // No support for decorations - border, border-radius or outline. 138 // No support for decorations - border, border-radius or outline.
137 // Only simple background - solid color or transparent. 139 // Only simple background - solid color or transparent.
138 if (hasBoxDecorationsOrBackgroundImage(layoutObject->styleRef())) 140 if (hasBoxDecorationsOrBackgroundImage(layoutObject.styleRef()))
139 return false; 141 return false;
140 142
141 // If there is no background, there is nothing to support. 143 // If there is no background, there is nothing to support.
142 if (!layoutObject->style()->hasBackground()) 144 if (!layoutObject.style()->hasBackground())
143 return true; 145 return true;
144 146
145 // Simple background that is contained within the contents rect. 147 // Simple background that is contained within the contents rect.
146 return contentsRect(layoutObject).contains(backgroundRect(layoutObject)); 148 return contentsRect(layoutObject).contains(backgroundRect(layoutObject));
147 } 149 }
148 150
149 static WebLayer* platformLayerForPlugin(LayoutObject* layoutObject) { 151 static WebLayer* platformLayerForPlugin(LayoutObject& layoutObject) {
150 if (!layoutObject->isEmbeddedObject()) 152 if (!layoutObject.isEmbeddedObject())
151 return nullptr; 153 return nullptr;
152 Widget* widget = toLayoutEmbeddedObject(layoutObject)->widget(); 154 Widget* widget = toLayoutEmbeddedObject(layoutObject).widget();
153 if (!widget || !widget->isPluginView()) 155 if (!widget || !widget->isPluginView())
154 return nullptr; 156 return nullptr;
155 return toPluginView(widget)->platformLayer(); 157 return toPluginView(widget)->platformLayer();
156 } 158 }
157 159
158 static inline bool isAcceleratedContents(LayoutObject* layoutObject) { 160 static inline bool isAcceleratedContents(LayoutObject& layoutObject) {
159 return isAcceleratedCanvas(layoutObject) || 161 return isAcceleratedCanvas(layoutObject) ||
160 (layoutObject->isEmbeddedObject() && 162 (layoutObject.isEmbeddedObject() &&
161 toLayoutEmbeddedObject(layoutObject) 163 toLayoutEmbeddedObject(layoutObject)
162 ->requiresAcceleratedCompositing()) || 164 .requiresAcceleratedCompositing()) ||
163 layoutObject->isVideo(); 165 layoutObject.isVideo();
164 } 166 }
165 167
166 // Get the scrolling coordinator in a way that works inside 168 // Get the scrolling coordinator in a way that works inside
167 // CompositedLayerMapping's destructor. 169 // CompositedLayerMapping's destructor.
168 static ScrollingCoordinator* scrollingCoordinatorFromLayer(PaintLayer& layer) { 170 static ScrollingCoordinator* scrollingCoordinatorFromLayer(PaintLayer& layer) {
169 Page* page = layer.layoutObject()->frame()->page(); 171 Page* page = layer.layoutObject().frame()->page();
170 return (!page) ? nullptr : page->scrollingCoordinator(); 172 return (!page) ? nullptr : page->scrollingCoordinator();
171 } 173 }
172 174
173 CompositedLayerMapping::CompositedLayerMapping(PaintLayer& layer) 175 CompositedLayerMapping::CompositedLayerMapping(PaintLayer& layer)
174 : m_owningLayer(layer), 176 : m_owningLayer(layer),
175 m_contentOffsetInCompositingLayerDirty(false), 177 m_contentOffsetInCompositingLayerDirty(false),
176 m_pendingUpdateScope(GraphicsLayerUpdateNone), 178 m_pendingUpdateScope(GraphicsLayerUpdateNone),
177 m_isMainFrameLayoutViewLayer(false), 179 m_isMainFrameLayoutViewLayer(false),
178 m_backgroundLayerPaintsFixedRootBackground(false), 180 m_backgroundLayerPaintsFixedRootBackground(false),
179 m_scrollingContentsAreEmpty(false), 181 m_scrollingContentsAreEmpty(false),
180 m_backgroundPaintsOntoScrollingContentsLayer(false), 182 m_backgroundPaintsOntoScrollingContentsLayer(false),
181 m_backgroundPaintsOntoGraphicsLayer(false), 183 m_backgroundPaintsOntoGraphicsLayer(false),
182 m_drawsBackgroundOntoContentLayer(false) { 184 m_drawsBackgroundOntoContentLayer(false) {
183 if (layer.isRootLayer() && layoutObject()->frame()->isMainFrame()) 185 if (layer.isRootLayer() && layoutObject().frame()->isMainFrame())
184 m_isMainFrameLayoutViewLayer = true; 186 m_isMainFrameLayoutViewLayer = true;
185 187
186 createPrimaryGraphicsLayer(); 188 createPrimaryGraphicsLayer();
187 } 189 }
188 190
189 CompositedLayerMapping::~CompositedLayerMapping() { 191 CompositedLayerMapping::~CompositedLayerMapping() {
190 // Hits in compositing/squashing/squash-onto-nephew.html. 192 // Hits in compositing/squashing/squash-onto-nephew.html.
191 DisableCompositingQueryAsserts disabler; 193 DisableCompositingQueryAsserts disabler;
192 194
193 // Do not leave the destroyed pointer dangling on any Layers that painted to 195 // Do not leave the destroyed pointer dangling on any Layers that painted to
(...skipping 21 matching lines...) Expand all
215 destroyGraphicsLayers(); 217 destroyGraphicsLayers();
216 } 218 }
217 219
218 std::unique_ptr<GraphicsLayer> CompositedLayerMapping::createGraphicsLayer( 220 std::unique_ptr<GraphicsLayer> CompositedLayerMapping::createGraphicsLayer(
219 CompositingReasons reasons, 221 CompositingReasons reasons,
220 SquashingDisallowedReasons squashingDisallowedReasons) { 222 SquashingDisallowedReasons squashingDisallowedReasons) {
221 std::unique_ptr<GraphicsLayer> graphicsLayer = GraphicsLayer::create(this); 223 std::unique_ptr<GraphicsLayer> graphicsLayer = GraphicsLayer::create(this);
222 224
223 graphicsLayer->setCompositingReasons(reasons); 225 graphicsLayer->setCompositingReasons(reasons);
224 graphicsLayer->setSquashingDisallowedReasons(squashingDisallowedReasons); 226 graphicsLayer->setSquashingDisallowedReasons(squashingDisallowedReasons);
225 if (Node* owningNode = m_owningLayer.layoutObject()->node()) 227 if (Node* owningNode = m_owningLayer.layoutObject().node())
226 graphicsLayer->setOwnerNodeId(DOMNodeIds::idForNode(owningNode)); 228 graphicsLayer->setOwnerNodeId(DOMNodeIds::idForNode(owningNode));
227 229
228 return graphicsLayer; 230 return graphicsLayer;
229 } 231 }
230 232
231 void CompositedLayerMapping::createPrimaryGraphicsLayer() { 233 void CompositedLayerMapping::createPrimaryGraphicsLayer() {
232 m_graphicsLayer = 234 m_graphicsLayer =
233 createGraphicsLayer(m_owningLayer.getCompositingReasons(), 235 createGraphicsLayer(m_owningLayer.getCompositingReasons(),
234 m_owningLayer.getSquashingDisallowedReasons()); 236 m_owningLayer.getSquashingDisallowedReasons());
235 237
236 updateOpacity(layoutObject()->styleRef()); 238 updateOpacity(layoutObject().styleRef());
237 updateTransform(layoutObject()->styleRef()); 239 updateTransform(layoutObject().styleRef());
238 updateFilters(layoutObject()->styleRef()); 240 updateFilters(layoutObject().styleRef());
239 updateBackdropFilters(layoutObject()->styleRef()); 241 updateBackdropFilters(layoutObject().styleRef());
240 updateLayerBlendMode(layoutObject()->styleRef()); 242 updateLayerBlendMode(layoutObject().styleRef());
241 updateIsRootForIsolatedGroup(); 243 updateIsRootForIsolatedGroup();
242 } 244 }
243 245
244 void CompositedLayerMapping::destroyGraphicsLayers() { 246 void CompositedLayerMapping::destroyGraphicsLayers() {
245 if (m_graphicsLayer) 247 if (m_graphicsLayer)
246 m_graphicsLayer->removeFromParent(); 248 m_graphicsLayer->removeFromParent();
247 249
248 m_ancestorClippingLayer = nullptr; 250 m_ancestorClippingLayer = nullptr;
249 m_ancestorClippingMaskLayer = nullptr; 251 m_ancestorClippingMaskLayer = nullptr;
250 m_graphicsLayer = nullptr; 252 m_graphicsLayer = nullptr;
(...skipping 11 matching lines...) Expand all
262 void CompositedLayerMapping::updateOpacity(const ComputedStyle& style) { 264 void CompositedLayerMapping::updateOpacity(const ComputedStyle& style) {
263 m_graphicsLayer->setOpacity(compositingOpacity(style.opacity())); 265 m_graphicsLayer->setOpacity(compositingOpacity(style.opacity()));
264 } 266 }
265 267
266 void CompositedLayerMapping::updateTransform(const ComputedStyle& style) { 268 void CompositedLayerMapping::updateTransform(const ComputedStyle& style) {
267 // FIXME: This could use m_owningLayer.transform(), but that currently has 269 // FIXME: This could use m_owningLayer.transform(), but that currently has
268 // transform-origin baked into it, and we don't want that. 270 // transform-origin baked into it, and we don't want that.
269 TransformationMatrix t; 271 TransformationMatrix t;
270 if (m_owningLayer.hasTransformRelatedProperty()) { 272 if (m_owningLayer.hasTransformRelatedProperty()) {
271 style.applyTransform( 273 style.applyTransform(
272 t, LayoutSize(toLayoutBox(layoutObject())->pixelSnappedSize()), 274 t, LayoutSize(toLayoutBox(layoutObject()).pixelSnappedSize()),
273 ComputedStyle::ExcludeTransformOrigin, ComputedStyle::IncludeMotionPath, 275 ComputedStyle::ExcludeTransformOrigin, ComputedStyle::IncludeMotionPath,
274 ComputedStyle::IncludeIndependentTransformProperties); 276 ComputedStyle::IncludeIndependentTransformProperties);
275 makeMatrixRenderable(t, compositor()->hasAcceleratedCompositing()); 277 makeMatrixRenderable(t, compositor()->hasAcceleratedCompositing());
276 } 278 }
277 279
278 m_graphicsLayer->setTransform(t); 280 m_graphicsLayer->setTransform(t);
279 } 281 }
280 282
281 void CompositedLayerMapping::updateFilters(const ComputedStyle& style) { 283 void CompositedLayerMapping::updateFilters(const ComputedStyle& style) {
282 m_graphicsLayer->setFilters( 284 m_graphicsLayer->setFilters(
283 owningLayer().createCompositorFilterOperationsForFilter(style)); 285 owningLayer().createCompositorFilterOperationsForFilter(style));
284 } 286 }
285 287
286 void CompositedLayerMapping::updateBackdropFilters(const ComputedStyle& style) { 288 void CompositedLayerMapping::updateBackdropFilters(const ComputedStyle& style) {
287 m_graphicsLayer->setBackdropFilters( 289 m_graphicsLayer->setBackdropFilters(
288 owningLayer().createCompositorFilterOperationsForBackdropFilter(style)); 290 owningLayer().createCompositorFilterOperationsForBackdropFilter(style));
289 } 291 }
290 292
291 void CompositedLayerMapping::updateStickyConstraints( 293 void CompositedLayerMapping::updateStickyConstraints(
292 const ComputedStyle& style) { 294 const ComputedStyle& style) {
293 bool sticky = style.position() == EPosition::kSticky; 295 bool sticky = style.position() == EPosition::kSticky;
294 const PaintLayer* ancestorOverflowLayer = 296 const PaintLayer* ancestorOverflowLayer =
295 m_owningLayer.ancestorOverflowLayer(); 297 m_owningLayer.ancestorOverflowLayer();
296 // TODO(flackr): Do we still need this? 298 // TODO(flackr): Do we still need this?
297 if (sticky) { 299 if (sticky) {
298 if (!ancestorOverflowLayer->isRootLayer()) { 300 if (!ancestorOverflowLayer->isRootLayer()) {
299 sticky = ancestorOverflowLayer->needsCompositedScrolling(); 301 sticky = ancestorOverflowLayer->needsCompositedScrolling();
300 } else { 302 } else {
301 sticky = layoutObject()->view()->frameView()->isScrollable(); 303 sticky = layoutObject().view()->frameView()->isScrollable();
302 } 304 }
303 } 305 }
304 306
305 WebLayerStickyPositionConstraint webConstraint; 307 WebLayerStickyPositionConstraint webConstraint;
306 if (sticky) { 308 if (sticky) {
307 const StickyPositionScrollingConstraints& constraints = 309 const StickyPositionScrollingConstraints& constraints =
308 ancestorOverflowLayer->getScrollableArea()->stickyConstraintsMap().get( 310 ancestorOverflowLayer->getScrollableArea()->stickyConstraintsMap().get(
309 &m_owningLayer); 311 &m_owningLayer);
310 312
311 // Find the layout offset of the unshifted sticky box within its enclosing 313 // Find the layout offset of the unshifted sticky box within its enclosing
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 m_backgroundPaintsOntoGraphicsLayer = shouldPaintOntoGraphicsLayer; 389 m_backgroundPaintsOntoGraphicsLayer = shouldPaintOntoGraphicsLayer;
388 // The graphics layer needs to be updated for changed 390 // The graphics layer needs to be updated for changed
389 // m_backgroundPaintsOntoGraphicsLayer. 391 // m_backgroundPaintsOntoGraphicsLayer.
390 m_graphicsLayer->setNeedsDisplay(); 392 m_graphicsLayer->setNeedsDisplay();
391 } 393 }
392 } 394 }
393 395
394 void CompositedLayerMapping::updateContentsOpaque() { 396 void CompositedLayerMapping::updateContentsOpaque() {
395 if (isAcceleratedCanvas(layoutObject())) { 397 if (isAcceleratedCanvas(layoutObject())) {
396 CanvasRenderingContext* context = 398 CanvasRenderingContext* context =
397 toHTMLCanvasElement(layoutObject()->node())->renderingContext(); 399 toHTMLCanvasElement(layoutObject().node())->renderingContext();
398 WebLayer* layer = context ? context->platformLayer() : nullptr; 400 WebLayer* layer = context ? context->platformLayer() : nullptr;
399 // Determine whether the external texture layer covers the whole graphics 401 // Determine whether the external texture layer covers the whole graphics
400 // layer. This may not be the case if there are box decorations or 402 // layer. This may not be the case if there are box decorations or
401 // shadows. 403 // shadows.
402 if (layer && 404 if (layer &&
403 layer->bounds() == m_graphicsLayer->platformLayer()->bounds()) { 405 layer->bounds() == m_graphicsLayer->platformLayer()->bounds()) {
404 // Determine whether the rendering context's external texture layer is 406 // Determine whether the rendering context's external texture layer is
405 // opaque. 407 // opaque.
406 if (!context->creationAttributes().alpha()) { 408 if (!context->creationAttributes().alpha()) {
407 m_graphicsLayer->setContentsOpaque(true); 409 m_graphicsLayer->setContentsOpaque(true);
(...skipping 13 matching lines...) Expand all
421 // layer if all backgrounds are background attachment local, otherwise 423 // layer if all backgrounds are background attachment local, otherwise
422 // background is painted by the primary graphics layer. 424 // background is painted by the primary graphics layer.
423 if (hasScrollingLayer() && m_backgroundPaintsOntoScrollingContentsLayer) { 425 if (hasScrollingLayer() && m_backgroundPaintsOntoScrollingContentsLayer) {
424 // Backgrounds painted onto the foreground are clipped by the padding box 426 // Backgrounds painted onto the foreground are clipped by the padding box
425 // rect. 427 // rect.
426 // TODO(flackr): This should actually check the entire overflow rect 428 // TODO(flackr): This should actually check the entire overflow rect
427 // within the scrolling contents layer but since we currently only trigger 429 // within the scrolling contents layer but since we currently only trigger
428 // this for solid color backgrounds the answer will be the same. 430 // this for solid color backgrounds the answer will be the same.
429 m_scrollingContentsLayer->setContentsOpaque( 431 m_scrollingContentsLayer->setContentsOpaque(
430 m_owningLayer.backgroundIsKnownToBeOpaqueInRect( 432 m_owningLayer.backgroundIsKnownToBeOpaqueInRect(
431 toLayoutBox(layoutObject())->paddingBoxRect())); 433 toLayoutBox(layoutObject()).paddingBoxRect()));
432 434
433 if (m_owningLayer.backgroundPaintLocation() & 435 if (m_owningLayer.backgroundPaintLocation() &
434 BackgroundPaintInGraphicsLayer) { 436 BackgroundPaintInGraphicsLayer) {
435 m_graphicsLayer->setContentsOpaque( 437 m_graphicsLayer->setContentsOpaque(
436 m_owningLayer.backgroundIsKnownToBeOpaqueInRect( 438 m_owningLayer.backgroundIsKnownToBeOpaqueInRect(
437 compositedBounds())); 439 compositedBounds()));
438 } else { 440 } else {
439 // If we only paint the background onto the scrolling contents layer we 441 // If we only paint the background onto the scrolling contents layer we
440 // are going to leave a hole in the m_graphicsLayer where the background 442 // are going to leave a hole in the m_graphicsLayer where the background
441 // is so it is not opaque. 443 // is so it is not opaque.
(...skipping 11 matching lines...) Expand all
453 void CompositedLayerMapping::updateCompositedBounds() { 455 void CompositedLayerMapping::updateCompositedBounds() {
454 ASSERT(m_owningLayer.compositor()->lifecycle().state() == 456 ASSERT(m_owningLayer.compositor()->lifecycle().state() ==
455 DocumentLifecycle::InCompositingUpdate); 457 DocumentLifecycle::InCompositingUpdate);
456 // FIXME: if this is really needed for performance, it would be better to 458 // FIXME: if this is really needed for performance, it would be better to
457 // store it on Layer. 459 // store it on Layer.
458 m_compositedBounds = m_owningLayer.boundingBoxForCompositing(); 460 m_compositedBounds = m_owningLayer.boundingBoxForCompositing();
459 m_contentOffsetInCompositingLayerDirty = true; 461 m_contentOffsetInCompositingLayerDirty = true;
460 } 462 }
461 463
462 void CompositedLayerMapping::updateAfterPartResize() { 464 void CompositedLayerMapping::updateAfterPartResize() {
463 if (layoutObject()->isLayoutPart()) { 465 if (layoutObject().isLayoutPart()) {
464 if (PaintLayerCompositor* innerCompositor = 466 if (PaintLayerCompositor* innerCompositor =
465 PaintLayerCompositor::frameContentsCompositor( 467 PaintLayerCompositor::frameContentsCompositor(
466 toLayoutPart(layoutObject()))) { 468 toLayoutPart(layoutObject()))) {
467 innerCompositor->frameViewDidChangeSize(); 469 innerCompositor->frameViewDidChangeSize();
468 // We can floor this point because our frameviews are always aligned to 470 // We can floor this point because our frameviews are always aligned to
469 // pixel boundaries. 471 // pixel boundaries.
470 ASSERT(m_compositedBounds.location() == 472 ASSERT(m_compositedBounds.location() ==
471 flooredIntPoint(m_compositedBounds.location())); 473 flooredIntPoint(m_compositedBounds.location()));
472 innerCompositor->frameViewDidChangeLocation( 474 innerCompositor->frameViewDidChangeLocation(
473 flooredIntPoint(contentsBox().location())); 475 flooredIntPoint(contentsBox().location()));
474 } 476 }
475 } 477 }
476 } 478 }
477 479
478 void CompositedLayerMapping::updateCompositingReasons() { 480 void CompositedLayerMapping::updateCompositingReasons() {
479 // All other layers owned by this mapping will have the same compositing 481 // All other layers owned by this mapping will have the same compositing
480 // reason for their lifetime, so they are initialized only when created. 482 // reason for their lifetime, so they are initialized only when created.
481 m_graphicsLayer->setCompositingReasons(m_owningLayer.getCompositingReasons()); 483 m_graphicsLayer->setCompositingReasons(m_owningLayer.getCompositingReasons());
482 m_graphicsLayer->setSquashingDisallowedReasons( 484 m_graphicsLayer->setSquashingDisallowedReasons(
483 m_owningLayer.getSquashingDisallowedReasons()); 485 m_owningLayer.getSquashingDisallowedReasons());
484 } 486 }
485 487
486 bool CompositedLayerMapping::ancestorRoundedCornersWontClip( 488 bool CompositedLayerMapping::ancestorRoundedCornersWontClip(
487 const LayoutObject* child, 489 const LayoutBoxModelObject& child,
488 const LayoutObject* clippingAncestor) { 490 const LayoutBoxModelObject& clippingAncestor) {
489 if (!clippingAncestor->isBoxModelObject())
490 return false;
491 const LayoutBoxModelObject* clippingObject =
492 toLayoutBoxModelObject(clippingAncestor);
493 LayoutRect localVisualRect = m_compositedBounds; 491 LayoutRect localVisualRect = m_compositedBounds;
494 child->mapToVisualRectInAncestorSpace(clippingObject, localVisualRect); 492 child.mapToVisualRectInAncestorSpace(&clippingAncestor, localVisualRect);
495 FloatRoundedRect roundedClipRect = 493 FloatRoundedRect roundedClipRect =
496 clippingObject->style()->getRoundedInnerBorderFor( 494 clippingAncestor.style()->getRoundedInnerBorderFor(
497 clippingObject->localVisualRect()); 495 clippingAncestor.localVisualRect());
498 FloatRect innerClipRect = roundedClipRect.radiusCenterRect(); 496 FloatRect innerClipRect = roundedClipRect.radiusCenterRect();
499 // The first condition catches cases where the child is certainly inside 497 // The first condition catches cases where the child is certainly inside
500 // the rounded corner portion of the border, and cannot be clipped by 498 // the rounded corner portion of the border, and cannot be clipped by
501 // the rounded portion. The second catches cases where the child is 499 // the rounded portion. The second catches cases where the child is
502 // entirely outside the rectangular border (ignoring rounded corners) so 500 // entirely outside the rectangular border (ignoring rounded corners) so
503 // is also unaffected by the rounded corners. In both cases the existing 501 // is also unaffected by the rounded corners. In both cases the existing
504 // rectangular clip is adequate and the mask is unnecessary. 502 // rectangular clip is adequate and the mask is unnecessary.
505 return innerClipRect.contains(FloatRect(localVisualRect)) || 503 return innerClipRect.contains(FloatRect(localVisualRect)) ||
506 !localVisualRect.intersects( 504 !localVisualRect.intersects(
507 enclosingLayoutRect(roundedClipRect.rect())); 505 enclosingLayoutRect(roundedClipRect.rect()));
508 } 506 }
509 507
510 void CompositedLayerMapping:: 508 void CompositedLayerMapping::
511 owningLayerClippedOrMaskedByLayerNotAboveCompositedAncestor( 509 owningLayerClippedOrMaskedByLayerNotAboveCompositedAncestor(
512 const PaintLayer* scrollParent, 510 const PaintLayer* scrollParent,
513 bool& owningLayerIsClipped, 511 bool& owningLayerIsClipped,
514 bool& owningLayerIsMasked) { 512 bool& owningLayerIsMasked) {
515 owningLayerIsClipped = false; 513 owningLayerIsClipped = false;
516 owningLayerIsMasked = false; 514 owningLayerIsMasked = false;
517 515
518 if (!m_owningLayer.parent()) 516 if (!m_owningLayer.parent())
519 return; 517 return;
520 518
521 const PaintLayer* compositingAncestor = 519 const PaintLayer* compositingAncestor =
522 m_owningLayer.enclosingLayerWithCompositedLayerMapping(ExcludeSelf); 520 m_owningLayer.enclosingLayerWithCompositedLayerMapping(ExcludeSelf);
523 if (!compositingAncestor) 521 if (!compositingAncestor)
524 return; 522 return;
525 523
526 const LayoutObject* clippingContainer = m_owningLayer.clippingContainer(); 524 const LayoutBoxModelObject* clippingContainer =
525 m_owningLayer.clippingContainer();
527 if (!clippingContainer) 526 if (!clippingContainer)
528 return; 527 return;
529 528
530 if (clippingContainer->enclosingLayer() == scrollParent) 529 if (clippingContainer->enclosingLayer() == scrollParent)
531 return; 530 return;
532 531
533 if (clippingContainer->enclosingLayer()->hasRootScrollerAsDescendant()) 532 if (clippingContainer->enclosingLayer()->hasRootScrollerAsDescendant())
534 return; 533 return;
535 534
536 if (compositingAncestor->layoutObject()->isDescendantOf(clippingContainer)) 535 if (compositingAncestor->layoutObject().isDescendantOf(clippingContainer))
537 return; 536 return;
538 537
539 // We ignore overflow clip here; we want composited overflow content to 538 // We ignore overflow clip here; we want composited overflow content to
540 // behave as if it lives in an unclipped universe so it can prepaint, etc. 539 // behave as if it lives in an unclipped universe so it can prepaint, etc.
541 // This means that we need to check if we are actually clipped before 540 // This means that we need to check if we are actually clipped before
542 // setting up m_ancestorClippingLayer otherwise 541 // setting up m_ancestorClippingLayer otherwise
543 // updateAncestorClippingLayerGeometry will fail as the clip rect will be 542 // updateAncestorClippingLayerGeometry will fail as the clip rect will be
544 // infinite. 543 // infinite.
545 // FIXME: this should use cached clip rects, but this sometimes give 544 // FIXME: this should use cached clip rects, but this sometimes give
546 // inaccurate results (and trips the ASSERTS in PaintLayerClipper). 545 // inaccurate results (and trips the ASSERTS in PaintLayerClipper).
547 ClipRectsContext clipRectsContext(compositingAncestor, UncachedClipRects, 546 ClipRectsContext clipRectsContext(compositingAncestor, UncachedClipRects,
548 IgnoreOverlayScrollbarSize); 547 IgnoreOverlayScrollbarSize);
549 clipRectsContext.setIgnoreOverflowClip(); 548 clipRectsContext.setIgnoreOverflowClip();
550 LayoutRect unsnappedParentClipRect = 549 LayoutRect unsnappedParentClipRect =
551 m_owningLayer.clipper(PaintLayer::DoNotUseGeometryMapper) 550 m_owningLayer.clipper(PaintLayer::DoNotUseGeometryMapper)
552 .backgroundClipRect(clipRectsContext) 551 .backgroundClipRect(clipRectsContext)
553 .rect(); 552 .rect();
554 IntRect parentClipRect = pixelSnappedIntRect(unsnappedParentClipRect); 553 IntRect parentClipRect = pixelSnappedIntRect(unsnappedParentClipRect);
555 owningLayerIsClipped = parentClipRect != LayoutRect::infiniteIntRect(); 554 owningLayerIsClipped = parentClipRect != LayoutRect::infiniteIntRect();
556 555
557 // TODO(schenney): CSS clips are not applied to composited children, and 556 // TODO(schenney): CSS clips are not applied to composited children, and
558 // should be via mask or by compositing the parent too. 557 // should be via mask or by compositing the parent too.
559 // https://bugs.chromium.org/p/chromium/issues/detail?id=615870 558 // https://bugs.chromium.org/p/chromium/issues/detail?id=615870
560 DCHECK(clippingContainer->style()); 559 DCHECK(clippingContainer->style());
561 owningLayerIsMasked = 560 owningLayerIsMasked =
562 owningLayerIsClipped && clippingContainer->style()->hasBorderRadius() && 561 owningLayerIsClipped && clippingContainer->style()->hasBorderRadius() &&
563 !ancestorRoundedCornersWontClip(layoutObject(), clippingContainer); 562 !ancestorRoundedCornersWontClip(layoutObject(), *clippingContainer);
564 } 563 }
565 564
566 const PaintLayer* CompositedLayerMapping::scrollParent() { 565 const PaintLayer* CompositedLayerMapping::scrollParent() {
567 const PaintLayer* scrollParent = m_owningLayer.scrollParent(); 566 const PaintLayer* scrollParent = m_owningLayer.scrollParent();
568 if (scrollParent && !scrollParent->needsCompositedScrolling()) 567 if (scrollParent && !scrollParent->needsCompositedScrolling())
569 return nullptr; 568 return nullptr;
570 return scrollParent; 569 return scrollParent;
571 } 570 }
572 571
573 bool CompositedLayerMapping::updateGraphicsLayerConfiguration() { 572 bool CompositedLayerMapping::updateGraphicsLayerConfiguration() {
574 ASSERT(m_owningLayer.compositor()->lifecycle().state() == 573 ASSERT(m_owningLayer.compositor()->lifecycle().state() ==
575 DocumentLifecycle::InCompositingUpdate); 574 DocumentLifecycle::InCompositingUpdate);
576 575
577 // Note carefully: here we assume that the compositing state of all 576 // Note carefully: here we assume that the compositing state of all
578 // descendants have been updated already, so it is legitimate to compute and 577 // descendants have been updated already, so it is legitimate to compute and
579 // cache the composited bounds for this layer. 578 // cache the composited bounds for this layer.
580 updateCompositedBounds(); 579 updateCompositedBounds();
581 580
582 PaintLayerCompositor* compositor = this->compositor(); 581 PaintLayerCompositor* compositor = this->compositor();
583 LayoutObject* layoutObject = this->layoutObject(); 582 LayoutObject& layoutObject = this->layoutObject();
584 const ComputedStyle& style = layoutObject->styleRef(); 583 const ComputedStyle& style = layoutObject.styleRef();
585 584
586 bool layerConfigChanged = false; 585 bool layerConfigChanged = false;
587 setBackgroundLayerPaintsFixedRootBackground( 586 setBackgroundLayerPaintsFixedRootBackground(
588 compositor->needsFixedRootBackgroundLayer(&m_owningLayer)); 587 compositor->needsFixedRootBackgroundLayer(&m_owningLayer));
589 588
590 // The background layer is currently only used for fixed root backgrounds. 589 // The background layer is currently only used for fixed root backgrounds.
591 if (updateBackgroundLayer(m_backgroundLayerPaintsFixedRootBackground)) 590 if (updateBackgroundLayer(m_backgroundLayerPaintsFixedRootBackground))
592 layerConfigChanged = true; 591 layerConfigChanged = true;
593 592
594 if (updateForegroundLayer( 593 if (updateForegroundLayer(
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 625
627 bool scrollingConfigChanged = false; 626 bool scrollingConfigChanged = false;
628 if (updateScrollingLayers(m_owningLayer.needsCompositedScrolling())) { 627 if (updateScrollingLayers(m_owningLayer.needsCompositedScrolling())) {
629 layerConfigChanged = true; 628 layerConfigChanged = true;
630 scrollingConfigChanged = true; 629 scrollingConfigChanged = true;
631 } 630 }
632 631
633 // If the outline needs to draw over the composited scrolling contents layer 632 // If the outline needs to draw over the composited scrolling contents layer
634 // or scrollbar layers it needs to be drawn into a separate layer. 633 // or scrollbar layers it needs to be drawn into a separate layer.
635 int minBorderWidth = 634 int minBorderWidth =
636 std::min(layoutObject->style()->borderTopWidth(), 635 std::min(layoutObject.style()->borderTopWidth(),
637 std::min(layoutObject->style()->borderLeftWidth(), 636 std::min(layoutObject.style()->borderLeftWidth(),
638 std::min(layoutObject->style()->borderRightWidth(), 637 std::min(layoutObject.style()->borderRightWidth(),
639 layoutObject->style()->borderBottomWidth()))); 638 layoutObject.style()->borderBottomWidth())));
640 bool needsDecorationOutlineLayer = 639 bool needsDecorationOutlineLayer =
641 m_owningLayer.getScrollableArea() && 640 m_owningLayer.getScrollableArea() &&
642 m_owningLayer.getScrollableArea()->usesCompositedScrolling() && 641 m_owningLayer.getScrollableArea()->usesCompositedScrolling() &&
643 layoutObject->style()->hasOutline() && 642 layoutObject.style()->hasOutline() &&
644 layoutObject->style()->outlineOffset() < -minBorderWidth; 643 layoutObject.style()->outlineOffset() < -minBorderWidth;
645 644
646 if (updateDecorationOutlineLayer(needsDecorationOutlineLayer)) 645 if (updateDecorationOutlineLayer(needsDecorationOutlineLayer))
647 layerConfigChanged = true; 646 layerConfigChanged = true;
648 647
649 if (updateOverflowControlsLayers( 648 if (updateOverflowControlsLayers(
650 requiresHorizontalScrollbarLayer(), requiresVerticalScrollbarLayer(), 649 requiresHorizontalScrollbarLayer(), requiresVerticalScrollbarLayer(),
651 requiresScrollCornerLayer(), needsAncestorClip)) 650 requiresScrollCornerLayer(), needsAncestorClip))
652 layerConfigChanged = true; 651 layerConfigChanged = true;
653 652
654 bool hasPerspective = style.hasPerspective(); 653 bool hasPerspective = style.hasPerspective();
655 bool needsChildTransformLayer = hasPerspective && layoutObject->isBox(); 654 bool needsChildTransformLayer = hasPerspective && layoutObject.isBox();
656 if (updateChildTransformLayer(needsChildTransformLayer)) 655 if (updateChildTransformLayer(needsChildTransformLayer))
657 layerConfigChanged = true; 656 layerConfigChanged = true;
658 657
659 if (updateSquashingLayers(!m_squashedLayers.isEmpty())) 658 if (updateSquashingLayers(!m_squashedLayers.isEmpty()))
660 layerConfigChanged = true; 659 layerConfigChanged = true;
661 660
662 updateScrollParent(scrollParent); 661 updateScrollParent(scrollParent);
663 updateClipParent(scrollParent); 662 updateClipParent(scrollParent);
664 663
665 if (layerConfigChanged) 664 if (layerConfigChanged)
666 updateInternalHierarchy(); 665 updateInternalHierarchy();
667 666
668 if (scrollingConfigChanged) { 667 if (scrollingConfigChanged) {
669 if (layoutObject->view()) 668 if (layoutObject.view())
670 compositor->scrollingLayerDidChange(&m_owningLayer); 669 compositor->scrollingLayerDidChange(&m_owningLayer);
671 } 670 }
672 671
673 // A mask layer is not part of the hierarchy proper, it's an auxiliary layer 672 // A mask layer is not part of the hierarchy proper, it's an auxiliary layer
674 // that's plugged into another GraphicsLayer that is part of the hierarchy. 673 // that's plugged into another GraphicsLayer that is part of the hierarchy.
675 // It has no parent or child GraphicsLayer. For that reason, we process it 674 // It has no parent or child GraphicsLayer. For that reason, we process it
676 // here, after the hierarchy has been updated. 675 // here, after the hierarchy has been updated.
677 bool maskLayerChanged = updateMaskLayer(layoutObject->hasMask()); 676 bool maskLayerChanged = updateMaskLayer(layoutObject.hasMask());
678 if (maskLayerChanged) 677 if (maskLayerChanged)
679 m_graphicsLayer->setMaskLayer(m_maskLayer.get()); 678 m_graphicsLayer->setMaskLayer(m_maskLayer.get());
680 679
681 bool hasChildClippingLayer = 680 bool hasChildClippingLayer =
682 compositor->clipsCompositingDescendants(&m_owningLayer) && 681 compositor->clipsCompositingDescendants(&m_owningLayer) &&
683 (hasClippingLayer() || hasScrollingLayer()); 682 (hasClippingLayer() || hasScrollingLayer());
684 // If we have a border radius or clip path on a scrolling layer, we need a 683 // If we have a border radius or clip path on a scrolling layer, we need a
685 // clipping mask to properly clip the scrolled contents, even if there are no 684 // clipping mask to properly clip the scrolled contents, even if there are no
686 // composited descendants. 685 // composited descendants.
687 bool hasClipPath = style.clipPath(); 686 bool hasClipPath = style.clipPath();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 scrollingLayer()->setMaskLayer(layerToApplyChildClippingMask == 726 scrollingLayer()->setMaskLayer(layerToApplyChildClippingMask ==
728 scrollingLayer() 727 scrollingLayer()
729 ? m_childClippingMaskLayer.get() 728 ? m_childClippingMaskLayer.get()
730 : nullptr); 729 : nullptr);
731 m_graphicsLayer->setContentsClippingMaskLayer( 730 m_graphicsLayer->setContentsClippingMaskLayer(
732 shouldApplyChildClippingMaskOnContents ? m_childClippingMaskLayer.get() 731 shouldApplyChildClippingMaskOnContents ? m_childClippingMaskLayer.get()
733 : nullptr); 732 : nullptr);
734 733
735 updateBackgroundColor(); 734 updateBackgroundColor();
736 735
737 if (layoutObject->isImage()) { 736 if (layoutObject.isImage()) {
738 if (isDirectlyCompositedImage()) { 737 if (isDirectlyCompositedImage()) {
739 updateImageContents(); 738 updateImageContents();
740 } else if (m_graphicsLayer->hasContentsLayer()) { 739 } else if (m_graphicsLayer->hasContentsLayer()) {
741 m_graphicsLayer->setContentsToImage(nullptr); 740 m_graphicsLayer->setContentsToImage(nullptr);
742 } 741 }
743 } 742 }
744 743
745 if (WebLayer* layer = platformLayerForPlugin(layoutObject)) { 744 if (WebLayer* layer = platformLayerForPlugin(layoutObject)) {
746 m_graphicsLayer->setContentsToPlatformLayer(layer); 745 m_graphicsLayer->setContentsToPlatformLayer(layer);
747 } else if (layoutObject->node() && 746 } else if (layoutObject.node() &&
748 layoutObject->node()->isFrameOwnerElement() && 747 layoutObject.node()->isFrameOwnerElement() &&
749 toHTMLFrameOwnerElement(layoutObject->node())->contentFrame()) { 748 toHTMLFrameOwnerElement(layoutObject.node())->contentFrame()) {
750 Frame* frame = 749 Frame* frame = toHTMLFrameOwnerElement(layoutObject.node())->contentFrame();
751 toHTMLFrameOwnerElement(layoutObject->node())->contentFrame();
752 if (frame->isRemoteFrame()) { 750 if (frame->isRemoteFrame()) {
753 WebLayer* layer = toRemoteFrame(frame)->webLayer(); 751 WebLayer* layer = toRemoteFrame(frame)->webLayer();
754 m_graphicsLayer->setContentsToPlatformLayer(layer); 752 m_graphicsLayer->setContentsToPlatformLayer(layer);
755 } 753 }
756 } else if (layoutObject->isVideo()) { 754 } else if (layoutObject.isVideo()) {
757 HTMLMediaElement* mediaElement = toHTMLMediaElement(layoutObject->node()); 755 HTMLMediaElement* mediaElement = toHTMLMediaElement(layoutObject.node());
758 m_graphicsLayer->setContentsToPlatformLayer(mediaElement->platformLayer()); 756 m_graphicsLayer->setContentsToPlatformLayer(mediaElement->platformLayer());
759 } else if (isCanvasControlledByOffscreen(layoutObject)) { 757 } else if (isCanvasControlledByOffscreen(layoutObject)) {
760 HTMLCanvasElement* canvas = toHTMLCanvasElement(layoutObject->node()); 758 HTMLCanvasElement* canvas = toHTMLCanvasElement(layoutObject.node());
761 m_graphicsLayer->setContentsToPlatformLayer( 759 m_graphicsLayer->setContentsToPlatformLayer(
762 canvas->surfaceLayerBridge()->getWebLayer()); 760 canvas->surfaceLayerBridge()->getWebLayer());
763 layerConfigChanged = true; 761 layerConfigChanged = true;
764 } else if (isAcceleratedCanvas(layoutObject)) { 762 } else if (isAcceleratedCanvas(layoutObject)) {
765 HTMLCanvasElement* canvas = toHTMLCanvasElement(layoutObject->node()); 763 HTMLCanvasElement* canvas = toHTMLCanvasElement(layoutObject.node());
766 if (CanvasRenderingContext* context = canvas->renderingContext()) 764 if (CanvasRenderingContext* context = canvas->renderingContext())
767 m_graphicsLayer->setContentsToPlatformLayer(context->platformLayer()); 765 m_graphicsLayer->setContentsToPlatformLayer(context->platformLayer());
768 layerConfigChanged = true; 766 layerConfigChanged = true;
769 } 767 }
770 if (layoutObject->isLayoutPart()) { 768 if (layoutObject.isLayoutPart()) {
771 if (PaintLayerCompositor::attachFrameContentLayersToIframeLayer( 769 if (PaintLayerCompositor::attachFrameContentLayersToIframeLayer(
772 toLayoutPart(layoutObject))) 770 toLayoutPart(layoutObject)))
773 layerConfigChanged = true; 771 layerConfigChanged = true;
774 } 772 }
775 773
776 // Changes to either the internal hierarchy or the mask layer have an impact 774 // Changes to either the internal hierarchy or the mask layer have an impact
777 // on painting phases, so we need to update when either are updated. 775 // on painting phases, so we need to update when either are updated.
778 if (layerConfigChanged || maskLayerChanged) 776 if (layerConfigChanged || maskLayerChanged)
779 updatePaintingPhases(); 777 updatePaintingPhases();
780 778
781 updateElementIdAndCompositorMutableProperties(); 779 updateElementIdAndCompositorMutableProperties();
782 780
783 m_graphicsLayer->setHasWillChangeTransformHint( 781 m_graphicsLayer->setHasWillChangeTransformHint(
784 style.hasWillChangeTransformHint()); 782 style.hasWillChangeTransformHint());
785 783
786 if (style.preserves3D() && style.hasOpacity() && 784 if (style.preserves3D() && style.hasOpacity() &&
787 m_owningLayer.has3DTransformedDescendant()) 785 m_owningLayer.has3DTransformedDescendant())
788 UseCounter::count(layoutObject->document(), 786 UseCounter::count(layoutObject.document(),
789 UseCounter::OpacityWithPreserve3DQuirk); 787 UseCounter::OpacityWithPreserve3DQuirk);
790 788
791 return layerConfigChanged; 789 return layerConfigChanged;
792 } 790 }
793 791
794 static IntRect clipBox(LayoutBox* layoutObject) { 792 static IntRect clipBox(LayoutBox& layoutObject) {
795 // TODO(chrishtr): pixel snapping is most likely incorrect here. 793 // TODO(chrishtr): pixel snapping is most likely incorrect here.
796 return pixelSnappedIntRect(layoutObject->clippingRect()); 794 return pixelSnappedIntRect(layoutObject.clippingRect());
797 } 795 }
798 796
799 static LayoutPoint computeOffsetFromCompositedAncestor( 797 static LayoutPoint computeOffsetFromCompositedAncestor(
800 const PaintLayer* layer, 798 const PaintLayer* layer,
801 const PaintLayer* compositedAncestor) { 799 const PaintLayer* compositedAncestor) {
802 LayoutPoint offset = layer->visualOffsetFromAncestor(compositedAncestor); 800 LayoutPoint offset = layer->visualOffsetFromAncestor(compositedAncestor);
803 if (compositedAncestor) 801 if (compositedAncestor)
804 offset.move(compositedAncestor->compositedLayerMapping() 802 offset.move(compositedAncestor->compositedLayerMapping()
805 ->owningLayer() 803 ->owningLayer()
806 .subpixelAccumulation()); 804 .subpixelAccumulation());
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
923 IntSize newOffsetFromLayoutObject = 921 IntSize newOffsetFromLayoutObject =
924 -IntSize(offsetFromSquashLayerOrigin.width().round(), 922 -IntSize(offsetFromSquashLayerOrigin.width().round(),
925 offsetFromSquashLayerOrigin.height().round()); 923 offsetFromSquashLayerOrigin.height().round());
926 LayoutSize subpixelAccumulation = 924 LayoutSize subpixelAccumulation =
927 offsetFromSquashLayerOrigin + newOffsetFromLayoutObject; 925 offsetFromSquashLayerOrigin + newOffsetFromLayoutObject;
928 if (layers[i].offsetFromLayoutObjectSet && 926 if (layers[i].offsetFromLayoutObjectSet &&
929 layers[i].offsetFromLayoutObject != newOffsetFromLayoutObject) { 927 layers[i].offsetFromLayoutObject != newOffsetFromLayoutObject) {
930 // It is ok to issue paint invalidation here, because all of the geometry 928 // It is ok to issue paint invalidation here, because all of the geometry
931 // needed to correctly invalidate paint is computed by this point. 929 // needed to correctly invalidate paint is computed by this point.
932 DisablePaintInvalidationStateAsserts disabler; 930 DisablePaintInvalidationStateAsserts disabler;
933 ObjectPaintInvalidator(*layers[i].paintLayer->layoutObject()) 931 ObjectPaintInvalidator(layers[i].paintLayer->layoutObject())
934 .invalidatePaintIncludingNonCompositingDescendants(); 932 .invalidatePaintIncludingNonCompositingDescendants();
935 933
936 TRACE_LAYER_INVALIDATION(layers[i].paintLayer, 934 TRACE_LAYER_INVALIDATION(layers[i].paintLayer,
937 InspectorLayerInvalidationTrackingEvent:: 935 InspectorLayerInvalidationTrackingEvent::
938 SquashingLayerGeometryWasUpdated); 936 SquashingLayerGeometryWasUpdated);
939 layersNeedingPaintInvalidation.push_back(layers[i].paintLayer); 937 layersNeedingPaintInvalidation.push_back(layers[i].paintLayer);
940 } 938 }
941 layers[i].offsetFromLayoutObject = newOffsetFromLayoutObject; 939 layers[i].offsetFromLayoutObject = newOffsetFromLayoutObject;
942 layers[i].offsetFromLayoutObjectSet = true; 940 layers[i].offsetFromLayoutObjectSet = true;
943 941
(...skipping 15 matching lines...) Expand all
959 957
960 void CompositedLayerMapping::updateGraphicsLayerGeometry( 958 void CompositedLayerMapping::updateGraphicsLayerGeometry(
961 const PaintLayer* compositingContainer, 959 const PaintLayer* compositingContainer,
962 const PaintLayer* compositingStackingContext, 960 const PaintLayer* compositingStackingContext,
963 Vector<PaintLayer*>& layersNeedingPaintInvalidation) { 961 Vector<PaintLayer*>& layersNeedingPaintInvalidation) {
964 ASSERT(m_owningLayer.compositor()->lifecycle().state() == 962 ASSERT(m_owningLayer.compositor()->lifecycle().state() ==
965 DocumentLifecycle::InCompositingUpdate); 963 DocumentLifecycle::InCompositingUpdate);
966 964
967 // Set transform property, if it is not animating. We have to do this here 965 // Set transform property, if it is not animating. We have to do this here
968 // because the transform is affected by the layer dimensions. 966 // because the transform is affected by the layer dimensions.
969 if (!layoutObject()->style()->isRunningTransformAnimationOnCompositor()) 967 if (!layoutObject().style()->isRunningTransformAnimationOnCompositor())
970 updateTransform(layoutObject()->styleRef()); 968 updateTransform(layoutObject().styleRef());
971 969
972 // Set opacity, if it is not animating. 970 // Set opacity, if it is not animating.
973 if (!layoutObject()->style()->isRunningOpacityAnimationOnCompositor()) 971 if (!layoutObject().style()->isRunningOpacityAnimationOnCompositor())
974 updateOpacity(layoutObject()->styleRef()); 972 updateOpacity(layoutObject().styleRef());
975 973
976 if (!layoutObject()->style()->isRunningFilterAnimationOnCompositor()) 974 if (!layoutObject().style()->isRunningFilterAnimationOnCompositor())
977 updateFilters(layoutObject()->styleRef()); 975 updateFilters(layoutObject().styleRef());
978 976
979 if (!layoutObject()->style()->isRunningBackdropFilterAnimationOnCompositor()) 977 if (!layoutObject().style()->isRunningBackdropFilterAnimationOnCompositor())
980 updateBackdropFilters(layoutObject()->styleRef()); 978 updateBackdropFilters(layoutObject().styleRef());
981 979
982 // We compute everything relative to the enclosing compositing layer. 980 // We compute everything relative to the enclosing compositing layer.
983 IntRect ancestorCompositingBounds; 981 IntRect ancestorCompositingBounds;
984 if (compositingContainer) { 982 if (compositingContainer) {
985 ASSERT(compositingContainer->hasCompositedLayerMapping()); 983 ASSERT(compositingContainer->hasCompositedLayerMapping());
986 ancestorCompositingBounds = compositingContainer->compositedLayerMapping() 984 ancestorCompositingBounds = compositingContainer->compositedLayerMapping()
987 ->pixelSnappedCompositedBounds(); 985 ->pixelSnappedCompositedBounds();
988 } 986 }
989 987
990 IntRect localCompositingBounds; 988 IntRect localCompositingBounds;
(...skipping 17 matching lines...) Expand all
1008 FloatSize contentsSize(relativeCompositingBounds.size()); 1006 FloatSize contentsSize(relativeCompositingBounds.size());
1009 1007
1010 updateMainGraphicsLayerGeometry(relativeCompositingBounds, 1008 updateMainGraphicsLayerGeometry(relativeCompositingBounds,
1011 localCompositingBounds, 1009 localCompositingBounds,
1012 graphicsLayerParentLocation); 1010 graphicsLayerParentLocation);
1013 updateOverflowControlsHostLayerGeometry(compositingStackingContext, 1011 updateOverflowControlsHostLayerGeometry(compositingStackingContext,
1014 compositingContainer, 1012 compositingContainer,
1015 graphicsLayerParentLocation); 1013 graphicsLayerParentLocation);
1016 updateContentsOffsetInCompositingLayer(snappedOffsetFromCompositedAncestor, 1014 updateContentsOffsetInCompositingLayer(snappedOffsetFromCompositedAncestor,
1017 graphicsLayerParentLocation); 1015 graphicsLayerParentLocation);
1018 updateStickyConstraints(layoutObject()->styleRef()); 1016 updateStickyConstraints(layoutObject().styleRef());
1019 updateSquashingLayerGeometry( 1017 updateSquashingLayerGeometry(
1020 graphicsLayerParentLocation, compositingContainer, m_squashedLayers, 1018 graphicsLayerParentLocation, compositingContainer, m_squashedLayers,
1021 m_squashingLayer.get(), &m_squashingLayerOffsetFromTransformedAncestor, 1019 m_squashingLayer.get(), &m_squashingLayerOffsetFromTransformedAncestor,
1022 layersNeedingPaintInvalidation); 1020 layersNeedingPaintInvalidation);
1023 1021
1024 // If we have a layer that clips children, position it. 1022 // If we have a layer that clips children, position it.
1025 IntRect clippingBox; 1023 IntRect clippingBox;
1026 if (m_childContainmentLayer && layoutObject()->isBox()) 1024 if (m_childContainmentLayer && layoutObject().isBox())
1027 clippingBox = clipBox(toLayoutBox(layoutObject())); 1025 clippingBox = clipBox(toLayoutBox(layoutObject()));
1028 1026
1029 updateChildTransformLayerGeometry(); 1027 updateChildTransformLayerGeometry();
1030 updateChildContainmentLayerGeometry(clippingBox, localCompositingBounds); 1028 updateChildContainmentLayerGeometry(clippingBox, localCompositingBounds);
1031 1029
1032 updateMaskLayerGeometry(); 1030 updateMaskLayerGeometry();
1033 updateTransformGeometry(snappedOffsetFromCompositedAncestor, 1031 updateTransformGeometry(snappedOffsetFromCompositedAncestor,
1034 relativeCompositingBounds); 1032 relativeCompositingBounds);
1035 updateForegroundLayerGeometry(contentsSize, clippingBox); 1033 updateForegroundLayerGeometry(contentsSize, clippingBox);
1036 updateBackgroundLayerGeometry(contentsSize); 1034 updateBackgroundLayerGeometry(contentsSize);
1037 // TODO(yigu): Currently the decoration layer uses the same contentSize 1035 // TODO(yigu): Currently the decoration layer uses the same contentSize
1038 // as background layer and foreground layer. There are scenarios that 1036 // as background layer and foreground layer. There are scenarios that
1039 // the sizes could be different. The actual size of the decoration layer 1037 // the sizes could be different. The actual size of the decoration layer
1040 // should be calculated separately. 1038 // should be calculated separately.
1041 // The size of the background layer should be different as well. We need to 1039 // The size of the background layer should be different as well. We need to
1042 // check whether we are painting the decoration layer into the background and 1040 // check whether we are painting the decoration layer into the background and
1043 // then ignore or consider the outline when determining the contentSize. 1041 // then ignore or consider the outline when determining the contentSize.
1044 updateDecorationOutlineLayerGeometry(contentsSize); 1042 updateDecorationOutlineLayerGeometry(contentsSize);
1045 updateScrollingLayerGeometry(localCompositingBounds); 1043 updateScrollingLayerGeometry(localCompositingBounds);
1046 updateChildClippingMaskLayerGeometry(); 1044 updateChildClippingMaskLayerGeometry();
1047 1045
1048 if (m_owningLayer.getScrollableArea() && 1046 if (m_owningLayer.getScrollableArea() &&
1049 m_owningLayer.getScrollableArea()->scrollsOverflow()) 1047 m_owningLayer.getScrollableArea()->scrollsOverflow())
1050 m_owningLayer.getScrollableArea()->positionOverflowControls(); 1048 m_owningLayer.getScrollableArea()->positionOverflowControls();
1051 1049
1052 updateLayerBlendMode(layoutObject()->styleRef()); 1050 updateLayerBlendMode(layoutObject().styleRef());
1053 updateIsRootForIsolatedGroup(); 1051 updateIsRootForIsolatedGroup();
1054 updateContentsRect(); 1052 updateContentsRect();
1055 updateBackgroundColor(); 1053 updateBackgroundColor();
1056 updateDrawsContent(); 1054 updateDrawsContent();
1057 updateElementIdAndCompositorMutableProperties(); 1055 updateElementIdAndCompositorMutableProperties();
1058 updateBackgroundPaintsOntoScrollingContentsLayer(); 1056 updateBackgroundPaintsOntoScrollingContentsLayer();
1059 updateContentsOpaque(); 1057 updateContentsOpaque();
1060 updateAfterPartResize(); 1058 updateAfterPartResize();
1061 updateRenderingContext(); 1059 updateRenderingContext();
1062 updateShouldFlattenTransform(); 1060 updateShouldFlattenTransform();
(...skipping 20 matching lines...) Expand all
1083 1081
1084 // m_graphicsLayer is the corresponding GraphicsLayer for this PaintLayer and 1082 // m_graphicsLayer is the corresponding GraphicsLayer for this PaintLayer and
1085 // its non-compositing descendants. So, the visibility flag for 1083 // its non-compositing descendants. So, the visibility flag for
1086 // m_graphicsLayer should be true if there are any non-compositing visible 1084 // m_graphicsLayer should be true if there are any non-compositing visible
1087 // layers. 1085 // layers.
1088 bool contentsVisible = m_owningLayer.hasVisibleContent() || 1086 bool contentsVisible = m_owningLayer.hasVisibleContent() ||
1089 hasVisibleNonCompositingDescendant(&m_owningLayer); 1087 hasVisibleNonCompositingDescendant(&m_owningLayer);
1090 m_graphicsLayer->setContentsVisible(contentsVisible); 1088 m_graphicsLayer->setContentsVisible(contentsVisible);
1091 1089
1092 m_graphicsLayer->setBackfaceVisibility( 1090 m_graphicsLayer->setBackfaceVisibility(
1093 layoutObject()->style()->backfaceVisibility() == 1091 layoutObject().style()->backfaceVisibility() ==
1094 BackfaceVisibilityVisible); 1092 BackfaceVisibilityVisible);
1095 } 1093 }
1096 1094
1097 void CompositedLayerMapping::computeGraphicsLayerParentLocation( 1095 void CompositedLayerMapping::computeGraphicsLayerParentLocation(
1098 const PaintLayer* compositingContainer, 1096 const PaintLayer* compositingContainer,
1099 const IntRect& ancestorCompositingBounds, 1097 const IntRect& ancestorCompositingBounds,
1100 IntPoint& graphicsLayerParentLocation) { 1098 IntPoint& graphicsLayerParentLocation) {
1101 if (compositingContainer && 1099 if (compositingContainer &&
1102 compositingContainer->compositedLayerMapping()->hasClippingLayer() && 1100 compositingContainer->compositedLayerMapping()->hasClippingLayer() &&
1103 compositingContainer->layoutObject()->isBox()) { 1101 compositingContainer->layoutObject().isBox()) {
1104 // If the compositing ancestor has a layer to clip children, we parent in 1102 // If the compositing ancestor has a layer to clip children, we parent in
1105 // that, and therefore position relative to it. 1103 // that, and therefore position relative to it.
1106 IntRect clippingBox = 1104 IntRect clippingBox =
1107 clipBox(toLayoutBox(compositingContainer->layoutObject())); 1105 clipBox(toLayoutBox(compositingContainer->layoutObject()));
1108 graphicsLayerParentLocation = 1106 graphicsLayerParentLocation =
1109 clippingBox.location() + 1107 clippingBox.location() +
1110 roundedIntSize(compositingContainer->subpixelAccumulation()); 1108 roundedIntSize(compositingContainer->subpixelAccumulation());
1111 } else if (compositingContainer && 1109 } else if (compositingContainer &&
1112 compositingContainer->compositedLayerMapping() 1110 compositingContainer->compositedLayerMapping()
1113 ->childTransformLayer()) { 1111 ->childTransformLayer()) {
1114 // Similarly, if the compositing ancestor has a child transform layer, we 1112 // Similarly, if the compositing ancestor has a child transform layer, we
1115 // parent in that, and therefore position relative to it. It's already taken 1113 // parent in that, and therefore position relative to it. It's already taken
1116 // into account the contents offset, so we do not need to here. 1114 // into account the contents offset, so we do not need to here.
1117 graphicsLayerParentLocation = 1115 graphicsLayerParentLocation =
1118 roundedIntPoint(compositingContainer->subpixelAccumulation()); 1116 roundedIntPoint(compositingContainer->subpixelAccumulation());
1119 } else if (compositingContainer) { 1117 } else if (compositingContainer) {
1120 graphicsLayerParentLocation = ancestorCompositingBounds.location(); 1118 graphicsLayerParentLocation = ancestorCompositingBounds.location();
1121 } else { 1119 } else {
1122 graphicsLayerParentLocation = 1120 graphicsLayerParentLocation =
1123 layoutObject()->view()->documentRect().location(); 1121 layoutObject().view()->documentRect().location();
1124 } 1122 }
1125 1123
1126 if (compositingContainer && 1124 if (compositingContainer &&
1127 compositingContainer->needsCompositedScrolling()) { 1125 compositingContainer->needsCompositedScrolling()) {
1128 LayoutBox* layoutBox = toLayoutBox(compositingContainer->layoutObject()); 1126 LayoutBox& layoutBox = toLayoutBox(compositingContainer->layoutObject());
1129 IntSize scrollOffset = layoutBox->scrolledContentOffset(); 1127 IntSize scrollOffset = layoutBox.scrolledContentOffset();
1130 IntPoint scrollOrigin = 1128 IntPoint scrollOrigin =
1131 compositingContainer->getScrollableArea()->scrollOrigin(); 1129 compositingContainer->getScrollableArea()->scrollOrigin();
1132 scrollOrigin.move(-layoutBox->borderLeft().toInt(), 1130 scrollOrigin.move(-layoutBox.borderLeft().toInt(),
1133 -layoutBox->borderTop().toInt()); 1131 -layoutBox.borderTop().toInt());
1134 graphicsLayerParentLocation = -(scrollOrigin + scrollOffset); 1132 graphicsLayerParentLocation = -(scrollOrigin + scrollOffset);
1135 } 1133 }
1136 } 1134 }
1137 1135
1138 void CompositedLayerMapping::updateAncestorClippingLayerGeometry( 1136 void CompositedLayerMapping::updateAncestorClippingLayerGeometry(
1139 const PaintLayer* compositingContainer, 1137 const PaintLayer* compositingContainer,
1140 const IntPoint& snappedOffsetFromCompositedAncestor, 1138 const IntPoint& snappedOffsetFromCompositedAncestor,
1141 IntPoint& graphicsLayerParentLocation) { 1139 IntPoint& graphicsLayerParentLocation) {
1142 if (!compositingContainer || !m_ancestorClippingLayer) 1140 if (!compositingContainer || !m_ancestorClippingLayer)
1143 return; 1141 return;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1218 } 1216 }
1219 1217
1220 m_overflowControlsAncestorClippingLayer->setPosition(position); 1218 m_overflowControlsAncestorClippingLayer->setPosition(position);
1221 hostLayerPosition.move( 1219 hostLayerPosition.move(
1222 -m_ancestorClippingLayer->offsetFromLayoutObject()); 1220 -m_ancestorClippingLayer->offsetFromLayoutObject());
1223 } else { 1221 } else {
1224 // The controls are in the same 2D space as the compositing container, so 1222 // The controls are in the same 2D space as the compositing container, so
1225 // we can map them into the space of the container. 1223 // we can map them into the space of the container.
1226 TransformState transformState(TransformState::ApplyTransformDirection, 1224 TransformState transformState(TransformState::ApplyTransformDirection,
1227 FloatPoint()); 1225 FloatPoint());
1228 m_owningLayer.layoutObject()->mapLocalToAncestor( 1226 m_owningLayer.layoutObject().mapLocalToAncestor(
1229 compositingStackingContext->layoutObject(), transformState, 1227 &compositingStackingContext->layoutObject(), transformState,
1230 ApplyContainerFlip); 1228 ApplyContainerFlip);
1231 transformState.flatten(); 1229 transformState.flatten();
1232 hostLayerPosition = LayoutPoint(transformState.lastPlanarPoint()); 1230 hostLayerPosition = LayoutPoint(transformState.lastPlanarPoint());
1233 if (PaintLayerScrollableArea* scrollableArea = 1231 if (PaintLayerScrollableArea* scrollableArea =
1234 compositingStackingContext->getScrollableArea()) { 1232 compositingStackingContext->getScrollableArea()) {
1235 hostLayerPosition.move( 1233 hostLayerPosition.move(
1236 LayoutSize(toFloatSize(scrollableArea->scrollPosition()))); 1234 LayoutSize(toFloatSize(scrollableArea->scrollPosition())));
1237 } 1235 }
1238 hostLayerPosition.move(-stackingOffsetFromLayoutObject); 1236 hostLayerPosition.move(-stackingOffsetFromLayoutObject);
1239 } 1237 }
1240 } else { 1238 } else {
1241 hostLayerPosition.move(-m_graphicsLayer->offsetFromLayoutObject()); 1239 hostLayerPosition.move(-m_graphicsLayer->offsetFromLayoutObject());
1242 } 1240 }
1243 1241
1244 m_overflowControlsHostLayer->setPosition(FloatPoint(hostLayerPosition)); 1242 m_overflowControlsHostLayer->setPosition(FloatPoint(hostLayerPosition));
1245 1243
1246 const IntRect borderBox = 1244 const IntRect borderBox =
1247 toLayoutBox(m_owningLayer.layoutObject())->pixelSnappedBorderBoxRect(); 1245 toLayoutBox(m_owningLayer.layoutObject()).pixelSnappedBorderBoxRect();
1248 m_overflowControlsHostLayer->setSize(FloatSize(borderBox.size())); 1246 m_overflowControlsHostLayer->setSize(FloatSize(borderBox.size()));
1249 m_overflowControlsHostLayer->setMasksToBounds(true); 1247 m_overflowControlsHostLayer->setMasksToBounds(true);
1250 } 1248 }
1251 1249
1252 void CompositedLayerMapping::updateChildContainmentLayerGeometry( 1250 void CompositedLayerMapping::updateChildContainmentLayerGeometry(
1253 const IntRect& clippingBox, 1251 const IntRect& clippingBox,
1254 const IntRect& localCompositingBounds) { 1252 const IntRect& localCompositingBounds) {
1255 if (!m_childContainmentLayer) 1253 if (!m_childContainmentLayer)
1256 return; 1254 return;
1257 1255
1258 FloatPoint clipPositionInLayoutObjectSpace( 1256 FloatPoint clipPositionInLayoutObjectSpace(
1259 clippingBox.location() - localCompositingBounds.location() + 1257 clippingBox.location() - localCompositingBounds.location() +
1260 roundedIntSize(m_owningLayer.subpixelAccumulation())); 1258 roundedIntSize(m_owningLayer.subpixelAccumulation()));
1261 1259
1262 // If there are layers between the the child containment layer and 1260 // If there are layers between the the child containment layer and
1263 // m_graphicsLayer (eg, the child transform layer), we must adjust the clip 1261 // m_graphicsLayer (eg, the child transform layer), we must adjust the clip
1264 // position to get it in the correct space. 1262 // position to get it in the correct space.
1265 FloatPoint clipPositionInParentSpace = clipPositionInLayoutObjectSpace; 1263 FloatPoint clipPositionInParentSpace = clipPositionInLayoutObjectSpace;
1266 for (GraphicsLayer* ancestor = m_childContainmentLayer->parent(); 1264 for (GraphicsLayer* ancestor = m_childContainmentLayer->parent();
1267 ancestor != mainGraphicsLayer(); ancestor = ancestor->parent()) 1265 ancestor != mainGraphicsLayer(); ancestor = ancestor->parent())
1268 clipPositionInParentSpace -= toFloatSize(ancestor->position()); 1266 clipPositionInParentSpace -= toFloatSize(ancestor->position());
1269 1267
1270 m_childContainmentLayer->setPosition(clipPositionInParentSpace); 1268 m_childContainmentLayer->setPosition(clipPositionInParentSpace);
1271 m_childContainmentLayer->setSize(FloatSize(clippingBox.size())); 1269 m_childContainmentLayer->setSize(FloatSize(clippingBox.size()));
1272 m_childContainmentLayer->setOffsetFromLayoutObject( 1270 m_childContainmentLayer->setOffsetFromLayoutObject(
1273 toIntSize(clippingBox.location())); 1271 toIntSize(clippingBox.location()));
1274 if (m_childClippingMaskLayer && !m_scrollingLayer && 1272 if (m_childClippingMaskLayer && !m_scrollingLayer &&
1275 !layoutObject()->style()->clipPath()) { 1273 !layoutObject().style()->clipPath()) {
1276 m_childClippingMaskLayer->setSize(m_childContainmentLayer->size()); 1274 m_childClippingMaskLayer->setSize(m_childContainmentLayer->size());
1277 m_childClippingMaskLayer->setOffsetFromLayoutObject( 1275 m_childClippingMaskLayer->setOffsetFromLayoutObject(
1278 m_childContainmentLayer->offsetFromLayoutObject()); 1276 m_childContainmentLayer->offsetFromLayoutObject());
1279 } 1277 }
1280 } 1278 }
1281 1279
1282 void CompositedLayerMapping::updateChildTransformLayerGeometry() { 1280 void CompositedLayerMapping::updateChildTransformLayerGeometry() {
1283 if (!m_childTransformLayer) 1281 if (!m_childTransformLayer)
1284 return; 1282 return;
1285 const IntRect borderBox = 1283 const IntRect borderBox =
1286 toLayoutBox(m_owningLayer.layoutObject())->pixelSnappedBorderBoxRect(); 1284 toLayoutBox(m_owningLayer.layoutObject()).pixelSnappedBorderBoxRect();
1287 m_childTransformLayer->setSize(FloatSize(borderBox.size())); 1285 m_childTransformLayer->setSize(FloatSize(borderBox.size()));
1288 m_childTransformLayer->setPosition( 1286 m_childTransformLayer->setPosition(
1289 FloatPoint(contentOffsetInCompositingLayer())); 1287 FloatPoint(contentOffsetInCompositingLayer()));
1290 } 1288 }
1291 1289
1292 void CompositedLayerMapping::updateMaskLayerGeometry() { 1290 void CompositedLayerMapping::updateMaskLayerGeometry() {
1293 if (!m_maskLayer) 1291 if (!m_maskLayer)
1294 return; 1292 return;
1295 1293
1296 if (m_maskLayer->size() != m_graphicsLayer->size()) { 1294 if (m_maskLayer->size() != m_graphicsLayer->size()) {
1297 m_maskLayer->setSize(m_graphicsLayer->size()); 1295 m_maskLayer->setSize(m_graphicsLayer->size());
1298 m_maskLayer->setNeedsDisplay(); 1296 m_maskLayer->setNeedsDisplay();
1299 } 1297 }
1300 m_maskLayer->setPosition(FloatPoint()); 1298 m_maskLayer->setPosition(FloatPoint());
1301 m_maskLayer->setOffsetFromLayoutObject( 1299 m_maskLayer->setOffsetFromLayoutObject(
1302 m_graphicsLayer->offsetFromLayoutObject()); 1300 m_graphicsLayer->offsetFromLayoutObject());
1303 } 1301 }
1304 1302
1305 void CompositedLayerMapping::updateTransformGeometry( 1303 void CompositedLayerMapping::updateTransformGeometry(
1306 const IntPoint& snappedOffsetFromCompositedAncestor, 1304 const IntPoint& snappedOffsetFromCompositedAncestor,
1307 const IntRect& relativeCompositingBounds) { 1305 const IntRect& relativeCompositingBounds) {
1308 if (m_owningLayer.hasTransformRelatedProperty()) { 1306 if (m_owningLayer.hasTransformRelatedProperty()) {
1309 const LayoutRect borderBox = toLayoutBox(layoutObject())->borderBoxRect(); 1307 const LayoutRect borderBox = toLayoutBox(layoutObject()).borderBoxRect();
1310 1308
1311 // Get layout bounds in the coords of compositingContainer to match 1309 // Get layout bounds in the coords of compositingContainer to match
1312 // relativeCompositingBounds. 1310 // relativeCompositingBounds.
1313 IntRect layerBounds = pixelSnappedIntRect( 1311 IntRect layerBounds = pixelSnappedIntRect(
1314 toLayoutPoint(m_owningLayer.subpixelAccumulation()), borderBox.size()); 1312 toLayoutPoint(m_owningLayer.subpixelAccumulation()), borderBox.size());
1315 layerBounds.moveBy(snappedOffsetFromCompositedAncestor); 1313 layerBounds.moveBy(snappedOffsetFromCompositedAncestor);
1316 1314
1317 // Update properties that depend on layer dimensions 1315 // Update properties that depend on layer dimensions
1318 FloatPoint3D transformOrigin = 1316 FloatPoint3D transformOrigin =
1319 computeTransformOrigin(IntRect(IntPoint(), layerBounds.size())); 1317 computeTransformOrigin(IntRect(IntPoint(), layerBounds.size()));
(...skipping 14 matching lines...) Expand all
1334 m_graphicsLayer->setTransformOrigin(compositedTransformOrigin); 1332 m_graphicsLayer->setTransformOrigin(compositedTransformOrigin);
1335 } 1333 }
1336 } 1334 }
1337 1335
1338 void CompositedLayerMapping::updateScrollingLayerGeometry( 1336 void CompositedLayerMapping::updateScrollingLayerGeometry(
1339 const IntRect& localCompositingBounds) { 1337 const IntRect& localCompositingBounds) {
1340 if (!m_scrollingLayer) 1338 if (!m_scrollingLayer)
1341 return; 1339 return;
1342 1340
1343 ASSERT(m_scrollingContentsLayer); 1341 ASSERT(m_scrollingContentsLayer);
1344 LayoutBox* layoutBox = toLayoutBox(layoutObject()); 1342 LayoutBox& layoutBox = toLayoutBox(layoutObject());
1345 IntRect overflowClipRect = 1343 IntRect overflowClipRect =
1346 pixelSnappedIntRect(layoutBox->overflowClipRect(LayoutPoint())); 1344 pixelSnappedIntRect(layoutBox.overflowClipRect(LayoutPoint()));
1347 1345
1348 const TopDocumentRootScrollerController& globalRootScrollerController = 1346 const TopDocumentRootScrollerController& globalRootScrollerController =
1349 layoutBox->document().frameHost()->globalRootScrollerController(); 1347 layoutBox.document().frameHost()->globalRootScrollerController();
1350 1348
1351 if (&m_owningLayer == globalRootScrollerController.rootScrollerPaintLayer()) { 1349 if (&m_owningLayer == globalRootScrollerController.rootScrollerPaintLayer()) {
1352 LayoutRect clipRect = 1350 LayoutRect clipRect =
1353 layoutBox->document().layoutView()->overflowClipRect(LayoutPoint()); 1351 layoutBox.document().layoutView()->overflowClipRect(LayoutPoint());
1354 DCHECK(clipRect.size() == LayoutSize(pixelSnappedIntRect(clipRect).size())); 1352 DCHECK(clipRect.size() == LayoutSize(pixelSnappedIntRect(clipRect).size()));
1355 overflowClipRect.setSize(pixelSnappedIntRect(clipRect).size()); 1353 overflowClipRect.setSize(pixelSnappedIntRect(clipRect).size());
1356 } 1354 }
1357 1355
1358 // When a m_childTransformLayer exists, local content offsets for the 1356 // When a m_childTransformLayer exists, local content offsets for the
1359 // m_scrollingLayer have already been applied. Otherwise, we apply them here. 1357 // m_scrollingLayer have already been applied. Otherwise, we apply them here.
1360 IntSize localContentOffset(0, 0); 1358 IntSize localContentOffset(0, 0);
1361 if (!m_childTransformLayer) { 1359 if (!m_childTransformLayer) {
1362 localContentOffset = roundedIntPoint(m_owningLayer.subpixelAccumulation()) - 1360 localContentOffset = roundedIntPoint(m_owningLayer.subpixelAccumulation()) -
1363 localCompositingBounds.location(); 1361 localCompositingBounds.location();
1364 } 1362 }
1365 m_scrollingLayer->setPosition( 1363 m_scrollingLayer->setPosition(
1366 FloatPoint(overflowClipRect.location() + localContentOffset)); 1364 FloatPoint(overflowClipRect.location() + localContentOffset));
1367 m_scrollingLayer->setSize(FloatSize(overflowClipRect.size())); 1365 m_scrollingLayer->setSize(FloatSize(overflowClipRect.size()));
1368 1366
1369 IntSize oldScrollingLayerOffset = m_scrollingLayer->offsetFromLayoutObject(); 1367 IntSize oldScrollingLayerOffset = m_scrollingLayer->offsetFromLayoutObject();
1370 m_scrollingLayer->setOffsetFromLayoutObject( 1368 m_scrollingLayer->setOffsetFromLayoutObject(
1371 -toIntSize(overflowClipRect.location())); 1369 -toIntSize(overflowClipRect.location()));
1372 1370
1373 if (m_childClippingMaskLayer && !layoutObject()->style()->clipPath()) { 1371 if (m_childClippingMaskLayer && !layoutObject().style()->clipPath()) {
1374 m_childClippingMaskLayer->setPosition(m_scrollingLayer->position()); 1372 m_childClippingMaskLayer->setPosition(m_scrollingLayer->position());
1375 m_childClippingMaskLayer->setSize(m_scrollingLayer->size()); 1373 m_childClippingMaskLayer->setSize(m_scrollingLayer->size());
1376 m_childClippingMaskLayer->setOffsetFromLayoutObject( 1374 m_childClippingMaskLayer->setOffsetFromLayoutObject(
1377 toIntSize(overflowClipRect.location())); 1375 toIntSize(overflowClipRect.location()));
1378 } 1376 }
1379 1377
1380 bool overflowClipRectOffsetChanged = 1378 bool overflowClipRectOffsetChanged =
1381 oldScrollingLayerOffset != m_scrollingLayer->offsetFromLayoutObject(); 1379 oldScrollingLayerOffset != m_scrollingLayer->offsetFromLayoutObject();
1382 1380
1383 IntSize scrollSize(layoutBox->pixelSnappedScrollWidth(), 1381 IntSize scrollSize(layoutBox.pixelSnappedScrollWidth(),
1384 layoutBox->pixelSnappedScrollHeight()); 1382 layoutBox.pixelSnappedScrollHeight());
1385 if (overflowClipRectOffsetChanged) 1383 if (overflowClipRectOffsetChanged)
1386 m_scrollingContentsLayer->setNeedsDisplay(); 1384 m_scrollingContentsLayer->setNeedsDisplay();
1387 1385
1388 FloatPoint scrollPosition = 1386 FloatPoint scrollPosition =
1389 m_owningLayer.getScrollableArea()->scrollPosition(); 1387 m_owningLayer.getScrollableArea()->scrollPosition();
1390 DoubleSize scrollingContentsOffset( 1388 DoubleSize scrollingContentsOffset(
1391 overflowClipRect.location().x() - scrollPosition.x(), 1389 overflowClipRect.location().x() - scrollPosition.x(),
1392 overflowClipRect.location().y() - scrollPosition.y()); 1390 overflowClipRect.location().y() - scrollPosition.y());
1393 // The scroll offset change is compared using floating point so that 1391 // The scroll offset change is compared using floating point so that
1394 // fractional scroll offset change can be propagated to compositor. 1392 // fractional scroll offset change can be propagated to compositor.
(...skipping 25 matching lines...) Expand all
1420 if (m_foregroundLayer) { 1418 if (m_foregroundLayer) {
1421 if (m_foregroundLayer->size() != m_scrollingContentsLayer->size()) 1419 if (m_foregroundLayer->size() != m_scrollingContentsLayer->size())
1422 m_foregroundLayer->setSize(m_scrollingContentsLayer->size()); 1420 m_foregroundLayer->setSize(m_scrollingContentsLayer->size());
1423 m_foregroundLayer->setNeedsDisplay(); 1421 m_foregroundLayer->setNeedsDisplay();
1424 m_foregroundLayer->setOffsetFromLayoutObject( 1422 m_foregroundLayer->setOffsetFromLayoutObject(
1425 m_scrollingContentsLayer->offsetFromLayoutObject()); 1423 m_scrollingContentsLayer->offsetFromLayoutObject());
1426 } 1424 }
1427 } 1425 }
1428 1426
1429 void CompositedLayerMapping::updateChildClippingMaskLayerGeometry() { 1427 void CompositedLayerMapping::updateChildClippingMaskLayerGeometry() {
1430 if (!m_childClippingMaskLayer || !layoutObject()->style()->clipPath() || 1428 if (!m_childClippingMaskLayer || !layoutObject().style()->clipPath() ||
1431 !layoutObject()->isBox()) 1429 !layoutObject().isBox())
1432 return; 1430 return;
1433 LayoutBox* layoutBox = toLayoutBox(layoutObject()); 1431 LayoutBox& layoutBox = toLayoutBox(layoutObject());
1434 IntRect clientBox = enclosingIntRect(layoutBox->clientBoxRect()); 1432 IntRect clientBox = enclosingIntRect(layoutBox.clientBoxRect());
1435 1433
1436 m_childClippingMaskLayer->setPosition(m_graphicsLayer->position()); 1434 m_childClippingMaskLayer->setPosition(m_graphicsLayer->position());
1437 m_childClippingMaskLayer->setSize(m_graphicsLayer->size()); 1435 m_childClippingMaskLayer->setSize(m_graphicsLayer->size());
1438 m_childClippingMaskLayer->setOffsetFromLayoutObject( 1436 m_childClippingMaskLayer->setOffsetFromLayoutObject(
1439 toIntSize(clientBox.location())); 1437 toIntSize(clientBox.location()));
1440 1438
1441 // NOTE: also some stuff happening in updateChildContainmentLayerGeometry(). 1439 // NOTE: also some stuff happening in updateChildContainmentLayerGeometry().
1442 } 1440 }
1443 1441
1444 void CompositedLayerMapping::updateForegroundLayerGeometry( 1442 void CompositedLayerMapping::updateForegroundLayerGeometry(
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1478 // updateScrollingLayerGeometry(). 1476 // updateScrollingLayerGeometry().
1479 } 1477 }
1480 1478
1481 void CompositedLayerMapping::updateBackgroundLayerGeometry( 1479 void CompositedLayerMapping::updateBackgroundLayerGeometry(
1482 const FloatSize& relativeCompositingBoundsSize) { 1480 const FloatSize& relativeCompositingBoundsSize) {
1483 if (!m_backgroundLayer) 1481 if (!m_backgroundLayer)
1484 return; 1482 return;
1485 1483
1486 FloatSize backgroundSize = relativeCompositingBoundsSize; 1484 FloatSize backgroundSize = relativeCompositingBoundsSize;
1487 if (backgroundLayerPaintsFixedRootBackground()) { 1485 if (backgroundLayerPaintsFixedRootBackground()) {
1488 FrameView* frameView = toLayoutView(layoutObject())->frameView(); 1486 FrameView* frameView = toLayoutView(layoutObject()).frameView();
1489 backgroundSize = FloatSize(frameView->visibleContentRect().size()); 1487 backgroundSize = FloatSize(frameView->visibleContentRect().size());
1490 } 1488 }
1491 m_backgroundLayer->setPosition(FloatPoint()); 1489 m_backgroundLayer->setPosition(FloatPoint());
1492 if (backgroundSize != m_backgroundLayer->size()) { 1490 if (backgroundSize != m_backgroundLayer->size()) {
1493 m_backgroundLayer->setSize(backgroundSize); 1491 m_backgroundLayer->setSize(backgroundSize);
1494 m_backgroundLayer->setNeedsDisplay(); 1492 m_backgroundLayer->setNeedsDisplay();
1495 } 1493 }
1496 m_backgroundLayer->setOffsetFromLayoutObject( 1494 m_backgroundLayer->setOffsetFromLayoutObject(
1497 m_graphicsLayer->offsetFromLayoutObject()); 1495 m_graphicsLayer->offsetFromLayoutObject());
1498 } 1496 }
(...skipping 19 matching lines...) Expand all
1518 scrollingCoordinatorFromLayer(m_owningLayer); 1516 scrollingCoordinatorFromLayer(m_owningLayer);
1519 if (!scrollingCoordinator) 1517 if (!scrollingCoordinator)
1520 return; 1518 return;
1521 1519
1522 scrollingCoordinator->updateLayerPositionConstraint(&m_owningLayer); 1520 scrollingCoordinator->updateLayerPositionConstraint(&m_owningLayer);
1523 1521
1524 // Page scale is applied as a transform on the root layout view layer. Because 1522 // Page scale is applied as a transform on the root layout view layer. Because
1525 // the scroll layer is further up in the hierarchy, we need to avoid marking 1523 // the scroll layer is further up in the hierarchy, we need to avoid marking
1526 // the root layout view layer as a container. 1524 // the root layout view layer as a container.
1527 bool isContainer = 1525 bool isContainer =
1528 m_owningLayer.layoutObject()->style()->canContainFixedPositionObjects() && 1526 m_owningLayer.layoutObject().style()->canContainFixedPositionObjects() &&
1529 !m_owningLayer.isRootLayer(); 1527 !m_owningLayer.isRootLayer();
1530 scrollingCoordinator->setLayerIsContainerForFixedPositionLayers( 1528 scrollingCoordinator->setLayerIsContainerForFixedPositionLayers(
1531 m_graphicsLayer.get(), isContainer); 1529 m_graphicsLayer.get(), isContainer);
1532 } 1530 }
1533 1531
1534 void CompositedLayerMapping::updateInternalHierarchy() { 1532 void CompositedLayerMapping::updateInternalHierarchy() {
1535 // m_foregroundLayer has to be inserted in the correct order with child 1533 // m_foregroundLayer has to be inserted in the correct order with child
1536 // layers, so it's not inserted here. 1534 // layers, so it's not inserted here.
1537 if (m_ancestorClippingLayer) 1535 if (m_ancestorClippingLayer)
1538 m_ancestorClippingLayer->removeAllChildren(); 1536 m_ancestorClippingLayer->removeAllChildren();
(...skipping 16 matching lines...) Expand all
1555 updateBottomLayer(m_childContainmentLayer.get()); 1553 updateBottomLayer(m_childContainmentLayer.get());
1556 updateBottomLayer(m_scrollingLayer.get()); 1554 updateBottomLayer(m_scrollingLayer.get());
1557 1555
1558 // Now constructing the subtree for the overflow controls. 1556 // Now constructing the subtree for the overflow controls.
1559 bottomLayer = m_graphicsLayer.get(); 1557 bottomLayer = m_graphicsLayer.get();
1560 // TODO(pdr): Ensure painting uses the correct GraphicsLayer when root layer 1558 // TODO(pdr): Ensure painting uses the correct GraphicsLayer when root layer
1561 // scrolls is enabled. crbug.com/638719 1559 // scrolls is enabled. crbug.com/638719
1562 if (m_isMainFrameLayoutViewLayer && 1560 if (m_isMainFrameLayoutViewLayer &&
1563 !RuntimeEnabledFeatures::slimmingPaintV2Enabled()) 1561 !RuntimeEnabledFeatures::slimmingPaintV2Enabled())
1564 bottomLayer = layoutObject() 1562 bottomLayer = layoutObject()
1565 ->frame() 1563 .frame()
1566 ->page() 1564 ->page()
1567 ->frameHost() 1565 ->frameHost()
1568 .visualViewport() 1566 .visualViewport()
1569 .containerLayer(); 1567 .containerLayer();
1570 updateBottomLayer(m_overflowControlsAncestorClippingLayer.get()); 1568 updateBottomLayer(m_overflowControlsAncestorClippingLayer.get());
1571 updateBottomLayer(m_overflowControlsHostLayer.get()); 1569 updateBottomLayer(m_overflowControlsHostLayer.get());
1572 if (m_layerForHorizontalScrollbar) 1570 if (m_layerForHorizontalScrollbar)
1573 m_overflowControlsHostLayer->addChild(m_layerForHorizontalScrollbar.get()); 1571 m_overflowControlsHostLayer->addChild(m_layerForHorizontalScrollbar.get());
1574 if (m_layerForVerticalScrollbar) 1572 if (m_layerForVerticalScrollbar)
1575 m_overflowControlsHostLayer->addChild(m_layerForVerticalScrollbar.get()); 1573 m_overflowControlsHostLayer->addChild(m_layerForVerticalScrollbar.get());
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1664 // graphicsLayerParentLocation it appears). 1662 // graphicsLayerParentLocation it appears).
1665 FloatPoint offsetDueToAncestorGraphicsLayers = 1663 FloatPoint offsetDueToAncestorGraphicsLayers =
1666 m_graphicsLayer->position() + graphicsLayerParentLocation; 1664 m_graphicsLayer->position() + graphicsLayerParentLocation;
1667 m_contentOffsetInCompositingLayer = LayoutSize( 1665 m_contentOffsetInCompositingLayer = LayoutSize(
1668 snappedOffsetFromCompositedAncestor - offsetDueToAncestorGraphicsLayers); 1666 snappedOffsetFromCompositedAncestor - offsetDueToAncestorGraphicsLayers);
1669 m_contentOffsetInCompositingLayerDirty = false; 1667 m_contentOffsetInCompositingLayerDirty = false;
1670 } 1668 }
1671 1669
1672 void CompositedLayerMapping::updateDrawsContent() { 1670 void CompositedLayerMapping::updateDrawsContent() {
1673 bool inOverlayFullscreenVideo = false; 1671 bool inOverlayFullscreenVideo = false;
1674 if (layoutObject()->isVideo()) { 1672 if (layoutObject().isVideo()) {
1675 HTMLVideoElement* videoElement = toHTMLVideoElement(layoutObject()->node()); 1673 HTMLVideoElement* videoElement = toHTMLVideoElement(layoutObject().node());
1676 if (videoElement->isFullscreen() && 1674 if (videoElement->isFullscreen() &&
1677 videoElement->usesOverlayFullscreenVideo()) 1675 videoElement->usesOverlayFullscreenVideo())
1678 inOverlayFullscreenVideo = true; 1676 inOverlayFullscreenVideo = true;
1679 } 1677 }
1680 bool hasPaintedContent = 1678 bool hasPaintedContent =
1681 inOverlayFullscreenVideo ? false : containsPaintedContent(); 1679 inOverlayFullscreenVideo ? false : containsPaintedContent();
1682 m_graphicsLayer->setDrawsContent(hasPaintedContent); 1680 m_graphicsLayer->setDrawsContent(hasPaintedContent);
1683 1681
1684 if (m_scrollingLayer) { 1682 if (m_scrollingLayer) {
1685 // m_scrollingLayer never has backing store. 1683 // m_scrollingLayer never has backing store.
1686 // m_scrollingContentsLayer only needs backing store if the scrolled 1684 // m_scrollingContentsLayer only needs backing store if the scrolled
1687 // contents need to paint. 1685 // contents need to paint.
1688 m_scrollingContentsAreEmpty = 1686 m_scrollingContentsAreEmpty =
1689 !m_owningLayer.hasVisibleContent() || 1687 !m_owningLayer.hasVisibleContent() ||
1690 !(layoutObject()->styleRef().hasBackground() || 1688 !(layoutObject().styleRef().hasBackground() ||
1691 layoutObject()->hasBackdropFilter() || paintsChildren()); 1689 layoutObject().hasBackdropFilter() || paintsChildren());
1692 m_scrollingContentsLayer->setDrawsContent(!m_scrollingContentsAreEmpty); 1690 m_scrollingContentsLayer->setDrawsContent(!m_scrollingContentsAreEmpty);
1693 } 1691 }
1694 1692
1695 m_drawsBackgroundOntoContentLayer = false; 1693 m_drawsBackgroundOntoContentLayer = false;
1696 1694
1697 if (hasPaintedContent && isAcceleratedCanvas(layoutObject())) { 1695 if (hasPaintedContent && isAcceleratedCanvas(layoutObject())) {
1698 CanvasRenderingContext* context = 1696 CanvasRenderingContext* context =
1699 toHTMLCanvasElement(layoutObject()->node())->renderingContext(); 1697 toHTMLCanvasElement(layoutObject().node())->renderingContext();
1700 // Content layer may be null if context is lost. 1698 // Content layer may be null if context is lost.
1701 if (WebLayer* contentLayer = context->platformLayer()) { 1699 if (WebLayer* contentLayer = context->platformLayer()) {
1702 Color bgColor(Color::transparent); 1700 Color bgColor(Color::transparent);
1703 if (contentLayerSupportsDirectBackgroundComposition(layoutObject())) { 1701 if (contentLayerSupportsDirectBackgroundComposition(layoutObject())) {
1704 bgColor = layoutObjectBackgroundColor(); 1702 bgColor = layoutObjectBackgroundColor();
1705 hasPaintedContent = false; 1703 hasPaintedContent = false;
1706 m_drawsBackgroundOntoContentLayer = true; 1704 m_drawsBackgroundOntoContentLayer = true;
1707 } 1705 }
1708 contentLayer->setBackgroundColor(bgColor.rgb()); 1706 contentLayer->setBackgroundColor(bgColor.rgb());
1709 } 1707 }
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
2054 // NB, it is illegal at this point to query an ancestor's compositing state. 2052 // NB, it is illegal at this point to query an ancestor's compositing state.
2055 // Some compositing reasons depend on the compositing state of ancestors. So 2053 // Some compositing reasons depend on the compositing state of ancestors. So
2056 // if we want a rendering context id for the context root, we cannot ask for 2054 // if we want a rendering context id for the context root, we cannot ask for
2057 // the id of its associated WebLayer now; it may not have one yet. We could do 2055 // the id of its associated WebLayer now; it may not have one yet. We could do
2058 // a second pass after doing the compositing updates to get these ids, but 2056 // a second pass after doing the compositing updates to get these ids, but
2059 // this would actually be harmful. We do not want to attach any semantic 2057 // this would actually be harmful. We do not want to attach any semantic
2060 // meaning to the context id other than the fact that they group a number of 2058 // meaning to the context id other than the fact that they group a number of
2061 // layers together for the sake of 3d sorting. So instead we will ask the 2059 // layers together for the sake of 3d sorting. So instead we will ask the
2062 // compositor to vend us an arbitrary, but consistent id. 2060 // compositor to vend us an arbitrary, but consistent id.
2063 if (PaintLayer* root = m_owningLayer.renderingContextRoot()) { 2061 if (PaintLayer* root = m_owningLayer.renderingContextRoot()) {
2064 if (Node* node = root->layoutObject()->node()) 2062 if (Node* node = root->layoutObject().node())
2065 id = static_cast<int>(PtrHash<Node>::hash(node)); 2063 id = static_cast<int>(PtrHash<Node>::hash(node));
2066 } 2064 }
2067 2065
2068 UpdateRenderingContextFunctor functor = {id}; 2066 UpdateRenderingContextFunctor functor = {id};
2069 ApplyToGraphicsLayers<UpdateRenderingContextFunctor>( 2067 ApplyToGraphicsLayers<UpdateRenderingContextFunctor>(
2070 this, functor, ApplyToAllGraphicsLayers); 2068 this, functor, ApplyToAllGraphicsLayers);
2071 } 2069 }
2072 2070
2073 struct UpdateShouldFlattenTransformFunctor { 2071 struct UpdateShouldFlattenTransformFunctor {
2074 void operator()(GraphicsLayer* layer) const { 2072 void operator()(GraphicsLayer* layer) const {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2116 // 2114 //
2117 // The element id for the scroll layers is assigned when they're constructed, 2115 // The element id for the scroll layers is assigned when they're constructed,
2118 // since this is unconditional. However, the element id for the primary layer as 2116 // since this is unconditional. However, the element id for the primary layer as
2119 // well as the mutable properties for all layers may change according to the 2117 // well as the mutable properties for all layers may change according to the
2120 // rules above so we update those values here. 2118 // rules above so we update those values here.
2121 void CompositedLayerMapping::updateElementIdAndCompositorMutableProperties() { 2119 void CompositedLayerMapping::updateElementIdAndCompositorMutableProperties() {
2122 int elementId = 0; 2120 int elementId = 0;
2123 uint32_t primaryMutableProperties = CompositorMutableProperty::kNone; 2121 uint32_t primaryMutableProperties = CompositorMutableProperty::kNone;
2124 uint32_t scrollMutableProperties = CompositorMutableProperty::kNone; 2122 uint32_t scrollMutableProperties = CompositorMutableProperty::kNone;
2125 2123
2126 Node* owningNode = m_owningLayer.layoutObject()->node(); 2124 Node* owningNode = m_owningLayer.layoutObject().node();
2127 Element* animatingElement = nullptr; 2125 Element* animatingElement = nullptr;
2128 const ComputedStyle* animatingStyle = nullptr; 2126 const ComputedStyle* animatingStyle = nullptr;
2129 if (owningNode) { 2127 if (owningNode) {
2130 Document& document = owningNode->document(); 2128 Document& document = owningNode->document();
2131 Element* scrollingElement = document.scrollingElementNoLayout(); 2129 Element* scrollingElement = document.scrollingElementNoLayout();
2132 if (owningNode->isElementNode() && 2130 if (owningNode->isElementNode() &&
2133 (!RuntimeEnabledFeatures::rootLayerScrollingEnabled() || 2131 (!RuntimeEnabledFeatures::rootLayerScrollingEnabled() ||
2134 owningNode != scrollingElement)) { 2132 owningNode != scrollingElement)) {
2135 animatingElement = toElement(owningNode); 2133 animatingElement = toElement(owningNode);
2136 animatingStyle = m_owningLayer.layoutObject()->style(); 2134 animatingStyle = m_owningLayer.layoutObject().style();
2137 } else if (owningNode->isDocumentNode() && 2135 } else if (owningNode->isDocumentNode() &&
2138 RuntimeEnabledFeatures::rootLayerScrollingEnabled()) { 2136 RuntimeEnabledFeatures::rootLayerScrollingEnabled()) {
2139 owningNode = animatingElement = scrollingElement; 2137 owningNode = animatingElement = scrollingElement;
2140 if (scrollingElement && scrollingElement->layoutObject()) 2138 if (scrollingElement && scrollingElement->layoutObject())
2141 animatingStyle = scrollingElement->layoutObject()->style(); 2139 animatingStyle = scrollingElement->layoutObject()->style();
2142 } 2140 }
2143 } 2141 }
2144 2142
2145 if (RuntimeEnabledFeatures::compositorWorkerEnabled() && animatingStyle && 2143 if (RuntimeEnabledFeatures::compositorWorkerEnabled() && animatingStyle &&
2146 animatingStyle->hasCompositorProxy()) { 2144 animatingStyle->hasCompositorProxy()) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
2202 layerChanged = true; 2200 layerChanged = true;
2203 } 2201 }
2204 } else { 2202 } else {
2205 if (m_backgroundLayer) { 2203 if (m_backgroundLayer) {
2206 m_backgroundLayer->removeFromParent(); 2204 m_backgroundLayer->removeFromParent();
2207 m_backgroundLayer = nullptr; 2205 m_backgroundLayer = nullptr;
2208 layerChanged = true; 2206 layerChanged = true;
2209 } 2207 }
2210 } 2208 }
2211 2209
2212 if (layerChanged && !m_owningLayer.layoutObject()->documentBeingDestroyed()) 2210 if (layerChanged && !m_owningLayer.layoutObject().documentBeingDestroyed())
2213 compositor()->rootFixedBackgroundsChanged(); 2211 compositor()->rootFixedBackgroundsChanged();
2214 2212
2215 return layerChanged; 2213 return layerChanged;
2216 } 2214 }
2217 2215
2218 bool CompositedLayerMapping::updateDecorationOutlineLayer( 2216 bool CompositedLayerMapping::updateDecorationOutlineLayer(
2219 bool needsDecorationOutlineLayer) { 2217 bool needsDecorationOutlineLayer) {
2220 bool layerChanged = false; 2218 bool layerChanged = false;
2221 if (needsDecorationOutlineLayer) { 2219 if (needsDecorationOutlineLayer) {
2222 if (!m_decorationOutlineLayer) { 2220 if (!m_decorationOutlineLayer) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
2272 if (!m_scrollingLayer) { 2270 if (!m_scrollingLayer) {
2273 // Outer layer which corresponds with the scroll view. 2271 // Outer layer which corresponds with the scroll view.
2274 m_scrollingLayer = 2272 m_scrollingLayer =
2275 createGraphicsLayer(CompositingReasonLayerForScrollingContainer); 2273 createGraphicsLayer(CompositingReasonLayerForScrollingContainer);
2276 m_scrollingLayer->setDrawsContent(false); 2274 m_scrollingLayer->setDrawsContent(false);
2277 2275
2278 // Inner layer which renders the content that scrolls. 2276 // Inner layer which renders the content that scrolls.
2279 m_scrollingContentsLayer = 2277 m_scrollingContentsLayer =
2280 createGraphicsLayer(CompositingReasonLayerForScrollingContents); 2278 createGraphicsLayer(CompositingReasonLayerForScrollingContents);
2281 2279
2282 if (Node* owningNode = m_owningLayer.layoutObject()->node()) 2280 if (Node* owningNode = m_owningLayer.layoutObject().node())
2283 m_scrollingContentsLayer->setElementId(createCompositorElementId( 2281 m_scrollingContentsLayer->setElementId(createCompositorElementId(
2284 DOMNodeIds::idForNode(owningNode), CompositorSubElementId::Scroll)); 2282 DOMNodeIds::idForNode(owningNode), CompositorSubElementId::Scroll));
2285 2283
2286 m_scrollingLayer->addChild(m_scrollingContentsLayer.get()); 2284 m_scrollingLayer->addChild(m_scrollingContentsLayer.get());
2287 2285
2288 layerChanged = true; 2286 layerChanged = true;
2289 if (scrollingCoordinator) { 2287 if (scrollingCoordinator) {
2290 scrollingCoordinator->scrollableAreaScrollLayerDidChange( 2288 scrollingCoordinator->scrollableAreaScrollLayerDidChange(
2291 m_owningLayer.getScrollableArea()); 2289 m_owningLayer.getScrollableArea());
2292 scrollingCoordinator->scrollableAreasDidChange(); 2290 scrollingCoordinator->scrollableAreasDidChange();
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
2465 // break here. 2463 // break here.
2466 // 2464 //
2467 // FIXME: with grouped backings, a composited descendant will have to 2465 // FIXME: with grouped backings, a composited descendant will have to
2468 // continue past the grouped (squashed) layers that its parents may 2466 // continue past the grouped (squashed) layers that its parents may
2469 // contribute to. This whole confusion can be avoided by specifying 2467 // contribute to. This whole confusion can be avoided by specifying
2470 // explicitly the composited ancestor where we would stop accumulating 2468 // explicitly the composited ancestor where we would stop accumulating
2471 // opacity. 2469 // opacity.
2472 if (curr->compositingState() == PaintsIntoOwnBacking) 2470 if (curr->compositingState() == PaintsIntoOwnBacking)
2473 break; 2471 break;
2474 2472
2475 finalOpacity *= curr->layoutObject()->opacity(); 2473 finalOpacity *= curr->layoutObject().opacity();
2476 } 2474 }
2477 2475
2478 return finalOpacity; 2476 return finalOpacity;
2479 } 2477 }
2480 2478
2481 Color CompositedLayerMapping::layoutObjectBackgroundColor() const { 2479 Color CompositedLayerMapping::layoutObjectBackgroundColor() const {
2482 return layoutObject()->resolveColor(CSSPropertyBackgroundColor); 2480 return layoutObject().resolveColor(CSSPropertyBackgroundColor);
2483 } 2481 }
2484 2482
2485 void CompositedLayerMapping::updateBackgroundColor() { 2483 void CompositedLayerMapping::updateBackgroundColor() {
2486 m_graphicsLayer->setBackgroundColor(layoutObjectBackgroundColor()); 2484 m_graphicsLayer->setBackgroundColor(layoutObjectBackgroundColor());
2487 } 2485 }
2488 2486
2489 bool CompositedLayerMapping::paintsChildren() const { 2487 bool CompositedLayerMapping::paintsChildren() const {
2490 if (m_owningLayer.hasVisibleContent() && 2488 if (m_owningLayer.hasVisibleContent() &&
2491 m_owningLayer.hasNonEmptyChildLayoutObjects()) 2489 m_owningLayer.hasNonEmptyChildLayoutObjects())
2492 return true; 2490 return true;
2493 2491
2494 if (hasVisibleNonCompositingDescendant(&m_owningLayer)) 2492 if (hasVisibleNonCompositingDescendant(&m_owningLayer))
2495 return true; 2493 return true;
2496 2494
2497 return false; 2495 return false;
2498 } 2496 }
2499 2497
2500 static bool isCompositedPlugin(LayoutObject* layoutObject) { 2498 static bool isCompositedPlugin(LayoutObject& layoutObject) {
2501 return layoutObject->isEmbeddedObject() && 2499 return layoutObject.isEmbeddedObject() &&
2502 toLayoutEmbeddedObject(layoutObject)->requiresAcceleratedCompositing(); 2500 toLayoutEmbeddedObject(layoutObject).requiresAcceleratedCompositing();
2503 } 2501 }
2504 2502
2505 bool CompositedLayerMapping::hasVisibleNonCompositingDescendant( 2503 bool CompositedLayerMapping::hasVisibleNonCompositingDescendant(
2506 PaintLayer* parent) { 2504 PaintLayer* parent) {
2507 if (!parent->hasVisibleDescendant()) 2505 if (!parent->hasVisibleDescendant())
2508 return false; 2506 return false;
2509 2507
2510 // FIXME: We shouldn't be called with a stale z-order lists. See bug 85512. 2508 // FIXME: We shouldn't be called with a stale z-order lists. See bug 85512.
2511 parent->stackingNode()->updateLayerListsIfNeeded(); 2509 parent->stackingNode()->updateLayerListsIfNeeded();
2512 2510
2513 #if DCHECK_IS_ON() 2511 #if DCHECK_IS_ON()
2514 LayerListMutationDetector mutationChecker(parent->stackingNode()); 2512 LayerListMutationDetector mutationChecker(parent->stackingNode());
2515 #endif 2513 #endif
2516 2514
2517 PaintLayerStackingNodeIterator normalFlowIterator(*parent->stackingNode(), 2515 PaintLayerStackingNodeIterator normalFlowIterator(*parent->stackingNode(),
2518 AllChildren); 2516 AllChildren);
2519 while (PaintLayerStackingNode* curNode = normalFlowIterator.next()) { 2517 while (PaintLayerStackingNode* curNode = normalFlowIterator.next()) {
2520 PaintLayer* curLayer = curNode->layer(); 2518 PaintLayer* curLayer = curNode->layer();
2521 if (curLayer->hasCompositedLayerMapping()) 2519 if (curLayer->hasCompositedLayerMapping())
2522 continue; 2520 continue;
2523 if (curLayer->hasVisibleContent() || 2521 if (curLayer->hasVisibleContent() ||
2524 hasVisibleNonCompositingDescendant(curLayer)) 2522 hasVisibleNonCompositingDescendant(curLayer))
2525 return true; 2523 return true;
2526 } 2524 }
2527 2525
2528 return false; 2526 return false;
2529 } 2527 }
2530 2528
2531 bool CompositedLayerMapping::containsPaintedContent() const { 2529 bool CompositedLayerMapping::containsPaintedContent() const {
2532 if (layoutObject()->isImage() && isDirectlyCompositedImage()) 2530 if (layoutObject().isImage() && isDirectlyCompositedImage())
2533 return false; 2531 return false;
2534 2532
2535 LayoutObject* layoutObject = this->layoutObject(); 2533 LayoutObject& layoutObject = this->layoutObject();
2536 // FIXME: we could optimize cases where the image, video or canvas is known to 2534 // FIXME: we could optimize cases where the image, video or canvas is known to
2537 // fill the border box entirely, and set background color on the layer in that 2535 // fill the border box entirely, and set background color on the layer in that
2538 // case, instead of allocating backing store and painting. 2536 // case, instead of allocating backing store and painting.
2539 if (layoutObject->isVideo() && 2537 if (layoutObject.isVideo() &&
2540 toLayoutVideo(layoutObject)->shouldDisplayVideo()) 2538 toLayoutVideo(layoutObject).shouldDisplayVideo())
2541 return m_owningLayer.hasBoxDecorationsOrBackground(); 2539 return m_owningLayer.hasBoxDecorationsOrBackground();
2542 2540
2543 if (m_owningLayer.hasVisibleBoxDecorations()) 2541 if (m_owningLayer.hasVisibleBoxDecorations())
2544 return true; 2542 return true;
2545 2543
2546 if (layoutObject->hasMask()) // masks require special treatment 2544 if (layoutObject.hasMask()) // masks require special treatment
2547 return true; 2545 return true;
2548 2546
2549 if (layoutObject->isAtomicInlineLevel() && !isCompositedPlugin(layoutObject)) 2547 if (layoutObject.isAtomicInlineLevel() && !isCompositedPlugin(layoutObject))
2550 return true; 2548 return true;
2551 2549
2552 if (layoutObject->isLayoutMultiColumnSet()) 2550 if (layoutObject.isLayoutMultiColumnSet())
2553 return true; 2551 return true;
2554 2552
2555 if (layoutObject->node() && layoutObject->node()->isDocumentNode()) { 2553 if (layoutObject.node() && layoutObject.node()->isDocumentNode()) {
2556 // Look to see if the root object has a non-simple background 2554 // Look to see if the root object has a non-simple background
2557 LayoutObject* rootObject = 2555 LayoutObject* rootObject =
2558 layoutObject->document().documentElement() 2556 layoutObject.document().documentElement()
2559 ? layoutObject->document().documentElement()->layoutObject() 2557 ? layoutObject.document().documentElement()->layoutObject()
2560 : 0; 2558 : 0;
2561 // Reject anything that has a border, a border-radius or outline, 2559 // Reject anything that has a border, a border-radius or outline,
2562 // or is not a simple background (no background, or solid color). 2560 // or is not a simple background (no background, or solid color).
2563 if (rootObject && 2561 if (rootObject &&
2564 hasBoxDecorationsOrBackgroundImage(rootObject->styleRef())) 2562 hasBoxDecorationsOrBackgroundImage(rootObject->styleRef()))
2565 return true; 2563 return true;
2566 2564
2567 // Now look at the body's layoutObject. 2565 // Now look at the body's layoutObject.
2568 HTMLElement* body = layoutObject->document().body(); 2566 HTMLElement* body = layoutObject.document().body();
2569 LayoutObject* bodyObject = 2567 LayoutObject* bodyObject =
2570 isHTMLBodyElement(body) ? body->layoutObject() : 0; 2568 isHTMLBodyElement(body) ? body->layoutObject() : 0;
2571 if (bodyObject && 2569 if (bodyObject &&
2572 hasBoxDecorationsOrBackgroundImage(bodyObject->styleRef())) 2570 hasBoxDecorationsOrBackgroundImage(bodyObject->styleRef()))
2573 return true; 2571 return true;
2574 } 2572 }
2575 2573
2576 // FIXME: it's O(n^2). A better solution is needed. 2574 // FIXME: it's O(n^2). A better solution is needed.
2577 return paintsChildren(); 2575 return paintsChildren();
2578 } 2576 }
2579 2577
2580 // An image can be directly composited if it's the sole content of the layer, 2578 // An image can be directly composited if it's the sole content of the layer,
2581 // and has no box decorations or clipping that require painting. Direct 2579 // and has no box decorations or clipping that require painting. Direct
2582 // compositing saves a backing store. 2580 // compositing saves a backing store.
2583 bool CompositedLayerMapping::isDirectlyCompositedImage() const { 2581 bool CompositedLayerMapping::isDirectlyCompositedImage() const {
2584 ASSERT(layoutObject()->isImage()); 2582 DCHECK(layoutObject().isImage());
2585 LayoutImage* imageLayoutObject = toLayoutImage(layoutObject()); 2583 LayoutImage& imageLayoutObject = toLayoutImage(layoutObject());
2586 2584
2587 if (m_owningLayer.hasBoxDecorationsOrBackground() || 2585 if (m_owningLayer.hasBoxDecorationsOrBackground() ||
2588 imageLayoutObject->hasClip() || imageLayoutObject->hasClipPath() || 2586 imageLayoutObject.hasClip() || imageLayoutObject.hasClipPath() ||
2589 imageLayoutObject->hasObjectFit()) 2587 imageLayoutObject.hasObjectFit())
2590 return false; 2588 return false;
2591 2589
2592 if (ImageResourceContent* cachedImage = imageLayoutObject->cachedImage()) { 2590 if (ImageResourceContent* cachedImage = imageLayoutObject.cachedImage()) {
2593 if (!cachedImage->hasImage()) 2591 if (!cachedImage->hasImage())
2594 return false; 2592 return false;
2595 2593
2596 Image* image = cachedImage->getImage(); 2594 Image* image = cachedImage->getImage();
2597 if (!image->isBitmapImage()) 2595 if (!image->isBitmapImage())
2598 return false; 2596 return false;
2599 2597
2600 return true; 2598 return true;
2601 } 2599 }
2602 2600
2603 return false; 2601 return false;
2604 } 2602 }
2605 2603
2606 void CompositedLayerMapping::contentChanged(ContentChangeType changeType) { 2604 void CompositedLayerMapping::contentChanged(ContentChangeType changeType) {
2607 if ((changeType == ImageChanged) && layoutObject()->isImage() && 2605 if ((changeType == ImageChanged) && layoutObject().isImage() &&
2608 isDirectlyCompositedImage()) { 2606 isDirectlyCompositedImage()) {
2609 updateImageContents(); 2607 updateImageContents();
2610 return; 2608 return;
2611 } 2609 }
2612 2610
2613 if (changeType == CanvasChanged && isAcceleratedCanvas(layoutObject())) { 2611 if (changeType == CanvasChanged && isAcceleratedCanvas(layoutObject())) {
2614 m_graphicsLayer->setContentsNeedsDisplay(); 2612 m_graphicsLayer->setContentsNeedsDisplay();
2615 return; 2613 return;
2616 } 2614 }
2617 } 2615 }
2618 2616
2619 void CompositedLayerMapping::updateImageContents() { 2617 void CompositedLayerMapping::updateImageContents() {
2620 ASSERT(layoutObject()->isImage()); 2618 DCHECK(layoutObject().isImage());
2621 LayoutImage* imageLayoutObject = toLayoutImage(layoutObject()); 2619 LayoutImage& imageLayoutObject = toLayoutImage(layoutObject());
2622 2620
2623 ImageResourceContent* cachedImage = imageLayoutObject->cachedImage(); 2621 ImageResourceContent* cachedImage = imageLayoutObject.cachedImage();
2624 if (!cachedImage) 2622 if (!cachedImage)
2625 return; 2623 return;
2626 2624
2627 Image* image = cachedImage->getImage(); 2625 Image* image = cachedImage->getImage();
2628 if (!image) 2626 if (!image)
2629 return; 2627 return;
2630 2628
2631 // This is a no-op if the layer doesn't have an inner layer for the image. 2629 // This is a no-op if the layer doesn't have an inner layer for the image.
2632 m_graphicsLayer->setContentsToImage( 2630 m_graphicsLayer->setContentsToImage(
2633 image, LayoutObject::shouldRespectImageOrientation(imageLayoutObject)); 2631 image, LayoutObject::shouldRespectImageOrientation(&imageLayoutObject));
2634 2632
2635 m_graphicsLayer->setFilterQuality(layoutObject()->style()->imageRendering() == 2633 m_graphicsLayer->setFilterQuality(layoutObject().style()->imageRendering() ==
2636 ImageRenderingPixelated 2634 ImageRenderingPixelated
2637 ? kNone_SkFilterQuality 2635 ? kNone_SkFilterQuality
2638 : kLow_SkFilterQuality); 2636 : kLow_SkFilterQuality);
2639 2637
2640 // Prevent double-drawing: https://bugs.webkit.org/show_bug.cgi?id=58632 2638 // Prevent double-drawing: https://bugs.webkit.org/show_bug.cgi?id=58632
2641 updateDrawsContent(); 2639 updateDrawsContent();
2642 2640
2643 // Image animation is "lazy", in that it automatically stops unless someone is 2641 // Image animation is "lazy", in that it automatically stops unless someone is
2644 // drawing the image. So we have to kick the animation each time; this has the 2642 // drawing the image. So we have to kick the animation each time; this has the
2645 // downside that the image will keep animating, even if its layer is not 2643 // downside that the image will keep animating, even if its layer is not
2646 // visible. 2644 // visible.
2647 image->startAnimation(); 2645 image->startAnimation();
2648 } 2646 }
2649 2647
2650 FloatPoint3D CompositedLayerMapping::computeTransformOrigin( 2648 FloatPoint3D CompositedLayerMapping::computeTransformOrigin(
2651 const IntRect& borderBox) const { 2649 const IntRect& borderBox) const {
2652 const ComputedStyle& style = layoutObject()->styleRef(); 2650 const ComputedStyle& style = layoutObject().styleRef();
2653 2651
2654 FloatPoint3D origin; 2652 FloatPoint3D origin;
2655 origin.setX(floatValueForLength(style.transformOriginX(), borderBox.width())); 2653 origin.setX(floatValueForLength(style.transformOriginX(), borderBox.width()));
2656 origin.setY( 2654 origin.setY(
2657 floatValueForLength(style.transformOriginY(), borderBox.height())); 2655 floatValueForLength(style.transformOriginY(), borderBox.height()));
2658 origin.setZ(style.transformOriginZ()); 2656 origin.setZ(style.transformOriginZ());
2659 2657
2660 return origin; 2658 return origin;
2661 } 2659 }
2662 2660
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
2776 2774
2777 IntRect r; 2775 IntRect r;
2778 PaintInvalidationReason invalidationReason; 2776 PaintInvalidationReason invalidationReason;
2779 const DisplayItemClient& client; 2777 const DisplayItemClient& client;
2780 }; 2778 };
2781 2779
2782 void CompositedLayerMapping::setContentsNeedDisplayInRect( 2780 void CompositedLayerMapping::setContentsNeedDisplayInRect(
2783 const LayoutRect& r, 2781 const LayoutRect& r,
2784 PaintInvalidationReason invalidationReason, 2782 PaintInvalidationReason invalidationReason,
2785 const DisplayItemClient& client) { 2783 const DisplayItemClient& client) {
2786 DCHECK(!m_owningLayer.layoutObject()->usesCompositedScrolling()); 2784 DCHECK(!m_owningLayer.layoutObject().usesCompositedScrolling());
2787 // TODO(wangxianzhu): Enable the following assert after paint invalidation for 2785 // TODO(wangxianzhu): Enable the following assert after paint invalidation for
2788 // spv2 is ready. 2786 // spv2 is ready.
2789 // ASSERT(!RuntimeEnabledFeatures::slimmingPaintV2Enabled()); 2787 // ASSERT(!RuntimeEnabledFeatures::slimmingPaintV2Enabled());
2790 2788
2791 SetContentsNeedsDisplayInRectFunctor functor = { 2789 SetContentsNeedsDisplayInRectFunctor functor = {
2792 enclosingIntRect(LayoutRect( 2790 enclosingIntRect(LayoutRect(
2793 r.location() + m_owningLayer.subpixelAccumulation(), r.size())), 2791 r.location() + m_owningLayer.subpixelAccumulation(), r.size())),
2794 invalidationReason, client}; 2792 invalidationReason, client};
2795 ApplyToGraphicsLayers(this, functor, ApplyToContentLayers); 2793 ApplyToGraphicsLayers(this, functor, ApplyToContentLayers);
2796 } 2794 }
2797 2795
2798 void CompositedLayerMapping::setNonScrollingContentsNeedDisplayInRect( 2796 void CompositedLayerMapping::setNonScrollingContentsNeedDisplayInRect(
2799 const LayoutRect& r, 2797 const LayoutRect& r,
2800 PaintInvalidationReason invalidationReason, 2798 PaintInvalidationReason invalidationReason,
2801 const DisplayItemClient& client) { 2799 const DisplayItemClient& client) {
2802 DCHECK(m_owningLayer.layoutObject()->usesCompositedScrolling()); 2800 DCHECK(m_owningLayer.layoutObject().usesCompositedScrolling());
2803 // TODO(wangxianzhu): Enable the following assert after paint invalidation for 2801 // TODO(wangxianzhu): Enable the following assert after paint invalidation for
2804 // spv2 is ready. 2802 // spv2 is ready.
2805 // ASSERT(!RuntimeEnabledFeatures::slimmingPaintV2Enabled()); 2803 // ASSERT(!RuntimeEnabledFeatures::slimmingPaintV2Enabled());
2806 2804
2807 SetContentsNeedsDisplayInRectFunctor functor = { 2805 SetContentsNeedsDisplayInRectFunctor functor = {
2808 enclosingIntRect(LayoutRect( 2806 enclosingIntRect(LayoutRect(
2809 r.location() + m_owningLayer.subpixelAccumulation(), r.size())), 2807 r.location() + m_owningLayer.subpixelAccumulation(), r.size())),
2810 invalidationReason, client}; 2808 invalidationReason, client};
2811 ApplyToGraphicsLayers(this, functor, ApplyToNonScrollingContentLayers); 2809 ApplyToGraphicsLayers(this, functor, ApplyToNonScrollingContentLayers);
2812 } 2810 }
2813 2811
2814 void CompositedLayerMapping::setScrollingContentsNeedDisplayInRect( 2812 void CompositedLayerMapping::setScrollingContentsNeedDisplayInRect(
2815 const LayoutRect& r, 2813 const LayoutRect& r,
2816 PaintInvalidationReason invalidationReason, 2814 PaintInvalidationReason invalidationReason,
2817 const DisplayItemClient& client) { 2815 const DisplayItemClient& client) {
2818 DCHECK(m_owningLayer.layoutObject()->usesCompositedScrolling()); 2816 DCHECK(m_owningLayer.layoutObject().usesCompositedScrolling());
2819 // TODO(wangxianzhu): Enable the following assert after paint invalidation for 2817 // TODO(wangxianzhu): Enable the following assert after paint invalidation for
2820 // spv2 is ready. 2818 // spv2 is ready.
2821 // ASSERT(!RuntimeEnabledFeatures::slimmingPaintV2Enabled()); 2819 // ASSERT(!RuntimeEnabledFeatures::slimmingPaintV2Enabled());
2822 2820
2823 SetContentsNeedsDisplayInRectFunctor functor = { 2821 SetContentsNeedsDisplayInRectFunctor functor = {
2824 enclosingIntRect(LayoutRect( 2822 enclosingIntRect(LayoutRect(
2825 r.location() + m_owningLayer.subpixelAccumulation(), r.size())), 2823 r.location() + m_owningLayer.subpixelAccumulation(), r.size())),
2826 invalidationReason, client}; 2824 invalidationReason, client};
2827 ApplyToGraphicsLayers(this, functor, ApplyToScrollingContentLayers); 2825 ApplyToGraphicsLayers(this, functor, ApplyToScrollingContentLayers);
2828 } 2826 }
2829 2827
2830 const GraphicsLayerPaintInfo* CompositedLayerMapping::containingSquashedLayer( 2828 const GraphicsLayerPaintInfo* CompositedLayerMapping::containingSquashedLayer(
2831 const LayoutObject* layoutObject, 2829 const LayoutObject* layoutObject,
2832 const Vector<GraphicsLayerPaintInfo>& layers, 2830 const Vector<GraphicsLayerPaintInfo>& layers,
2833 unsigned maxSquashedLayerIndex) { 2831 unsigned maxSquashedLayerIndex) {
2834 if (!layoutObject) 2832 if (!layoutObject)
2835 return nullptr; 2833 return nullptr;
2836 for (size_t i = 0; i < layers.size() && i < maxSquashedLayerIndex; ++i) { 2834 for (size_t i = 0; i < layers.size() && i < maxSquashedLayerIndex; ++i) {
2837 if (layoutObject->isDescendantOf(layers[i].paintLayer->layoutObject())) 2835 if (layoutObject->isDescendantOf(&layers[i].paintLayer->layoutObject()))
2838 return &layers[i]; 2836 return &layers[i];
2839 } 2837 }
2840 return nullptr; 2838 return nullptr;
2841 } 2839 }
2842 2840
2843 const GraphicsLayerPaintInfo* CompositedLayerMapping::containingSquashedLayer( 2841 const GraphicsLayerPaintInfo* CompositedLayerMapping::containingSquashedLayer(
2844 const LayoutObject* layoutObject, 2842 const LayoutObject* layoutObject,
2845 unsigned maxSquashedLayerIndex) { 2843 unsigned maxSquashedLayerIndex) {
2846 return CompositedLayerMapping::containingSquashedLayer( 2844 return CompositedLayerMapping::containingSquashedLayer(
2847 layoutObject, m_squashedLayers, maxSquashedLayerIndex); 2845 layoutObject, m_squashedLayers, maxSquashedLayerIndex);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
2903 PaintLayerPaintingAncestorClippingMaskPhase)) { 2901 PaintLayerPaintingAncestorClippingMaskPhase)) {
2904 dirtyRect.move( 2902 dirtyRect.move(
2905 roundedIntSize(paintInfo.paintLayer->subpixelAccumulation())); 2903 roundedIntSize(paintInfo.paintLayer->subpixelAccumulation()));
2906 } else { 2904 } else {
2907 LayoutRect bounds = paintInfo.compositedBounds; 2905 LayoutRect bounds = paintInfo.compositedBounds;
2908 bounds.move(paintInfo.paintLayer->subpixelAccumulation()); 2906 bounds.move(paintInfo.paintLayer->subpixelAccumulation());
2909 dirtyRect.intersect(pixelSnappedIntRect(bounds)); 2907 dirtyRect.intersect(pixelSnappedIntRect(bounds));
2910 } 2908 }
2911 2909
2912 #if DCHECK_IS_ON() 2910 #if DCHECK_IS_ON()
2913 if (!layoutObject()->view()->frame() || 2911 if (!layoutObject().view()->frame() ||
2914 !layoutObject()->view()->frame()->shouldThrottleRendering()) 2912 !layoutObject().view()->frame()->shouldThrottleRendering())
2915 paintInfo.paintLayer->layoutObject()->assertSubtreeIsLaidOut(); 2913 paintInfo.paintLayer->layoutObject().assertSubtreeIsLaidOut();
2916 #endif 2914 #endif
2917 2915
2918 float deviceScaleFactor = 2916 float deviceScaleFactor =
2919 blink::deviceScaleFactor(paintInfo.paintLayer->layoutObject()->frame()); 2917 blink::deviceScaleFactor(paintInfo.paintLayer->layoutObject().frame());
2920 context.setDeviceScaleFactor(deviceScaleFactor); 2918 context.setDeviceScaleFactor(deviceScaleFactor);
2921 2919
2922 if (paintInfo.paintLayer->compositingState() != PaintsIntoGroupedBacking) { 2920 if (paintInfo.paintLayer->compositingState() != PaintsIntoGroupedBacking) {
2923 // FIXME: GraphicsLayers need a way to split for multicol. 2921 // FIXME: GraphicsLayers need a way to split for multicol.
2924 PaintLayerPaintingInfo paintingInfo( 2922 PaintLayerPaintingInfo paintingInfo(
2925 paintInfo.paintLayer, LayoutRect(dirtyRect), GlobalPaintNormalPhase, 2923 paintInfo.paintLayer, LayoutRect(dirtyRect), GlobalPaintNormalPhase,
2926 paintInfo.paintLayer->subpixelAccumulation()); 2924 paintInfo.paintLayer->subpixelAccumulation());
2927 PaintLayerPainter(*paintInfo.paintLayer) 2925 PaintLayerPainter(*paintInfo.paintLayer)
2928 .paintLayerContents(context, paintingInfo, paintLayerFlags); 2926 .paintLayerContents(context, paintingInfo, paintLayerFlags);
2929 2927
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
2989 if (graphicsLayer == m_squashingLayer.get()) { 2987 if (graphicsLayer == m_squashingLayer.get()) {
2990 // TODO(chrishtr): this is a speculative fix for crbug.com/561306. However, 2988 // TODO(chrishtr): this is a speculative fix for crbug.com/561306. However,
2991 // it should never be the case that m_squashingLayer exists, 2989 // it should never be the case that m_squashingLayer exists,
2992 // yet m_squashedLayers.size() == 0. There must be a bug elsewhere. 2990 // yet m_squashedLayers.size() == 0. There must be a bug elsewhere.
2993 if (m_squashedLayers.size() == 0) 2991 if (m_squashedLayers.size() == 0)
2994 return IntRect(); 2992 return IntRect();
2995 // All squashed layers have the same clip and transform space, so we can use 2993 // All squashed layers have the same clip and transform space, so we can use
2996 // the first squashed layer's layoutObject to map the squashing layer's 2994 // the first squashed layer's layoutObject to map the squashing layer's
2997 // bounds into viewport space, with offsetFromAnchorLayoutObject to 2995 // bounds into viewport space, with offsetFromAnchorLayoutObject to
2998 // translate squashing layer's bounds into the first squashed layer's space. 2996 // translate squashing layer's bounds into the first squashed layer's space.
2999 anchorLayoutObject = m_squashedLayers[0].paintLayer->layoutObject(); 2997 anchorLayoutObject = &m_squashedLayers[0].paintLayer->layoutObject();
3000 offsetFromAnchorLayoutObject = m_squashedLayers[0].offsetFromLayoutObject; 2998 offsetFromAnchorLayoutObject = m_squashedLayers[0].offsetFromLayoutObject;
3001 } else { 2999 } else {
3002 ASSERT(graphicsLayer == m_graphicsLayer.get() || 3000 ASSERT(graphicsLayer == m_graphicsLayer.get() ||
3003 graphicsLayer == m_scrollingContentsLayer.get()); 3001 graphicsLayer == m_scrollingContentsLayer.get());
3004 anchorLayoutObject = m_owningLayer.layoutObject(); 3002 anchorLayoutObject = &m_owningLayer.layoutObject();
3005 offsetFromAnchorLayoutObject = graphicsLayer->offsetFromLayoutObject(); 3003 offsetFromAnchorLayoutObject = graphicsLayer->offsetFromLayoutObject();
3006 adjustForCompositedScrolling(graphicsLayer, offsetFromAnchorLayoutObject); 3004 adjustForCompositedScrolling(graphicsLayer, offsetFromAnchorLayoutObject);
3007 } 3005 }
3008 3006
3009 // Start with the bounds of the graphics layer in the space of the anchor 3007 // Start with the bounds of the graphics layer in the space of the anchor
3010 // LayoutObject. 3008 // LayoutObject.
3011 FloatRect graphicsLayerBoundsInObjectSpace(graphicsLayerBounds); 3009 FloatRect graphicsLayerBoundsInObjectSpace(graphicsLayerBounds);
3012 graphicsLayerBoundsInObjectSpace.move(offsetFromAnchorLayoutObject); 3010 graphicsLayerBoundsInObjectSpace.move(offsetFromAnchorLayoutObject);
3013 3011
3014 // Now map the bounds to its visible content rect in root view space, 3012 // Now map the bounds to its visible content rect in root view space,
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
3149 void CompositedLayerMapping::paintContents( 3147 void CompositedLayerMapping::paintContents(
3150 const GraphicsLayer* graphicsLayer, 3148 const GraphicsLayer* graphicsLayer,
3151 GraphicsContext& context, 3149 GraphicsContext& context,
3152 GraphicsLayerPaintingPhase graphicsLayerPaintingPhase, 3150 GraphicsLayerPaintingPhase graphicsLayerPaintingPhase,
3153 const IntRect& interestRect) const { 3151 const IntRect& interestRect) const {
3154 // https://code.google.com/p/chromium/issues/detail?id=343772 3152 // https://code.google.com/p/chromium/issues/detail?id=343772
3155 DisableCompositingQueryAsserts disabler; 3153 DisableCompositingQueryAsserts disabler;
3156 // Allow throttling to make sure no painting paths (e.g., 3154 // Allow throttling to make sure no painting paths (e.g.,
3157 // ContentLayerDelegate::paintContents) try to paint throttled content. 3155 // ContentLayerDelegate::paintContents) try to paint throttled content.
3158 DocumentLifecycle::AllowThrottlingScope allowThrottling( 3156 DocumentLifecycle::AllowThrottlingScope allowThrottling(
3159 m_owningLayer.layoutObject()->document().lifecycle()); 3157 m_owningLayer.layoutObject().document().lifecycle());
3160 #if DCHECK_IS_ON() 3158 #if DCHECK_IS_ON()
3161 // FIXME: once the state machine is ready, this can be removed and we can 3159 // FIXME: once the state machine is ready, this can be removed and we can
3162 // refer to that instead. 3160 // refer to that instead.
3163 if (Page* page = layoutObject()->frame()->page()) 3161 if (Page* page = layoutObject().frame()->page())
3164 page->setIsPainting(true); 3162 page->setIsPainting(true);
3165 #endif 3163 #endif
3166 3164
3167 TRACE_EVENT1( 3165 TRACE_EVENT1(
3168 "devtools.timeline,rail", "Paint", "data", 3166 "devtools.timeline,rail", "Paint", "data",
3169 InspectorPaintEvent::data(m_owningLayer.layoutObject(), 3167 InspectorPaintEvent::data(&m_owningLayer.layoutObject(),
3170 LayoutRect(interestRect), graphicsLayer)); 3168 LayoutRect(interestRect), graphicsLayer));
3171 3169
3172 PaintLayerFlags paintLayerFlags = 0; 3170 PaintLayerFlags paintLayerFlags = 0;
3173 if (graphicsLayerPaintingPhase & GraphicsLayerPaintBackground) 3171 if (graphicsLayerPaintingPhase & GraphicsLayerPaintBackground)
3174 paintLayerFlags |= PaintLayerPaintingCompositingBackgroundPhase; 3172 paintLayerFlags |= PaintLayerPaintingCompositingBackgroundPhase;
3175 else 3173 else
3176 paintLayerFlags |= PaintLayerPaintingSkipRootBackground; 3174 paintLayerFlags |= PaintLayerPaintingSkipRootBackground;
3177 if (graphicsLayerPaintingPhase & GraphicsLayerPaintForeground) 3175 if (graphicsLayerPaintingPhase & GraphicsLayerPaintForeground)
3178 paintLayerFlags |= PaintLayerPaintingCompositingForegroundPhase; 3176 paintLayerFlags |= PaintLayerPaintingCompositingForegroundPhase;
3179 if (graphicsLayerPaintingPhase & GraphicsLayerPaintMask) 3177 if (graphicsLayerPaintingPhase & GraphicsLayerPaintMask)
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
3225 // compute and cache clipRects. 3223 // compute and cache clipRects.
3226 doPaintTask(paintInfo, *graphicsLayer, paintLayerFlags, context, 3224 doPaintTask(paintInfo, *graphicsLayer, paintLayerFlags, context,
3227 interestRect); 3225 interestRect);
3228 } else if (graphicsLayer == m_squashingLayer.get()) { 3226 } else if (graphicsLayer == m_squashingLayer.get()) {
3229 for (size_t i = 0; i < m_squashedLayers.size(); ++i) 3227 for (size_t i = 0; i < m_squashedLayers.size(); ++i)
3230 doPaintTask(m_squashedLayers[i], *graphicsLayer, paintLayerFlags, context, 3228 doPaintTask(m_squashedLayers[i], *graphicsLayer, paintLayerFlags, context,
3231 interestRect); 3229 interestRect);
3232 } else if (isScrollableAreaLayer(graphicsLayer)) { 3230 } else if (isScrollableAreaLayer(graphicsLayer)) {
3233 paintScrollableArea(graphicsLayer, context, interestRect); 3231 paintScrollableArea(graphicsLayer, context, interestRect);
3234 } 3232 }
3235 InspectorInstrumentation::didPaint(m_owningLayer.layoutObject()->frame(), 3233 InspectorInstrumentation::didPaint(m_owningLayer.layoutObject().frame(),
3236 graphicsLayer, context, 3234 graphicsLayer, context,
3237 LayoutRect(interestRect)); 3235 LayoutRect(interestRect));
3238 #if DCHECK_IS_ON() 3236 #if DCHECK_IS_ON()
3239 if (Page* page = layoutObject()->frame()->page()) 3237 if (Page* page = layoutObject().frame()->page())
3240 page->setIsPainting(false); 3238 page->setIsPainting(false);
3241 #endif 3239 #endif
3242 } 3240 }
3243 3241
3244 void CompositedLayerMapping::paintScrollableArea( 3242 void CompositedLayerMapping::paintScrollableArea(
3245 const GraphicsLayer* graphicsLayer, 3243 const GraphicsLayer* graphicsLayer,
3246 GraphicsContext& context, 3244 GraphicsContext& context,
3247 const IntRect& interestRect) const { 3245 const IntRect& interestRect) const {
3248 // Note the composited scrollable area painted here is never associated with a 3246 // Note the composited scrollable area painted here is never associated with a
3249 // frame. For painting frame ScrollableAreas, see 3247 // frame. For painting frame ScrollableAreas, see
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
3291 graphicsLayer == layerForScrollCorner(); 3289 graphicsLayer == layerForScrollCorner();
3292 } 3290 }
3293 3291
3294 bool CompositedLayerMapping::isTrackingRasterInvalidations() const { 3292 bool CompositedLayerMapping::isTrackingRasterInvalidations() const {
3295 GraphicsLayerClient* client = compositor(); 3293 GraphicsLayerClient* client = compositor();
3296 return client ? client->isTrackingRasterInvalidations() : false; 3294 return client ? client->isTrackingRasterInvalidations() : false;
3297 } 3295 }
3298 3296
3299 #if DCHECK_IS_ON() 3297 #if DCHECK_IS_ON()
3300 void CompositedLayerMapping::verifyNotPainting() { 3298 void CompositedLayerMapping::verifyNotPainting() {
3301 ASSERT(!layoutObject()->frame()->page() || 3299 DCHECK(!layoutObject().frame()->page() ||
3302 !layoutObject()->frame()->page()->isPainting()); 3300 !layoutObject().frame()->page()->isPainting());
3303 } 3301 }
3304 #endif 3302 #endif
3305 3303
3306 // Only used for performance benchmark testing. Intended to be a 3304 // Only used for performance benchmark testing. Intended to be a
3307 // sufficiently-unique element id name to allow picking out the target element 3305 // sufficiently-unique element id name to allow picking out the target element
3308 // for invalidation. 3306 // for invalidation.
3309 static const char* kTestPaintInvalidationTargetName = 3307 static const char* kTestPaintInvalidationTargetName =
3310 "blinkPaintInvalidationTarget"; 3308 "blinkPaintInvalidationTarget";
3311 3309
3312 void CompositedLayerMapping::invalidateTargetElementForTesting() { 3310 void CompositedLayerMapping::invalidateTargetElementForTesting() {
3313 // The below is an artificial construct formed intentionally to focus a 3311 // The below is an artificial construct formed intentionally to focus a
3314 // microbenchmark on the cost of paint with a partial invalidation. 3312 // microbenchmark on the cost of paint with a partial invalidation.
3315 Element* targetElement = 3313 Element* targetElement =
3316 m_owningLayer.layoutObject()->document().getElementById( 3314 m_owningLayer.layoutObject().document().getElementById(
3317 AtomicString(kTestPaintInvalidationTargetName)); 3315 AtomicString(kTestPaintInvalidationTargetName));
3318 // TODO(wkorman): If we don't find the expected target element, we could 3316 // TODO(wkorman): If we don't find the expected target element, we could
3319 // consider walking to the first leaf node so that the partial-invalidation 3317 // consider walking to the first leaf node so that the partial-invalidation
3320 // benchmark mode still provides some value when running on generic pages. 3318 // benchmark mode still provides some value when running on generic pages.
3321 if (!targetElement) 3319 if (!targetElement)
3322 return; 3320 return;
3323 LayoutObject* targetObject = targetElement->layoutObject(); 3321 LayoutObject* targetObject = targetElement->layoutObject();
3324 if (!targetObject) 3322 if (!targetObject)
3325 return; 3323 return;
3326 targetObject->enclosingLayer()->setNeedsRepaint(); 3324 targetObject->enclosingLayer()->setNeedsRepaint();
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
3482 } else if (graphicsLayer == m_decorationOutlineLayer.get()) { 3480 } else if (graphicsLayer == m_decorationOutlineLayer.get()) {
3483 name = "Decoration Layer"; 3481 name = "Decoration Layer";
3484 } else { 3482 } else {
3485 ASSERT_NOT_REACHED(); 3483 ASSERT_NOT_REACHED();
3486 } 3484 }
3487 3485
3488 return name; 3486 return name;
3489 } 3487 }
3490 3488
3491 } // namespace blink 3489 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698