OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "Test.h" | 8 #include "Test.h" |
9 | 9 |
10 #include "SkMallocPixelRef.h" | 10 #include "SkMallocPixelRef.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 int* fPtr; | 66 int* fPtr; |
67 }; | 67 }; |
68 | 68 |
69 DEF_TEST(PixelRef_GenIDChange, r) { | 69 DEF_TEST(PixelRef_GenIDChange, r) { |
70 SkImageInfo info = SkImageInfo::MakeN32Premul(10, 10); | 70 SkImageInfo info = SkImageInfo::MakeN32Premul(10, 10); |
71 | 71 |
72 SkAutoTUnref<SkPixelRef> pixelRef(SkMallocPixelRef::NewAllocate(info, 0, NUL
L)); | 72 SkAutoTUnref<SkPixelRef> pixelRef(SkMallocPixelRef::NewAllocate(info, 0, NUL
L)); |
73 | 73 |
74 // Register a listener. | 74 // Register a listener. |
75 int count = 0; | 75 int count = 0; |
76 pixelRef->addGenIDChangeListener(SkNEW_ARGS(TestListener, (&count))); | 76 pixelRef->addGenIDChangeListener(new TestListener(&count)); |
77 REPORTER_ASSERT(r, 0 == count); | 77 REPORTER_ASSERT(r, 0 == count); |
78 | 78 |
79 // No one has looked at our pixelRef's generation ID, so invalidating it doe
sn't make sense. | 79 // No one has looked at our pixelRef's generation ID, so invalidating it doe
sn't make sense. |
80 // (An SkPixelRef tree falls in the forest but there's nobody around to hear
it. Do we care?) | 80 // (An SkPixelRef tree falls in the forest but there's nobody around to hear
it. Do we care?) |
81 pixelRef->notifyPixelsChanged(); | 81 pixelRef->notifyPixelsChanged(); |
82 REPORTER_ASSERT(r, 0 == count); | 82 REPORTER_ASSERT(r, 0 == count); |
83 | 83 |
84 // Force the generation ID to be calculated. | 84 // Force the generation ID to be calculated. |
85 REPORTER_ASSERT(r, 0 != pixelRef->getGenerationID()); | 85 REPORTER_ASSERT(r, 0 != pixelRef->getGenerationID()); |
86 | 86 |
87 // Our listener was dropped in the first call to notifyPixelsChanged(). Thi
s is a no-op. | 87 // Our listener was dropped in the first call to notifyPixelsChanged(). Thi
s is a no-op. |
88 pixelRef->notifyPixelsChanged(); | 88 pixelRef->notifyPixelsChanged(); |
89 REPORTER_ASSERT(r, 0 == count); | 89 REPORTER_ASSERT(r, 0 == count); |
90 | 90 |
91 // Force the generation ID to be recalculated, then add a listener. | 91 // Force the generation ID to be recalculated, then add a listener. |
92 REPORTER_ASSERT(r, 0 != pixelRef->getGenerationID()); | 92 REPORTER_ASSERT(r, 0 != pixelRef->getGenerationID()); |
93 pixelRef->addGenIDChangeListener(SkNEW_ARGS(TestListener, (&count))); | 93 pixelRef->addGenIDChangeListener(new TestListener(&count)); |
94 pixelRef->notifyPixelsChanged(); | 94 pixelRef->notifyPixelsChanged(); |
95 REPORTER_ASSERT(r, 1 == count); | 95 REPORTER_ASSERT(r, 1 == count); |
96 | 96 |
97 // Quick check that NULL is safe. | 97 // Quick check that NULL is safe. |
98 REPORTER_ASSERT(r, 0 != pixelRef->getGenerationID()); | 98 REPORTER_ASSERT(r, 0 != pixelRef->getGenerationID()); |
99 pixelRef->addGenIDChangeListener(NULL); | 99 pixelRef->addGenIDChangeListener(NULL); |
100 pixelRef->notifyPixelsChanged(); | 100 pixelRef->notifyPixelsChanged(); |
101 | 101 |
102 test_install(r); | 102 test_install(r); |
103 test_dont_leak_install(r); | 103 test_dont_leak_install(r); |
104 } | 104 } |
OLD | NEW |