| 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 "GrDrawState.h" | 10 #include "GrDrawState.h" |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 /** | 319 /** |
| 320 * Software rasterizes path to A8 mask (possibly using the context's matrix) | 320 * Software rasterizes path to A8 mask (possibly using the context's matrix) |
| 321 * and uploads the result to a scratch texture. Returns the resulting | 321 * and uploads the result to a scratch texture. Returns the resulting |
| 322 * texture on success; NULL on failure. | 322 * texture on success; NULL on failure. |
| 323 */ | 323 */ |
| 324 GrTexture* GrSWMaskHelper::DrawPathMaskToTexture(GrContext* context, | 324 GrTexture* GrSWMaskHelper::DrawPathMaskToTexture(GrContext* context, |
| 325 const SkPath& path, | 325 const SkPath& path, |
| 326 const SkStrokeRec& stroke, | 326 const SkStrokeRec& stroke, |
| 327 const SkIRect& resultBounds, | 327 const SkIRect& resultBounds, |
| 328 bool antiAlias, | 328 bool antiAlias, |
| 329 SkMatrix* matrix) { | 329 const SkMatrix* matrix) { |
| 330 GrSWMaskHelper helper(context); | 330 GrSWMaskHelper helper(context); |
| 331 | 331 |
| 332 if (!helper.init(resultBounds, matrix)) { | 332 if (!helper.init(resultBounds, matrix)) { |
| 333 return NULL; | 333 return NULL; |
| 334 } | 334 } |
| 335 | 335 |
| 336 helper.draw(path, stroke, SkRegion::kReplace_Op, antiAlias, 0xFF); | 336 helper.draw(path, stroke, SkRegion::kReplace_Op, antiAlias, 0xFF); |
| 337 | 337 |
| 338 GrTexture* texture(helper.createTexture()); | 338 GrTexture* texture(helper.createTexture()); |
| 339 if (!texture) { | 339 if (!texture) { |
| 340 return NULL; | 340 return NULL; |
| 341 } | 341 } |
| 342 | 342 |
| 343 helper.toTexture(texture); | 343 helper.toTexture(texture); |
| 344 | 344 |
| 345 return texture; | 345 return texture; |
| 346 } | 346 } |
| 347 | 347 |
| 348 void GrSWMaskHelper::DrawToTargetWithPathMask(GrTexture* texture, | 348 void GrSWMaskHelper::DrawToTargetWithPathMask(GrTexture* texture, |
| 349 GrDrawTarget* target, | 349 GrDrawTarget* target, |
| 350 GrDrawState* drawState, | 350 GrDrawState* drawState, |
| 351 GrColor color, | 351 GrColor color, |
| 352 const SkMatrix& viewMatrix, |
| 352 const SkIRect& rect) { | 353 const SkIRect& rect) { |
| 353 SkMatrix invert; | 354 SkMatrix invert; |
| 354 if (!drawState->getViewMatrix().invert(&invert)) { | 355 if (!viewMatrix.invert(&invert)) { |
| 355 return; | 356 return; |
| 356 } | 357 } |
| 357 GrDrawState::AutoViewMatrixRestore avmr(drawState); | |
| 358 GrDrawState::AutoRestoreEffects are(drawState); | 358 GrDrawState::AutoRestoreEffects are(drawState); |
| 359 | 359 |
| 360 SkRect dstRect = SkRect::MakeLTRB(SK_Scalar1 * rect.fLeft, | 360 SkRect dstRect = SkRect::MakeLTRB(SK_Scalar1 * rect.fLeft, |
| 361 SK_Scalar1 * rect.fTop, | 361 SK_Scalar1 * rect.fTop, |
| 362 SK_Scalar1 * rect.fRight, | 362 SK_Scalar1 * rect.fRight, |
| 363 SK_Scalar1 * rect.fBottom); | 363 SK_Scalar1 * rect.fBottom); |
| 364 | 364 |
| 365 // We use device coords to compute the texture coordinates. We take the devi
ce coords and apply | 365 // We use device coords to compute the texture coordinates. We take the devi
ce coords and apply |
| 366 // a translation so that the top-left of the device bounds maps to 0,0, and
then a scaling | 366 // a translation so that the top-left of the device bounds maps to 0,0, and
then a scaling |
| 367 // matrix to normalized coords. | 367 // matrix to normalized coords. |
| 368 SkMatrix maskMatrix; | 368 SkMatrix maskMatrix; |
| 369 maskMatrix.setIDiv(texture->width(), texture->height()); | 369 maskMatrix.setIDiv(texture->width(), texture->height()); |
| 370 maskMatrix.preTranslate(SkIntToScalar(-rect.fLeft), SkIntToScalar(-rect.fTop
)); | 370 maskMatrix.preTranslate(SkIntToScalar(-rect.fLeft), SkIntToScalar(-rect.fTop
)); |
| 371 | 371 |
| 372 drawState->addCoverageProcessor( | 372 drawState->addCoverageProcessor( |
| 373 GrSimpleTextureEffect::Create(texture, | 373 GrSimpleTextureEffect::Create(texture, |
| 374 maskMatrix, | 374 maskMatrix, |
| 375 GrTextureParams::kNone_Fi
lterMode, | 375 GrTextureParams::kNone_Fi
lterMode, |
| 376 kDevice_GrCoordSet))->unr
ef(); | 376 kDevice_GrCoordSet))->unr
ef(); |
| 377 | 377 |
| 378 target->drawRect(drawState, color, dstRect, NULL, &invert); | 378 target->drawRect(drawState, color, SkMatrix::I(), dstRect, NULL, &invert); |
| 379 } | 379 } |
| OLD | NEW |