aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/image/SkSurface_Raster.cpp4
-rw-r--r--tests/SurfaceTest.cpp39
-rw-r--r--tools/sk_tool_utils.cpp22
-rw-r--r--tools/sk_tool_utils.h1
4 files changed, 62 insertions, 4 deletions
diff --git a/src/image/SkSurface_Raster.cpp b/src/image/SkSurface_Raster.cpp
index 8cb3fd98a5..fab75ed817 100644
--- a/src/image/SkSurface_Raster.cpp
+++ b/src/image/SkSurface_Raster.cpp
@@ -6,6 +6,7 @@
*/
#include "SkSurface_Base.h"
+#include "SkImageInfoPriv.h"
#include "SkImagePriv.h"
#include "SkCanvas.h"
#include "SkDevice.h"
@@ -36,6 +37,9 @@ private:
///////////////////////////////////////////////////////////////////////////////
bool SkSurfaceValidateRasterInfo(const SkImageInfo& info, size_t rowBytes) {
+ if (!SkImageInfoIsValidCommon(info)) {
+ return false;
+ }
if (info.isEmpty()) {
return false;
}
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));
+ }
+ }
+ }
+}
diff --git a/tools/sk_tool_utils.cpp b/tools/sk_tool_utils.cpp
index 9d1b4df56c..4c4474cc57 100644
--- a/tools/sk_tool_utils.cpp
+++ b/tools/sk_tool_utils.cpp
@@ -93,19 +93,33 @@ const char* platform_font_manager() {
}
+const char* alphatype_name(SkAlphaType at) {
+ switch (at) {
+ case kUnknown_SkAlphaType: return "Unknown";
+ case kOpaque_SkAlphaType: return "Opaque";
+ case kPremul_SkAlphaType: return "Premul";
+ case kUnpremul_SkAlphaType: return "Unpremul";
+ }
+ SkASSERT(false);
+ return "unexpected alphatype";
+}
+
const char* colortype_name(SkColorType ct) {
switch (ct) {
case kUnknown_SkColorType: return "Unknown";
case kAlpha_8_SkColorType: return "Alpha_8";
- case kARGB_4444_SkColorType: return "ARGB_4444";
case kRGB_565_SkColorType: return "RGB_565";
+ case kARGB_4444_SkColorType: return "ARGB_4444";
case kRGBA_8888_SkColorType: return "RGBA_8888";
+ case kRGB_888x_SkColorType: return "RGB_888x";
case kBGRA_8888_SkColorType: return "BGRA_8888";
+ case kRGBA_1010102_SkColorType: return "RGBA_1010102";
+ case kRGB_101010x_SkColorType: return "RGB_101010x";
+ case kGray_8_SkColorType: return "Gray_8";
case kRGBA_F16_SkColorType: return "RGBA_F16";
- default:
- SkASSERT(false);
- return "unexpected colortype";
}
+ SkASSERT(false);
+ return "unexpected colortype";
}
SkColor color_to_565(SkColor color) {
diff --git a/tools/sk_tool_utils.h b/tools/sk_tool_utils.h
index d27a14a068..a1b5b7fe37 100644
--- a/tools/sk_tool_utils.h
+++ b/tools/sk_tool_utils.h
@@ -32,6 +32,7 @@ class SkTextBlobBuilder;
namespace sk_tool_utils {
+ const char* alphatype_name(SkAlphaType);
const char* colortype_name(SkColorType);
/**