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