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>
diff --git a/tests/SurfaceTest.cpp b/tests/SurfaceTest.cpp
index a598c1c..17201fb 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 @@
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));
+ }
+ }
+ }
+}