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

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

Issue 1338183002: Fix GPU-only snapping bug in mask blur rendering (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fixed compiler complaint Created 5 years, 3 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 | « no previous file | no next file » | 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"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 texture->writePixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig, 90 texture->writePixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig,
91 dstM.fImage, dstM.fRowBytes); 91 dstM.fImage, dstM.fRowBytes);
92 92
93 SkRect maskRect = SkRect::Make(dstM.fBounds); 93 SkRect maskRect = SkRect::Make(dstM.fBounds);
94 94
95 return draw_mask(drawContext, rt, clipData, viewMatrix, maskRect, grp, textu re); 95 return draw_mask(drawContext, rt, clipData, viewMatrix, maskRect, grp, textu re);
96 } 96 }
97 97
98 // Create a mask of 'devPath' and place the result in 'mask'. 98 // Create a mask of 'devPath' and place the result in 'mask'.
99 static GrTexture* create_mask_GPU(GrContext* context, 99 static GrTexture* create_mask_GPU(GrContext* context,
100 const SkRect& maskRect, 100 SkRect* maskRect,
101 const SkPath& devPath, 101 const SkPath& devPath,
102 const GrStrokeInfo& strokeInfo, 102 const GrStrokeInfo& strokeInfo,
103 bool doAA, 103 bool doAA,
104 int sampleCnt) { 104 int sampleCnt) {
105 // This mask will ultimately be drawn as a non-AA rect (see draw_mask).
106 // Non-AA rects have a bad habit of snapping arbitrarily. Integerize here
107 // so the mask draws in a reproducible manner.
108 *maskRect = SkRect::Make(maskRect->roundOut());
109
105 GrSurfaceDesc desc; 110 GrSurfaceDesc desc;
106 desc.fFlags = kRenderTarget_GrSurfaceFlag; 111 desc.fFlags = kRenderTarget_GrSurfaceFlag;
107 desc.fWidth = SkScalarCeilToInt(maskRect.width()); 112 desc.fWidth = SkScalarCeilToInt(maskRect->width());
108 desc.fHeight = SkScalarCeilToInt(maskRect.height()); 113 desc.fHeight = SkScalarCeilToInt(maskRect->height());
109 desc.fSampleCnt = doAA ? sampleCnt : 0; 114 desc.fSampleCnt = doAA ? sampleCnt : 0;
110 // We actually only need A8, but it often isn't supported as a 115 // We actually only need A8, but it often isn't supported as a
111 // render target so default to RGBA_8888 116 // render target so default to RGBA_8888
112 desc.fConfig = kRGBA_8888_GrPixelConfig; 117 desc.fConfig = kRGBA_8888_GrPixelConfig;
113 118
114 if (context->caps()->isConfigRenderable(kAlpha_8_GrPixelConfig, desc.fSample Cnt > 0)) { 119 if (context->caps()->isConfigRenderable(kAlpha_8_GrPixelConfig, desc.fSample Cnt > 0)) {
115 desc.fConfig = kAlpha_8_GrPixelConfig; 120 desc.fConfig = kAlpha_8_GrPixelConfig;
116 } 121 }
117 122
118 GrTexture* mask = context->textureProvider()->createApproxTexture(desc); 123 GrTexture* mask = context->textureProvider()->createApproxTexture(desc);
119 if (nullptr == mask) { 124 if (nullptr == mask) {
120 return nullptr; 125 return nullptr;
121 } 126 }
122 127
123 SkRect clipRect = SkRect::MakeWH(maskRect.width(), maskRect.height()); 128 SkRect clipRect = SkRect::MakeWH(maskRect->width(), maskRect->height());
124 129
125 SkAutoTUnref<GrDrawContext> drawContext(context->drawContext()); 130 SkAutoTUnref<GrDrawContext> drawContext(context->drawContext());
126 if (!drawContext) { 131 if (!drawContext) {
127 return nullptr; 132 return nullptr;
128 } 133 }
129 134
130 drawContext->clear(mask->asRenderTarget(), nullptr, 0x0, true); 135 drawContext->clear(mask->asRenderTarget(), nullptr, 0x0, true);
131 136
132 GrPaint tempPaint; 137 GrPaint tempPaint;
133 tempPaint.setAntiAlias(doAA); 138 tempPaint.setAntiAlias(doAA);
134 tempPaint.setCoverageSetOpXPFactory(SkRegion::kReplace_Op); 139 tempPaint.setCoverageSetOpXPFactory(SkRegion::kReplace_Op);
135 140
136 // setup new clip 141 // setup new clip
137 GrClip clip(clipRect); 142 GrClip clip(clipRect);
138 143
139 // Draw the mask into maskTexture with the path's top-left at the origin usi ng tempPaint. 144 // Draw the mask into maskTexture with the path's integerized top-left at
145 // the origin using tempPaint.
140 SkMatrix translate; 146 SkMatrix translate;
141 translate.setTranslate(-maskRect.fLeft, -maskRect.fTop); 147 translate.setTranslate(-maskRect->fLeft, -maskRect->fTop);
142 drawContext->drawPath(mask->asRenderTarget(), clip, tempPaint, translate, de vPath, strokeInfo); 148 drawContext->drawPath(mask->asRenderTarget(), clip, tempPaint, translate, de vPath, strokeInfo);
143 return mask; 149 return mask;
144 } 150 }
145 151
146 void GrBlurUtils::drawPathWithMaskFilter(GrContext* context, 152 void GrBlurUtils::drawPathWithMaskFilter(GrContext* context,
147 GrDrawContext* drawContext, 153 GrDrawContext* drawContext,
148 GrRenderTarget* renderTarget, 154 GrRenderTarget* renderTarget,
149 const GrClip& clip, 155 const GrClip& clip,
150 const SkPath& origSrcPath, 156 const SkPath& origSrcPath,
151 const SkPaint& paint, 157 const SkPaint& paint,
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 clip, 253 clip,
248 viewMatrix, 254 viewMatrix,
249 strokeInfo, 255 strokeInfo,
250 *devPathPtr)) { 256 *devPathPtr)) {
251 // the mask filter was able to draw itself directly, so there's nothing 257 // the mask filter was able to draw itself directly, so there's nothing
252 // left to do. 258 // left to do.
253 return; 259 return;
254 } 260 }
255 261
256 SkAutoTUnref<GrTexture> mask(create_mask_GPU(context, 262 SkAutoTUnref<GrTexture> mask(create_mask_GPU(context,
257 maskRect, 263 &maskRect,
258 *devPathPtr, 264 *devPathPtr,
259 strokeInfo, 265 strokeInfo,
260 grPaint.isAntiAlias(), 266 grPaint.isAntiAlias(),
261 renderTarget->numColorS amples())); 267 renderTarget->numColorS amples()));
262 if (mask) { 268 if (mask) {
263 GrTexture* filtered; 269 GrTexture* filtered;
264 270
265 if (paint.getMaskFilter()->filterMaskGPU(mask, viewMatrix, maskR ect, 271 if (paint.getMaskFilter()->filterMaskGPU(mask, viewMatrix, maskR ect,
266 &filtered, true)) { 272 &filtered, true)) {
267 // filterMaskGPU gives us ownership of a ref to the result 273 // filterMaskGPU gives us ownership of a ref to the result
(...skipping 18 matching lines...) Expand all
286 SkPaint::kFill_Sty le; 292 SkPaint::kFill_Sty le;
287 draw_with_mask_filter(drawContext, context->textureProvider(), renderTar get, 293 draw_with_mask_filter(drawContext, context->textureProvider(), renderTar get,
288 clip, viewMatrix, *devPathPtr, 294 clip, viewMatrix, *devPathPtr,
289 paint.getMaskFilter(), clipBounds, &grPaint, style ); 295 paint.getMaskFilter(), clipBounds, &grPaint, style );
290 return; 296 return;
291 } 297 }
292 298
293 drawContext->drawPath(renderTarget, clip, grPaint, viewMatrix, *pathPtr, str okeInfo); 299 drawContext->drawPath(renderTarget, clip, grPaint, viewMatrix, *pathPtr, str okeInfo);
294 } 300 }
295 301
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698