Home | History | Annotate | Download | only in default
      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 
     19 #include "Gralloc.h"
     20 #include "Gralloc0Allocator.h"
     21 #include "Gralloc1Allocator.h"
     22 
     23 #include <log/log.h>
     24 
     25 namespace android {
     26 namespace hardware {
     27 namespace graphics {
     28 namespace allocator {
     29 namespace V2_0 {
     30 namespace implementation {
     31 
     32 IAllocator* HIDL_FETCH_IAllocator(const char* /* name */) {
     33     const hw_module_t* module = nullptr;
     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;
     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;
     49     }
     50 }
     51 
     52 } // namespace implementation
     53 } // namespace V2_0
     54 } // namespace allocator
     55 } // namespace graphics
     56 } // namespace hardware
     57 } // namespace android
     58