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