• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <DamageAccumulator.h>
20 #include <Matrix.h>
21 #include <utils/LinearAllocator.h>
22 
23 #include <SkRect.h>
24 
25 using namespace android;
26 using namespace android::uirenderer;
27 
28 // Test that push & pop are propegating the dirty rect
29 // There is no transformation of the dirty rect, the input is the same
30 // as the output.
TEST(DamageAccumulator,identity)31 TEST(DamageAccumulator, identity) {
32     DamageAccumulator da;
33     Matrix4 identity;
34     SkRect curDirty;
35     identity.loadIdentity();
36     da.pushTransform(&identity);
37     da.dirty(50, 50, 100, 100);
38     da.pushTransform(&identity);
39     da.peekAtDirty(&curDirty);
40     ASSERT_EQ(SkRect(), curDirty);
41     da.popTransform();
42     da.peekAtDirty(&curDirty);
43     ASSERT_EQ(SkRect::MakeLTRB(50, 50, 100, 100), curDirty);
44     da.popTransform();
45     da.finish(&curDirty);
46     ASSERT_EQ(SkRect::MakeLTRB(50, 50, 100, 100), curDirty);
47 }
48 
49 // Test that transformation is happening at the correct levels via
50 // peekAtDirty & popTransform. Just uses a simple translate to test this
TEST(DamageAccumulator,translate)51 TEST(DamageAccumulator, translate) {
52     DamageAccumulator da;
53     Matrix4 translate;
54     SkRect curDirty;
55     translate.loadTranslate(25, 25, 0);
56     da.pushTransform(&translate);
57     da.dirty(50, 50, 100, 100);
58     da.peekAtDirty(&curDirty);
59     ASSERT_EQ(SkRect::MakeLTRB(50, 50, 100, 100), curDirty);
60     da.popTransform();
61     da.finish(&curDirty);
62     ASSERT_EQ(SkRect::MakeLTRB(75, 75, 125, 125), curDirty);
63 }
64 
65 // Test that dirty rectangles are being unioned across "siblings
TEST(DamageAccumulator,union)66 TEST(DamageAccumulator, union) {
67     DamageAccumulator da;
68     Matrix4 identity;
69     SkRect curDirty;
70     identity.loadIdentity();
71     da.pushTransform(&identity);
72     da.pushTransform(&identity);
73     da.dirty(50, 50, 100, 100);
74     da.popTransform();
75     da.pushTransform(&identity);
76     da.dirty(150, 50, 200, 125);
77     da.popTransform();
78     da.popTransform();
79     da.finish(&curDirty);
80     ASSERT_EQ(SkRect::MakeLTRB(50, 50, 200, 125), curDirty);
81 }
82