Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "core/paint/BoxClipper.h" | 6 #include "core/paint/BoxClipper.h" |
| 7 | 7 |
| 8 #include "core/layout/LayoutBox.h" | 8 #include "core/layout/LayoutBox.h" |
| 9 #include "core/paint/DeprecatedPaintLayer.h" | 9 #include "core/paint/DeprecatedPaintLayer.h" |
| 10 #include "core/paint/PaintInfo.h" | 10 #include "core/paint/PaintInfo.h" |
| 11 #include "platform/RuntimeEnabledFeatures.h" | 11 #include "platform/RuntimeEnabledFeatures.h" |
| 12 #include "platform/graphics/GraphicsLayer.h" | 12 #include "platform/graphics/GraphicsLayer.h" |
| 13 #include "platform/graphics/paint/ClipDisplayItem.h" | 13 #include "platform/graphics/paint/ClipDisplayItem.h" |
| 14 #include "platform/graphics/paint/DisplayItemList.h" | 14 #include "platform/graphics/paint/DisplayItemList.h" |
| 15 | 15 |
| 16 namespace blink { | 16 namespace blink { |
| 17 | 17 |
| 18 BoxClipper::BoxClipper(LayoutBox& box, const PaintInfo& paintInfo, const LayoutP oint& accumulatedOffset, ContentsClipBehavior contentsClipBehavior) | 18 BoxClipper::BoxClipper(const LayoutBox& box, const PaintInfo& paintInfo, const L ayoutPoint& accumulatedOffset, ContentsClipBehavior contentsClipBehavior) |
| 19 : m_pushedClip(false) | 19 : m_box(box) |
| 20 , m_accumulatedOffset(accumulatedOffset) | |
| 21 , m_paintInfo(paintInfo) | 20 , m_paintInfo(paintInfo) |
| 22 , m_box(box) | 21 , m_clipType(DisplayItem::UninitializedType) |
| 23 , m_clipType(DisplayItem::ClipBoxPaintPhaseFirst) | |
| 24 { | 22 { |
| 25 if (m_paintInfo.phase == PaintPhaseBlockBackground || m_paintInfo.phase == P aintPhaseSelfOutline || m_paintInfo.phase == PaintPhaseMask) | 23 if (m_paintInfo.phase == PaintPhaseBlockBackground || m_paintInfo.phase == P aintPhaseSelfOutline || m_paintInfo.phase == PaintPhaseMask) |
| 26 return; | 24 return; |
| 27 | 25 |
| 28 bool isControlClip = m_box.hasControlClip(); | 26 bool isControlClip = m_box.hasControlClip(); |
| 29 bool isOverflowClip = m_box.hasOverflowClip() && !m_box.layer()->isSelfPaint ingLayer(); | 27 bool isOverflowClip = m_box.hasOverflowClip() && !m_box.layer()->isSelfPaint ingLayer(); |
| 30 | 28 |
| 31 if (!isControlClip && !isOverflowClip) | 29 if (!isControlClip && !isOverflowClip) |
| 32 return; | 30 return; |
| 33 | 31 |
| 34 LayoutRect clipRect = isControlClip ? m_box.controlClipRect(m_accumulatedOff set) : m_box.overflowClipRect(m_accumulatedOffset); | 32 LayoutRect clipRect = isControlClip ? m_box.controlClipRect(accumulatedOffse t) : m_box.overflowClipRect(accumulatedOffset); |
| 35 FloatRoundedRect clipRoundedRect(0, 0, 0, 0); | 33 FloatRoundedRect clipRoundedRect(0, 0, 0, 0); |
| 36 bool hasBorderRadius = m_box.style()->hasBorderRadius(); | 34 bool hasBorderRadius = m_box.style()->hasBorderRadius(); |
| 37 if (hasBorderRadius) | 35 if (hasBorderRadius) |
| 38 clipRoundedRect = m_box.style()->getRoundedInnerBorderFor(LayoutRect(m_a ccumulatedOffset, m_box.size())); | 36 clipRoundedRect = m_box.style()->getRoundedInnerBorderFor(LayoutRect(acc umulatedOffset, m_box.size())); |
| 39 | 37 |
| 40 if (contentsClipBehavior == SkipContentsClipIfPossible) { | 38 if (contentsClipBehavior == SkipContentsClipIfPossible) { |
| 41 LayoutRect contentsVisualOverflow = m_box.contentsVisualOverflowRect(); | 39 LayoutRect contentsVisualOverflow = m_box.contentsVisualOverflowRect(); |
| 42 if (contentsVisualOverflow.isEmpty()) | 40 if (contentsVisualOverflow.isEmpty()) |
| 43 return; | 41 return; |
| 44 | 42 |
| 45 LayoutRect conservativeClipRect = clipRect; | 43 LayoutRect conservativeClipRect = clipRect; |
| 46 if (hasBorderRadius) | 44 if (hasBorderRadius) |
| 47 conservativeClipRect.intersect(LayoutRect(clipRoundedRect.radiusCent erRect())); | 45 conservativeClipRect.intersect(LayoutRect(clipRoundedRect.radiusCent erRect())); |
| 48 conservativeClipRect.moveBy(-m_accumulatedOffset); | 46 conservativeClipRect.moveBy(-accumulatedOffset); |
| 49 if (m_box.hasLayer()) | 47 if (m_box.hasLayer()) |
| 50 conservativeClipRect.move(m_box.scrolledContentOffset()); | 48 conservativeClipRect.move(m_box.scrolledContentOffset()); |
| 51 if (conservativeClipRect.contains(contentsVisualOverflow)) | 49 if (conservativeClipRect.contains(contentsVisualOverflow)) |
| 52 return; | 50 return; |
| 53 } | 51 } |
| 54 | 52 |
| 55 OwnPtr<Vector<FloatRoundedRect>> roundedRects; | 53 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) { |
| 56 if (hasBorderRadius) { | 54 ASSERT(m_paintInfo.context->displayItemList()); |
| 57 roundedRects = adoptPtr(new Vector<FloatRoundedRect>()); | 55 if (!m_paintInfo.context->displayItemList()->displayItemConstructionIsDi sabled()) { |
| 58 roundedRects->append(clipRoundedRect); | 56 m_clipType = m_paintInfo.displayItemTypeForClipping(); |
| 57 OwnPtr<Vector<FloatRoundedRect>> roundedRects; | |
|
jbroman
2015/06/29 18:11:56
This code is used in both paths; suggest lifting i
jbroman
2015/06/29 18:11:56
Not introduced in this change, but why the double
| |
| 58 if (hasBorderRadius) { | |
| 59 roundedRects = adoptPtr(new Vector<FloatRoundedRect>()); | |
| 60 roundedRects->append(clipRoundedRect); | |
| 61 } | |
| 62 m_paintInfo.context->displayItemList()->createAndAppend<ClipDisplayI tem>(m_box, m_clipType, pixelSnappedIntRect(clipRect), roundedRects.release()); | |
| 63 } | |
| 64 } else { | |
| 65 m_clipType = m_paintInfo.displayItemTypeForClipping(); | |
| 66 OwnPtr<Vector<FloatRoundedRect>> roundedRects; | |
| 67 if (hasBorderRadius) { | |
| 68 roundedRects = adoptPtr(new Vector<FloatRoundedRect>()); | |
| 69 roundedRects->append(clipRoundedRect); | |
| 70 } | |
| 71 ClipDisplayItem clipDisplayItem(m_box, m_clipType, pixelSnappedIntRect(c lipRect), roundedRects.release()); | |
| 72 clipDisplayItem.replay(*paintInfo.context); | |
| 59 } | 73 } |
| 60 | |
| 61 OwnPtr<ClipDisplayItem> clipDisplayItem = ClipDisplayItem::create(m_box, m_c lipType, pixelSnappedIntRect(clipRect), roundedRects.release()); | |
| 62 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) { | |
| 63 m_clipType = m_paintInfo.displayItemTypeForClipping(); | |
| 64 ASSERT(m_paintInfo.context->displayItemList()); | |
| 65 if (!m_paintInfo.context->displayItemList()->displayItemConstructionIsDi sabled()) | |
| 66 m_paintInfo.context->displayItemList()->add(clipDisplayItem.release( )); | |
| 67 } else { | |
| 68 clipDisplayItem->replay(*paintInfo.context); | |
| 69 } | |
| 70 | |
| 71 m_pushedClip = true; | |
| 72 } | 74 } |
| 73 | 75 |
| 74 BoxClipper::~BoxClipper() | 76 BoxClipper::~BoxClipper() |
| 75 { | 77 { |
| 76 if (!m_pushedClip) | 78 if (m_clipType == DisplayItem::UninitializedType) |
|
danakj
2015/06/29 17:43:51
now the assert below will not run if slimming pain
| |
| 77 return; | 79 return; |
| 78 | 80 |
| 79 ASSERT(m_box.hasControlClip() || (m_box.hasOverflowClip() && !m_box.layer()- >isSelfPaintingLayer())); | 81 ASSERT(m_box.hasControlClip() || (m_box.hasOverflowClip() && !m_box.layer()- >isSelfPaintingLayer())); |
| 80 | 82 |
| 81 DisplayItem::Type endType = DisplayItem::clipTypeToEndClipType(m_clipType); | |
| 82 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) { | 83 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) { |
| 83 ASSERT(m_paintInfo.context->displayItemList()); | 84 ASSERT(m_paintInfo.context->displayItemList()); |
| 84 if (!m_paintInfo.context->displayItemList()->displayItemConstructionIsDi sabled()) { | 85 if (!m_paintInfo.context->displayItemList()->displayItemConstructionIsDi sabled()) { |
| 85 if (m_paintInfo.context->displayItemList()->lastDisplayItemIsNoopBeg in()) | 86 if (m_paintInfo.context->displayItemList()->lastDisplayItemIsNoopBeg in()) |
| 86 m_paintInfo.context->displayItemList()->removeLastDisplayItem(); | 87 m_paintInfo.context->displayItemList()->removeLastDisplayItem(); |
| 87 else | 88 else |
| 88 m_paintInfo.context->displayItemList()->add(EndClipDisplayItem:: create(m_box, endType)); | 89 m_paintInfo.context->displayItemList()->createAndAppend<EndClipD isplayItem>(m_box, DisplayItem::clipTypeToEndClipType(m_clipType)); |
| 89 } | 90 } |
| 90 } else { | 91 } else { |
| 91 EndClipDisplayItem endClipDisplayItem(m_box, endType); | 92 EndClipDisplayItem endClipDisplayItem(m_box, DisplayItem::clipTypeToEndC lipType(m_clipType)); |
| 92 endClipDisplayItem.replay(*m_paintInfo.context); | 93 endClipDisplayItem.replay(*m_paintInfo.context); |
| 93 } | 94 } |
| 94 } | 95 } |
| 95 | 96 |
| 96 } // namespace blink | 97 } // namespace blink |
| OLD | NEW |