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

Side by Side Diff: tests/CachedDecodingPixelRefTest.cpp

Issue 465823003: SkImage::NewFromGenerator(SkImageGenerator*), and a unit test. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix ARGB/AGBR byte order bug (edit) Created 6 years, 4 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
« no previous file with comments | « src/image/SkImage_Raster.cpp ('k') | no next file » | no next file with comments »
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 "SkCachingPixelRef.h" 9 #include "SkCachingPixelRef.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 class TestImageGenerator : public SkImageGenerator { 168 class TestImageGenerator : public SkImageGenerator {
169 public: 169 public:
170 enum TestType { 170 enum TestType {
171 kFailGetInfo_TestType, 171 kFailGetInfo_TestType,
172 kFailGetPixels_TestType, 172 kFailGetPixels_TestType,
173 kSucceedGetPixels_TestType, 173 kSucceedGetPixels_TestType,
174 kLast_TestType = kSucceedGetPixels_TestType 174 kLast_TestType = kSucceedGetPixels_TestType
175 }; 175 };
176 static int Width() { return 10; } 176 static int Width() { return 10; }
177 static int Height() { return 10; } 177 static int Height() { return 10; }
178 static SkColor Color() { return SK_ColorCYAN; } 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, NULL != info);
188 if ((NULL == info) || (kFailGetInfo_TestType == fType)) { 188 if ((NULL == info) || (kFailGetInfo_TestType == fType)) {
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 315
316 SkDiscardableMemoryPool* globalPool = SkGetGlobalDiscardableMemoryPool(); 316 SkDiscardableMemoryPool* globalPool = SkGetGlobalDiscardableMemoryPool();
317 // Only acts differently from NULL on a platform that has a 317 // Only acts differently from NULL on a platform that has a
318 // default discardable memory implementation that differs from the 318 // default discardable memory implementation that differs from the
319 // global DM pool. 319 // global DM pool.
320 check_pixelref(TestImageGenerator::kFailGetPixels_TestType, 320 check_pixelref(TestImageGenerator::kFailGetPixels_TestType,
321 reporter, kSkDiscardable_PixelRefType, globalPool); 321 reporter, kSkDiscardable_PixelRefType, globalPool);
322 check_pixelref(TestImageGenerator::kSucceedGetPixels_TestType, 322 check_pixelref(TestImageGenerator::kSucceedGetPixels_TestType,
323 reporter, kSkDiscardable_PixelRefType, globalPool); 323 reporter, kSkDiscardable_PixelRefType, globalPool);
324 } 324 }
325
326 ////////////////////////////////////////////////////////////////////////////////
327
328 DEF_TEST(Image_NewFromGenerator, r) {
329 TestImageGenerator::TestType testTypes[] = {
330 TestImageGenerator::kFailGetInfo_TestType,
331 TestImageGenerator::kFailGetPixels_TestType,
332 TestImageGenerator::kSucceedGetPixels_TestType,
333 };
334 for (size_t i = 0; i < SK_ARRAY_COUNT(testTypes); ++i) {
335 TestImageGenerator::TestType test = testTypes[i];
336 SkImageGenerator* gen = SkNEW_ARGS(TestImageGenerator, (test, r));
337 SkAutoTUnref<SkImage> image(SkImage::NewFromGenerator(gen));
338 if (TestImageGenerator::kFailGetInfo_TestType == test) {
339 REPORTER_ASSERT(r, NULL == image.get());
340 continue;
341 }
342 if (NULL == image.get()) {
343 ERRORF(r, "SkImage::NewFromGenerator unexpecedly failed ["
344 SK_SIZE_T_SPECIFIER "]", i);
345 continue;
346 }
347 REPORTER_ASSERT(r, TestImageGenerator::Width() == image->width());
348 REPORTER_ASSERT(r, TestImageGenerator::Height() == image->height());
349
350 SkBitmap bitmap;
351 SkAssertResult(bitmap.allocN32Pixels(TestImageGenerator::Width(),
352 TestImageGenerator::Height()));
353 SkCanvas canvas(bitmap);
354 const SkColor kDefaultColor = 0xffabcdef;
355 canvas.clear(kDefaultColor);
356 image->draw(&canvas, 0, 0, NULL);
357 if (TestImageGenerator::kSucceedGetPixels_TestType == test) {
358 REPORTER_ASSERT(
359 r, TestImageGenerator::Color() == *bitmap.getAddr32(0, 0));
360 } else {
361 REPORTER_ASSERT(r, kDefaultColor == bitmap.getColor(0,0));
362 }
363 }
364 }
OLDNEW
« no previous file with comments | « src/image/SkImage_Raster.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698