Chromium Code Reviews| 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" |
| 11 #include "SkBitmapDevice.h" | 11 #include "SkBitmapDevice.h" |
| 12 #include "SkBitmapProcShader.h" | 12 #include "SkBitmapProcShader.h" |
| 13 #include "SkDeferredCanvas.h" | 13 #include "SkDeferredCanvas.h" |
| 14 #include "SkGradientShader.h" | 14 #include "SkGradientShader.h" |
| 15 #include "SkShader.h" | 15 #include "SkShader.h" |
| 16 #include "SkSurface.h" | |
| 16 #include "Test.h" | 17 #include "Test.h" |
| 17 #if SK_SUPPORT_GPU | 18 #if SK_SUPPORT_GPU |
| 18 #include "GrContextFactory.h" | 19 #include "GrContextFactory.h" |
| 19 #else | 20 #else |
| 20 class GrContextFactory; | 21 class GrContextFactory; |
| 21 #endif | 22 #endif |
| 22 | 23 |
| 23 static const int gWidth = 2; | 24 static const int gWidth = 2; |
| 24 static const int gHeight = 2; | 25 static const int gHeight = 2; |
| 25 | 26 |
| 26 static void create(SkBitmap* bm, SkBitmap::Config config, SkColor color) { | 27 static void create(SkBitmap* bm, SkBitmap::Config config, SkColor color) { |
| 27 bm->setConfig(config, gWidth, gHeight); | 28 bm->setConfig(config, gWidth, gHeight); |
| 28 bm->allocPixels(); | 29 bm->allocPixels(); |
| 29 bm->eraseColor(color); | 30 bm->eraseColor(color); |
| 30 } | 31 } |
| 31 | 32 |
| 33 static SkSurface* createSurface(SkColor color) { | |
| 34 SkSurface* surface = SkSurface::NewRasterPMColor(gWidth, gHeight); | |
| 35 surface->getCanvas()->clear(color); | |
| 36 return surface; | |
| 37 } | |
| 38 | |
| 39 static SkPMColor read_pixel(SkSurface* surface, int x, int y) { | |
| 40 SkPMColor pixel = 0; | |
| 41 SkBitmap bitmap; | |
| 42 bitmap.installPixels(SkImageInfo::MakeN32Premul(1, 1), &pixel, 4, NULL, NULL ); | |
| 43 SkCanvas canvas(bitmap); | |
| 44 | |
| 45 SkPaint paint; | |
| 46 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | |
| 47 surface->draw(&canvas, -x, -y, &paint); | |
| 48 return pixel; | |
| 49 } | |
| 50 | |
| 32 static void TestDeferredCanvasBitmapAccess(skiatest::Reporter* reporter) { | 51 static void TestDeferredCanvasBitmapAccess(skiatest::Reporter* reporter) { |
| 33 SkBitmap store; | 52 SkBitmap store; |
| 34 | 53 |
| 35 create(&store, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF); | 54 SkAutoTUnref<SkSurface> surface(createSurface(0xFFFFFFFF)); |
| 36 SkBitmapDevice device(store); | 55 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get() )); |
| 37 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(&device)); | 56 |
| 38 | |
| 39 canvas->clear(0x00000000); | 57 canvas->clear(0x00000000); |
| 40 | 58 |
| 41 SkAutoLockPixels alp(store); | 59 // verify that the clear() was deferred |
| 42 REPORTER_ASSERT(reporter, store.getColor(0,0) == 0xFFFFFFFF); //verify that clear was deferred | 60 REPORTER_ASSERT(reporter, 0xFFFFFFFF == read_pixel(surface, 0, 0)); |
| 61 | |
| 43 SkBitmap accessed = canvas->getDevice()->accessBitmap(false); | 62 SkBitmap accessed = canvas->getDevice()->accessBitmap(false); |
| 44 REPORTER_ASSERT(reporter, store.getColor(0,0) == 0x00000000); //verify that clear was executed | 63 |
| 45 REPORTER_ASSERT(reporter, accessed.pixelRef() == store.pixelRef()); | 64 // verify that clear was executed |
| 65 REPORTER_ASSERT(reporter, 0 == read_pixel(surface, 0, 0)); | |
| 46 } | 66 } |
| 47 | 67 |
| 48 class MockSurface : public SkSurface_Base { | 68 class MockSurface : public SkSurface_Base { |
| 49 public: | 69 public: |
| 50 MockSurface(int width, int height) : SkSurface_Base(width, height) { | 70 MockSurface(int width, int height) : SkSurface_Base(width, height) { |
| 51 clearCounts(); | 71 clearCounts(); |
| 52 fBitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); | 72 fBitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); |
| 53 fBitmap.allocPixels(); | 73 fBitmap.allocPixels(); |
| 54 } | 74 } |
| 55 | 75 |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 249 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); | 269 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); |
| 250 REPORTER_ASSERT(reporter, 1 == surface->fRetainCount); | 270 REPORTER_ASSERT(reporter, 1 == surface->fRetainCount); |
| 251 | 271 |
| 252 surface->clearCounts(); | 272 surface->clearCounts(); |
| 253 canvas->flush(); | 273 canvas->flush(); |
| 254 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); | 274 REPORTER_ASSERT(reporter, 0 == surface->fDiscardCount); |
| 255 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount); | 275 REPORTER_ASSERT(reporter, 0 == surface->fRetainCount); |
| 256 } | 276 } |
| 257 | 277 |
| 258 static void TestDeferredCanvasFlush(skiatest::Reporter* reporter) { | 278 static void TestDeferredCanvasFlush(skiatest::Reporter* reporter) { |
| 259 SkBitmap store; | 279 SkAutoTUnref<SkSurface> surface(createSurface(0xFFFFFFFF)); |
| 260 | 280 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get() )); |
| 261 create(&store, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF); | |
| 262 SkBitmapDevice device(store); | |
| 263 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(&device)); | |
| 264 | 281 |
| 265 canvas->clear(0x00000000); | 282 canvas->clear(0x00000000); |
| 266 | 283 |
| 267 SkAutoLockPixels alp(store); | 284 // verify that clear was deferred |
| 268 REPORTER_ASSERT(reporter, store.getColor(0,0) == 0xFFFFFFFF); //verify that clear was deferred | 285 REPORTER_ASSERT(reporter, 0xFFFFFFFF == read_pixel(surface, 0, 0)); |
| 286 | |
| 269 canvas->flush(); | 287 canvas->flush(); |
| 270 REPORTER_ASSERT(reporter, store.getColor(0,0) == 0x00000000); //verify that clear was executed | 288 |
| 289 // verify that clear was executed | |
| 290 REPORTER_ASSERT(reporter, 0 == read_pixel(surface, 0, 0)); | |
| 271 } | 291 } |
| 272 | 292 |
| 273 static void TestDeferredCanvasFreshFrame(skiatest::Reporter* reporter) { | 293 static void TestDeferredCanvasFreshFrame(skiatest::Reporter* reporter) { |
| 274 SkBitmap store; | |
| 275 SkRect fullRect; | 294 SkRect fullRect; |
| 276 fullRect.setXYWH(SkIntToScalar(0), SkIntToScalar(0), SkIntToScalar(gWidth), | 295 fullRect.setXYWH(SkIntToScalar(0), SkIntToScalar(0), SkIntToScalar(gWidth), |
| 277 SkIntToScalar(gHeight)); | 296 SkIntToScalar(gHeight)); |
| 278 SkRect partialRect; | 297 SkRect partialRect; |
| 279 partialRect.setXYWH(SkIntToScalar(0), SkIntToScalar(0), | 298 partialRect.setXYWH(SkIntToScalar(0), SkIntToScalar(0), |
| 280 SkIntToScalar(1), SkIntToScalar(1)); | 299 SkIntToScalar(1), SkIntToScalar(1)); |
| 281 create(&store, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF); | 300 |
| 282 SkBitmapDevice device(store); | 301 SkAutoTUnref<SkSurface> surface(createSurface(0xFFFFFFFF)); |
| 283 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(&device)); | 302 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get() )); |
| 284 | 303 |
| 285 // verify that frame is intially fresh | 304 // verify that frame is intially fresh |
| 286 REPORTER_ASSERT(reporter, canvas->isFreshFrame()); | 305 REPORTER_ASSERT(reporter, canvas->isFreshFrame()); |
| 287 // no clearing op since last call to isFreshFrame -> not fresh | 306 // no clearing op since last call to isFreshFrame -> not fresh |
| 288 REPORTER_ASSERT(reporter, !canvas->isFreshFrame()); | 307 REPORTER_ASSERT(reporter, !canvas->isFreshFrame()); |
| 289 | 308 |
| 290 // Verify that clear triggers a fresh frame | 309 // Verify that clear triggers a fresh frame |
| 291 canvas->clear(0x00000000); | 310 canvas->clear(0x00000000); |
| 292 REPORTER_ASSERT(reporter, canvas->isFreshFrame()); | 311 REPORTER_ASSERT(reporter, canvas->isFreshFrame()); |
| 293 | 312 |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 442 const SkMatrix&, const SkPaint&) SK_OVERRIDE { | 461 const SkMatrix&, const SkPaint&) SK_OVERRIDE { |
| 443 fDrawBitmapCallCount++; | 462 fDrawBitmapCallCount++; |
| 444 } | 463 } |
| 445 | 464 |
| 446 int fDrawBitmapCallCount; | 465 int fDrawBitmapCallCount; |
| 447 }; | 466 }; |
| 448 | 467 |
| 449 // Verifies that the deferred canvas triggers a flush when its memory | 468 // Verifies that the deferred canvas triggers a flush when its memory |
| 450 // limit is exceeded | 469 // limit is exceeded |
| 451 static void TestDeferredCanvasMemoryLimit(skiatest::Reporter* reporter) { | 470 static void TestDeferredCanvasMemoryLimit(skiatest::Reporter* reporter) { |
| 471 #if 0 // TODO -- need a surface-oriented way to exercise this. | |
|
Justin Novosad
2014/02/03 21:33:47
You could register an SkDeferredCanvas::Notificati
reed1
2014/02/03 21:52:40
Done.
| |
| 452 SkBitmap store; | 472 SkBitmap store; |
| 453 store.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); | 473 store.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); |
| 454 store.allocPixels(); | 474 store.allocPixels(); |
| 455 MockDevice mockDevice(store); | 475 MockDevice mockDevice(store); |
| 456 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(&mockDevice)) ; | 476 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(&mockDevice)) ; |
| 457 canvas->setMaxRecordingStorage(160000); | 477 canvas->setMaxRecordingStorage(160000); |
| 458 | 478 |
| 459 SkBitmap sourceImage; | 479 SkBitmap sourceImage; |
| 460 // 100 by 100 image, takes 40,000 bytes in memory | 480 // 100 by 100 image, takes 40,000 bytes in memory |
| 461 sourceImage.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); | 481 sourceImage.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); |
| 462 sourceImage.allocPixels(); | 482 sourceImage.allocPixels(); |
| 463 | 483 |
| 464 for (int i = 0; i < 5; i++) { | 484 for (int i = 0; i < 5; i++) { |
| 465 sourceImage.notifyPixelsChanged(); // to force re-serialization | 485 sourceImage.notifyPixelsChanged(); // to force re-serialization |
| 466 canvas->drawBitmap(sourceImage, 0, 0, NULL); | 486 canvas->drawBitmap(sourceImage, 0, 0, NULL); |
| 467 } | 487 } |
| 468 | 488 |
| 469 REPORTER_ASSERT(reporter, mockDevice.fDrawBitmapCallCount == 4); | 489 REPORTER_ASSERT(reporter, mockDevice.fDrawBitmapCallCount == 4); |
| 490 #endif | |
| 470 } | 491 } |
| 471 | 492 |
| 472 class NotificationCounter : public SkDeferredCanvas::NotificationClient { | 493 class NotificationCounter : public SkDeferredCanvas::NotificationClient { |
| 473 public: | 494 public: |
| 474 NotificationCounter() { | 495 NotificationCounter() { |
| 475 fPrepareForDrawCount = fStorageAllocatedChangedCount = | 496 fPrepareForDrawCount = fStorageAllocatedChangedCount = |
| 476 fFlushedDrawCommandsCount = fSkippedPendingDrawCommandsCount = 0; | 497 fFlushedDrawCommandsCount = fSkippedPendingDrawCommandsCount = 0; |
| 477 } | 498 } |
| 478 | 499 |
| 479 virtual void prepareForDraw() SK_OVERRIDE { | 500 virtual void prepareForDraw() SK_OVERRIDE { |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 492 int fPrepareForDrawCount; | 513 int fPrepareForDrawCount; |
| 493 int fStorageAllocatedChangedCount; | 514 int fStorageAllocatedChangedCount; |
| 494 int fFlushedDrawCommandsCount; | 515 int fFlushedDrawCommandsCount; |
| 495 int fSkippedPendingDrawCommandsCount; | 516 int fSkippedPendingDrawCommandsCount; |
| 496 | 517 |
| 497 private: | 518 private: |
| 498 typedef SkDeferredCanvas::NotificationClient INHERITED; | 519 typedef SkDeferredCanvas::NotificationClient INHERITED; |
| 499 }; | 520 }; |
| 500 | 521 |
| 501 static void TestDeferredCanvasBitmapCaching(skiatest::Reporter* reporter) { | 522 static void TestDeferredCanvasBitmapCaching(skiatest::Reporter* reporter) { |
| 502 SkBitmap store; | 523 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(100, 100)); |
| 503 store.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); | 524 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get() )); |
| 504 store.allocPixels(); | 525 |
| 505 SkBitmapDevice device(store); | |
| 506 NotificationCounter notificationCounter; | 526 NotificationCounter notificationCounter; |
| 507 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(&device)); | |
| 508 canvas->setNotificationClient(¬ificationCounter); | 527 canvas->setNotificationClient(¬ificationCounter); |
| 509 | 528 |
| 510 const int imageCount = 2; | 529 const int imageCount = 2; |
| 511 SkBitmap sourceImages[imageCount]; | 530 SkBitmap sourceImages[imageCount]; |
| 512 for (int i = 0; i < imageCount; i++) | 531 for (int i = 0; i < imageCount; i++) |
| 513 { | 532 { |
| 514 sourceImages[i].setConfig(SkBitmap::kARGB_8888_Config, 100, 100); | 533 sourceImages[i].setConfig(SkBitmap::kARGB_8888_Config, 100, 100); |
| 515 sourceImages[i].allocPixels(); | 534 sourceImages[i].allocPixels(); |
| 516 } | 535 } |
| 517 | 536 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 575 canvas->drawBitmap(sourceImages[1], 0, 0, NULL); | 594 canvas->drawBitmap(sourceImages[1], 0, 0, NULL); |
| 576 sourceImages[1].notifyPixelsChanged(); | 595 sourceImages[1].notifyPixelsChanged(); |
| 577 canvas->drawBitmap(sourceImages[1], 0, 0, NULL); | 596 canvas->drawBitmap(sourceImages[1], 0, 0, NULL); |
| 578 REPORTER_ASSERT(reporter, canvas->storageAllocatedForRecording() > 2*bitmapS ize); | 597 REPORTER_ASSERT(reporter, canvas->storageAllocatedForRecording() > 2*bitmapS ize); |
| 579 | 598 |
| 580 // Verify that nothing in this test caused commands to be skipped | 599 // Verify that nothing in this test caused commands to be skipped |
| 581 REPORTER_ASSERT(reporter, 0 == notificationCounter.fSkippedPendingDrawComman dsCount); | 600 REPORTER_ASSERT(reporter, 0 == notificationCounter.fSkippedPendingDrawComman dsCount); |
| 582 } | 601 } |
| 583 | 602 |
| 584 static void TestDeferredCanvasSkip(skiatest::Reporter* reporter) { | 603 static void TestDeferredCanvasSkip(skiatest::Reporter* reporter) { |
| 585 SkBitmap store; | 604 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(100, 100)); |
| 586 store.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); | 605 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get() )); |
| 587 store.allocPixels(); | 606 |
| 588 SkBitmapDevice device(store); | |
| 589 NotificationCounter notificationCounter; | 607 NotificationCounter notificationCounter; |
| 590 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(&device)); | |
| 591 canvas->setNotificationClient(¬ificationCounter); | 608 canvas->setNotificationClient(¬ificationCounter); |
| 592 canvas->clear(0x0); | 609 canvas->clear(0x0); |
| 593 REPORTER_ASSERT(reporter, 1 == notificationCounter.fSkippedPendingDrawComman dsCount); | 610 REPORTER_ASSERT(reporter, 1 == notificationCounter.fSkippedPendingDrawComman dsCount); |
| 594 REPORTER_ASSERT(reporter, 0 == notificationCounter.fFlushedDrawCommandsCount ); | 611 REPORTER_ASSERT(reporter, 0 == notificationCounter.fFlushedDrawCommandsCount ); |
| 595 canvas->flush(); | 612 canvas->flush(); |
| 596 REPORTER_ASSERT(reporter, 1 == notificationCounter.fSkippedPendingDrawComman dsCount); | 613 REPORTER_ASSERT(reporter, 1 == notificationCounter.fSkippedPendingDrawComman dsCount); |
| 597 REPORTER_ASSERT(reporter, 1 == notificationCounter.fFlushedDrawCommandsCount ); | 614 REPORTER_ASSERT(reporter, 1 == notificationCounter.fFlushedDrawCommandsCount ); |
| 598 | 615 |
| 599 } | 616 } |
| 600 | 617 |
| 601 static void TestDeferredCanvasBitmapShaderNoLeak(skiatest::Reporter* reporter) { | 618 static void TestDeferredCanvasBitmapShaderNoLeak(skiatest::Reporter* reporter) { |
| 602 // This is a regression test for crbug.com/155875 | 619 // This is a regression test for crbug.com/155875 |
| 603 // This test covers a code path that inserts bitmaps into the bitmap heap th rough the | 620 // This test covers a code path that inserts bitmaps into the bitmap heap th rough the |
| 604 // flattening of SkBitmapProcShaders. The refcount in the bitmap heap is mai ntained through | 621 // flattening of SkBitmapProcShaders. The refcount in the bitmap heap is mai ntained through |
| 605 // the flattening and unflattening of the shader. | 622 // the flattening and unflattening of the shader. |
| 606 SkBitmap store; | 623 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(100, 100)); |
| 607 store.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); | 624 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get() )); |
| 608 store.allocPixels(); | |
| 609 SkBitmapDevice device(store); | |
| 610 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(&device)); | |
| 611 // test will fail if nbIterations is not in sync with | 625 // test will fail if nbIterations is not in sync with |
| 612 // BITMAPS_TO_KEEP in SkGPipeWrite.cpp | 626 // BITMAPS_TO_KEEP in SkGPipeWrite.cpp |
| 613 const int nbIterations = 5; | 627 const int nbIterations = 5; |
| 614 size_t bytesAllocated = 0; | 628 size_t bytesAllocated = 0; |
| 615 for(int pass = 0; pass < 2; ++pass) { | 629 for(int pass = 0; pass < 2; ++pass) { |
| 616 for(int i = 0; i < nbIterations; ++i) { | 630 for(int i = 0; i < nbIterations; ++i) { |
| 617 SkPaint paint; | 631 SkPaint paint; |
| 618 SkBitmap paintPattern; | 632 SkBitmap paintPattern; |
| 619 paintPattern.setConfig(SkBitmap::kARGB_8888_Config, 10, 10); | 633 paintPattern.setConfig(SkBitmap::kARGB_8888_Config, 10, 10); |
| 620 paintPattern.allocPixels(); | 634 paintPattern.allocPixels(); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 634 REPORTER_ASSERT(reporter, newBytesAllocated == bytesAllocated); | 648 REPORTER_ASSERT(reporter, newBytesAllocated == bytesAllocated); |
| 635 } | 649 } |
| 636 } | 650 } |
| 637 } | 651 } |
| 638 // All cached resources should be evictable since last canvas call was flush () | 652 // All cached resources should be evictable since last canvas call was flush () |
| 639 canvas->freeMemoryIfPossible(~0U); | 653 canvas->freeMemoryIfPossible(~0U); |
| 640 REPORTER_ASSERT(reporter, 0 == canvas->storageAllocatedForRecording()); | 654 REPORTER_ASSERT(reporter, 0 == canvas->storageAllocatedForRecording()); |
| 641 } | 655 } |
| 642 | 656 |
| 643 static void TestDeferredCanvasBitmapSizeThreshold(skiatest::Reporter* reporter) { | 657 static void TestDeferredCanvasBitmapSizeThreshold(skiatest::Reporter* reporter) { |
| 644 SkBitmap store; | 658 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(100, 100)); |
| 645 store.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); | |
| 646 store.allocPixels(); | |
| 647 | 659 |
| 648 SkBitmap sourceImage; | 660 SkBitmap sourceImage; |
| 649 // 100 by 100 image, takes 40,000 bytes in memory | 661 // 100 by 100 image, takes 40,000 bytes in memory |
| 650 sourceImage.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); | 662 sourceImage.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); |
| 651 sourceImage.allocPixels(); | 663 sourceImage.allocPixels(); |
| 652 | 664 |
| 653 // 1 under : should not store the image | 665 // 1 under : should not store the image |
| 654 { | 666 { |
| 655 SkBitmapDevice device(store); | 667 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.g et())); |
| 656 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(&device)) ; | |
| 657 canvas->setBitmapSizeThreshold(39999); | 668 canvas->setBitmapSizeThreshold(39999); |
| 658 canvas->drawBitmap(sourceImage, 0, 0, NULL); | 669 canvas->drawBitmap(sourceImage, 0, 0, NULL); |
| 659 size_t newBytesAllocated = canvas->storageAllocatedForRecording(); | 670 size_t newBytesAllocated = canvas->storageAllocatedForRecording(); |
| 660 REPORTER_ASSERT(reporter, newBytesAllocated == 0); | 671 REPORTER_ASSERT(reporter, newBytesAllocated == 0); |
| 661 } | 672 } |
| 662 | 673 |
| 663 // exact value : should store the image | 674 // exact value : should store the image |
| 664 { | 675 { |
| 665 SkBitmapDevice device(store); | 676 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.g et())); |
| 666 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(&device)) ; | |
| 667 canvas->setBitmapSizeThreshold(40000); | 677 canvas->setBitmapSizeThreshold(40000); |
| 668 canvas->drawBitmap(sourceImage, 0, 0, NULL); | 678 canvas->drawBitmap(sourceImage, 0, 0, NULL); |
| 669 size_t newBytesAllocated = canvas->storageAllocatedForRecording(); | 679 size_t newBytesAllocated = canvas->storageAllocatedForRecording(); |
| 670 REPORTER_ASSERT(reporter, newBytesAllocated > 0); | 680 REPORTER_ASSERT(reporter, newBytesAllocated > 0); |
| 671 } | 681 } |
| 672 | 682 |
| 673 // 1 over : should still store the image | 683 // 1 over : should still store the image |
| 674 { | 684 { |
| 675 SkBitmapDevice device(store); | 685 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.g et())); |
| 676 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(&device)) ; | |
| 677 canvas->setBitmapSizeThreshold(40001); | 686 canvas->setBitmapSizeThreshold(40001); |
| 678 canvas->drawBitmap(sourceImage, 0, 0, NULL); | 687 canvas->drawBitmap(sourceImage, 0, 0, NULL); |
| 679 size_t newBytesAllocated = canvas->storageAllocatedForRecording(); | 688 size_t newBytesAllocated = canvas->storageAllocatedForRecording(); |
| 680 REPORTER_ASSERT(reporter, newBytesAllocated > 0); | 689 REPORTER_ASSERT(reporter, newBytesAllocated > 0); |
| 681 } | 690 } |
| 682 } | 691 } |
| 683 | 692 |
| 684 | 693 |
| 685 typedef void* PixelPtr; | 694 typedef void* PixelPtr; |
| 686 // Returns an opaque pointer which, either points to a GrTexture or RAM pixel | 695 // Returns an opaque pointer which, either points to a GrTexture or RAM pixel |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 804 REPORTER_ASSERT(reporter, getSurfacePixelPtr(surface, useGpu) == pixels1); | 813 REPORTER_ASSERT(reporter, getSurfacePixelPtr(surface, useGpu) == pixels1); |
| 805 REPORTER_ASSERT(reporter, getSurfacePixelPtr(alternateSurface, useGpu) == pi xels2); | 814 REPORTER_ASSERT(reporter, getSurfacePixelPtr(alternateSurface, useGpu) == pi xels2); |
| 806 // Verify that a flushed draw command will trigger a copy on write on altern ateSurface. | 815 // Verify that a flushed draw command will trigger a copy on write on altern ateSurface. |
| 807 canvas->clear(SK_ColorWHITE); | 816 canvas->clear(SK_ColorWHITE); |
| 808 canvas->flush(); | 817 canvas->flush(); |
| 809 REPORTER_ASSERT(reporter, getSurfacePixelPtr(surface, useGpu) == pixels1); | 818 REPORTER_ASSERT(reporter, getSurfacePixelPtr(surface, useGpu) == pixels1); |
| 810 REPORTER_ASSERT(reporter, getSurfacePixelPtr(alternateSurface, useGpu) != pi xels2); | 819 REPORTER_ASSERT(reporter, getSurfacePixelPtr(alternateSurface, useGpu) != pi xels2); |
| 811 } | 820 } |
| 812 | 821 |
| 813 static void TestDeferredCanvasCreateCompatibleDevice(skiatest::Reporter* reporte r) { | 822 static void TestDeferredCanvasCreateCompatibleDevice(skiatest::Reporter* reporte r) { |
| 814 SkBitmap store; | 823 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(100, 100)); |
| 815 store.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); | 824 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get() )); |
| 816 store.allocPixels(); | 825 |
| 817 SkBitmapDevice device(store); | |
| 818 NotificationCounter notificationCounter; | 826 NotificationCounter notificationCounter; |
| 819 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(&device)); | |
| 820 canvas->setNotificationClient(¬ificationCounter); | 827 canvas->setNotificationClient(¬ificationCounter); |
| 828 | |
| 821 SkAutoTUnref<SkBaseDevice> secondaryDevice(canvas->createCompatibleDevice( | 829 SkAutoTUnref<SkBaseDevice> secondaryDevice(canvas->createCompatibleDevice( |
| 822 SkBitmap::kARGB_8888_Config, 10, 10, device.isOpaque())); | 830 SkBitmap::kARGB_8888_Config, 10, 10, false)); |
| 823 SkCanvas secondaryCanvas(secondaryDevice.get()); | 831 SkCanvas secondaryCanvas(secondaryDevice.get()); |
| 824 SkRect rect = SkRect::MakeWH(5, 5); | 832 SkRect rect = SkRect::MakeWH(5, 5); |
| 825 SkPaint paint; | 833 SkPaint paint; |
| 826 // After spawning a compatible canvas: | 834 // After spawning a compatible canvas: |
| 827 // 1) Verify that secondary canvas is usable and does not report to the noti fication client. | 835 // 1) Verify that secondary canvas is usable and does not report to the noti fication client. |
| 828 secondaryCanvas.drawRect(rect, paint); | 836 secondaryCanvas.drawRect(rect, paint); |
| 829 REPORTER_ASSERT(reporter, notificationCounter.fStorageAllocatedChangedCount == 0); | 837 REPORTER_ASSERT(reporter, notificationCounter.fStorageAllocatedChangedCount == 0); |
| 830 // 2) Verify that original canvas is usable and still reports to the notific ation client. | 838 // 2) Verify that original canvas is usable and still reports to the notific ation client. |
| 831 canvas->drawRect(rect, paint); | 839 canvas->drawRect(rect, paint); |
| 832 REPORTER_ASSERT(reporter, notificationCounter.fStorageAllocatedChangedCount == 1); | 840 REPORTER_ASSERT(reporter, notificationCounter.fStorageAllocatedChangedCount == 1); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 843 TestDeferredCanvasBitmapSizeThreshold(reporter); | 851 TestDeferredCanvasBitmapSizeThreshold(reporter); |
| 844 TestDeferredCanvasCreateCompatibleDevice(reporter); | 852 TestDeferredCanvasCreateCompatibleDevice(reporter); |
| 845 TestDeferredCanvasWritePixelsToSurface(reporter); | 853 TestDeferredCanvasWritePixelsToSurface(reporter); |
| 846 TestDeferredCanvasSurface(reporter, NULL); | 854 TestDeferredCanvasSurface(reporter, NULL); |
| 847 TestDeferredCanvasSetSurface(reporter, NULL); | 855 TestDeferredCanvasSetSurface(reporter, NULL); |
| 848 if (NULL != factory) { | 856 if (NULL != factory) { |
| 849 TestDeferredCanvasSurface(reporter, factory); | 857 TestDeferredCanvasSurface(reporter, factory); |
| 850 TestDeferredCanvasSetSurface(reporter, factory); | 858 TestDeferredCanvasSetSurface(reporter, factory); |
| 851 } | 859 } |
| 852 } | 860 } |
| OLD | NEW |