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 "GrDrawTarget.h" | 11 #include "GrDrawTarget.h" |
12 #include "GrGpu.h" | 12 #include "GrGpu.h" |
13 #include "GrPipelineBuilder.h" | 13 #include "GrPipelineBuilder.h" |
| 14 #include "GrStyle.h" |
14 | 15 |
15 #include "SkData.h" | 16 #include "SkData.h" |
16 #include "SkDistanceFieldGen.h" | 17 #include "SkDistanceFieldGen.h" |
17 #include "SkStrokeRec.h" | 18 #include "SkStrokeRec.h" |
18 | 19 |
19 #include "batches/GrRectBatchFactory.h" | 20 #include "batches/GrRectBatchFactory.h" |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
23 /* | 24 /* |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 paint.setXfermode(SkXfermode::Make(op_to_mode(op))); | 111 paint.setXfermode(SkXfermode::Make(op_to_mode(op))); |
111 paint.setAntiAlias(antiAlias); | 112 paint.setAntiAlias(antiAlias); |
112 paint.setColor(SkColorSetARGB(alpha, alpha, alpha, alpha)); | 113 paint.setColor(SkColorSetARGB(alpha, alpha, alpha, alpha)); |
113 | 114 |
114 fDraw.drawRect(rect, paint); | 115 fDraw.drawRect(rect, paint); |
115 } | 116 } |
116 | 117 |
117 /** | 118 /** |
118 * Draw a single path element of the clip stack into the accumulation bitmap | 119 * Draw a single path element of the clip stack into the accumulation bitmap |
119 */ | 120 */ |
120 void GrSWMaskHelper::draw(const SkPath& path, const SkStrokeRec& stroke, SkRegio
n::Op op, | 121 void GrSWMaskHelper::draw(const SkPath& path, const GrStyle& style, SkRegion::Op
op, |
121 bool antiAlias, uint8_t alpha) { | 122 bool antiAlias, uint8_t alpha) { |
122 | |
123 SkPaint paint; | 123 SkPaint paint; |
124 if (stroke.isHairlineStyle()) { | 124 paint.setPathEffect(sk_ref_sp(style.pathEffect())); |
125 paint.setStyle(SkPaint::kStroke_Style); | 125 style.strokeRec().applyToPaint(&paint); |
126 } else { | |
127 if (stroke.isFillStyle()) { | |
128 paint.setStyle(SkPaint::kFill_Style); | |
129 } else { | |
130 paint.setStyle(SkPaint::kStroke_Style); | |
131 paint.setStrokeJoin(stroke.getJoin()); | |
132 paint.setStrokeCap(stroke.getCap()); | |
133 paint.setStrokeWidth(stroke.getWidth()); | |
134 } | |
135 } | |
136 paint.setAntiAlias(antiAlias); | 126 paint.setAntiAlias(antiAlias); |
137 | 127 |
138 SkTBlitterAllocator allocator; | 128 SkTBlitterAllocator allocator; |
139 SkBlitter* blitter = nullptr; | 129 SkBlitter* blitter = nullptr; |
140 if (kBlitter_CompressionMode == fCompressionMode) { | 130 if (kBlitter_CompressionMode == fCompressionMode) { |
141 SkASSERT(fCompressedBuffer.get()); | 131 SkASSERT(fCompressedBuffer.get()); |
142 blitter = SkTextureCompressor::CreateBlitterForFormat( | 132 blitter = SkTextureCompressor::CreateBlitterForFormat( |
143 fPixels.width(), fPixels.height(), fCompressedBuffer.get(), &allocat
or, | 133 fPixels.width(), fPixels.height(), fCompressedBuffer.get(), &allocat
or, |
144 fCompressedFormat)
; | 134 fCompressedFormat)
; |
145 } | 135 } |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 } | 290 } |
301 | 291 |
302 //////////////////////////////////////////////////////////////////////////////// | 292 //////////////////////////////////////////////////////////////////////////////// |
303 /** | 293 /** |
304 * Software rasterizes path to A8 mask (possibly using the context's matrix) | 294 * Software rasterizes path to A8 mask (possibly using the context's matrix) |
305 * and uploads the result to a scratch texture. Returns the resulting | 295 * and uploads the result to a scratch texture. Returns the resulting |
306 * texture on success; nullptr on failure. | 296 * texture on success; nullptr on failure. |
307 */ | 297 */ |
308 GrTexture* GrSWMaskHelper::DrawPathMaskToTexture(GrContext* context, | 298 GrTexture* GrSWMaskHelper::DrawPathMaskToTexture(GrContext* context, |
309 const SkPath& path, | 299 const SkPath& path, |
310 const SkStrokeRec& stroke, | 300 const GrStyle& style, |
311 const SkIRect& resultBounds, | 301 const SkIRect& resultBounds, |
312 bool antiAlias, | 302 bool antiAlias, |
313 const SkMatrix* matrix) { | 303 const SkMatrix* matrix) { |
314 GrSWMaskHelper helper(context); | 304 GrSWMaskHelper helper(context); |
315 | 305 |
316 if (!helper.init(resultBounds, matrix)) { | 306 if (!helper.init(resultBounds, matrix)) { |
317 return nullptr; | 307 return nullptr; |
318 } | 308 } |
319 | 309 |
320 helper.draw(path, stroke, SkRegion::kReplace_Op, antiAlias, 0xFF); | 310 helper.draw(path, style, SkRegion::kReplace_Op, antiAlias, 0xFF); |
321 | 311 |
322 GrTexture* texture(helper.createTexture()); | 312 GrTexture* texture(helper.createTexture()); |
323 if (!texture) { | 313 if (!texture) { |
324 return nullptr; | 314 return nullptr; |
325 } | 315 } |
326 | 316 |
327 helper.toTexture(texture); | 317 helper.toTexture(texture); |
328 | 318 |
329 return texture; | 319 return texture; |
330 } | 320 } |
(...skipping 25 matching lines...) Expand all Loading... |
356 pipelineBuilder->addCoverageFragmentProcessor( | 346 pipelineBuilder->addCoverageFragmentProcessor( |
357 GrSimpleTextureEffect::Create(texture, | 347 GrSimpleTextureEffect::Create(texture, |
358 maskMatrix, | 348 maskMatrix, |
359 GrTextureParams::kNone_Fi
lterMode, | 349 GrTextureParams::kNone_Fi
lterMode, |
360 kDevice_GrCoordSet))->unr
ef(); | 350 kDevice_GrCoordSet))->unr
ef(); |
361 | 351 |
362 SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateNonAAFill(color, S
kMatrix::I(), | 352 SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateNonAAFill(color, S
kMatrix::I(), |
363 dstRect,
nullptr, &invert)); | 353 dstRect,
nullptr, &invert)); |
364 target->drawBatch(*pipelineBuilder, batch); | 354 target->drawBatch(*pipelineBuilder, batch); |
365 } | 355 } |
OLD | NEW |