| 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 14 matching lines...) Expand all Loading... |
| 25 SkDebugf(" [-h|--help]\n\n"); | 25 SkDebugf(" [-h|--help]\n\n"); |
| 26 SkDebugf(" -i inFile : file to filter.\n"); | 26 SkDebugf(" -i inFile : file to filter.\n"); |
| 27 SkDebugf(" -o outFile : result of filtering.\n"); | 27 SkDebugf(" -o outFile : result of filtering.\n"); |
| 28 SkDebugf(" --input-dir : process all files in dir with .skp extension.\n"
); | 28 SkDebugf(" --input-dir : process all files in dir with .skp extension.\n"
); |
| 29 SkDebugf(" --output-dir : results of filtering the input dir.\n"); | 29 SkDebugf(" --output-dir : results of filtering the input dir.\n"); |
| 30 SkDebugf(" -h|--help : Show this help message.\n"); | 30 SkDebugf(" -h|--help : Show this help message.\n"); |
| 31 } | 31 } |
| 32 | 32 |
| 33 // Is the supplied paint simply a color? | 33 // Is the supplied paint simply a color? |
| 34 static bool is_simple(const SkPaint& p) { | 34 static bool is_simple(const SkPaint& p) { |
| 35 return NULL == p.getPathEffect() && | 35 return nullptr == p.getPathEffect() && |
| 36 NULL == p.getShader() && | 36 nullptr == p.getShader() && |
| 37 NULL == p.getXfermode() && | 37 nullptr == p.getXfermode() && |
| 38 NULL == p.getMaskFilter() && | 38 nullptr == p.getMaskFilter() && |
| 39 NULL == p.getColorFilter() && | 39 nullptr == p.getColorFilter() && |
| 40 NULL == p.getRasterizer() && | 40 nullptr == p.getRasterizer() && |
| 41 NULL == p.getLooper() && | 41 nullptr == p.getLooper() && |
| 42 NULL == p.getImageFilter(); | 42 nullptr == p.getImageFilter(); |
| 43 } | 43 } |
| 44 | 44 |
| 45 | 45 |
| 46 // Check for: | 46 // Check for: |
| 47 // SAVE_LAYER | 47 // SAVE_LAYER |
| 48 // DRAW_BITMAP_RECT_TO_RECT | 48 // DRAW_BITMAP_RECT_TO_RECT |
| 49 // RESTORE | 49 // RESTORE |
| 50 // where the saveLayer's color can be moved into the drawBitmapRect | 50 // where the saveLayer's color can be moved into the drawBitmapRect |
| 51 static bool check_0(SkDebugCanvas* canvas, int curCommand) { | 51 static bool check_0(SkDebugCanvas* canvas, int curCommand) { |
| 52 if (SkDrawCommand::kSaveLayer_OpType != canvas->getDrawCommandAt(curCommand)
->getType() || | 52 if (SkDrawCommand::kSaveLayer_OpType != canvas->getDrawCommandAt(curCommand)
->getType() || |
| (...skipping 11 matching lines...) Expand all Loading... |
| 64 const SkPaint* saveLayerPaint = saveLayer->paint(); | 64 const SkPaint* saveLayerPaint = saveLayer->paint(); |
| 65 SkPaint* dbmrPaint = dbmr->paint(); | 65 SkPaint* dbmrPaint = dbmr->paint(); |
| 66 | 66 |
| 67 // For this optimization we only fold the saveLayer and drawBitmapRect | 67 // For this optimization we only fold the saveLayer and drawBitmapRect |
| 68 // together if the saveLayer's draw is simple (i.e., no fancy effects) | 68 // together if the saveLayer's draw is simple (i.e., no fancy effects) |
| 69 // and the only difference in the colors is their alpha value | 69 // and the only difference in the colors is their alpha value |
| 70 SkColor layerColor = saveLayerPaint->getColor() | 0xFF000000; // force opaqu
e | 70 SkColor layerColor = saveLayerPaint->getColor() | 0xFF000000; // force opaqu
e |
| 71 SkColor dbmrColor = dbmrPaint->getColor() | 0xFF000000; // force opaqu
e | 71 SkColor dbmrColor = dbmrPaint->getColor() | 0xFF000000; // force opaqu
e |
| 72 | 72 |
| 73 // If either operation lacks a paint then the collapse is trivial | 73 // If either operation lacks a paint then the collapse is trivial |
| 74 return NULL == saveLayerPaint || | 74 return nullptr == saveLayerPaint || |
| 75 NULL == dbmrPaint || | 75 nullptr == dbmrPaint || |
| 76 (is_simple(*saveLayerPaint) && dbmrColor == layerColor); | 76 (is_simple(*saveLayerPaint) && dbmrColor == layerColor); |
| 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 (nullptr == saveLayerPaint) the dbmr's paint doesn't need to be change
d |
| 87 if (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 (nullptr == 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 (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 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 // For this optimization we only fold the saveLayer and drawBitmapRect | 142 // For this optimization we only fold the saveLayer and drawBitmapRect |
| 143 // together if the saveLayer's draw is simple (i.e., no fancy effects) and | 143 // together if the saveLayer's draw is simple (i.e., no fancy effects) and |
| 144 // and the only difference in the colors is that the saveLayer's can have | 144 // and the only difference in the colors is that the saveLayer's can have |
| 145 // an alpha while the drawBitmapRect's is opaque. | 145 // an alpha while the drawBitmapRect's is opaque. |
| 146 // TODO: it should be possible to fold them together even if they both | 146 // TODO: it should be possible to fold them together even if they both |
| 147 // have different non-255 alphas but this is low priority since we have | 147 // have different non-255 alphas but this is low priority since we have |
| 148 // never seen that case | 148 // never seen that case |
| 149 // If either operation lacks a paint then the collapse is trivial | 149 // If either operation lacks a paint then the collapse is trivial |
| 150 SkColor layerColor = saveLayerPaint->getColor() | 0xFF000000; // force opaqu
e | 150 SkColor layerColor = saveLayerPaint->getColor() | 0xFF000000; // force opaqu
e |
| 151 | 151 |
| 152 return NULL == saveLayerPaint || | 152 return nullptr == saveLayerPaint || |
| 153 NULL == dbmrPaint || | 153 nullptr == dbmrPaint || |
| 154 (is_simple(*saveLayerPaint) && dbmrPaint->getColor() == layerColor); | 154 (is_simple(*saveLayerPaint) && dbmrPaint->getColor() == layerColor); |
| 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 (nullptr == saveLayerPaint) the dbmr's paint doesn't need to be change
d |
| 165 if (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 (nullptr == 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); |
| 176 } | 176 } |
| 177 } | 177 } |
| 178 | 178 |
| 179 canvas->deleteDrawCommandAt(curCommand+5); // restore | 179 canvas->deleteDrawCommandAt(curCommand+5); // restore |
| 180 canvas->deleteDrawCommandAt(curCommand); // saveLayer | 180 canvas->deleteDrawCommandAt(curCommand); // saveLayer |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 SkRegion::kIntersect_Op != clip2->op()) { | 360 SkRegion::kIntersect_Op != clip2->op()) { |
| 361 return false; | 361 return false; |
| 362 } | 362 } |
| 363 | 363 |
| 364 if (!clip0->rect().contains(clip1->rect()) || | 364 if (!clip0->rect().contains(clip1->rect()) || |
| 365 !clip1->rect().contains(clip2->rect())) { | 365 !clip1->rect().contains(clip2->rect())) { |
| 366 return false; | 366 return false; |
| 367 } | 367 } |
| 368 | 368 |
| 369 // The src->dest mapping needs to be 1-to-1 | 369 // The src->dest mapping needs to be 1-to-1 |
| 370 if (NULL == dbmr->srcRect()) { | 370 if (nullptr == dbmr->srcRect()) { |
| 371 if (dbmr->bitmap().width() != dbmr->dstRect().width() || | 371 if (dbmr->bitmap().width() != dbmr->dstRect().width() || |
| 372 dbmr->bitmap().height() != dbmr->dstRect().height()) { | 372 dbmr->bitmap().height() != dbmr->dstRect().height()) { |
| 373 return false; | 373 return false; |
| 374 } | 374 } |
| 375 } else { | 375 } else { |
| 376 if (dbmr->srcRect()->width() != dbmr->dstRect().width() || | 376 if (dbmr->srcRect()->width() != dbmr->dstRect().width() || |
| 377 dbmr->srcRect()->height() != dbmr->dstRect().height()) { | 377 dbmr->srcRect()->height() != dbmr->dstRect().height()) { |
| 378 return false; | 378 return false; |
| 379 } | 379 } |
| 380 } | 380 } |
| 381 | 381 |
| 382 if (!dbmr->dstRect().contains(clip2->rect())) { | 382 if (!dbmr->dstRect().contains(clip2->rect())) { |
| 383 return false; | 383 return false; |
| 384 } | 384 } |
| 385 | 385 |
| 386 const SkPaint* saveLayerPaint0 = saveLayer0->paint(); | 386 const SkPaint* saveLayerPaint0 = saveLayer0->paint(); |
| 387 const SkPaint* saveLayerPaint1 = saveLayer1->paint(); | 387 const SkPaint* saveLayerPaint1 = saveLayer1->paint(); |
| 388 | 388 |
| 389 if ((saveLayerPaint0 && !is_simple(*saveLayerPaint0)) || | 389 if ((saveLayerPaint0 && !is_simple(*saveLayerPaint0)) || |
| 390 (saveLayerPaint1 && !is_simple(*saveLayerPaint1))) { | 390 (saveLayerPaint1 && !is_simple(*saveLayerPaint1))) { |
| 391 return false; | 391 return false; |
| 392 } | 392 } |
| 393 | 393 |
| 394 SkPaint* dbmrPaint = dbmr->paint(); | 394 SkPaint* dbmrPaint = dbmr->paint(); |
| 395 | 395 |
| 396 if (NULL == dbmrPaint) { | 396 if (nullptr == dbmrPaint) { |
| 397 return true; | 397 return true; |
| 398 } | 398 } |
| 399 | 399 |
| 400 if (saveLayerPaint0) { | 400 if (saveLayerPaint0) { |
| 401 SkColor layerColor0 = saveLayerPaint0->getColor() | 0xFF000000; // force
opaque | 401 SkColor layerColor0 = saveLayerPaint0->getColor() | 0xFF000000; // force
opaque |
| 402 if (dbmrPaint->getColor() != layerColor0) { | 402 if (dbmrPaint->getColor() != layerColor0) { |
| 403 return false; | 403 return false; |
| 404 } | 404 } |
| 405 } | 405 } |
| 406 | 406 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 SkClipRectCommand* clip = | 507 SkClipRectCommand* clip = |
| 508 (SkClipRectCommand*) canvas->getDrawCommandAt(curCommand+1); | 508 (SkClipRectCommand*) canvas->getDrawCommandAt(curCommand+1); |
| 509 SkDrawBitmapRectCommand* dbmr = | 509 SkDrawBitmapRectCommand* dbmr = |
| 510 (SkDrawBitmapRectCommand*) canvas->getDrawCommandAt(curCommand+2); | 510 (SkDrawBitmapRectCommand*) canvas->getDrawCommandAt(curCommand+2); |
| 511 | 511 |
| 512 if (clip->doAA() || SkRegion::kIntersect_Op != clip->op()) { | 512 if (clip->doAA() || SkRegion::kIntersect_Op != clip->op()) { |
| 513 return false; | 513 return false; |
| 514 } | 514 } |
| 515 | 515 |
| 516 // The src->dest mapping needs to be 1-to-1 | 516 // The src->dest mapping needs to be 1-to-1 |
| 517 if (NULL == dbmr->srcRect()) { | 517 if (nullptr == dbmr->srcRect()) { |
| 518 if (dbmr->bitmap().width() != dbmr->dstRect().width() || | 518 if (dbmr->bitmap().width() != dbmr->dstRect().width() || |
| 519 dbmr->bitmap().height() != dbmr->dstRect().height()) { | 519 dbmr->bitmap().height() != dbmr->dstRect().height()) { |
| 520 return false; | 520 return false; |
| 521 } | 521 } |
| 522 } else { | 522 } else { |
| 523 if (dbmr->srcRect()->width() != dbmr->dstRect().width() || | 523 if (dbmr->srcRect()->width() != dbmr->dstRect().width() || |
| 524 dbmr->srcRect()->height() != dbmr->dstRect().height()) { | 524 dbmr->srcRect()->height() != dbmr->dstRect().height()) { |
| 525 return false; | 525 return false; |
| 526 } | 526 } |
| 527 } | 527 } |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 | 622 |
| 623 | 623 |
| 624 static int filter_picture(const SkString& inFile, const SkString& outFile) { | 624 static int filter_picture(const SkString& inFile, const SkString& outFile) { |
| 625 SkAutoTUnref<SkPicture> inPicture; | 625 SkAutoTUnref<SkPicture> inPicture; |
| 626 | 626 |
| 627 SkFILEStream inStream(inFile.c_str()); | 627 SkFILEStream inStream(inFile.c_str()); |
| 628 if (inStream.isValid()) { | 628 if (inStream.isValid()) { |
| 629 inPicture.reset(SkPicture::CreateFromStream(&inStream)); | 629 inPicture.reset(SkPicture::CreateFromStream(&inStream)); |
| 630 } | 630 } |
| 631 | 631 |
| 632 if (NULL == inPicture.get()) { | 632 if (nullptr == inPicture.get()) { |
| 633 SkDebugf("Could not read file %s\n", inFile.c_str()); | 633 SkDebugf("Could not read file %s\n", inFile.c_str()); |
| 634 return -1; | 634 return -1; |
| 635 } | 635 } |
| 636 | 636 |
| 637 int localCount[SK_ARRAY_COUNT(gOptTable)]; | 637 int localCount[SK_ARRAY_COUNT(gOptTable)]; |
| 638 | 638 |
| 639 memset(localCount, 0, sizeof(localCount)); | 639 memset(localCount, 0, sizeof(localCount)); |
| 640 | 640 |
| 641 SkDebugCanvas debugCanvas(SkScalarCeilToInt(inPicture->cullRect().width()), | 641 SkDebugCanvas debugCanvas(SkScalarCeilToInt(inPicture->cullRect().width()), |
| 642 SkScalarCeilToInt(inPicture->cullRect().height()))
; | 642 SkScalarCeilToInt(inPicture->cullRect().height()))
; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 673 } | 673 } |
| 674 } | 674 } |
| 675 } | 675 } |
| 676 | 676 |
| 677 int numAfter = debugCanvas.getSize(); | 677 int numAfter = debugCanvas.getSize(); |
| 678 | 678 |
| 679 if (!outFile.isEmpty()) { | 679 if (!outFile.isEmpty()) { |
| 680 SkPictureRecorder recorder; | 680 SkPictureRecorder recorder; |
| 681 SkCanvas* canvas = recorder.beginRecording(inPicture->cullRect().width()
, | 681 SkCanvas* canvas = recorder.beginRecording(inPicture->cullRect().width()
, |
| 682 inPicture->cullRect().height(
), | 682 inPicture->cullRect().height(
), |
| 683 NULL, 0); | 683 nullptr, 0); |
| 684 debugCanvas.draw(canvas); | 684 debugCanvas.draw(canvas); |
| 685 SkAutoTUnref<SkPicture> outPicture(recorder.endRecording()); | 685 SkAutoTUnref<SkPicture> outPicture(recorder.endRecording()); |
| 686 | 686 |
| 687 SkFILEWStream outStream(outFile.c_str()); | 687 SkFILEWStream outStream(outFile.c_str()); |
| 688 | 688 |
| 689 outPicture->serialize(&outStream); | 689 outPicture->serialize(&outStream); |
| 690 } | 690 } |
| 691 | 691 |
| 692 bool someOptFired = false; | 692 bool someOptFired = false; |
| 693 for (size_t opt = 0; opt < SK_ARRAY_COUNT(gOptTable); ++opt) { | 693 for (size_t opt = 0; opt < SK_ARRAY_COUNT(gOptTable); ++opt) { |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 796 | 796 |
| 797 SkGraphics::Term(); | 797 SkGraphics::Term(); |
| 798 return 0; | 798 return 0; |
| 799 } | 799 } |
| 800 | 800 |
| 801 #if !defined SK_BUILD_FOR_IOS | 801 #if !defined SK_BUILD_FOR_IOS |
| 802 int main(int argc, char * const argv[]) { | 802 int main(int argc, char * const argv[]) { |
| 803 return tool_main(argc, (char**) argv); | 803 return tool_main(argc, (char**) argv); |
| 804 } | 804 } |
| 805 #endif | 805 #endif |
| OLD | NEW |