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

Unified Diff: tests/SurfaceTest.cpp

Issue 830033003: change API contract: disallow zero-sized images or surfaces (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 12 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/lazy/SkDiscardablePixelRef.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 28abf9804c1f3dc43b14f486f4d47f31150210c3..d8c6d9d76caa5d883b2edf97977538fd229360b1 100644
--- a/tests/SurfaceTest.cpp
+++ b/tests/SurfaceTest.cpp
@@ -71,6 +71,35 @@ enum ImageType {
kCodec_ImageType,
};
+#include "SkImageGenerator.h"
+
+class EmptyGenerator : public SkImageGenerator {
+protected:
+ bool onGetInfo(SkImageInfo* info) SK_OVERRIDE {
+ *info = SkImageInfo::Make(0, 0, kN32_SkColorType, kPremul_SkAlphaType);
+ return true;
+ }
+};
+
+static void test_empty_image(skiatest::Reporter* reporter) {
+ const SkImageInfo info = SkImageInfo::Make(0, 0, kN32_SkColorType, kPremul_SkAlphaType);
+
+ REPORTER_ASSERT(reporter, NULL == SkImage::NewRasterCopy(info, NULL, 0));
+ REPORTER_ASSERT(reporter, NULL == SkImage::NewRasterData(info, NULL, 0));
+ REPORTER_ASSERT(reporter, NULL == SkImage::NewFromGenerator(SkNEW(EmptyGenerator)));
+}
+
+static void test_empty_surface(skiatest::Reporter* reporter, GrContext* ctx) {
+ const SkImageInfo info = SkImageInfo::Make(0, 0, kN32_SkColorType, kPremul_SkAlphaType);
+
+ REPORTER_ASSERT(reporter, NULL == SkSurface::NewRaster(info));
+ REPORTER_ASSERT(reporter, NULL == SkSurface::NewRasterDirect(info, NULL, 0));
+ if (ctx) {
+ REPORTER_ASSERT(reporter, NULL == SkSurface::NewRenderTarget(ctx, info, 0, NULL));
+ REPORTER_ASSERT(reporter, NULL == SkSurface::NewScratchRenderTarget(ctx, info, 0, NULL));
+ }
+}
+
static void test_image(skiatest::Reporter* reporter) {
SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1);
size_t rowBytes = info.minRowBytes();
@@ -475,6 +504,9 @@ DEF_GPUTEST(Surface, reporter, factory) {
TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kDiscard_ContentChangeMode);
TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kRetain_ContentChangeMode);
+ test_empty_image(reporter);
+ test_empty_surface(reporter, NULL);
+
test_imagepeek(reporter, factory);
test_canvaspeek(reporter, factory);
@@ -500,6 +532,7 @@ DEF_GPUTEST(Surface, reporter, factory) {
TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context, SkSurface::kRetain_ContentChangeMode);
TestGetTexture(reporter, kGpu_SurfaceType, context);
TestGetTexture(reporter, kGpuScratch_SurfaceType, context);
+ test_empty_surface(reporter, context);
}
}
}
« no previous file with comments | « src/lazy/SkDiscardablePixelRef.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698