1 /*
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 <LayerUpdateQueue.h>
20 #include <RenderNode.h>
21
22 #include <tests/common/TestUtils.h>
23
24 namespace android {
25 namespace uirenderer {
26
TEST(LayerUpdateQueue,construct)27 TEST(LayerUpdateQueue, construct) {
28 LayerUpdateQueue queue;
29 EXPECT_TRUE(queue.entries().empty());
30 }
31
32 // sync node properties, so properties() reflects correct width and height
createSyncedNode(uint32_t width,uint32_t height)33 static sp<RenderNode> createSyncedNode(uint32_t width, uint32_t height) {
34 sp<RenderNode> node = TestUtils::createNode(0, 0, width, height, nullptr);
35 TestUtils::syncHierarchyPropertiesAndDisplayList(node);
36 return node;
37 }
38
TEST(LayerUpdateQueue,enqueueSimple)39 TEST(LayerUpdateQueue, enqueueSimple) {
40 sp<RenderNode> a = createSyncedNode(100, 100);
41 sp<RenderNode> b = createSyncedNode(200, 200);
42 sp<RenderNode> c = createSyncedNode(200, 200);
43
44 LayerUpdateQueue queue;
45 queue.enqueueLayerWithDamage(a.get(), Rect(25, 25, 75, 75));
46 queue.enqueueLayerWithDamage(b.get(), Rect(100, 100, 300, 300));
47 queue.enqueueLayerWithDamage(c.get(), Rect(.5, .5, .5, .5));
48
49 EXPECT_EQ(3u, queue.entries().size());
50
51 EXPECT_EQ(a.get(), queue.entries()[0].renderNode.get());
52 EXPECT_EQ(Rect(25, 25, 75, 75), queue.entries()[0].damage);
53 EXPECT_EQ(b.get(), queue.entries()[1].renderNode.get());
54 EXPECT_EQ(Rect(100, 100, 200, 200), queue.entries()[1].damage); // clipped to bounds
55 EXPECT_EQ(c.get(), queue.entries()[2].renderNode.get());
56 EXPECT_EQ(Rect(0, 0, 1, 1), queue.entries()[2].damage); // rounded out
57 }
58
TEST(LayerUpdateQueue,enqueueUnion)59 TEST(LayerUpdateQueue, enqueueUnion) {
60 sp<RenderNode> a = createSyncedNode(100, 100);
61
62 LayerUpdateQueue queue;
63 queue.enqueueLayerWithDamage(a.get(), Rect(10, 10, 20, 20));
64 queue.enqueueLayerWithDamage(a.get(), Rect(30, 30, 40, 40));
65
66 EXPECT_EQ(1u, queue.entries().size());
67
68 EXPECT_EQ(a.get(), queue.entries()[0].renderNode.get());
69 EXPECT_EQ(Rect(10, 10, 40, 40), queue.entries()[0].damage);
70 }
71
TEST(LayerUpdateQueue,clear)72 TEST(LayerUpdateQueue, clear) {
73 sp<RenderNode> a = createSyncedNode(100, 100);
74
75 LayerUpdateQueue queue;
76 queue.enqueueLayerWithDamage(a.get(), Rect(100, 100));
77
78 EXPECT_FALSE(queue.entries().empty());
79
80 queue.clear();
81
82 EXPECT_TRUE(queue.entries().empty());
83 }
84 }
85 }
86