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

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

Issue 979883002: [S.P.] Move clip painting to SVGClipPainter. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: code shuffling 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "config.h"
6 #include "core/paint/SVGClipPainter.h"
7
8 #include "core/dom/ElementTraversal.h"
9 #include "core/layout/PaintInfo.h"
10 #include "core/layout/svg/LayoutSVGResourceClipper.h"
11 #include "core/layout/svg/SVGResources.h"
12 #include "core/layout/svg/SVGResourcesCache.h"
13 #include "core/paint/CompositingRecorder.h"
14 #include "core/paint/TransformRecorder.h"
15 #include "platform/graphics/paint/ClipPathDisplayItem.h"
16 #include "platform/graphics/paint/CompositingDisplayItem.h"
17 #include "platform/graphics/paint/DisplayItemList.h"
18 #include "platform/graphics/paint/DrawingDisplayItem.h"
19 #include "wtf/TemporaryChange.h"
20
21 namespace blink {
22
23 bool SVGClipPainter::applyStatefulResource(LayoutObject* object, GraphicsContext *& context, ClipperState& clipperState)
24 {
25 ASSERT(object);
26 ASSERT(context);
27
28 m_clip.clearInvalidationMask();
29
30 return applyClippingToContext(object, object->objectBoundingBox(), object->p aintInvalidationRectInLocalCoordinates(), context, clipperState);
31 }
32
33 class SVGClipExpansionCycleHelper {
34 public:
35 SVGClipExpansionCycleHelper(LayoutSVGResourceClipper& clip) : m_clip(clip) { clip.beginClipExpansion(); }
36 ~SVGClipExpansionCycleHelper() { m_clip.endClipExpansion(); }
37 private:
38 LayoutSVGResourceClipper& m_clip;
39 };
40
41 bool SVGClipPainter::applyClippingToContext(LayoutObject* target, const FloatRec t& targetBoundingBox,
42 const FloatRect& paintInvalidationRect, GraphicsContext* context, ClipperSta te& clipperState)
43 {
44 ASSERT(target);
45 ASSERT(context);
46 ASSERT(clipperState == ClipperNotApplied);
47 ASSERT_WITH_SECURITY_IMPLICATION(!m_clip.needsLayout());
48
49 if (paintInvalidationRect.isEmpty() || m_clip.hasCycle())
50 return false;
51
52 SVGClipExpansionCycleHelper inClipExpansionChange(m_clip);
53
54 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.
56 // 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).
58 if (!target->isSVG() && m_clip.clipPathUnits() == SVGUnitTypes::SVG_UNIT_TYP E_USERSPACEONUSE) {
59 ASSERT(m_clip.style());
60 animatedLocalTransform.scale(m_clip.style()->effectiveZoom());
61 }
62
63 // First, try to apply the clip as a clipPath.
64 if (m_clip.tryPathOnlyClipping(target->displayItemClient(), context, animate dLocalTransform, targetBoundingBox)) {
65 clipperState = ClipperAppliedPath;
66 return true;
67 }
68
69 // Fall back to masking.
70 clipperState = ClipperAppliedMask;
71
72 // Begin compositing the clip mask.
73 CompositingRecorder::beginCompositing(context, target->displayItemClient(), SkXfermode::kSrcOver_Mode, 1, &paintInvalidationRect);
74 {
75 TransformRecorder recorder(*context, target->displayItemClient(), animat edLocalTransform);
76
77 // clipPath can also be clipped by another clipPath.
78 SVGResources* resources = SVGResourcesCache::cachedResourcesForLayoutObj ect(&m_clip);
79 LayoutSVGResourceClipper* clipPathClipper = resources ? resources->clipp er() : 0;
80 ClipperState clipPathClipperState = ClipperNotApplied;
81 if (clipPathClipper && !SVGClipPainter(*clipPathClipper).applyClippingTo Context(&m_clip, targetBoundingBox, paintInvalidationRect, context, clipPathClip perState)) {
82 // End the clip mask's compositor.
83 CompositingRecorder::endCompositing(context, target->displayItemClie nt());
84 return false;
85 }
86
87 drawClipMaskContent(context, target->displayItemClient(), targetBounding Box);
88
89 if (clipPathClipper)
90 SVGClipPainter(*clipPathClipper).postApplyStatefulResource(&m_clip, context, clipPathClipperState);
91 }
92
93 // Masked content layer start.
94 CompositingRecorder::beginCompositing(context, target->displayItemClient(), SkXfermode::kSrcIn_Mode, 1, &paintInvalidationRect);
95
96 return true;
97 }
98
99 void SVGClipPainter::postApplyStatefulResource(LayoutObject* target, GraphicsCon text*& context, ClipperState& clipperState)
100 {
101 switch (clipperState) {
102 case ClipperAppliedPath:
103 // Path-only clipping, no layers to restore but we need to emit an end t o the clip path display item.
104 {
pdr. 2015/03/05 22:21:16 Are these braces needed?
Erik Dahlström (inactive) 2015/03/06 11:55:49 Doesn't seem like it. Consider them gone.
105 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) {
106 context->displayItemList()->add(EndClipPathDisplayItem::create(t arget->displayItemClient()));
107 } else {
108 EndClipPathDisplayItem endClipPathDisplayItem(target->displayIte mClient());
109 endClipPathDisplayItem.replay(context);
110 }
111 }
112 break;
113 case ClipperAppliedMask:
114 // Transfer content -> clip mask (SrcIn)
115 CompositingRecorder::endCompositing(context, target->displayItemClient() );
116
117 // Transfer clip mask -> bg (SrcOver)
118 CompositingRecorder::endCompositing(context, target->displayItemClient() );
119 break;
120 default:
121 ASSERT_NOT_REACHED();
122 }
123 }
124
125 void SVGClipPainter::drawClipMaskContent(GraphicsContext* context, DisplayItemCl ient client, const FloatRect& targetBoundingBox)
126 {
127 ASSERT(context);
128
129 AffineTransform contentTransformation;
130 RefPtr<const SkPicture> clipContentPicture = m_clip.createContentPicture(con tentTransformation, targetBoundingBox);
131
132 TransformRecorder recorder(*context, client, contentTransformation);
133 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) {
134 ASSERT(context->displayItemList());
135 context->displayItemList()->add(DrawingDisplayItem::create(client, Displ ayItem::SVGClip, clipContentPicture));
136 } else {
137 DrawingDisplayItem clipPicture(client, DisplayItem::SVGClip, clipContent Picture);
138 clipPicture.replay(context);
139 }
140 }
141
142 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698