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