OLD | NEW |
1 /* | |
2 * Copyright 2015 Google Inc. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license that can be | |
5 * found in the LICENSE file. | |
6 */ | |
7 | |
8 #include "Test.h" | 1 #include "Test.h" |
9 | 2 |
10 #include "SkMallocPixelRef.h" | 3 #include "SkMallocPixelRef.h" |
11 #include "SkPixelRef.h" | 4 #include "SkPixelRef.h" |
12 | 5 |
13 static void test_install(skiatest::Reporter* reporter) { | |
14 SkImageInfo info = SkImageInfo::MakeN32Premul(0, 0); | |
15 SkBitmap bm; | |
16 // make sure we don't assert on an empty install | |
17 bm.installPixels(info, NULL, 0); | |
18 } | |
19 | |
20 class TestListener : public SkPixelRef::GenIDChangeListener { | 6 class TestListener : public SkPixelRef::GenIDChangeListener { |
21 public: | 7 public: |
22 explicit TestListener(int* ptr) : fPtr(ptr) {} | 8 explicit TestListener(int* ptr) : fPtr(ptr) {} |
23 void onChange() override { (*fPtr)++; } | 9 void onChange() override { (*fPtr)++; } |
24 private: | 10 private: |
25 int* fPtr; | 11 int* fPtr; |
26 }; | 12 }; |
27 | 13 |
28 DEF_TEST(PixelRef_GenIDChange, r) { | 14 DEF_TEST(PixelRef_GenIDChange, r) { |
29 SkImageInfo info = SkImageInfo::MakeN32Premul(10, 10); | 15 SkImageInfo info = SkImageInfo::MakeN32Premul(10, 10); |
(...skipping 20 matching lines...) Expand all Loading... |
50 // Force the generation ID to be recalculated, then add a listener. | 36 // Force the generation ID to be recalculated, then add a listener. |
51 REPORTER_ASSERT(r, 0 != pixelRef->getGenerationID()); | 37 REPORTER_ASSERT(r, 0 != pixelRef->getGenerationID()); |
52 pixelRef->addGenIDChangeListener(SkNEW_ARGS(TestListener, (&count))); | 38 pixelRef->addGenIDChangeListener(SkNEW_ARGS(TestListener, (&count))); |
53 pixelRef->notifyPixelsChanged(); | 39 pixelRef->notifyPixelsChanged(); |
54 REPORTER_ASSERT(r, 1 == count); | 40 REPORTER_ASSERT(r, 1 == count); |
55 | 41 |
56 // Quick check that NULL is safe. | 42 // Quick check that NULL is safe. |
57 REPORTER_ASSERT(r, 0 != pixelRef->getGenerationID()); | 43 REPORTER_ASSERT(r, 0 != pixelRef->getGenerationID()); |
58 pixelRef->addGenIDChangeListener(NULL); | 44 pixelRef->addGenIDChangeListener(NULL); |
59 pixelRef->notifyPixelsChanged(); | 45 pixelRef->notifyPixelsChanged(); |
60 | |
61 test_install(r); | |
62 } | 46 } |
OLD | NEW |