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.2/IComposer.h>
24 #include <composer-hal/2.1/Composer.h>
25 #include <composer-hal/2.2/ComposerClient.h>
26 
27 namespace android {
28 namespace hardware {
29 namespace graphics {
30 namespace composer {
31 namespace V2_2 {
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_1::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     ComposerImpl(std::unique_ptr<Hal> hal) : BaseType2_1(std::move(hal)) {}
45 
46    protected:
createClient()47     V2_1::IComposerClient* createClient() override {
48         auto client = ComposerClient::create(mHal.get());
49         if (!client) {
50             return nullptr;
51         }
52 
53         auto clientDestroyed = [this]() { onClientDestroyed(); };
54         client->setOnClientDestroyed(clientDestroyed);
55 
56         return client.release();
57     }
58 
59    private:
60     using BaseType2_1 = V2_1::hal::detail::ComposerImpl<Interface, Hal>;
61     using BaseType2_1::mHal;
62     using BaseType2_1::onClientDestroyed;
63 };
64 
65 }  // namespace detail
66 
67 using Composer = detail::ComposerImpl<IComposer, ComposerHal>;
68 
69 }  // namespace hal
70 }  // namespace V2_2
71 }  // namespace composer
72 }  // namespace graphics
73 }  // namespace hardware
74 }  // namespace android
75