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

Unified Diff: tests/SurfaceTest.cpp

Issue 1643873002: allow the caller to specified raster-surface rowbytes (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: update dox for snapped image rowbytes Created 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/image/SkSurface_Raster.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/SurfaceTest.cpp
diff --git a/tests/SurfaceTest.cpp b/tests/SurfaceTest.cpp
index f0d9b17591c64b9bb0c81d5910c0de03c5ab2e40..5b7325e9af201bf681dd87a08aa0ebd7f45d4226 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);
+}
« no previous file with comments | « src/image/SkSurface_Raster.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698