aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/SurfaceTest.cpp
diff options
context:
space:
mode:
authorGravatar Mike Reed <reed@google.com>2018-02-07 16:05:29 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-02-08 16:50:59 +0000
commitd4746984e51e18ba3d2e52e96305d72d0fd84c31 (patch)
treec27cbe22c5a42560e3afadf88e191f084d21b8f9 /tests/SurfaceTest.cpp
parent30ff2ac47e2c0fc9a2f51b761948a2237b8c5815 (diff)
ensure that what is valid for a surface is also valid for an image
Note, this change will cause some previously succeeding surfaces to fail to build (since they could not snap their image) Bug: skia:7598 Change-Id: I012ca752ba1351a904625d216429eab646ca4a85 Reviewed-on: https://skia-review.googlesource.com/105421 Reviewed-by: Florin Malita <fmalita@chromium.org> Reviewed-by: Mike Klein <mtklein@chromium.org> Commit-Queue: Mike Reed <reed@google.com>
Diffstat (limited to 'tests/SurfaceTest.cpp')
-rw-r--r--tests/SurfaceTest.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/SurfaceTest.cpp b/tests/SurfaceTest.cpp
index a598c1ce0a..17201fba6f 100644
--- a/tests/SurfaceTest.cpp
+++ b/tests/SurfaceTest.cpp
@@ -32,6 +32,8 @@
#include "SkSurface_Gpu.h"
#endif
+#include "sk_tool_utils.h"
+
#include <initializer_list>
static void release_direct_surface_storage(void* pixels, void* context) {
@@ -1074,3 +1076,40 @@ DEF_TEST(Surface_null, r) {
canvas->drawPaint(SkPaint()); // should not crash, but don't expect anything to draw
REPORTER_ASSERT(r, surf->makeImageSnapshot() == nullptr);
}
+
+// assert: if a given imageinfo is valid for a surface, then it must be valid for an image
+// (so the snapshot can succeed)
+DEF_TEST(surface_image_unity, reporter) {
+ auto do_test = [reporter](const SkImageInfo& info) {
+ size_t rowBytes = info.minRowBytes();
+ auto surf = SkSurface::MakeRaster(info, rowBytes, nullptr);
+ if (surf) {
+ auto img = surf->makeImageSnapshot();
+ if (!img && false) { // change to true to document the differences
+ SkDebugf("image failed: [%08X %08X] %14s %s\n",
+ info.width(), info.height(),
+ sk_tool_utils::colortype_name(info.colorType()),
+ sk_tool_utils::alphatype_name(info.alphaType()));
+ return;
+ }
+ REPORTER_ASSERT(reporter, img != nullptr);
+
+ char dummyPixel = 0; // just need a valid address (not a valid size)
+ SkPixmap pmap = { info, &dummyPixel, rowBytes };
+ img = SkImage::MakeFromRaster(pmap, nullptr, nullptr);
+ REPORTER_ASSERT(reporter, img != nullptr);
+ }
+ };
+
+ const int32_t sizes[] = { 0, 1, 1 << 15, 1 << 16, 1 << 28, 1 << 29, 1 << 30, -1 };
+ for (int cti = 0; cti < kLastEnum_SkColorType; ++cti) {
+ SkColorType ct = static_cast<SkColorType>(cti);
+ for (int ati = 0; ati < kLastEnum_SkAlphaType; ++ati) {
+ SkAlphaType at = static_cast<SkAlphaType>(ati);
+ for (int32_t size : sizes) {
+ do_test(SkImageInfo::Make(1, size, ct, at));
+ do_test(SkImageInfo::Make(size, 1, ct, at));
+ }
+ }
+ }
+}