aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/ImageNewShaderTest.cpp
diff options
context:
space:
mode:
authorGravatar piotaixr <piotaixr@chromium.org>2014-07-22 15:02:05 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-07-22 15:02:05 -0700
commit76d5b477c92ef076374fc7ea9d551c798656bebd (patch)
tree2afc05ee8510aa022cdac0deae9d32d1a6b4e7eb /tests/ImageNewShaderTest.cpp
parent85d36525c613c6c94e1f1c5dc51c1a2f73a0bc9c (diff)
Now able to set the localMatrix when creating a SkShader from a SkImage
BUG=skia:2771 R=junov@chromium.org, reed@chromium.org, bsalomon@chromium.org, bsalomon@google.com Author: piotaixr@chromium.org Review URL: https://codereview.chromium.org/409653003
Diffstat (limited to 'tests/ImageNewShaderTest.cpp')
-rw-r--r--tests/ImageNewShaderTest.cpp113
1 files changed, 80 insertions, 33 deletions
diff --git a/tests/ImageNewShaderTest.cpp b/tests/ImageNewShaderTest.cpp
index f34d066f6b..dfc5a24c33 100644
--- a/tests/ImageNewShaderTest.cpp
+++ b/tests/ImageNewShaderTest.cpp
@@ -17,49 +17,97 @@
#include "Test.h"
void testBitmapEquality(skiatest::Reporter* reporter, SkBitmap& bm1, SkBitmap& bm2) {
- bm1.lockPixels();
- bm2.lockPixels();
+ SkAutoLockPixels lockBm1(bm1);
+ SkAutoLockPixels lockBm2(bm2);
REPORTER_ASSERT(reporter, bm1.getSize() == bm2.getSize());
REPORTER_ASSERT(reporter, 0 == memcmp(bm1.getPixels(), bm2.getPixels(), bm1.getSize()));
+}
+
+void paintSource(SkSurface* sourceSurface) {
+ SkCanvas* sourceCanvas = sourceSurface->getCanvas();
+ sourceCanvas->clear(0xFFDEDEDE);
+
+ SkPaint paintColor;
+ paintColor.setColor(0xFFFF0000);
+ paintColor.setStyle(SkPaint::kFill_Style);
- bm2.unlockPixels();
- bm1.unlockPixels();
+ SkRect rect = SkRect::MakeXYWH(
+ SkIntToScalar(1),
+ SkIntToScalar(0),
+ SkIntToScalar(1),
+ SkIntToScalar(sourceSurface->height()));
+
+ sourceCanvas->drawRect(rect, paintColor);
}
-void runShaderTest(skiatest::Reporter* reporter, SkSurface* source, SkSurface* destination, SkImageInfo& info) {
- SkCanvas* rasterCanvas = source->getCanvas();
- rasterCanvas->drawColor(0xFFDEDEDE, SkXfermode::kSrc_Mode);
+void runShaderTest(skiatest::Reporter* reporter, SkSurface* sourceSurface, SkSurface* destinationSurface, SkImageInfo& info) {
+ paintSource(sourceSurface);
- SkAutoTUnref<SkImage> rasterImage(source->newImageSnapshot());
- SkAutoTUnref<SkShader> rasterShader(rasterImage->newShader(
+ SkAutoTUnref<SkImage> sourceImage(sourceSurface->newImageSnapshot());
+ SkAutoTUnref<SkShader> sourceShader(sourceImage->newShader(
SkShader::kRepeat_TileMode,
SkShader::kRepeat_TileMode));
SkPaint paint;
- paint.setShader(rasterShader);
- SkCanvas* canvasDest = destination->getCanvas();
- canvasDest->clear(SK_ColorTRANSPARENT);
- canvasDest->drawPaint(paint);
+ paint.setShader(sourceShader);
+
+ SkCanvas* destinationCanvas = destinationSurface->getCanvas();
+ destinationCanvas->clear(SK_ColorTRANSPARENT);
+ destinationCanvas->drawPaint(paint);
- SkIRect rect = SkIRect::MakeXYWH(0, 0, 5, 5);
+ SkIRect rect = SkIRect::MakeWH(info.width(), info.height());
SkBitmap bmOrig;
- rasterCanvas->readPixels(rect, &bmOrig);
+ sourceSurface->getCanvas()->readPixels(rect, &bmOrig);
+
SkBitmap bm;
- canvasDest->readPixels(rect, &bm);
+ destinationCanvas->readPixels(rect, &bm);
testBitmapEquality(reporter, bmOrig, bm);
+
+
+
+ // Test with a translated shader
+ SkMatrix matrix;
+ matrix.setTranslate(SkIntToScalar(-1), SkIntToScalar(0));
+
+ SkAutoTUnref<SkShader> sourceShaderTranslated(sourceImage->newShader(
+ SkShader::kRepeat_TileMode,
+ SkShader::kRepeat_TileMode,
+ &matrix));
+
+ destinationCanvas->clear(SK_ColorTRANSPARENT);
+
+ SkPaint paintTranslated;
+ paintTranslated.setShader(sourceShaderTranslated);
+
+ destinationCanvas->drawPaint(paintTranslated);
+
+ SkBitmap bmt;
+ destinationCanvas->readPixels(rect, &bmt);
+
+ // Test correctness
+ {
+ SkAutoLockPixels lockBm(bmt);
+ for (int y = 0; y < info.height(); y++) {
+ REPORTER_ASSERT(reporter, 0xFFFF0000 == bmt.getColor(0, y));
+
+ for (int x = 1; x < info.width(); x++) {
+ REPORTER_ASSERT(reporter, 0xFFDEDEDE == bmt.getColor(x, y));
+ }
+ }
+ }
}
DEF_TEST(ImageNewShader, reporter) {
SkImageInfo info = SkImageInfo::MakeN32Premul(5, 5);
- SkAutoTUnref<SkSurface> srcSurface(SkSurface::NewRaster(info));
- SkAutoTUnref<SkSurface> dstSurface(SkSurface::NewRaster(info));
+ SkAutoTUnref<SkSurface> sourceSurface(SkSurface::NewRaster(info));
+ SkAutoTUnref<SkSurface> destinationSurface(SkSurface::NewRaster(info));
- runShaderTest(reporter, srcSurface.get(), dstSurface.get(), info);
+ runShaderTest(reporter, sourceSurface.get(), destinationSurface.get(), info);
}
#if SK_SUPPORT_GPU
@@ -67,32 +115,32 @@ DEF_TEST(ImageNewShader, reporter) {
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));
+ SkAutoTUnref<SkSurface> sourceSurface(SkSurface::NewRenderTarget(context, info));
+ SkAutoTUnref<SkSurface> destinationSurface(SkSurface::NewRenderTarget(context, info));
- runShaderTest(reporter, srcSurface.get(), dstSurface.get(), info);
+ runShaderTest(reporter, sourceSurface.get(), destinationSurface.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));
+ SkAutoTUnref<SkSurface> sourceSurface(SkSurface::NewRenderTarget(context, info));
+ SkAutoTUnref<SkSurface> destinationSurface(SkSurface::NewRaster(info));
- runShaderTest(reporter, srcSurface.get(), dstSurface.get(), info);
+ runShaderTest(reporter, sourceSurface.get(), destinationSurface.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));
+ SkAutoTUnref<SkSurface> sourceSurface(SkSurface::NewRaster(info));
+ SkAutoTUnref<SkSurface> destinationSurface(SkSurface::NewRenderTarget(context, info));
- runShaderTest(reporter, srcSurface.get(), dstSurface.get(), info);
+ runShaderTest(reporter, sourceSurface.get(), destinationSurface.get(), info);
}
DEF_GPUTEST(ImageNewShader_GPU, reporter, factory) {
- for (int i= 0; i < GrContextFactory::kGLContextTypeCnt; ++i) {
+ for (int i = 0; i < GrContextFactory::kGLContextTypeCnt; ++i) {
GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLContextType) i;
if (!GrContextFactory::IsRenderingGLContext(glCtxType)) {
@@ -105,14 +153,13 @@ DEF_GPUTEST(ImageNewShader_GPU, reporter, factory) {
continue;
}
- // GPU -> GPU
+ // GPU -> GPU
gpuToGpu(reporter, context);
- // GPU -> RASTER
+ // GPU -> RASTER
gpuToRaster(reporter, context);
-
- // RASTER -> GPU
+ // RASTER -> GPU
rasterToGpu(reporter, context);
}
}