| OLD | NEW | 
|---|
| 1 #include "Test.h" | 1 #include "Test.h" | 
| 2 | 2 | 
| 3 #include "SkMallocPixelRef.h" | 3 #include "SkMallocPixelRef.h" | 
| 4 #include "SkPixelRef.h" | 4 #include "SkPixelRef.h" | 
| 5 | 5 | 
| 6 static void test_info(skiatest::Reporter* reporter) { |  | 
| 7     static const struct { |  | 
| 8         SkBitmap::Config    fConfig; |  | 
| 9         SkAlphaType         fAlphaType; |  | 
| 10         SkColorType         fExpectedColorType; |  | 
| 11         bool                fExpectedSuccess; |  | 
| 12     } gRec[] = { |  | 
| 13         { SkBitmap::kNo_Config,         kPremul_SkAlphaType,    kPMColor_SkColor
    Type,   false }, |  | 
| 14         { SkBitmap::kARGB_8888_Config,  kPremul_SkAlphaType,    kPMColor_SkColor
    Type,   true }, |  | 
| 15         { SkBitmap::kARGB_8888_Config,  kOpaque_SkAlphaType,    kPMColor_SkColor
    Type,   true }, |  | 
| 16         { SkBitmap::kRGB_565_Config,    kOpaque_SkAlphaType,    kRGB_565_SkColor
    Type,   true }, |  | 
| 17         { SkBitmap::kARGB_4444_Config,  kPremul_SkAlphaType,    kARGB_4444_SkCol
    orType, true }, |  | 
| 18         { SkBitmap::kARGB_4444_Config,  kOpaque_SkAlphaType,    kARGB_4444_SkCol
    orType, true }, |  | 
| 19         { SkBitmap::kA8_Config,         kPremul_SkAlphaType,    kAlpha_8_SkColor
    Type,   true }, |  | 
| 20         { SkBitmap::kA8_Config,         kOpaque_SkAlphaType,    kAlpha_8_SkColor
    Type,   true }, |  | 
| 21         { SkBitmap::kIndex8_Config,     kPremul_SkAlphaType,    kIndex_8_SkColor
    Type,   true }, |  | 
| 22         { SkBitmap::kIndex8_Config,     kOpaque_SkAlphaType,    kIndex_8_SkColor
    Type,   true }, |  | 
| 23     }; |  | 
| 24 |  | 
| 25     SkBitmap bitmap; |  | 
| 26     SkImageInfo info; |  | 
| 27 |  | 
| 28     for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { |  | 
| 29         bool success = bitmap.setConfig(gRec[i].fConfig, 10, 10, 0, gRec[i].fAlp
    haType); |  | 
| 30         REPORTER_ASSERT(reporter, success); |  | 
| 31         success = bitmap.asImageInfo(&info); |  | 
| 32         REPORTER_ASSERT(reporter, success == gRec[i].fExpectedSuccess); |  | 
| 33         if (success && gRec[i].fExpectedSuccess) { |  | 
| 34             REPORTER_ASSERT(reporter, info.fAlphaType == gRec[i].fAlphaType); |  | 
| 35             REPORTER_ASSERT(reporter, info.fColorType == gRec[i].fExpectedColorT
    ype); |  | 
| 36         } |  | 
| 37     } |  | 
| 38 } |  | 
| 39 |  | 
| 40 class TestListener : public SkPixelRef::GenIDChangeListener { | 6 class TestListener : public SkPixelRef::GenIDChangeListener { | 
| 41 public: | 7 public: | 
| 42     explicit TestListener(int* ptr) : fPtr(ptr) {} | 8     explicit TestListener(int* ptr) : fPtr(ptr) {} | 
| 43     virtual void onChange() SK_OVERRIDE { (*fPtr)++; } | 9     virtual void onChange() SK_OVERRIDE { (*fPtr)++; } | 
| 44 private: | 10 private: | 
| 45     int* fPtr; | 11     int* fPtr; | 
| 46 }; | 12 }; | 
| 47 | 13 | 
| 48 DEF_TEST(PixelRef_GenIDChange, r) { | 14 DEF_TEST(PixelRef_GenIDChange, r) { | 
| 49     SkImageInfo info = SkImageInfo::MakeN32Premul(10, 10); | 15     SkImageInfo info = SkImageInfo::MakeN32Premul(10, 10); | 
| (...skipping 20 matching lines...) Expand all  Loading... | 
| 70     // Force the generation ID to be recalculated, then add a listener. | 36     // Force the generation ID to be recalculated, then add a listener. | 
| 71     REPORTER_ASSERT(r, 0 != pixelRef->getGenerationID()); | 37     REPORTER_ASSERT(r, 0 != pixelRef->getGenerationID()); | 
| 72     pixelRef->addGenIDChangeListener(SkNEW_ARGS(TestListener, (&count))); | 38     pixelRef->addGenIDChangeListener(SkNEW_ARGS(TestListener, (&count))); | 
| 73     pixelRef->notifyPixelsChanged(); | 39     pixelRef->notifyPixelsChanged(); | 
| 74     REPORTER_ASSERT(r, 1 == count); | 40     REPORTER_ASSERT(r, 1 == count); | 
| 75 | 41 | 
| 76     // Quick check that NULL is safe. | 42     // Quick check that NULL is safe. | 
| 77     REPORTER_ASSERT(r, 0 != pixelRef->getGenerationID()); | 43     REPORTER_ASSERT(r, 0 != pixelRef->getGenerationID()); | 
| 78     pixelRef->addGenIDChangeListener(NULL); | 44     pixelRef->addGenIDChangeListener(NULL); | 
| 79     pixelRef->notifyPixelsChanged(); | 45     pixelRef->notifyPixelsChanged(); | 
| 80 |  | 
| 81     test_info(r); |  | 
| 82 } | 46 } | 
| OLD | NEW | 
|---|