blob: d0cea5565ce9c2c39af51b7b06ec08526980ec29 [file]
/*
* 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 "GrTestUtils.h"
#include "SkMatrix.h"
#ifdef GR_TEST_UTILS
namespace GrTest {
const SkMatrix& TestMatrix(SkRandom* random) {
static SkMatrix gMatrices[5];
static bool gOnce;
if (!gOnce) {
gMatrices[0].reset();
gMatrices[1].setTranslate(SkIntToScalar(-100), SkIntToScalar(100));
gMatrices[2].setRotate(SkIntToScalar(17));
gMatrices[3].setRotate(SkIntToScalar(185));
gMatrices[3].postTranslate(SkIntToScalar(66), SkIntToScalar(-33));
gMatrices[3].postScale(SkIntToScalar(2), SK_ScalarHalf);
gMatrices[4].setRotate(SkIntToScalar(215));
gMatrices[4].set(SkMatrix::kMPersp0, 0.00013f);
gMatrices[4].set(SkMatrix::kMPersp1, -0.000039f);
gOnce = true;
}
return gMatrices[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(gMatrices)))];
}
const SkMatrix& TestMatrixPreservesRightAngles(SkRandom* random) {
static SkMatrix gMatrices[4];
static bool gOnce;
if (!gOnce) {
// identity
gMatrices[0].reset();
// translation
gMatrices[1].setTranslate(SkIntToScalar(-100), SkIntToScalar(100));
// scale
gMatrices[2].setScale(SkIntToScalar(17), SkIntToScalar(17));
// scale + translation
gMatrices[3].setScale(SkIntToScalar(-17), SkIntToScalar(-17));
gMatrices[3].postTranslate(SkIntToScalar(66), SkIntToScalar(-33));
// orthogonal basis vectors
gMatrices[4].reset();
gMatrices[4].setScale(SkIntToScalar(-1), SkIntToScalar(-1));
gMatrices[4].setRotate(47);
gOnce = true;
for (size_t i = 0; i < SK_ARRAY_COUNT(gMatrices); i++) {
SkASSERT(gMatrices[i].preservesRightAngles());
}
}
return gMatrices[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(gMatrices)))];
}
const SkRect& TestRect(SkRandom* random) {
static SkRect gRects[1];
static bool gOnce;
if (!gOnce) {
gRects[0] = SkRect::MakeWH(1.f, 1.f);
gRects[1] = SkRect::MakeWH(1.0f, 256.0f);
gRects[2] = SkRect::MakeWH(256.0f, 1.0f);
gRects[4] = SkRect::MakeLargest();
gRects[5] = SkRect::MakeLTRB(-65535.0f, -65535.0f, 65535.0f, 65535.0f);
gRects[6] = SkRect::MakeLTRB(10.0f, 10.0f, -10.0f, -10.0f);
gOnce = true;
}
return gRects[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(gRects)))];
}
};
#endif