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