blob: fafb49efba630c8bfafc4284dc1221775db9eaf6 [file] [log] [blame]
Vishnu Nairc43a23c2020-05-29 14:32:27 -07001/*
2 * Copyright (C) 2020 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
23namespace android {
24
25class EffectLayerTest : public LayerTransactionTest {
26protected:
27 virtual void SetUp() {
28 LayerTransactionTest::SetUp();
29 ASSERT_EQ(NO_ERROR, mClient->initCheck());
30
31 const auto display = SurfaceComposerClient::getInternalDisplayToken();
32 ASSERT_FALSE(display == nullptr);
33
34 mParentLayer = createColorLayer("Parent layer", Color::RED);
35 asTransaction([&](Transaction& t) {
36 t.setDisplayLayerStack(display, 0);
37 t.setLayer(mParentLayer, INT32_MAX - 2).show(mParentLayer);
38 t.setFlags(mParentLayer, layer_state_t::eLayerOpaque, layer_state_t::eLayerOpaque);
39 });
40 }
41
42 virtual void TearDown() {
43 LayerTransactionTest::TearDown();
44 mParentLayer = 0;
45 }
46
47 sp<SurfaceControl> mParentLayer;
48};
49
50TEST_F(EffectLayerTest, DefaultEffectLayerHasSolidBlackFill) {
51 sp<SurfaceControl> effectLayer =
52 mClient->createSurface(String8("Effect Layer"), 0 /* width */, 0 /* height */,
53 PIXEL_FORMAT_RGBA_8888, ISurfaceComposerClient::eFXSurfaceEffect,
Vishnu Nair992496b2020-10-22 17:27:21 -070054 mParentLayer->getHandle());
Vishnu Nairc43a23c2020-05-29 14:32:27 -070055
56 EXPECT_NE(nullptr, effectLayer.get()) << "failed to create SurfaceControl";
57 asTransaction([&](Transaction& t) {
58 t.setCrop_legacy(effectLayer, Rect(0, 0, 400, 400));
59 t.show(effectLayer);
60 });
61
62 {
63 SCOPED_TRACE("Default effect Layer has solid black fill");
64 auto shot = screenshot();
65 shot->expectColor(Rect(0, 0, 400, 400), Color::BLACK);
66 }
67}
68
69TEST_F(EffectLayerTest, EffectLayerWithNoFill) {
70 sp<SurfaceControl> effectLayer =
71 mClient->createSurface(String8("Effect Layer"), 0 /* width */, 0 /* height */,
72 PIXEL_FORMAT_RGBA_8888,
73 ISurfaceComposerClient::eFXSurfaceEffect |
74 ISurfaceComposerClient::eNoColorFill,
Vishnu Nair992496b2020-10-22 17:27:21 -070075 mParentLayer->getHandle());
Vishnu Nairc43a23c2020-05-29 14:32:27 -070076
77 EXPECT_NE(nullptr, effectLayer.get()) << "failed to create SurfaceControl";
78 asTransaction([&](Transaction& t) {
79 t.setCrop_legacy(effectLayer, Rect(0, 0, 400, 400));
80 t.show(effectLayer);
81 });
82
83 {
84 SCOPED_TRACE("Effect layer with nofill option is transparent");
85 auto shot = screenshot();
86 shot->expectColor(Rect(0, 0, 400, 400), Color::RED);
87 }
88}
89
90TEST_F(EffectLayerTest, EffectLayerCanSetColor) {
91 sp<SurfaceControl> effectLayer =
92 mClient->createSurface(String8("Effect Layer"), 0 /* width */, 0 /* height */,
93 PIXEL_FORMAT_RGBA_8888,
94 ISurfaceComposerClient::eFXSurfaceEffect |
95 ISurfaceComposerClient::eNoColorFill,
Vishnu Nair992496b2020-10-22 17:27:21 -070096 mParentLayer->getHandle());
Vishnu Nairc43a23c2020-05-29 14:32:27 -070097
98 EXPECT_NE(nullptr, effectLayer.get()) << "failed to create SurfaceControl";
99 asTransaction([&](Transaction& t) {
100 t.setCrop_legacy(effectLayer, Rect(0, 0, 400, 400));
101 t.setColor(effectLayer,
102 half3{Color::GREEN.r / 255.0f, Color::GREEN.g / 255.0f,
103 Color::GREEN.b / 255.0f});
104 t.show(effectLayer);
105 });
106
107 {
108 SCOPED_TRACE("Effect Layer can set color");
109 auto shot = screenshot();
110 shot->expectColor(Rect(0, 0, 400, 400), Color::GREEN);
111 }
112}
113
114} // namespace android
115
116// TODO(b/129481165): remove the #pragma below and fix conversion issues
117#pragma clang diagnostic pop // ignored "-Wconversion"