Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: src/gpu/GrBlurUtils.cpp

Issue 1404823005: GrDrawContext now holds GrRenderTarget pointer (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix overlength line Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/effects/SkXfermodeImageFilter.cpp ('k') | src/gpu/GrContext.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "GrContext.h" 11 #include "GrContext.h"
12 #include "effects/GrSimpleTextureEffect.h" 12 #include "effects/GrSimpleTextureEffect.h"
13 #include "GrStrokeInfo.h" 13 #include "GrStrokeInfo.h"
14 #include "GrTexture.h" 14 #include "GrTexture.h"
15 #include "GrTextureProvider.h" 15 #include "GrTextureProvider.h"
16 #include "SkDraw.h" 16 #include "SkDraw.h"
17 #include "SkGrPriv.h" 17 #include "SkGrPriv.h"
18 #include "SkMaskFilter.h" 18 #include "SkMaskFilter.h"
19 #include "SkPaint.h" 19 #include "SkPaint.h"
20 20
21 static bool clip_bounds_quick_reject(const SkIRect& clipBounds, const SkIRect& r ect) { 21 static bool clip_bounds_quick_reject(const SkIRect& clipBounds, const SkIRect& r ect) {
22 return clipBounds.isEmpty() || rect.isEmpty() || !SkIRect::Intersects(clipBo unds, rect); 22 return clipBounds.isEmpty() || rect.isEmpty() || !SkIRect::Intersects(clipBo unds, rect);
23 } 23 }
24 24
25 // Draw a mask using the supplied paint. Since the coverage/geometry 25 // Draw a mask using the supplied paint. Since the coverage/geometry
26 // is already burnt into the mask this boils down to a rect draw. 26 // is already burnt into the mask this boils down to a rect draw.
27 // Return true if the mask was successfully drawn. 27 // Return true if the mask was successfully drawn.
28 static bool draw_mask(GrDrawContext* drawContext, 28 static bool draw_mask(GrDrawContext* drawContext,
29 GrRenderTarget* rt,
30 const GrClip& clip, 29 const GrClip& clip,
31 const SkMatrix& viewMatrix, 30 const SkMatrix& viewMatrix,
32 const SkRect& maskRect, 31 const SkRect& maskRect,
33 GrPaint* grp, 32 GrPaint* grp,
34 GrTexture* mask) { 33 GrTexture* mask) {
35 SkMatrix matrix; 34 SkMatrix matrix;
36 matrix.setTranslate(-maskRect.fLeft, -maskRect.fTop); 35 matrix.setTranslate(-maskRect.fLeft, -maskRect.fTop);
37 matrix.postIDiv(mask->width(), mask->height()); 36 matrix.postIDiv(mask->width(), mask->height());
38 37
39 grp->addCoverageFragmentProcessor(GrSimpleTextureEffect::Create(mask, matrix , 38 grp->addCoverageFragmentProcessor(GrSimpleTextureEffect::Create(mask, matrix ,
40 kDevice_GrCo ordSet))->unref(); 39 kDevice_GrCo ordSet))->unref();
41 40
42 SkMatrix inverse; 41 SkMatrix inverse;
43 if (!viewMatrix.invert(&inverse)) { 42 if (!viewMatrix.invert(&inverse)) {
44 return false; 43 return false;
45 } 44 }
46 drawContext->drawNonAARectWithLocalMatrix(rt, clip, *grp, SkMatrix::I(), mas kRect, inverse); 45 drawContext->drawNonAARectWithLocalMatrix(clip, *grp, SkMatrix::I(), maskRec t, inverse);
47 return true; 46 return true;
48 } 47 }
49 48
50 static bool draw_with_mask_filter(GrDrawContext* drawContext, 49 static bool draw_with_mask_filter(GrDrawContext* drawContext,
51 GrTextureProvider* textureProvider, 50 GrTextureProvider* textureProvider,
52 GrRenderTarget* rt,
53 const GrClip& clipData, 51 const GrClip& clipData,
54 const SkMatrix& viewMatrix, 52 const SkMatrix& viewMatrix,
55 const SkPath& devPath, 53 const SkPath& devPath,
56 SkMaskFilter* filter, 54 SkMaskFilter* filter,
57 const SkIRect& clipBounds, 55 const SkIRect& clipBounds,
58 GrPaint* grp, 56 GrPaint* grp,
59 SkPaint::Style style) { 57 SkPaint::Style style) {
60 SkMask srcM, dstM; 58 SkMask srcM, dstM;
61 59
62 if (!SkDraw::DrawToMask(devPath, &clipBounds, filter, &viewMatrix, &srcM, 60 if (!SkDraw::DrawToMask(devPath, &clipBounds, filter, &viewMatrix, &srcM,
(...skipping 21 matching lines...) Expand all
84 82
85 SkAutoTUnref<GrTexture> texture(textureProvider->createApproxTexture(desc)); 83 SkAutoTUnref<GrTexture> texture(textureProvider->createApproxTexture(desc));
86 if (!texture) { 84 if (!texture) {
87 return false; 85 return false;
88 } 86 }
89 texture->writePixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig, 87 texture->writePixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig,
90 dstM.fImage, dstM.fRowBytes); 88 dstM.fImage, dstM.fRowBytes);
91 89
92 SkRect maskRect = SkRect::Make(dstM.fBounds); 90 SkRect maskRect = SkRect::Make(dstM.fBounds);
93 91
94 return draw_mask(drawContext, rt, clipData, viewMatrix, maskRect, grp, textu re); 92 return draw_mask(drawContext, clipData, viewMatrix, maskRect, grp, texture);
95 } 93 }
96 94
97 // Create a mask of 'devPath' and place the result in 'mask'. 95 // Create a mask of 'devPath' and place the result in 'mask'.
98 static GrTexture* create_mask_GPU(GrContext* context, 96 static GrTexture* create_mask_GPU(GrContext* context,
99 SkRect* maskRect, 97 SkRect* maskRect,
100 const SkPath& devPath, 98 const SkPath& devPath,
101 const GrStrokeInfo& strokeInfo, 99 const GrStrokeInfo& strokeInfo,
102 bool doAA, 100 bool doAA,
103 int sampleCnt) { 101 int sampleCnt) {
104 // 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).
(...skipping 14 matching lines...) Expand all
119 desc.fConfig = kAlpha_8_GrPixelConfig; 117 desc.fConfig = kAlpha_8_GrPixelConfig;
120 } 118 }
121 119
122 GrTexture* mask = context->textureProvider()->createApproxTexture(desc); 120 GrTexture* mask = context->textureProvider()->createApproxTexture(desc);
123 if (nullptr == mask) { 121 if (nullptr == mask) {
124 return nullptr; 122 return nullptr;
125 } 123 }
126 124
127 SkRect clipRect = SkRect::MakeWH(maskRect->width(), maskRect->height()); 125 SkRect clipRect = SkRect::MakeWH(maskRect->width(), maskRect->height());
128 126
129 SkAutoTUnref<GrDrawContext> drawContext(context->drawContext()); 127 SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(mask->asRenderT arget()));
130 if (!drawContext) { 128 if (!drawContext) {
131 return nullptr; 129 return nullptr;
132 } 130 }
133 131
134 drawContext->clear(mask->asRenderTarget(), nullptr, 0x0, true); 132 drawContext->clear(nullptr, 0x0, true);
135 133
136 GrPaint tempPaint; 134 GrPaint tempPaint;
137 tempPaint.setAntiAlias(doAA); 135 tempPaint.setAntiAlias(doAA);
138 tempPaint.setCoverageSetOpXPFactory(SkRegion::kReplace_Op); 136 tempPaint.setCoverageSetOpXPFactory(SkRegion::kReplace_Op);
139 137
140 // setup new clip 138 // setup new clip
141 GrClip clip(clipRect); 139 GrClip clip(clipRect);
142 140
143 // 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
144 // the origin using tempPaint. 142 // the origin using tempPaint.
145 SkMatrix translate; 143 SkMatrix translate;
146 translate.setTranslate(-maskRect->fLeft, -maskRect->fTop); 144 translate.setTranslate(-maskRect->fLeft, -maskRect->fTop);
147 drawContext->drawPath(mask->asRenderTarget(), clip, tempPaint, translate, de vPath, strokeInfo); 145 drawContext->drawPath(clip, tempPaint, translate, devPath, strokeInfo);
148 return mask; 146 return mask;
149 } 147 }
150 148
151 void GrBlurUtils::drawPathWithMaskFilter(GrContext* context, 149 void GrBlurUtils::drawPathWithMaskFilter(GrContext* context,
152 GrDrawContext* drawContext, 150 GrDrawContext* drawContext,
153 GrRenderTarget* renderTarget, 151 GrRenderTarget* renderTarget,
154 const GrClip& clip, 152 const GrClip& clip,
155 const SkPath& origSrcPath, 153 const SkPath& origSrcPath,
156 const SkPaint& paint, 154 const SkPaint& paint,
157 const SkMatrix& origViewMatrix, 155 const SkMatrix& origViewMatrix,
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 &maskRect)) { 238 &maskRect)) {
241 SkIRect finalIRect; 239 SkIRect finalIRect;
242 maskRect.roundOut(&finalIRect); 240 maskRect.roundOut(&finalIRect);
243 if (clip_bounds_quick_reject(clipBounds, finalIRect)) { 241 if (clip_bounds_quick_reject(clipBounds, finalIRect)) {
244 // clipped out 242 // clipped out
245 return; 243 return;
246 } 244 }
247 245
248 if (paint.getMaskFilter()->directFilterMaskGPU(context->textureProvi der(), 246 if (paint.getMaskFilter()->directFilterMaskGPU(context->textureProvi der(),
249 drawContext, 247 drawContext,
250 renderTarget,
251 &grPaint, 248 &grPaint,
252 clip, 249 clip,
253 viewMatrix, 250 viewMatrix,
254 strokeInfo, 251 strokeInfo,
255 *devPathPtr)) { 252 *devPathPtr)) {
256 // the mask filter was able to draw itself directly, so there's nothing 253 // the mask filter was able to draw itself directly, so there's nothing
257 // left to do. 254 // left to do.
258 return; 255 return;
259 } 256 }
260 257
261 SkAutoTUnref<GrTexture> mask(create_mask_GPU(context, 258 SkAutoTUnref<GrTexture> mask(create_mask_GPU(context,
262 &maskRect, 259 &maskRect,
263 *devPathPtr, 260 *devPathPtr,
264 strokeInfo, 261 strokeInfo,
265 grPaint.isAntiAlias(), 262 grPaint.isAntiAlias(),
266 renderTarget->numColorS amples())); 263 renderTarget->numColorS amples()));
267 if (mask) { 264 if (mask) {
268 GrTexture* filtered; 265 GrTexture* filtered;
269 266
270 if (paint.getMaskFilter()->filterMaskGPU(mask, viewMatrix, maskR ect, 267 if (paint.getMaskFilter()->filterMaskGPU(mask, viewMatrix, maskR ect,
271 &filtered, true)) { 268 &filtered, true)) {
272 // filterMaskGPU gives us ownership of a ref to the result 269 // filterMaskGPU gives us ownership of a ref to the result
273 SkAutoTUnref<GrTexture> atu(filtered); 270 SkAutoTUnref<GrTexture> atu(filtered);
274 if (draw_mask(drawContext, 271 if (draw_mask(drawContext,
275 renderTarget,
276 clip, 272 clip,
277 viewMatrix, 273 viewMatrix,
278 maskRect, 274 maskRect,
279 &grPaint, 275 &grPaint,
280 filtered)) { 276 filtered)) {
281 // This path is completely drawn 277 // This path is completely drawn
282 return; 278 return;
283 } 279 }
284 } 280 }
285 } 281 }
286 } 282 }
287 283
288 // draw the mask on the CPU - this is a fallthrough path in case the 284 // draw the mask on the CPU - this is a fallthrough path in case the
289 // GPU path fails 285 // GPU path fails
290 SkPaint::Style style = strokeInfo.isHairlineStyle() ? SkPaint::kStroke_S tyle : 286 SkPaint::Style style = strokeInfo.isHairlineStyle() ? SkPaint::kStroke_S tyle :
291 SkPaint::kFill_Sty le; 287 SkPaint::kFill_Sty le;
292 draw_with_mask_filter(drawContext, context->textureProvider(), renderTar get, 288 draw_with_mask_filter(drawContext, context->textureProvider(),
293 clip, viewMatrix, *devPathPtr, 289 clip, viewMatrix, *devPathPtr,
294 paint.getMaskFilter(), clipBounds, &grPaint, style ); 290 paint.getMaskFilter(), clipBounds, &grPaint, style );
295 return; 291 return;
296 } 292 }
297 293
298 drawContext->drawPath(renderTarget, clip, grPaint, viewMatrix, *pathPtr, str okeInfo); 294 drawContext->drawPath(clip, grPaint, viewMatrix, *pathPtr, strokeInfo);
299 } 295 }
300 296
OLDNEW
« no previous file with comments | « src/effects/SkXfermodeImageFilter.cpp ('k') | src/gpu/GrContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698