| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/RoundedInnerRectClipper.h" | 6 #include "core/paint/RoundedInnerRectClipper.h" |
| 7 | 7 |
| 8 #include "core/layout/LayoutBox.h" | 8 #include "core/layout/LayoutBox.h" |
| 9 #include "core/paint/PaintInfo.h" | 9 #include "core/paint/PaintInfo.h" |
| 10 #include "platform/graphics/paint/ClipDisplayItem.h" | 10 #include "platform/graphics/paint/ClipDisplayItem.h" |
| 11 #include "platform/graphics/paint/DisplayItemList.h" | 11 #include "platform/graphics/paint/DisplayItemList.h" |
| 12 | 12 |
| 13 namespace blink { | 13 namespace blink { |
| 14 | 14 |
| 15 RoundedInnerRectClipper::RoundedInnerRectClipper(LayoutObject& layoutObject, con
st PaintInfo& paintInfo, const LayoutRect& rect, const FloatRoundedRect& clipRec
t, RoundedInnerRectClipperBehavior behavior) | 15 RoundedInnerRectClipper::RoundedInnerRectClipper(LayoutObject& layoutObject, con
st PaintInfo& paintInfo) |
| 16 : m_layoutObject(layoutObject) | 16 : m_layoutObject(layoutObject) |
| 17 , m_paintInfo(paintInfo) | 17 , m_paintInfo(paintInfo) |
| 18 , m_useDisplayItemList(RuntimeEnabledFeatures::slimmingPaintEnabled() && beh
avior == ApplyToDisplayListIfEnabled) | 18 , m_useDisplayItemList(false) |
| 19 , m_clipType(m_useDisplayItemList ? m_paintInfo.displayItemTypeForClipping()
: DisplayItem::ClipBoxPaintPhaseFirst) | 19 , m_clipType(DisplayItem::ClipBoxPaintPhaseFirst) |
| 20 , m_engaged(false) |
| 20 { | 21 { |
| 21 OwnPtr<ClipDisplayItem> clipDisplayItem = ClipDisplayItem::create(layoutObje
ct, m_clipType, LayoutRect::infiniteIntRect()); | 22 } |
| 23 |
| 24 RoundedInnerRectClipper::RoundedInnerRectClipper(LayoutObject& layoutObject, con
st PaintInfo& paintInfo, const LayoutRect& rect, const FloatRoundedRect& clipRec
t, RoundedInnerRectClipperBehavior behavior) |
| 25 : RoundedInnerRectClipper(layoutObject, paintInfo) |
| 26 { |
| 27 begin(rect, clipRect, behavior); |
| 28 } |
| 29 |
| 30 RoundedInnerRectClipper::~RoundedInnerRectClipper() |
| 31 { |
| 32 if (!m_engaged) |
| 33 return; |
| 34 |
| 35 DisplayItem::Type endType = DisplayItem::clipTypeToEndClipType(m_clipType); |
| 36 if (m_useDisplayItemList) { |
| 37 ASSERT(m_paintInfo.context->displayItemList()); |
| 38 if (m_paintInfo.context->displayItemList()->displayItemConstructionIsDis
abled()) |
| 39 return; |
| 40 OwnPtr<EndClipDisplayItem> endClipDisplayItem = EndClipDisplayItem::crea
te(m_layoutObject, endType); |
| 41 m_paintInfo.context->displayItemList()->add(endClipDisplayItem.release()
); |
| 42 } else { |
| 43 EndClipDisplayItem endClipDisplayItem(m_layoutObject, endType); |
| 44 endClipDisplayItem.replay(*m_paintInfo.context); |
| 45 } |
| 46 } |
| 47 |
| 48 void RoundedInnerRectClipper::begin(const LayoutRect& rect, const FloatRoundedRe
ct& clipRect, RoundedInnerRectClipperBehavior behavior) |
| 49 { |
| 50 ASSERT(!m_engaged); |
| 51 m_engaged = true; |
| 52 |
| 53 m_useDisplayItemList = RuntimeEnabledFeatures::slimmingPaintEnabled() && beh
avior == ApplyToDisplayListIfEnabled; |
| 54 m_clipType = m_useDisplayItemList ? m_paintInfo.displayItemTypeForClipping()
: DisplayItem::ClipBoxPaintPhaseFirst; |
| 55 |
| 56 OwnPtr<ClipDisplayItem> clipDisplayItem = ClipDisplayItem::create(m_layoutOb
ject, m_clipType, LayoutRect::infiniteIntRect()); |
| 22 | 57 |
| 23 if (clipRect.isRenderable()) { | 58 if (clipRect.isRenderable()) { |
| 24 clipDisplayItem->roundedRectClips().append(clipRect); | 59 clipDisplayItem->roundedRectClips().append(clipRect); |
| 25 } else { | 60 } else { |
| 26 // We create a rounded rect for each of the corners and clip it, while m
aking sure we clip opposing corners together. | 61 // We create a rounded rect for each of the corners and clip it, while m
aking sure we clip opposing corners together. |
| 27 if (!clipRect.radii().topLeft().isEmpty() || !clipRect.radii().bottomRig
ht().isEmpty()) { | 62 if (!clipRect.radii().topLeft().isEmpty() || !clipRect.radii().bottomRig
ht().isEmpty()) { |
| 28 FloatRect topCorner(clipRect.rect().x(), clipRect.rect().y(), rect.m
axX() - clipRect.rect().x(), rect.maxY() - clipRect.rect().y()); | 63 FloatRect topCorner(clipRect.rect().x(), clipRect.rect().y(), rect.m
axX() - clipRect.rect().x(), rect.maxY() - clipRect.rect().y()); |
| 29 FloatRoundedRect::Radii topCornerRadii; | 64 FloatRoundedRect::Radii topCornerRadii; |
| 30 topCornerRadii.setTopLeft(clipRect.radii().topLeft()); | 65 topCornerRadii.setTopLeft(clipRect.radii().topLeft()); |
| 31 clipDisplayItem->roundedRectClips().append(FloatRoundedRect(topCorne
r, topCornerRadii)); | 66 clipDisplayItem->roundedRectClips().append(FloatRoundedRect(topCorne
r, topCornerRadii)); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 48 clipDisplayItem->roundedRectClips().append(FloatRoundedRect(bottomCo
rner, bottomCornerRadii)); | 83 clipDisplayItem->roundedRectClips().append(FloatRoundedRect(bottomCo
rner, bottomCornerRadii)); |
| 49 } | 84 } |
| 50 } | 85 } |
| 51 | 86 |
| 52 if (m_useDisplayItemList) { | 87 if (m_useDisplayItemList) { |
| 53 ASSERT(m_paintInfo.context->displayItemList()); | 88 ASSERT(m_paintInfo.context->displayItemList()); |
| 54 if (m_paintInfo.context->displayItemList()->displayItemConstructionIsDis
abled()) | 89 if (m_paintInfo.context->displayItemList()->displayItemConstructionIsDis
abled()) |
| 55 return; | 90 return; |
| 56 m_paintInfo.context->displayItemList()->add(clipDisplayItem.release()); | 91 m_paintInfo.context->displayItemList()->add(clipDisplayItem.release()); |
| 57 } else { | 92 } else { |
| 58 clipDisplayItem->replay(*paintInfo.context); | 93 clipDisplayItem->replay(*m_paintInfo.context); |
| 59 } | 94 } |
| 60 } | 95 } |
| 61 | 96 |
| 62 RoundedInnerRectClipper::~RoundedInnerRectClipper() | |
| 63 { | |
| 64 DisplayItem::Type endType = DisplayItem::clipTypeToEndClipType(m_clipType); | |
| 65 if (m_useDisplayItemList) { | |
| 66 ASSERT(m_paintInfo.context->displayItemList()); | |
| 67 if (m_paintInfo.context->displayItemList()->displayItemConstructionIsDis
abled()) | |
| 68 return; | |
| 69 OwnPtr<EndClipDisplayItem> endClipDisplayItem = EndClipDisplayItem::crea
te(m_layoutObject, endType); | |
| 70 m_paintInfo.context->displayItemList()->add(endClipDisplayItem.release()
); | |
| 71 } else { | |
| 72 EndClipDisplayItem endClipDisplayItem(m_layoutObject, endType); | |
| 73 endClipDisplayItem.replay(*m_paintInfo.context); | |
| 74 } | |
| 75 } | |
| 76 | |
| 77 } // namespace blink | 97 } // namespace blink |
| OLD | NEW |