diff options
author | reed <reed@google.com> | 2016-01-30 10:01:06 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-01-30 10:01:06 -0800 |
commit | 9cd016e9b63f3827580d5b19a187dbf26b8e1436 (patch) | |
tree | a3e33dbff8b8f3197d167505a34b6da1b5e31bf3 /tests | |
parent | ae658e15477df86d1a864feb48d0274af2784f40 (diff) |
allow the caller to specified raster-surface rowbytes.
along the way, simplify how we copy the surface's bitmap
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1643873002
Review URL: https://codereview.chromium.org/1643873002
Diffstat (limited to 'tests')
-rw-r--r-- | tests/SurfaceTest.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/SurfaceTest.cpp b/tests/SurfaceTest.cpp index f0d9b17591..5b7325e9af 100644 --- a/tests/SurfaceTest.cpp +++ b/tests/SurfaceTest.cpp @@ -661,3 +661,44 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceNoCanvas_Gpu, reporter, context) { } } #endif + +static void check_rowbytes_remain_consistent(SkSurface* surface, skiatest::Reporter* reporter) { + SkImageInfo info; + size_t rowBytes; + REPORTER_ASSERT(reporter, surface->peekPixels(&info, &rowBytes)); + + SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); + SkImageInfo im_info; + size_t im_rowbytes; + REPORTER_ASSERT(reporter, image->peekPixels(&im_info, &im_rowbytes)); + + REPORTER_ASSERT(reporter, rowBytes == im_rowbytes); + + // trigger a copy-on-write + surface->getCanvas()->drawPaint(SkPaint()); + SkAutoTUnref<SkImage> image2(surface->newImageSnapshot()); + REPORTER_ASSERT(reporter, image->uniqueID() != image2->uniqueID()); + + SkImageInfo im_info2; + size_t im_rowbytes2; + REPORTER_ASSERT(reporter, image2->peekPixels(&im_info2, &im_rowbytes2)); + + REPORTER_ASSERT(reporter, im_rowbytes2 == im_rowbytes); +} + +DEF_TEST(surface_rowbytes, reporter) { + const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); + + SkAutoTUnref<SkSurface> surf0(SkSurface::NewRaster(info)); + check_rowbytes_remain_consistent(surf0, reporter); + + // specify a larger rowbytes + SkAutoTUnref<SkSurface> surf1(SkSurface::NewRaster(info, 500, nullptr)); + check_rowbytes_remain_consistent(surf1, reporter); + + // Try some illegal rowByte values + SkSurface* s = SkSurface::NewRaster(info, 396, nullptr); // needs to be at least 400 + REPORTER_ASSERT(reporter, nullptr == s); + s = SkSurface::NewRaster(info, 1 << 30, nullptr); // allocation to large + REPORTER_ASSERT(reporter, nullptr == s); +} |