OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkBitmap.h" | 8 #include "SkBitmap.h" |
9 #include "SkCachingPixelRef.h" | 9 #include "SkCachingPixelRef.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 REPORTER_ASSERT(reporter, b1.empty() == b2.empty()); | 56 REPORTER_ASSERT(reporter, b1.empty() == b2.empty()); |
57 REPORTER_ASSERT(reporter, b1.width() == b2.width()); | 57 REPORTER_ASSERT(reporter, b1.width() == b2.width()); |
58 REPORTER_ASSERT(reporter, b1.height() == b2.height()); | 58 REPORTER_ASSERT(reporter, b1.height() == b2.height()); |
59 REPORTER_ASSERT(reporter, b1.isNull() == b2.isNull()); | 59 REPORTER_ASSERT(reporter, b1.isNull() == b2.isNull()); |
60 SkAutoLockPixels autoLockPixels1(b1); | 60 SkAutoLockPixels autoLockPixels1(b1); |
61 SkAutoLockPixels autoLockPixels2(b2); | 61 SkAutoLockPixels autoLockPixels2(b2); |
62 REPORTER_ASSERT(reporter, b1.isNull() == b2.isNull()); | 62 REPORTER_ASSERT(reporter, b1.isNull() == b2.isNull()); |
63 if (b1.isNull() || b1.empty()) { | 63 if (b1.isNull() || b1.empty()) { |
64 return; | 64 return; |
65 } | 65 } |
66 REPORTER_ASSERT(reporter, NULL != b1.getPixels()); | 66 REPORTER_ASSERT(reporter, b1.getPixels()); |
67 REPORTER_ASSERT(reporter, NULL != b2.getPixels()); | 67 REPORTER_ASSERT(reporter, b2.getPixels()); |
68 if ((!(b1.getPixels())) || (!(b2.getPixels()))) { | 68 if ((!(b1.getPixels())) || (!(b2.getPixels()))) { |
69 return; | 69 return; |
70 } | 70 } |
71 if ((b1.width() != b2.width()) || | 71 if ((b1.width() != b2.width()) || |
72 (b1.height() != b2.height())) { | 72 (b1.height() != b2.height())) { |
73 return; | 73 return; |
74 } | 74 } |
75 if (!pixelPerfect) { | 75 if (!pixelPerfect) { |
76 return; | 76 return; |
77 } | 77 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 } | 115 } |
116 SkBitmap lazy; | 116 SkBitmap lazy; |
117 bool installSuccess = install(encoded.get(), &lazy); | 117 bool installSuccess = install(encoded.get(), &lazy); |
118 REPORTER_ASSERT(reporter, installSuccess); | 118 REPORTER_ASSERT(reporter, installSuccess); |
119 if (!installSuccess) { | 119 if (!installSuccess) { |
120 continue; | 120 continue; |
121 } | 121 } |
122 REPORTER_ASSERT(reporter, NULL == lazy.getPixels()); | 122 REPORTER_ASSERT(reporter, NULL == lazy.getPixels()); |
123 { | 123 { |
124 SkAutoLockPixels autoLockPixels(lazy); // now pixels are good. | 124 SkAutoLockPixels autoLockPixels(lazy); // now pixels are good. |
125 REPORTER_ASSERT(reporter, NULL != lazy.getPixels()); | 125 REPORTER_ASSERT(reporter, lazy.getPixels()); |
126 if (NULL == lazy.getPixels()) { | 126 if (NULL == lazy.getPixels()) { |
127 continue; | 127 continue; |
128 } | 128 } |
129 } | 129 } |
130 // pixels should be gone! | 130 // pixels should be gone! |
131 REPORTER_ASSERT(reporter, NULL == lazy.getPixels()); | 131 REPORTER_ASSERT(reporter, NULL == lazy.getPixels()); |
132 { | 132 { |
133 SkAutoLockPixels autoLockPixels(lazy); // now pixels are good. | 133 SkAutoLockPixels autoLockPixels(lazy); // now pixels are good. |
134 REPORTER_ASSERT(reporter, NULL != lazy.getPixels()); | 134 REPORTER_ASSERT(reporter, lazy.getPixels()); |
135 if (NULL == lazy.getPixels()) { | 135 if (NULL == lazy.getPixels()) { |
136 continue; | 136 continue; |
137 } | 137 } |
138 } | 138 } |
139 bool comparePixels = (SkImageEncoder::kPNG_Type == type); | 139 bool comparePixels = (SkImageEncoder::kPNG_Type == type); |
140 compare_bitmaps(reporter, original, lazy, comparePixels); | 140 compare_bitmaps(reporter, original, lazy, comparePixels); |
141 } | 141 } |
142 } | 142 } |
143 | 143 |
144 //////////////////////////////////////////////////////////////////////////////// | 144 //////////////////////////////////////////////////////////////////////////////// |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 static int Height() { return 10; } | 177 static int Height() { return 10; } |
178 static uint32_t Color() { return 0xff123456; } | 178 static uint32_t Color() { return 0xff123456; } |
179 TestImageGenerator(TestType type, skiatest::Reporter* reporter) | 179 TestImageGenerator(TestType type, skiatest::Reporter* reporter) |
180 : fType(type), fReporter(reporter) { | 180 : fType(type), fReporter(reporter) { |
181 SkASSERT((fType <= kLast_TestType) && (fType >= 0)); | 181 SkASSERT((fType <= kLast_TestType) && (fType >= 0)); |
182 } | 182 } |
183 virtual ~TestImageGenerator() { } | 183 virtual ~TestImageGenerator() { } |
184 | 184 |
185 protected: | 185 protected: |
186 virtual bool onGetInfo(SkImageInfo* info) SK_OVERRIDE { | 186 virtual bool onGetInfo(SkImageInfo* info) SK_OVERRIDE { |
187 REPORTER_ASSERT(fReporter, NULL != info); | 187 REPORTER_ASSERT(fReporter, info); |
188 if ((NULL == info) || (kFailGetInfo_TestType == fType)) { | 188 if ((NULL == info) || (kFailGetInfo_TestType == fType)) { |
189 return false; | 189 return false; |
190 } | 190 } |
191 *info = SkImageInfo::MakeN32(TestImageGenerator::Width(), | 191 *info = SkImageInfo::MakeN32(TestImageGenerator::Width(), |
192 TestImageGenerator::Height(), | 192 TestImageGenerator::Height(), |
193 kOpaque_SkAlphaType); | 193 kOpaque_SkAlphaType); |
194 return true; | 194 return true; |
195 } | 195 } |
196 | 196 |
197 virtual bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBy
tes, | 197 virtual bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBy
tes, |
(...skipping 18 matching lines...) Expand all Loading... |
216 private: | 216 private: |
217 const TestType fType; | 217 const TestType fType; |
218 skiatest::Reporter* const fReporter; | 218 skiatest::Reporter* const fReporter; |
219 }; | 219 }; |
220 | 220 |
221 static void check_test_image_generator_bitmap(skiatest::Reporter* reporter, | 221 static void check_test_image_generator_bitmap(skiatest::Reporter* reporter, |
222 const SkBitmap& bm) { | 222 const SkBitmap& bm) { |
223 REPORTER_ASSERT(reporter, TestImageGenerator::Width() == bm.width()); | 223 REPORTER_ASSERT(reporter, TestImageGenerator::Width() == bm.width()); |
224 REPORTER_ASSERT(reporter, TestImageGenerator::Height() == bm.height()); | 224 REPORTER_ASSERT(reporter, TestImageGenerator::Height() == bm.height()); |
225 SkAutoLockPixels autoLockPixels(bm); | 225 SkAutoLockPixels autoLockPixels(bm); |
226 REPORTER_ASSERT(reporter, NULL != bm.getPixels()); | 226 REPORTER_ASSERT(reporter, bm.getPixels()); |
227 if (NULL == bm.getPixels()) { | 227 if (NULL == bm.getPixels()) { |
228 return; | 228 return; |
229 } | 229 } |
230 int errors = 0; | 230 int errors = 0; |
231 for (int y = 0; y < bm.height(); ++y) { | 231 for (int y = 0; y < bm.height(); ++y) { |
232 for (int x = 0; x < bm.width(); ++x) { | 232 for (int x = 0; x < bm.width(); ++x) { |
233 if (TestImageGenerator::Color() != *bm.getAddr32(x, y)) { | 233 if (TestImageGenerator::Color() != *bm.getAddr32(x, y)) { |
234 ++errors; | 234 ++errors; |
235 } | 235 } |
236 } | 236 } |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 canvas.clear(kDefaultColor); | 352 canvas.clear(kDefaultColor); |
353 image->draw(&canvas, 0, 0, NULL); | 353 image->draw(&canvas, 0, 0, NULL); |
354 if (TestImageGenerator::kSucceedGetPixels_TestType == test) { | 354 if (TestImageGenerator::kSucceedGetPixels_TestType == test) { |
355 REPORTER_ASSERT( | 355 REPORTER_ASSERT( |
356 r, TestImageGenerator::Color() == *bitmap.getAddr32(0, 0)); | 356 r, TestImageGenerator::Color() == *bitmap.getAddr32(0, 0)); |
357 } else { | 357 } else { |
358 REPORTER_ASSERT(r, kDefaultColor == bitmap.getColor(0,0)); | 358 REPORTER_ASSERT(r, kDefaultColor == bitmap.getColor(0,0)); |
359 } | 359 } |
360 } | 360 } |
361 } | 361 } |
OLD | NEW |