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 "../src/image/SkImagePriv.h" | 8 #include "../src/image/SkImagePriv.h" |
9 #include "../src/image/SkSurface_Base.h" | 9 #include "../src/image/SkSurface_Base.h" |
10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get()
)); | 480 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get()
)); |
481 | 481 |
482 NotificationCounter notificationCounter; | 482 NotificationCounter notificationCounter; |
483 canvas->setNotificationClient(¬ificationCounter); | 483 canvas->setNotificationClient(¬ificationCounter); |
484 | 484 |
485 canvas->setMaxRecordingStorage(160000); | 485 canvas->setMaxRecordingStorage(160000); |
486 | 486 |
487 SkBitmap sourceImage; | 487 SkBitmap sourceImage; |
488 // 100 by 100 image, takes 40,000 bytes in memory | 488 // 100 by 100 image, takes 40,000 bytes in memory |
489 sourceImage.allocN32Pixels(100, 100); | 489 sourceImage.allocN32Pixels(100, 100); |
| 490 sourceImage.eraseColor(SK_ColorGREEN); |
490 | 491 |
491 for (int i = 0; i < 5; i++) { | 492 for (int i = 0; i < 5; i++) { |
492 sourceImage.notifyPixelsChanged(); // to force re-serialization | 493 sourceImage.notifyPixelsChanged(); // to force re-serialization |
493 canvas->drawBitmap(sourceImage, 0, 0, NULL); | 494 canvas->drawBitmap(sourceImage, 0, 0, NULL); |
494 } | 495 } |
495 | 496 |
496 REPORTER_ASSERT(reporter, 1 == notificationCounter.fFlushedDrawCommandsCount
); | 497 REPORTER_ASSERT(reporter, 1 == notificationCounter.fFlushedDrawCommandsCount
); |
497 } | 498 } |
498 | 499 |
499 static void TestDeferredCanvasSilentFlush(skiatest::Reporter* reporter) { | 500 static void TestDeferredCanvasSilentFlush(skiatest::Reporter* reporter) { |
(...skipping 13 matching lines...) Expand all Loading... |
513 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(100, 100)); | 514 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(100, 100)); |
514 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get()
)); | 515 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get()
)); |
515 | 516 |
516 NotificationCounter notificationCounter; | 517 NotificationCounter notificationCounter; |
517 canvas->setNotificationClient(¬ificationCounter); | 518 canvas->setNotificationClient(¬ificationCounter); |
518 | 519 |
519 const int imageCount = 2; | 520 const int imageCount = 2; |
520 SkBitmap sourceImages[imageCount]; | 521 SkBitmap sourceImages[imageCount]; |
521 for (int i = 0; i < imageCount; i++) { | 522 for (int i = 0; i < imageCount; i++) { |
522 sourceImages[i].allocN32Pixels(100, 100); | 523 sourceImages[i].allocN32Pixels(100, 100); |
| 524 sourceImages[i].eraseColor(SK_ColorGREEN); |
523 } | 525 } |
524 | 526 |
525 size_t bitmapSize = sourceImages[0].getSize(); | 527 size_t bitmapSize = sourceImages[0].getSize(); |
526 | 528 |
527 canvas->drawBitmap(sourceImages[0], 0, 0, NULL); | 529 canvas->drawBitmap(sourceImages[0], 0, 0, NULL); |
528 REPORTER_ASSERT(reporter, 1 == notificationCounter.fStorageAllocatedChangedC
ount); | 530 REPORTER_ASSERT(reporter, 1 == notificationCounter.fStorageAllocatedChangedC
ount); |
529 // stored bitmap + drawBitmap command | 531 // stored bitmap + drawBitmap command |
530 REPORTER_ASSERT(reporter, canvas->storageAllocatedForRecording() > bitmapSiz
e); | 532 REPORTER_ASSERT(reporter, canvas->storageAllocatedForRecording() > bitmapSiz
e); |
531 | 533 |
532 // verify that nothing can be freed at this point | 534 // verify that nothing can be freed at this point |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get()
)); | 614 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get()
)); |
613 // test will fail if nbIterations is not in sync with | 615 // test will fail if nbIterations is not in sync with |
614 // BITMAPS_TO_KEEP in SkGPipeWrite.cpp | 616 // BITMAPS_TO_KEEP in SkGPipeWrite.cpp |
615 const int nbIterations = 5; | 617 const int nbIterations = 5; |
616 size_t bytesAllocated = 0; | 618 size_t bytesAllocated = 0; |
617 for(int pass = 0; pass < 2; ++pass) { | 619 for(int pass = 0; pass < 2; ++pass) { |
618 for(int i = 0; i < nbIterations; ++i) { | 620 for(int i = 0; i < nbIterations; ++i) { |
619 SkPaint paint; | 621 SkPaint paint; |
620 SkBitmap paintPattern; | 622 SkBitmap paintPattern; |
621 paintPattern.allocN32Pixels(10, 10); | 623 paintPattern.allocN32Pixels(10, 10); |
| 624 paintPattern.eraseColor(SK_ColorGREEN); |
622 paint.setShader(SkNEW_ARGS(SkBitmapProcShader, | 625 paint.setShader(SkNEW_ARGS(SkBitmapProcShader, |
623 (paintPattern, SkShader::kClamp_TileMode, SkShader::kClamp_TileM
ode)))->unref(); | 626 (paintPattern, SkShader::kClamp_TileMode, SkShader::kClamp_TileM
ode)))->unref(); |
624 canvas->drawPaint(paint); | 627 canvas->drawPaint(paint); |
625 canvas->flush(); | 628 canvas->flush(); |
626 | 629 |
627 // In the first pass, memory allocation should be monotonically incr
easing as | 630 // In the first pass, memory allocation should be monotonically incr
easing as |
628 // the bitmap heap slots fill up. In the second pass memory allocat
ion should be | 631 // the bitmap heap slots fill up. In the second pass memory allocat
ion should be |
629 // stable as bitmap heap slots get recycled. | 632 // stable as bitmap heap slots get recycled. |
630 size_t newBytesAllocated = canvas->storageAllocatedForRecording(); | 633 size_t newBytesAllocated = canvas->storageAllocatedForRecording(); |
631 if (pass == 0) { | 634 if (pass == 0) { |
632 REPORTER_ASSERT(reporter, newBytesAllocated > bytesAllocated); | 635 REPORTER_ASSERT(reporter, newBytesAllocated > bytesAllocated); |
633 bytesAllocated = newBytesAllocated; | 636 bytesAllocated = newBytesAllocated; |
634 } else { | 637 } else { |
635 REPORTER_ASSERT(reporter, newBytesAllocated == bytesAllocated); | 638 REPORTER_ASSERT(reporter, newBytesAllocated == bytesAllocated); |
636 } | 639 } |
637 } | 640 } |
638 } | 641 } |
639 // All cached resources should be evictable since last canvas call was flush
() | 642 // All cached resources should be evictable since last canvas call was flush
() |
640 canvas->freeMemoryIfPossible(~0U); | 643 canvas->freeMemoryIfPossible(~0U); |
641 REPORTER_ASSERT(reporter, 0 == canvas->storageAllocatedForRecording()); | 644 REPORTER_ASSERT(reporter, 0 == canvas->storageAllocatedForRecording()); |
642 } | 645 } |
643 | 646 |
644 static void TestDeferredCanvasBitmapSizeThreshold(skiatest::Reporter* reporter)
{ | 647 static void TestDeferredCanvasBitmapSizeThreshold(skiatest::Reporter* reporter)
{ |
645 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(100, 100)); | 648 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(100, 100)); |
646 | 649 |
647 SkBitmap sourceImage; | 650 SkBitmap sourceImage; |
648 // 100 by 100 image, takes 40,000 bytes in memory | 651 // 100 by 100 image, takes 40,000 bytes in memory |
649 sourceImage.allocN32Pixels(100, 100); | 652 sourceImage.allocN32Pixels(100, 100); |
| 653 sourceImage.eraseColor(SK_ColorGREEN); |
650 | 654 |
651 // 1 under : should not store the image | 655 // 1 under : should not store the image |
652 { | 656 { |
653 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.g
et())); | 657 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.g
et())); |
654 canvas->setBitmapSizeThreshold(39999); | 658 canvas->setBitmapSizeThreshold(39999); |
655 canvas->drawBitmap(sourceImage, 0, 0, NULL); | 659 canvas->drawBitmap(sourceImage, 0, 0, NULL); |
656 size_t newBytesAllocated = canvas->storageAllocatedForRecording(); | 660 size_t newBytesAllocated = canvas->storageAllocatedForRecording(); |
657 REPORTER_ASSERT(reporter, newBytesAllocated == 0); | 661 REPORTER_ASSERT(reporter, newBytesAllocated == 0); |
658 } | 662 } |
659 | 663 |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
831 TestDeferredCanvasSurface(reporter, NULL); | 835 TestDeferredCanvasSurface(reporter, NULL); |
832 TestDeferredCanvasSetSurface(reporter, NULL); | 836 TestDeferredCanvasSetSurface(reporter, NULL); |
833 } | 837 } |
834 | 838 |
835 DEF_GPUTEST(DeferredCanvas_GPU, reporter, factory) { | 839 DEF_GPUTEST(DeferredCanvas_GPU, reporter, factory) { |
836 if (factory != NULL) { | 840 if (factory != NULL) { |
837 TestDeferredCanvasSurface(reporter, factory); | 841 TestDeferredCanvasSurface(reporter, factory); |
838 TestDeferredCanvasSetSurface(reporter, factory); | 842 TestDeferredCanvasSetSurface(reporter, factory); |
839 } | 843 } |
840 } | 844 } |
OLD | NEW |