OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "GrBlurUtils.h" | 8 #include "GrBlurUtils.h" |
9 #include "GrDrawContext.h" | 9 #include "GrDrawContext.h" |
10 #include "GrCaps.h" | 10 #include "GrCaps.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 GrPaint* grp, | 59 GrPaint* grp, |
60 SkPaint::Style style) { | 60 SkPaint::Style style) { |
61 SkMask srcM, dstM; | 61 SkMask srcM, dstM; |
62 | 62 |
63 if (!SkDraw::DrawToMask(devPath, &clipBounds, filter, &viewMatrix, &srcM, | 63 if (!SkDraw::DrawToMask(devPath, &clipBounds, filter, &viewMatrix, &srcM, |
64 SkMask::kComputeBoundsAndRenderImage_CreateMode, sty
le)) { | 64 SkMask::kComputeBoundsAndRenderImage_CreateMode, sty
le)) { |
65 return false; | 65 return false; |
66 } | 66 } |
67 SkAutoMaskFreeImage autoSrc(srcM.fImage); | 67 SkAutoMaskFreeImage autoSrc(srcM.fImage); |
68 | 68 |
69 if (!filter->filterMask(&dstM, srcM, viewMatrix, NULL)) { | 69 if (!filter->filterMask(&dstM, srcM, viewMatrix, nullptr)) { |
70 return false; | 70 return false; |
71 } | 71 } |
72 // this will free-up dstM when we're done (allocated in filterMask()) | 72 // this will free-up dstM when we're done (allocated in filterMask()) |
73 SkAutoMaskFreeImage autoDst(dstM.fImage); | 73 SkAutoMaskFreeImage autoDst(dstM.fImage); |
74 | 74 |
75 if (clip_bounds_quick_reject(clipBounds, dstM.fBounds)) { | 75 if (clip_bounds_quick_reject(clipBounds, dstM.fBounds)) { |
76 return false; | 76 return false; |
77 } | 77 } |
78 | 78 |
79 // we now have a device-aligned 8bit mask in dstM, ready to be drawn using | 79 // we now have a device-aligned 8bit mask in dstM, ready to be drawn using |
(...skipping 29 matching lines...) Expand all Loading... |
109 desc.fSampleCnt = doAA ? sampleCnt : 0; | 109 desc.fSampleCnt = doAA ? sampleCnt : 0; |
110 // We actually only need A8, but it often isn't supported as a | 110 // We actually only need A8, but it often isn't supported as a |
111 // render target so default to RGBA_8888 | 111 // render target so default to RGBA_8888 |
112 desc.fConfig = kRGBA_8888_GrPixelConfig; | 112 desc.fConfig = kRGBA_8888_GrPixelConfig; |
113 | 113 |
114 if (context->caps()->isConfigRenderable(kAlpha_8_GrPixelConfig, desc.fSample
Cnt > 0)) { | 114 if (context->caps()->isConfigRenderable(kAlpha_8_GrPixelConfig, desc.fSample
Cnt > 0)) { |
115 desc.fConfig = kAlpha_8_GrPixelConfig; | 115 desc.fConfig = kAlpha_8_GrPixelConfig; |
116 } | 116 } |
117 | 117 |
118 GrTexture* mask = context->textureProvider()->createApproxTexture(desc); | 118 GrTexture* mask = context->textureProvider()->createApproxTexture(desc); |
119 if (NULL == mask) { | 119 if (nullptr == mask) { |
120 return NULL; | 120 return nullptr; |
121 } | 121 } |
122 | 122 |
123 SkRect clipRect = SkRect::MakeWH(maskRect.width(), maskRect.height()); | 123 SkRect clipRect = SkRect::MakeWH(maskRect.width(), maskRect.height()); |
124 | 124 |
125 GrDrawContext* drawContext = context->drawContext(); | 125 GrDrawContext* drawContext = context->drawContext(); |
126 if (!drawContext) { | 126 if (!drawContext) { |
127 return NULL; | 127 return nullptr; |
128 } | 128 } |
129 | 129 |
130 drawContext->clear(mask->asRenderTarget(), NULL, 0x0, true); | 130 drawContext->clear(mask->asRenderTarget(), nullptr, 0x0, true); |
131 | 131 |
132 GrPaint tempPaint; | 132 GrPaint tempPaint; |
133 tempPaint.setAntiAlias(doAA); | 133 tempPaint.setAntiAlias(doAA); |
134 tempPaint.setCoverageSetOpXPFactory(SkRegion::kReplace_Op); | 134 tempPaint.setCoverageSetOpXPFactory(SkRegion::kReplace_Op); |
135 | 135 |
136 // setup new clip | 136 // setup new clip |
137 GrClip clip(clipRect); | 137 GrClip clip(clipRect); |
138 | 138 |
139 // Draw the mask into maskTexture with the path's top-left at the origin usi
ng tempPaint. | 139 // Draw the mask into maskTexture with the path's top-left at the origin usi
ng tempPaint. |
140 SkMatrix translate; | 140 SkMatrix translate; |
(...skipping 22 matching lines...) Expand all Loading... |
163 SkPath* pathPtr = const_cast<SkPath*>(&origSrcPath); | 163 SkPath* pathPtr = const_cast<SkPath*>(&origSrcPath); |
164 SkTLazy<SkPath> tmpPath; | 164 SkTLazy<SkPath> tmpPath; |
165 SkTLazy<SkPath> effectPath; | 165 SkTLazy<SkPath> effectPath; |
166 SkPathEffect* pathEffect = paint.getPathEffect(); | 166 SkPathEffect* pathEffect = paint.getPathEffect(); |
167 | 167 |
168 SkMatrix viewMatrix = origViewMatrix; | 168 SkMatrix viewMatrix = origViewMatrix; |
169 | 169 |
170 if (prePathMatrix) { | 170 if (prePathMatrix) { |
171 // stroking, path effects, and blurs are supposed to be applied *after*
the prePathMatrix. | 171 // stroking, path effects, and blurs are supposed to be applied *after*
the prePathMatrix. |
172 // The pre-path-matrix also should not affect shading. | 172 // The pre-path-matrix also should not affect shading. |
173 if (NULL == paint.getMaskFilter() && NULL == pathEffect && NULL == paint
.getShader() && | 173 if (nullptr == paint.getMaskFilter() && nullptr == pathEffect && nullptr
== paint.getShader() && |
174 (strokeInfo.isFillStyle() || strokeInfo.isHairlineStyle())) { | 174 (strokeInfo.isFillStyle() || strokeInfo.isHairlineStyle())) { |
175 viewMatrix.preConcat(*prePathMatrix); | 175 viewMatrix.preConcat(*prePathMatrix); |
176 } else { | 176 } else { |
177 SkPath* result = pathPtr; | 177 SkPath* result = pathPtr; |
178 | 178 |
179 if (!pathIsMutable) { | 179 if (!pathIsMutable) { |
180 result = tmpPath.init(); | 180 result = tmpPath.init(); |
181 result->setIsVolatile(true); | 181 result->setIsVolatile(true); |
182 pathIsMutable = true; | 182 pathIsMutable = true; |
183 } | 183 } |
184 // should I push prePathMatrix on our MV stack temporarily, instead | 184 // should I push prePathMatrix on our MV stack temporarily, instead |
185 // of applying it here? See SkDraw.cpp | 185 // of applying it here? See SkDraw.cpp |
186 pathPtr->transform(*prePathMatrix, result); | 186 pathPtr->transform(*prePathMatrix, result); |
187 pathPtr = result; | 187 pathPtr = result; |
188 } | 188 } |
189 } | 189 } |
190 // at this point we're done with prePathMatrix | 190 // at this point we're done with prePathMatrix |
191 SkDEBUGCODE(prePathMatrix = (const SkMatrix*)0x50FF8001;) | 191 SkDEBUGCODE(prePathMatrix = (const SkMatrix*)0x50FF8001;) |
192 | 192 |
193 GrPaint grPaint; | 193 GrPaint grPaint; |
194 if (!SkPaint2GrPaint(context, renderTarget, paint, viewMatrix, true, &grPain
t)) { | 194 if (!SkPaint2GrPaint(context, renderTarget, paint, viewMatrix, true, &grPain
t)) { |
195 return; | 195 return; |
196 } | 196 } |
197 | 197 |
198 const SkRect* cullRect = NULL; // TODO: what is our bounds? | 198 const SkRect* cullRect = nullptr; // TODO: what is our bounds? |
199 if (!strokeInfo.isDashed() && pathEffect && pathEffect->filterPath(effectPat
h.init(), *pathPtr, | 199 if (!strokeInfo.isDashed() && pathEffect && pathEffect->filterPath(effectPat
h.init(), *pathPtr, |
200 &strokeIn
fo, cullRect)) { | 200 &strokeIn
fo, cullRect)) { |
201 pathPtr = effectPath.get(); | 201 pathPtr = effectPath.get(); |
202 pathIsMutable = true; | 202 pathIsMutable = true; |
203 } | 203 } |
204 | 204 |
205 if (paint.getMaskFilter()) { | 205 if (paint.getMaskFilter()) { |
206 if (!strokeInfo.isHairlineStyle()) { | 206 if (!strokeInfo.isHairlineStyle()) { |
207 SkPath* strokedPath = pathIsMutable ? pathPtr : tmpPath.init(); | 207 SkPath* strokedPath = pathIsMutable ? pathPtr : tmpPath.init(); |
208 if (strokeInfo.isDashed()) { | 208 if (strokeInfo.isDashed()) { |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 SkPaint::kFill_Sty
le; | 286 SkPaint::kFill_Sty
le; |
287 draw_with_mask_filter(drawContext, context->textureProvider(), renderTar
get, | 287 draw_with_mask_filter(drawContext, context->textureProvider(), renderTar
get, |
288 clip, viewMatrix, *devPathPtr, | 288 clip, viewMatrix, *devPathPtr, |
289 paint.getMaskFilter(), clipBounds, &grPaint, style
); | 289 paint.getMaskFilter(), clipBounds, &grPaint, style
); |
290 return; | 290 return; |
291 } | 291 } |
292 | 292 |
293 drawContext->drawPath(renderTarget, clip, grPaint, viewMatrix, *pathPtr, str
okeInfo); | 293 drawContext->drawPath(renderTarget, clip, grPaint, viewMatrix, *pathPtr, str
okeInfo); |
294 } | 294 } |
295 | 295 |
OLD | NEW |