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

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

Issue 2237433004: Adds DevTools commands for forced viewport override. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sync. Created 4 years, 3 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 2267 matching lines...) Expand 10 before | Expand all | Expand 10 after
2278 if (!scrollbar) 2278 if (!scrollbar)
2279 return; 2279 return;
2280 2280
2281 const IntRect& scrollbarRect = scrollbar->frameRect(); 2281 const IntRect& scrollbarRect = scrollbar->frameRect();
2282 TransformRecorder transformRecorder(context, *scrollbar, AffineTransform::tr anslation(-scrollbarRect.x(), -scrollbarRect.y())); 2282 TransformRecorder transformRecorder(context, *scrollbar, AffineTransform::tr anslation(-scrollbarRect.x(), -scrollbarRect.y()));
2283 IntRect transformedClip = clip; 2283 IntRect transformedClip = clip;
2284 transformedClip.moveBy(scrollbarRect.location()); 2284 transformedClip.moveBy(scrollbarRect.location());
2285 scrollbar->paint(context, CullRect(transformedClip)); 2285 scrollbar->paint(context, CullRect(transformedClip));
2286 } 2286 }
2287 2287
2288 // TODO(eseckler): Make recording distance configurable, e.g. for use in
2289 // headless, where we would like to record an exact area (distance = 0).
2288 static const int kPixelDistanceToRecord = 4000; 2290 static const int kPixelDistanceToRecord = 4000;
2289 2291
2290 IntRect CompositedLayerMapping::recomputeInterestRect(const GraphicsLayer* graph icsLayer) const 2292 IntRect CompositedLayerMapping::recomputeInterestRect(const GraphicsLayer* graph icsLayer) const
2291 { 2293 {
2292 FloatRect graphicsLayerBounds(FloatPoint(), graphicsLayer->size()); 2294 FloatRect graphicsLayerBounds(FloatPoint(), graphicsLayer->size());
2293 2295
2294 IntSize offsetFromAnchorLayoutObject; 2296 IntSize offsetFromAnchorLayoutObject;
2295 const LayoutBoxModelObject* anchorLayoutObject; 2297 const LayoutBoxModelObject* anchorLayoutObject;
2296 if (graphicsLayer == m_squashingLayer.get()) { 2298 if (graphicsLayer == m_squashingLayer.get()) {
2297 // TODO(chrishtr): this is a speculative fix for crbug.com/561306. Howev er, it should never be the case that 2299 // TODO(chrishtr): this is a speculative fix for crbug.com/561306. Howev er, it should never be the case that
2298 // m_squashingLayer exists yet m_squashedLayers.size() == 0. There must be a bug elsewhere. 2300 // m_squashingLayer exists yet m_squashedLayers.size() == 0. There must be a bug elsewhere.
2299 if (m_squashedLayers.size() == 0) 2301 if (m_squashedLayers.size() == 0)
2300 return IntRect(); 2302 return IntRect();
2301 // All squashed layers have the same clip and transform space, so we can use the first squashed layer's 2303 // All squashed layers have the same clip and transform space, so we can use the first squashed layer's
2302 // layoutObject to map the squashing layer's bounds into viewport space, with offsetFromAnchorLayoutObject 2304 // layoutObject to map the squashing layer's bounds into viewport space, with offsetFromAnchorLayoutObject
2303 // to translate squashing layer's bounds into the first squashed layer's space. 2305 // to translate squashing layer's bounds into the first squashed layer's space.
2304 anchorLayoutObject = m_squashedLayers[0].paintLayer->layoutObject(); 2306 anchorLayoutObject = m_squashedLayers[0].paintLayer->layoutObject();
2305 offsetFromAnchorLayoutObject = m_squashedLayers[0].offsetFromLayoutObjec t; 2307 offsetFromAnchorLayoutObject = m_squashedLayers[0].offsetFromLayoutObjec t;
2306 } else { 2308 } else {
2307 ASSERT(graphicsLayer == m_graphicsLayer.get() || graphicsLayer == m_scro llingContentsLayer.get()); 2309 ASSERT(graphicsLayer == m_graphicsLayer.get() || graphicsLayer == m_scro llingContentsLayer.get());
2308 anchorLayoutObject = m_owningLayer.layoutObject(); 2310 anchorLayoutObject = m_owningLayer.layoutObject();
2309 offsetFromAnchorLayoutObject = graphicsLayer->offsetFromLayoutObject(); 2311 offsetFromAnchorLayoutObject = graphicsLayer->offsetFromLayoutObject();
2310 adjustForCompositedScrolling(graphicsLayer, offsetFromAnchorLayoutObject ); 2312 adjustForCompositedScrolling(graphicsLayer, offsetFromAnchorLayoutObject );
2311 } 2313 }
2312 2314
2313 // Start with the bounds of the graphics layer in the space of the anchor La youtObject. 2315 // Start with the bounds of the graphics layer in the space of the anchor La youtObject.
2314 FloatRect graphicsLayerBoundsInObjectSpace(graphicsLayerBounds); 2316 FloatRect graphicsLayerBoundsInObjectSpace(graphicsLayerBounds);
2315 graphicsLayerBoundsInObjectSpace.move(offsetFromAnchorLayoutObject); 2317 graphicsLayerBoundsInObjectSpace.move(offsetFromAnchorLayoutObject);
2316 2318
2317 // Now map the bounds to its visible content rect in screen space, including applying clips along the way. 2319 // Now map the bounds to its visible content rect in root view space, includ ing applying clips along the way.
2318 LayoutRect visibleContentRect(graphicsLayerBoundsInObjectSpace); 2320 LayoutRect graphicsLayerBoundsInRootViewSpace(graphicsLayerBoundsInObjectSpa ce);
2319 LayoutView* rootView = anchorLayoutObject->view(); 2321 LayoutView* rootView = anchorLayoutObject->view();
2320 while (rootView->frame()->ownerLayoutObject()) 2322 while (rootView->frame()->ownerLayoutObject())
2321 rootView = rootView->frame()->ownerLayoutObject()->view(); 2323 rootView = rootView->frame()->ownerLayoutObject()->view();
2322 anchorLayoutObject->mapToVisualRectInAncestorSpace(rootView, visibleContentR ect); 2324 anchorLayoutObject->mapToVisualRectInAncestorSpace(rootView, graphicsLayerBo undsInRootViewSpace);
2323 visibleContentRect.intersect(LayoutRect(rootView->frameView()->visibleConten tRect())); 2325 FloatRect visibleContentRect(graphicsLayerBoundsInRootViewSpace);
2326 rootView->frameView()->clipPaintRect(&visibleContentRect);
2324 2327
2325 IntRect enclosingGraphicsLayerBounds(enclosingIntRect(graphicsLayerBounds)); 2328 IntRect enclosingGraphicsLayerBounds(enclosingIntRect(graphicsLayerBounds));
2326 2329
2327 // Map the visible content rect from screen space to local graphics layer sp ace. 2330 // Map the visible content rect from root view space to local graphics layer space.
2328 IntRect localInterestRect; 2331 IntRect localInterestRect;
2329 // If the visible content rect is empty, then it makes no sense to map it ba ck since there is nothing to map. 2332 // If the visible content rect is empty, then it makes no sense to map it ba ck since there is nothing to map.
2330 if (!visibleContentRect.isEmpty()) { 2333 if (!visibleContentRect.isEmpty()) {
2331 localInterestRect = anchorLayoutObject->absoluteToLocalQuad(FloatRect(vi sibleContentRect), UseTransforms | TraverseDocumentBoundaries).enclosingBounding Box(); 2334 localInterestRect = anchorLayoutObject->absoluteToLocalQuad(visibleConte ntRect, UseTransforms | TraverseDocumentBoundaries).enclosingBoundingBox();
2332 localInterestRect.move(-offsetFromAnchorLayoutObject); 2335 localInterestRect.move(-offsetFromAnchorLayoutObject);
2333 // TODO(chrishtr): the code below is a heuristic, instead we should dete ct and return whether the mapping failed. 2336 // TODO(chrishtr): the code below is a heuristic, instead we should dete ct and return whether the mapping failed.
2334 // In some cases, absoluteToLocalQuad can fail to map back to the local space, due to passing through 2337 // In some cases, absoluteToLocalQuad can fail to map back to the local space, due to passing through
2335 // non-invertible transforms or floating-point accuracy issues. Examples include rotation near 90 degrees 2338 // non-invertible transforms or floating-point accuracy issues. Examples include rotation near 90 degrees
2336 // or perspective. In such cases, fall back to painting the first kPixel DistanceToRecord pixels in each direction. 2339 // or perspective. In such cases, fall back to painting the first kPixel DistanceToRecord pixels in each direction.
2337 localInterestRect.intersect(enclosingGraphicsLayerBounds); 2340 localInterestRect.intersect(enclosingGraphicsLayerBounds);
2338 } 2341 }
2339 // Expand by interest rect padding amount. 2342 // Expand by interest rect padding amount.
2340 localInterestRect.inflate(kPixelDistanceToRecord); 2343 localInterestRect.inflate(kPixelDistanceToRecord);
2341 localInterestRect.intersect(enclosingGraphicsLayerBounds); 2344 localInterestRect.intersect(enclosingGraphicsLayerBounds);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
2373 if (newInterestRect.maxY() == layerSize.height() && previousInterestRect.max Y() != layerSize.height()) 2376 if (newInterestRect.maxY() == layerSize.height() && previousInterestRect.max Y() != layerSize.height())
2374 return true; 2377 return true;
2375 2378
2376 return false; 2379 return false;
2377 } 2380 }
2378 2381
2379 IntRect CompositedLayerMapping::computeInterestRect(const GraphicsLayer* graphic sLayer, const IntRect& previousInterestRect) const 2382 IntRect CompositedLayerMapping::computeInterestRect(const GraphicsLayer* graphic sLayer, const IntRect& previousInterestRect) const
2380 { 2383 {
2381 // Use the previous interest rect if it covers the whole layer. 2384 // Use the previous interest rect if it covers the whole layer.
2382 IntRect wholeLayerRect = IntRect(IntPoint(), expandedIntSize(graphicsLayer-> size())); 2385 IntRect wholeLayerRect = IntRect(IntPoint(), expandedIntSize(graphicsLayer-> size()));
2383 if (!needsRepaint(*graphicsLayer) && previousInterestRect == wholeLayerRect) 2386 if (!needsRepaint(*graphicsLayer) && previousInterestRect == wholeLayerRect)
dgozman 2016/08/29 20:45:36 I'm curios what happens if you forceViewport to co
Eric Seckler 2016/09/12 13:58:00 I think you're right, the logic for replacing old
chrishtr 2016/09/13 00:49:18 https://codereview.chromium.org/1441973003 is what
Xianzhu 2016/09/13 01:20:11 The behavior is mainly for performance. See https:
2384 return previousInterestRect; 2387 return previousInterestRect;
2385 2388
2386 // Paint the whole layer if "mainFrameClipsContent" is false, meaning that W ebPreferences::record_whole_document is true. 2389 if (graphicsLayer != m_graphicsLayer.get() && graphicsLayer != m_squashingLa yer.get() && graphicsLayer != m_scrollingContentsLayer.get())
2387 bool shouldPaintWholePage = !m_owningLayer.layoutObject()->document().settin gs()->mainFrameClipsContent();
2388 if (shouldPaintWholePage
2389 || (graphicsLayer != m_graphicsLayer.get() && graphicsLayer != m_squashi ngLayer.get() && graphicsLayer != m_scrollingContentsLayer.get()))
2390 return wholeLayerRect; 2390 return wholeLayerRect;
2391 2391
2392 IntRect newInterestRect = recomputeInterestRect(graphicsLayer); 2392 IntRect newInterestRect = recomputeInterestRect(graphicsLayer);
2393 if (interestRectChangedEnoughToRepaint(previousInterestRect, newInterestRect , expandedIntSize(graphicsLayer->size()))) 2393 if (interestRectChangedEnoughToRepaint(previousInterestRect, newInterestRect , expandedIntSize(graphicsLayer->size())))
2394 return newInterestRect; 2394 return newInterestRect;
2395 return previousInterestRect; 2395 return previousInterestRect;
2396 } 2396 }
2397 2397
2398 LayoutSize CompositedLayerMapping::subpixelAccumulation() const 2398 LayoutSize CompositedLayerMapping::subpixelAccumulation() const
2399 { 2399 {
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
2694 } else if (graphicsLayer == m_scrollingContentsLayer.get()) { 2694 } else if (graphicsLayer == m_scrollingContentsLayer.get()) {
2695 name = "Scrolling Contents Layer"; 2695 name = "Scrolling Contents Layer";
2696 } else { 2696 } else {
2697 ASSERT_NOT_REACHED(); 2697 ASSERT_NOT_REACHED();
2698 } 2698 }
2699 2699
2700 return name; 2700 return name;
2701 } 2701 }
2702 2702
2703 } // namespace blink 2703 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698