Flutter Engine
The Flutter Engine
BlitMaskClip.cpp
Go to the documentation of this file.
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
11#include "src/core/SkBlitter.h"
12#include "src/core/SkMask.h"
13#include "tests/Test.h"
14
15#include <cstdint>
16#include <cstring>
17
18class TestBlitter : public SkBlitter {
19public:
21 : fBounds(bounds)
22 , fReporter(reporter) { }
23
24 void blitH(int x, int y, int width) override {
25
26 REPORTER_ASSERT(fReporter, x >= fBounds.fLeft && x < fBounds.fRight);
27 REPORTER_ASSERT(fReporter, y >= fBounds.fTop && y < fBounds.fBottom);
28 int right = x + width;
29 REPORTER_ASSERT(fReporter, right > fBounds.fLeft && right <= fBounds.fRight);
30 }
31
32 void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]) override {
33 SkDEBUGFAIL("blitAntiH not implemented");
34 }
35
36private:
37 SkIRect fBounds;
38 skiatest::Reporter* fReporter;
39};
40
41// Exercise all clips compared with different widths of bitMask. Make sure that no buffer
42// overruns happen.
43DEF_TEST(BlitAndClip, reporter) {
44 const int originX = 100;
45 const int originY = 100;
46 for (int width = 1; width <= 32; width++) {
47 const int height = 2;
48 int rowBytes = (width + 7) >> 3;
49 uint8_t* bits = new uint8_t[rowBytes * height];
50 memset(bits, 0xAA, rowBytes * height);
51
52 SkIRect b = {originX, originY, originX + width, originY + height};
53 SkMask mask(bits, b, rowBytes, SkMask::kBW_Format);
55
56 for (int top = b.fTop; top < b.fBottom; top++) {
57 for (int bottom = top + 1; bottom <= b.fBottom; bottom++) {
58 for (int left = b.fLeft; left < b.fRight; left++) {
59 for (int right = left + 1; right <= b.fRight; right++) {
60 SkIRect clipRect = {left, top, right, bottom};
61 tb.blitMask(mask, clipRect);
62 }
63 }
64 }
65 }
66
67 delete [] bits;
68 }
69}
DEF_TEST(BlitAndClip, reporter)
reporter
Definition: FontMgrTest.cpp:39
#define SkDEBUGFAIL(message)
Definition: SkAssert.h:118
uint8_t SkAlpha
Definition: SkColor.h:26
static bool left(const SkPoint &p0, const SkPoint &p1)
static bool right(const SkPoint &p0, const SkPoint &p1)
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
virtual void blitMask(const SkMask &, const SkIRect &clip)
Definition: SkBlitter.cpp:201
TestBlitter(SkIRect bounds, skiatest::Reporter *reporter)
void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]) override
void blitH(int x, int y, int width) override
Blit a horizontal run of one or more pixels.
static bool b
double y
double x
Optional< SkRect > bounds
Definition: SkRecords.h:189
clipRect(r.rect, r.opAA.op(), r.opAA.aa())) template<> void Draw
int32_t height
int32_t width
Definition: SkRect.h:32
int32_t fBottom
larger y-axis bounds
Definition: SkRect.h:36
int32_t fTop
smaller y-axis bounds
Definition: SkRect.h:34
int32_t fLeft
smaller x-axis bounds
Definition: SkRect.h:33
int32_t fRight
larger x-axis bounds
Definition: SkRect.h:35
Definition: SkMask.h:25
@ kBW_Format
1bit per pixel mask (e.g. monochrome)
Definition: SkMask.h:27
const SkIRect fBounds
Definition: SkMask.h:42