diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/ImageTest.cpp | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp index bd39779d8b..f646a386d9 100644 --- a/tests/ImageTest.cpp +++ b/tests/ImageTest.cpp @@ -6,6 +6,7 @@ */ #include <functional> +#include <initializer_list> #include "DMGpuSupport.h" #include "SkBitmap.h" @@ -64,6 +65,31 @@ static SkImage* create_image() { draw_image_test_pattern(surface->getCanvas()); return surface->newImageSnapshot(); } +#if 0 +static SkImage* create_image_565() { + const SkImageInfo info = SkImageInfo::Make(20, 20, kRGB_565_SkColorType, kOpaque_SkAlphaType); + SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info)); + draw_image_test_pattern(surface->getCanvas()); + return surface->newImageSnapshot(); +} +#endif +static SkImage* create_image_ct() { + SkPMColor colors[] = { + SkPreMultiplyARGB(0xFF, 0xFF, 0xFF, 0x00), + SkPreMultiplyARGB(0x80, 0x00, 0xA0, 0xFF), + SkPreMultiplyARGB(0xFF, 0xBB, 0x00, 0xBB) + }; + SkAutoTUnref<SkColorTable> colorTable(new SkColorTable(colors, SK_ARRAY_COUNT(colors))); + uint8_t data[] = { + 0, 0, 0, 0, 0, + 0, 1, 1, 1, 0, + 0, 1, 2, 1, 0, + 0, 1, 1, 1, 0, + 0, 0, 0, 0, 0 + }; + SkImageInfo info = SkImageInfo::Make(5, 5, kIndex_8_SkColorType, kPremul_SkAlphaType); + return SkImage::NewRasterCopy(info, data, 5, colorTable); +} static SkData* create_image_data(SkImageInfo* info) { *info = SkImageInfo::MakeN32(20, 20, kOpaque_SkAlphaType); const size_t rowBytes = info->minRowBytes(); @@ -733,4 +759,72 @@ DEF_GPUTEST_FOR_NATIVE_CONTEXT(SkImage_NewFromTexture, reporter, context) { refImg.reset(nullptr); // force a release of the image REPORTER_ASSERT(reporter, 1 == releaseChecker.fReleaseCount); } + +static void check_images_same(skiatest::Reporter* reporter, const SkImage* a, const SkImage* b) { + if (a->width() != b->width() || a->height() != b->height()) { + ERRORF(reporter, "Images must have the same size"); + return; + } + if (a->isOpaque() != b->isOpaque()) { + ERRORF(reporter, "Images must have the same opaquness"); + return; + } + + SkImageInfo info = SkImageInfo::MakeN32Premul(a->width(), a->height()); + SkAutoPixmapStorage apm; + SkAutoPixmapStorage bpm; + + apm.alloc(info); + bpm.alloc(info); + + if (!a->readPixels(apm, 0, 0)) { + ERRORF(reporter, "Could not read image a's pixels"); + return; + } + if (!b->readPixels(bpm, 0, 0)) { + ERRORF(reporter, "Could not read image b's pixels"); + return; + } + + for (auto y = 0; y < info.height(); ++y) { + for (auto x = 0; x < info.width(); ++x) { + uint32_t pixelA = *apm.addr32(x, y); + uint32_t pixelB = *bpm.addr32(x, y); + if (pixelA != pixelB) { + ERRORF(reporter, "Expected image pixels to be the same. At %d,%d 0x%08x != 0x%08x", + x, y, pixelA, pixelB); + return; + } + } + } +} + +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(NewTextureFromPixmap, reporter, context) { + for (auto create : {&create_image +#if 0 // read pixels failing for non RT formats (565 not a RT on some desktop GLs). + , &create_image_565 +#endif + , &create_image_ct + }) { + SkAutoTUnref<SkImage> image((*create)()); + if (!image) { + ERRORF(reporter, "Could not create image"); + return; + } + + SkPixmap pixmap; + if (!image->peekPixels(&pixmap)) { + ERRORF(reporter, "peek failed"); + } else { + SkAutoTUnref<SkImage> texImage(SkImage::NewTextureFromPixmap(context, pixmap, + SkBudgeted::kNo)); + if (!texImage) { + ERRORF(reporter, "NewTextureFromPixmap failed."); + } else { + check_images_same(reporter, image, texImage); + } + } + } +} + #endif |