1 /* 2 * Copyright (C) 2016 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 <Snapshot.h> 20 21 #include <tests/common/TestUtils.h> 22 23 using namespace android::uirenderer; 24 25 TEST(Snapshot, serializeIntersectedClip) { 26 auto actualRoot = TestUtils::makeSnapshot(Matrix4::identity(), Rect(0, 0, 100, 100)); 27 auto root = TestUtils::makeSnapshot(Matrix4::identity(), Rect(10, 10, 90, 90)); 28 auto child = TestUtils::makeSnapshot(Matrix4::identity(), Rect(50, 50, 90, 90)); 29 root->previous = actualRoot.get(); 30 child->previous = root.get(); 31 32 LinearAllocator allocator; 33 ClipRect rect(Rect(0, 0, 75, 75)); 34 { 35 auto intersectWithChild = 36 child->serializeIntersectedClip(allocator, &rect, Matrix4::identity()); 37 ASSERT_NE(nullptr, intersectWithChild); 38 EXPECT_EQ(Rect(50, 50, 75, 75), intersectWithChild->rect) << "Expect intersect with child"; 39 } 40 41 rect.intersectWithRoot = true; 42 { 43 auto intersectWithRoot = 44 child->serializeIntersectedClip(allocator, &rect, Matrix4::identity()); 45 ASSERT_NE(nullptr, intersectWithRoot); 46 EXPECT_EQ(Rect(10, 10, 75, 75), intersectWithRoot->rect) << "Expect intersect with root"; 47 } 48 } 49 50 TEST(Snapshot, applyClip) { 51 auto actualRoot = TestUtils::makeSnapshot(Matrix4::identity(), Rect(0, 0, 100, 100)); 52 auto root = TestUtils::makeSnapshot(Matrix4::identity(), Rect(10, 10, 90, 90)); 53 root->previous = actualRoot.get(); 54 55 ClipRect rect(Rect(0, 0, 75, 75)); 56 { 57 auto child = TestUtils::makeSnapshot(Matrix4::identity(), Rect(50, 50, 90, 90)); 58 child->previous = root.get(); 59 child->applyClip(&rect, Matrix4::identity()); 60 61 EXPECT_TRUE(child->getClipArea().isSimple()); 62 EXPECT_EQ(Rect(50, 50, 75, 75), child->getRenderTargetClip()); 63 } 64 65 { 66 rect.intersectWithRoot = true; 67 auto child = TestUtils::makeSnapshot(Matrix4::identity(), Rect(50, 50, 90, 90)); 68 child->previous = root.get(); 69 child->applyClip(&rect, Matrix4::identity()); 70 71 EXPECT_TRUE(child->getClipArea().isSimple()); 72 EXPECT_EQ(Rect(10, 10, 75, 75), child->getRenderTargetClip()); 73 } 74 } 75