driver.cpp revision 136b8eb38e98d96009799eee59d4ea0088544b54
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"
20#include "loader.h"
21
22namespace vulkan {
23namespace driver {
24
25namespace {
26
27hwvulkan_device_t* g_hwdevice = nullptr;
28
29}  // anonymous namespace
30
31bool Debuggable() {
32    return (prctl(PR_GET_DUMPABLE, 0, 0, 0, 0) >= 0);
33}
34
35bool 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
67}  // namespace driver
68}  // namespace vulkan
69