• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2025 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 #pragma once
18 
19 #include <memory>
20 #include <span>
21 #include <string>
22 #include <vector>
23 
24 #include <android-base/expected.h>
25 #include <android-base/logging.h>
26 
27 #include "test_framework/core/DisplayConfiguration.h"
28 
29 namespace android::surfaceflinger::tests::end2end::test_framework {
30 
31 namespace surfaceflinger {
32 
33 class SFController;
34 
35 }  // namespace surfaceflinger
36 
37 namespace fake_hwc3 {
38 
39 class Hwc3Controller;
40 
41 }  // namespace fake_hwc3
42 
43 namespace core {
44 
45 class TestService final {
46     struct Passkey;  // Uses the passkey idiom to restrict construction.
47 
48   public:
49     // Constructs the test service, and starts it with the given displays as connected at boot.
50     [[nodiscard]] static auto startWithDisplays(const std::vector<DisplayConfiguration>& displays)
51             -> base::expected<std::unique_ptr<TestService>, std::string>;
52 
53     explicit TestService(Passkey passkey);
54 
55     // Obtains the HWC3 back-end controller
56     [[nodiscard]] auto hwc() -> fake_hwc3::Hwc3Controller& {
57         CHECK(mHwc);
58         return *mHwc;
59     }
60 
61     // Obtains the SurfaceFlinger front-end controller
62     [[nodiscard]] auto flinger() -> surfaceflinger::SFController& {
63         CHECK(mFlinger);
64         return *mFlinger;
65     }
66 
67   private:
68     [[nodiscard]] auto init(std::span<const DisplayConfiguration> displays)
69             -> base::expected<void, std::string>;
70 
71     std::shared_ptr<fake_hwc3::Hwc3Controller> mHwc;
72     std::shared_ptr<surfaceflinger::SFController> mFlinger;
73 };
74 
75 }  // namespace core
76 }  // namespace android::surfaceflinger::tests::end2end::test_framework
77