Ejemplo n.º 1
0
static void test_treatAsSprite(skiatest::Reporter* reporter) {

    SkMatrix mat;
    SkISize  size;
    SkRandom rand;

    SkPaint noaaPaint;
    SkPaint aaPaint;
    aaPaint.setAntiAlias(true);

    // assert: translate-only no-aa can always be treated as sprite
    for (int i = 0; i < 1000; ++i) {
        rand_matrix(&mat, rand, SkMatrix::kTranslate_Mask);
        for (int j = 0; j < 1000; ++j) {
            rand_size(&size, rand);
            REPORTER_ASSERT(reporter, SkTreatAsSprite(mat, size, noaaPaint));
        }
    }

    // assert: rotate/perspect is never treated as sprite
    for (int i = 0; i < 1000; ++i) {
        rand_matrix(&mat, rand, SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask);
        for (int j = 0; j < 1000; ++j) {
            rand_size(&size, rand);
            REPORTER_ASSERT(reporter, !SkTreatAsSprite(mat, size, noaaPaint));
            REPORTER_ASSERT(reporter, !SkTreatAsSprite(mat, size, aaPaint));
        }
    }

    size.set(500, 600);

    const SkScalar tooMuchSubpixel = 100.1f;
    mat.setTranslate(tooMuchSubpixel, 0);
    REPORTER_ASSERT(reporter, !SkTreatAsSprite(mat, size, aaPaint));
    mat.setTranslate(0, tooMuchSubpixel);
    REPORTER_ASSERT(reporter, !SkTreatAsSprite(mat, size, aaPaint));

    const SkScalar tinySubPixel = 100.02f;
    mat.setTranslate(tinySubPixel, 0);
    REPORTER_ASSERT(reporter, SkTreatAsSprite(mat, size, aaPaint));
    mat.setTranslate(0, tinySubPixel);
    REPORTER_ASSERT(reporter, SkTreatAsSprite(mat, size, aaPaint));

    const SkScalar twoThirds = SK_Scalar1 * 2 / 3;
    const SkScalar bigScale = (size.width() + twoThirds) / size.width();
    mat.setScale(bigScale, bigScale);
    REPORTER_ASSERT(reporter, !SkTreatAsSprite(mat, size, noaaPaint));
    REPORTER_ASSERT(reporter, !SkTreatAsSprite(mat, size, aaPaint));

    const SkScalar oneThird = SK_Scalar1 / 3;
    const SkScalar smallScale = (size.width() + oneThird) / size.width();
    mat.setScale(smallScale, smallScale);
    REPORTER_ASSERT(reporter, SkTreatAsSprite(mat, size, noaaPaint));
    REPORTER_ASSERT(reporter, !SkTreatAsSprite(mat, size, aaPaint));

    const SkScalar oneFortyth = SK_Scalar1 / 40;
    const SkScalar tinyScale = (size.width() + oneFortyth) / size.width();
    mat.setScale(tinyScale, tinyScale);
    REPORTER_ASSERT(reporter, SkTreatAsSprite(mat, size, noaaPaint));
    REPORTER_ASSERT(reporter, SkTreatAsSprite(mat, size, aaPaint));
}
static bool treat_as_sprite(const SkMatrix& mat, const SkISize& size,
                            unsigned bits) {
    return SkTreatAsSprite(mat, size.width(), size.height(), bits);
}