OLD | NEW |
(Empty) | |
| 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 "SkBlitter.h" |
| 9 #include "SkMask.h" |
| 10 #include "Test.h" |
| 11 |
| 12 class TestBlitter : public SkBlitter { |
| 13 public: |
| 14 TestBlitter(SkIRect bounds, skiatest::Reporter* reporter) |
| 15 : fBounds(bounds) |
| 16 , fReporter(reporter) { } |
| 17 |
| 18 void blitH(int x, int y, int width) override { |
| 19 |
| 20 REPORTER_ASSERT(fReporter, x >= fBounds.fLeft && x < fBounds.fRight); |
| 21 REPORTER_ASSERT(fReporter, y >= fBounds.fTop && y < fBounds.fBottom); |
| 22 int right = x + width; |
| 23 REPORTER_ASSERT(fReporter, right > fBounds.fLeft && right <= fBounds.fRi
ght); |
| 24 } |
| 25 |
| 26 private: |
| 27 SkIRect fBounds; |
| 28 skiatest::Reporter* fReporter; |
| 29 }; |
| 30 |
| 31 |
| 32 // Exercise all clips compared with different widths of bitMask. Make sure that
no buffer |
| 33 // overruns happen. |
| 34 DEF_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]; |
| 41 |
| 42 SkIRect b = {originX, originY, originX + width, originY + height}; |
| 43 |
| 44 SkMask mask; |
| 45 mask.fFormat = SkMask::kBW_Format; |
| 46 mask.fBounds = b; |
| 47 mask.fImage = (uint8_t*)bits; |
| 48 mask.fRowBytes = rowBytes; |
| 49 |
| 50 TestBlitter tb(mask.fBounds, reporter); |
| 51 |
| 52 for (int top = b.fTop; top < b.fBottom; top++) { |
| 53 for (int bottom = top + 1; bottom <= b.fBottom; bottom++) { |
| 54 for (int left = b.fLeft; left < b.fRight; left++) { |
| 55 for (int right = left + 1; right <= b.fRight; right++) { |
| 56 SkIRect clipRect = {left, top, right, bottom}; |
| 57 tb.blitMask(mask, clipRect); |
| 58 } |
| 59 } |
| 60 } |
| 61 } |
| 62 |
| 63 delete [] bits; |
| 64 } |
| 65 } |
OLD | NEW |