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

Side by Side Diff: Source/core/paint/BoxClipper.cpp

Issue 1212293003: Clean up BoxClipper (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 5 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
« no previous file with comments | « Source/core/paint/BoxClipper.h ('k') | Source/platform/graphics/paint/DisplayItem.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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;
56 if (hasBorderRadius) {
57 roundedRects = adoptPtr(new Vector<FloatRoundedRect>());
58 roundedRects->append(clipRoundedRect);
59 }
60
61 OwnPtr<ClipDisplayItem> clipDisplayItem = ClipDisplayItem::create(m_box, m_c lipType, pixelSnappedIntRect(clipRect), roundedRects.release());
62 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) { 53 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) {
54 ASSERT(m_paintInfo.context->displayItemList());
55 if (!m_paintInfo.context->displayItemList()->displayItemConstructionIsDi sabled()) {
56 m_clipType = m_paintInfo.displayItemTypeForClipping();
57 OwnPtr<Vector<FloatRoundedRect>> roundedRects;
58 if (hasBorderRadius) {
59 roundedRects = adoptPtr(new Vector<FloatRoundedRect>());
60 roundedRects->append(clipRoundedRect);
61 }
62 OwnPtr<ClipDisplayItem> clipDisplayItem = ClipDisplayItem::create(m_ box, m_clipType, pixelSnappedIntRect(clipRect), roundedRects.release());
63 m_paintInfo.context->displayItemList()->add(clipDisplayItem.release( ));
64 }
65 } else {
63 m_clipType = m_paintInfo.displayItemTypeForClipping(); 66 m_clipType = m_paintInfo.displayItemTypeForClipping();
64 ASSERT(m_paintInfo.context->displayItemList()); 67 OwnPtr<Vector<FloatRoundedRect>> roundedRects;
65 if (!m_paintInfo.context->displayItemList()->displayItemConstructionIsDi sabled()) 68 if (hasBorderRadius) {
66 m_paintInfo.context->displayItemList()->add(clipDisplayItem.release( )); 69 roundedRects = adoptPtr(new Vector<FloatRoundedRect>());
67 } else { 70 roundedRects->append(clipRoundedRect);
71 }
72 OwnPtr<ClipDisplayItem> clipDisplayItem = ClipDisplayItem::create(m_box, m_clipType, pixelSnappedIntRect(clipRect), roundedRects.release());
68 clipDisplayItem->replay(*paintInfo.context); 73 clipDisplayItem->replay(*paintInfo.context);
69 } 74 }
70
71 m_pushedClip = true;
72 } 75 }
73 76
74 BoxClipper::~BoxClipper() 77 BoxClipper::~BoxClipper()
75 { 78 {
76 if (!m_pushedClip) 79 if (m_clipType == DisplayItem::UninitializedType)
77 return; 80 return;
78 81
79 ASSERT(m_box.hasControlClip() || (m_box.hasOverflowClip() && !m_box.layer()- >isSelfPaintingLayer())); 82 ASSERT(m_box.hasControlClip() || (m_box.hasOverflowClip() && !m_box.layer()- >isSelfPaintingLayer()));
80 83
81 DisplayItem::Type endType = DisplayItem::clipTypeToEndClipType(m_clipType);
82 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) { 84 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) {
83 ASSERT(m_paintInfo.context->displayItemList()); 85 ASSERT(m_paintInfo.context->displayItemList());
84 if (!m_paintInfo.context->displayItemList()->displayItemConstructionIsDi sabled()) { 86 if (!m_paintInfo.context->displayItemList()->displayItemConstructionIsDi sabled()) {
85 if (m_paintInfo.context->displayItemList()->lastDisplayItemIsNoopBeg in()) 87 if (m_paintInfo.context->displayItemList()->lastDisplayItemIsNoopBeg in())
86 m_paintInfo.context->displayItemList()->removeLastDisplayItem(); 88 m_paintInfo.context->displayItemList()->removeLastDisplayItem();
87 else 89 else
88 m_paintInfo.context->displayItemList()->add(EndClipDisplayItem:: create(m_box, endType)); 90 m_paintInfo.context->displayItemList()->add(EndClipDisplayItem:: create(m_box, DisplayItem::clipTypeToEndClipType(m_clipType)));
89 } 91 }
90 } else { 92 } else {
91 EndClipDisplayItem endClipDisplayItem(m_box, endType); 93 EndClipDisplayItem endClipDisplayItem(m_box, DisplayItem::clipTypeToEndC lipType(m_clipType));
92 endClipDisplayItem.replay(*m_paintInfo.context); 94 endClipDisplayItem.replay(*m_paintInfo.context);
93 } 95 }
94 } 96 }
95 97
96 } // namespace blink 98 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/paint/BoxClipper.h ('k') | Source/platform/graphics/paint/DisplayItem.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698