Chia-I Wu | 109571a | 2016-09-05 11:46:36 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 LOG_TAG "GrallocPassthrough" |
| 18 | |
Chia-I Wu | 109571a | 2016-09-05 11:46:36 +0800 | [diff] [blame] | 19 | #include "Gralloc.h" |
Chia-I Wu | 79d13ff | 2017-03-31 12:48:11 -0700 | [diff] [blame] | 20 | #include "Gralloc0Allocator.h" |
| 21 | #include "Gralloc1Allocator.h" |
| 22 | |
| 23 | #include <log/log.h> |
Chia-I Wu | 109571a | 2016-09-05 11:46:36 +0800 | [diff] [blame] | 24 | |
| 25 | namespace android { |
| 26 | namespace hardware { |
| 27 | namespace graphics { |
| 28 | namespace allocator { |
| 29 | namespace V2_0 { |
| 30 | namespace implementation { |
| 31 | |
Chia-I Wu | 109571a | 2016-09-05 11:46:36 +0800 | [diff] [blame] | 32 | IAllocator* HIDL_FETCH_IAllocator(const char* /* name */) { |
Chia-I Wu | e176835 | 2016-12-19 12:56:54 +0800 | [diff] [blame] | 33 | const hw_module_t* module = nullptr; |
Chia-I Wu | 109571a | 2016-09-05 11:46:36 +0800 | [diff] [blame] | 34 | int err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module); |
| 35 | if (err) { |
| 36 | ALOGE("failed to get gralloc module"); |
| 37 | return nullptr; |
| 38 | } |
| 39 | |
| 40 | uint8_t major = (module->module_api_version >> 8) & 0xff; |
Chia-I Wu | 79d13ff | 2017-03-31 12:48:11 -0700 | [diff] [blame] | 41 | switch (major) { |
| 42 | case 1: |
| 43 | return new Gralloc1Allocator(module); |
| 44 | case 0: |
| 45 | return new Gralloc0Allocator(module); |
| 46 | default: |
| 47 | ALOGE("unknown gralloc module major version %d", major); |
| 48 | return nullptr; |
Chia-I Wu | 109571a | 2016-09-05 11:46:36 +0800 | [diff] [blame] | 49 | } |
Chia-I Wu | 109571a | 2016-09-05 11:46:36 +0800 | [diff] [blame] | 50 | } |
| 51 | |
Chia-I Wu | 864c9f8 | 2017-12-15 14:57:46 -0800 | [diff] [blame] | 52 | } // namespace implementation |
| 53 | } // namespace V2_0 |
| 54 | } // namespace allocator |
| 55 | } // namespace graphics |
| 56 | } // namespace hardware |
| 57 | } // namespace android |