blob: 8ba2cea3e065316b114ad05f343bd2e9137a0a64 [file] [log] [blame]
herb5520ded2015-11-18 10:50:33 -08001/*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "SkBlitter.h"
9#include "SkMask.h"
10#include "Test.h"
herb1ac026d2015-11-20 13:37:37 -080011#include <string.h>
herb5520ded2015-11-18 10:50:33 -080012
13class TestBlitter : public SkBlitter {
14public:
15 TestBlitter(SkIRect bounds, skiatest::Reporter* reporter)
16 : fBounds(bounds)
17 , fReporter(reporter) { }
18
19 void blitH(int x, int y, int width) override {
20
21 REPORTER_ASSERT(fReporter, x >= fBounds.fLeft && x < fBounds.fRight);
22 REPORTER_ASSERT(fReporter, y >= fBounds.fTop && y < fBounds.fBottom);
23 int right = x + width;
24 REPORTER_ASSERT(fReporter, right > fBounds.fLeft && right <= fBounds.fRight);
25 }
26
27private:
28 SkIRect fBounds;
29 skiatest::Reporter* fReporter;
30};
31
herb5520ded2015-11-18 10:50:33 -080032// Exercise all clips compared with different widths of bitMask. Make sure that no buffer
33// overruns happen.
34DEF_TEST(BlitAndClip, reporter) {
35 const int originX = 100;
36 const int originY = 100;
37 for (int width = 1; width <= 32; width++) {
38 const int height = 2;
39 int rowBytes = (width + 7) >> 3;
40 uint8_t* bits = new uint8_t[rowBytes * height];
herb1ac026d2015-11-20 13:37:37 -080041 memset(bits, 0xAA, rowBytes * height);
herb5520ded2015-11-18 10:50:33 -080042
43 SkIRect b = {originX, originY, originX + width, originY + height};
44
45 SkMask mask;
46 mask.fFormat = SkMask::kBW_Format;
47 mask.fBounds = b;
48 mask.fImage = (uint8_t*)bits;
49 mask.fRowBytes = rowBytes;
50
51 TestBlitter tb(mask.fBounds, reporter);
52
53 for (int top = b.fTop; top < b.fBottom; top++) {
54 for (int bottom = top + 1; bottom <= b.fBottom; bottom++) {
55 for (int left = b.fLeft; left < b.fRight; left++) {
56 for (int right = left + 1; right <= b.fRight; right++) {
57 SkIRect clipRect = {left, top, right, bottom};
58 tb.blitMask(mask, clipRect);
59 }
60 }
61 }
62 }
63
64 delete [] bits;
65 }
66}