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 "GrGpu.h" | 10 #include "GrGpu.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 }; | 30 }; |
31 | 31 |
32 return modeMap[op]; | 32 return modeMap[op]; |
33 } | 33 } |
34 | 34 |
35 } | 35 } |
36 | 36 |
37 /** | 37 /** |
38 * Draw a single rect element of the clip stack into the accumulation bitmap | 38 * Draw a single rect element of the clip stack into the accumulation bitmap |
39 */ | 39 */ |
40 void GrSWMaskHelper::draw(const GrRect& rect, SkRegion::Op op, | 40 void GrSWMaskHelper::draw(const SkRect& rect, SkRegion::Op op, |
41 bool antiAlias, uint8_t alpha) { | 41 bool antiAlias, uint8_t alpha) { |
42 SkPaint paint; | 42 SkPaint paint; |
43 | 43 |
44 SkXfermode* mode = SkXfermode::Create(op_to_mode(op)); | 44 SkXfermode* mode = SkXfermode::Create(op_to_mode(op)); |
45 | 45 |
46 paint.setXfermode(mode); | 46 paint.setXfermode(mode); |
47 paint.setAntiAlias(antiAlias); | 47 paint.setAntiAlias(antiAlias); |
48 paint.setColor(SkColorSetARGB(alpha, alpha, alpha, alpha)); | 48 paint.setColor(SkColorSetARGB(alpha, alpha, alpha, alpha)); |
49 | 49 |
50 fDraw.drawRect(rect, paint); | 50 fDraw.drawRect(rect, paint); |
(...skipping 26 matching lines...) Expand all Loading... |
77 | 77 |
78 paint.setXfermode(mode); | 78 paint.setXfermode(mode); |
79 paint.setAntiAlias(antiAlias); | 79 paint.setAntiAlias(antiAlias); |
80 paint.setColor(SkColorSetARGB(alpha, alpha, alpha, alpha)); | 80 paint.setColor(SkColorSetARGB(alpha, alpha, alpha, alpha)); |
81 | 81 |
82 fDraw.drawPath(path, paint); | 82 fDraw.drawPath(path, paint); |
83 | 83 |
84 SkSafeUnref(mode); | 84 SkSafeUnref(mode); |
85 } | 85 } |
86 | 86 |
87 bool GrSWMaskHelper::init(const GrIRect& resultBounds, | 87 bool GrSWMaskHelper::init(const SkIRect& resultBounds, |
88 const SkMatrix* matrix) { | 88 const SkMatrix* matrix) { |
89 if (NULL != matrix) { | 89 if (NULL != matrix) { |
90 fMatrix = *matrix; | 90 fMatrix = *matrix; |
91 } else { | 91 } else { |
92 fMatrix.setIdentity(); | 92 fMatrix.setIdentity(); |
93 } | 93 } |
94 | 94 |
95 // Now translate so the bound's UL corner is at the origin | 95 // Now translate so the bound's UL corner is at the origin |
96 fMatrix.postTranslate(-resultBounds.fLeft * SK_Scalar1, | 96 fMatrix.postTranslate(-resultBounds.fLeft * SK_Scalar1, |
97 -resultBounds.fTop * SK_Scalar1); | 97 -resultBounds.fTop * SK_Scalar1); |
98 GrIRect bounds = GrIRect::MakeWH(resultBounds.width(), | 98 SkIRect bounds = SkIRect::MakeWH(resultBounds.width(), |
99 resultBounds.height()); | 99 resultBounds.height()); |
100 | 100 |
101 fBM.setConfig(SkBitmap::kA8_Config, bounds.fRight, bounds.fBottom); | 101 fBM.setConfig(SkBitmap::kA8_Config, bounds.fRight, bounds.fBottom); |
102 if (!fBM.allocPixels()) { | 102 if (!fBM.allocPixels()) { |
103 return false; | 103 return false; |
104 } | 104 } |
105 sk_bzero(fBM.getPixels(), fBM.getSafeSize()); | 105 sk_bzero(fBM.getPixels(), fBM.getSafeSize()); |
106 | 106 |
107 sk_bzero(&fDraw, sizeof(fDraw)); | 107 sk_bzero(&fDraw, sizeof(fDraw)); |
108 fRasterClip.setRect(bounds); | 108 fRasterClip.setRect(bounds); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 | 153 |
154 //////////////////////////////////////////////////////////////////////////////// | 154 //////////////////////////////////////////////////////////////////////////////// |
155 /** | 155 /** |
156 * Software rasterizes path to A8 mask (possibly using the context's matrix) | 156 * Software rasterizes path to A8 mask (possibly using the context's matrix) |
157 * and uploads the result to a scratch texture. Returns the resulting | 157 * and uploads the result to a scratch texture. Returns the resulting |
158 * texture on success; NULL on failure. | 158 * texture on success; NULL on failure. |
159 */ | 159 */ |
160 GrTexture* GrSWMaskHelper::DrawPathMaskToTexture(GrContext* context, | 160 GrTexture* GrSWMaskHelper::DrawPathMaskToTexture(GrContext* context, |
161 const SkPath& path, | 161 const SkPath& path, |
162 const SkStrokeRec& stroke, | 162 const SkStrokeRec& stroke, |
163 const GrIRect& resultBounds, | 163 const SkIRect& resultBounds, |
164 bool antiAlias, | 164 bool antiAlias, |
165 SkMatrix* matrix) { | 165 SkMatrix* matrix) { |
166 GrAutoScratchTexture ast; | 166 GrAutoScratchTexture ast; |
167 | 167 |
168 GrSWMaskHelper helper(context); | 168 GrSWMaskHelper helper(context); |
169 | 169 |
170 if (!helper.init(resultBounds, matrix)) { | 170 if (!helper.init(resultBounds, matrix)) { |
171 return NULL; | 171 return NULL; |
172 } | 172 } |
173 | 173 |
174 helper.draw(path, stroke, SkRegion::kReplace_Op, antiAlias, 0xFF); | 174 helper.draw(path, stroke, SkRegion::kReplace_Op, antiAlias, 0xFF); |
175 | 175 |
176 if (!helper.getTexture(&ast)) { | 176 if (!helper.getTexture(&ast)) { |
177 return NULL; | 177 return NULL; |
178 } | 178 } |
179 | 179 |
180 helper.toTexture(ast.texture(), 0x00); | 180 helper.toTexture(ast.texture(), 0x00); |
181 | 181 |
182 return ast.detach(); | 182 return ast.detach(); |
183 } | 183 } |
184 | 184 |
185 void GrSWMaskHelper::DrawToTargetWithPathMask(GrTexture* texture, | 185 void GrSWMaskHelper::DrawToTargetWithPathMask(GrTexture* texture, |
186 GrDrawTarget* target, | 186 GrDrawTarget* target, |
187 const GrIRect& rect) { | 187 const SkIRect& rect) { |
188 GrDrawState* drawState = target->drawState(); | 188 GrDrawState* drawState = target->drawState(); |
189 | 189 |
190 GrDrawState::AutoViewMatrixRestore avmr; | 190 GrDrawState::AutoViewMatrixRestore avmr; |
191 if (!avmr.setIdentity(drawState)) { | 191 if (!avmr.setIdentity(drawState)) { |
192 return; | 192 return; |
193 } | 193 } |
194 GrDrawState::AutoRestoreEffects are(drawState); | 194 GrDrawState::AutoRestoreEffects are(drawState); |
195 | 195 |
196 GrRect dstRect = GrRect::MakeLTRB( | 196 SkRect dstRect = SkRect::MakeLTRB(SK_Scalar1 * rect.fLeft, |
197 SK_Scalar1 * rect.fLeft, | 197 SK_Scalar1 * rect.fTop, |
198 SK_Scalar1 * rect.fTop, | 198 SK_Scalar1 * rect.fRight, |
199 SK_Scalar1 * rect.fRight, | 199 SK_Scalar1 * rect.fBottom); |
200 SK_Scalar1 * rect.fBottom); | |
201 | 200 |
202 // We want to use device coords to compute the texture coordinates. We set o
ur matrix to be | 201 // We want to use device coords to compute the texture coordinates. We set o
ur matrix to be |
203 // equal to the view matrix followed by a translation so that the top-left o
f the device bounds | 202 // equal to the view matrix followed by a translation so that the top-left o
f the device bounds |
204 // maps to 0,0, and then a scaling matrix to normalized coords. We apply thi
s matrix to the | 203 // maps to 0,0, and then a scaling matrix to normalized coords. We apply thi
s matrix to the |
205 // vertex positions rather than local coords. | 204 // vertex positions rather than local coords. |
206 SkMatrix maskMatrix; | 205 SkMatrix maskMatrix; |
207 maskMatrix.setIDiv(texture->width(), texture->height()); | 206 maskMatrix.setIDiv(texture->width(), texture->height()); |
208 maskMatrix.preTranslate(SkIntToScalar(-rect.fLeft), SkIntToScalar(-rect.fTop
)); | 207 maskMatrix.preTranslate(SkIntToScalar(-rect.fLeft), SkIntToScalar(-rect.fTop
)); |
209 maskMatrix.preConcat(drawState->getViewMatrix()); | 208 maskMatrix.preConcat(drawState->getViewMatrix()); |
210 | 209 |
211 drawState->addCoverageEffect( | 210 drawState->addCoverageEffect( |
212 GrSimpleTextureEffect::Create(texture, | 211 GrSimpleTextureEffect::Create(texture, |
213 maskMatrix, | 212 maskMatrix, |
214 false, | 213 false, |
215 GrEffect::kPosition_Coord
sType))->unref(); | 214 GrEffect::kPosition_Coord
sType))->unref(); |
216 | 215 |
217 target->drawSimpleRect(dstRect); | 216 target->drawSimpleRect(dstRect); |
218 } | 217 } |
OLD | NEW |