blob: bc1b69fa3729ce4d6c4ed1a038a40b431fba1c19 [file] [log] [blame]
Chris Craikb565df12015-10-05 13:00:52 -07001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <gtest/gtest.h>
18
19#include <BakedOpState.h>
20#include <RecordedOp.h>
21#include <unit_tests/TestUtils.h>
22
23namespace android {
24namespace uirenderer {
25
26TEST(ResolvedRenderState, resolution) {
27 Matrix4 identity;
28 identity.loadIdentity();
29
30 Matrix4 translate10x20;
31 translate10x20.loadTranslate(10, 20, 0);
32
33 SkPaint paint;
34 RectOp recordedOp(Rect(30, 40, 100, 200), translate10x20, Rect(0, 0, 100, 200), &paint);
35 {
36 // recorded with transform, no parent transform
37 auto parentSnapshot = TestUtils::makeSnapshot(identity, Rect(0, 0, 100, 200));
38 ResolvedRenderState state(*parentSnapshot, recordedOp);
39 EXPECT_MATRIX_APPROX_EQ(state.transform, translate10x20);
40 EXPECT_EQ(state.clipRect, Rect(0, 0, 100, 200));
41 EXPECT_EQ(state.clippedBounds, Rect(40, 60, 100, 200)); // translated and also clipped
42 }
43 {
44 // recorded with transform and parent transform
45 auto parentSnapshot = TestUtils::makeSnapshot(translate10x20, Rect(0, 0, 100, 200));
46 ResolvedRenderState state(*parentSnapshot, recordedOp);
47
48 Matrix4 expectedTranslate;
49 expectedTranslate.loadTranslate(20, 40, 0);
50 EXPECT_MATRIX_APPROX_EQ(state.transform, expectedTranslate);
51
52 // intersection of parent & transformed child clip
53 EXPECT_EQ(state.clipRect, Rect(10, 20, 100, 200));
54
55 // translated and also clipped
56 EXPECT_EQ(state.clippedBounds, Rect(50, 80, 100, 200));
57 }
58}
59
60TEST(BakedOpState, constructAndReject) {
61 LinearAllocator allocator;
62
63 Matrix4 identity;
64 identity.loadIdentity();
65
66 Matrix4 translate100x0;
67 translate100x0.loadTranslate(100, 0, 0);
68
69 SkPaint paint;
70 {
71 RectOp rejectOp(Rect(30, 40, 100, 200), translate100x0, Rect(0, 0, 100, 200), &paint);
72 auto snapshot = TestUtils::makeSnapshot(identity, Rect(0, 0, 100, 200));
73 BakedOpState* bakedOp = BakedOpState::tryConstruct(allocator, *snapshot, rejectOp);
74
75 EXPECT_EQ(bakedOp, nullptr); // rejected by clip, so not constructed
76 EXPECT_LE(allocator.usedSize(), 8u); // no significant allocation space used for rejected op
77 }
78 {
79 RectOp successOp(Rect(30, 40, 100, 200), identity, Rect(0, 0, 100, 200), &paint);
80 auto snapshot = TestUtils::makeSnapshot(identity, Rect(0, 0, 100, 200));
81 BakedOpState* bakedOp = BakedOpState::tryConstruct(allocator, *snapshot, successOp);
82
83 EXPECT_NE(bakedOp, nullptr); // NOT rejected by clip, so will be constructed
84 EXPECT_GT(allocator.usedSize(), 64u); // relatively large alloc for non-rejected op
85 }
86}
87
Chris Craikb565df12015-10-05 13:00:52 -070088}
89}