Chromium Code Reviews| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 44 } | 44 } |
| 45 drawContext->fillRectWithLocalMatrix(clip, *grp, SkMatrix::I(), maskRect, in verse); | 45 drawContext->fillRectWithLocalMatrix(clip, *grp, SkMatrix::I(), maskRect, in verse); |
| 46 return true; | 46 return true; |
| 47 } | 47 } |
| 48 | 48 |
| 49 static bool draw_with_mask_filter(GrDrawContext* drawContext, | 49 static bool draw_with_mask_filter(GrDrawContext* drawContext, |
| 50 GrTextureProvider* textureProvider, | 50 GrTextureProvider* textureProvider, |
| 51 const GrClip& clipData, | 51 const GrClip& clipData, |
| 52 const SkMatrix& viewMatrix, | 52 const SkMatrix& viewMatrix, |
| 53 const SkPath& devPath, | 53 const SkPath& devPath, |
| 54 SkMaskFilter* filter, | 54 const SkMaskFilter* filter, |
| 55 const SkIRect& clipBounds, | 55 const SkIRect& clipBounds, |
| 56 GrPaint* grp, | 56 GrPaint* grp, |
| 57 SkPaint::Style style) { | 57 SkPaint::Style style) { |
| 58 SkMask srcM, dstM; | 58 SkMask srcM, dstM; |
| 59 | 59 |
| 60 if (!SkDraw::DrawToMask(devPath, &clipBounds, filter, &viewMatrix, &srcM, | 60 if (!SkDraw::DrawToMask(devPath, &clipBounds, filter, &viewMatrix, &srcM, |
| 61 SkMask::kComputeBoundsAndRenderImage_CreateMode, sty le)) { | 61 SkMask::kComputeBoundsAndRenderImage_CreateMode, sty le)) { |
| 62 return false; | 62 return false; |
| 63 } | 63 } |
| 64 SkAutoMaskFreeImage autoSrc(srcM.fImage); | 64 SkAutoMaskFreeImage autoSrc(srcM.fImage); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 139 GrClip clip(clipRect); | 139 GrClip clip(clipRect); |
| 140 | 140 |
| 141 // Draw the mask into maskTexture with the path's integerized top-left at | 141 // Draw the mask into maskTexture with the path's integerized top-left at |
| 142 // the origin using tempPaint. | 142 // the origin using tempPaint. |
| 143 SkMatrix translate; | 143 SkMatrix translate; |
| 144 translate.setTranslate(-maskRect->fLeft, -maskRect->fTop); | 144 translate.setTranslate(-maskRect->fLeft, -maskRect->fTop); |
| 145 drawContext->drawPath(clip, tempPaint, translate, devPath, strokeInfo); | 145 drawContext->drawPath(clip, tempPaint, translate, devPath, strokeInfo); |
| 146 return mask; | 146 return mask; |
| 147 } | 147 } |
| 148 | 148 |
| 149 static void draw_path_with_mask_filter(GrContext* context, | |
| 150 GrDrawContext* drawContext, | |
| 151 GrRenderTarget* renderTarget, | |
| 152 const GrClip& clip, | |
| 153 GrPaint* paint, | |
| 154 const SkMatrix& viewMatrix, | |
| 155 const SkMaskFilter* maskFilter, | |
| 156 const SkPathEffect* pathEffect, | |
| 157 const GrStrokeInfo& origStrokeInfo, | |
| 158 SkPath* pathPtr, | |
| 159 bool pathIsMutable) { | |
| 160 SkASSERT(maskFilter); | |
| 161 | |
| 162 SkIRect clipBounds; | |
| 163 clip.getConservativeBounds(renderTarget, &clipBounds); | |
| 164 SkTLazy<SkPath> tmpPath; | |
| 165 GrStrokeInfo strokeInfo(origStrokeInfo); | |
| 166 | |
| 167 static const SkRect* cullRect = nullptr; // TODO: what is our bounds? | |
| 168 | |
| 169 if (!strokeInfo.isDashed() && pathEffect && pathEffect->filterPath(tmpPath.i nit(), *pathPtr, | |
| 170 &strokeIn fo, cullRect)) { | |
| 171 pathPtr = tmpPath.get(); | |
|
robertphillips
2015/11/05 20:13:23
do we need to set volatility here ?
bsalomon
2015/11/06 15:24:25
Done.
| |
| 172 pathIsMutable = true; | |
| 173 } | |
| 174 if (!strokeInfo.isHairlineStyle()) { | |
| 175 SkPath* strokedPath = pathIsMutable ? pathPtr : tmpPath.init(); | |
| 176 if (strokeInfo.isDashed()) { | |
| 177 if (pathEffect->filterPath(strokedPath, *pathPtr, &strokeInfo, cullR ect)) { | |
| 178 pathPtr = strokedPath; | |
|
robertphillips
2015/11/05 20:13:23
here ?
bsalomon
2015/11/06 15:24:25
Done.
| |
| 179 pathIsMutable = true; | |
| 180 } | |
| 181 strokeInfo.removeDash(); | |
| 182 } | |
| 183 if (strokeInfo.applyToPath(strokedPath, *pathPtr)) { | |
| 184 pathPtr = strokedPath; | |
| 185 pathIsMutable = true; | |
|
robertphillips
2015/11/05 20:13:23
here ?
bsalomon
2015/11/06 15:24:25
Done.
| |
| 186 strokeInfo.setFillStyle(); | |
| 187 } | |
| 188 } | |
| 189 | |
| 190 // avoid possibly allocating a new path in transform if we can | |
| 191 SkPath* devPathPtr = pathIsMutable ? pathPtr : tmpPath.init(); | |
| 192 if (!pathIsMutable) { | |
| 193 devPathPtr->setIsVolatile(true); | |
| 194 } | |
| 195 | |
| 196 // transform the path into device space | |
| 197 pathPtr->transform(viewMatrix, devPathPtr); | |
| 198 | |
| 199 SkRect maskRect; | |
| 200 if (maskFilter->canFilterMaskGPU(SkRRect::MakeRect(devPathPtr->getBounds()), | |
|
robertphillips
2015/11/05 20:13:23
tab these guys left?
bsalomon
2015/11/06 15:24:25
Done.
| |
| 201 clipBounds, | |
| 202 viewMatrix, | |
| 203 &maskRect)) { | |
| 204 SkIRect finalIRect; | |
| 205 maskRect.roundOut(&finalIRect); | |
| 206 if (clip_bounds_quick_reject(clipBounds, finalIRect)) { | |
| 207 // clipped out | |
| 208 return; | |
| 209 } | |
| 210 | |
| 211 if (maskFilter->directFilterMaskGPU(context->textureProvider(), | |
|
robertphillips
2015/11/05 20:13:24
tab these guys left too ?
bsalomon
2015/11/06 15:24:25
Done.
| |
| 212 drawContext, | |
| 213 paint, | |
| 214 clip, | |
| 215 viewMatrix, | |
| 216 strokeInfo, | |
| 217 *devPathPtr)) { | |
| 218 // the mask filter was able to draw itself directly, so there's noth ing | |
| 219 // left to do. | |
| 220 return; | |
| 221 } | |
| 222 | |
| 223 SkAutoTUnref<GrTexture> mask(create_mask_GPU(context, | |
| 224 &maskRect, | |
| 225 *devPathPtr, | |
| 226 strokeInfo, | |
| 227 paint->isAntiAlias(), | |
| 228 renderTarget->numColorSampl es())); | |
| 229 if (mask) { | |
| 230 GrTexture* filtered; | |
| 231 | |
| 232 if (maskFilter->filterMaskGPU(mask, viewMatrix, maskRect, | |
|
robertphillips
2015/11/05 20:13:23
on prior line ?
bsalomon
2015/11/06 15:24:25
Done.
| |
| 233 &filtered, true)) { | |
| 234 // filterMaskGPU gives us ownership of a ref to the result | |
| 235 SkAutoTUnref<GrTexture> atu(filtered); | |
| 236 if (draw_mask(drawContext, clip, viewMatrix, maskRect, paint, fi ltered)) { | |
| 237 // This path is completely drawn | |
| 238 return; | |
| 239 } | |
| 240 } | |
| 241 } | |
| 242 } | |
| 243 | |
| 244 // draw the mask on the CPU - this is a fallthrough path in case the | |
| 245 // GPU path fails | |
| 246 SkPaint::Style style = strokeInfo.isHairlineStyle() ? SkPaint::kStroke_Style : | |
| 247 SkPaint::kFill_Style; | |
| 248 draw_with_mask_filter(drawContext, context->textureProvider(), | |
| 249 clip, viewMatrix, *devPathPtr, | |
| 250 maskFilter, clipBounds, paint, style); | |
|
robertphillips
2015/11/05 20:13:24
rm this "return;" and the \n after it ?
bsalomon
2015/11/06 15:24:25
Done.
| |
| 251 return; | |
| 252 | |
| 253 } | |
| 254 | |
| 255 void GrBlurUtils::drawPathWithMaskFilter(GrContext* context, | |
| 256 GrDrawContext* drawContext, | |
| 257 GrRenderTarget* rt, | |
| 258 const GrClip& clip, | |
| 259 const SkPath& origPath, | |
| 260 GrPaint* paint, | |
| 261 const SkMatrix& viewMatrix, | |
| 262 const SkMaskFilter* mf, | |
| 263 const SkPathEffect* pe, | |
| 264 const GrStrokeInfo& strokeInfo) { | |
| 265 SkPath* path = const_cast<SkPath*>(&origPath); | |
| 266 draw_path_with_mask_filter(context, drawContext, rt, clip, paint, viewMatrix , mf, pe, | |
| 267 strokeInfo, path, false); | |
| 268 } | |
| 269 | |
| 149 void GrBlurUtils::drawPathWithMaskFilter(GrContext* context, | 270 void GrBlurUtils::drawPathWithMaskFilter(GrContext* context, |
| 150 GrDrawContext* drawContext, | 271 GrDrawContext* drawContext, |
| 151 GrRenderTarget* renderTarget, | 272 GrRenderTarget* renderTarget, |
| 152 const GrClip& clip, | 273 const GrClip& clip, |
| 153 const SkPath& origSrcPath, | 274 const SkPath& origSrcPath, |
| 154 const SkPaint& paint, | 275 const SkPaint& paint, |
| 155 const SkMatrix& origViewMatrix, | 276 const SkMatrix& origViewMatrix, |
| 156 const SkMatrix* prePathMatrix, | 277 const SkMatrix* prePathMatrix, |
| 157 const SkIRect& clipBounds, | 278 const SkIRect& clipBounds, |
| 158 bool pathIsMutable) { | 279 bool pathIsMutable) { |
| 159 SkASSERT(!pathIsMutable || origSrcPath.isVolatile()); | 280 SkASSERT(!pathIsMutable || origSrcPath.isVolatile()); |
| 160 | 281 |
| 161 GrStrokeInfo strokeInfo(paint); | 282 GrStrokeInfo strokeInfo(paint); |
| 162 | 283 |
| 163 // If we have a prematrix, apply it to the path, optimizing for the case | 284 // If we have a prematrix, apply it to the path, optimizing for the case |
| 164 // where the original path can in fact be modified in place (even though | 285 // where the original path can in fact be modified in place (even though |
| 165 // its parameter type is const). | 286 // its parameter type is const). |
| 166 SkPath* pathPtr = const_cast<SkPath*>(&origSrcPath); | 287 SkPath* pathPtr = const_cast<SkPath*>(&origSrcPath); |
| 167 SkTLazy<SkPath> tmpPath; | 288 SkTLazy<SkPath> tmpPath; |
| 168 SkTLazy<SkPath> effectPath; | 289 SkTLazy<SkPath> effectPath; |
| 169 SkPathEffect* pathEffect = paint.getPathEffect(); | 290 SkPathEffect* pathEffect = paint.getPathEffect(); |
| 170 | 291 |
| 171 SkMatrix viewMatrix = origViewMatrix; | 292 SkMatrix viewMatrix = origViewMatrix; |
| 172 | 293 |
| 173 if (prePathMatrix) { | 294 if (prePathMatrix) { |
| 174 // stroking, path effects, and blurs are supposed to be applied *after* the prePathMatrix. | 295 // stroking, path effects, and blurs are supposed to be applied *after* the prePathMatrix. |
| 175 // The pre-path-matrix also should not affect shading. | 296 // The pre-path-matrix also should not affect shading. |
| 176 if (nullptr == paint.getMaskFilter() && nullptr == pathEffect && nullptr == paint.getShader() && | 297 if (!paint.getMaskFilter() && !pathEffect && !paint.getShader() && |
| 177 (strokeInfo.isFillStyle() || strokeInfo.isHairlineStyle())) { | 298 (strokeInfo.isFillStyle() || strokeInfo.isHairlineStyle())) { |
| 178 viewMatrix.preConcat(*prePathMatrix); | 299 viewMatrix.preConcat(*prePathMatrix); |
| 179 } else { | 300 } else { |
| 180 SkPath* result = pathPtr; | 301 SkPath* result = pathPtr; |
| 181 | 302 |
| 182 if (!pathIsMutable) { | 303 if (!pathIsMutable) { |
| 183 result = tmpPath.init(); | 304 result = tmpPath.init(); |
| 184 result->setIsVolatile(true); | 305 result->setIsVolatile(true); |
| 185 pathIsMutable = true; | 306 pathIsMutable = true; |
| 186 } | 307 } |
| 187 // should I push prePathMatrix on our MV stack temporarily, instead | 308 // should I push prePathMatrix on our MV stack temporarily, instead |
| 188 // of applying it here? See SkDraw.cpp | 309 // of applying it here? See SkDraw.cpp |
| 189 pathPtr->transform(*prePathMatrix, result); | 310 pathPtr->transform(*prePathMatrix, result); |
| 190 pathPtr = result; | 311 pathPtr = result; |
| 191 } | 312 } |
| 192 } | 313 } |
| 193 // at this point we're done with prePathMatrix | 314 // at this point we're done with prePathMatrix |
| 194 SkDEBUGCODE(prePathMatrix = (const SkMatrix*)0x50FF8001;) | 315 SkDEBUGCODE(prePathMatrix = (const SkMatrix*)0x50FF8001;) |
| 195 | 316 |
| 196 GrPaint grPaint; | 317 GrPaint grPaint; |
| 197 if (!SkPaintToGrPaint(context, paint, viewMatrix, &grPaint)) { | 318 if (!SkPaintToGrPaint(context, paint, viewMatrix, &grPaint)) { |
| 198 return; | 319 return; |
| 199 } | 320 } |
| 200 | 321 |
| 201 const SkRect* cullRect = nullptr; // TODO: what is our bounds? | 322 if (paint.getMaskFilter()) { |
| 202 if (!strokeInfo.isDashed() && pathEffect && pathEffect->filterPath(effectPat h.init(), *pathPtr, | 323 draw_path_with_mask_filter(context, drawContext, renderTarget, clip, &gr Paint, viewMatrix, |
| 203 &strokeIn fo, cullRect)) { | 324 paint.getMaskFilter(), paint.getPathEffect(), strokeInfo, |
| 204 pathPtr = effectPath.get(); | 325 pathPtr, pathIsMutable); |
| 205 pathIsMutable = true; | 326 } else { |
|
robertphillips
2015/11/05 20:13:23
What happens if tmpPath was already activated by t
bsalomon
2015/11/06 15:24:25
Done, good catch
| |
| 327 if (!strokeInfo.isDashed() && pathEffect && pathEffect->filterPath(tmpPa th.init(), *pathPtr, | |
| 328 &stro keInfo, nullptr)) { | |
| 329 pathPtr = tmpPath.get(); | |
|
robertphillips
2015/11/05 20:13:23
volatile ?
bsalomon
2015/11/06 15:24:25
Done.
| |
| 330 pathIsMutable = true; | |
| 331 } | |
| 332 drawContext->drawPath(clip, grPaint, viewMatrix, *pathPtr, strokeInfo); | |
| 206 } | 333 } |
| 207 | |
| 208 if (paint.getMaskFilter()) { | |
| 209 if (!strokeInfo.isHairlineStyle()) { | |
| 210 SkPath* strokedPath = pathIsMutable ? pathPtr : tmpPath.init(); | |
| 211 if (strokeInfo.isDashed()) { | |
| 212 if (pathEffect->filterPath(strokedPath, *pathPtr, &strokeInfo, c ullRect)) { | |
| 213 pathPtr = strokedPath; | |
| 214 pathIsMutable = true; | |
| 215 } | |
| 216 strokeInfo.removeDash(); | |
| 217 } | |
| 218 if (strokeInfo.applyToPath(strokedPath, *pathPtr)) { | |
| 219 pathPtr = strokedPath; | |
| 220 pathIsMutable = true; | |
| 221 strokeInfo.setFillStyle(); | |
| 222 } | |
| 223 } | |
| 224 | |
| 225 // avoid possibly allocating a new path in transform if we can | |
| 226 SkPath* devPathPtr = pathIsMutable ? pathPtr : tmpPath.init(); | |
| 227 if (!pathIsMutable) { | |
| 228 devPathPtr->setIsVolatile(true); | |
| 229 } | |
| 230 | |
| 231 // transform the path into device space | |
| 232 pathPtr->transform(viewMatrix, devPathPtr); | |
| 233 | |
| 234 SkRect maskRect; | |
| 235 if (paint.getMaskFilter()->canFilterMaskGPU(SkRRect::MakeRect(devPathPtr ->getBounds()), | |
| 236 clipBounds, | |
| 237 viewMatrix, | |
| 238 &maskRect)) { | |
| 239 SkIRect finalIRect; | |
| 240 maskRect.roundOut(&finalIRect); | |
| 241 if (clip_bounds_quick_reject(clipBounds, finalIRect)) { | |
| 242 // clipped out | |
| 243 return; | |
| 244 } | |
| 245 | |
| 246 if (paint.getMaskFilter()->directFilterMaskGPU(context->textureProvi der(), | |
| 247 drawContext, | |
| 248 &grPaint, | |
| 249 clip, | |
| 250 viewMatrix, | |
| 251 strokeInfo, | |
| 252 *devPathPtr)) { | |
| 253 // the mask filter was able to draw itself directly, so there's nothing | |
| 254 // left to do. | |
| 255 return; | |
| 256 } | |
| 257 | |
| 258 SkAutoTUnref<GrTexture> mask(create_mask_GPU(context, | |
| 259 &maskRect, | |
| 260 *devPathPtr, | |
| 261 strokeInfo, | |
| 262 grPaint.isAntiAlias(), | |
| 263 renderTarget->numColorS amples())); | |
| 264 if (mask) { | |
| 265 GrTexture* filtered; | |
| 266 | |
| 267 if (paint.getMaskFilter()->filterMaskGPU(mask, viewMatrix, maskR ect, | |
| 268 &filtered, true)) { | |
| 269 // filterMaskGPU gives us ownership of a ref to the result | |
| 270 SkAutoTUnref<GrTexture> atu(filtered); | |
| 271 if (draw_mask(drawContext, | |
| 272 clip, | |
| 273 viewMatrix, | |
| 274 maskRect, | |
| 275 &grPaint, | |
| 276 filtered)) { | |
| 277 // This path is completely drawn | |
| 278 return; | |
| 279 } | |
| 280 } | |
| 281 } | |
| 282 } | |
| 283 | |
| 284 // draw the mask on the CPU - this is a fallthrough path in case the | |
| 285 // GPU path fails | |
| 286 SkPaint::Style style = strokeInfo.isHairlineStyle() ? SkPaint::kStroke_S tyle : | |
| 287 SkPaint::kFill_Sty le; | |
| 288 draw_with_mask_filter(drawContext, context->textureProvider(), | |
| 289 clip, viewMatrix, *devPathPtr, | |
| 290 paint.getMaskFilter(), clipBounds, &grPaint, style ); | |
| 291 return; | |
| 292 } | |
| 293 | |
| 294 drawContext->drawPath(clip, grPaint, viewMatrix, *pathPtr, strokeInfo); | |
| 295 } | 334 } |
| 296 | 335 |
| OLD | NEW |