blob: 09811a036a4ffe5347f6864f20555fe97e1a2192 [file] [log] [blame]
Chia-I Wu9d518162016-03-24 14:55:27 +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#include <sys/prctl.h>
18
19#include "driver.h"
Chia-I Wu136b8eb2016-03-24 15:01:52 +080020#include "loader.h"
Chia-I Wu9d518162016-03-24 14:55:27 +080021
22namespace vulkan {
23namespace driver {
24
Chia-I Wu136b8eb2016-03-24 15:01:52 +080025namespace {
26
27hwvulkan_device_t* g_hwdevice = nullptr;
28
29} // anonymous namespace
30
Chia-I Wu9d518162016-03-24 14:55:27 +080031bool Debuggable() {
32 return (prctl(PR_GET_DUMPABLE, 0, 0, 0, 0) >= 0);
33}
34
Chia-I Wu136b8eb2016-03-24 15:01:52 +080035bool 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 Wu9d518162016-03-24 14:55:27 +080067} // namespace driver
68} // namespace vulkan