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