Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Side by Side Diff: tests/PixelRefTest.cpp

Issue 108663004: make info real in SkPixelRef, and add bitmap::asImageInfo (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 },
scroggo 2013/12/09 21:33:41 Why isn't kIndex8_Config tested here?
reed1 2013/12/09 21:46:14 Done.
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 };
23
24 SkBitmap bitmap;
25 SkImageInfo info;
26
27 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
28 bool success = bitmap.setConfig(gRec[i].fConfig, 10, 10, 0, gRec[i].fAlp haType);
29 REPORTER_ASSERT(reporter, success);
30 success = bitmap.asImageInfo(&info);
31 REPORTER_ASSERT(reporter, success == gRec[i].fExpectedSuccess);
32 if (gRec[i].fExpectedSuccess) {
33 REPORTER_ASSERT(reporter, info.fAlphaType == gRec[i].fAlphaType);
34 REPORTER_ASSERT(reporter, info.fColorType == gRec[i].fExpectedColorT ype);
35 }
36 }
37 }
38
7 namespace { 39 namespace {
8 40
9 class TestListener : public SkPixelRef::GenIDChangeListener { 41 class TestListener : public SkPixelRef::GenIDChangeListener {
10 public: 42 public:
11 explicit TestListener(int* ptr) : fPtr(ptr) {} 43 explicit TestListener(int* ptr) : fPtr(ptr) {}
12 void onChange() SK_OVERRIDE { (*fPtr)++; } 44 void onChange() SK_OVERRIDE { (*fPtr)++; }
13 private: 45 private:
14 int* fPtr; 46 int* fPtr;
15 }; 47 };
16 48
(...skipping 22 matching lines...) Expand all
39 // Force the generation ID to be recalculated, then add a listener. 71 // Force the generation ID to be recalculated, then add a listener.
40 REPORTER_ASSERT(r, 0 != pixelRef.getGenerationID()); 72 REPORTER_ASSERT(r, 0 != pixelRef.getGenerationID());
41 pixelRef.addGenIDChangeListener(SkNEW_ARGS(TestListener, (&count))); 73 pixelRef.addGenIDChangeListener(SkNEW_ARGS(TestListener, (&count)));
42 pixelRef.notifyPixelsChanged(); 74 pixelRef.notifyPixelsChanged();
43 REPORTER_ASSERT(r, 1 == count); 75 REPORTER_ASSERT(r, 1 == count);
44 76
45 // Quick check that NULL is safe. 77 // Quick check that NULL is safe.
46 REPORTER_ASSERT(r, 0 != pixelRef.getGenerationID()); 78 REPORTER_ASSERT(r, 0 != pixelRef.getGenerationID());
47 pixelRef.addGenIDChangeListener(NULL); 79 pixelRef.addGenIDChangeListener(NULL);
48 pixelRef.notifyPixelsChanged(); 80 pixelRef.notifyPixelsChanged();
81
82 test_info(r);
49 } 83 }
OLDNEW
« src/image/SkImagePriv.h ('K') | « src/images/SkDecodingImageGenerator.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698