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 <cstdint>
18 #include <memory>
19 #include <string>
20 #include <string_view>
21 #include <utility>
22 #include <vector>
23
24 #include <aidl/android/hardware/graphics/composer3/BnComposer.h>
25 #include <aidl/android/hardware/graphics/composer3/Capability.h>
26 #include <aidl/android/hardware/graphics/composer3/IComposer.h>
27 #include <aidl/android/hardware/graphics/composer3/PowerMode.h>
28
29 #include <android-base/expected.h>
30 #include <android-base/logging.h>
31 #include <android/binder_auto_utils.h>
32 #include <android/binder_interface_utils.h>
33 #include <android/binder_status.h>
34 #include <ftl/ignore.h>
35
36 #include "test_framework/core/DisplayConfiguration.h"
37 #include "test_framework/fake_hwc3/Hwc3Composer.h"
38
39 namespace android::surfaceflinger::tests::end2end::test_framework::fake_hwc3 {
40
41 class Hwc3Composer::Hwc3ComposerImpl final
42 : public aidl::android::hardware::graphics::composer3::BnComposer {
43 using Capability = aidl::android::hardware::graphics::composer3::Capability;
44 using IComposerClient = aidl::android::hardware::graphics::composer3::IComposerClient;
45 using Hwc3PowerMode = aidl::android::hardware::graphics::composer3::PowerMode;
46
47 // begin IComposer overrides
48
dump(int dumpFd,const char ** args,uint32_t num_args)49 auto dump(int dumpFd, const char** args, uint32_t num_args) -> binder_status_t override {
50 UNIMPLEMENTED(WARNING);
51 ftl::ignore(dumpFd, args, num_args);
52 return static_cast<binder_status_t>(STATUS_NO_MEMORY);
53 }
54
createClient(std::shared_ptr<IComposerClient> * out_client)55 auto createClient(std::shared_ptr<IComposerClient>* out_client) -> ndk::ScopedAStatus override {
56 UNIMPLEMENTED(WARNING);
57 ftl::ignore(out_client);
58 return ndk::ScopedAStatus::fromServiceSpecificErrorWithMessage(
59 IComposer::EX_NO_RESOURCES, "Client failed to initialize");
60 }
61
getCapabilities(std::vector<Capability> * out_capabilities)62 auto getCapabilities(std::vector<Capability>* out_capabilities) -> ndk::ScopedAStatus override {
63 UNIMPLEMENTED(WARNING);
64 ftl::ignore(out_capabilities);
65 return ndk::ScopedAStatus::ok();
66 }
67
68 // end IComposer overrides
69 };
70
71 struct Hwc3Composer::Passkey final {};
72
getServiceName(std::string_view baseServiceName)73 auto Hwc3Composer::getServiceName(std::string_view baseServiceName) -> std::string {
74 return Hwc3ComposerImpl::makeServiceName(baseServiceName);
75 }
76
make()77 auto Hwc3Composer::make() -> base::expected<std::shared_ptr<Hwc3Composer>, std::string> {
78 using namespace std::string_literals;
79
80 auto composer = std::make_shared<Hwc3Composer>(Passkey{});
81 if (composer == nullptr) {
82 return base::unexpected("Failed to construct the Hwc3Composer instance."s);
83 }
84
85 if (auto result = composer->init(); !result) {
86 return base::unexpected("Failed to init the Hwc3Composer instance: "s + result.error());
87 }
88
89 return composer;
90 }
91
Hwc3Composer(Hwc3Composer::Passkey passkey)92 Hwc3Composer::Hwc3Composer(Hwc3Composer::Passkey passkey) {
93 ftl::ignore(passkey);
94 }
95
init()96 auto Hwc3Composer::init() -> base::expected<void, std::string> {
97 using namespace std::string_literals;
98
99 auto impl = ndk::SharedRefBase::make<Hwc3ComposerImpl>();
100 if (!impl) {
101 return base::unexpected("Failed to construct the Hwc3ComposerImpl instance."s);
102 }
103
104 mImpl = std::move(impl);
105
106 return {};
107 }
108
getComposer()109 auto Hwc3Composer::getComposer() -> std::shared_ptr<Hwc3IComposer> {
110 return mImpl;
111 }
112
addDisplay(const core::DisplayConfiguration & display)113 void Hwc3Composer::addDisplay(const core::DisplayConfiguration& display) {
114 UNIMPLEMENTED(WARNING);
115 ftl::ignore(display, mImpl);
116 }
117
removeDisplay(core::DisplayConfiguration::Id displayId)118 void Hwc3Composer::removeDisplay(core::DisplayConfiguration::Id displayId) {
119 UNIMPLEMENTED(WARNING);
120 ftl::ignore(displayId, mImpl);
121 }
122
123 } // namespace android::surfaceflinger::tests::end2end::test_framework::fake_hwc3
124