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 "GrPipelineBuilder.h" | 14 #include "GrPipelineBuilder.h" |
15 #include "GrShape.h" | 15 #include "GrShape.h" |
16 | 16 |
17 #include "SkDistanceFieldGen.h" | 17 #include "SkDistanceFieldGen.h" |
18 | 18 |
19 #include "batches/GrRectBatchFactory.h" | 19 #include "batches/GrRectBatchFactory.h" |
20 | 20 |
21 /* | 21 /* |
22 * Convert a boolean operation into a transfer mode code | 22 * Convert a boolean operation into a transfer mode code |
23 */ | 23 */ |
24 static SkXfermode::Mode op_to_mode(SkRegion::Op op) { | 24 static SkBlendMode op_to_mode(SkRegion::Op op) { |
25 | 25 |
26 static const SkXfermode::Mode modeMap[] = { | 26 static const SkBlendMode modeMap[] = { |
27 SkXfermode::kDstOut_Mode, // kDifference_Op | 27 SkBlendMode::kDstOut, // kDifference_Op |
28 SkXfermode::kModulate_Mode, // kIntersect_Op | 28 SkBlendMode::kModulate, // kIntersect_Op |
29 SkXfermode::kSrcOver_Mode, // kUnion_Op | 29 SkBlendMode::kSrcOver, // kUnion_Op |
30 SkXfermode::kXor_Mode, // kXOR_Op | 30 SkBlendMode::kXor, // kXOR_Op |
31 SkXfermode::kClear_Mode, // kReverseDifference_Op | 31 SkBlendMode::kClear, // kReverseDifference_Op |
32 SkXfermode::kSrc_Mode, // kReplace_Op | 32 SkBlendMode::kSrc, // kReplace_Op |
33 }; | 33 }; |
34 | 34 |
35 return modeMap[op]; | 35 return modeMap[op]; |
36 } | 36 } |
37 | 37 |
38 /** | 38 /** |
39 * Draw a single rect element of the clip stack into the accumulation bitmap | 39 * Draw a single rect element of the clip stack into the accumulation bitmap |
40 */ | 40 */ |
41 void GrSWMaskHelper::drawRect(const SkRect& rect, SkRegion::Op op, | 41 void GrSWMaskHelper::drawRect(const SkRect& rect, SkRegion::Op op, |
42 bool antiAlias, uint8_t alpha) { | 42 bool antiAlias, uint8_t alpha) { |
43 SkPaint paint; | 43 SkPaint paint; |
44 | 44 |
45 paint.setXfermode(SkXfermode::Make(op_to_mode(op))); | 45 paint.setBlendMode(op_to_mode(op)); |
46 paint.setAntiAlias(antiAlias); | 46 paint.setAntiAlias(antiAlias); |
47 paint.setColor(SkColorSetARGB(alpha, alpha, alpha, alpha)); | 47 paint.setColor(SkColorSetARGB(alpha, alpha, alpha, alpha)); |
48 | 48 |
49 fDraw.drawRect(rect, paint); | 49 fDraw.drawRect(rect, paint); |
50 } | 50 } |
51 | 51 |
52 /** | 52 /** |
53 * Draw a single path element of the clip stack into the accumulation bitmap | 53 * Draw a single path element of the clip stack into the accumulation bitmap |
54 */ | 54 */ |
55 void GrSWMaskHelper::drawShape(const GrShape& shape, SkRegion::Op op, bool antiA
lias, | 55 void GrSWMaskHelper::drawShape(const GrShape& shape, SkRegion::Op op, bool antiA
lias, |
56 uint8_t alpha) { | 56 uint8_t alpha) { |
57 SkPaint paint; | 57 SkPaint paint; |
58 paint.setPathEffect(sk_ref_sp(shape.style().pathEffect())); | 58 paint.setPathEffect(sk_ref_sp(shape.style().pathEffect())); |
59 shape.style().strokeRec().applyToPaint(&paint); | 59 shape.style().strokeRec().applyToPaint(&paint); |
60 paint.setAntiAlias(antiAlias); | 60 paint.setAntiAlias(antiAlias); |
61 | 61 |
62 SkPath path; | 62 SkPath path; |
63 shape.asPath(&path); | 63 shape.asPath(&path); |
64 if (SkRegion::kReplace_Op == op && 0xFF == alpha) { | 64 if (SkRegion::kReplace_Op == op && 0xFF == alpha) { |
65 SkASSERT(0xFF == paint.getAlpha()); | 65 SkASSERT(0xFF == paint.getAlpha()); |
66 fDraw.drawPathCoverage(path, paint); | 66 fDraw.drawPathCoverage(path, paint); |
67 } else { | 67 } else { |
68 paint.setXfermodeMode(op_to_mode(op)); | 68 paint.setBlendMode(op_to_mode(op)); |
69 paint.setColor(SkColorSetARGB(alpha, alpha, alpha, alpha)); | 69 paint.setColor(SkColorSetARGB(alpha, alpha, alpha, alpha)); |
70 fDraw.drawPath(path, paint); | 70 fDraw.drawPath(path, paint); |
71 } | 71 } |
72 } | 72 } |
73 | 73 |
74 bool GrSWMaskHelper::init(const SkIRect& resultBounds, const SkMatrix* matrix) { | 74 bool GrSWMaskHelper::init(const SkIRect& resultBounds, const SkMatrix* matrix) { |
75 if (matrix) { | 75 if (matrix) { |
76 fMatrix = *matrix; | 76 fMatrix = *matrix; |
77 } else { | 77 } else { |
78 fMatrix.setIdentity(); | 78 fMatrix.setIdentity(); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 GrSimpleTextureEffect::Make(texture, | 192 GrSimpleTextureEffect::Make(texture, |
193 nullptr, | 193 nullptr, |
194 maskMatrix, | 194 maskMatrix, |
195 GrTextureParams::kNone_Filt
erMode)); | 195 GrTextureParams::kNone_Filt
erMode)); |
196 | 196 |
197 SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateNonAAFill(paint.ge
tColor(), | 197 SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateNonAAFill(paint.ge
tColor(), |
198 SkMatrix
::I(), | 198 SkMatrix
::I(), |
199 dstRect,
nullptr, &invert)); | 199 dstRect,
nullptr, &invert)); |
200 drawContext->drawBatch(pipelineBuilder, clip, batch); | 200 drawContext->drawBatch(pipelineBuilder, clip, batch); |
201 } | 201 } |
OLD | NEW |