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