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 "HwcLoader.h included without LOG_TAG" 21 #endif 22 23 #include <composer-hal/2.3/Composer.h> 24 #include <composer-hal/2.3/ComposerHal.h> 25 #include <composer-passthrough/2.2/HwcLoader.h> 26 #include <composer-passthrough/2.3/HwcHal.h> 27 28 namespace android { 29 namespace hardware { 30 namespace graphics { 31 namespace composer { 32 namespace V2_3 { 33 namespace passthrough { 34 35 class HwcLoader : public V2_2::passthrough::HwcLoader { 36 public: load()37 static IComposer* load() { 38 const hw_module_t* module = loadModule(); 39 if (!module) { 40 return nullptr; 41 } 42 43 auto hal = createHalWithAdapter(module); 44 if (!hal) { 45 return nullptr; 46 } 47 48 return createComposer(std::move(hal)).release(); 49 } 50 51 // create a ComposerHal instance createHal(const hw_module_t * module)52 static std::unique_ptr<hal::ComposerHal> createHal(const hw_module_t* module) { 53 auto hal = std::make_unique<HwcHal>(); 54 return hal->initWithModule(module) ? std::move(hal) : nullptr; 55 } 56 57 // create a ComposerHal instance, insert an adapter if necessary createHalWithAdapter(const hw_module_t * module)58 static std::unique_ptr<hal::ComposerHal> createHalWithAdapter(const hw_module_t* module) { 59 bool adapted; 60 hwc2_device_t* device = openDeviceWithAdapter(module, &adapted); 61 if (!device) { 62 return nullptr; 63 } 64 auto hal = std::make_unique<HwcHal>(); 65 return hal->initWithDevice(std::move(device), !adapted) ? std::move(hal) : nullptr; 66 } 67 68 // create an IComposer instance createComposer(std::unique_ptr<hal::ComposerHal> hal)69 static std::unique_ptr<IComposer> createComposer(std::unique_ptr<hal::ComposerHal> hal) { 70 return hal::Composer::create(std::move(hal)); 71 } 72 }; 73 74 } // namespace passthrough 75 } // namespace V2_3 76 } // namespace composer 77 } // namespace graphics 78 } // namespace hardware 79 } // namespace android 80