1 /*
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 "include/core/SkColor.h"
9 #include "include/core/SkRect.h"
10 #include "include/core/SkTypes.h"
11 #include "src/core/SkBlitter.h"
12 #include "src/core/SkMask.h"
13 #include "tests/Test.h"
14
15 #include <cstdint>
16 #include <cstring>
17
18 class TestBlitter : public SkBlitter {
19 public:
TestBlitter(SkIRect bounds,skiatest::Reporter * reporter)20 TestBlitter(SkIRect bounds, skiatest::Reporter* reporter)
21 : fBounds(bounds)
22 , fReporter(reporter) { }
23
blitH(int x,int y,int width)24 void blitH(int x, int y, int width) override {
25
26 REPORTER_ASSERT(fReporter, x >= fBounds.fLeft && x < fBounds.fRight);
27 REPORTER_ASSERT(fReporter, y >= fBounds.fTop && y < fBounds.fBottom);
28 int right = x + width;
29 REPORTER_ASSERT(fReporter, right > fBounds.fLeft && right <= fBounds.fRight);
30 }
31
blitAntiH(int x,int y,const SkAlpha antialias[],const int16_t runs[])32 void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]) override {
33 SkDEBUGFAIL("blitAntiH not implemented");
34 }
35
36 private:
37 SkIRect fBounds;
38 skiatest::Reporter* fReporter;
39 };
40
41 // Exercise all clips compared with different widths of bitMask. Make sure that no buffer
42 // overruns happen.
DEF_TEST(BlitAndClip,reporter)43 DEF_TEST(BlitAndClip, reporter) {
44 const int originX = 100;
45 const int originY = 100;
46 for (int width = 1; width <= 32; width++) {
47 const int height = 2;
48 int rowBytes = (width + 7) >> 3;
49 uint8_t* bits = new uint8_t[rowBytes * height];
50 memset(bits, 0xAA, rowBytes * height);
51
52 SkIRect b = {originX, originY, originX + width, originY + height};
53 SkMask mask(bits, b, rowBytes, SkMask::kBW_Format);
54 TestBlitter tb(mask.fBounds, reporter);
55
56 for (int top = b.fTop; top < b.fBottom; top++) {
57 for (int bottom = top + 1; bottom <= b.fBottom; bottom++) {
58 for (int left = b.fLeft; left < b.fRight; left++) {
59 for (int right = left + 1; right <= b.fRight; right++) {
60 SkIRect clipRect = {left, top, right, bottom};
61 tb.blitMask(mask, clipRect);
62 }
63 }
64 }
65 }
66
67 delete [] bits;
68 }
69 }
70