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

Side by Side Diff: tests/CachedDecodingPixelRefTest.cpp

Issue 132403008: Remove unnamed namespace usage from tests/ (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 11 months 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
« no previous file with comments | « no previous file | tests/DrawBitmapRectTest.cpp » ('j') | tests/DrawBitmapRectTest.cpp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkData.h" 10 #include "SkData.h"
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 /** 160 /**
161 * This checks to see that a SkCachingPixelRef and a 161 * This checks to see that a SkCachingPixelRef and a
162 * SkDiscardablePixelRef works as advertised with a 162 * SkDiscardablePixelRef works as advertised with a
163 * SkDecodingImageGenerator. 163 * SkDecodingImageGenerator.
164 */ 164 */
165 DEF_TEST(DecodingImageGenerator, reporter) { 165 DEF_TEST(DecodingImageGenerator, reporter) {
166 test_three_encodings(reporter, install_skCachingPixelRef); 166 test_three_encodings(reporter, install_skCachingPixelRef);
167 test_three_encodings(reporter, install_skDiscardablePixelRef); 167 test_three_encodings(reporter, install_skDiscardablePixelRef);
168 } 168 }
169 169
170 ////////////////////////////////////////////////////////////////////////////////
171 namespace {
172 class TestImageGenerator : public SkImageGenerator { 170 class TestImageGenerator : public SkImageGenerator {
173 public: 171 public:
174 enum TestType { 172 enum TestType {
175 kFailGetInfo_TestType, 173 kFailGetInfo_TestType,
176 kFailGetPixels_TestType, 174 kFailGetPixels_TestType,
177 kSucceedGetPixels_TestType, 175 kSucceedGetPixels_TestType,
178 kLast_TestType = kSucceedGetPixels_TestType 176 kLast_TestType = kSucceedGetPixels_TestType
179 }; 177 };
180 static int Width() { return 10; } 178 static int Width() { return 10; }
181 static int Height() { return 10; } 179 static int Height() { return 10; }
182 static SkColor Color() { return SK_ColorCYAN; } 180 static SkColor Color() { return SK_ColorCYAN; }
183 TestImageGenerator(TestType type, skiatest::Reporter* reporter) 181 TestImageGenerator(TestType type, skiatest::Reporter* reporter)
184 : fType(type), fReporter(reporter) { 182 : fType(type), fReporter(reporter) {
185 SkASSERT((fType <= kLast_TestType) && (fType >= 0)); 183 SkASSERT((fType <= kLast_TestType) && (fType >= 0));
186 } 184 }
robertphillips 2014/01/14 13:19:37 virtual?
tfarina 2014/01/21 23:37:43 Done.
187 ~TestImageGenerator() { } 185 ~TestImageGenerator() { }
robertphillips 2014/01/14 13:19:37 virtual?
tfarina 2014/01/21 23:37:43 Done.
188 bool getInfo(SkImageInfo* info) SK_OVERRIDE { 186 bool getInfo(SkImageInfo* info) SK_OVERRIDE {
189 REPORTER_ASSERT(fReporter, NULL != info); 187 REPORTER_ASSERT(fReporter, NULL != info);
190 if ((NULL == info) || (kFailGetInfo_TestType == fType)) { 188 if ((NULL == info) || (kFailGetInfo_TestType == fType)) {
191 return false; 189 return false;
192 } 190 }
193 info->fWidth = TestImageGenerator::Width(); 191 info->fWidth = TestImageGenerator::Width();
194 info->fHeight = TestImageGenerator::Height(); 192 info->fHeight = TestImageGenerator::Height();
195 info->fColorType = kPMColor_SkColorType; 193 info->fColorType = kPMColor_SkColorType;
196 info->fAlphaType = kOpaque_SkAlphaType; 194 info->fAlphaType = kOpaque_SkAlphaType;
197 return true; 195 return true;
198 } 196 }
robertphillips 2014/01/14 13:19:37 virtual?
tfarina 2014/01/21 23:37:43 Done.
199 bool getPixels(const SkImageInfo& info, 197 bool getPixels(const SkImageInfo& info,
200 void* pixels, 198 void* pixels,
201 size_t rowBytes) SK_OVERRIDE { 199 size_t rowBytes) SK_OVERRIDE {
202 REPORTER_ASSERT(fReporter, pixels != NULL); 200 REPORTER_ASSERT(fReporter, pixels != NULL);
203 size_t minRowBytes 201 size_t minRowBytes
204 = static_cast<size_t>(info.fWidth * info.bytesPerPixel()); 202 = static_cast<size_t>(info.fWidth * info.bytesPerPixel());
205 REPORTER_ASSERT(fReporter, rowBytes >= minRowBytes); 203 REPORTER_ASSERT(fReporter, rowBytes >= minRowBytes);
206 if ((NULL == pixels) 204 if ((NULL == pixels)
207 || (fType != kSucceedGetPixels_TestType) 205 || (fType != kSucceedGetPixels_TestType)
208 || (info.fColorType != kPMColor_SkColorType)) { 206 || (info.fColorType != kPMColor_SkColorType)) {
209 return false; 207 return false;
210 } 208 }
211 char* bytePtr = static_cast<char*>(pixels); 209 char* bytePtr = static_cast<char*>(pixels);
212 for (int y = 0; y < info.fHeight; ++y) { 210 for (int y = 0; y < info.fHeight; ++y) {
213 sk_memset32(reinterpret_cast<SkColor*>(bytePtr), 211 sk_memset32(reinterpret_cast<SkColor*>(bytePtr),
214 TestImageGenerator::Color(), info.fWidth); 212 TestImageGenerator::Color(), info.fWidth);
215 bytePtr += rowBytes; 213 bytePtr += rowBytes;
216 } 214 }
217 return true; 215 return true;
218 } 216 }
219 217
220 private: 218 private:
221 const TestType fType; 219 const TestType fType;
222 skiatest::Reporter* const fReporter; 220 skiatest::Reporter* const fReporter;
223 }; 221 };
224 222
robertphillips 2014/01/14 13:19:37 check_test_image_generator_bitmap?
tfarina 2014/01/21 23:37:43 Done.
225 void CheckTestImageGeneratorBitmap(skiatest::Reporter* reporter, 223 static void CheckTestImageGeneratorBitmap(skiatest::Reporter* reporter,
226 const SkBitmap& bm) { 224 const SkBitmap& bm) {
227 REPORTER_ASSERT(reporter, TestImageGenerator::Width() == bm.width()); 225 REPORTER_ASSERT(reporter, TestImageGenerator::Width() == bm.width());
228 REPORTER_ASSERT(reporter, TestImageGenerator::Height() == bm.height()); 226 REPORTER_ASSERT(reporter, TestImageGenerator::Height() == bm.height());
229 SkAutoLockPixels autoLockPixels(bm); 227 SkAutoLockPixels autoLockPixels(bm);
230 REPORTER_ASSERT(reporter, NULL != bm.getPixels()); 228 REPORTER_ASSERT(reporter, NULL != bm.getPixels());
231 if (NULL == bm.getPixels()) { 229 if (NULL == bm.getPixels()) {
232 return; 230 return;
233 } 231 }
234 int errors = 0; 232 int errors = 0;
235 for (int y = 0; y < bm.height(); ++y) { 233 for (int y = 0; y < bm.height(); ++y) {
236 for (int x = 0; x < bm.width(); ++x) { 234 for (int x = 0; x < bm.width(); ++x) {
237 if (TestImageGenerator::Color() != *bm.getAddr32(x, y)) { 235 if (TestImageGenerator::Color() != *bm.getAddr32(x, y)) {
238 ++errors; 236 ++errors;
239 } 237 }
240 } 238 }
241 } 239 }
242 REPORTER_ASSERT(reporter, 0 == errors); 240 REPORTER_ASSERT(reporter, 0 == errors);
243 } 241 }
244 242
245 enum PixelRefType { 243 enum PixelRefType {
246 kSkCaching_PixelRefType, 244 kSkCaching_PixelRefType,
247 kSkDiscardable_PixelRefType, 245 kSkDiscardable_PixelRefType,
248 kLast_PixelRefType = kSkDiscardable_PixelRefType 246 kLast_PixelRefType = kSkDiscardable_PixelRefType
249 }; 247 };
250 void CheckPixelRef(TestImageGenerator::TestType type, 248
robertphillips 2014/01/14 13:19:37 check_pixelref?
tfarina 2014/01/21 23:37:43 Done.
251 skiatest::Reporter* reporter, 249 static void CheckPixelRef(TestImageGenerator::TestType type,
252 PixelRefType pixelRefType, 250 skiatest::Reporter* reporter,
253 SkDiscardableMemory::Factory* factory) { 251 PixelRefType pixelRefType,
252 SkDiscardableMemory::Factory* factory) {
254 SkASSERT((pixelRefType >= 0) && (pixelRefType <= kLast_PixelRefType)); 253 SkASSERT((pixelRefType >= 0) && (pixelRefType <= kLast_PixelRefType));
255 SkAutoTDelete<SkImageGenerator> gen(SkNEW_ARGS(TestImageGenerator, 254 SkAutoTDelete<SkImageGenerator> gen(SkNEW_ARGS(TestImageGenerator,
256 (type, reporter))); 255 (type, reporter)));
257 REPORTER_ASSERT(reporter, gen.get() != NULL); 256 REPORTER_ASSERT(reporter, gen.get() != NULL);
258 SkBitmap lazy; 257 SkBitmap lazy;
259 bool success; 258 bool success;
260 if (kSkCaching_PixelRefType == pixelRefType) { 259 if (kSkCaching_PixelRefType == pixelRefType) {
261 // Ignore factory; use global SkScaledImageCache. 260 // Ignore factory; use global SkScaledImageCache.
262 success = SkCachingPixelRef::Install(gen.detach(), &lazy); 261 success = SkCachingPixelRef::Install(gen.detach(), &lazy);
263 } else { 262 } else {
264 success = SkInstallDiscardablePixelRef(gen.detach(), &lazy, factory); 263 success = SkInstallDiscardablePixelRef(gen.detach(), &lazy, factory);
265 } 264 }
266 REPORTER_ASSERT(reporter, success 265 REPORTER_ASSERT(reporter, success
267 == (TestImageGenerator::kFailGetInfo_TestType != type)); 266 == (TestImageGenerator::kFailGetInfo_TestType != type));
268 if (TestImageGenerator::kSucceedGetPixels_TestType == type) { 267 if (TestImageGenerator::kSucceedGetPixels_TestType == type) {
269 CheckTestImageGeneratorBitmap(reporter, lazy); 268 CheckTestImageGeneratorBitmap(reporter, lazy);
270 } else if (TestImageGenerator::kFailGetPixels_TestType == type) { 269 } else if (TestImageGenerator::kFailGetPixels_TestType == type) {
271 SkAutoLockPixels autoLockPixels(lazy); 270 SkAutoLockPixels autoLockPixels(lazy);
272 REPORTER_ASSERT(reporter, NULL == lazy.getPixels()); 271 REPORTER_ASSERT(reporter, NULL == lazy.getPixels());
273 } 272 }
274 } 273 }
275 } // namespace
276 274
277 // new/lock/delete is an odd pattern for a pixelref, but it needs to not assert 275 // new/lock/delete is an odd pattern for a pixelref, but it needs to not assert
278 static void test_newlockdelete(skiatest::Reporter* reporter) { 276 static void test_newlockdelete(skiatest::Reporter* reporter) {
279 SkBitmap bm; 277 SkBitmap bm;
280 SkImageGenerator* ig = new TestImageGenerator( 278 SkImageGenerator* ig = new TestImageGenerator(
281 TestImageGenerator::kSucceedGetPixels_TestType, 279 TestImageGenerator::kSucceedGetPixels_TestType, reporter);
282 reporter);
283 SkInstallDiscardablePixelRef(ig, &bm, NULL); 280 SkInstallDiscardablePixelRef(ig, &bm, NULL);
284 bm.pixelRef()->lockPixels(); 281 bm.pixelRef()->lockPixels();
285 } 282 }
286 283
287 /** 284 /**
288 * This tests the basic functionality of SkDiscardablePixelRef with a 285 * This tests the basic functionality of SkDiscardablePixelRef with a
289 * basic SkImageGenerator implementation and several 286 * basic SkImageGenerator implementation and several
290 * SkDiscardableMemory::Factory choices. 287 * SkDiscardableMemory::Factory choices.
291 */ 288 */
292 DEF_TEST(DiscardableAndCachingPixelRef, reporter) { 289 DEF_TEST(DiscardableAndCachingPixelRef, reporter) {
(...skipping 25 matching lines...) Expand all
318 315
319 SkDiscardableMemoryPool* globalPool = SkGetGlobalDiscardableMemoryPool(); 316 SkDiscardableMemoryPool* globalPool = SkGetGlobalDiscardableMemoryPool();
320 // Only acts differently from NULL on a platform that has a 317 // Only acts differently from NULL on a platform that has a
321 // default discardable memory implementation that differs from the 318 // default discardable memory implementation that differs from the
322 // global DM pool. 319 // global DM pool.
323 CheckPixelRef(TestImageGenerator::kFailGetPixels_TestType, 320 CheckPixelRef(TestImageGenerator::kFailGetPixels_TestType,
324 reporter, kSkDiscardable_PixelRefType, globalPool); 321 reporter, kSkDiscardable_PixelRefType, globalPool);
325 CheckPixelRef(TestImageGenerator::kSucceedGetPixels_TestType, 322 CheckPixelRef(TestImageGenerator::kSucceedGetPixels_TestType,
326 reporter, kSkDiscardable_PixelRefType, globalPool); 323 reporter, kSkDiscardable_PixelRefType, globalPool);
327 } 324 }
328 ////////////////////////////////////////////////////////////////////////////////
OLDNEW
« no previous file with comments | « no previous file | tests/DrawBitmapRectTest.cpp » ('j') | tests/DrawBitmapRectTest.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698