• 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 #include <memory>
18 #include <span>
19 #include <string>
20 #include <utility>
21 #include <vector>
22 
23 #include <android-base/expected.h>
24 #include <ftl/ignore.h>
25 
26 #include "test_framework/core/DisplayConfiguration.h"
27 #include "test_framework/core/TestService.h"
28 #include "test_framework/fake_hwc3/Hwc3Controller.h"
29 #include "test_framework/surfaceflinger/SFController.h"
30 
31 namespace android::surfaceflinger::tests::end2end::test_framework::core {
32 
33 struct TestService::Passkey final {};
34 
startWithDisplays(const std::vector<DisplayConfiguration> & displays)35 auto TestService::startWithDisplays(const std::vector<DisplayConfiguration>& displays)
36         -> base::expected<std::unique_ptr<TestService>, std::string> {
37     using namespace std::string_literals;
38 
39     auto service = std::make_unique<TestService>(TestService::Passkey{});
40     if (service == nullptr) {
41         return base::unexpected("Failed to construct the TestService instance."s);
42     }
43 
44     if (auto result = service->init(displays); !result) {
45         return base::unexpected("Failed to init the TestService instance: "s + result.error());
46     }
47 
48     return service;
49 }
50 
TestService(Passkey passkey)51 TestService::TestService(Passkey passkey) {
52     ftl::ignore(passkey);
53 }
54 
init(std::span<const DisplayConfiguration> displays)55 auto TestService::init(std::span<const DisplayConfiguration> displays)
56         -> base::expected<void, std::string> {
57     using namespace std::string_literals;
58 
59     auto hwcResult = fake_hwc3::Hwc3Controller::make(displays);
60     if (!hwcResult) {
61         return base::unexpected(std::move(hwcResult).error());
62     }
63     auto hwc = *std::move(hwcResult);
64 
65     auto flingerResult = surfaceflinger::SFController::make();
66     if (!flingerResult) {
67         return base::unexpected(std::move(flingerResult).error());
68     }
69     auto flinger = *std::move(flingerResult);
70 
71     surfaceflinger::SFController::useHwcService(fake_hwc3::Hwc3Controller::getServiceName());
72 
73     if (auto result = flinger->startAndConnect(); !result) {
74         return base::unexpected(std::move(result).error());
75     }
76 
77     mHwc = std::move(hwc);
78     mFlinger = std::move(flinger);
79     return {};
80 }
81 
82 }  // namespace android::surfaceflinger::tests::end2end::test_framework::core
83