| 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 471 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 482     canvas->deleteDrawCommandAt(curCommand+7);    // clipRect | 482     canvas->deleteDrawCommandAt(curCommand+7);    // clipRect | 
| 483     canvas->deleteDrawCommandAt(curCommand+6);    // save | 483     canvas->deleteDrawCommandAt(curCommand+6);    // save | 
| 484     canvas->deleteDrawCommandAt(curCommand+5);    // saveLayer | 484     canvas->deleteDrawCommandAt(curCommand+5);    // saveLayer | 
| 485     canvas->deleteDrawCommandAt(curCommand+4);    // clipRect | 485     canvas->deleteDrawCommandAt(curCommand+4);    // clipRect | 
| 486     canvas->deleteDrawCommandAt(curCommand+3);    // save | 486     canvas->deleteDrawCommandAt(curCommand+3);    // save | 
| 487     canvas->deleteDrawCommandAt(curCommand+2);    // saveLayer | 487     canvas->deleteDrawCommandAt(curCommand+2);    // saveLayer | 
| 488     canvas->deleteDrawCommandAt(curCommand+1);    // clipRect | 488     canvas->deleteDrawCommandAt(curCommand+1);    // clipRect | 
| 489     canvas->deleteDrawCommandAt(curCommand);      // save | 489     canvas->deleteDrawCommandAt(curCommand);      // save | 
| 490 } | 490 } | 
| 491 | 491 | 
|  | 492 // Check for: | 
|  | 493 //    SAVE | 
|  | 494 //       CLIP_RECT | 
|  | 495 //       DRAWBITMAPRECTTORECT | 
|  | 496 //    RESTORE | 
|  | 497 // where: | 
|  | 498 //      the drawBitmapRectToRect is a 1-1 copy from src to dest | 
|  | 499 //      the clip rect is BW and a subset of the drawBitmapRectToRect's dest rect | 
|  | 500 static bool check_8(SkDebugCanvas* canvas, int curCommand) { | 
|  | 501     if (SAVE != canvas->getDrawCommandAt(curCommand)->getType() || | 
|  | 502         canvas->getSize() <= curCommand+4 || | 
|  | 503         CLIP_RECT != canvas->getDrawCommandAt(curCommand+1)->getType() || | 
|  | 504         DRAW_BITMAP_RECT_TO_RECT != canvas->getDrawCommandAt(curCommand+2)->getT
     ype() || | 
|  | 505         RESTORE != canvas->getDrawCommandAt(curCommand+3)->getType()) { | 
|  | 506         return false; | 
|  | 507     } | 
|  | 508 | 
|  | 509     ClipRect* clip = (ClipRect*) canvas->getDrawCommandAt(curCommand+1); | 
|  | 510     DrawBitmapRect* dbmr = (DrawBitmapRect*) canvas->getDrawCommandAt(curCommand
     +2); | 
|  | 511 | 
|  | 512     if (clip->doAA() || SkRegion::kIntersect_Op != clip->op()) { | 
|  | 513         return false; | 
|  | 514     } | 
|  | 515 | 
|  | 516     // The src->dest mapping needs to be 1-to-1 | 
|  | 517     if (NULL == dbmr->srcRect()) { | 
|  | 518         if (dbmr->bitmap().width() != dbmr->dstRect().width() || | 
|  | 519             dbmr->bitmap().height() != dbmr->dstRect().height()) { | 
|  | 520             return false; | 
|  | 521         } | 
|  | 522     } else { | 
|  | 523         if (dbmr->srcRect()->width() != dbmr->dstRect().width() || | 
|  | 524             dbmr->srcRect()->height() != dbmr->dstRect().height()) { | 
|  | 525             return false; | 
|  | 526         } | 
|  | 527     } | 
|  | 528 | 
|  | 529     if (!dbmr->dstRect().contains(clip->rect())) { | 
|  | 530         return false; | 
|  | 531     } | 
|  | 532 | 
|  | 533     return true; | 
|  | 534 } | 
|  | 535 | 
|  | 536 // Fold the clipRect into the drawBitmapRectToRect's src and dest rects | 
|  | 537 static void apply_8(SkDebugCanvas* canvas, int curCommand) { | 
|  | 538     ClipRect* clip = (ClipRect*) canvas->getDrawCommandAt(curCommand+1); | 
|  | 539     DrawBitmapRect* dbmr = (DrawBitmapRect*) canvas->getDrawCommandAt(curCommand
     +2); | 
|  | 540 | 
|  | 541     SkScalar newSrcLeft, newSrcTop; | 
|  | 542 | 
|  | 543     if (NULL != dbmr->srcRect()) { | 
|  | 544         newSrcLeft = dbmr->srcRect()->fLeft + clip->rect().fLeft - dbmr->dstRect
     ().fLeft; | 
|  | 545         newSrcTop  = dbmr->srcRect()->fTop + clip->rect().fTop - dbmr->dstRect()
     .fTop; | 
|  | 546     } else { | 
|  | 547         newSrcLeft = clip->rect().fLeft - dbmr->dstRect().fLeft; | 
|  | 548         newSrcTop  = clip->rect().fTop - dbmr->dstRect().fTop; | 
|  | 549     } | 
|  | 550 | 
|  | 551     SkRect newSrc = SkRect::MakeXYWH(newSrcLeft, newSrcTop, | 
|  | 552                                      clip->rect().width(), clip->rect().height()
     ); | 
|  | 553 | 
|  | 554     dbmr->setSrcRect(newSrc); | 
|  | 555     dbmr->setDstRect(clip->rect()); | 
|  | 556 | 
|  | 557     // remove everything except the drawbitmaprect | 
|  | 558     canvas->deleteDrawCommandAt(curCommand+3); | 
|  | 559     canvas->deleteDrawCommandAt(curCommand+1); | 
|  | 560     canvas->deleteDrawCommandAt(curCommand); | 
|  | 561 } | 
|  | 562 | 
|  | 563 // Check for: | 
|  | 564 //  SAVE | 
|  | 565 //    CLIP_RECT | 
|  | 566 //    DRAWBITMAPRECTTORECT | 
|  | 567 //  RESTORE | 
|  | 568 // where: | 
|  | 569 //      clipRect is BW and encloses the DBMR2R's dest rect | 
|  | 570 static bool check_9(SkDebugCanvas* canvas, int curCommand) { | 
|  | 571     if (SAVE != canvas->getDrawCommandAt(curCommand)->getType() || | 
|  | 572         canvas->getSize() <= curCommand+4 || | 
|  | 573         CLIP_RECT != canvas->getDrawCommandAt(curCommand+1)->getType() || | 
|  | 574         DRAW_BITMAP_RECT_TO_RECT != canvas->getDrawCommandAt(curCommand+2)->getT
     ype() || | 
|  | 575         RESTORE != canvas->getDrawCommandAt(curCommand+3)->getType()) { | 
|  | 576         return false; | 
|  | 577     } | 
|  | 578 | 
|  | 579     ClipRect* clip = (ClipRect*) canvas->getDrawCommandAt(curCommand+1); | 
|  | 580     DrawBitmapRect* dbmr = (DrawBitmapRect*) canvas->getDrawCommandAt(curCommand
     +2); | 
|  | 581 | 
|  | 582     if (clip->doAA() || SkRegion::kIntersect_Op != clip->op()) { | 
|  | 583         return false; | 
|  | 584     } | 
|  | 585 | 
|  | 586     if (!clip->rect().contains(dbmr->dstRect())) { | 
|  | 587         return false; | 
|  | 588     } | 
|  | 589 | 
|  | 590     return true; | 
|  | 591 } | 
|  | 592 | 
|  | 593 // remove everything except the drawbitmaprect | 
|  | 594 static void apply_9(SkDebugCanvas* canvas, int curCommand) { | 
|  | 595     canvas->deleteDrawCommandAt(curCommand+3);   // restore | 
|  | 596     // drawBitmapRectToRect | 
|  | 597     canvas->deleteDrawCommandAt(curCommand+1);   // clipRect | 
|  | 598     canvas->deleteDrawCommandAt(curCommand);     // save | 
|  | 599 } | 
|  | 600 | 
| 492 typedef bool (*PFCheck)(SkDebugCanvas* canvas, int curCommand); | 601 typedef bool (*PFCheck)(SkDebugCanvas* canvas, int curCommand); | 
| 493 typedef void (*PFApply)(SkDebugCanvas* canvas, int curCommand); | 602 typedef void (*PFApply)(SkDebugCanvas* canvas, int curCommand); | 
| 494 | 603 | 
| 495 struct OptTableEntry { | 604 struct OptTableEntry { | 
| 496     PFCheck fCheck; | 605     PFCheck fCheck; | 
| 497     PFApply fApply; | 606     PFApply fApply; | 
| 498     int fNumTimesApplied; | 607     int fNumTimesApplied; | 
| 499 } gOptTable[] = { | 608 } gOptTable[] = { | 
| 500     { check_0, apply_0, 0 }, | 609     { check_0, apply_0, 0 }, | 
| 501     { check_1, apply_1, 0 }, | 610     { check_1, apply_1, 0 }, | 
| 502     { check_2, apply_2, 0 }, | 611     { check_2, apply_2, 0 }, | 
| 503     { check_3, apply_3, 0 }, | 612     { check_3, apply_3, 0 }, | 
| 504     { check_4, apply_4, 0 }, | 613     { check_4, apply_4, 0 }, | 
| 505     { check_5, apply_5, 0 }, | 614     { check_5, apply_5, 0 }, | 
| 506     { check_6, apply_6, 0 }, | 615     { check_6, apply_6, 0 }, | 
| 507     { check_7, apply_7, 0 }, | 616     { check_7, apply_7, 0 }, | 
|  | 617     { check_8, apply_8, 0 }, | 
|  | 618     { check_9, apply_9, 0 }, | 
| 508 }; | 619 }; | 
| 509 | 620 | 
| 510 | 621 | 
| 511 static int filter_picture(const SkString& inFile, const SkString& outFile) { | 622 static int filter_picture(const SkString& inFile, const SkString& outFile) { | 
| 512     SkPicture* inPicture = NULL; | 623     SkPicture* inPicture = NULL; | 
| 513 | 624 | 
| 514     SkFILEStream inStream(inFile.c_str()); | 625     SkFILEStream inStream(inFile.c_str()); | 
| 515     if (inStream.isValid()) { | 626     if (inStream.isValid()) { | 
| 516         inPicture = SkNEW_ARGS(SkPicture, (&inStream, NULL, &SkImageDecoder::Dec
     odeMemory)); | 627         inPicture = SkNEW_ARGS(SkPicture, (&inStream, NULL, &SkImageDecoder::Dec
     odeMemory)); | 
| 517     } | 628     } | 
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 678 | 789 | 
| 679     SkGraphics::Term(); | 790     SkGraphics::Term(); | 
| 680     return 0; | 791     return 0; | 
| 681 } | 792 } | 
| 682 | 793 | 
| 683 #if !defined SK_BUILD_FOR_IOS | 794 #if !defined SK_BUILD_FOR_IOS | 
| 684 int main(int argc, char * const argv[]) { | 795 int main(int argc, char * const argv[]) { | 
| 685     return tool_main(argc, (char**) argv); | 796     return tool_main(argc, (char**) argv); | 
| 686 } | 797 } | 
| 687 #endif | 798 #endif | 
| OLD | NEW | 
|---|