Chia-I Wu | 9d51816 | 2016-03-24 14:55:27 +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 | #include <sys/prctl.h> |
| 18 | |
| 19 | #include "driver.h" |
Chia-I Wu | 136b8eb | 2016-03-24 15:01:52 +0800 | [diff] [blame^] | 20 | #include "loader.h" |
Chia-I Wu | 9d51816 | 2016-03-24 14:55:27 +0800 | [diff] [blame] | 21 | |
| 22 | namespace vulkan { |
| 23 | namespace driver { |
| 24 | |
Chia-I Wu | 136b8eb | 2016-03-24 15:01:52 +0800 | [diff] [blame^] | 25 | namespace { |
| 26 | |
| 27 | hwvulkan_device_t* g_hwdevice = nullptr; |
| 28 | |
| 29 | } // anonymous namespace |
| 30 | |
Chia-I Wu | 9d51816 | 2016-03-24 14:55:27 +0800 | [diff] [blame] | 31 | bool Debuggable() { |
| 32 | return (prctl(PR_GET_DUMPABLE, 0, 0, 0, 0) >= 0); |
| 33 | } |
| 34 | |
Chia-I Wu | 136b8eb | 2016-03-24 15:01:52 +0800 | [diff] [blame^] | 35 | bool OpenHAL() { |
| 36 | if (g_hwdevice) |
| 37 | return true; |
| 38 | |
| 39 | const hwvulkan_module_t* module; |
| 40 | int result = |
| 41 | hw_get_module("vulkan", reinterpret_cast<const hw_module_t**>(&module)); |
| 42 | if (result != 0) { |
| 43 | ALOGE("failed to load vulkan hal: %s (%d)", strerror(-result), result); |
| 44 | return false; |
| 45 | } |
| 46 | |
| 47 | hwvulkan_device_t* device; |
| 48 | result = |
| 49 | module->common.methods->open(&module->common, HWVULKAN_DEVICE_0, |
| 50 | reinterpret_cast<hw_device_t**>(&device)); |
| 51 | if (result != 0) { |
| 52 | ALOGE("failed to open vulkan driver: %s (%d)", strerror(-result), |
| 53 | result); |
| 54 | return false; |
| 55 | } |
| 56 | |
| 57 | if (!InitLoader(device)) { |
| 58 | device->common.close(&device->common); |
| 59 | return false; |
| 60 | } |
| 61 | |
| 62 | g_hwdevice = device; |
| 63 | |
| 64 | return true; |
| 65 | } |
| 66 | |
Chia-I Wu | 9d51816 | 2016-03-24 14:55:27 +0800 | [diff] [blame] | 67 | } // namespace driver |
| 68 | } // namespace vulkan |