10b7e8245db728d127ada698be63d78b33fc6e4daChris Craik/*
20b7e8245db728d127ada698be63d78b33fc6e4daChris Craik * Copyright (C) 2015 The Android Open Source Project
30b7e8245db728d127ada698be63d78b33fc6e4daChris Craik *
40b7e8245db728d127ada698be63d78b33fc6e4daChris Craik * Licensed under the Apache License, Version 2.0 (the "License");
50b7e8245db728d127ada698be63d78b33fc6e4daChris Craik * you may not use this file except in compliance with the License.
60b7e8245db728d127ada698be63d78b33fc6e4daChris Craik * You may obtain a copy of the License at
70b7e8245db728d127ada698be63d78b33fc6e4daChris Craik *
80b7e8245db728d127ada698be63d78b33fc6e4daChris Craik *      http://www.apache.org/licenses/LICENSE-2.0
90b7e8245db728d127ada698be63d78b33fc6e4daChris Craik *
100b7e8245db728d127ada698be63d78b33fc6e4daChris Craik * Unless required by applicable law or agreed to in writing, software
110b7e8245db728d127ada698be63d78b33fc6e4daChris Craik * distributed under the License is distributed on an "AS IS" BASIS,
120b7e8245db728d127ada698be63d78b33fc6e4daChris Craik * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
130b7e8245db728d127ada698be63d78b33fc6e4daChris Craik * See the License for the specific language governing permissions and
140b7e8245db728d127ada698be63d78b33fc6e4daChris Craik * limitations under the License.
150b7e8245db728d127ada698be63d78b33fc6e4daChris Craik */
160b7e8245db728d127ada698be63d78b33fc6e4daChris Craik
170b7e8245db728d127ada698be63d78b33fc6e4daChris Craik#include <gtest/gtest.h>
180b7e8245db728d127ada698be63d78b33fc6e4daChris Craik
190b7e8245db728d127ada698be63d78b33fc6e4daChris Craik#include <LayerUpdateQueue.h>
200b7e8245db728d127ada698be63d78b33fc6e4daChris Craik#include <RenderNode.h>
210b7e8245db728d127ada698be63d78b33fc6e4daChris Craik
228160f20b0aca8c6595d4b385d673f59b6bcd16a4Chris Craik#include <tests/common/TestUtils.h>
230b7e8245db728d127ada698be63d78b33fc6e4daChris Craik
240b7e8245db728d127ada698be63d78b33fc6e4daChris Craiknamespace android {
250b7e8245db728d127ada698be63d78b33fc6e4daChris Craiknamespace uirenderer {
260b7e8245db728d127ada698be63d78b33fc6e4daChris Craik
270b7e8245db728d127ada698be63d78b33fc6e4daChris CraikTEST(LayerUpdateQueue, construct) {
280b7e8245db728d127ada698be63d78b33fc6e4daChris Craik    LayerUpdateQueue queue;
290b7e8245db728d127ada698be63d78b33fc6e4daChris Craik    EXPECT_TRUE(queue.entries().empty());
300b7e8245db728d127ada698be63d78b33fc6e4daChris Craik}
310b7e8245db728d127ada698be63d78b33fc6e4daChris Craik
320b7e8245db728d127ada698be63d78b33fc6e4daChris Craik// sync node properties, so properties() reflects correct width and height
330b7e8245db728d127ada698be63d78b33fc6e4daChris Craikstatic sp<RenderNode> createSyncedNode(uint32_t width, uint32_t height) {
348d1f2120fe80b23ab03c7168e3b6b2d13bafe2e7Chris Craik    sp<RenderNode> node = TestUtils::createNode(0, 0, width, height, nullptr);
35161f54b2d4160b8d3f3da9eba5746da5162e4821Chris Craik    TestUtils::syncHierarchyPropertiesAndDisplayList(node);
360b7e8245db728d127ada698be63d78b33fc6e4daChris Craik    return node;
370b7e8245db728d127ada698be63d78b33fc6e4daChris Craik}
380b7e8245db728d127ada698be63d78b33fc6e4daChris Craik
390b7e8245db728d127ada698be63d78b33fc6e4daChris CraikTEST(LayerUpdateQueue, enqueueSimple) {
400b7e8245db728d127ada698be63d78b33fc6e4daChris Craik    sp<RenderNode> a = createSyncedNode(100, 100);
410b7e8245db728d127ada698be63d78b33fc6e4daChris Craik    sp<RenderNode> b = createSyncedNode(200, 200);
42ac046387be01e586ab29519adb6d865381efa37fJohn Reck    sp<RenderNode> c = createSyncedNode(200, 200);
430b7e8245db728d127ada698be63d78b33fc6e4daChris Craik
440b7e8245db728d127ada698be63d78b33fc6e4daChris Craik    LayerUpdateQueue queue;
450b7e8245db728d127ada698be63d78b33fc6e4daChris Craik    queue.enqueueLayerWithDamage(a.get(), Rect(25, 25, 75, 75));
460b7e8245db728d127ada698be63d78b33fc6e4daChris Craik    queue.enqueueLayerWithDamage(b.get(), Rect(100, 100, 300, 300));
47ac046387be01e586ab29519adb6d865381efa37fJohn Reck    queue.enqueueLayerWithDamage(c.get(), Rect(.5, .5, .5, .5));
480b7e8245db728d127ada698be63d78b33fc6e4daChris Craik
49ac046387be01e586ab29519adb6d865381efa37fJohn Reck    EXPECT_EQ(3u, queue.entries().size());
500b7e8245db728d127ada698be63d78b33fc6e4daChris Craik
51fc29f7acd1352efa97269b5f3856eb879d5cfd53John Reck    EXPECT_EQ(a.get(), queue.entries()[0].renderNode.get());
520b7e8245db728d127ada698be63d78b33fc6e4daChris Craik    EXPECT_EQ(Rect(25, 25, 75, 75), queue.entries()[0].damage);
53fc29f7acd1352efa97269b5f3856eb879d5cfd53John Reck    EXPECT_EQ(b.get(), queue.entries()[1].renderNode.get());
540b7e8245db728d127ada698be63d78b33fc6e4daChris Craik    EXPECT_EQ(Rect(100, 100, 200, 200), queue.entries()[1].damage); // clipped to bounds
55fc29f7acd1352efa97269b5f3856eb879d5cfd53John Reck    EXPECT_EQ(c.get(), queue.entries()[2].renderNode.get());
56ac046387be01e586ab29519adb6d865381efa37fJohn Reck    EXPECT_EQ(Rect(0, 0, 1, 1), queue.entries()[2].damage); // rounded out
570b7e8245db728d127ada698be63d78b33fc6e4daChris Craik}
580b7e8245db728d127ada698be63d78b33fc6e4daChris Craik
590b7e8245db728d127ada698be63d78b33fc6e4daChris CraikTEST(LayerUpdateQueue, enqueueUnion) {
600b7e8245db728d127ada698be63d78b33fc6e4daChris Craik    sp<RenderNode> a = createSyncedNode(100, 100);
610b7e8245db728d127ada698be63d78b33fc6e4daChris Craik
620b7e8245db728d127ada698be63d78b33fc6e4daChris Craik    LayerUpdateQueue queue;
630b7e8245db728d127ada698be63d78b33fc6e4daChris Craik    queue.enqueueLayerWithDamage(a.get(), Rect(10, 10, 20, 20));
640b7e8245db728d127ada698be63d78b33fc6e4daChris Craik    queue.enqueueLayerWithDamage(a.get(), Rect(30, 30, 40, 40));
650b7e8245db728d127ada698be63d78b33fc6e4daChris Craik
660b7e8245db728d127ada698be63d78b33fc6e4daChris Craik    EXPECT_EQ(1u, queue.entries().size());
670b7e8245db728d127ada698be63d78b33fc6e4daChris Craik
68fc29f7acd1352efa97269b5f3856eb879d5cfd53John Reck    EXPECT_EQ(a.get(), queue.entries()[0].renderNode.get());
690b7e8245db728d127ada698be63d78b33fc6e4daChris Craik    EXPECT_EQ(Rect(10, 10, 40, 40), queue.entries()[0].damage);
700b7e8245db728d127ada698be63d78b33fc6e4daChris Craik}
710b7e8245db728d127ada698be63d78b33fc6e4daChris Craik
720b7e8245db728d127ada698be63d78b33fc6e4daChris CraikTEST(LayerUpdateQueue, clear) {
730b7e8245db728d127ada698be63d78b33fc6e4daChris Craik    sp<RenderNode> a = createSyncedNode(100, 100);
740b7e8245db728d127ada698be63d78b33fc6e4daChris Craik
750b7e8245db728d127ada698be63d78b33fc6e4daChris Craik    LayerUpdateQueue queue;
760b7e8245db728d127ada698be63d78b33fc6e4daChris Craik    queue.enqueueLayerWithDamage(a.get(), Rect(100, 100));
770b7e8245db728d127ada698be63d78b33fc6e4daChris Craik
780b7e8245db728d127ada698be63d78b33fc6e4daChris Craik    EXPECT_FALSE(queue.entries().empty());
790b7e8245db728d127ada698be63d78b33fc6e4daChris Craik
800b7e8245db728d127ada698be63d78b33fc6e4daChris Craik    queue.clear();
810b7e8245db728d127ada698be63d78b33fc6e4daChris Craik
820b7e8245db728d127ada698be63d78b33fc6e4daChris Craik    EXPECT_TRUE(queue.entries().empty());
830b7e8245db728d127ada698be63d78b33fc6e4daChris Craik}
840b7e8245db728d127ada698be63d78b33fc6e4daChris Craik
850b7e8245db728d127ada698be63d78b33fc6e4daChris Craik};
860b7e8245db728d127ada698be63d78b33fc6e4daChris Craik};
87