aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/BlitMaskClip.cpp
blob: 8ba2cea3e065316b114ad05f343bd2e9137a0a64 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
 * 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 "SkBlitter.h"
#include "SkMask.h"
#include "Test.h"
#include <string.h>

class TestBlitter : public SkBlitter {
public:
    TestBlitter(SkIRect bounds, skiatest::Reporter* reporter)
        : fBounds(bounds)
        , fReporter(reporter) { }

    void blitH(int x, int y, int width) override {

        REPORTER_ASSERT(fReporter, x >= fBounds.fLeft && x < fBounds.fRight);
        REPORTER_ASSERT(fReporter, y >= fBounds.fTop && y < fBounds.fBottom);
        int right = x + width;
        REPORTER_ASSERT(fReporter, right > fBounds.fLeft && right <= fBounds.fRight);
    }

private:
    SkIRect fBounds;
    skiatest::Reporter* fReporter;
};

// Exercise all clips compared with different widths of bitMask. Make sure that no buffer
// overruns happen.
DEF_TEST(BlitAndClip, reporter) {
    const int originX = 100;
    const int originY = 100;
    for (int width = 1; width <= 32; width++) {
        const int height = 2;
        int rowBytes = (width + 7) >> 3;
        uint8_t* bits = new uint8_t[rowBytes * height];
        memset(bits, 0xAA, rowBytes * height);

        SkIRect b = {originX, originY, originX + width, originY + height};

        SkMask mask;
        mask.fFormat = SkMask::kBW_Format;
        mask.fBounds = b;
        mask.fImage = (uint8_t*)bits;
        mask.fRowBytes = rowBytes;

        TestBlitter tb(mask.fBounds, reporter);

        for (int top = b.fTop; top < b.fBottom; top++) {
            for (int bottom = top + 1; bottom <= b.fBottom; bottom++) {
                for (int left = b.fLeft; left < b.fRight; left++) {
                    for (int right = left + 1; right <= b.fRight; right++) {
                        SkIRect clipRect = {left, top, right, bottom};
                        tb.blitMask(mask, clipRect);
                    }
                }
            }
        }

        delete [] bits;
    }
}