blob: af578e8e195594c168008667bfb2ee3644db6df1 [file] [log] [blame]
Chia-I Wu109571a2016-09-05 11:46:36 +08001/*
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 Wu109571a2016-09-05 11:46:36 +080019#include "Gralloc.h"
Chia-I Wu79d13ff2017-03-31 12:48:11 -070020#include "Gralloc0Allocator.h"
21#include "Gralloc1Allocator.h"
22
23#include <log/log.h>
Chia-I Wu109571a2016-09-05 11:46:36 +080024
25namespace android {
26namespace hardware {
27namespace graphics {
28namespace allocator {
29namespace V2_0 {
30namespace implementation {
31
Chia-I Wu109571a2016-09-05 11:46:36 +080032IAllocator* HIDL_FETCH_IAllocator(const char* /* name */) {
Chia-I Wue1768352016-12-19 12:56:54 +080033 const hw_module_t* module = nullptr;
Chia-I Wu109571a2016-09-05 11:46:36 +080034 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 Wu79d13ff2017-03-31 12:48:11 -070041 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 Wu109571a2016-09-05 11:46:36 +080049 }
Chia-I Wu109571a2016-09-05 11:46:36 +080050}
51
Chia-I Wu864c9f82017-12-15 14:57:46 -080052} // namespace implementation
53} // namespace V2_0
54} // namespace allocator
55} // namespace graphics
56} // namespace hardware
57} // namespace android