Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(289)

Side by Side Diff: src/gpu/SkGpuDevice.cpp

Issue 283803003: Move skPaint2GrPaint to SkGr.h/cpp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add else clause to Sk2GrShader Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/gpu/SkGr.h ('k') | src/gpu/SkGr.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 SkPaint2GrPaintShader(this, paint, true, &grPaint);
515 return;
516 }
517 401
518 fContext->drawPaint(grPaint); 402 fContext->drawPaint(grPaint);
519 } 403 }
520 404
521 // must be in SkCanvas::PointMode order 405 // must be in SkCanvas::PointMode order
522 static const GrPrimitiveType gPointMode2PrimtiveType[] = { 406 static const GrPrimitiveType gPointMode2PrimtiveType[] = {
523 kPoints_GrPrimitiveType, 407 kPoints_GrPrimitiveType,
524 kLines_GrPrimitiveType, 408 kLines_GrPrimitiveType,
525 kLineStrip_GrPrimitiveType 409 kLineStrip_GrPrimitiveType
526 }; 410 };
527 411
528 void SkGpuDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, 412 void SkGpuDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode,
529 size_t count, const SkPoint pts[], const SkPaint& p aint) { 413 size_t count, const SkPoint pts[], const SkPaint& p aint) {
530 CHECK_FOR_ANNOTATION(paint); 414 CHECK_FOR_ANNOTATION(paint);
531 CHECK_SHOULD_DRAW(draw, false); 415 CHECK_SHOULD_DRAW(draw, false);
532 416
533 SkScalar width = paint.getStrokeWidth(); 417 SkScalar width = paint.getStrokeWidth();
534 if (width < 0) { 418 if (width < 0) {
535 return; 419 return;
536 } 420 }
537 421
538 // we only handle hairlines and paints without path effects or mask filters, 422 // we only handle hairlines and paints without path effects or mask filters,
539 // else we let the SkDraw call our drawPath() 423 // else we let the SkDraw call our drawPath()
540 if (width > 0 || paint.getPathEffect() || paint.getMaskFilter()) { 424 if (width > 0 || paint.getPathEffect() || paint.getMaskFilter()) {
541 draw.drawPoints(mode, count, pts, paint, true); 425 draw.drawPoints(mode, count, pts, paint, true);
542 return; 426 return;
543 } 427 }
544 428
545 GrPaint grPaint; 429 GrPaint grPaint;
546 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { 430 SkPaint2GrPaintShader(this, paint, true, &grPaint);
547 return;
548 }
549 431
550 fContext->drawVertices(grPaint, 432 fContext->drawVertices(grPaint,
551 gPointMode2PrimtiveType[mode], 433 gPointMode2PrimtiveType[mode],
552 SkToS32(count), 434 SkToS32(count),
553 (SkPoint*)pts, 435 (SkPoint*)pts,
554 NULL, 436 NULL,
555 NULL, 437 NULL,
556 NULL, 438 NULL,
557 0); 439 0);
558 } 440 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 } 477 }
596 478
597 if (usePath) { 479 if (usePath) {
598 SkPath path; 480 SkPath path;
599 path.addRect(rect); 481 path.addRect(rect);
600 this->drawPath(draw, path, paint, NULL, true); 482 this->drawPath(draw, path, paint, NULL, true);
601 return; 483 return;
602 } 484 }
603 485
604 GrPaint grPaint; 486 GrPaint grPaint;
605 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { 487 SkPaint2GrPaintShader(this, paint, true, &grPaint);
606 return;
607 }
608 488
609 if (!doStroke) { 489 if (!doStroke) {
610 fContext->drawRect(grPaint, rect); 490 fContext->drawRect(grPaint, rect);
611 } else { 491 } else {
612 SkStrokeRec stroke(paint); 492 SkStrokeRec stroke(paint);
613 fContext->drawRect(grPaint, rect, &stroke); 493 fContext->drawRect(grPaint, rect, &stroke);
614 } 494 }
615 } 495 }
616 496
617 /////////////////////////////////////////////////////////////////////////////// 497 ///////////////////////////////////////////////////////////////////////////////
618 498
619 void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rect, 499 void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rect,
620 const SkPaint& paint) { 500 const SkPaint& paint) {
621 CHECK_FOR_ANNOTATION(paint); 501 CHECK_FOR_ANNOTATION(paint);
622 CHECK_SHOULD_DRAW(draw, false); 502 CHECK_SHOULD_DRAW(draw, false);
623 503
624 GrPaint grPaint; 504 GrPaint grPaint;
625 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { 505 SkPaint2GrPaintShader(this, paint, true, &grPaint);
626 return;
627 }
628 506
629 SkStrokeRec stroke(paint); 507 SkStrokeRec stroke(paint);
630 if (paint.getMaskFilter()) { 508 if (paint.getMaskFilter()) {
631 // try to hit the fast path for drawing filtered round rects 509 // try to hit the fast path for drawing filtered round rects
632 510
633 SkRRect devRRect; 511 SkRRect devRRect;
634 if (rect.transform(fContext->getMatrix(), &devRRect)) { 512 if (rect.transform(fContext->getMatrix(), &devRRect)) {
635 if (devRRect.allCornersCircular()) { 513 if (devRRect.allCornersCircular()) {
636 SkRect maskRect; 514 SkRect maskRect;
637 if (paint.getMaskFilter()->canFilterMaskGPU(devRRect.rect(), 515 if (paint.getMaskFilter()->canFilterMaskGPU(devRRect.rect(),
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 549
672 void SkGpuDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer, 550 void SkGpuDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer,
673 const SkRRect& inner, const SkPaint& paint) { 551 const SkRRect& inner, const SkPaint& paint) {
674 SkStrokeRec stroke(paint); 552 SkStrokeRec stroke(paint);
675 if (stroke.isFillStyle()) { 553 if (stroke.isFillStyle()) {
676 554
677 CHECK_FOR_ANNOTATION(paint); 555 CHECK_FOR_ANNOTATION(paint);
678 CHECK_SHOULD_DRAW(draw, false); 556 CHECK_SHOULD_DRAW(draw, false);
679 557
680 GrPaint grPaint; 558 GrPaint grPaint;
681 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { 559 SkPaint2GrPaintShader(this, paint, true, &grPaint);
682 return;
683 }
684 560
685 if (NULL == paint.getMaskFilter() && NULL == paint.getPathEffect()) { 561 if (NULL == paint.getMaskFilter() && NULL == paint.getPathEffect()) {
686 fContext->drawDRRect(grPaint, outer, inner); 562 fContext->drawDRRect(grPaint, outer, inner);
687 return; 563 return;
688 } 564 }
689 } 565 }
690 566
691 SkPath path; 567 SkPath path;
692 path.addRRect(outer); 568 path.addRRect(outer);
693 path.addRRect(inner); 569 path.addRRect(inner);
(...skipping 17 matching lines...) Expand all
711 } 587 }
712 588
713 if (usePath) { 589 if (usePath) {
714 SkPath path; 590 SkPath path;
715 path.addOval(oval); 591 path.addOval(oval);
716 this->drawPath(draw, path, paint, NULL, true); 592 this->drawPath(draw, path, paint, NULL, true);
717 return; 593 return;
718 } 594 }
719 595
720 GrPaint grPaint; 596 GrPaint grPaint;
721 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { 597 SkPaint2GrPaintShader(this, paint, true, &grPaint);
722 return;
723 }
724 SkStrokeRec stroke(paint); 598 SkStrokeRec stroke(paint);
725 599
726 fContext->drawOval(grPaint, oval, stroke); 600 fContext->drawOval(grPaint, oval, stroke);
727 } 601 }
728 602
729 #include "SkMaskFilter.h" 603 #include "SkMaskFilter.h"
730 #include "SkBounder.h" 604 #include "SkBounder.h"
731 605
732 /////////////////////////////////////////////////////////////////////////////// 606 ///////////////////////////////////////////////////////////////////////////////
733 607
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 738
865 }; 739 };
866 740
867 void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath, 741 void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath,
868 const SkPaint& paint, const SkMatrix* prePathMatrix, 742 const SkPaint& paint, const SkMatrix* prePathMatrix,
869 bool pathIsMutable) { 743 bool pathIsMutable) {
870 CHECK_FOR_ANNOTATION(paint); 744 CHECK_FOR_ANNOTATION(paint);
871 CHECK_SHOULD_DRAW(draw, false); 745 CHECK_SHOULD_DRAW(draw, false);
872 746
873 GrPaint grPaint; 747 GrPaint grPaint;
874 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { 748 SkPaint2GrPaintShader(this, paint, true, &grPaint);
875 return;
876 }
877 749
878 // If we have a prematrix, apply it to the path, optimizing for the case 750 // 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 751 // where the original path can in fact be modified in place (even though
880 // its parameter type is const). 752 // its parameter type is const).
881 SkPath* pathPtr = const_cast<SkPath*>(&origSrcPath); 753 SkPath* pathPtr = const_cast<SkPath*>(&origSrcPath);
882 SkTLazy<SkPath> tmpPath; 754 SkTLazy<SkPath> tmpPath;
883 SkTLazy<SkPath> effectPath; 755 SkTLazy<SkPath> effectPath;
884 756
885 if (prePathMatrix) { 757 if (prePathMatrix) {
886 SkPath* result = pathPtr; 758 SkPath* result = pathPtr;
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after
1514 effect.reset(GrBicubicEffect::Create(texture, SkMatrix::I(), tileModes)) ; 1386 effect.reset(GrBicubicEffect::Create(texture, SkMatrix::I(), tileModes)) ;
1515 } else { 1387 } else {
1516 effect.reset(GrSimpleTextureEffect::Create(texture, SkMatrix::I(), param s)); 1388 effect.reset(GrSimpleTextureEffect::Create(texture, SkMatrix::I(), param s));
1517 } 1389 }
1518 1390
1519 // Construct a GrPaint by setting the bitmap texture as the first effect and then configuring 1391 // Construct a GrPaint by setting the bitmap texture as the first effect and then configuring
1520 // the rest from the SkPaint. 1392 // the rest from the SkPaint.
1521 GrPaint grPaint; 1393 GrPaint grPaint;
1522 grPaint.addColorEffect(effect); 1394 grPaint.addColorEffect(effect);
1523 bool alphaOnly = !(SkBitmap::kA8_Config == bitmap.config()); 1395 bool alphaOnly = !(SkBitmap::kA8_Config == bitmap.config());
1524 if (!skPaint2GrPaintNoShader(this, paint, alphaOnly, false, &grPaint)) { 1396 SkPaint2GrPaintNoShader(this, paint, alphaOnly, false, &grPaint);
1525 return;
1526 }
1527 1397
1528 fContext->drawRectToRect(grPaint, dstRect, paintRect, NULL); 1398 fContext->drawRectToRect(grPaint, dstRect, paintRect, NULL);
1529 } 1399 }
1530 1400
1531 static bool filter_texture(SkBaseDevice* device, GrContext* context, 1401 static bool filter_texture(SkBaseDevice* device, GrContext* context,
1532 GrTexture* texture, const SkImageFilter* filter, 1402 GrTexture* texture, const SkImageFilter* filter,
1533 int w, int h, const SkImageFilter::Context& ctx, 1403 int w, int h, const SkImageFilter::Context& ctx,
1534 SkBitmap* result, SkIPoint* offset) { 1404 SkBitmap* result, SkIPoint* offset) {
1535 SkASSERT(filter); 1405 SkASSERT(filter);
1536 SkDeviceImageFilterProxy proxy(device); 1406 SkDeviceImageFilterProxy proxy(device);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1582 left += offset.x(); 1452 left += offset.x();
1583 top += offset.y(); 1453 top += offset.y();
1584 } else { 1454 } else {
1585 return; 1455 return;
1586 } 1456 }
1587 } 1457 }
1588 1458
1589 GrPaint grPaint; 1459 GrPaint grPaint;
1590 grPaint.addColorTextureEffect(texture, SkMatrix::I()); 1460 grPaint.addColorTextureEffect(texture, SkMatrix::I());
1591 1461
1592 if(!skPaint2GrPaintNoShader(this, paint, true, false, &grPaint)) { 1462 SkPaint2GrPaintNoShader(this, paint, true, false, &grPaint);
1593 return;
1594 }
1595 1463
1596 fContext->drawRectToRect(grPaint, 1464 fContext->drawRectToRect(grPaint,
1597 SkRect::MakeXYWH(SkIntToScalar(left), 1465 SkRect::MakeXYWH(SkIntToScalar(left),
1598 SkIntToScalar(top), 1466 SkIntToScalar(top),
1599 SkIntToScalar(w), 1467 SkIntToScalar(w),
1600 SkIntToScalar(h)), 1468 SkIntToScalar(h)),
1601 SkRect::MakeXYWH(0, 1469 SkRect::MakeXYWH(0,
1602 0, 1470 0,
1603 SK_Scalar1 * w / texture->width(), 1471 SK_Scalar1 * w / texture->width(),
1604 SK_Scalar1 * h / texture->height() )); 1472 SK_Scalar1 * h / texture->height() ));
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1692 x += offset.fX; 1560 x += offset.fX;
1693 y += offset.fY; 1561 y += offset.fY;
1694 } else { 1562 } else {
1695 return; 1563 return;
1696 } 1564 }
1697 } 1565 }
1698 1566
1699 GrPaint grPaint; 1567 GrPaint grPaint;
1700 grPaint.addColorTextureEffect(devTex, SkMatrix::I()); 1568 grPaint.addColorTextureEffect(devTex, SkMatrix::I());
1701 1569
1702 if (!skPaint2GrPaintNoShader(this, paint, true, false, &grPaint)) { 1570 SkPaint2GrPaintNoShader(this, paint, true, false, &grPaint);
1703 return;
1704 }
1705 1571
1706 SkRect dstRect = SkRect::MakeXYWH(SkIntToScalar(x), 1572 SkRect dstRect = SkRect::MakeXYWH(SkIntToScalar(x),
1707 SkIntToScalar(y), 1573 SkIntToScalar(y),
1708 SkIntToScalar(w), 1574 SkIntToScalar(w),
1709 SkIntToScalar(h)); 1575 SkIntToScalar(h));
1710 1576
1711 // The device being drawn may not fill up its texture (e.g. saveLayer uses a pproximate 1577 // The device being drawn may not fill up its texture (e.g. saveLayer uses a pproximate
1712 // scratch texture). 1578 // scratch texture).
1713 SkRect srcRect = SkRect::MakeWH(SK_Scalar1 * w / devTex->width(), 1579 SkRect srcRect = SkRect::MakeWH(SK_Scalar1 * w / devTex->width(),
1714 SK_Scalar1 * h / devTex->height()); 1580 SK_Scalar1 * h / devTex->height());
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1755 int vertexCount, const SkPoint vertices[], 1621 int vertexCount, const SkPoint vertices[],
1756 const SkPoint texs[], const SkColor colors[], 1622 const SkPoint texs[], const SkColor colors[],
1757 SkXfermode* xmode, 1623 SkXfermode* xmode,
1758 const uint16_t indices[], int indexCount, 1624 const uint16_t indices[], int indexCount,
1759 const SkPaint& paint) { 1625 const SkPaint& paint) {
1760 CHECK_SHOULD_DRAW(draw, false); 1626 CHECK_SHOULD_DRAW(draw, false);
1761 1627
1762 GrPaint grPaint; 1628 GrPaint grPaint;
1763 // we ignore the shader if texs is null. 1629 // we ignore the shader if texs is null.
1764 if (NULL == texs) { 1630 if (NULL == texs) {
1765 if (!skPaint2GrPaintNoShader(this, paint, false, NULL == colors, &grPain t)) { 1631 SkPaint2GrPaintNoShader(this, paint, false, NULL == colors, &grPaint);
1766 return;
1767 }
1768 } else { 1632 } else {
1769 if (!skPaint2GrPaintShader(this, paint, NULL == colors, &grPaint)) { 1633 SkPaint2GrPaintShader(this, paint, NULL == colors, &grPaint);
1770 return;
1771 }
1772 } 1634 }
1773 1635
1774 if (NULL != xmode && NULL != texs && NULL != colors) { 1636 if (NULL != xmode && NULL != texs && NULL != colors) {
1775 if (!SkXfermode::IsMode(xmode, SkXfermode::kModulate_Mode)) { 1637 if (!SkXfermode::IsMode(xmode, SkXfermode::kModulate_Mode)) {
1776 SkDebugf("Unsupported vertex-color/texture xfer mode.\n"); 1638 SkDebugf("Unsupported vertex-color/texture xfer mode.\n");
1777 #if 0 1639 #if 0
1778 return 1640 return
1779 #endif 1641 #endif
1780 } 1642 }
1781 } 1643 }
(...skipping 19 matching lines...) Expand all
1801 1663
1802 /////////////////////////////////////////////////////////////////////////////// 1664 ///////////////////////////////////////////////////////////////////////////////
1803 1665
1804 void SkGpuDevice::drawText(const SkDraw& draw, const void* text, 1666 void SkGpuDevice::drawText(const SkDraw& draw, const void* text,
1805 size_t byteLength, SkScalar x, SkScalar y, 1667 size_t byteLength, SkScalar x, SkScalar y,
1806 const SkPaint& paint) { 1668 const SkPaint& paint) {
1807 CHECK_SHOULD_DRAW(draw, false); 1669 CHECK_SHOULD_DRAW(draw, false);
1808 1670
1809 if (fMainTextContext->canDraw(paint)) { 1671 if (fMainTextContext->canDraw(paint)) {
1810 GrPaint grPaint; 1672 GrPaint grPaint;
1811 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { 1673 SkPaint2GrPaintShader(this, paint, true, &grPaint);
1812 return;
1813 }
1814 1674
1815 SkDEBUGCODE(this->validate();) 1675 SkDEBUGCODE(this->validate();)
1816 1676
1817 fMainTextContext->drawText(grPaint, paint, (const char *)text, byteLengt h, x, y); 1677 fMainTextContext->drawText(grPaint, paint, (const char *)text, byteLengt h, x, y);
1818 } else if (fFallbackTextContext && fFallbackTextContext->canDraw(paint)) { 1678 } else if (fFallbackTextContext && fFallbackTextContext->canDraw(paint)) {
1819 GrPaint grPaint; 1679 GrPaint grPaint;
1820 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { 1680 SkPaint2GrPaintShader(this, paint, true, &grPaint);
1821 return;
1822 }
1823 1681
1824 SkDEBUGCODE(this->validate();) 1682 SkDEBUGCODE(this->validate();)
1825 1683
1826 fFallbackTextContext->drawText(grPaint, paint, (const char *)text, byteL ength, x, y); 1684 fFallbackTextContext->drawText(grPaint, paint, (const char *)text, byteL ength, x, y);
1827 } else { 1685 } else {
1828 // this guy will just call our drawPath() 1686 // this guy will just call our drawPath()
1829 draw.drawText_asPaths((const char*)text, byteLength, x, y, paint); 1687 draw.drawText_asPaths((const char*)text, byteLength, x, y, paint);
1830 } 1688 }
1831 } 1689 }
1832 1690
1833 void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, 1691 void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text,
1834 size_t byteLength, const SkScalar pos[], 1692 size_t byteLength, const SkScalar pos[],
1835 SkScalar constY, int scalarsPerPos, 1693 SkScalar constY, int scalarsPerPos,
1836 const SkPaint& paint) { 1694 const SkPaint& paint) {
1837 CHECK_SHOULD_DRAW(draw, false); 1695 CHECK_SHOULD_DRAW(draw, false);
1838 1696
1839 if (fMainTextContext->canDraw(paint)) { 1697 if (fMainTextContext->canDraw(paint)) {
1840 GrPaint grPaint; 1698 GrPaint grPaint;
1841 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { 1699 SkPaint2GrPaintShader(this, paint, true, &grPaint);
1842 return;
1843 }
1844 1700
1845 SkDEBUGCODE(this->validate();) 1701 SkDEBUGCODE(this->validate();)
1846 1702
1847 fMainTextContext->drawPosText(grPaint, paint, (const char *)text, byteLe ngth, pos, 1703 fMainTextContext->drawPosText(grPaint, paint, (const char *)text, byteLe ngth, pos,
1848 constY, scalarsPerPos); 1704 constY, scalarsPerPos);
1849 } else if (fFallbackTextContext && fFallbackTextContext->canDraw(paint)) { 1705 } else if (fFallbackTextContext && fFallbackTextContext->canDraw(paint)) {
1850 GrPaint grPaint; 1706 GrPaint grPaint;
1851 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { 1707 SkPaint2GrPaintShader(this, paint, true, &grPaint);
1852 return;
1853 }
1854 1708
1855 SkDEBUGCODE(this->validate();) 1709 SkDEBUGCODE(this->validate();)
1856 1710
1857 fFallbackTextContext->drawPosText(grPaint, paint, (const char *)text, by teLength, pos, 1711 fFallbackTextContext->drawPosText(grPaint, paint, (const char *)text, by teLength, pos,
1858 constY, scalarsPerPos); 1712 constY, scalarsPerPos);
1859 } else { 1713 } else {
1860 draw.drawPosText_asPaths((const char*)text, byteLength, pos, constY, 1714 draw.drawPosText_asPaths((const char*)text, byteLength, pos, constY,
1861 scalarsPerPos, paint); 1715 scalarsPerPos, paint);
1862 } 1716 }
1863 } 1717 }
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
2120 GrCachedLayer* layer = fContext->getLayerCache()->findLayerOrCreate(pict ure, i); 1974 GrCachedLayer* layer = fContext->getLayerCache()->findLayerOrCreate(pict ure, i);
2121 1975
2122 if (NULL != layer->getTexture()) { 1976 if (NULL != layer->getTexture()) {
2123 fContext->unlockScratchTexture(layer->getTexture()); 1977 fContext->unlockScratchTexture(layer->getTexture());
2124 layer->setTexture(NULL); 1978 layer->setTexture(NULL);
2125 } 1979 }
2126 } 1980 }
2127 1981
2128 return true; 1982 return true;
2129 } 1983 }
OLDNEW
« no previous file with comments | « include/gpu/SkGr.h ('k') | src/gpu/SkGr.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698