| 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 #include "GrDrawState.h" | 9 #include "GrDrawState.h" |
| 10 #include "GrDrawTargetCaps.h" | 10 #include "GrDrawTargetCaps.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 } else { | 66 } else { |
| 67 if (stroke.isFillStyle()) { | 67 if (stroke.isFillStyle()) { |
| 68 paint.setStyle(SkPaint::kFill_Style); | 68 paint.setStyle(SkPaint::kFill_Style); |
| 69 } else { | 69 } else { |
| 70 paint.setStyle(SkPaint::kStroke_Style); | 70 paint.setStyle(SkPaint::kStroke_Style); |
| 71 paint.setStrokeJoin(stroke.getJoin()); | 71 paint.setStrokeJoin(stroke.getJoin()); |
| 72 paint.setStrokeCap(stroke.getCap()); | 72 paint.setStrokeCap(stroke.getCap()); |
| 73 paint.setStrokeWidth(stroke.getWidth()); | 73 paint.setStrokeWidth(stroke.getWidth()); |
| 74 } | 74 } |
| 75 } | 75 } |
| 76 paint.setAntiAlias(antiAlias); |
| 76 | 77 |
| 77 SkXfermode* mode = SkXfermode::Create(op_to_mode(op)); | 78 if (SkRegion::kReplace_Op == op && 0xFF == alpha) { |
| 78 | 79 SkASSERT(0xFF == paint.getAlpha()); |
| 79 paint.setXfermode(mode); | 80 fDraw.drawPathCoverage(path, paint); |
| 80 paint.setAntiAlias(antiAlias); | 81 } else { |
| 81 paint.setColor(SkColorSetARGB(alpha, alpha, alpha, alpha)); | 82 paint.setXfermodeMode(op_to_mode(op)); |
| 82 | 83 paint.setColor(SkColorSetARGB(alpha, alpha, alpha, alpha)); |
| 83 fDraw.drawPath(path, paint); | 84 fDraw.drawPath(path, paint); |
| 84 | 85 } |
| 85 SkSafeUnref(mode); | |
| 86 } | 86 } |
| 87 | 87 |
| 88 bool GrSWMaskHelper::init(const SkIRect& resultBounds, | 88 bool GrSWMaskHelper::init(const SkIRect& resultBounds, |
| 89 const SkMatrix* matrix) { | 89 const SkMatrix* matrix, |
| 90 bool zeroPixels) { |
| 90 if (NULL != matrix) { | 91 if (NULL != matrix) { |
| 91 fMatrix = *matrix; | 92 fMatrix = *matrix; |
| 92 } else { | 93 } else { |
| 93 fMatrix.setIdentity(); | 94 fMatrix.setIdentity(); |
| 94 } | 95 } |
| 95 | 96 |
| 96 // Now translate so the bound's UL corner is at the origin | 97 // Now translate so the bound's UL corner is at the origin |
| 97 fMatrix.postTranslate(-resultBounds.fLeft * SK_Scalar1, | 98 fMatrix.postTranslate(-resultBounds.fLeft * SK_Scalar1, |
| 98 -resultBounds.fTop * SK_Scalar1); | 99 -resultBounds.fTop * SK_Scalar1); |
| 99 SkIRect bounds = SkIRect::MakeWH(resultBounds.width(), | 100 SkIRect bounds = SkIRect::MakeWH(resultBounds.width(), |
| 100 resultBounds.height()); | 101 resultBounds.height()); |
| 101 | 102 |
| 102 fBM.setConfig(SkBitmap::kA8_Config, bounds.fRight, bounds.fBottom); | 103 fBM.setConfig(SkBitmap::kA8_Config, bounds.fRight, bounds.fBottom); |
| 103 if (!fBM.allocPixels()) { | 104 if (!fBM.allocPixels()) { |
| 104 return false; | 105 return false; |
| 105 } | 106 } |
| 106 sk_bzero(fBM.getPixels(), fBM.getSafeSize()); | 107 if (zeroPixels) { |
| 108 sk_bzero(fBM.getPixels(), fBM.getSafeSize()); |
| 109 } |
| 107 | 110 |
| 108 sk_bzero(&fDraw, sizeof(fDraw)); | 111 sk_bzero(&fDraw, sizeof(fDraw)); |
| 109 fRasterClip.setRect(bounds); | 112 fRasterClip.setRect(bounds); |
| 110 fDraw.fRC = &fRasterClip; | 113 fDraw.fRC = &fRasterClip; |
| 111 fDraw.fClip = &fRasterClip.bwRgn(); | 114 fDraw.fClip = &fRasterClip.bwRgn(); |
| 112 fDraw.fMatrix = &fMatrix; | 115 fDraw.fMatrix = &fMatrix; |
| 113 fDraw.fBitmap = &fBM; | 116 fDraw.fBitmap = &fBM; |
| 114 return true; | 117 return true; |
| 115 } | 118 } |
| 116 | 119 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 GrTexture* GrSWMaskHelper::DrawPathMaskToTexture(GrContext* context, | 159 GrTexture* GrSWMaskHelper::DrawPathMaskToTexture(GrContext* context, |
| 157 const SkPath& path, | 160 const SkPath& path, |
| 158 const SkStrokeRec& stroke, | 161 const SkStrokeRec& stroke, |
| 159 const SkIRect& resultBounds, | 162 const SkIRect& resultBounds, |
| 160 bool antiAlias, | 163 bool antiAlias, |
| 161 SkMatrix* matrix) { | 164 SkMatrix* matrix) { |
| 162 GrAutoScratchTexture ast; | 165 GrAutoScratchTexture ast; |
| 163 | 166 |
| 164 GrSWMaskHelper helper(context); | 167 GrSWMaskHelper helper(context); |
| 165 | 168 |
| 166 if (!helper.init(resultBounds, matrix)) { | 169 if (!helper.init(resultBounds, matrix, false)) { |
| 167 return NULL; | 170 return NULL; |
| 168 } | 171 } |
| 169 | 172 |
| 170 helper.draw(path, stroke, SkRegion::kReplace_Op, antiAlias, 0xFF); | 173 helper.draw(path, stroke, SkRegion::kReplace_Op, antiAlias, 0xFF); |
| 171 | 174 |
| 172 if (!helper.getTexture(&ast)) { | 175 if (!helper.getTexture(&ast)) { |
| 173 return NULL; | 176 return NULL; |
| 174 } | 177 } |
| 175 | 178 |
| 176 helper.toTexture(ast.texture()); | 179 helper.toTexture(ast.texture()); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 204 maskMatrix.preConcat(drawState->getViewMatrix()); | 207 maskMatrix.preConcat(drawState->getViewMatrix()); |
| 205 | 208 |
| 206 drawState->addCoverageEffect( | 209 drawState->addCoverageEffect( |
| 207 GrSimpleTextureEffect::Create(texture, | 210 GrSimpleTextureEffect::Create(texture, |
| 208 maskMatrix, | 211 maskMatrix, |
| 209 GrTextureParams::kNone_Fi
lterMode, | 212 GrTextureParams::kNone_Fi
lterMode, |
| 210 kPosition_GrCoordSet))->u
nref(); | 213 kPosition_GrCoordSet))->u
nref(); |
| 211 | 214 |
| 212 target->drawSimpleRect(dstRect); | 215 target->drawSimpleRect(dstRect); |
| 213 } | 216 } |
| OLD | NEW |