blob: 21fe56236850ba537be400965deea51e6f943467 [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
herb7df9e4a2016-06-10 13:01:27 -070027 void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]) override {
28 SkDEBUGFAIL("blitAntiH not implemented");
29 }
30
herb5520ded2015-11-18 10:50:33 -080031private:
32 SkIRect fBounds;
33 skiatest::Reporter* fReporter;
34};
35
herb5520ded2015-11-18 10:50:33 -080036// Exercise all clips compared with different widths of bitMask. Make sure that no buffer
37// overruns happen.
38DEF_TEST(BlitAndClip, reporter) {
39 const int originX = 100;
40 const int originY = 100;
41 for (int width = 1; width <= 32; width++) {
42 const int height = 2;
43 int rowBytes = (width + 7) >> 3;
44 uint8_t* bits = new uint8_t[rowBytes * height];
herb1ac026d2015-11-20 13:37:37 -080045 memset(bits, 0xAA, rowBytes * height);
herb5520ded2015-11-18 10:50:33 -080046
47 SkIRect b = {originX, originY, originX + width, originY + height};
48
49 SkMask mask;
50 mask.fFormat = SkMask::kBW_Format;
51 mask.fBounds = b;
52 mask.fImage = (uint8_t*)bits;
53 mask.fRowBytes = rowBytes;
54
55 TestBlitter tb(mask.fBounds, reporter);
56
57 for (int top = b.fTop; top < b.fBottom; top++) {
58 for (int bottom = top + 1; bottom <= b.fBottom; bottom++) {
59 for (int left = b.fLeft; left < b.fRight; left++) {
60 for (int right = left + 1; right <= b.fRight; right++) {
61 SkIRect clipRect = {left, top, right, bottom};
62 tb.blitMask(mask, clipRect);
63 }
64 }
65 }
66 }
67
68 delete [] bits;
69 }
70}