| 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 "SkGraphics.h" | 10 #include "SkGraphics.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 return false; | 54 return false; |
| 55 } | 55 } |
| 56 | 56 |
| 57 SaveLayer* saveLayer = (SaveLayer*) canvas->getDrawCommandAt(curCommand); | 57 SaveLayer* saveLayer = (SaveLayer*) canvas->getDrawCommandAt(curCommand); |
| 58 DrawBitmapRect* dbmr = (DrawBitmapRect*) canvas->getDrawCommandAt(curCommand
+1); | 58 DrawBitmapRect* dbmr = (DrawBitmapRect*) canvas->getDrawCommandAt(curCommand
+1); |
| 59 | 59 |
| 60 const SkPaint* saveLayerPaint = saveLayer->paint(); | 60 const SkPaint* saveLayerPaint = saveLayer->paint(); |
| 61 SkPaint* dbmrPaint = dbmr->paint(); | 61 SkPaint* dbmrPaint = dbmr->paint(); |
| 62 | 62 |
| 63 // For this optimization we only fold the saveLayer and drawBitmapRect | 63 // For this optimization we only fold the saveLayer and drawBitmapRect |
| 64 // together if the saveLayer's draw is simple (i.e., no fancy effects) and | 64 // together if the saveLayer's draw is simple (i.e., no fancy effects) |
| 65 // and the only difference in the colors is that the saveLayer's can have | 65 // and the only difference in the colors is their alpha value |
| 66 // an alpha while the drawBitmapRect's is opaque. | 66 SkColor layerColor = saveLayerPaint->getColor() | 0xFF000000; // force opaqu
e |
| 67 // TODO: it should be possible to fold them together even if they both | 67 SkColor dbmrColor = dbmrPaint->getColor() | 0xFF000000; // force opaqu
e |
| 68 // have different non-255 alphas but this is low priority since we have | 68 |
| 69 // never seen that case | |
| 70 // If either operation lacks a paint then the collapse is trivial | 69 // If either operation lacks a paint then the collapse is trivial |
| 71 SkColor layerColor = saveLayerPaint->getColor() | 0xFF000000; // force opaqu
e | |
| 72 | |
| 73 return NULL == saveLayerPaint || | 70 return NULL == saveLayerPaint || |
| 74 NULL == dbmrPaint || | 71 NULL == dbmrPaint || |
| 75 (is_simple(*saveLayerPaint) && dbmrPaint->getColor() == layerColor); | 72 (is_simple(*saveLayerPaint) && dbmrColor == layerColor); |
| 76 } | 73 } |
| 77 | 74 |
| 78 // Fold the saveLayer's alpha into the drawBitmapRect and remove the saveLayer | 75 // Fold the saveLayer's alpha into the drawBitmapRect and remove the saveLayer |
| 79 // and restore | 76 // and restore |
| 80 static void apply_0(SkDebugCanvas* canvas, int curCommand) { | 77 static void apply_0(SkDebugCanvas* canvas, int curCommand) { |
| 81 SaveLayer* saveLayer = (SaveLayer*) canvas->getDrawCommandAt(curCommand); | 78 SaveLayer* saveLayer = (SaveLayer*) canvas->getDrawCommandAt(curCommand); |
| 82 const SkPaint* saveLayerPaint = saveLayer->paint(); | 79 const SkPaint* saveLayerPaint = saveLayer->paint(); |
| 83 | 80 |
| 84 // if (NULL == saveLayerPaint) the dbmr's paint doesn't need to be changed | 81 // if (NULL == saveLayerPaint) the dbmr's paint doesn't need to be changed |
| 85 if (NULL != saveLayerPaint) { | 82 if (NULL != saveLayerPaint) { |
| 86 DrawBitmapRect* dbmr = (DrawBitmapRect*) canvas->getDrawCommandAt(curCom
mand+1); | 83 DrawBitmapRect* dbmr = (DrawBitmapRect*) canvas->getDrawCommandAt(curCom
mand+1); |
| 87 SkPaint* dbmrPaint = dbmr->paint(); | 84 SkPaint* dbmrPaint = dbmr->paint(); |
| 88 | 85 |
| 89 if (NULL == dbmrPaint) { | 86 if (NULL == dbmrPaint) { |
| 90 // if the DBMR doesn't have a paint just use the saveLayer's | 87 // if the DBMR doesn't have a paint just use the saveLayer's |
| 91 dbmr->setPaint(*saveLayerPaint); | 88 dbmr->setPaint(*saveLayerPaint); |
| 92 } else if (NULL != saveLayerPaint) { | 89 } else if (NULL != saveLayerPaint) { |
| 93 SkColor newColor = SkColorSetA(dbmrPaint->getColor(), | 90 // Both paints are present so their alphas need to be combined |
| 94 SkColorGetA(saveLayerPaint->getColor(
))); | 91 SkColor color = saveLayerPaint->getColor(); |
| 92 int a0 = SkColorGetA(color); |
| 93 |
| 94 color = dbmrPaint->getColor(); |
| 95 int a1 = SkColorGetA(color); |
| 96 |
| 97 int newA = SkMulDiv255Round(a0, a1); |
| 98 SkASSERT(newA <= 0xFF); |
| 99 |
| 100 SkColor newColor = SkColorSetA(color, newA); |
| 95 dbmrPaint->setColor(newColor); | 101 dbmrPaint->setColor(newColor); |
| 96 } | 102 } |
| 97 } | 103 } |
| 98 | 104 |
| 99 canvas->deleteDrawCommandAt(curCommand+2); // restore | 105 canvas->deleteDrawCommandAt(curCommand+2); // restore |
| 100 canvas->deleteDrawCommandAt(curCommand); // saveLayer | 106 canvas->deleteDrawCommandAt(curCommand); // saveLayer |
| 101 } | 107 } |
| 102 | 108 |
| 103 // Check for: | 109 // Check for: |
| 104 // SAVE_LAYER | 110 // SAVE_LAYER |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 } | 456 } |
| 451 | 457 |
| 452 const SkPaint* saveLayerPaint1 = saveLayer1->paint(); | 458 const SkPaint* saveLayerPaint1 = saveLayer1->paint(); |
| 453 if (NULL != saveLayerPaint1) { | 459 if (NULL != saveLayerPaint1) { |
| 454 color = saveLayerPaint1->getColor(); | 460 color = saveLayerPaint1->getColor(); |
| 455 a1 = SkColorGetA(color); | 461 a1 = SkColorGetA(color); |
| 456 } else { | 462 } else { |
| 457 a1 = 0xFF; | 463 a1 = 0xFF; |
| 458 } | 464 } |
| 459 | 465 |
| 460 int newA = (a0 * a1) / 255; | 466 int newA = SkMulDiv255Round(a0, a1); |
| 461 SkASSERT(newA <= 0xFF); | 467 SkASSERT(newA <= 0xFF); |
| 462 | 468 |
| 463 SkPaint* dbmrPaint = dbmr->paint(); | 469 SkPaint* dbmrPaint = dbmr->paint(); |
| 464 | 470 |
| 465 if (NULL != dbmrPaint) { | 471 if (NULL != dbmrPaint) { |
| 466 SkColor newColor = SkColorSetA(dbmrPaint->getColor(), newA); | 472 SkColor newColor = SkColorSetA(dbmrPaint->getColor(), newA); |
| 467 dbmrPaint->setColor(newColor); | 473 dbmrPaint->setColor(newColor); |
| 468 } else { | 474 } else { |
| 469 SkColor newColor = SkColorSetA(color, newA); | 475 SkColor newColor = SkColorSetA(color, newA); |
| 470 | 476 |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 789 | 795 |
| 790 SkGraphics::Term(); | 796 SkGraphics::Term(); |
| 791 return 0; | 797 return 0; |
| 792 } | 798 } |
| 793 | 799 |
| 794 #if !defined SK_BUILD_FOR_IOS | 800 #if !defined SK_BUILD_FOR_IOS |
| 795 int main(int argc, char * const argv[]) { | 801 int main(int argc, char * const argv[]) { |
| 796 return tool_main(argc, (char**) argv); | 802 return tool_main(argc, (char**) argv); |
| 797 } | 803 } |
| 798 #endif | 804 #endif |
| OLD | NEW |