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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/image/SkImage_Raster.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/CachedDecodingPixelRefTest.cpp
diff --git a/tests/CachedDecodingPixelRefTest.cpp b/tests/CachedDecodingPixelRefTest.cpp
index 8de7da79a252e54404cd64457dee387234b70f32..e9ee62276410bf1692133ef5ddf2d7b27ef92b83 100644
--- a/tests/CachedDecodingPixelRefTest.cpp
+++ b/tests/CachedDecodingPixelRefTest.cpp
@@ -175,7 +175,7 @@ public:
};
static int Width() { return 10; }
static int Height() { return 10; }
- static SkColor Color() { return SK_ColorCYAN; }
+ static uint32_t Color() { return 0xff123456; }
TestImageGenerator(TestType type, skiatest::Reporter* reporter)
: fType(type), fReporter(reporter) {
SkASSERT((fType <= kLast_TestType) && (fType >= 0));
@@ -322,3 +322,43 @@ DEF_TEST(DiscardableAndCachingPixelRef, reporter) {
check_pixelref(TestImageGenerator::kSucceedGetPixels_TestType,
reporter, kSkDiscardable_PixelRefType, globalPool);
}
+
+////////////////////////////////////////////////////////////////////////////////
+
+DEF_TEST(Image_NewFromGenerator, r) {
+ TestImageGenerator::TestType testTypes[] = {
+ TestImageGenerator::kFailGetInfo_TestType,
+ TestImageGenerator::kFailGetPixels_TestType,
+ TestImageGenerator::kSucceedGetPixels_TestType,
+ };
+ for (size_t i = 0; i < SK_ARRAY_COUNT(testTypes); ++i) {
+ TestImageGenerator::TestType test = testTypes[i];
+ SkImageGenerator* gen = SkNEW_ARGS(TestImageGenerator, (test, r));
+ SkAutoTUnref<SkImage> image(SkImage::NewFromGenerator(gen));
+ if (TestImageGenerator::kFailGetInfo_TestType == test) {
+ REPORTER_ASSERT(r, NULL == image.get());
+ continue;
+ }
+ if (NULL == image.get()) {
+ ERRORF(r, "SkImage::NewFromGenerator unexpecedly failed ["
+ SK_SIZE_T_SPECIFIER "]", i);
+ continue;
+ }
+ REPORTER_ASSERT(r, TestImageGenerator::Width() == image->width());
+ REPORTER_ASSERT(r, TestImageGenerator::Height() == image->height());
+
+ SkBitmap bitmap;
+ SkAssertResult(bitmap.allocN32Pixels(TestImageGenerator::Width(),
+ TestImageGenerator::Height()));
+ SkCanvas canvas(bitmap);
+ const SkColor kDefaultColor = 0xffabcdef;
+ canvas.clear(kDefaultColor);
+ image->draw(&canvas, 0, 0, NULL);
+ if (TestImageGenerator::kSucceedGetPixels_TestType == test) {
+ REPORTER_ASSERT(
+ r, TestImageGenerator::Color() == *bitmap.getAddr32(0, 0));
+ } else {
+ REPORTER_ASSERT(r, kDefaultColor == bitmap.getColor(0,0));
+ }
+ }
+}
« 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