Flutter Engine
The Flutter Engine
QuickRejectTest.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2011 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
15#include "include/core/SkRect.h"
20#include "tests/Test.h"
21
24 src.allocN32Pixels(10, 10);
25 src.eraseColor(SK_ColorWHITE);
26
28 dst.allocN32Pixels(10, 10);
29 dst.eraseColor(SK_ColorTRANSPARENT);
30
31 SkCanvas canvas(dst);
32
33 // we are initially transparent
34 REPORTER_ASSERT(reporter, 0 == *dst.getAddr32(5, 5));
35
36 // we see the bitmap drawn
37 canvas.drawImage(src.asImage(), 0, 0);
38 REPORTER_ASSERT(reporter, 0xFFFFFFFF == *dst.getAddr32(5, 5));
39
40 // reverify we are clear again
41 dst.eraseColor(SK_ColorTRANSPARENT);
42 REPORTER_ASSERT(reporter, 0 == *dst.getAddr32(5, 5));
43
44 // if the bitmap is clipped out, we don't draw it
45 canvas.drawImage(src.asImage(), SkIntToScalar(-10), 0);
46 REPORTER_ASSERT(reporter, 0 == *dst.getAddr32(5, 5));
47}
48
50 SkCanvas canvas(100, 100);
51
52 SkRect r = SkRect::MakeWH(10, 10);
53 REPORTER_ASSERT(reporter, false == canvas.quickReject(r));
54
55 r.offset(300, 300);
56 REPORTER_ASSERT(reporter, true == canvas.quickReject(r));
57
58 // Test that saveLayer updates quickReject
59 SkRect bounds = SkRect::MakeLTRB(50, 50, 70, 70);
60 canvas.saveLayer(&bounds, nullptr);
61 REPORTER_ASSERT(reporter, true == canvas.quickReject(SkRect::MakeWH(10, 10)));
62 REPORTER_ASSERT(reporter, false == canvas.quickReject(SkRect::MakeWH(60, 60)));
63}
64
66 SkCanvas canvas(100, 100);
67 SkRect r0 = SkRect::MakeLTRB(-50.0f, -50.0f, 50.0f, 50.0f);
68 SkRect r1 = SkRect::MakeLTRB(-50.0f, 110.0f, 50.0f, 120.0f);
69 SkRect r2 = SkRect::MakeLTRB(110.0f, -50.0f, 120.0f, 50.0f);
70 SkRect r3 = SkRect::MakeLTRB(-120.0f, -50.0f, 120.0f, 50.0f);
71 SkRect r4 = SkRect::MakeLTRB(-50.0f, -120.0f, 50.0f, 120.0f);
72 SkRect r5 = SkRect::MakeLTRB(-120.0f, -120.0f, 120.0f, 120.0f);
73 SkRect r6 = SkRect::MakeLTRB(-120.0f, -120.0f, -110.0f, -110.0f);
74 SkRect r7 = SkRect::MakeLTRB(SK_ScalarNaN, -50.0f, 50.0f, 50.0f);
75 SkRect r8 = SkRect::MakeLTRB(-50.0f, SK_ScalarNaN, 50.0f, 50.0f);
76 SkRect r9 = SkRect::MakeLTRB(-50.0f, -50.0f, SK_ScalarNaN, 50.0f);
77 SkRect r10 = SkRect::MakeLTRB(-50.0f, -50.0f, 50.0f, SK_ScalarNaN);
78 REPORTER_ASSERT(reporter, false == canvas.quickReject(r0));
79 REPORTER_ASSERT(reporter, true == canvas.quickReject(r1));
80 REPORTER_ASSERT(reporter, true == canvas.quickReject(r2));
81 REPORTER_ASSERT(reporter, false == canvas.quickReject(r3));
82 REPORTER_ASSERT(reporter, false == canvas.quickReject(r4));
83 REPORTER_ASSERT(reporter, false == canvas.quickReject(r5));
84 REPORTER_ASSERT(reporter, true == canvas.quickReject(r6));
85 REPORTER_ASSERT(reporter, true == canvas.quickReject(r7));
86 REPORTER_ASSERT(reporter, true == canvas.quickReject(r8));
87 REPORTER_ASSERT(reporter, true == canvas.quickReject(r9));
88 REPORTER_ASSERT(reporter, true == canvas.quickReject(r10));
89
91 m.setTranslateX(10.0f);
92 m.setTranslateY(10.0f);
93 canvas.setMatrix(m);
94 SkRect r11 = SkRect::MakeLTRB(5.0f, 5.0f, 100.0f, 100.0f);
95 SkRect r12 = SkRect::MakeLTRB(5.0f, 50.0f, 100.0f, 100.0f);
96 SkRect r13 = SkRect::MakeLTRB(50.0f, 5.0f, 100.0f, 100.0f);
97 REPORTER_ASSERT(reporter, false == canvas.quickReject(r11));
98 REPORTER_ASSERT(reporter, true == canvas.quickReject(r12));
99 REPORTER_ASSERT(reporter, true == canvas.quickReject(r13));
100}
101
102DEF_TEST(QuickReject, reporter) {
106}
107
108// Regression test to make sure that we keep fIsScaleTranslate up to date on the canvas.
109// It is possible to set a new matrix on the canvas without calling setMatrix(). This tests
110// that code path.
111DEF_TEST(QuickReject_MatrixState, reporter) {
112 SkCanvas canvas(100, 100);
113
115 matrix.setRotate(45.0f);
116 canvas.setMatrix(matrix);
117
120 SkPoint3::Make(1.0f, 1.0f, 1.0f), 0xFF0000FF, 2.0f, 0.5f, nullptr);
121 REPORTER_ASSERT(reporter, filter);
122 paint.setImageFilter(filter);
124 rec.fPaint = &paint;
125 canvas.saveLayer(rec);
126
127 // quickReject() will assert if the matrix is out of sync.
128 canvas.quickReject(SkRect::MakeWH(100.0f, 100.0f));
129}
reporter
Definition: FontMgrTest.cpp:39
static void test_drawBitmap(skiatest::Reporter *reporter)
static void test_layers(skiatest::Reporter *reporter)
static void test_quick_reject(skiatest::Reporter *reporter)
DEF_TEST(QuickReject, reporter)
constexpr SkColor SK_ColorTRANSPARENT
Definition: SkColor.h:99
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
#define SK_ScalarNaN
Definition: SkScalar.h:28
#define SkIntToScalar(x)
Definition: SkScalar.h:57
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
int saveLayer(const SkRect *bounds, const SkPaint *paint)
Definition: SkCanvas.cpp:496
void setMatrix(const SkM44 &matrix)
Definition: SkCanvas.cpp:1349
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition: SkCanvas.h:1528
bool quickReject(const SkRect &rect) const
Definition: SkCanvas.cpp:1557
static sk_sp< SkImageFilter > DistantLitDiffuse(const SkPoint3 &direction, SkColor lightColor, SkScalar surfaceScale, SkScalar kd, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
static SkMatrix Scale(SkScalar sx, SkScalar sy)
Definition: SkMatrix.h:75
const Paint & paint
Definition: color_source.cc:38
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
Optional< SkRect > bounds
Definition: SkRecords.h:189
dst
Definition: cp.py:12
const SkPaint * fPaint
Definition: SkCanvas.h:743
static SkPoint3 Make(SkScalar x, SkScalar y, SkScalar z)
Definition: SkPoint3.h:18
void offset(float dx, float dy)
Definition: SkRect.h:1016
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition: SkRect.h:646