2 * Copyright (C) 2015 The Android Open Source Project
3 * Copyright (C) 2015 NVIDIA Corporation.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <cutils/log.h>
20 #include <hardware/gralloc.h>
22 #include "drm_hwcomposer.h"
24 struct hwc_import_context {
25 const gralloc_module_t *gralloc_module;
28 int hwc_import_init(struct hwc_import_context **ctx)
31 struct hwc_import_context *import_ctx;
33 import_ctx = (struct hwc_import_context *)calloc(1,
36 ALOGE("Failed to allocate gralloc import context");
40 ret = hw_get_module(GRALLOC_HARDWARE_MODULE_ID,
41 (const hw_module_t **)&import_ctx->gralloc_module);
43 ALOGE("Failed to open gralloc module");
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);
60 int hwc_import_destroy(struct hwc_import_context *ctx)
66 int hwc_create_bo_from_import(int fd, hwc_import_context *ctx,
67 buffer_handle_t handle, struct hwc_drm_bo *bo)
69 const gralloc_module_t *g = ctx->gralloc_module;
72 return g->perform(g, GRALLOC_MODULE_PERFORM_DRM_IMPORT, fd, handle, bo);