Index: tests/ImageNewShaderTest.cpp |
diff --git a/tests/ImageNewShaderTest.cpp b/tests/ImageNewShaderTest.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8c4a24248aa180011d6b2905e1b9b256f6b6edf2 |
--- /dev/null |
+++ b/tests/ImageNewShaderTest.cpp |
@@ -0,0 +1,102 @@ |
+/* |
+ * Copyright 2013 Google Inc. |
+ * |
+ * Use of this source code is governed by a BSD-style license that can be |
+ * found in the LICENSE file. |
+ */ |
+ |
+#include "SkImage.h" |
Justin Novosad
2014/07/10 19:24:36
Alphabetical order please.
Rémi Piotaix
2014/07/10 20:16:04
Done.
|
+#include "SkSurface.h" |
+#include "SkCanvas.h" |
+#include "SkShader.h" |
+#include "GrContextFactory.h" |
Justin Novosad
2014/07/10 19:24:36
The include of GrContextFactory should be guarded
Rémi Piotaix
2014/07/10 20:16:04
Done.
|
+ |
+#include "Test.h" |
+ |
+void testBitmapEquality(skiatest::Reporter* reporter, SkBitmap& bm1, SkBitmap& bm2, int width, int height) { |
+ for (int x = 0; x < width; x++) { |
+ for (int y = 0; y < height; y++) { |
+ REPORTER_ASSERT(reporter, 5 >= x && 5 >= y); |
Justin Novosad
2014/07/10 19:24:36
Where does the 5 come from? I don't think this is
Rémi Piotaix
2014/07/10 20:16:04
Done.
|
+ REPORTER_ASSERT(reporter, bm1.getColor(x, y) == bm2.getColor(x, y)); |
Justin Novosad
2014/07/10 19:24:36
This is OK, but it would be more efficient to do a
Rémi Piotaix
2014/07/10 20:16:04
Done.
|
+ } |
+ } |
+} |
+ |
+void runShaderTest(skiatest::Reporter* reporter, SkSurface* source, SkSurface* destination, SkImageInfo& info) { |
+ SkCanvas* rasterCanvas = source->getCanvas(); |
+ rasterCanvas->drawColor(0xFFDEDEDE, SkXfermode::kSrc_Mode); |
+ |
+ SkAutoTUnref<SkImage> rasterImage(source->newImageSnapshot()); |
+ SkAutoTUnref<SkShader> rasterShader(rasterImage->newShader( |
+ SkShader::kRepeat_TileMode, |
+ SkShader::kRepeat_TileMode)); |
+ |
+ SkPaint paint; |
+ paint.setShader(rasterShader); |
+ SkCanvas* canvasDest = destination->getCanvas(); |
+ canvasDest->drawPaint(paint); |
Justin Novosad
2014/07/10 19:24:36
To make the test more robust, consider clearing th
Rémi Piotaix
2014/07/10 20:16:04
Done.
|
+ |
+ SkIRect rect = SkIRect::MakeXYWH(0, 0, 5, 5); |
+ |
+ SkBitmap bmOrig; |
+ rasterCanvas->readPixels(rect, &bmOrig); |
+ |
+ SkBitmap bm; |
+ canvasDest->readPixels(rect, &bm); |
+ |
+ testBitmapEquality(reporter, bmOrig, bm, info.fWidth, info.fHeight); |
+} |
+ |
+DEF_TEST(ImageNewShader, reporter) { |
+ SkImageInfo info = SkImageInfo::MakeN32Premul(5, 5); |
+ |
+ SkAutoTUnref<SkSurface> srcSurface(SkSurface::NewRaster(info)); |
+ SkAutoTUnref<SkSurface> dstSurface(SkSurface::NewRaster(info)); |
+ |
+ runShaderTest(reporter, srcSurface.get(), dstSurface.get(), info); |
+} |
+ |
+#if SK_SUPPORT_GPU |
+ |
+void gpuToGpu(skiatest::Reporter* reporter, GrContext* context) { |
+ SkImageInfo info = SkImageInfo::MakeN32Premul(5, 5); |
+ |
+ SkAutoTUnref<SkSurface> srcSurface(SkSurface::NewRenderTarget(context, info)); |
+ SkAutoTUnref<SkSurface> dstSurface(SkSurface::NewRenderTarget(context, info)); |
+ |
+ runShaderTest(reporter, srcSurface.get(), dstSurface.get(), info); |
+} |
+ |
+void gpuToRaster(skiatest::Reporter* reporter, GrContext* context) { |
+ SkImageInfo info = SkImageInfo::MakeN32Premul(5, 5); |
+ |
+ SkAutoTUnref<SkSurface> srcSurface(SkSurface::NewRenderTarget(context, info)); |
+ SkAutoTUnref<SkSurface> dstSurface(SkSurface::NewRaster(info)); |
+ |
+ runShaderTest(reporter, srcSurface.get(), dstSurface.get(), info); |
+} |
+ |
+void rasterToGpu(skiatest::Reporter* reporter, GrContext* context) { |
+ SkImageInfo info = SkImageInfo::MakeN32Premul(5, 5); |
+ |
+ SkAutoTUnref<SkSurface> srcSurface(SkSurface::NewRaster(info)); |
+ SkAutoTUnref<SkSurface> dstSurface(SkSurface::NewRenderTarget(context, info)); |
+ |
+ runShaderTest(reporter, srcSurface.get(), dstSurface.get(), info); |
+} |
+ |
+DEF_GPUTEST(ImageNewSHader_GPU, reporter, factory) { |
Justin Novosad
2014/07/10 19:24:36
"H" -> "h"
Rémi Piotaix
2014/07/10 20:16:04
Done.
|
+ GrContext* context = factory->get(GrContextFactory::kNative_GLContextType); |
+ |
+ // GPU -> GPU |
+ gpuToGpu(reporter, context); |
+ |
+ // GPU -> RASTER |
+ gpuToRaster(reporter, context); |
+ |
+ |
+ // RASTER -> GPU |
+ rasterToGpu(reporter, context); |
+} |
+ |
+#endif |