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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 fDrawBitmapCallCount = 0; | 458 fDrawBitmapCallCount = 0; |
440 } | 459 } |
441 virtual void drawBitmap(const SkDraw&, const SkBitmap&, | 460 virtual void drawBitmap(const SkDraw&, const SkBitmap&, |
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 | |
450 // limit is exceeded | |
451 static void TestDeferredCanvasMemoryLimit(skiatest::Reporter* reporter) { | |
452 SkBitmap store; | |
453 store.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); | |
454 store.allocPixels(); | |
455 MockDevice mockDevice(store); | |
456 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(&mockDevice))
; | |
457 canvas->setMaxRecordingStorage(160000); | |
458 | |
459 SkBitmap sourceImage; | |
460 // 100 by 100 image, takes 40,000 bytes in memory | |
461 sourceImage.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); | |
462 sourceImage.allocPixels(); | |
463 | |
464 for (int i = 0; i < 5; i++) { | |
465 sourceImage.notifyPixelsChanged(); // to force re-serialization | |
466 canvas->drawBitmap(sourceImage, 0, 0, NULL); | |
467 } | |
468 | |
469 REPORTER_ASSERT(reporter, mockDevice.fDrawBitmapCallCount == 4); | |
470 } | |
471 | |
472 class NotificationCounter : public SkDeferredCanvas::NotificationClient { | 468 class NotificationCounter : public SkDeferredCanvas::NotificationClient { |
473 public: | 469 public: |
474 NotificationCounter() { | 470 NotificationCounter() { |
475 fPrepareForDrawCount = fStorageAllocatedChangedCount = | 471 fPrepareForDrawCount = fStorageAllocatedChangedCount = |
476 fFlushedDrawCommandsCount = fSkippedPendingDrawCommandsCount = 0; | 472 fFlushedDrawCommandsCount = fSkippedPendingDrawCommandsCount = 0; |
477 } | 473 } |
478 | 474 |
479 virtual void prepareForDraw() SK_OVERRIDE { | 475 virtual void prepareForDraw() SK_OVERRIDE { |
480 fPrepareForDrawCount++; | 476 fPrepareForDrawCount++; |
481 } | 477 } |
482 virtual void storageAllocatedForRecordingChanged(size_t) SK_OVERRIDE { | 478 virtual void storageAllocatedForRecordingChanged(size_t) SK_OVERRIDE { |
483 fStorageAllocatedChangedCount++; | 479 fStorageAllocatedChangedCount++; |
484 } | 480 } |
485 virtual void flushedDrawCommands() SK_OVERRIDE { | 481 virtual void flushedDrawCommands() SK_OVERRIDE { |
486 fFlushedDrawCommandsCount++; | 482 fFlushedDrawCommandsCount++; |
487 } | 483 } |
488 virtual void skippedPendingDrawCommands() SK_OVERRIDE { | 484 virtual void skippedPendingDrawCommands() SK_OVERRIDE { |
489 fSkippedPendingDrawCommandsCount++; | 485 fSkippedPendingDrawCommandsCount++; |
490 } | 486 } |
491 | 487 |
492 int fPrepareForDrawCount; | 488 int fPrepareForDrawCount; |
493 int fStorageAllocatedChangedCount; | 489 int fStorageAllocatedChangedCount; |
494 int fFlushedDrawCommandsCount; | 490 int fFlushedDrawCommandsCount; |
495 int fSkippedPendingDrawCommandsCount; | 491 int fSkippedPendingDrawCommandsCount; |
496 | 492 |
497 private: | 493 private: |
498 typedef SkDeferredCanvas::NotificationClient INHERITED; | 494 typedef SkDeferredCanvas::NotificationClient INHERITED; |
499 }; | 495 }; |
500 | 496 |
| 497 // Verifies that the deferred canvas triggers a flush when its memory |
| 498 // limit is exceeded |
| 499 static void TestDeferredCanvasMemoryLimit(skiatest::Reporter* reporter) { |
| 500 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(100, 100)); |
| 501 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get()
)); |
| 502 |
| 503 NotificationCounter notificationCounter; |
| 504 canvas->setNotificationClient(¬ificationCounter); |
| 505 |
| 506 canvas->setMaxRecordingStorage(160000); |
| 507 |
| 508 SkBitmap sourceImage; |
| 509 // 100 by 100 image, takes 40,000 bytes in memory |
| 510 sourceImage.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); |
| 511 sourceImage.allocPixels(); |
| 512 |
| 513 for (int i = 0; i < 5; i++) { |
| 514 sourceImage.notifyPixelsChanged(); // to force re-serialization |
| 515 canvas->drawBitmap(sourceImage, 0, 0, NULL); |
| 516 } |
| 517 |
| 518 REPORTER_ASSERT(reporter, 1 == notificationCounter.fFlushedDrawCommandsCount
); |
| 519 } |
| 520 |
501 static void TestDeferredCanvasBitmapCaching(skiatest::Reporter* reporter) { | 521 static void TestDeferredCanvasBitmapCaching(skiatest::Reporter* reporter) { |
502 SkBitmap store; | 522 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(100, 100)); |
503 store.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); | 523 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get()
)); |
504 store.allocPixels(); | 524 |
505 SkBitmapDevice device(store); | |
506 NotificationCounter notificationCounter; | 525 NotificationCounter notificationCounter; |
507 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(&device)); | |
508 canvas->setNotificationClient(¬ificationCounter); | 526 canvas->setNotificationClient(¬ificationCounter); |
509 | 527 |
510 const int imageCount = 2; | 528 const int imageCount = 2; |
511 SkBitmap sourceImages[imageCount]; | 529 SkBitmap sourceImages[imageCount]; |
512 for (int i = 0; i < imageCount; i++) | 530 for (int i = 0; i < imageCount; i++) |
513 { | 531 { |
514 sourceImages[i].setConfig(SkBitmap::kARGB_8888_Config, 100, 100); | 532 sourceImages[i].setConfig(SkBitmap::kARGB_8888_Config, 100, 100); |
515 sourceImages[i].allocPixels(); | 533 sourceImages[i].allocPixels(); |
516 } | 534 } |
517 | 535 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 canvas->drawBitmap(sourceImages[1], 0, 0, NULL); | 593 canvas->drawBitmap(sourceImages[1], 0, 0, NULL); |
576 sourceImages[1].notifyPixelsChanged(); | 594 sourceImages[1].notifyPixelsChanged(); |
577 canvas->drawBitmap(sourceImages[1], 0, 0, NULL); | 595 canvas->drawBitmap(sourceImages[1], 0, 0, NULL); |
578 REPORTER_ASSERT(reporter, canvas->storageAllocatedForRecording() > 2*bitmapS
ize); | 596 REPORTER_ASSERT(reporter, canvas->storageAllocatedForRecording() > 2*bitmapS
ize); |
579 | 597 |
580 // Verify that nothing in this test caused commands to be skipped | 598 // Verify that nothing in this test caused commands to be skipped |
581 REPORTER_ASSERT(reporter, 0 == notificationCounter.fSkippedPendingDrawComman
dsCount); | 599 REPORTER_ASSERT(reporter, 0 == notificationCounter.fSkippedPendingDrawComman
dsCount); |
582 } | 600 } |
583 | 601 |
584 static void TestDeferredCanvasSkip(skiatest::Reporter* reporter) { | 602 static void TestDeferredCanvasSkip(skiatest::Reporter* reporter) { |
585 SkBitmap store; | 603 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(100, 100)); |
586 store.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); | 604 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get()
)); |
587 store.allocPixels(); | 605 |
588 SkBitmapDevice device(store); | |
589 NotificationCounter notificationCounter; | 606 NotificationCounter notificationCounter; |
590 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(&device)); | |
591 canvas->setNotificationClient(¬ificationCounter); | 607 canvas->setNotificationClient(¬ificationCounter); |
592 canvas->clear(0x0); | 608 canvas->clear(0x0); |
593 REPORTER_ASSERT(reporter, 1 == notificationCounter.fSkippedPendingDrawComman
dsCount); | 609 REPORTER_ASSERT(reporter, 1 == notificationCounter.fSkippedPendingDrawComman
dsCount); |
594 REPORTER_ASSERT(reporter, 0 == notificationCounter.fFlushedDrawCommandsCount
); | 610 REPORTER_ASSERT(reporter, 0 == notificationCounter.fFlushedDrawCommandsCount
); |
595 canvas->flush(); | 611 canvas->flush(); |
596 REPORTER_ASSERT(reporter, 1 == notificationCounter.fSkippedPendingDrawComman
dsCount); | 612 REPORTER_ASSERT(reporter, 1 == notificationCounter.fSkippedPendingDrawComman
dsCount); |
597 REPORTER_ASSERT(reporter, 1 == notificationCounter.fFlushedDrawCommandsCount
); | 613 REPORTER_ASSERT(reporter, 1 == notificationCounter.fFlushedDrawCommandsCount
); |
598 | 614 |
599 } | 615 } |
600 | 616 |
601 static void TestDeferredCanvasBitmapShaderNoLeak(skiatest::Reporter* reporter) { | 617 static void TestDeferredCanvasBitmapShaderNoLeak(skiatest::Reporter* reporter) { |
602 // This is a regression test for crbug.com/155875 | 618 // 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 | 619 // 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 | 620 // flattening of SkBitmapProcShaders. The refcount in the bitmap heap is mai
ntained through |
605 // the flattening and unflattening of the shader. | 621 // the flattening and unflattening of the shader. |
606 SkBitmap store; | 622 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(100, 100)); |
607 store.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); | 623 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 | 624 // test will fail if nbIterations is not in sync with |
612 // BITMAPS_TO_KEEP in SkGPipeWrite.cpp | 625 // BITMAPS_TO_KEEP in SkGPipeWrite.cpp |
613 const int nbIterations = 5; | 626 const int nbIterations = 5; |
614 size_t bytesAllocated = 0; | 627 size_t bytesAllocated = 0; |
615 for(int pass = 0; pass < 2; ++pass) { | 628 for(int pass = 0; pass < 2; ++pass) { |
616 for(int i = 0; i < nbIterations; ++i) { | 629 for(int i = 0; i < nbIterations; ++i) { |
617 SkPaint paint; | 630 SkPaint paint; |
618 SkBitmap paintPattern; | 631 SkBitmap paintPattern; |
619 paintPattern.setConfig(SkBitmap::kARGB_8888_Config, 10, 10); | 632 paintPattern.setConfig(SkBitmap::kARGB_8888_Config, 10, 10); |
620 paintPattern.allocPixels(); | 633 paintPattern.allocPixels(); |
(...skipping 13 matching lines...) Expand all Loading... |
634 REPORTER_ASSERT(reporter, newBytesAllocated == bytesAllocated); | 647 REPORTER_ASSERT(reporter, newBytesAllocated == bytesAllocated); |
635 } | 648 } |
636 } | 649 } |
637 } | 650 } |
638 // All cached resources should be evictable since last canvas call was flush
() | 651 // All cached resources should be evictable since last canvas call was flush
() |
639 canvas->freeMemoryIfPossible(~0U); | 652 canvas->freeMemoryIfPossible(~0U); |
640 REPORTER_ASSERT(reporter, 0 == canvas->storageAllocatedForRecording()); | 653 REPORTER_ASSERT(reporter, 0 == canvas->storageAllocatedForRecording()); |
641 } | 654 } |
642 | 655 |
643 static void TestDeferredCanvasBitmapSizeThreshold(skiatest::Reporter* reporter)
{ | 656 static void TestDeferredCanvasBitmapSizeThreshold(skiatest::Reporter* reporter)
{ |
644 SkBitmap store; | 657 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(100, 100)); |
645 store.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); | |
646 store.allocPixels(); | |
647 | 658 |
648 SkBitmap sourceImage; | 659 SkBitmap sourceImage; |
649 // 100 by 100 image, takes 40,000 bytes in memory | 660 // 100 by 100 image, takes 40,000 bytes in memory |
650 sourceImage.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); | 661 sourceImage.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); |
651 sourceImage.allocPixels(); | 662 sourceImage.allocPixels(); |
652 | 663 |
653 // 1 under : should not store the image | 664 // 1 under : should not store the image |
654 { | 665 { |
655 SkBitmapDevice device(store); | 666 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.g
et())); |
656 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(&device))
; | |
657 canvas->setBitmapSizeThreshold(39999); | 667 canvas->setBitmapSizeThreshold(39999); |
658 canvas->drawBitmap(sourceImage, 0, 0, NULL); | 668 canvas->drawBitmap(sourceImage, 0, 0, NULL); |
659 size_t newBytesAllocated = canvas->storageAllocatedForRecording(); | 669 size_t newBytesAllocated = canvas->storageAllocatedForRecording(); |
660 REPORTER_ASSERT(reporter, newBytesAllocated == 0); | 670 REPORTER_ASSERT(reporter, newBytesAllocated == 0); |
661 } | 671 } |
662 | 672 |
663 // exact value : should store the image | 673 // exact value : should store the image |
664 { | 674 { |
665 SkBitmapDevice device(store); | 675 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.g
et())); |
666 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(&device))
; | |
667 canvas->setBitmapSizeThreshold(40000); | 676 canvas->setBitmapSizeThreshold(40000); |
668 canvas->drawBitmap(sourceImage, 0, 0, NULL); | 677 canvas->drawBitmap(sourceImage, 0, 0, NULL); |
669 size_t newBytesAllocated = canvas->storageAllocatedForRecording(); | 678 size_t newBytesAllocated = canvas->storageAllocatedForRecording(); |
670 REPORTER_ASSERT(reporter, newBytesAllocated > 0); | 679 REPORTER_ASSERT(reporter, newBytesAllocated > 0); |
671 } | 680 } |
672 | 681 |
673 // 1 over : should still store the image | 682 // 1 over : should still store the image |
674 { | 683 { |
675 SkBitmapDevice device(store); | 684 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.g
et())); |
676 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(&device))
; | |
677 canvas->setBitmapSizeThreshold(40001); | 685 canvas->setBitmapSizeThreshold(40001); |
678 canvas->drawBitmap(sourceImage, 0, 0, NULL); | 686 canvas->drawBitmap(sourceImage, 0, 0, NULL); |
679 size_t newBytesAllocated = canvas->storageAllocatedForRecording(); | 687 size_t newBytesAllocated = canvas->storageAllocatedForRecording(); |
680 REPORTER_ASSERT(reporter, newBytesAllocated > 0); | 688 REPORTER_ASSERT(reporter, newBytesAllocated > 0); |
681 } | 689 } |
682 } | 690 } |
683 | 691 |
684 | 692 |
685 typedef void* PixelPtr; | 693 typedef void* PixelPtr; |
686 // Returns an opaque pointer which, either points to a GrTexture or RAM pixel | 694 // 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); | 812 REPORTER_ASSERT(reporter, getSurfacePixelPtr(surface, useGpu) == pixels1); |
805 REPORTER_ASSERT(reporter, getSurfacePixelPtr(alternateSurface, useGpu) == pi
xels2); | 813 REPORTER_ASSERT(reporter, getSurfacePixelPtr(alternateSurface, useGpu) == pi
xels2); |
806 // Verify that a flushed draw command will trigger a copy on write on altern
ateSurface. | 814 // Verify that a flushed draw command will trigger a copy on write on altern
ateSurface. |
807 canvas->clear(SK_ColorWHITE); | 815 canvas->clear(SK_ColorWHITE); |
808 canvas->flush(); | 816 canvas->flush(); |
809 REPORTER_ASSERT(reporter, getSurfacePixelPtr(surface, useGpu) == pixels1); | 817 REPORTER_ASSERT(reporter, getSurfacePixelPtr(surface, useGpu) == pixels1); |
810 REPORTER_ASSERT(reporter, getSurfacePixelPtr(alternateSurface, useGpu) != pi
xels2); | 818 REPORTER_ASSERT(reporter, getSurfacePixelPtr(alternateSurface, useGpu) != pi
xels2); |
811 } | 819 } |
812 | 820 |
813 static void TestDeferredCanvasCreateCompatibleDevice(skiatest::Reporter* reporte
r) { | 821 static void TestDeferredCanvasCreateCompatibleDevice(skiatest::Reporter* reporte
r) { |
814 SkBitmap store; | 822 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(100, 100)); |
815 store.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); | 823 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get()
)); |
816 store.allocPixels(); | 824 |
817 SkBitmapDevice device(store); | |
818 NotificationCounter notificationCounter; | 825 NotificationCounter notificationCounter; |
819 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(&device)); | |
820 canvas->setNotificationClient(¬ificationCounter); | 826 canvas->setNotificationClient(¬ificationCounter); |
| 827 |
821 SkAutoTUnref<SkBaseDevice> secondaryDevice(canvas->createCompatibleDevice( | 828 SkAutoTUnref<SkBaseDevice> secondaryDevice(canvas->createCompatibleDevice( |
822 SkBitmap::kARGB_8888_Config, 10, 10, device.isOpaque())); | 829 SkBitmap::kARGB_8888_Config, 10, 10, false)); |
823 SkCanvas secondaryCanvas(secondaryDevice.get()); | 830 SkCanvas secondaryCanvas(secondaryDevice.get()); |
824 SkRect rect = SkRect::MakeWH(5, 5); | 831 SkRect rect = SkRect::MakeWH(5, 5); |
825 SkPaint paint; | 832 SkPaint paint; |
826 // After spawning a compatible canvas: | 833 // After spawning a compatible canvas: |
827 // 1) Verify that secondary canvas is usable and does not report to the noti
fication client. | 834 // 1) Verify that secondary canvas is usable and does not report to the noti
fication client. |
828 secondaryCanvas.drawRect(rect, paint); | 835 secondaryCanvas.drawRect(rect, paint); |
829 REPORTER_ASSERT(reporter, notificationCounter.fStorageAllocatedChangedCount
== 0); | 836 REPORTER_ASSERT(reporter, notificationCounter.fStorageAllocatedChangedCount
== 0); |
830 // 2) Verify that original canvas is usable and still reports to the notific
ation client. | 837 // 2) Verify that original canvas is usable and still reports to the notific
ation client. |
831 canvas->drawRect(rect, paint); | 838 canvas->drawRect(rect, paint); |
832 REPORTER_ASSERT(reporter, notificationCounter.fStorageAllocatedChangedCount
== 1); | 839 REPORTER_ASSERT(reporter, notificationCounter.fStorageAllocatedChangedCount
== 1); |
(...skipping 10 matching lines...) Expand all Loading... |
843 TestDeferredCanvasBitmapSizeThreshold(reporter); | 850 TestDeferredCanvasBitmapSizeThreshold(reporter); |
844 TestDeferredCanvasCreateCompatibleDevice(reporter); | 851 TestDeferredCanvasCreateCompatibleDevice(reporter); |
845 TestDeferredCanvasWritePixelsToSurface(reporter); | 852 TestDeferredCanvasWritePixelsToSurface(reporter); |
846 TestDeferredCanvasSurface(reporter, NULL); | 853 TestDeferredCanvasSurface(reporter, NULL); |
847 TestDeferredCanvasSetSurface(reporter, NULL); | 854 TestDeferredCanvasSetSurface(reporter, NULL); |
848 if (NULL != factory) { | 855 if (NULL != factory) { |
849 TestDeferredCanvasSurface(reporter, factory); | 856 TestDeferredCanvasSurface(reporter, factory); |
850 TestDeferredCanvasSetSurface(reporter, factory); | 857 TestDeferredCanvasSetSurface(reporter, factory); |
851 } | 858 } |
852 } | 859 } |
OLD | NEW |