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

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

Issue 1035463002: [S.P.] Use LayoutObject references instead of pointers. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: codereview fixes Created 5 years, 9 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/SVGClipPainter.h ('k') | Source/core/paint/SVGPaintContext.cpp » ('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 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/SVGClipPainter.h" 6 #include "core/paint/SVGClipPainter.h"
7 7
8 #include "core/dom/ElementTraversal.h" 8 #include "core/dom/ElementTraversal.h"
9 #include "core/layout/PaintInfo.h" 9 #include "core/layout/PaintInfo.h"
10 #include "core/layout/svg/LayoutSVGResourceClipper.h" 10 #include "core/layout/svg/LayoutSVGResourceClipper.h"
11 #include "core/layout/svg/SVGResources.h" 11 #include "core/layout/svg/SVGResources.h"
12 #include "core/layout/svg/SVGResourcesCache.h" 12 #include "core/layout/svg/SVGResourcesCache.h"
13 #include "core/paint/CompositingRecorder.h" 13 #include "core/paint/CompositingRecorder.h"
14 #include "core/paint/TransformRecorder.h" 14 #include "core/paint/TransformRecorder.h"
15 #include "platform/graphics/paint/ClipPathDisplayItem.h" 15 #include "platform/graphics/paint/ClipPathDisplayItem.h"
16 #include "platform/graphics/paint/CompositingDisplayItem.h" 16 #include "platform/graphics/paint/CompositingDisplayItem.h"
17 #include "platform/graphics/paint/DisplayItemList.h" 17 #include "platform/graphics/paint/DisplayItemList.h"
18 #include "platform/graphics/paint/DrawingDisplayItem.h" 18 #include "platform/graphics/paint/DrawingDisplayItem.h"
19 #include "wtf/TemporaryChange.h" 19 #include "wtf/TemporaryChange.h"
20 20
21 namespace blink { 21 namespace blink {
22 22
23 bool SVGClipPainter::applyStatefulResource(LayoutObject* object, GraphicsContext * context, ClipperState& clipperState) 23 bool SVGClipPainter::applyStatefulResource(const LayoutObject& object, GraphicsC ontext* context, ClipperState& clipperState)
24 { 24 {
25 ASSERT(object);
26 ASSERT(context); 25 ASSERT(context);
27 26
28 m_clip.clearInvalidationMask(); 27 m_clip.clearInvalidationMask();
29 28
30 return applyClippingToContext(object, object->objectBoundingBox(), object->p aintInvalidationRectInLocalCoordinates(), context, clipperState); 29 return applyClippingToContext(object, object.objectBoundingBox(), object.pai ntInvalidationRectInLocalCoordinates(), context, clipperState);
31 } 30 }
32 31
33 class SVGClipExpansionCycleHelper { 32 class SVGClipExpansionCycleHelper {
34 public: 33 public:
35 SVGClipExpansionCycleHelper(LayoutSVGResourceClipper& clip) : m_clip(clip) { clip.beginClipExpansion(); } 34 SVGClipExpansionCycleHelper(LayoutSVGResourceClipper& clip) : m_clip(clip) { clip.beginClipExpansion(); }
36 ~SVGClipExpansionCycleHelper() { m_clip.endClipExpansion(); } 35 ~SVGClipExpansionCycleHelper() { m_clip.endClipExpansion(); }
37 private: 36 private:
38 LayoutSVGResourceClipper& m_clip; 37 LayoutSVGResourceClipper& m_clip;
39 }; 38 };
40 39
41 bool SVGClipPainter::applyClippingToContext(LayoutObject* target, const FloatRec t& targetBoundingBox, 40 bool SVGClipPainter::applyClippingToContext(const LayoutObject& target, const Fl oatRect& targetBoundingBox,
42 const FloatRect& paintInvalidationRect, GraphicsContext* context, ClipperSta te& clipperState) 41 const FloatRect& paintInvalidationRect, GraphicsContext* context, ClipperSta te& clipperState)
43 { 42 {
44 ASSERT(target);
45 ASSERT(context); 43 ASSERT(context);
46 ASSERT(clipperState == ClipperNotApplied); 44 ASSERT(clipperState == ClipperNotApplied);
47 ASSERT_WITH_SECURITY_IMPLICATION(!m_clip.needsLayout()); 45 ASSERT_WITH_SECURITY_IMPLICATION(!m_clip.needsLayout());
48 46
49 if (paintInvalidationRect.isEmpty() || m_clip.hasCycle()) 47 if (paintInvalidationRect.isEmpty() || m_clip.hasCycle())
50 return false; 48 return false;
51 49
52 SVGClipExpansionCycleHelper inClipExpansionChange(m_clip); 50 SVGClipExpansionCycleHelper inClipExpansionChange(m_clip);
53 51
54 AffineTransform animatedLocalTransform = toSVGClipPathElement(m_clip.element ())->calculateAnimatedLocalTransform(); 52 AffineTransform animatedLocalTransform = toSVGClipPathElement(m_clip.element ())->calculateAnimatedLocalTransform();
55 // When drawing a clip for non-SVG elements, the CTM does not include the zo om factor. 53 // When drawing a clip for non-SVG elements, the CTM does not include the zo om factor.
56 // In this case, we need to apply the zoom scale explicitly - but only for c lips with 54 // In this case, we need to apply the zoom scale explicitly - but only for c lips with
57 // userSpaceOnUse units (the zoom is accounted for objectBoundingBox-resolve d lengths). 55 // userSpaceOnUse units (the zoom is accounted for objectBoundingBox-resolve d lengths).
58 if (!target->isSVG() && m_clip.clipPathUnits() == SVGUnitTypes::SVG_UNIT_TYP E_USERSPACEONUSE) { 56 if (!target.isSVG() && m_clip.clipPathUnits() == SVGUnitTypes::SVG_UNIT_TYPE _USERSPACEONUSE) {
59 ASSERT(m_clip.style()); 57 ASSERT(m_clip.style());
60 animatedLocalTransform.scale(m_clip.style()->effectiveZoom()); 58 animatedLocalTransform.scale(m_clip.style()->effectiveZoom());
61 } 59 }
62 60
63 // First, try to apply the clip as a clipPath. 61 // First, try to apply the clip as a clipPath.
64 if (m_clip.tryPathOnlyClipping(target->displayItemClient(), context, animate dLocalTransform, targetBoundingBox)) { 62 if (m_clip.tryPathOnlyClipping(target.displayItemClient(), context, animated LocalTransform, targetBoundingBox)) {
65 clipperState = ClipperAppliedPath; 63 clipperState = ClipperAppliedPath;
66 return true; 64 return true;
67 } 65 }
68 66
69 // Fall back to masking. 67 // Fall back to masking.
70 clipperState = ClipperAppliedMask; 68 clipperState = ClipperAppliedMask;
71 69
72 // Begin compositing the clip mask. 70 // Begin compositing the clip mask.
73 CompositingRecorder::beginCompositing(context, target->displayItemClient(), SkXfermode::kSrcOver_Mode, 1, &paintInvalidationRect); 71 CompositingRecorder::beginCompositing(context, target.displayItemClient(), S kXfermode::kSrcOver_Mode, 1, &paintInvalidationRect);
74 { 72 {
75 TransformRecorder recorder(*context, target->displayItemClient(), animat edLocalTransform); 73 TransformRecorder recorder(*context, target.displayItemClient(), animate dLocalTransform);
76 74
77 // clipPath can also be clipped by another clipPath. 75 // clipPath can also be clipped by another clipPath.
78 SVGResources* resources = SVGResourcesCache::cachedResourcesForLayoutObj ect(&m_clip); 76 SVGResources* resources = SVGResourcesCache::cachedResourcesForLayoutObj ect(&m_clip);
79 LayoutSVGResourceClipper* clipPathClipper = resources ? resources->clipp er() : 0; 77 LayoutSVGResourceClipper* clipPathClipper = resources ? resources->clipp er() : 0;
80 ClipperState clipPathClipperState = ClipperNotApplied; 78 ClipperState clipPathClipperState = ClipperNotApplied;
81 if (clipPathClipper && !SVGClipPainter(*clipPathClipper).applyClippingTo Context(&m_clip, targetBoundingBox, paintInvalidationRect, context, clipPathClip perState)) { 79 if (clipPathClipper && !SVGClipPainter(*clipPathClipper).applyClippingTo Context(m_clip, targetBoundingBox, paintInvalidationRect, context, clipPathClipp erState)) {
82 // End the clip mask's compositor. 80 // End the clip mask's compositor.
83 CompositingRecorder::endCompositing(context, target->displayItemClie nt()); 81 CompositingRecorder::endCompositing(context, target.displayItemClien t());
84 return false; 82 return false;
85 } 83 }
86 84
87 drawClipMaskContent(context, target->displayItemClient(), targetBounding Box); 85 drawClipMaskContent(context, target.displayItemClient(), targetBoundingB ox);
88 86
89 if (clipPathClipper) 87 if (clipPathClipper)
90 SVGClipPainter(*clipPathClipper).postApplyStatefulResource(&m_clip, context, clipPathClipperState); 88 SVGClipPainter(*clipPathClipper).postApplyStatefulResource(m_clip, c ontext, clipPathClipperState);
91 } 89 }
92 90
93 // Masked content layer start. 91 // Masked content layer start.
94 CompositingRecorder::beginCompositing(context, target->displayItemClient(), SkXfermode::kSrcIn_Mode, 1, &paintInvalidationRect); 92 CompositingRecorder::beginCompositing(context, target.displayItemClient(), S kXfermode::kSrcIn_Mode, 1, &paintInvalidationRect);
95 93
96 return true; 94 return true;
97 } 95 }
98 96
99 void SVGClipPainter::postApplyStatefulResource(LayoutObject* target, GraphicsCon text* context, ClipperState& clipperState) 97 void SVGClipPainter::postApplyStatefulResource(const LayoutObject& target, Graph icsContext* context, ClipperState& clipperState)
100 { 98 {
101 switch (clipperState) { 99 switch (clipperState) {
102 case ClipperAppliedPath: 100 case ClipperAppliedPath:
103 // Path-only clipping, no layers to restore but we need to emit an end t o the clip path display item. 101 // Path-only clipping, no layers to restore but we need to emit an end t o the clip path display item.
104 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) { 102 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) {
105 context->displayItemList()->add(EndClipPathDisplayItem::create(targe t->displayItemClient())); 103 context->displayItemList()->add(EndClipPathDisplayItem::create(targe t.displayItemClient()));
106 } else { 104 } else {
107 EndClipPathDisplayItem endClipPathDisplayItem(target->displayItemCli ent()); 105 EndClipPathDisplayItem endClipPathDisplayItem(target.displayItemClie nt());
108 endClipPathDisplayItem.replay(context); 106 endClipPathDisplayItem.replay(context);
109 } 107 }
110 break; 108 break;
111 case ClipperAppliedMask: 109 case ClipperAppliedMask:
112 // Transfer content -> clip mask (SrcIn) 110 // Transfer content -> clip mask (SrcIn)
113 CompositingRecorder::endCompositing(context, target->displayItemClient() ); 111 CompositingRecorder::endCompositing(context, target.displayItemClient()) ;
114 112
115 // Transfer clip mask -> bg (SrcOver) 113 // Transfer clip mask -> bg (SrcOver)
116 CompositingRecorder::endCompositing(context, target->displayItemClient() ); 114 CompositingRecorder::endCompositing(context, target.displayItemClient()) ;
117 break; 115 break;
118 default: 116 default:
119 ASSERT_NOT_REACHED(); 117 ASSERT_NOT_REACHED();
120 } 118 }
121 } 119 }
122 120
123 void SVGClipPainter::drawClipMaskContent(GraphicsContext* context, DisplayItemCl ient client, const FloatRect& targetBoundingBox) 121 void SVGClipPainter::drawClipMaskContent(GraphicsContext* context, DisplayItemCl ient client, const FloatRect& targetBoundingBox)
124 { 122 {
125 ASSERT(context); 123 ASSERT(context);
126 124
127 AffineTransform contentTransformation; 125 AffineTransform contentTransformation;
128 RefPtr<const SkPicture> clipContentPicture = m_clip.createContentPicture(con tentTransformation, targetBoundingBox); 126 RefPtr<const SkPicture> clipContentPicture = m_clip.createContentPicture(con tentTransformation, targetBoundingBox);
129 127
130 TransformRecorder recorder(*context, client, contentTransformation); 128 TransformRecorder recorder(*context, client, contentTransformation);
131 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) { 129 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) {
132 ASSERT(context->displayItemList()); 130 ASSERT(context->displayItemList());
133 context->displayItemList()->add(DrawingDisplayItem::create(client, Displ ayItem::SVGClip, clipContentPicture)); 131 context->displayItemList()->add(DrawingDisplayItem::create(client, Displ ayItem::SVGClip, clipContentPicture));
134 } else { 132 } else {
135 DrawingDisplayItem clipPicture(client, DisplayItem::SVGClip, clipContent Picture); 133 DrawingDisplayItem clipPicture(client, DisplayItem::SVGClip, clipContent Picture);
136 clipPicture.replay(context); 134 clipPicture.replay(context);
137 } 135 }
138 } 136 }
139 137
140 } 138 }
OLDNEW
« no previous file with comments | « Source/core/paint/SVGClipPainter.h ('k') | Source/core/paint/SVGPaintContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698