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