Skip to content

Commit 1160cdf

Browse files
manxiaoliangsysopenci
authored andcommitted
Remove composer3 hal diff patches frome utils repo.
Putting it to drm-hwcomposer master repo. Tracked-On: OAM-118438 Signed-off-by: manxiaoliang <xiaoliangx.man@intel.com>
1 parent 9858512 commit 1160cdf

21 files changed

+4307
-0
lines changed

hwc3-server/default/Android.bp

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// Copyright (C) 2022 The Android Open Source Project
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package {
16+
// See: http://go/android-license-faq
17+
// A large-scale-change added 'default_applicable_licenses' to import
18+
// all of the 'license_kinds' from "hardware_interfaces_license"
19+
// to get the below license kinds:
20+
// SPDX-license-identifier-Apache-2.0
21+
// default_applicable_licenses: ["hardware_interfaces_license"],
22+
}
23+
24+
cc_binary {
25+
name: "android.hardware.graphics.composer3-service.intel",
26+
relative_install_path: "hw",
27+
init_rc: ["android.hardware.graphics.composer3-service.intel.rc"],
28+
vendor: true,
29+
cflags:[
30+
"-Wall",
31+
"-Werror",
32+
"-DLOG_TAG=\"hwc3\"",
33+
],
34+
cppflags: [
35+
"-Wextra",
36+
"-Wunused",
37+
"-Wunreachable-code",
38+
"-Wno-sign-compare",
39+
"-Wno-unused-parameter",
40+
],
41+
local_include_dirs:[
42+
"include",
43+
"impl",
44+
],
45+
include_dirs: [
46+
],
47+
header_libs: [
48+
"android.hardware.graphics.composer3-command-buffer",
49+
],
50+
static_libs:[
51+
"libaidlcommonsupport",
52+
],
53+
shared_libs: [
54+
"android.hardware.graphics.composer@2.1-resources",
55+
"android.hardware.graphics.composer@2.2-resources",
56+
"android.hardware.graphics.composer3-V2-ndk",
57+
"libbase",
58+
"libbinder_ndk",
59+
"libcutils",
60+
"libhardware",
61+
"libhwc2on1adapter",
62+
"libhwc2onfbadapter",
63+
"libhardware_legacy",
64+
"liblog",
65+
"libsync",
66+
"libutils",
67+
],
68+
srcs: [
69+
"Composer.cpp",
70+
"ComposerClient.cpp",
71+
"ComposerCommandEngine.cpp",
72+
"impl/HalImpl.cpp",
73+
"impl/HwcLoader.cpp",
74+
"impl/ResourceManager.cpp",
75+
"service.cpp",
76+
],
77+
}
78+

hwc3-server/default/Composer.cpp

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
* Copyright (C) 2021 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+
#define ATRACE_TAG (ATRACE_TAG_GRAPHICS | ATRACE_TAG_HAL)
18+
19+
#include "Composer.h"
20+
21+
#include <android-base/logging.h>
22+
#include <android/binder_ibinder_platform.h>
23+
24+
#include "Util.h"
25+
26+
namespace aidl::android::hardware::graphics::composer3::impl {
27+
28+
ndk::ScopedAStatus Composer::createClient(std::shared_ptr<IComposerClient>* outClient) {
29+
DEBUG_FUNC();
30+
std::unique_lock<std::mutex> lock(mClientMutex);
31+
if (!waitForClientDestroyedLocked(lock)) {
32+
*outClient = nullptr;
33+
return TO_BINDER_STATUS(EX_NO_RESOURCES);
34+
}
35+
36+
auto client = ndk::SharedRefBase::make<ComposerClient>(mHal.get());
37+
if (!client || !client->init()) {
38+
*outClient = nullptr;
39+
return TO_BINDER_STATUS(EX_NO_RESOURCES);
40+
}
41+
42+
auto clientDestroyed = [this]() { onClientDestroyed(); };
43+
client->setOnClientDestroyed(clientDestroyed);
44+
45+
mClientAlive = true;
46+
*outClient = client;
47+
48+
return ndk::ScopedAStatus::ok();
49+
}
50+
51+
binder_status_t Composer::dump(int fd, const char** /*args*/, uint32_t /*numArgs*/) {
52+
std::string output;
53+
mHal->dumpDebugInfo(&output);
54+
write(fd, output.c_str(), output.size());
55+
return STATUS_OK;
56+
}
57+
58+
ndk::ScopedAStatus Composer::getCapabilities(std::vector<Capability>* caps) {
59+
DEBUG_FUNC();
60+
mHal->getCapabilities(caps);
61+
return ndk::ScopedAStatus::ok();
62+
}
63+
64+
bool Composer::waitForClientDestroyedLocked(std::unique_lock<std::mutex>& lock) {
65+
if (mClientAlive) {
66+
using namespace std::chrono_literals;
67+
68+
// In surface flinger we delete a composer client on one thread and
69+
// then create a new client on another thread. Although surface
70+
// flinger ensures the calls are made in that sequence (destroy and
71+
// then create), sometimes the calls land in the composer service
72+
// inverted (create and then destroy). Wait for a brief period to
73+
// see if the existing client is destroyed.
74+
LOG(DEBUG) << "waiting for previous client to be destroyed";
75+
mClientDestroyedCondition.wait_for(lock, 1s,
76+
[this]() -> bool { return !mClientAlive; });
77+
if (mClientAlive) {
78+
LOG(DEBUG) << "previous client was not destroyed";
79+
}
80+
}
81+
82+
return !mClientAlive;
83+
}
84+
85+
void Composer::onClientDestroyed() {
86+
std::lock_guard<std::mutex> lock(mClientMutex);
87+
mClientAlive = false;
88+
mClientDestroyedCondition.notify_all();
89+
}
90+
91+
::ndk::SpAIBinder Composer::createBinder() {
92+
auto binder = BnComposer::createBinder();
93+
AIBinder_setInheritRt(binder.get(), true);
94+
return binder;
95+
}
96+
97+
} // namespace aidl::android::hardware::graphics::composer3::impl
98+

hwc3-server/default/Composer.h

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (C) 2021 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+
#ifndef ANDROID_HWC_COMPOSER_H
18+
#define ANDROID_HWC_COMPOSER_H
19+
20+
#include <aidl/android/hardware/graphics/composer3/BnComposer.h>
21+
#include <utils/Mutex.h>
22+
23+
#include "include/IComposerHal.h"
24+
#include "ComposerClient.h"
25+
26+
namespace aidl::android::hardware::graphics::composer3::impl {
27+
28+
class Composer : public BnComposer {
29+
public:
30+
Composer(std::unique_ptr<IComposerHal> hal) : mHal(std::move(hal)) {}
31+
32+
binder_status_t dump(int fd, const char** args, uint32_t numArgs) override;
33+
34+
// compser3 api
35+
ndk::ScopedAStatus createClient(std::shared_ptr<IComposerClient>* client) override;
36+
ndk::ScopedAStatus getCapabilities(std::vector<Capability>* caps) override;
37+
38+
protected:
39+
ndk::SpAIBinder createBinder() override;
40+
41+
private:
42+
bool waitForClientDestroyedLocked(std::unique_lock<std::mutex>& lock);
43+
void onClientDestroyed();
44+
45+
const std::unique_ptr<IComposerHal> mHal;
46+
std::mutex mClientMutex;
47+
bool mClientAlive GUARDED_BY(mClientMutex) = false;
48+
std::condition_variable mClientDestroyedCondition;
49+
};
50+
51+
} // namespace aidl::android::hardware::graphics::composer3::impl
52+
#endif

0 commit comments

Comments
 (0)