| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 #include "Test.h" | 8 #include "Test.h" |
| 9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
| 10 #include "SkBitmapProcShader.h" | 10 #include "SkBitmapProcShader.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 bm->setConfig(config, gWidth, gHeight); | 27 bm->setConfig(config, gWidth, gHeight); |
| 28 bm->allocPixels(); | 28 bm->allocPixels(); |
| 29 bm->eraseColor(color); | 29 bm->eraseColor(color); |
| 30 } | 30 } |
| 31 | 31 |
| 32 static void TestDeferredCanvasBitmapAccess(skiatest::Reporter* reporter) { | 32 static void TestDeferredCanvasBitmapAccess(skiatest::Reporter* reporter) { |
| 33 SkBitmap store; | 33 SkBitmap store; |
| 34 | 34 |
| 35 create(&store, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF); | 35 create(&store, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF); |
| 36 SkDevice device(store); | 36 SkDevice device(store); |
| 37 SkAutoTUnref<SkDeferredCanvas> canvas( | 37 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(&device)); |
| 38 #if SK_DEFERRED_CANVAS_USES_FACTORIES | |
| 39 SkDeferredCanvas::Create(&device)); | |
| 40 #else | |
| 41 SkNEW_ARGS(SkDeferredCanvas, (&device))); | |
| 42 #endif | |
| 43 | 38 |
| 44 canvas->clear(0x00000000); | 39 canvas->clear(0x00000000); |
| 45 | 40 |
| 46 SkAutoLockPixels alp(store); | 41 SkAutoLockPixels alp(store); |
| 47 REPORTER_ASSERT(reporter, store.getColor(0,0) == 0xFFFFFFFF); //verify that
clear was deferred | 42 REPORTER_ASSERT(reporter, store.getColor(0,0) == 0xFFFFFFFF); //verify that
clear was deferred |
| 48 SkBitmap accessed = canvas->getDevice()->accessBitmap(false); | 43 SkBitmap accessed = canvas->getDevice()->accessBitmap(false); |
| 49 REPORTER_ASSERT(reporter, store.getColor(0,0) == 0x00000000); //verify that
clear was executed | 44 REPORTER_ASSERT(reporter, store.getColor(0,0) == 0x00000000); //verify that
clear was executed |
| 50 REPORTER_ASSERT(reporter, accessed.pixelRef() == store.pixelRef()); | 45 REPORTER_ASSERT(reporter, accessed.pixelRef() == store.pixelRef()); |
| 51 } | 46 } |
| 52 | 47 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 82 fDiscardCount = 0; | 77 fDiscardCount = 0; |
| 83 fRetainCount = 0; | 78 fRetainCount = 0; |
| 84 } | 79 } |
| 85 | 80 |
| 86 int fDiscardCount, fRetainCount; | 81 int fDiscardCount, fRetainCount; |
| 87 SkBitmap fBitmap; | 82 SkBitmap fBitmap; |
| 88 }; | 83 }; |
| 89 | 84 |
| 90 static void TestDeferredCanvasWritePixelsToSurface(skiatest::Reporter* reporter)
{ | 85 static void TestDeferredCanvasWritePixelsToSurface(skiatest::Reporter* reporter)
{ |
| 91 SkAutoTUnref<MockSurface> surface(SkNEW_ARGS(MockSurface, (10, 10))); | 86 SkAutoTUnref<MockSurface> surface(SkNEW_ARGS(MockSurface, (10, 10))); |
| 92 SkAutoTUnref<SkDeferredCanvas> canvas( | 87 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get()
)); |
| 93 #if SK_DEFERRED_CANVAS_USES_FACTORIES | |
| 94 SkDeferredCanvas::Create(surface.get())); | |
| 95 #else | |
| 96 SkNEW_ARGS(SkDeferredCanvas, (surface.get()))); | |
| 97 #endif | |
| 98 | 88 |
| 99 SkBitmap srcBitmap; | 89 SkBitmap srcBitmap; |
| 100 srcBitmap.setConfig(SkBitmap::kARGB_8888_Config, 10, 10); | 90 srcBitmap.setConfig(SkBitmap::kARGB_8888_Config, 10, 10); |
| 101 srcBitmap.allocPixels(); | 91 srcBitmap.allocPixels(); |
| 102 srcBitmap.eraseColor(SK_ColorGREEN); | 92 srcBitmap.eraseColor(SK_ColorGREEN); |
| 103 // Tests below depend on this bitmap being recognized as opaque | 93 // Tests below depend on this bitmap being recognized as opaque |
| 104 | 94 |
| 105 // Preliminary sanity check: no copy on write if no active snapshot | 95 // Preliminary sanity check: no copy on write if no active snapshot |
| 106 surface->clearCounts(); | 96 surface->clearCounts(); |
| 107 canvas->clear(SK_ColorWHITE); | 97 canvas->clear(SK_ColorWHITE); |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 canvas->flush(); | 253 canvas->flush(); |
| 264 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); | 254 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); |
| 265 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount); | 255 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount); |
| 266 } | 256 } |
| 267 | 257 |
| 268 static void TestDeferredCanvasFlush(skiatest::Reporter* reporter) { | 258 static void TestDeferredCanvasFlush(skiatest::Reporter* reporter) { |
| 269 SkBitmap store; | 259 SkBitmap store; |
| 270 | 260 |
| 271 create(&store, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF); | 261 create(&store, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF); |
| 272 SkDevice device(store); | 262 SkDevice device(store); |
| 273 SkAutoTUnref<SkDeferredCanvas> canvas( | 263 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(&device)); |
| 274 #if SK_DEFERRED_CANVAS_USES_FACTORIES | |
| 275 SkDeferredCanvas::Create(&device)); | |
| 276 #else | |
| 277 SkNEW_ARGS(SkDeferredCanvas, (&device))); | |
| 278 #endif | |
| 279 | 264 |
| 280 canvas->clear(0x00000000); | 265 canvas->clear(0x00000000); |
| 281 | 266 |
| 282 SkAutoLockPixels alp(store); | 267 SkAutoLockPixels alp(store); |
| 283 REPORTER_ASSERT(reporter, store.getColor(0,0) == 0xFFFFFFFF); //verify that
clear was deferred | 268 REPORTER_ASSERT(reporter, store.getColor(0,0) == 0xFFFFFFFF); //verify that
clear was deferred |
| 284 canvas->flush(); | 269 canvas->flush(); |
| 285 REPORTER_ASSERT(reporter, store.getColor(0,0) == 0x00000000); //verify that
clear was executed | 270 REPORTER_ASSERT(reporter, store.getColor(0,0) == 0x00000000); //verify that
clear was executed |
| 286 } | 271 } |
| 287 | 272 |
| 288 static void TestDeferredCanvasFreshFrame(skiatest::Reporter* reporter) { | 273 static void TestDeferredCanvasFreshFrame(skiatest::Reporter* reporter) { |
| 289 SkBitmap store; | 274 SkBitmap store; |
| 290 SkRect fullRect; | 275 SkRect fullRect; |
| 291 fullRect.setXYWH(SkIntToScalar(0), SkIntToScalar(0), SkIntToScalar(gWidth), | 276 fullRect.setXYWH(SkIntToScalar(0), SkIntToScalar(0), SkIntToScalar(gWidth), |
| 292 SkIntToScalar(gHeight)); | 277 SkIntToScalar(gHeight)); |
| 293 SkRect partialRect; | 278 SkRect partialRect; |
| 294 partialRect.setXYWH(SkIntToScalar(0), SkIntToScalar(0), | 279 partialRect.setXYWH(SkIntToScalar(0), SkIntToScalar(0), |
| 295 SkIntToScalar(1), SkIntToScalar(1)); | 280 SkIntToScalar(1), SkIntToScalar(1)); |
| 296 create(&store, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF); | 281 create(&store, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF); |
| 297 SkDevice device(store); | 282 SkDevice device(store); |
| 298 SkAutoTUnref<SkDeferredCanvas> canvas( | 283 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(&device)); |
| 299 #if SK_DEFERRED_CANVAS_USES_FACTORIES | |
| 300 SkDeferredCanvas::Create(&device)); | |
| 301 #else | |
| 302 SkNEW_ARGS(SkDeferredCanvas, (&device))); | |
| 303 #endif | |
| 304 | 284 |
| 305 // verify that frame is intially fresh | 285 // verify that frame is intially fresh |
| 306 REPORTER_ASSERT(reporter, canvas->isFreshFrame()); | 286 REPORTER_ASSERT(reporter, canvas->isFreshFrame()); |
| 307 // no clearing op since last call to isFreshFrame -> not fresh | 287 // no clearing op since last call to isFreshFrame -> not fresh |
| 308 REPORTER_ASSERT(reporter, !canvas->isFreshFrame()); | 288 REPORTER_ASSERT(reporter, !canvas->isFreshFrame()); |
| 309 | 289 |
| 310 // Verify that clear triggers a fresh frame | 290 // Verify that clear triggers a fresh frame |
| 311 canvas->clear(0x00000000); | 291 canvas->clear(0x00000000); |
| 312 REPORTER_ASSERT(reporter, canvas->isFreshFrame()); | 292 REPORTER_ASSERT(reporter, canvas->isFreshFrame()); |
| 313 | 293 |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 int fDrawBitmapCallCount; | 446 int fDrawBitmapCallCount; |
| 467 }; | 447 }; |
| 468 | 448 |
| 469 // Verifies that the deferred canvas triggers a flush when its memory | 449 // Verifies that the deferred canvas triggers a flush when its memory |
| 470 // limit is exceeded | 450 // limit is exceeded |
| 471 static void TestDeferredCanvasMemoryLimit(skiatest::Reporter* reporter) { | 451 static void TestDeferredCanvasMemoryLimit(skiatest::Reporter* reporter) { |
| 472 SkBitmap store; | 452 SkBitmap store; |
| 473 store.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); | 453 store.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); |
| 474 store.allocPixels(); | 454 store.allocPixels(); |
| 475 MockDevice mockDevice(store); | 455 MockDevice mockDevice(store); |
| 476 SkAutoTUnref<SkDeferredCanvas> canvas( | 456 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(&mockDevice))
; |
| 477 #if SK_DEFERRED_CANVAS_USES_FACTORIES | |
| 478 SkDeferredCanvas::Create(&mockDevice)); | |
| 479 #else | |
| 480 SkNEW_ARGS(SkDeferredCanvas, (&mockDevice))); | |
| 481 #endif | |
| 482 canvas->setMaxRecordingStorage(160000); | 457 canvas->setMaxRecordingStorage(160000); |
| 483 | 458 |
| 484 SkBitmap sourceImage; | 459 SkBitmap sourceImage; |
| 485 // 100 by 100 image, takes 40,000 bytes in memory | 460 // 100 by 100 image, takes 40,000 bytes in memory |
| 486 sourceImage.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); | 461 sourceImage.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); |
| 487 sourceImage.allocPixels(); | 462 sourceImage.allocPixels(); |
| 488 | 463 |
| 489 for (int i = 0; i < 5; i++) { | 464 for (int i = 0; i < 5; i++) { |
| 490 sourceImage.notifyPixelsChanged(); // to force re-serialization | 465 sourceImage.notifyPixelsChanged(); // to force re-serialization |
| 491 canvas->drawBitmap(sourceImage, 0, 0, NULL); | 466 canvas->drawBitmap(sourceImage, 0, 0, NULL); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 522 private: | 497 private: |
| 523 typedef SkDeferredCanvas::NotificationClient INHERITED; | 498 typedef SkDeferredCanvas::NotificationClient INHERITED; |
| 524 }; | 499 }; |
| 525 | 500 |
| 526 static void TestDeferredCanvasBitmapCaching(skiatest::Reporter* reporter) { | 501 static void TestDeferredCanvasBitmapCaching(skiatest::Reporter* reporter) { |
| 527 SkBitmap store; | 502 SkBitmap store; |
| 528 store.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); | 503 store.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); |
| 529 store.allocPixels(); | 504 store.allocPixels(); |
| 530 SkDevice device(store); | 505 SkDevice device(store); |
| 531 NotificationCounter notificationCounter; | 506 NotificationCounter notificationCounter; |
| 532 SkAutoTUnref<SkDeferredCanvas> canvas( | 507 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(&device)); |
| 533 #if SK_DEFERRED_CANVAS_USES_FACTORIES | |
| 534 SkDeferredCanvas::Create(&device)); | |
| 535 #else | |
| 536 SkNEW_ARGS(SkDeferredCanvas, (&device))); | |
| 537 #endif | |
| 538 canvas->setNotificationClient(¬ificationCounter); | 508 canvas->setNotificationClient(¬ificationCounter); |
| 539 | 509 |
| 540 const int imageCount = 2; | 510 const int imageCount = 2; |
| 541 SkBitmap sourceImages[imageCount]; | 511 SkBitmap sourceImages[imageCount]; |
| 542 for (int i = 0; i < imageCount; i++) | 512 for (int i = 0; i < imageCount; i++) |
| 543 { | 513 { |
| 544 sourceImages[i].setConfig(SkBitmap::kARGB_8888_Config, 100, 100); | 514 sourceImages[i].setConfig(SkBitmap::kARGB_8888_Config, 100, 100); |
| 545 sourceImages[i].allocPixels(); | 515 sourceImages[i].allocPixels(); |
| 546 } | 516 } |
| 547 | 517 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 // Verify that nothing in this test caused commands to be skipped | 580 // Verify that nothing in this test caused commands to be skipped |
| 611 REPORTER_ASSERT(reporter, 0 == notificationCounter.fSkippedPendingDrawComman
dsCount); | 581 REPORTER_ASSERT(reporter, 0 == notificationCounter.fSkippedPendingDrawComman
dsCount); |
| 612 } | 582 } |
| 613 | 583 |
| 614 static void TestDeferredCanvasSkip(skiatest::Reporter* reporter) { | 584 static void TestDeferredCanvasSkip(skiatest::Reporter* reporter) { |
| 615 SkBitmap store; | 585 SkBitmap store; |
| 616 store.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); | 586 store.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); |
| 617 store.allocPixels(); | 587 store.allocPixels(); |
| 618 SkDevice device(store); | 588 SkDevice device(store); |
| 619 NotificationCounter notificationCounter; | 589 NotificationCounter notificationCounter; |
| 620 SkAutoTUnref<SkDeferredCanvas> canvas( | 590 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(&device)); |
| 621 #if SK_DEFERRED_CANVAS_USES_FACTORIES | |
| 622 SkDeferredCanvas::Create(&device)); | |
| 623 #else | |
| 624 SkNEW_ARGS(SkDeferredCanvas, (&device))); | |
| 625 #endif | |
| 626 canvas->setNotificationClient(¬ificationCounter); | 591 canvas->setNotificationClient(¬ificationCounter); |
| 627 canvas->clear(0x0); | 592 canvas->clear(0x0); |
| 628 REPORTER_ASSERT(reporter, 1 == notificationCounter.fSkippedPendingDrawComman
dsCount); | 593 REPORTER_ASSERT(reporter, 1 == notificationCounter.fSkippedPendingDrawComman
dsCount); |
| 629 REPORTER_ASSERT(reporter, 0 == notificationCounter.fFlushedDrawCommandsCount
); | 594 REPORTER_ASSERT(reporter, 0 == notificationCounter.fFlushedDrawCommandsCount
); |
| 630 canvas->flush(); | 595 canvas->flush(); |
| 631 REPORTER_ASSERT(reporter, 1 == notificationCounter.fSkippedPendingDrawComman
dsCount); | 596 REPORTER_ASSERT(reporter, 1 == notificationCounter.fSkippedPendingDrawComman
dsCount); |
| 632 REPORTER_ASSERT(reporter, 1 == notificationCounter.fFlushedDrawCommandsCount
); | 597 REPORTER_ASSERT(reporter, 1 == notificationCounter.fFlushedDrawCommandsCount
); |
| 633 | 598 |
| 634 } | 599 } |
| 635 | 600 |
| 636 static void TestDeferredCanvasBitmapShaderNoLeak(skiatest::Reporter* reporter) { | 601 static void TestDeferredCanvasBitmapShaderNoLeak(skiatest::Reporter* reporter) { |
| 637 // This is a regression test for crbug.com/155875 | 602 // This is a regression test for crbug.com/155875 |
| 638 // This test covers a code path that inserts bitmaps into the bitmap heap th
rough the | 603 // This test covers a code path that inserts bitmaps into the bitmap heap th
rough the |
| 639 // flattening of SkBitmapProcShaders. The refcount in the bitmap heap is mai
ntained through | 604 // flattening of SkBitmapProcShaders. The refcount in the bitmap heap is mai
ntained through |
| 640 // the flattening and unflattening of the shader. | 605 // the flattening and unflattening of the shader. |
| 641 SkBitmap store; | 606 SkBitmap store; |
| 642 store.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); | 607 store.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); |
| 643 store.allocPixels(); | 608 store.allocPixels(); |
| 644 SkDevice device(store); | 609 SkDevice device(store); |
| 645 SkAutoTUnref<SkDeferredCanvas> canvas( | 610 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(&device)); |
| 646 #if SK_DEFERRED_CANVAS_USES_FACTORIES | |
| 647 SkDeferredCanvas::Create(&device)); | |
| 648 #else | |
| 649 SkNEW_ARGS(SkDeferredCanvas, (&device))); | |
| 650 #endif | |
| 651 // test will fail if nbIterations is not in sync with | 611 // test will fail if nbIterations is not in sync with |
| 652 // BITMAPS_TO_KEEP in SkGPipeWrite.cpp | 612 // BITMAPS_TO_KEEP in SkGPipeWrite.cpp |
| 653 const int nbIterations = 5; | 613 const int nbIterations = 5; |
| 654 size_t bytesAllocated = 0; | 614 size_t bytesAllocated = 0; |
| 655 for(int pass = 0; pass < 2; ++pass) { | 615 for(int pass = 0; pass < 2; ++pass) { |
| 656 for(int i = 0; i < nbIterations; ++i) { | 616 for(int i = 0; i < nbIterations; ++i) { |
| 657 SkPaint paint; | 617 SkPaint paint; |
| 658 SkBitmap paintPattern; | 618 SkBitmap paintPattern; |
| 659 paintPattern.setConfig(SkBitmap::kARGB_8888_Config, 10, 10); | 619 paintPattern.setConfig(SkBitmap::kARGB_8888_Config, 10, 10); |
| 660 paintPattern.allocPixels(); | 620 paintPattern.allocPixels(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 686 store.allocPixels(); | 646 store.allocPixels(); |
| 687 | 647 |
| 688 SkBitmap sourceImage; | 648 SkBitmap sourceImage; |
| 689 // 100 by 100 image, takes 40,000 bytes in memory | 649 // 100 by 100 image, takes 40,000 bytes in memory |
| 690 sourceImage.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); | 650 sourceImage.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); |
| 691 sourceImage.allocPixels(); | 651 sourceImage.allocPixels(); |
| 692 | 652 |
| 693 // 1 under : should not store the image | 653 // 1 under : should not store the image |
| 694 { | 654 { |
| 695 SkDevice device(store); | 655 SkDevice device(store); |
| 696 SkAutoTUnref<SkDeferredCanvas> canvas( | 656 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(&device))
; |
| 697 #if SK_DEFERRED_CANVAS_USES_FACTORIES | |
| 698 SkDeferredCanvas::Create(&device)); | |
| 699 #else | |
| 700 SkNEW_ARGS(SkDeferredCanvas, (&device))); | |
| 701 #endif | |
| 702 canvas->setBitmapSizeThreshold(39999); | 657 canvas->setBitmapSizeThreshold(39999); |
| 703 canvas->drawBitmap(sourceImage, 0, 0, NULL); | 658 canvas->drawBitmap(sourceImage, 0, 0, NULL); |
| 704 size_t newBytesAllocated = canvas->storageAllocatedForRecording(); | 659 size_t newBytesAllocated = canvas->storageAllocatedForRecording(); |
| 705 REPORTER_ASSERT(reporter, newBytesAllocated == 0); | 660 REPORTER_ASSERT(reporter, newBytesAllocated == 0); |
| 706 } | 661 } |
| 707 | 662 |
| 708 // exact value : should store the image | 663 // exact value : should store the image |
| 709 { | 664 { |
| 710 SkDevice device(store); | 665 SkDevice device(store); |
| 711 SkAutoTUnref<SkDeferredCanvas> canvas( | 666 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(&device))
; |
| 712 #if SK_DEFERRED_CANVAS_USES_FACTORIES | |
| 713 SkDeferredCanvas::Create(&device)); | |
| 714 #else | |
| 715 SkNEW_ARGS(SkDeferredCanvas, (&device))); | |
| 716 #endif | |
| 717 canvas->setBitmapSizeThreshold(40000); | 667 canvas->setBitmapSizeThreshold(40000); |
| 718 canvas->drawBitmap(sourceImage, 0, 0, NULL); | 668 canvas->drawBitmap(sourceImage, 0, 0, NULL); |
| 719 size_t newBytesAllocated = canvas->storageAllocatedForRecording(); | 669 size_t newBytesAllocated = canvas->storageAllocatedForRecording(); |
| 720 REPORTER_ASSERT(reporter, newBytesAllocated > 0); | 670 REPORTER_ASSERT(reporter, newBytesAllocated > 0); |
| 721 } | 671 } |
| 722 | 672 |
| 723 // 1 over : should still store the image | 673 // 1 over : should still store the image |
| 724 { | 674 { |
| 725 SkDevice device(store); | 675 SkDevice device(store); |
| 726 SkAutoTUnref<SkDeferredCanvas> canvas( | 676 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(&device))
; |
| 727 #if SK_DEFERRED_CANVAS_USES_FACTORIES | |
| 728 SkDeferredCanvas::Create(&device)); | |
| 729 #else | |
| 730 SkNEW_ARGS(SkDeferredCanvas, (&device))); | |
| 731 #endif | |
| 732 canvas->setBitmapSizeThreshold(40001); | 677 canvas->setBitmapSizeThreshold(40001); |
| 733 canvas->drawBitmap(sourceImage, 0, 0, NULL); | 678 canvas->drawBitmap(sourceImage, 0, 0, NULL); |
| 734 size_t newBytesAllocated = canvas->storageAllocatedForRecording(); | 679 size_t newBytesAllocated = canvas->storageAllocatedForRecording(); |
| 735 REPORTER_ASSERT(reporter, newBytesAllocated > 0); | 680 REPORTER_ASSERT(reporter, newBytesAllocated > 0); |
| 736 } | 681 } |
| 737 } | 682 } |
| 738 | 683 |
| 739 | 684 |
| 740 typedef void* PixelPtr; | 685 typedef void* PixelPtr; |
| 741 // Returns an opaque pointer which, either points to a GrTexture or RAM pixel | 686 // Returns an opaque pointer which, either points to a GrTexture or RAM pixel |
| (...skipping 19 matching lines...) Expand all Loading... |
| 761 surface = SkSurface::NewRenderTarget(context, imageSpec); | 706 surface = SkSurface::NewRenderTarget(context, imageSpec); |
| 762 } else { | 707 } else { |
| 763 surface = SkSurface::NewRaster(imageSpec); | 708 surface = SkSurface::NewRaster(imageSpec); |
| 764 } | 709 } |
| 765 #else | 710 #else |
| 766 SkASSERT(!useGpu); | 711 SkASSERT(!useGpu); |
| 767 surface = SkSurface::NewRaster(imageSpec); | 712 surface = SkSurface::NewRaster(imageSpec); |
| 768 #endif | 713 #endif |
| 769 SkASSERT(NULL != surface); | 714 SkASSERT(NULL != surface); |
| 770 SkAutoTUnref<SkSurface> aur(surface); | 715 SkAutoTUnref<SkSurface> aur(surface); |
| 771 SkAutoTUnref<SkDeferredCanvas> canvas( | 716 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface)); |
| 772 #if SK_DEFERRED_CANVAS_USES_FACTORIES | |
| 773 SkDeferredCanvas::Create(surface)); | |
| 774 #else | |
| 775 SkNEW_ARGS(SkDeferredCanvas, (surface))); | |
| 776 #endif | |
| 777 | 717 |
| 778 SkImage* image1 = canvas->newImageSnapshot(); | 718 SkImage* image1 = canvas->newImageSnapshot(); |
| 779 SkAutoTUnref<SkImage> aur_i1(image1); | 719 SkAutoTUnref<SkImage> aur_i1(image1); |
| 780 PixelPtr pixels1 = getSurfacePixelPtr(surface, useGpu); | 720 PixelPtr pixels1 = getSurfacePixelPtr(surface, useGpu); |
| 781 // The following clear would normally trigger a copy on write, but | 721 // The following clear would normally trigger a copy on write, but |
| 782 // it won't because rendering is deferred. | 722 // it won't because rendering is deferred. |
| 783 canvas->clear(SK_ColorBLACK); | 723 canvas->clear(SK_ColorBLACK); |
| 784 // Obtaining a snapshot directly from the surface (as opposed to the | 724 // Obtaining a snapshot directly from the surface (as opposed to the |
| 785 // SkDeferredCanvas) will not trigger a flush of deferred draw operations | 725 // SkDeferredCanvas) will not trigger a flush of deferred draw operations |
| 786 // and will therefore return the same image as the previous snapshot. | 726 // and will therefore return the same image as the previous snapshot. |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 841 SkASSERT(!useGpu); | 781 SkASSERT(!useGpu); |
| 842 surface = SkSurface::NewRaster(imageSpec); | 782 surface = SkSurface::NewRaster(imageSpec); |
| 843 alternateSurface = SkSurface::NewRaster(imageSpec); | 783 alternateSurface = SkSurface::NewRaster(imageSpec); |
| 844 #endif | 784 #endif |
| 845 SkASSERT(NULL != surface); | 785 SkASSERT(NULL != surface); |
| 846 SkASSERT(NULL != alternateSurface); | 786 SkASSERT(NULL != alternateSurface); |
| 847 SkAutoTUnref<SkSurface> aur1(surface); | 787 SkAutoTUnref<SkSurface> aur1(surface); |
| 848 SkAutoTUnref<SkSurface> aur2(alternateSurface); | 788 SkAutoTUnref<SkSurface> aur2(alternateSurface); |
| 849 PixelPtr pixels1 = getSurfacePixelPtr(surface, useGpu); | 789 PixelPtr pixels1 = getSurfacePixelPtr(surface, useGpu); |
| 850 PixelPtr pixels2 = getSurfacePixelPtr(alternateSurface, useGpu); | 790 PixelPtr pixels2 = getSurfacePixelPtr(alternateSurface, useGpu); |
| 851 SkAutoTUnref<SkDeferredCanvas> canvas( | 791 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface)); |
| 852 #if SK_DEFERRED_CANVAS_USES_FACTORIES | |
| 853 SkDeferredCanvas::Create(surface)); | |
| 854 #else | |
| 855 SkNEW_ARGS(SkDeferredCanvas, (surface))); | |
| 856 #endif | |
| 857 SkAutoTUnref<SkImage> image1(canvas->newImageSnapshot()); | 792 SkAutoTUnref<SkImage> image1(canvas->newImageSnapshot()); |
| 858 canvas->setSurface(alternateSurface); | 793 canvas->setSurface(alternateSurface); |
| 859 SkAutoTUnref<SkImage> image2(canvas->newImageSnapshot()); | 794 SkAutoTUnref<SkImage> image2(canvas->newImageSnapshot()); |
| 860 REPORTER_ASSERT(reporter, image1->uniqueID() != image2->uniqueID()); | 795 REPORTER_ASSERT(reporter, image1->uniqueID() != image2->uniqueID()); |
| 861 // Verify that none of the above operations triggered a surface copy on writ
e. | 796 // Verify that none of the above operations triggered a surface copy on writ
e. |
| 862 REPORTER_ASSERT(reporter, getSurfacePixelPtr(surface, useGpu) == pixels1); | 797 REPORTER_ASSERT(reporter, getSurfacePixelPtr(surface, useGpu) == pixels1); |
| 863 REPORTER_ASSERT(reporter, getSurfacePixelPtr(alternateSurface, useGpu) == pi
xels2); | 798 REPORTER_ASSERT(reporter, getSurfacePixelPtr(alternateSurface, useGpu) == pi
xels2); |
| 864 // Verify that a flushed draw command will trigger a copy on write on altern
ateSurface. | 799 // Verify that a flushed draw command will trigger a copy on write on altern
ateSurface. |
| 865 canvas->clear(SK_ColorWHITE); | 800 canvas->clear(SK_ColorWHITE); |
| 866 canvas->flush(); | 801 canvas->flush(); |
| 867 REPORTER_ASSERT(reporter, getSurfacePixelPtr(surface, useGpu) == pixels1); | 802 REPORTER_ASSERT(reporter, getSurfacePixelPtr(surface, useGpu) == pixels1); |
| 868 REPORTER_ASSERT(reporter, getSurfacePixelPtr(alternateSurface, useGpu) != pi
xels2); | 803 REPORTER_ASSERT(reporter, getSurfacePixelPtr(alternateSurface, useGpu) != pi
xels2); |
| 869 } | 804 } |
| 870 | 805 |
| 871 static void TestDeferredCanvasCreateCompatibleDevice(skiatest::Reporter* reporte
r) { | 806 static void TestDeferredCanvasCreateCompatibleDevice(skiatest::Reporter* reporte
r) { |
| 872 SkBitmap store; | 807 SkBitmap store; |
| 873 store.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); | 808 store.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); |
| 874 store.allocPixels(); | 809 store.allocPixels(); |
| 875 SkDevice device(store); | 810 SkDevice device(store); |
| 876 NotificationCounter notificationCounter; | 811 NotificationCounter notificationCounter; |
| 877 SkAutoTUnref<SkDeferredCanvas> canvas( | 812 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(&device)); |
| 878 #if SK_DEFERRED_CANVAS_USES_FACTORIES | |
| 879 SkDeferredCanvas::Create(&device)); | |
| 880 #else | |
| 881 SkNEW_ARGS(SkDeferredCanvas, (&device))); | |
| 882 #endif | |
| 883 canvas->setNotificationClient(¬ificationCounter); | 813 canvas->setNotificationClient(¬ificationCounter); |
| 884 SkAutoTUnref<SkDevice> secondaryDevice(canvas->createCompatibleDevice( | 814 SkAutoTUnref<SkDevice> secondaryDevice(canvas->createCompatibleDevice( |
| 885 SkBitmap::kARGB_8888_Config, 10, 10, device.isOpaque())); | 815 SkBitmap::kARGB_8888_Config, 10, 10, device.isOpaque())); |
| 886 SkCanvas secondaryCanvas(secondaryDevice.get()); | 816 SkCanvas secondaryCanvas(secondaryDevice.get()); |
| 887 SkRect rect = SkRect::MakeWH(5, 5); | 817 SkRect rect = SkRect::MakeWH(5, 5); |
| 888 SkPaint paint; | 818 SkPaint paint; |
| 889 // After spawning a compatible canvas: | 819 // After spawning a compatible canvas: |
| 890 // 1) Verify that secondary canvas is usable and does not report to the noti
fication client. | 820 // 1) Verify that secondary canvas is usable and does not report to the noti
fication client. |
| 891 secondaryCanvas.drawRect(rect, paint); | 821 secondaryCanvas.drawRect(rect, paint); |
| 892 REPORTER_ASSERT(reporter, notificationCounter.fStorageAllocatedChangedCount
== 0); | 822 REPORTER_ASSERT(reporter, notificationCounter.fStorageAllocatedChangedCount
== 0); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 909 TestDeferredCanvasSurface(reporter, NULL); | 839 TestDeferredCanvasSurface(reporter, NULL); |
| 910 TestDeferredCanvasSetSurface(reporter, NULL); | 840 TestDeferredCanvasSetSurface(reporter, NULL); |
| 911 if (NULL != factory) { | 841 if (NULL != factory) { |
| 912 TestDeferredCanvasSurface(reporter, factory); | 842 TestDeferredCanvasSurface(reporter, factory); |
| 913 TestDeferredCanvasSetSurface(reporter, factory); | 843 TestDeferredCanvasSetSurface(reporter, factory); |
| 914 } | 844 } |
| 915 } | 845 } |
| 916 | 846 |
| 917 #include "TestClassDef.h" | 847 #include "TestClassDef.h" |
| 918 DEFINE_GPUTESTCLASS("DeferredCanvas", TestDeferredCanvasClass, TestDeferredCanva
s) | 848 DEFINE_GPUTESTCLASS("DeferredCanvas", TestDeferredCanvasClass, TestDeferredCanva
s) |
| OLD | NEW |