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 "SkDebugCanvas.h" | 8 #include "SkDebugCanvas.h" |
9 #include "SkDevice.h" | 9 #include "SkDevice.h" |
10 #include "SkForceLinking.h" | 10 #include "SkForceLinking.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 } | 77 } |
78 | 78 |
79 // Fold the saveLayer's alpha into the drawBitmapRect and remove the saveLayer | 79 // Fold the saveLayer's alpha into the drawBitmapRect and remove the saveLayer |
80 // and restore | 80 // and restore |
81 static void apply_0(SkDebugCanvas* canvas, int curCommand) { | 81 static void apply_0(SkDebugCanvas* canvas, int curCommand) { |
82 SkSaveLayerCommand* saveLayer = | 82 SkSaveLayerCommand* saveLayer = |
83 (SkSaveLayerCommand*) canvas->getDrawCommandAt(curCommand); | 83 (SkSaveLayerCommand*) canvas->getDrawCommandAt(curCommand); |
84 const SkPaint* saveLayerPaint = saveLayer->paint(); | 84 const SkPaint* saveLayerPaint = saveLayer->paint(); |
85 | 85 |
86 // if (NULL == saveLayerPaint) the dbmr's paint doesn't need to be changed | 86 // if (NULL == saveLayerPaint) the dbmr's paint doesn't need to be changed |
87 if (NULL != saveLayerPaint) { | 87 if (saveLayerPaint) { |
88 SkDrawBitmapRectCommand* dbmr = | 88 SkDrawBitmapRectCommand* dbmr = |
89 (SkDrawBitmapRectCommand*) canvas->getDrawCommandAt(curCommand+1); | 89 (SkDrawBitmapRectCommand*) canvas->getDrawCommandAt(curCommand+1); |
90 SkPaint* dbmrPaint = dbmr->paint(); | 90 SkPaint* dbmrPaint = dbmr->paint(); |
91 | 91 |
92 if (NULL == dbmrPaint) { | 92 if (NULL == dbmrPaint) { |
93 // if the DBMR doesn't have a paint just use the saveLayer's | 93 // if the DBMR doesn't have a paint just use the saveLayer's |
94 dbmr->setPaint(*saveLayerPaint); | 94 dbmr->setPaint(*saveLayerPaint); |
95 } else if (NULL != saveLayerPaint) { | 95 } else if (saveLayerPaint) { |
96 // Both paints are present so their alphas need to be combined | 96 // Both paints are present so their alphas need to be combined |
97 SkColor color = saveLayerPaint->getColor(); | 97 SkColor color = saveLayerPaint->getColor(); |
98 int a0 = SkColorGetA(color); | 98 int a0 = SkColorGetA(color); |
99 | 99 |
100 color = dbmrPaint->getColor(); | 100 color = dbmrPaint->getColor(); |
101 int a1 = SkColorGetA(color); | 101 int a1 = SkColorGetA(color); |
102 | 102 |
103 int newA = SkMulDiv255Round(a0, a1); | 103 int newA = SkMulDiv255Round(a0, a1); |
104 SkASSERT(newA <= 0xFF); | 104 SkASSERT(newA <= 0xFF); |
105 | 105 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 } | 155 } |
156 | 156 |
157 // Fold the saveLayer's alpha into the drawBitmapRect and remove the saveLayer | 157 // Fold the saveLayer's alpha into the drawBitmapRect and remove the saveLayer |
158 // and restore | 158 // and restore |
159 static void apply_1(SkDebugCanvas* canvas, int curCommand) { | 159 static void apply_1(SkDebugCanvas* canvas, int curCommand) { |
160 SkSaveLayerCommand* saveLayer = | 160 SkSaveLayerCommand* saveLayer = |
161 (SkSaveLayerCommand*) canvas->getDrawCommandAt(curCommand); | 161 (SkSaveLayerCommand*) canvas->getDrawCommandAt(curCommand); |
162 const SkPaint* saveLayerPaint = saveLayer->paint(); | 162 const SkPaint* saveLayerPaint = saveLayer->paint(); |
163 | 163 |
164 // if (NULL == saveLayerPaint) the dbmr's paint doesn't need to be changed | 164 // if (NULL == saveLayerPaint) the dbmr's paint doesn't need to be changed |
165 if (NULL != saveLayerPaint) { | 165 if (saveLayerPaint) { |
166 SkDrawBitmapRectCommand* dbmr = | 166 SkDrawBitmapRectCommand* dbmr = |
167 (SkDrawBitmapRectCommand*) canvas->getDrawCommandAt(curCommand+3); | 167 (SkDrawBitmapRectCommand*) canvas->getDrawCommandAt(curCommand+3); |
168 SkPaint* dbmrPaint = dbmr->paint(); | 168 SkPaint* dbmrPaint = dbmr->paint(); |
169 | 169 |
170 if (NULL == dbmrPaint) { | 170 if (NULL == dbmrPaint) { |
171 dbmr->setPaint(*saveLayerPaint); | 171 dbmr->setPaint(*saveLayerPaint); |
172 } else { | 172 } else { |
173 SkColor newColor = SkColorSetA(dbmrPaint->getColor(), | 173 SkColor newColor = SkColorSetA(dbmrPaint->getColor(), |
174 SkColorGetA(saveLayerPaint->getColor(
))); | 174 SkColorGetA(saveLayerPaint->getColor(
))); |
175 dbmrPaint->setColor(newColor); | 175 dbmrPaint->setColor(newColor); |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 } | 416 } |
417 } | 417 } |
418 | 418 |
419 if (!dbmr->dstRect().contains(clip2->rect())) { | 419 if (!dbmr->dstRect().contains(clip2->rect())) { |
420 return false; | 420 return false; |
421 } | 421 } |
422 | 422 |
423 const SkPaint* saveLayerPaint0 = saveLayer0->paint(); | 423 const SkPaint* saveLayerPaint0 = saveLayer0->paint(); |
424 const SkPaint* saveLayerPaint1 = saveLayer1->paint(); | 424 const SkPaint* saveLayerPaint1 = saveLayer1->paint(); |
425 | 425 |
426 if ((NULL != saveLayerPaint0 && !is_simple(*saveLayerPaint0)) || | 426 if ((saveLayerPaint0 && !is_simple(*saveLayerPaint0)) || |
427 (NULL != saveLayerPaint1 && !is_simple(*saveLayerPaint1))) { | 427 (saveLayerPaint1 && !is_simple(*saveLayerPaint1))) { |
428 return false; | 428 return false; |
429 } | 429 } |
430 | 430 |
431 SkPaint* dbmrPaint = dbmr->paint(); | 431 SkPaint* dbmrPaint = dbmr->paint(); |
432 | 432 |
433 if (NULL == dbmrPaint) { | 433 if (NULL == dbmrPaint) { |
434 return true; | 434 return true; |
435 } | 435 } |
436 | 436 |
437 if (NULL != saveLayerPaint0) { | 437 if (saveLayerPaint0) { |
438 SkColor layerColor0 = saveLayerPaint0->getColor() | 0xFF000000; // force
opaque | 438 SkColor layerColor0 = saveLayerPaint0->getColor() | 0xFF000000; // force
opaque |
439 if (dbmrPaint->getColor() != layerColor0) { | 439 if (dbmrPaint->getColor() != layerColor0) { |
440 return false; | 440 return false; |
441 } | 441 } |
442 } | 442 } |
443 | 443 |
444 if (NULL != saveLayerPaint1) { | 444 if (saveLayerPaint1) { |
445 SkColor layerColor1 = saveLayerPaint1->getColor() | 0xFF000000; // force
opaque | 445 SkColor layerColor1 = saveLayerPaint1->getColor() | 0xFF000000; // force
opaque |
446 if (dbmrPaint->getColor() != layerColor1) { | 446 if (dbmrPaint->getColor() != layerColor1) { |
447 return false; | 447 return false; |
448 } | 448 } |
449 } | 449 } |
450 | 450 |
451 return true; | 451 return true; |
452 } | 452 } |
453 | 453 |
454 // Reduce to a single drawBitmapRectToRect call by folding the clipRect's into | 454 // Reduce to a single drawBitmapRectToRect call by folding the clipRect's into |
(...skipping 15 matching lines...) Expand all Loading... |
470 SkRect newSrc = SkRect::MakeXYWH(newSrcLeft, newSrcTop, | 470 SkRect newSrc = SkRect::MakeXYWH(newSrcLeft, newSrcTop, |
471 clip2->rect().width(), clip2->rect().height
()); | 471 clip2->rect().width(), clip2->rect().height
()); |
472 | 472 |
473 dbmr->setSrcRect(newSrc); | 473 dbmr->setSrcRect(newSrc); |
474 dbmr->setDstRect(clip2->rect()); | 474 dbmr->setDstRect(clip2->rect()); |
475 | 475 |
476 SkColor color = 0xFF000000; | 476 SkColor color = 0xFF000000; |
477 int a0, a1; | 477 int a0, a1; |
478 | 478 |
479 const SkPaint* saveLayerPaint0 = saveLayer0->paint(); | 479 const SkPaint* saveLayerPaint0 = saveLayer0->paint(); |
480 if (NULL != saveLayerPaint0) { | 480 if (saveLayerPaint0) { |
481 color = saveLayerPaint0->getColor(); | 481 color = saveLayerPaint0->getColor(); |
482 a0 = SkColorGetA(color); | 482 a0 = SkColorGetA(color); |
483 } else { | 483 } else { |
484 a0 = 0xFF; | 484 a0 = 0xFF; |
485 } | 485 } |
486 | 486 |
487 const SkPaint* saveLayerPaint1 = saveLayer1->paint(); | 487 const SkPaint* saveLayerPaint1 = saveLayer1->paint(); |
488 if (NULL != saveLayerPaint1) { | 488 if (saveLayerPaint1) { |
489 color = saveLayerPaint1->getColor(); | 489 color = saveLayerPaint1->getColor(); |
490 a1 = SkColorGetA(color); | 490 a1 = SkColorGetA(color); |
491 } else { | 491 } else { |
492 a1 = 0xFF; | 492 a1 = 0xFF; |
493 } | 493 } |
494 | 494 |
495 int newA = SkMulDiv255Round(a0, a1); | 495 int newA = SkMulDiv255Round(a0, a1); |
496 SkASSERT(newA <= 0xFF); | 496 SkASSERT(newA <= 0xFF); |
497 | 497 |
498 SkPaint* dbmrPaint = dbmr->paint(); | 498 SkPaint* dbmrPaint = dbmr->paint(); |
499 | 499 |
500 if (NULL != dbmrPaint) { | 500 if (dbmrPaint) { |
501 SkColor newColor = SkColorSetA(dbmrPaint->getColor(), newA); | 501 SkColor newColor = SkColorSetA(dbmrPaint->getColor(), newA); |
502 dbmrPaint->setColor(newColor); | 502 dbmrPaint->setColor(newColor); |
503 } else { | 503 } else { |
504 SkColor newColor = SkColorSetA(color, newA); | 504 SkColor newColor = SkColorSetA(color, newA); |
505 | 505 |
506 SkPaint newPaint; | 506 SkPaint newPaint; |
507 newPaint.setColor(newColor); | 507 newPaint.setColor(newColor); |
508 dbmr->setPaint(newPaint); | 508 dbmr->setPaint(newPaint); |
509 } | 509 } |
510 | 510 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
572 | 572 |
573 // Fold the clipRect into the drawBitmapRectToRect's src and dest rects | 573 // Fold the clipRect into the drawBitmapRectToRect's src and dest rects |
574 static void apply_8(SkDebugCanvas* canvas, int curCommand) { | 574 static void apply_8(SkDebugCanvas* canvas, int curCommand) { |
575 SkClipRectCommand* clip = | 575 SkClipRectCommand* clip = |
576 (SkClipRectCommand*) canvas->getDrawCommandAt(curCommand+1); | 576 (SkClipRectCommand*) canvas->getDrawCommandAt(curCommand+1); |
577 SkDrawBitmapRectCommand* dbmr = | 577 SkDrawBitmapRectCommand* dbmr = |
578 (SkDrawBitmapRectCommand*) canvas->getDrawCommandAt(curCommand+2); | 578 (SkDrawBitmapRectCommand*) canvas->getDrawCommandAt(curCommand+2); |
579 | 579 |
580 SkScalar newSrcLeft, newSrcTop; | 580 SkScalar newSrcLeft, newSrcTop; |
581 | 581 |
582 if (NULL != dbmr->srcRect()) { | 582 if (dbmr->srcRect()) { |
583 newSrcLeft = dbmr->srcRect()->fLeft + clip->rect().fLeft - dbmr->dstRect
().fLeft; | 583 newSrcLeft = dbmr->srcRect()->fLeft + clip->rect().fLeft - dbmr->dstRect
().fLeft; |
584 newSrcTop = dbmr->srcRect()->fTop + clip->rect().fTop - dbmr->dstRect()
.fTop; | 584 newSrcTop = dbmr->srcRect()->fTop + clip->rect().fTop - dbmr->dstRect()
.fTop; |
585 } else { | 585 } else { |
586 newSrcLeft = clip->rect().fLeft - dbmr->dstRect().fLeft; | 586 newSrcLeft = clip->rect().fLeft - dbmr->dstRect().fLeft; |
587 newSrcTop = clip->rect().fTop - dbmr->dstRect().fTop; | 587 newSrcTop = clip->rect().fTop - dbmr->dstRect().fTop; |
588 } | 588 } |
589 | 589 |
590 SkRect newSrc = SkRect::MakeXYWH(newSrcLeft, newSrcTop, | 590 SkRect newSrc = SkRect::MakeXYWH(newSrcLeft, newSrcTop, |
591 clip->rect().width(), clip->rect().height()
); | 591 clip->rect().width(), clip->rect().height()
); |
592 | 592 |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
839 | 839 |
840 SkGraphics::Term(); | 840 SkGraphics::Term(); |
841 return 0; | 841 return 0; |
842 } | 842 } |
843 | 843 |
844 #if !defined SK_BUILD_FOR_IOS | 844 #if !defined SK_BUILD_FOR_IOS |
845 int main(int argc, char * const argv[]) { | 845 int main(int argc, char * const argv[]) { |
846 return tool_main(argc, (char**) argv); | 846 return tool_main(argc, (char**) argv); |
847 } | 847 } |
848 #endif | 848 #endif |
OLD | NEW |