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