OSDN Git Service

drm_hwcomposer: Support Nvidia gralloc
[android-x86/external-drm_hwcomposer.git] / hwcomposer_import_nv_gralloc.cpp
1 /*
2  * Copyright (C) 2015 The Android Open Source Project
3  * Copyright (C) 2015 NVIDIA Corporation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18
19 #include <cutils/log.h>
20 #include <hardware/gralloc.h>
21
22 #include "drm_hwcomposer.h"
23
24 struct hwc_import_context {
25         const gralloc_module_t *gralloc_module;
26 };
27
28 int hwc_import_init(struct hwc_import_context **ctx)
29 {
30         int ret;
31         struct hwc_import_context *import_ctx;
32
33         import_ctx = (struct hwc_import_context *)calloc(1,
34                                 sizeof(*import_ctx));
35         if (!ctx) {
36                 ALOGE("Failed to allocate gralloc import context");
37                 return -ENOMEM;
38         }
39
40         ret = hw_get_module(GRALLOC_HARDWARE_MODULE_ID,
41                         (const hw_module_t **)&import_ctx->gralloc_module);
42         if (ret) {
43                 ALOGE("Failed to open gralloc module");
44                 goto err;
45         }
46
47         if (!strcasecmp(import_ctx->gralloc_module->common.author, "NVIDIA"))
48                 ALOGW("Using non-NVIDIA gralloc module: %s\n",
49                         import_ctx->gralloc_module->common.name);
50
51         *ctx = import_ctx;
52
53         return 0;
54
55 err:
56         free(import_ctx);
57         return ret;
58 }
59
60 int hwc_import_destroy(struct hwc_import_context *ctx)
61 {
62         free(ctx);
63         return 0;
64 }
65
66 int hwc_create_bo_from_import(int fd, hwc_import_context *ctx,
67                               buffer_handle_t handle, struct hwc_drm_bo *bo)
68 {
69         const gralloc_module_t *g = ctx->gralloc_module;
70
71         bo->importer_fd = -1;
72         return g->perform(g, GRALLOC_MODULE_PERFORM_DRM_IMPORT, fd, handle, bo);
73 }