blob: 46b98f9193bec3eee42de6babe9eedfe558179d6 [file] [log] [blame]
Valerie Hau9cfc6d82019-09-23 13:54:07 -07001/*
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
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -080017// TODO(b/129481165): remove the #pragma below and fix conversion issues
18#pragma clang diagnostic push
19#pragma clang diagnostic ignored "-Wconversion"
20
Valerie Hau9cfc6d82019-09-23 13:54:07 -070021#include "LayerTransactionTest.h"
22namespace android {
23
24using android::hardware::graphics::common::V1_1::BufferUsage;
25
26::testing::Environment* const binderEnv =
27 ::testing::AddGlobalTestEnvironment(new BinderEnvironment());
28
29class DereferenceSurfaceControlTest : public LayerTransactionTest {
30protected:
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 }
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
54TEST_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
63TEST_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
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -080074
75// TODO(b/129481165): remove the #pragma below and fix conversion issues
76#pragma clang diagnostic pop // ignored "-Wconversion"