1 /*
2  * Copyright (C) 2019 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 // TODO(b/129481165): remove the #pragma below and fix conversion issues
18 #pragma clang diagnostic push
19 #pragma clang diagnostic ignored "-Wconversion"
20 
21 #include "LayerTransactionTest.h"
22 namespace android {
23 
24 using android::hardware::graphics::common::V1_1::BufferUsage;
25 
26 ::testing::Environment* const binderEnv =
27         ::testing::AddGlobalTestEnvironment(new BinderEnvironment());
28 
29 class DereferenceSurfaceControlTest : public LayerTransactionTest {
30 protected:
SetUp()31     void SetUp() override {
32         LayerTransactionTest::SetUp();
33         bgLayer = createLayer("BG layer", 20, 20);
34         fillBufferQueueLayerColor(bgLayer, Color::RED, 20, 20);
35         fgLayer = createLayer("FG layer", 20, 20);
36         fillBufferQueueLayerColor(fgLayer, Color::BLUE, 20, 20);
37         Transaction().setLayer(fgLayer, mLayerZBase + 1).apply();
38         {
39             SCOPED_TRACE("before anything");
40             auto shot = screenshot();
41             shot->expectColor(Rect(0, 0, 20, 20), Color::BLUE);
42         }
43     }
TearDown()44     void TearDown() override {
45         LayerTransactionTest::TearDown();
46         bgLayer = 0;
47         fgLayer = 0;
48     }
49 
50     sp<SurfaceControl> bgLayer;
51     sp<SurfaceControl> fgLayer;
52 };
53 
TEST_F(DereferenceSurfaceControlTest,LayerNotInTransaction)54 TEST_F(DereferenceSurfaceControlTest, LayerNotInTransaction) {
55     fgLayer = nullptr;
56     {
57         SCOPED_TRACE("after setting null");
58         auto shot = screenshot();
59         shot->expectColor(Rect(0, 0, 20, 20), Color::RED);
60     }
61 }
62 
TEST_F(DereferenceSurfaceControlTest,LayerInTransaction)63 TEST_F(DereferenceSurfaceControlTest, LayerInTransaction) {
64     auto transaction = Transaction().show(fgLayer);
65     fgLayer = nullptr;
66     {
67         SCOPED_TRACE("after setting null");
68         auto shot = screenshot();
69         shot->expectColor(Rect(0, 0, 20, 20), Color::BLUE);
70     }
71 }
72 
73 } // namespace android
74 
75 // TODO(b/129481165): remove the #pragma below and fix conversion issues
76 #pragma clang diagnostic pop // ignored "-Wconversion"
77