switch to SkM44
Change-Id: I2d44eb5b1984212fb461977f5e9ee95717046a8e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/272467
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Mike Reed <reed@google.com>
diff --git a/gm/crbug_224618.cpp b/gm/crbug_224618.cpp
index de4f516..dfc759c 100644
--- a/gm/crbug_224618.cpp
+++ b/gm/crbug_224618.cpp
@@ -8,25 +8,12 @@
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkImage.h"
+#include "include/core/SkM44.h"
#include "include/core/SkMatrix.h"
-#include "include/core/SkMatrix44.h"
#include "include/core/SkSurface.h"
#include "include/effects/SkGradientShader.h"
-#include "include/core/SkM44.h"
#include "tools/timer/TimeUtils.h"
-static SkM44 rotate_axis_angle(SkScalar x, SkScalar y, SkScalar z, SkScalar radians) {
- // SkM44 doesn't expose any rotation factories yet
- SkMatrix44 m;
- m.setRotateAboutUnit(x, y, z, radians);
-
- float a[16];
- m.asColMajorf(a);
- SkM44 m4;
- m4.setColMajor(a);
- return m4;
-}
-
// Adapted from https://codepen.io/adamdupuis/pen/qLYzqB
class CrBug224618GM : public skiagm::GM {
public:
@@ -73,7 +60,7 @@
0.f, 0.f, -1.f / radius, 1.f};
SkM44 zoom = SkM44::Translate(0.f, 0.f, radius);
SkM44 postZoom = SkM44::Translate(0.f, 0.f, -radius - 1.f);
- SkM44 rotateHorizontal = rotate_axis_angle(0.f, 1.f, 0.f, 2.356194490192345f);
+ SkM44 rotateHorizontal = SkM44::Rotate({0, 1, 0}, 2.356194490192345f);
// w in degrees will need to be converted to radians
SkV4 axisAngles[6] = {
@@ -94,7 +81,7 @@
};
for (int i = 0; i < 6; ++i) {
- SkM44 model = rotate_axis_angle(axisAngles[i].x, axisAngles[i].y, axisAngles[i].z,
+ SkM44 model = SkM44::Rotate({axisAngles[i].x, axisAngles[i].y, axisAngles[i].z},
SkDegreesToRadians(axisAngles[i].w));
model = SkM44::Translate(radius, radius) * proj * // project and place content
zoom * rotateHorizontal * model * postZoom * // main model matrix
diff --git a/gm/postercircle.cpp b/gm/postercircle.cpp
index 6785f9f..37735e1 100644
--- a/gm/postercircle.cpp
+++ b/gm/postercircle.cpp
@@ -12,8 +12,8 @@
#include "include/core/SkFont.h"
#include "include/core/SkFontTypes.h"
#include "include/core/SkImage.h"
+#include "include/core/SkM44.h"
#include "include/core/SkMatrix.h"
-#include "include/core/SkMatrix44.h"
#include "include/core/SkPaint.h"
#include "include/core/SkRRect.h"
#include "include/core/SkRect.h"
@@ -82,8 +82,8 @@
void onDraw(SkCanvas* canvas) override {
// See https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/perspective
// for projection matrix when --webkit-perspective: 800px is used.
- SkMatrix44 proj(SkMatrix44::kIdentity_Constructor);
- proj.set(3, 2, -1.f / 800.f);
+ SkM44 proj;
+ proj.setRC(3, 2, -1.f / 800.f);
for (int pass = 0; pass < 2; ++pass) {
// Want to draw 90 to 270 first (the back), then 270 to 90 (the front), but do all 3
@@ -119,19 +119,12 @@
// Matrix matches transform: rotateY(<angle>deg) translateZ(200px); nested in an
// element with the perspective projection matrix above.
- SkMatrix44 model;
- // No post/preRotate, so start with rotation matrix and adjust from there
- model.setRotateAboutUnit(0.f, 1.f, 0.f, SkDegreesToRadians(yRotation));
- model.preTranslate(0.f, 0.f, kRingRadius); // *before* rotation
- model.postTranslate(0.f, ringY, 0.f); // *after* rotation
- model.postConcat(proj);
- model.postTranslate(0.5f * kStageWidth, 0.5f * kStageHeight + 25, 0.f);
-
- // Flatten the 4x4 matrix by discarding the 3rd row and column
- canvas->concat(SkMatrix::MakeAll(
- model.get(0, 0), model.get(0, 1), model.get(0, 3),
- model.get(1, 0), model.get(1, 1), model.get(1, 3),
- model.get(3, 0), model.get(3, 1), model.get(3, 3)));
+ SkM44 model = SkM44::Translate(kStageWidth/2, kStageHeight/2 + 25, 0)
+ * proj
+ * SkM44::Translate(0, ringY, 0)
+ * SkM44::Rotate({0,1,0}, SkDegreesToRadians(yRotation))
+ * SkM44::Translate(0, 0, kRingRadius);
+ canvas->concat44(model);
SkRect poster = SkRect::MakeLTRB(-0.5f * kPosterSize, -0.5f * kPosterSize,
0.5f * kPosterSize, 0.5f * kPosterSize);