• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2018 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 #ifndef LOG_TAG
20 #warning "Composer.h included without LOG_TAG"
21 #endif
22 
23 #include <android/hardware/graphics/composer/2.3/IComposer.h>
24 #include <composer-hal/2.2/Composer.h>
25 #include <composer-hal/2.3/ComposerClient.h>
26 
27 namespace android {
28 namespace hardware {
29 namespace graphics {
30 namespace composer {
31 namespace V2_3 {
32 namespace hal {
33 
34 namespace detail {
35 
36 // ComposerImpl implements V2_*::IComposer on top of V2_*::ComposerHal
37 template <typename Interface, typename Hal>
38 class ComposerImpl : public V2_2::hal::detail::ComposerImpl<Interface, Hal> {
39    public:
create(std::unique_ptr<Hal> hal)40     static std::unique_ptr<ComposerImpl> create(std::unique_ptr<Hal> hal) {
41         return std::make_unique<ComposerImpl>(std::move(hal));
42     }
43 
ComposerImpl(std::unique_ptr<Hal> hal)44     explicit ComposerImpl(std::unique_ptr<Hal> hal) : BaseType2_2(std::move(hal)) {}
45 
46     // IComposer 2.3 interface
47 
createClient_2_3(IComposer::createClient_2_3_cb hidl_cb)48     Return<void> createClient_2_3(IComposer::createClient_2_3_cb hidl_cb) override {
49         std::unique_lock<std::mutex> lock(mClientMutex);
50         if (!waitForClientDestroyedLocked(lock)) {
51             hidl_cb(Error::NO_RESOURCES, nullptr);
52             return Void();
53         }
54 
55         sp<ComposerClient> client = ComposerClient::create(mHal.get()).release();
56         if (!client) {
57             hidl_cb(Error::NO_RESOURCES, nullptr);
58             return Void();
59         }
60 
61         auto clientDestroyed = [this]() { onClientDestroyed(); };
62         client->setOnClientDestroyed(clientDestroyed);
63 
64         mClient = client;
65         hidl_cb(Error::NONE, client);
66         return Void();
67     }
68 
69    private:
70     using BaseType2_2 = V2_2::hal::detail::ComposerImpl<Interface, Hal>;
71     using BaseType2_1 = V2_1::hal::detail::ComposerImpl<Interface, Hal>;
72 
73     using BaseType2_1::mClient;
74     using BaseType2_1::mClientMutex;
75     using BaseType2_1::mHal;
76     using BaseType2_1::onClientDestroyed;
77     using BaseType2_1::waitForClientDestroyedLocked;
78 };
79 
80 }  // namespace detail
81 
82 using Composer = detail::ComposerImpl<IComposer, ComposerHal>;
83 
84 }  // namespace hal
85 }  // namespace V2_3
86 }  // namespace composer
87 }  // namespace graphics
88 }  // namespace hardware
89 }  // namespace android
90