OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkGpuDevice.h" | 8 #include "SkGpuDevice.h" |
9 | 9 |
10 #include "effects/GrBicubicEffect.h" | 10 #include "effects/GrBicubicEffect.h" |
11 #include "effects/GrTextureDomain.h" | 11 #include "effects/GrTextureDomain.h" |
12 #include "effects/GrSimpleTextureEffect.h" | 12 #include "effects/GrSimpleTextureEffect.h" |
13 | 13 |
14 #include "GrContext.h" | 14 #include "GrContext.h" |
15 #include "GrBitmapTextContext.h" | 15 #include "GrBitmapTextContext.h" |
16 #include "GrDistanceFieldTextContext.h" | 16 #include "GrDistanceFieldTextContext.h" |
17 #include "GrLayerCache.h" | 17 #include "GrLayerCache.h" |
18 #include "GrPictureUtils.h" | 18 #include "GrPictureUtils.h" |
19 | 19 |
20 #include "SkGrTexturePixelRef.h" | 20 #include "SkGrTexturePixelRef.h" |
21 | 21 |
22 #include "SkBounder.h" | 22 #include "SkBounder.h" |
23 #include "SkColorFilter.h" | |
24 #include "SkDeviceImageFilterProxy.h" | 23 #include "SkDeviceImageFilterProxy.h" |
25 #include "SkDrawProcs.h" | 24 #include "SkDrawProcs.h" |
26 #include "SkGlyphCache.h" | 25 #include "SkGlyphCache.h" |
27 #include "SkImageFilter.h" | 26 #include "SkImageFilter.h" |
28 #include "SkMaskFilter.h" | 27 #include "SkMaskFilter.h" |
29 #include "SkPathEffect.h" | 28 #include "SkPathEffect.h" |
30 #include "SkPicture.h" | 29 #include "SkPicture.h" |
31 #include "SkPicturePlayback.h" | 30 #include "SkPicturePlayback.h" |
32 #include "SkRRect.h" | 31 #include "SkRRect.h" |
33 #include "SkStroke.h" | 32 #include "SkStroke.h" |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 SK_COMPILE_ASSERT(SkShader::kDefault_BitmapType == 1, shader_type_mismatch); | 369 SK_COMPILE_ASSERT(SkShader::kDefault_BitmapType == 1, shader_type_mismatch); |
371 SK_COMPILE_ASSERT(SkShader::kRadial_BitmapType == 2, shader_type_mismatch); | 370 SK_COMPILE_ASSERT(SkShader::kRadial_BitmapType == 2, shader_type_mismatch); |
372 SK_COMPILE_ASSERT(SkShader::kSweep_BitmapType == 3, shader_type_mismatch); | 371 SK_COMPILE_ASSERT(SkShader::kSweep_BitmapType == 3, shader_type_mismatch); |
373 SK_COMPILE_ASSERT(SkShader::kTwoPointRadial_BitmapType == 4, | 372 SK_COMPILE_ASSERT(SkShader::kTwoPointRadial_BitmapType == 4, |
374 shader_type_mismatch); | 373 shader_type_mismatch); |
375 SK_COMPILE_ASSERT(SkShader::kTwoPointConical_BitmapType == 5, | 374 SK_COMPILE_ASSERT(SkShader::kTwoPointConical_BitmapType == 5, |
376 shader_type_mismatch); | 375 shader_type_mismatch); |
377 SK_COMPILE_ASSERT(SkShader::kLinear_BitmapType == 6, shader_type_mismatch); | 376 SK_COMPILE_ASSERT(SkShader::kLinear_BitmapType == 6, shader_type_mismatch); |
378 SK_COMPILE_ASSERT(SkShader::kLast_BitmapType == 6, shader_type_mismatch); | 377 SK_COMPILE_ASSERT(SkShader::kLast_BitmapType == 6, shader_type_mismatch); |
379 | 378 |
380 namespace { | |
381 | |
382 // converts a SkPaint to a GrPaint, ignoring the skPaint's shader | |
383 // justAlpha indicates that skPaint's alpha should be used rather than the color | |
384 // Callers may subsequently modify the GrPaint. Setting constantColor indicates | |
385 // that the final paint will draw the same color at every pixel. This allows | |
386 // an optimization where the the color filter can be applied to the skPaint's | |
387 // color once while converting to GrPaint and then ignored. | |
388 inline bool skPaint2GrPaintNoShader(SkGpuDevice* dev, | |
389 const SkPaint& skPaint, | |
390 bool justAlpha, | |
391 bool constantColor, | |
392 GrPaint* grPaint) { | |
393 | |
394 grPaint->setDither(skPaint.isDither()); | |
395 grPaint->setAntiAlias(skPaint.isAntiAlias()); | |
396 | |
397 SkXfermode::Coeff sm; | |
398 SkXfermode::Coeff dm; | |
399 | |
400 SkXfermode* mode = skPaint.getXfermode(); | |
401 GrEffectRef* xferEffect = NULL; | |
402 if (SkXfermode::AsNewEffectOrCoeff(mode, &xferEffect, &sm, &dm)) { | |
403 if (NULL != xferEffect) { | |
404 grPaint->addColorEffect(xferEffect)->unref(); | |
405 sm = SkXfermode::kOne_Coeff; | |
406 dm = SkXfermode::kZero_Coeff; | |
407 } | |
408 } else { | |
409 //SkDEBUGCODE(SkDebugf("Unsupported xfer mode.\n");) | |
410 #if 0 | |
411 return false; | |
412 #else | |
413 // Fall back to src-over | |
414 sm = SkXfermode::kOne_Coeff; | |
415 dm = SkXfermode::kISA_Coeff; | |
416 #endif | |
417 } | |
418 grPaint->setBlendFunc(sk_blend_to_grblend(sm), sk_blend_to_grblend(dm)); | |
419 | |
420 if (justAlpha) { | |
421 uint8_t alpha = skPaint.getAlpha(); | |
422 grPaint->setColor(GrColorPackRGBA(alpha, alpha, alpha, alpha)); | |
423 // justAlpha is currently set to true only if there is a texture, | |
424 // so constantColor should not also be true. | |
425 SkASSERT(!constantColor); | |
426 } else { | |
427 grPaint->setColor(SkColor2GrColor(skPaint.getColor())); | |
428 } | |
429 | |
430 SkColorFilter* colorFilter = skPaint.getColorFilter(); | |
431 if (NULL != colorFilter) { | |
432 // if the source color is a constant then apply the filter here once rat
her than per pixel | |
433 // in a shader. | |
434 if (constantColor) { | |
435 SkColor filtered = colorFilter->filterColor(skPaint.getColor()); | |
436 grPaint->setColor(SkColor2GrColor(filtered)); | |
437 } else { | |
438 SkAutoTUnref<GrEffectRef> effect(colorFilter->asNewEffect(dev->conte
xt())); | |
439 if (NULL != effect.get()) { | |
440 grPaint->addColorEffect(effect); | |
441 } | |
442 } | |
443 } | |
444 | |
445 return true; | |
446 } | |
447 | |
448 // This function is similar to skPaint2GrPaintNoShader but also converts | |
449 // skPaint's shader to a GrTexture/GrEffectStage if possible. The texture to | |
450 // be used is set on grPaint and returned in param act. constantColor has the | |
451 // same meaning as in skPaint2GrPaintNoShader. | |
452 inline bool skPaint2GrPaintShader(SkGpuDevice* dev, | |
453 const SkPaint& skPaint, | |
454 bool constantColor, | |
455 GrPaint* grPaint) { | |
456 SkShader* shader = skPaint.getShader(); | |
457 if (NULL == shader) { | |
458 return skPaint2GrPaintNoShader(dev, skPaint, false, constantColor, grPai
nt); | |
459 } | |
460 | |
461 // SkShader::asNewEffect() may do offscreen rendering. Setup default drawing
state and require | |
462 // the shader to set a render target . | |
463 GrContext::AutoWideOpenIdentityDraw awo(dev->context(), NULL); | |
464 | |
465 // setup the shader as the first color effect on the paint | |
466 SkAutoTUnref<GrEffectRef> effect(shader->asNewEffect(dev->context(), skPaint
, NULL)); | |
467 if (NULL != effect.get()) { | |
468 grPaint->addColorEffect(effect); | |
469 // Now setup the rest of the paint. | |
470 return skPaint2GrPaintNoShader(dev, skPaint, true, false, grPaint); | |
471 } else { | |
472 // We still don't have SkColorShader::asNewEffect() implemented. | |
473 SkShader::GradientInfo info; | |
474 SkColor color; | |
475 | |
476 info.fColors = &color; | |
477 info.fColorOffsets = NULL; | |
478 info.fColorCount = 1; | |
479 if (SkShader::kColor_GradientType == shader->asAGradient(&info)) { | |
480 SkPaint copy(skPaint); | |
481 copy.setShader(NULL); | |
482 // modulate the paint alpha by the shader's solid color alpha | |
483 U8CPU newA = SkMulDiv255Round(SkColorGetA(color), copy.getAlpha()); | |
484 copy.setColor(SkColorSetA(color, newA)); | |
485 return skPaint2GrPaintNoShader(dev, copy, false, constantColor, grPa
int); | |
486 } else { | |
487 return false; | |
488 } | |
489 } | |
490 } | |
491 } | |
492 | |
493 /////////////////////////////////////////////////////////////////////////////// | 379 /////////////////////////////////////////////////////////////////////////////// |
494 | 380 |
495 SkBitmap::Config SkGpuDevice::config() const { | 381 SkBitmap::Config SkGpuDevice::config() const { |
496 if (NULL == fRenderTarget) { | 382 if (NULL == fRenderTarget) { |
497 return SkBitmap::kNo_Config; | 383 return SkBitmap::kNo_Config; |
498 } | 384 } |
499 | 385 |
500 bool isOpaque; | 386 bool isOpaque; |
501 return grConfig2skConfig(fRenderTarget->config(), &isOpaque); | 387 return grConfig2skConfig(fRenderTarget->config(), &isOpaque); |
502 } | 388 } |
503 | 389 |
504 void SkGpuDevice::clear(SkColor color) { | 390 void SkGpuDevice::clear(SkColor color) { |
505 SkIRect rect = SkIRect::MakeWH(this->width(), this->height()); | 391 SkIRect rect = SkIRect::MakeWH(this->width(), this->height()); |
506 fContext->clear(&rect, SkColor2GrColor(color), true, fRenderTarget); | 392 fContext->clear(&rect, SkColor2GrColor(color), true, fRenderTarget); |
507 fNeedClear = false; | 393 fNeedClear = false; |
508 } | 394 } |
509 | 395 |
510 void SkGpuDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { | 396 void SkGpuDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { |
511 CHECK_SHOULD_DRAW(draw, false); | 397 CHECK_SHOULD_DRAW(draw, false); |
512 | 398 |
513 GrPaint grPaint; | 399 GrPaint grPaint; |
514 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { | 400 if (!SkPaint2GrPaintShader(this, paint, true, &grPaint)) { |
515 return; | 401 return; |
516 } | 402 } |
517 | 403 |
518 fContext->drawPaint(grPaint); | 404 fContext->drawPaint(grPaint); |
519 } | 405 } |
520 | 406 |
521 // must be in SkCanvas::PointMode order | 407 // must be in SkCanvas::PointMode order |
522 static const GrPrimitiveType gPointMode2PrimtiveType[] = { | 408 static const GrPrimitiveType gPointMode2PrimtiveType[] = { |
523 kPoints_GrPrimitiveType, | 409 kPoints_GrPrimitiveType, |
524 kLines_GrPrimitiveType, | 410 kLines_GrPrimitiveType, |
(...skipping 11 matching lines...) Expand all Loading... |
536 } | 422 } |
537 | 423 |
538 // we only handle hairlines and paints without path effects or mask filters, | 424 // we only handle hairlines and paints without path effects or mask filters, |
539 // else we let the SkDraw call our drawPath() | 425 // else we let the SkDraw call our drawPath() |
540 if (width > 0 || paint.getPathEffect() || paint.getMaskFilter()) { | 426 if (width > 0 || paint.getPathEffect() || paint.getMaskFilter()) { |
541 draw.drawPoints(mode, count, pts, paint, true); | 427 draw.drawPoints(mode, count, pts, paint, true); |
542 return; | 428 return; |
543 } | 429 } |
544 | 430 |
545 GrPaint grPaint; | 431 GrPaint grPaint; |
546 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { | 432 if (!SkPaint2GrPaintShader(this, paint, true, &grPaint)) { |
547 return; | 433 return; |
548 } | 434 } |
549 | 435 |
550 fContext->drawVertices(grPaint, | 436 fContext->drawVertices(grPaint, |
551 gPointMode2PrimtiveType[mode], | 437 gPointMode2PrimtiveType[mode], |
552 SkToS32(count), | 438 SkToS32(count), |
553 (SkPoint*)pts, | 439 (SkPoint*)pts, |
554 NULL, | 440 NULL, |
555 NULL, | 441 NULL, |
556 NULL, | 442 NULL, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 } | 481 } |
596 | 482 |
597 if (usePath) { | 483 if (usePath) { |
598 SkPath path; | 484 SkPath path; |
599 path.addRect(rect); | 485 path.addRect(rect); |
600 this->drawPath(draw, path, paint, NULL, true); | 486 this->drawPath(draw, path, paint, NULL, true); |
601 return; | 487 return; |
602 } | 488 } |
603 | 489 |
604 GrPaint grPaint; | 490 GrPaint grPaint; |
605 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { | 491 if (!SkPaint2GrPaintShader(this, paint, true, &grPaint)) { |
606 return; | 492 return; |
607 } | 493 } |
608 | 494 |
609 if (!doStroke) { | 495 if (!doStroke) { |
610 fContext->drawRect(grPaint, rect); | 496 fContext->drawRect(grPaint, rect); |
611 } else { | 497 } else { |
612 SkStrokeRec stroke(paint); | 498 SkStrokeRec stroke(paint); |
613 fContext->drawRect(grPaint, rect, &stroke); | 499 fContext->drawRect(grPaint, rect, &stroke); |
614 } | 500 } |
615 } | 501 } |
616 | 502 |
617 /////////////////////////////////////////////////////////////////////////////// | 503 /////////////////////////////////////////////////////////////////////////////// |
618 | 504 |
619 void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rect, | 505 void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rect, |
620 const SkPaint& paint) { | 506 const SkPaint& paint) { |
621 CHECK_FOR_ANNOTATION(paint); | 507 CHECK_FOR_ANNOTATION(paint); |
622 CHECK_SHOULD_DRAW(draw, false); | 508 CHECK_SHOULD_DRAW(draw, false); |
623 | 509 |
624 GrPaint grPaint; | 510 GrPaint grPaint; |
625 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { | 511 if (!SkPaint2GrPaintShader(this, paint, true, &grPaint)) { |
626 return; | 512 return; |
627 } | 513 } |
628 | 514 |
629 SkStrokeRec stroke(paint); | 515 SkStrokeRec stroke(paint); |
630 if (paint.getMaskFilter()) { | 516 if (paint.getMaskFilter()) { |
631 // try to hit the fast path for drawing filtered round rects | 517 // try to hit the fast path for drawing filtered round rects |
632 | 518 |
633 SkRRect devRRect; | 519 SkRRect devRRect; |
634 if (rect.transform(fContext->getMatrix(), &devRRect)) { | 520 if (rect.transform(fContext->getMatrix(), &devRRect)) { |
635 if (devRRect.allCornersCircular()) { | 521 if (devRRect.allCornersCircular()) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
671 | 557 |
672 void SkGpuDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer, | 558 void SkGpuDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer, |
673 const SkRRect& inner, const SkPaint& paint) { | 559 const SkRRect& inner, const SkPaint& paint) { |
674 SkStrokeRec stroke(paint); | 560 SkStrokeRec stroke(paint); |
675 if (stroke.isFillStyle()) { | 561 if (stroke.isFillStyle()) { |
676 | 562 |
677 CHECK_FOR_ANNOTATION(paint); | 563 CHECK_FOR_ANNOTATION(paint); |
678 CHECK_SHOULD_DRAW(draw, false); | 564 CHECK_SHOULD_DRAW(draw, false); |
679 | 565 |
680 GrPaint grPaint; | 566 GrPaint grPaint; |
681 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { | 567 if (!SkPaint2GrPaintShader(this, paint, true, &grPaint)) { |
682 return; | 568 return; |
683 } | 569 } |
684 | 570 |
685 if (NULL == paint.getMaskFilter() && NULL == paint.getPathEffect()) { | 571 if (NULL == paint.getMaskFilter() && NULL == paint.getPathEffect()) { |
686 fContext->drawDRRect(grPaint, outer, inner); | 572 fContext->drawDRRect(grPaint, outer, inner); |
687 return; | 573 return; |
688 } | 574 } |
689 } | 575 } |
690 | 576 |
691 SkPath path; | 577 SkPath path; |
(...skipping 19 matching lines...) Expand all Loading... |
711 } | 597 } |
712 | 598 |
713 if (usePath) { | 599 if (usePath) { |
714 SkPath path; | 600 SkPath path; |
715 path.addOval(oval); | 601 path.addOval(oval); |
716 this->drawPath(draw, path, paint, NULL, true); | 602 this->drawPath(draw, path, paint, NULL, true); |
717 return; | 603 return; |
718 } | 604 } |
719 | 605 |
720 GrPaint grPaint; | 606 GrPaint grPaint; |
721 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { | 607 if (!SkPaint2GrPaintShader(this, paint, true, &grPaint)) { |
722 return; | 608 return; |
723 } | 609 } |
724 SkStrokeRec stroke(paint); | 610 SkStrokeRec stroke(paint); |
725 | 611 |
726 fContext->drawOval(grPaint, oval, stroke); | 612 fContext->drawOval(grPaint, oval, stroke); |
727 } | 613 } |
728 | 614 |
729 #include "SkMaskFilter.h" | 615 #include "SkMaskFilter.h" |
730 #include "SkBounder.h" | 616 #include "SkBounder.h" |
731 | 617 |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
864 | 750 |
865 }; | 751 }; |
866 | 752 |
867 void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath, | 753 void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath, |
868 const SkPaint& paint, const SkMatrix* prePathMatrix, | 754 const SkPaint& paint, const SkMatrix* prePathMatrix, |
869 bool pathIsMutable) { | 755 bool pathIsMutable) { |
870 CHECK_FOR_ANNOTATION(paint); | 756 CHECK_FOR_ANNOTATION(paint); |
871 CHECK_SHOULD_DRAW(draw, false); | 757 CHECK_SHOULD_DRAW(draw, false); |
872 | 758 |
873 GrPaint grPaint; | 759 GrPaint grPaint; |
874 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { | 760 if (!SkPaint2GrPaintShader(this, paint, true, &grPaint)) { |
875 return; | 761 return; |
876 } | 762 } |
877 | 763 |
878 // If we have a prematrix, apply it to the path, optimizing for the case | 764 // If we have a prematrix, apply it to the path, optimizing for the case |
879 // where the original path can in fact be modified in place (even though | 765 // where the original path can in fact be modified in place (even though |
880 // its parameter type is const). | 766 // its parameter type is const). |
881 SkPath* pathPtr = const_cast<SkPath*>(&origSrcPath); | 767 SkPath* pathPtr = const_cast<SkPath*>(&origSrcPath); |
882 SkTLazy<SkPath> tmpPath; | 768 SkTLazy<SkPath> tmpPath; |
883 SkTLazy<SkPath> effectPath; | 769 SkTLazy<SkPath> effectPath; |
884 | 770 |
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1514 effect.reset(GrBicubicEffect::Create(texture, SkMatrix::I(), tileModes))
; | 1400 effect.reset(GrBicubicEffect::Create(texture, SkMatrix::I(), tileModes))
; |
1515 } else { | 1401 } else { |
1516 effect.reset(GrSimpleTextureEffect::Create(texture, SkMatrix::I(), param
s)); | 1402 effect.reset(GrSimpleTextureEffect::Create(texture, SkMatrix::I(), param
s)); |
1517 } | 1403 } |
1518 | 1404 |
1519 // Construct a GrPaint by setting the bitmap texture as the first effect and
then configuring | 1405 // Construct a GrPaint by setting the bitmap texture as the first effect and
then configuring |
1520 // the rest from the SkPaint. | 1406 // the rest from the SkPaint. |
1521 GrPaint grPaint; | 1407 GrPaint grPaint; |
1522 grPaint.addColorEffect(effect); | 1408 grPaint.addColorEffect(effect); |
1523 bool alphaOnly = !(SkBitmap::kA8_Config == bitmap.config()); | 1409 bool alphaOnly = !(SkBitmap::kA8_Config == bitmap.config()); |
1524 if (!skPaint2GrPaintNoShader(this, paint, alphaOnly, false, &grPaint)) { | 1410 if (!SkPaint2GrPaintNoShader(this, paint, alphaOnly, false, &grPaint)) { |
1525 return; | 1411 return; |
1526 } | 1412 } |
1527 | 1413 |
1528 fContext->drawRectToRect(grPaint, dstRect, paintRect, NULL); | 1414 fContext->drawRectToRect(grPaint, dstRect, paintRect, NULL); |
1529 } | 1415 } |
1530 | 1416 |
1531 static bool filter_texture(SkBaseDevice* device, GrContext* context, | 1417 static bool filter_texture(SkBaseDevice* device, GrContext* context, |
1532 GrTexture* texture, const SkImageFilter* filter, | 1418 GrTexture* texture, const SkImageFilter* filter, |
1533 int w, int h, const SkImageFilter::Context& ctx, | 1419 int w, int h, const SkImageFilter::Context& ctx, |
1534 SkBitmap* result, SkIPoint* offset) { | 1420 SkBitmap* result, SkIPoint* offset) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1582 left += offset.x(); | 1468 left += offset.x(); |
1583 top += offset.y(); | 1469 top += offset.y(); |
1584 } else { | 1470 } else { |
1585 return; | 1471 return; |
1586 } | 1472 } |
1587 } | 1473 } |
1588 | 1474 |
1589 GrPaint grPaint; | 1475 GrPaint grPaint; |
1590 grPaint.addColorTextureEffect(texture, SkMatrix::I()); | 1476 grPaint.addColorTextureEffect(texture, SkMatrix::I()); |
1591 | 1477 |
1592 if(!skPaint2GrPaintNoShader(this, paint, true, false, &grPaint)) { | 1478 if(!SkPaint2GrPaintNoShader(this, paint, true, false, &grPaint)) { |
1593 return; | 1479 return; |
1594 } | 1480 } |
1595 | 1481 |
1596 fContext->drawRectToRect(grPaint, | 1482 fContext->drawRectToRect(grPaint, |
1597 SkRect::MakeXYWH(SkIntToScalar(left), | 1483 SkRect::MakeXYWH(SkIntToScalar(left), |
1598 SkIntToScalar(top), | 1484 SkIntToScalar(top), |
1599 SkIntToScalar(w), | 1485 SkIntToScalar(w), |
1600 SkIntToScalar(h)), | 1486 SkIntToScalar(h)), |
1601 SkRect::MakeXYWH(0, | 1487 SkRect::MakeXYWH(0, |
1602 0, | 1488 0, |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1692 x += offset.fX; | 1578 x += offset.fX; |
1693 y += offset.fY; | 1579 y += offset.fY; |
1694 } else { | 1580 } else { |
1695 return; | 1581 return; |
1696 } | 1582 } |
1697 } | 1583 } |
1698 | 1584 |
1699 GrPaint grPaint; | 1585 GrPaint grPaint; |
1700 grPaint.addColorTextureEffect(devTex, SkMatrix::I()); | 1586 grPaint.addColorTextureEffect(devTex, SkMatrix::I()); |
1701 | 1587 |
1702 if (!skPaint2GrPaintNoShader(this, paint, true, false, &grPaint)) { | 1588 if (!SkPaint2GrPaintNoShader(this, paint, true, false, &grPaint)) { |
1703 return; | 1589 return; |
1704 } | 1590 } |
1705 | 1591 |
1706 SkRect dstRect = SkRect::MakeXYWH(SkIntToScalar(x), | 1592 SkRect dstRect = SkRect::MakeXYWH(SkIntToScalar(x), |
1707 SkIntToScalar(y), | 1593 SkIntToScalar(y), |
1708 SkIntToScalar(w), | 1594 SkIntToScalar(w), |
1709 SkIntToScalar(h)); | 1595 SkIntToScalar(h)); |
1710 | 1596 |
1711 // The device being drawn may not fill up its texture (e.g. saveLayer uses a
pproximate | 1597 // The device being drawn may not fill up its texture (e.g. saveLayer uses a
pproximate |
1712 // scratch texture). | 1598 // scratch texture). |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1755 int vertexCount, const SkPoint vertices[], | 1641 int vertexCount, const SkPoint vertices[], |
1756 const SkPoint texs[], const SkColor colors[], | 1642 const SkPoint texs[], const SkColor colors[], |
1757 SkXfermode* xmode, | 1643 SkXfermode* xmode, |
1758 const uint16_t indices[], int indexCount, | 1644 const uint16_t indices[], int indexCount, |
1759 const SkPaint& paint) { | 1645 const SkPaint& paint) { |
1760 CHECK_SHOULD_DRAW(draw, false); | 1646 CHECK_SHOULD_DRAW(draw, false); |
1761 | 1647 |
1762 GrPaint grPaint; | 1648 GrPaint grPaint; |
1763 // we ignore the shader if texs is null. | 1649 // we ignore the shader if texs is null. |
1764 if (NULL == texs) { | 1650 if (NULL == texs) { |
1765 if (!skPaint2GrPaintNoShader(this, paint, false, NULL == colors, &grPain
t)) { | 1651 if (!SkPaint2GrPaintNoShader(this, paint, false, NULL == colors, &grPain
t)) { |
1766 return; | 1652 return; |
1767 } | 1653 } |
1768 } else { | 1654 } else { |
1769 if (!skPaint2GrPaintShader(this, paint, NULL == colors, &grPaint)) { | 1655 if (!SkPaint2GrPaintShader(this, paint, NULL == colors, &grPaint)) { |
1770 return; | 1656 return; |
1771 } | 1657 } |
1772 } | 1658 } |
1773 | 1659 |
1774 if (NULL != xmode && NULL != texs && NULL != colors) { | 1660 if (NULL != xmode && NULL != texs && NULL != colors) { |
1775 if (!SkXfermode::IsMode(xmode, SkXfermode::kModulate_Mode)) { | 1661 if (!SkXfermode::IsMode(xmode, SkXfermode::kModulate_Mode)) { |
1776 SkDebugf("Unsupported vertex-color/texture xfer mode.\n"); | 1662 SkDebugf("Unsupported vertex-color/texture xfer mode.\n"); |
1777 #if 0 | 1663 #if 0 |
1778 return | 1664 return |
1779 #endif | 1665 #endif |
(...skipping 21 matching lines...) Expand all Loading... |
1801 | 1687 |
1802 /////////////////////////////////////////////////////////////////////////////// | 1688 /////////////////////////////////////////////////////////////////////////////// |
1803 | 1689 |
1804 void SkGpuDevice::drawText(const SkDraw& draw, const void* text, | 1690 void SkGpuDevice::drawText(const SkDraw& draw, const void* text, |
1805 size_t byteLength, SkScalar x, SkScalar y, | 1691 size_t byteLength, SkScalar x, SkScalar y, |
1806 const SkPaint& paint) { | 1692 const SkPaint& paint) { |
1807 CHECK_SHOULD_DRAW(draw, false); | 1693 CHECK_SHOULD_DRAW(draw, false); |
1808 | 1694 |
1809 if (fMainTextContext->canDraw(paint)) { | 1695 if (fMainTextContext->canDraw(paint)) { |
1810 GrPaint grPaint; | 1696 GrPaint grPaint; |
1811 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { | 1697 if (!SkPaint2GrPaintShader(this, paint, true, &grPaint)) { |
1812 return; | 1698 return; |
1813 } | 1699 } |
1814 | 1700 |
1815 SkDEBUGCODE(this->validate();) | 1701 SkDEBUGCODE(this->validate();) |
1816 | 1702 |
1817 fMainTextContext->drawText(grPaint, paint, (const char *)text, byteLengt
h, x, y); | 1703 fMainTextContext->drawText(grPaint, paint, (const char *)text, byteLengt
h, x, y); |
1818 } else if (fFallbackTextContext && fFallbackTextContext->canDraw(paint)) { | 1704 } else if (fFallbackTextContext && fFallbackTextContext->canDraw(paint)) { |
1819 GrPaint grPaint; | 1705 GrPaint grPaint; |
1820 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { | 1706 if (!SkPaint2GrPaintShader(this, paint, true, &grPaint)) { |
1821 return; | 1707 return; |
1822 } | 1708 } |
1823 | 1709 |
1824 SkDEBUGCODE(this->validate();) | 1710 SkDEBUGCODE(this->validate();) |
1825 | 1711 |
1826 fFallbackTextContext->drawText(grPaint, paint, (const char *)text, byteL
ength, x, y); | 1712 fFallbackTextContext->drawText(grPaint, paint, (const char *)text, byteL
ength, x, y); |
1827 } else { | 1713 } else { |
1828 // this guy will just call our drawPath() | 1714 // this guy will just call our drawPath() |
1829 draw.drawText_asPaths((const char*)text, byteLength, x, y, paint); | 1715 draw.drawText_asPaths((const char*)text, byteLength, x, y, paint); |
1830 } | 1716 } |
1831 } | 1717 } |
1832 | 1718 |
1833 void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, | 1719 void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, |
1834 size_t byteLength, const SkScalar pos[], | 1720 size_t byteLength, const SkScalar pos[], |
1835 SkScalar constY, int scalarsPerPos, | 1721 SkScalar constY, int scalarsPerPos, |
1836 const SkPaint& paint) { | 1722 const SkPaint& paint) { |
1837 CHECK_SHOULD_DRAW(draw, false); | 1723 CHECK_SHOULD_DRAW(draw, false); |
1838 | 1724 |
1839 if (fMainTextContext->canDraw(paint)) { | 1725 if (fMainTextContext->canDraw(paint)) { |
1840 GrPaint grPaint; | 1726 GrPaint grPaint; |
1841 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { | 1727 if (!SkPaint2GrPaintShader(this, paint, true, &grPaint)) { |
1842 return; | 1728 return; |
1843 } | 1729 } |
1844 | 1730 |
1845 SkDEBUGCODE(this->validate();) | 1731 SkDEBUGCODE(this->validate();) |
1846 | 1732 |
1847 fMainTextContext->drawPosText(grPaint, paint, (const char *)text, byteLe
ngth, pos, | 1733 fMainTextContext->drawPosText(grPaint, paint, (const char *)text, byteLe
ngth, pos, |
1848 constY, scalarsPerPos); | 1734 constY, scalarsPerPos); |
1849 } else if (fFallbackTextContext && fFallbackTextContext->canDraw(paint)) { | 1735 } else if (fFallbackTextContext && fFallbackTextContext->canDraw(paint)) { |
1850 GrPaint grPaint; | 1736 GrPaint grPaint; |
1851 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { | 1737 if (!SkPaint2GrPaintShader(this, paint, true, &grPaint)) { |
1852 return; | 1738 return; |
1853 } | 1739 } |
1854 | 1740 |
1855 SkDEBUGCODE(this->validate();) | 1741 SkDEBUGCODE(this->validate();) |
1856 | 1742 |
1857 fFallbackTextContext->drawPosText(grPaint, paint, (const char *)text, by
teLength, pos, | 1743 fFallbackTextContext->drawPosText(grPaint, paint, (const char *)text, by
teLength, pos, |
1858 constY, scalarsPerPos); | 1744 constY, scalarsPerPos); |
1859 } else { | 1745 } else { |
1860 draw.drawPosText_asPaths((const char*)text, byteLength, pos, constY, | 1746 draw.drawPosText_asPaths((const char*)text, byteLength, pos, constY, |
1861 scalarsPerPos, paint); | 1747 scalarsPerPos, paint); |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2120 GrCachedLayer* layer = fContext->getLayerCache()->findLayerOrCreate(pict
ure, i); | 2006 GrCachedLayer* layer = fContext->getLayerCache()->findLayerOrCreate(pict
ure, i); |
2121 | 2007 |
2122 if (NULL != layer->getTexture()) { | 2008 if (NULL != layer->getTexture()) { |
2123 fContext->unlockScratchTexture(layer->getTexture()); | 2009 fContext->unlockScratchTexture(layer->getTexture()); |
2124 layer->setTexture(NULL); | 2010 layer->setTexture(NULL); |
2125 } | 2011 } |
2126 } | 2012 } |
2127 | 2013 |
2128 return true; | 2014 return true; |
2129 } | 2015 } |
OLD | NEW |