| 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 } | 86 } |
| 87 texture->writePixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig, | 87 texture->writePixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig, |
| 88 dstM.fImage, dstM.fRowBytes); | 88 dstM.fImage, dstM.fRowBytes); |
| 89 | 89 |
| 90 SkRect maskRect = SkRect::Make(dstM.fBounds); | 90 SkRect maskRect = SkRect::Make(dstM.fBounds); |
| 91 | 91 |
| 92 return draw_mask(drawContext, clipData, viewMatrix, maskRect, grp, texture); | 92 return draw_mask(drawContext, clipData, viewMatrix, maskRect, grp, texture); |
| 93 } | 93 } |
| 94 | 94 |
| 95 // Create a mask of 'devPath' and place the result in 'mask'. | 95 // Create a mask of 'devPath' and place the result in 'mask'. |
| 96 static sk_sp<GrTexture> create_mask_GPU(GrContext* context, | 96 static GrTexture* create_mask_GPU(GrContext* context, |
| 97 SkRect* maskRect, | 97 SkRect* maskRect, |
| 98 const SkPath& devPath, | 98 const SkPath& devPath, |
| 99 const GrStrokeInfo& strokeInfo, | 99 const GrStrokeInfo& strokeInfo, |
| 100 bool doAA, | 100 bool doAA, |
| 101 int sampleCnt) { | 101 int sampleCnt) { |
| 102 // This mask will ultimately be drawn as a non-AA rect (see draw_mask). | 102 // This mask will ultimately be drawn as a non-AA rect (see draw_mask). |
| 103 // Non-AA rects have a bad habit of snapping arbitrarily. Integerize here | 103 // Non-AA rects have a bad habit of snapping arbitrarily. Integerize here |
| 104 // so the mask draws in a reproducible manner. | 104 // so the mask draws in a reproducible manner. |
| 105 *maskRect = SkRect::Make(maskRect->roundOut()); | 105 *maskRect = SkRect::Make(maskRect->roundOut()); |
| 106 | 106 |
| 107 if (!doAA) { | 107 GrSurfaceDesc desc; |
| 108 // Don't need MSAA if mask isn't AA | 108 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 109 sampleCnt = 0; | 109 desc.fWidth = SkScalarCeilToInt(maskRect->width()); |
| 110 desc.fHeight = SkScalarCeilToInt(maskRect->height()); |
| 111 desc.fSampleCnt = doAA ? sampleCnt : 0; |
| 112 // We actually only need A8, but it often isn't supported as a |
| 113 // render target so default to RGBA_8888 |
| 114 desc.fConfig = kRGBA_8888_GrPixelConfig; |
| 115 |
| 116 if (context->caps()->isConfigRenderable(kAlpha_8_GrPixelConfig, desc.fSample
Cnt > 0)) { |
| 117 desc.fConfig = kAlpha_8_GrPixelConfig; |
| 110 } | 118 } |
| 111 | 119 |
| 112 // We actually only need A8, but it often isn't supported as a | 120 GrTexture* mask = context->textureProvider()->createApproxTexture(desc); |
| 113 // render target so default to RGBA_8888 | 121 if (nullptr == mask) { |
| 114 GrPixelConfig config = kRGBA_8888_GrPixelConfig; | 122 return nullptr; |
| 115 if (context->caps()->isConfigRenderable(kAlpha_8_GrPixelConfig, sampleCnt >
0)) { | |
| 116 config = kAlpha_8_GrPixelConfig; | |
| 117 } | 123 } |
| 118 | 124 |
| 119 sk_sp<GrDrawContext> drawContext(context->newDrawContext(GrContext::kLoose_B
ackingFit, | 125 SkRect clipRect = SkRect::MakeWH(maskRect->width(), maskRect->height()); |
| 120 SkScalarCeilToInt(m
askRect->width()), | 126 |
| 121 SkScalarCeilToInt(m
askRect->height()), | 127 sk_sp<GrDrawContext> drawContext(context->drawContext(sk_ref_sp(mask->asRend
erTarget()))); |
| 122 config, | |
| 123 sampleCnt)); | |
| 124 if (!drawContext) { | 128 if (!drawContext) { |
| 125 return nullptr; | 129 return nullptr; |
| 126 } | 130 } |
| 127 | 131 |
| 128 drawContext->clear(nullptr, 0x0, true); | 132 drawContext->clear(nullptr, 0x0, true); |
| 129 | 133 |
| 130 GrPaint tempPaint; | 134 GrPaint tempPaint; |
| 131 tempPaint.setAntiAlias(doAA); | 135 tempPaint.setAntiAlias(doAA); |
| 132 tempPaint.setCoverageSetOpXPFactory(SkRegion::kReplace_Op); | 136 tempPaint.setCoverageSetOpXPFactory(SkRegion::kReplace_Op); |
| 133 | 137 |
| 134 // setup new clip | 138 // setup new clip |
| 135 const SkRect clipRect = SkRect::MakeWH(maskRect->width(), maskRect->height()
); | |
| 136 GrClip clip(clipRect); | 139 GrClip clip(clipRect); |
| 137 | 140 |
| 138 // 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 |
| 139 // the origin using tempPaint. | 142 // the origin using tempPaint. |
| 140 SkMatrix translate; | 143 SkMatrix translate; |
| 141 translate.setTranslate(-maskRect->fLeft, -maskRect->fTop); | 144 translate.setTranslate(-maskRect->fLeft, -maskRect->fTop); |
| 142 drawContext->drawPath(clip, tempPaint, translate, devPath, strokeInfo); | 145 drawContext->drawPath(clip, tempPaint, translate, devPath, strokeInfo); |
| 143 return drawContext->asTexture();; | 146 return mask; |
| 144 } | 147 } |
| 145 | 148 |
| 146 static void draw_path_with_mask_filter(GrContext* context, | 149 static void draw_path_with_mask_filter(GrContext* context, |
| 147 GrDrawContext* drawContext, | 150 GrDrawContext* drawContext, |
| 148 const GrClip& clip, | 151 const GrClip& clip, |
| 149 GrPaint* paint, | 152 GrPaint* paint, |
| 150 const SkMatrix& viewMatrix, | 153 const SkMatrix& viewMatrix, |
| 151 const SkMaskFilter* maskFilter, | 154 const SkMaskFilter* maskFilter, |
| 152 const SkPathEffect* pathEffect, | 155 const SkPathEffect* pathEffect, |
| 153 const GrStrokeInfo& origStrokeInfo, | 156 const GrStrokeInfo& origStrokeInfo, |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 paint, | 212 paint, |
| 210 clip, | 213 clip, |
| 211 viewMatrix, | 214 viewMatrix, |
| 212 strokeInfo, | 215 strokeInfo, |
| 213 *devPathPtr)) { | 216 *devPathPtr)) { |
| 214 // the mask filter was able to draw itself directly, so there's noth
ing | 217 // the mask filter was able to draw itself directly, so there's noth
ing |
| 215 // left to do. | 218 // left to do. |
| 216 return; | 219 return; |
| 217 } | 220 } |
| 218 | 221 |
| 219 sk_sp<GrTexture> mask(create_mask_GPU(context, | 222 SkAutoTUnref<GrTexture> mask(create_mask_GPU(context, |
| 220 &maskRect, | 223 &maskRect, |
| 221 *devPathPtr, | 224 *devPathPtr, |
| 222 strokeInfo, | 225 strokeInfo, |
| 223 paint->isAntiAlias(), | 226 paint->isAntiAlias(), |
| 224 drawContext->numColorSamples())); | 227 drawContext->numColorSample
s())); |
| 225 if (mask) { | 228 if (mask) { |
| 226 GrTexture* filtered; | 229 GrTexture* filtered; |
| 227 | 230 |
| 228 if (maskFilter->filterMaskGPU(mask.get(), viewMatrix, maskRect, &fil
tered, true)) { | 231 if (maskFilter->filterMaskGPU(mask, viewMatrix, maskRect, &filtered,
true)) { |
| 229 // filterMaskGPU gives us ownership of a ref to the result | 232 // filterMaskGPU gives us ownership of a ref to the result |
| 230 SkAutoTUnref<GrTexture> atu(filtered); | 233 SkAutoTUnref<GrTexture> atu(filtered); |
| 231 if (draw_mask(drawContext, clip, viewMatrix, maskRect, paint, fi
ltered)) { | 234 if (draw_mask(drawContext, clip, viewMatrix, maskRect, paint, fi
ltered)) { |
| 232 // This path is completely drawn | 235 // This path is completely drawn |
| 233 return; | 236 return; |
| 234 } | 237 } |
| 235 } | 238 } |
| 236 } | 239 } |
| 237 } | 240 } |
| 238 | 241 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 } | 341 } |
| 339 | 342 |
| 340 if (paint.getMaskFilter()) { | 343 if (paint.getMaskFilter()) { |
| 341 draw_path_with_mask_filter(context, drawContext, clip, &grPaint, viewMat
rix, | 344 draw_path_with_mask_filter(context, drawContext, clip, &grPaint, viewMat
rix, |
| 342 paint.getMaskFilter(), pathEffect, strokeInfo
, | 345 paint.getMaskFilter(), pathEffect, strokeInfo
, |
| 343 pathPtr, pathIsMutable); | 346 pathPtr, pathIsMutable); |
| 344 } else { | 347 } else { |
| 345 drawContext->drawPath(clip, grPaint, viewMatrix, *pathPtr, strokeInfo); | 348 drawContext->drawPath(clip, grPaint, viewMatrix, *pathPtr, strokeInfo); |
| 346 } | 349 } |
| 347 } | 350 } |
| OLD | NEW |