OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "GrSWMaskHelper.h" | 8 #include "GrSWMaskHelper.h" |
9 | 9 |
10 #include "GrCaps.h" | 10 #include "GrCaps.h" |
11 #include "GrContext.h" | 11 #include "GrContext.h" |
12 #include "batches/GrDrawBatch.h" | 12 #include "batches/GrDrawBatch.h" |
13 #include "GrDrawContext.h" | 13 #include "GrDrawContext.h" |
14 #include "GrGpu.h" | |
15 #include "GrPipelineBuilder.h" | 14 #include "GrPipelineBuilder.h" |
16 #include "GrStyle.h" | 15 #include "GrShape.h" |
17 | 16 |
18 #include "SkData.h" | |
19 #include "SkDistanceFieldGen.h" | 17 #include "SkDistanceFieldGen.h" |
20 #include "SkStrokeRec.h" | |
21 | 18 |
22 #include "batches/GrRectBatchFactory.h" | 19 #include "batches/GrRectBatchFactory.h" |
23 | 20 |
24 /* | 21 /* |
25 * Convert a boolean operation into a transfer mode code | 22 * Convert a boolean operation into a transfer mode code |
26 */ | 23 */ |
27 static SkXfermode::Mode op_to_mode(SkRegion::Op op) { | 24 static SkXfermode::Mode op_to_mode(SkRegion::Op op) { |
28 | 25 |
29 static const SkXfermode::Mode modeMap[] = { | 26 static const SkXfermode::Mode modeMap[] = { |
30 SkXfermode::kDstOut_Mode, // kDifference_Op | 27 SkXfermode::kDstOut_Mode, // kDifference_Op |
(...skipping 17 matching lines...) Expand all Loading... |
48 paint.setXfermode(SkXfermode::Make(op_to_mode(op))); | 45 paint.setXfermode(SkXfermode::Make(op_to_mode(op))); |
49 paint.setAntiAlias(antiAlias); | 46 paint.setAntiAlias(antiAlias); |
50 paint.setColor(SkColorSetARGB(alpha, alpha, alpha, alpha)); | 47 paint.setColor(SkColorSetARGB(alpha, alpha, alpha, alpha)); |
51 | 48 |
52 fDraw.drawRect(rect, paint); | 49 fDraw.drawRect(rect, paint); |
53 } | 50 } |
54 | 51 |
55 /** | 52 /** |
56 * Draw a single path element of the clip stack into the accumulation bitmap | 53 * Draw a single path element of the clip stack into the accumulation bitmap |
57 */ | 54 */ |
58 void GrSWMaskHelper::drawPath(const SkPath& path, const GrStyle& style, SkRegion
::Op op, | 55 void GrSWMaskHelper::drawShape(const GrShape& shape, SkRegion::Op op, bool antiA
lias, |
59 bool antiAlias, uint8_t alpha) { | 56 uint8_t alpha) { |
60 SkPaint paint; | 57 SkPaint paint; |
61 paint.setPathEffect(sk_ref_sp(style.pathEffect())); | 58 paint.setPathEffect(sk_ref_sp(shape.style().pathEffect())); |
62 style.strokeRec().applyToPaint(&paint); | 59 shape.style().strokeRec().applyToPaint(&paint); |
63 paint.setAntiAlias(antiAlias); | 60 paint.setAntiAlias(antiAlias); |
64 | 61 |
| 62 SkPath path; |
| 63 shape.asPath(&path); |
65 if (SkRegion::kReplace_Op == op && 0xFF == alpha) { | 64 if (SkRegion::kReplace_Op == op && 0xFF == alpha) { |
66 SkASSERT(0xFF == paint.getAlpha()); | 65 SkASSERT(0xFF == paint.getAlpha()); |
67 fDraw.drawPathCoverage(path, paint); | 66 fDraw.drawPathCoverage(path, paint); |
68 } else { | 67 } else { |
69 paint.setXfermodeMode(op_to_mode(op)); | 68 paint.setXfermodeMode(op_to_mode(op)); |
70 paint.setColor(SkColorSetARGB(alpha, alpha, alpha, alpha)); | 69 paint.setColor(SkColorSetARGB(alpha, alpha, alpha, alpha)); |
71 fDraw.drawPath(path, paint); | 70 fDraw.drawPath(path, paint); |
72 } | 71 } |
73 } | 72 } |
74 | 73 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 /** | 124 /** |
126 * Convert mask generation results to a signed distance field | 125 * Convert mask generation results to a signed distance field |
127 */ | 126 */ |
128 void GrSWMaskHelper::toSDF(unsigned char* sdf) { | 127 void GrSWMaskHelper::toSDF(unsigned char* sdf) { |
129 SkGenerateDistanceFieldFromA8Image(sdf, (const unsigned char*)fPixels.addr()
, | 128 SkGenerateDistanceFieldFromA8Image(sdf, (const unsigned char*)fPixels.addr()
, |
130 fPixels.width(), fPixels.height(), fPixel
s.rowBytes()); | 129 fPixels.width(), fPixels.height(), fPixel
s.rowBytes()); |
131 } | 130 } |
132 | 131 |
133 //////////////////////////////////////////////////////////////////////////////// | 132 //////////////////////////////////////////////////////////////////////////////// |
134 /** | 133 /** |
135 * Software rasterizes path to A8 mask (possibly using the context's matrix) | 134 * Software rasterizes shape to A8 mask and uploads the result to a scratch text
ure. Returns the |
136 * and uploads the result to a scratch texture. Returns the resulting | 135 * resulting texture on success; nullptr on failure. |
137 * texture on success; nullptr on failure. | |
138 */ | 136 */ |
139 GrTexture* GrSWMaskHelper::DrawPathMaskToTexture(GrTextureProvider* texProvider, | 137 GrTexture* GrSWMaskHelper::DrawShapeMaskToTexture(GrTextureProvider* texProvider
, |
140 const SkPath& path, | 138 const GrShape& shape, |
141 const GrStyle& style, | 139 const SkIRect& resultBounds, |
142 const SkIRect& resultBounds, | 140 bool antiAlias, |
143 bool antiAlias, | 141 const SkMatrix* matrix) { |
144 const SkMatrix* matrix) { | |
145 GrSWMaskHelper helper(texProvider); | 142 GrSWMaskHelper helper(texProvider); |
146 | 143 |
147 if (!helper.init(resultBounds, matrix)) { | 144 if (!helper.init(resultBounds, matrix)) { |
148 return nullptr; | 145 return nullptr; |
149 } | 146 } |
150 | 147 |
151 helper.drawPath(path, style, SkRegion::kReplace_Op, antiAlias, 0xFF); | 148 helper.drawShape(shape, SkRegion::kReplace_Op, antiAlias, 0xFF); |
152 | 149 |
153 GrTexture* texture(helper.createTexture()); | 150 GrTexture* texture(helper.createTexture()); |
154 if (!texture) { | 151 if (!texture) { |
155 return nullptr; | 152 return nullptr; |
156 } | 153 } |
157 | 154 |
158 helper.toTexture(texture); | 155 helper.toTexture(texture); |
159 | 156 |
160 return texture; | 157 return texture; |
161 } | 158 } |
162 | 159 |
163 void GrSWMaskHelper::DrawToTargetWithPathMask(GrTexture* texture, | 160 void GrSWMaskHelper::DrawToTargetWithShapeMask(GrTexture* texture, |
164 GrDrawContext* drawContext, | 161 GrDrawContext* drawContext, |
165 const GrPaint* paint, | 162 const GrPaint* paint, |
166 const GrUserStencilSettings* userS
tencilSettings, | 163 const GrUserStencilSettings* user
StencilSettings, |
167 const GrClip& clip, | 164 const GrClip& clip, |
168 GrColor color, | 165 GrColor color, |
169 const SkMatrix& viewMatrix, | 166 const SkMatrix& viewMatrix, |
170 const SkIRect& rect) { | 167 const SkIRect& rect) { |
171 SkMatrix invert; | 168 SkMatrix invert; |
172 if (!viewMatrix.invert(&invert)) { | 169 if (!viewMatrix.invert(&invert)) { |
173 return; | 170 return; |
174 } | 171 } |
175 | 172 |
176 SkRect dstRect = SkRect::MakeLTRB(SK_Scalar1 * rect.fLeft, | 173 SkRect dstRect = SkRect::MakeLTRB(SK_Scalar1 * rect.fLeft, |
177 SK_Scalar1 * rect.fTop, | 174 SK_Scalar1 * rect.fTop, |
178 SK_Scalar1 * rect.fRight, | 175 SK_Scalar1 * rect.fRight, |
179 SK_Scalar1 * rect.fBottom); | 176 SK_Scalar1 * rect.fBottom); |
180 | 177 |
(...skipping 10 matching lines...) Expand all Loading... |
191 pipelineBuilder.addCoverageFragmentProcessor( | 188 pipelineBuilder.addCoverageFragmentProcessor( |
192 GrSimpleTextureEffect::Make(texture, | 189 GrSimpleTextureEffect::Make(texture, |
193 maskMatrix, | 190 maskMatrix, |
194 GrTextureParams::kNone_Filt
erMode, | 191 GrTextureParams::kNone_Filt
erMode, |
195 kDevice_GrCoordSet)); | 192 kDevice_GrCoordSet)); |
196 | 193 |
197 SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateNonAAFill(color, S
kMatrix::I(), | 194 SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateNonAAFill(color, S
kMatrix::I(), |
198 dstRect,
nullptr, &invert)); | 195 dstRect,
nullptr, &invert)); |
199 drawContext->drawBatch(pipelineBuilder, clip, batch); | 196 drawContext->drawBatch(pipelineBuilder, clip, batch); |
200 } | 197 } |
OLD | NEW |