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 "GrRenderTargetContext.h" | 9 #include "GrRenderTargetContext.h" |
10 #include "GrCaps.h" | 10 #include "GrCaps.h" |
11 #include "GrContext.h" | 11 #include "GrContext.h" |
12 #include "GrFixedClip.h" | 12 #include "GrFixedClip.h" |
13 #include "effects/GrSimpleTextureEffect.h" | 13 #include "effects/GrSimpleTextureEffect.h" |
14 #include "GrStyle.h" | 14 #include "GrStyle.h" |
15 #include "GrTexture.h" | 15 #include "GrTexture.h" |
| 16 #include "GrTextureProxy.h" |
16 #include "GrTextureProvider.h" | 17 #include "GrTextureProvider.h" |
17 #include "SkDraw.h" | 18 #include "SkDraw.h" |
18 #include "SkGrPriv.h" | 19 #include "SkGrPriv.h" |
19 #include "SkMaskFilter.h" | 20 #include "SkMaskFilter.h" |
20 #include "SkPaint.h" | 21 #include "SkPaint.h" |
21 #include "SkTLazy.h" | 22 #include "SkTLazy.h" |
22 | 23 |
23 static bool clip_bounds_quick_reject(const SkIRect& clipBounds, const SkIRect& r
ect) { | 24 static bool clip_bounds_quick_reject(const SkIRect& clipBounds, const SkIRect& r
ect) { |
24 return clipBounds.isEmpty() || rect.isEmpty() || !SkIRect::Intersects(clipBo
unds, rect); | 25 return clipBounds.isEmpty() || rect.isEmpty() || !SkIRect::Intersects(clipBo
unds, rect); |
25 } | 26 } |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 if (!texture) { | 86 if (!texture) { |
86 return false; | 87 return false; |
87 } | 88 } |
88 texture->writePixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig, | 89 texture->writePixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig, |
89 dstM.fImage, dstM.fRowBytes); | 90 dstM.fImage, dstM.fRowBytes); |
90 | 91 |
91 return draw_mask(renderTargetContext, clipData, viewMatrix, dstM.fBounds, gr
p, texture.get()); | 92 return draw_mask(renderTargetContext, clipData, viewMatrix, dstM.fBounds, gr
p, texture.get()); |
92 } | 93 } |
93 | 94 |
94 // Create a mask of 'devPath' and place the result in 'mask'. | 95 // Create a mask of 'devPath' and place the result in 'mask'. |
95 static sk_sp<GrTexture> create_mask_GPU(GrContext* context, | 96 static sk_sp<GrTextureProxy> create_mask_GPU(GrContext* context, |
96 const SkIRect& maskRect, | 97 const SkIRect& maskRect, |
97 const SkPath& devPath, | 98 const SkPath& devPath, |
98 SkStrokeRec::InitStyle fillOrHairline, | 99 SkStrokeRec::InitStyle fillOrHairli
ne, |
99 bool doAA, | 100 bool doAA, |
100 int sampleCnt) { | 101 int sampleCnt) { |
101 if (!doAA) { | 102 if (!doAA) { |
102 // Don't need MSAA if mask isn't AA | 103 // Don't need MSAA if mask isn't AA |
103 sampleCnt = 0; | 104 sampleCnt = 0; |
104 } | 105 } |
105 | 106 |
106 sk_sp<GrRenderTargetContext> renderTargetContext(context->makeRenderTargetCo
ntextWithFallback( | 107 sk_sp<GrRenderTargetContext> rtContext(context->makeDeferredRenderTargetCont
extWithFallback( |
107 SkBackingFit::kApprox, maskRect.width(), maskRect.height(), kAlpha_8_GrP
ixelConfig, nullptr, | 108 SkBackingFit::kApprox, maskRect.width(), maskRect.height(), kAlpha_8_GrP
ixelConfig, nullptr, |
108 sampleCnt)); | 109 sampleCnt)); |
109 if (!renderTargetContext) { | 110 if (!rtContext) { |
110 return nullptr; | 111 return nullptr; |
111 } | 112 } |
112 | 113 |
113 renderTargetContext->clear(nullptr, 0x0, true); | 114 rtContext->clear(nullptr, 0x0, true); |
114 | 115 |
115 GrPaint tempPaint; | 116 GrPaint tempPaint; |
116 tempPaint.setAntiAlias(doAA); | 117 tempPaint.setAntiAlias(doAA); |
117 tempPaint.setCoverageSetOpXPFactory(SkRegion::kReplace_Op); | 118 tempPaint.setCoverageSetOpXPFactory(SkRegion::kReplace_Op); |
118 | 119 |
119 // setup new clip | 120 // setup new clip |
120 const SkIRect clipRect = SkIRect::MakeWH(maskRect.width(), maskRect.height()
); | 121 const SkIRect clipRect = SkIRect::MakeWH(maskRect.width(), maskRect.height()
); |
121 GrFixedClip clip(clipRect); | 122 GrFixedClip clip(clipRect); |
122 | 123 |
123 // Draw the mask into maskTexture with the path's integerized top-left at | 124 // Draw the mask into maskTexture with the path's integerized top-left at |
124 // the origin using tempPaint. | 125 // the origin using tempPaint. |
125 SkMatrix translate; | 126 SkMatrix translate; |
126 translate.setTranslate(-SkIntToScalar(maskRect.fLeft), -SkIntToScalar(maskRe
ct.fTop)); | 127 translate.setTranslate(-SkIntToScalar(maskRect.fLeft), -SkIntToScalar(maskRe
ct.fTop)); |
127 renderTargetContext->drawPath(clip, tempPaint, translate, devPath, GrStyle(f
illOrHairline)); | 128 rtContext->drawPath(clip, tempPaint, translate, devPath, GrStyle(fillOrHairl
ine)); |
128 return renderTargetContext->asTexture();; | 129 return sk_ref_sp(rtContext->asDeferredTexture()); |
129 } | 130 } |
130 | 131 |
131 static void draw_path_with_mask_filter(GrContext* context, | 132 static void draw_path_with_mask_filter(GrContext* context, |
132 GrRenderTargetContext* renderTargetContex
t, | 133 GrRenderTargetContext* renderTargetContex
t, |
133 const GrClip& clip, | 134 const GrClip& clip, |
134 GrPaint* paint, | 135 GrPaint* paint, |
135 const SkMatrix& viewMatrix, | 136 const SkMatrix& viewMatrix, |
136 const SkMaskFilter* maskFilter, | 137 const SkMaskFilter* maskFilter, |
137 const GrStyle& style, | 138 const GrStyle& style, |
138 const SkPath* path, | 139 const SkPath* path, |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 paint, | 198 paint, |
198 clip, | 199 clip, |
199 viewMatrix, | 200 viewMatrix, |
200 SkStrokeRec(fillOrHairline), | 201 SkStrokeRec(fillOrHairline), |
201 *path)) { | 202 *path)) { |
202 // the mask filter was able to draw itself directly, so there's noth
ing | 203 // the mask filter was able to draw itself directly, so there's noth
ing |
203 // left to do. | 204 // left to do. |
204 return; | 205 return; |
205 } | 206 } |
206 | 207 |
207 sk_sp<GrTexture> mask(create_mask_GPU(context, | 208 sk_sp<GrTextureProxy> maskProxy(create_mask_GPU(context, |
208 finalIRect, | 209 finalIRect, |
209 *path, | 210 *path, |
210 fillOrHairline, | 211 fillOrHairline, |
211 paint->isAntiAlias(), | 212 paint->isAntiAlias(), |
212 renderTargetContext->numColorSampl
es())); | 213 renderTargetContext->num
ColorSamples())); |
213 if (mask) { | 214 if (maskProxy) { |
214 GrTexture* filtered; | 215 GrTexture* filtered; |
215 | 216 |
216 if (maskFilter->filterMaskGPU(mask.get(), viewMatrix, finalIRect, &f
iltered)) { | 217 GrTexture* mask = maskProxy->instantiate(context->textureProvider())
; |
| 218 if (!mask) { |
| 219 return; |
| 220 } |
| 221 |
| 222 if (maskFilter->filterMaskGPU(mask, viewMatrix, finalIRect, &filtere
d)) { |
217 // filterMaskGPU gives us ownership of a ref to the result | 223 // filterMaskGPU gives us ownership of a ref to the result |
218 sk_sp<GrTexture> atu(filtered); | 224 sk_sp<GrTexture> atu(filtered); |
219 if (draw_mask(renderTargetContext, clip, viewMatrix, finalIRect,
paint, filtered)) { | 225 if (draw_mask(renderTargetContext, clip, viewMatrix, finalIRect,
paint, filtered)) { |
220 // This path is completely drawn | 226 // This path is completely drawn |
221 return; | 227 return; |
222 } | 228 } |
223 } | 229 } |
224 } | 230 } |
225 } | 231 } |
226 | 232 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 SkMaskFilter* mf = paint.getMaskFilter(); | 292 SkMaskFilter* mf = paint.getMaskFilter(); |
287 if (mf && !mf->asFragmentProcessor(nullptr, nullptr, viewMatrix)) { | 293 if (mf && !mf->asFragmentProcessor(nullptr, nullptr, viewMatrix)) { |
288 // The MaskFilter wasn't already handled in SkPaintToGrPaint | 294 // The MaskFilter wasn't already handled in SkPaintToGrPaint |
289 draw_path_with_mask_filter(context, renderTargetContext, clip, &grPaint,
viewMatrix, | 295 draw_path_with_mask_filter(context, renderTargetContext, clip, &grPaint,
viewMatrix, |
290 mf, style, | 296 mf, style, |
291 path, pathIsMutable); | 297 path, pathIsMutable); |
292 } else { | 298 } else { |
293 renderTargetContext->drawPath(clip, grPaint, viewMatrix, *path, style); | 299 renderTargetContext->drawPath(clip, grPaint, viewMatrix, *path, style); |
294 } | 300 } |
295 } | 301 } |
OLD | NEW |