| 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 bool success; | |
| 15 SkImageInfo info = SkImageInfo::MakeN32Premul(0, 0); | |
| 16 SkBitmap bm; | |
| 17 // make sure we don't assert on an empty install | |
| 18 success = bm.installPixels(info, NULL, 0); | |
| 19 REPORTER_ASSERT(reporter, success); | |
| 20 | |
| 21 // no pixels should be the same as setInfo() | |
| 22 info = SkImageInfo::MakeN32Premul(10, 10); | |
| 23 success = bm.installPixels(info, NULL, 0); | |
| 24 REPORTER_ASSERT(reporter, success); | |
| 25 } | |
| 26 | |
| 27 class TestListener : public SkPixelRef::GenIDChangeListener { | 6 class TestListener : public SkPixelRef::GenIDChangeListener { |
| 28 public: | 7 public: |
| 29 explicit TestListener(int* ptr) : fPtr(ptr) {} | 8 explicit TestListener(int* ptr) : fPtr(ptr) {} |
| 30 void onChange() override { (*fPtr)++; } | 9 void onChange() override { (*fPtr)++; } |
| 31 private: | 10 private: |
| 32 int* fPtr; | 11 int* fPtr; |
| 33 }; | 12 }; |
| 34 | 13 |
| 35 DEF_TEST(PixelRef_GenIDChange, r) { | 14 DEF_TEST(PixelRef_GenIDChange, r) { |
| 36 SkImageInfo info = SkImageInfo::MakeN32Premul(10, 10); | 15 SkImageInfo info = SkImageInfo::MakeN32Premul(10, 10); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 57 // Force the generation ID to be recalculated, then add a listener. | 36 // Force the generation ID to be recalculated, then add a listener. |
| 58 REPORTER_ASSERT(r, 0 != pixelRef->getGenerationID()); | 37 REPORTER_ASSERT(r, 0 != pixelRef->getGenerationID()); |
| 59 pixelRef->addGenIDChangeListener(SkNEW_ARGS(TestListener, (&count))); | 38 pixelRef->addGenIDChangeListener(SkNEW_ARGS(TestListener, (&count))); |
| 60 pixelRef->notifyPixelsChanged(); | 39 pixelRef->notifyPixelsChanged(); |
| 61 REPORTER_ASSERT(r, 1 == count); | 40 REPORTER_ASSERT(r, 1 == count); |
| 62 | 41 |
| 63 // Quick check that NULL is safe. | 42 // Quick check that NULL is safe. |
| 64 REPORTER_ASSERT(r, 0 != pixelRef->getGenerationID()); | 43 REPORTER_ASSERT(r, 0 != pixelRef->getGenerationID()); |
| 65 pixelRef->addGenIDChangeListener(NULL); | 44 pixelRef->addGenIDChangeListener(NULL); |
| 66 pixelRef->notifyPixelsChanged(); | 45 pixelRef->notifyPixelsChanged(); |
| 67 | |
| 68 test_install(r); | |
| 69 } | 46 } |
| OLD | NEW |