blob: 967b1b49690e68fa68c06aaca205037931d5ff70 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#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"
Ben Wagnere6b04a12018-03-09 14:41:36 -050014
herb1ac026d2015-11-20 13:37:37 -080015#include <string.h>
herb5520ded2015-11-18 10:50:33 -080016
17class TestBlitter : public SkBlitter {
18public:
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
herb7df9e4a2016-06-10 13:01:27 -070031 void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]) override {
32 SkDEBUGFAIL("blitAntiH not implemented");
33 }
34
herb5520ded2015-11-18 10:50:33 -080035private:
36 SkIRect fBounds;
37 skiatest::Reporter* fReporter;
38};
39
herb5520ded2015-11-18 10:50:33 -080040// Exercise all clips compared with different widths of bitMask. Make sure that no buffer
41// overruns happen.
42DEF_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];
herb1ac026d2015-11-20 13:37:37 -080049 memset(bits, 0xAA, rowBytes * height);
herb5520ded2015-11-18 10:50:33 -080050
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}