Flutter Engine
The Flutter Engine
Functions
QuickRejectTest.cpp File Reference
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkImageFilter.h"
#include "include/core/SkMatrix.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPoint3.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkScalar.h"
#include "include/core/SkTypes.h"
#include "include/effects/SkImageFilters.h"
#include "tests/Test.h"

Go to the source code of this file.

Functions

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)
 
 DEF_TEST (QuickReject_MatrixState, reporter)
 

Function Documentation

◆ DEF_TEST() [1/2]

DEF_TEST ( QuickReject  ,
reporter   
)

Definition at line 102 of file QuickRejectTest.cpp.

102 {
106}
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() [2/2]

DEF_TEST ( QuickReject_MatrixState  ,
reporter   
)

Definition at line 111 of file QuickRejectTest.cpp.

111 {
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}
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
static sk_sp< SkImageFilter > DistantLitDiffuse(const SkPoint3 &direction, SkColor lightColor, SkScalar surfaceScale, SkScalar kd, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
const Paint & paint
Definition: color_source.cc:38
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
const SkPaint * fPaint
Definition: SkCanvas.h:743
static SkPoint3 Make(SkScalar x, SkScalar y, SkScalar z)
Definition: SkPoint3.h:18
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609

◆ test_drawBitmap()

static void test_drawBitmap ( skiatest::Reporter reporter)
static

Definition at line 22 of file QuickRejectTest.cpp.

22 {
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}
constexpr SkColor SK_ColorTRANSPARENT
Definition: SkColor.h:99
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
#define SkIntToScalar(x)
Definition: SkScalar.h:57
dst
Definition: cp.py:12

◆ test_layers()

static void test_layers ( skiatest::Reporter reporter)
static

Definition at line 49 of file QuickRejectTest.cpp.

49 {
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}
Optional< SkRect > bounds
Definition: SkRecords.h:189
void offset(float dx, float dy)
Definition: SkRect.h:1016
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition: SkRect.h:646

◆ test_quick_reject()

static void test_quick_reject ( skiatest::Reporter reporter)
static

Definition at line 65 of file QuickRejectTest.cpp.

65 {
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}
#define SK_ScalarNaN
Definition: SkScalar.h:28
static SkMatrix Scale(SkScalar sx, SkScalar sy)
Definition: SkMatrix.h:75