| OLD | NEW |
| 1 #include "Test.h" | 1 #include "Test.h" |
| 2 #include "TestClassDef.h" | 2 #include "TestClassDef.h" |
| 3 | 3 |
| 4 #include "SkPixelRef.h" | 4 #include "SkPixelRef.h" |
| 5 #include "SkMallocPixelRef.h" | 5 #include "SkMallocPixelRef.h" |
| 6 | 6 |
| 7 static void test_info(skiatest::Reporter* reporter) { | 7 static void test_info(skiatest::Reporter* reporter) { |
| 8 static const struct { | 8 static const struct { |
| 9 SkBitmap::Config fConfig; | 9 SkBitmap::Config fConfig; |
| 10 SkAlphaType fAlphaType; | 10 SkAlphaType fAlphaType; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 public: | 44 public: |
| 45 explicit TestListener(int* ptr) : fPtr(ptr) {} | 45 explicit TestListener(int* ptr) : fPtr(ptr) {} |
| 46 void onChange() SK_OVERRIDE { (*fPtr)++; } | 46 void onChange() SK_OVERRIDE { (*fPtr)++; } |
| 47 private: | 47 private: |
| 48 int* fPtr; | 48 int* fPtr; |
| 49 }; | 49 }; |
| 50 | 50 |
| 51 } // namespace | 51 } // namespace |
| 52 | 52 |
| 53 DEF_TEST(PixelRef_GenIDChange, r) { | 53 DEF_TEST(PixelRef_GenIDChange, r) { |
| 54 SkImageInfo info = { 10, 10, kPMColor_SkColorType, kPremul_SkAlphaType }; | 54 SkMallocPixelRef pixelRef(NULL, 0, NULL); // We don't really care about the
pixels here. |
| 55 | |
| 56 SkAutoTUnref<SkPixelRef> pixelRef(SkMallocPixelRef::NewAllocate(info, 0, NUL
L)); | |
| 57 | 55 |
| 58 // Register a listener. | 56 // Register a listener. |
| 59 int count = 0; | 57 int count = 0; |
| 60 pixelRef->addGenIDChangeListener(SkNEW_ARGS(TestListener, (&count))); | 58 pixelRef.addGenIDChangeListener(SkNEW_ARGS(TestListener, (&count))); |
| 61 REPORTER_ASSERT(r, 0 == count); | 59 REPORTER_ASSERT(r, 0 == count); |
| 62 | 60 |
| 63 // No one has looked at our pixelRef's generation ID, so invalidating it doe
sn't make sense. | 61 // No one has looked at our pixelRef's generation ID, so invalidating it doe
sn't make sense. |
| 64 // (An SkPixelRef tree falls in the forest but there's nobody around to hear
it. Do we care?) | 62 // (An SkPixelRef tree falls in the forest but there's nobody around to hear
it. Do we care?) |
| 65 pixelRef->notifyPixelsChanged(); | 63 pixelRef.notifyPixelsChanged(); |
| 66 REPORTER_ASSERT(r, 0 == count); | 64 REPORTER_ASSERT(r, 0 == count); |
| 67 | 65 |
| 68 // Force the generation ID to be calculated. | 66 // Force the generation ID to be calculated. |
| 69 REPORTER_ASSERT(r, 0 != pixelRef->getGenerationID()); | 67 REPORTER_ASSERT(r, 0 != pixelRef.getGenerationID()); |
| 70 | 68 |
| 71 // Our listener was dropped in the first call to notifyPixelsChanged(). Thi
s is a no-op. | 69 // Our listener was dropped in the first call to notifyPixelsChanged(). Thi
s is a no-op. |
| 72 pixelRef->notifyPixelsChanged(); | 70 pixelRef.notifyPixelsChanged(); |
| 73 REPORTER_ASSERT(r, 0 == count); | 71 REPORTER_ASSERT(r, 0 == count); |
| 74 | 72 |
| 75 // Force the generation ID to be recalculated, then add a listener. | 73 // Force the generation ID to be recalculated, then add a listener. |
| 76 REPORTER_ASSERT(r, 0 != pixelRef->getGenerationID()); | 74 REPORTER_ASSERT(r, 0 != pixelRef.getGenerationID()); |
| 77 pixelRef->addGenIDChangeListener(SkNEW_ARGS(TestListener, (&count))); | 75 pixelRef.addGenIDChangeListener(SkNEW_ARGS(TestListener, (&count))); |
| 78 pixelRef->notifyPixelsChanged(); | 76 pixelRef.notifyPixelsChanged(); |
| 79 REPORTER_ASSERT(r, 1 == count); | 77 REPORTER_ASSERT(r, 1 == count); |
| 80 | 78 |
| 81 // Quick check that NULL is safe. | 79 // Quick check that NULL is safe. |
| 82 REPORTER_ASSERT(r, 0 != pixelRef->getGenerationID()); | 80 REPORTER_ASSERT(r, 0 != pixelRef.getGenerationID()); |
| 83 pixelRef->addGenIDChangeListener(NULL); | 81 pixelRef.addGenIDChangeListener(NULL); |
| 84 pixelRef->notifyPixelsChanged(); | 82 pixelRef.notifyPixelsChanged(); |
| 85 | 83 |
| 86 test_info(r); | 84 test_info(r); |
| 87 } | 85 } |
| OLD | NEW |