aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm
diff options
context:
space:
mode:
authorGravatar Matt Sarett <msarett@google.com>2017-04-12 10:21:30 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-04-12 15:11:03 +0000
commite5efa51b2acc86d1993132348d5b465855a653cc (patch)
tree4f8431dc47f3764f80d529c28e0d2e34828d2e42 /gm
parent5d884b562828ceb13ccacb71bc4581d2020e62bb (diff)
Fix SkLocalMatrixShader::isAImage() to respect local matrix and image local matrix
Fixes cts tests. b/37161109 b/37237678 Bug: skia: Change-Id: Ida9ac5e4261e8a6b22e8cdc0e585e0e7929dbbfd Reviewed-on: https://skia-review.googlesource.com/13249 Commit-Queue: Mike Klein <mtklein@chromium.org> Reviewed-by: Mike Klein <mtklein@chromium.org>
Diffstat (limited to 'gm')
-rw-r--r--gm/localmatriximageshader.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/gm/localmatriximageshader.cpp b/gm/localmatriximageshader.cpp
new file mode 100644
index 0000000000..2c9fcd2601
--- /dev/null
+++ b/gm/localmatriximageshader.cpp
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "gm.h"
+#include "SkCanvas.h"
+#include "SkSurface.h"
+
+static sk_sp<SkImage> make_image(SkCanvas* rootCanvas, SkColor color) {
+ SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100);
+ auto surface(rootCanvas->makeSurface(info));
+ if (!surface) {
+ surface = SkSurface::MakeRaster(info);
+ }
+
+ SkPaint paint;
+ paint.setAntiAlias(true);
+ paint.setColor(color);
+ surface->getCanvas()->drawIRect(SkIRect::MakeXYWH(25, 25, 50, 50), paint);
+ return surface->makeImageSnapshot();
+}
+
+DEF_SIMPLE_GM(localmatriximageshader, canvas, 250, 250) {
+ sk_sp<SkImage> redImage = make_image(canvas, SK_ColorRED);
+ SkMatrix translate = SkMatrix::MakeTrans(100.0f, 0.0f);
+ SkMatrix rotate;
+ rotate.setRotate(45.0f);
+ sk_sp<SkShader> redImageShader = redImage->makeShader(SkShader::TileMode::kClamp_TileMode,
+ SkShader::TileMode::kClamp_TileMode, &translate);
+ sk_sp<SkShader> redLocalMatrixShader = redImageShader->makeWithLocalMatrix(rotate);
+
+ // Rotate about the origin will happen first.
+ SkPaint paint;
+ paint.setShader(redLocalMatrixShader);
+ canvas->drawIRect(SkIRect::MakeWH(250, 250), paint);
+
+ sk_sp<SkImage> blueImage = make_image(canvas, SK_ColorBLUE);
+ sk_sp<SkShader> blueImageShader = blueImage->makeShader(SkShader::TileMode::kClamp_TileMode,
+ SkShader::TileMode::kClamp_TileMode, &rotate);
+ sk_sp<SkShader> blueLocalMatrixShader = blueImageShader->makeWithLocalMatrix(translate);
+
+ // Translate will happen first.
+ paint.setShader(blueLocalMatrixShader);
+ canvas->drawIRect(SkIRect::MakeWH(250, 250), paint);
+
+ canvas->translate(100.0f, 0.0f);
+
+ // Use isAImage() and confirm that the shaders will draw exactly the same (to the right by 100).
+ SkShader::TileMode mode[2];
+ SkMatrix matrix;
+ SkImage* image = redLocalMatrixShader->isAImage(&matrix, mode);
+ paint.setShader(image->makeShader(mode[0], mode[1], &matrix));
+ canvas->drawIRect(SkIRect::MakeWH(250, 250), paint);
+ image = blueLocalMatrixShader->isAImage(&matrix, mode);
+ paint.setShader(image->makeShader(mode[0], mode[1], &matrix));
+ canvas->drawIRect(SkIRect::MakeWH(250, 250), paint);
+}