1
0
Fork 0

drm_hwcomposer: Support Nvidia gralloc

When using an Nvidia gralloc implementation, ask Nvidia gralloc to import the
buffer_handle_t to the hwcomposer's drm device.

Arguably, the code to perform the import would more naturally belong to
drm_hwcomposer than Nvidia gralloc.  But letting Nvidia gralloc do it has two
advantages.  First, drm_hwcomposer doesn't need to include vendor headers or
link against vendor libraries.  This means that it's easy to support both
drm_gralloc and Nvidia gralloc from the same default build of drm_hwcomposer.
Second, Nvidia gralloc will take care of properly setting up any vendor
specific metadata (such as tiling parameters) of the imported GEM handle.

Change-Id: I0f77fb301e7e0bff2a8cd7befeae4bc4892220ad
Reviewed-on: https://chrome-internal-review.googlesource.com/195115
Reviewed-by: Stéphane Marchesin <marcheu@google.com>
Commit-Queue: Stéphane Marchesin <marcheu@google.com>
Tested-by: Stéphane Marchesin <marcheu@google.com>
This commit is contained in:
Lauri Peltonen 2015-02-02 14:45:13 +02:00 committed by Stéphane Marchesin
parent 64717b22fe
commit ceaadea1bd
3 changed files with 83 additions and 2 deletions

View file

@ -17,7 +17,7 @@ LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# TODO: We should specify this in device.mk
BUFFER_IMPORTER := gralloc
BUFFER_IMPORTER := nvidia-gralloc
LOCAL_SHARED_LIBRARIES := \
libcutils \
@ -40,10 +40,14 @@ LOCAL_C_INCLUDES := \
LOCAL_CFLAGS :=
LOCAL_SRC_FILES := hwcomposer.cpp
ifeq ($(strip $(BUFFER_IMPORTER)),gralloc)
ifeq ($(strip $(BUFFER_IMPORTER)),drm-gralloc)
LOCAL_C_INCLUDES += external/drm_gralloc
LOCAL_SRC_FILES += hwcomposer_import_drm_gralloc.cpp
endif
ifeq ($(strip $(BUFFER_IMPORTER)),nvidia-gralloc)
LOCAL_C_INCLUDES += external/drm_gralloc
LOCAL_SRC_FILES += hwcomposer_import_nv_gralloc.cpp
endif
LOCAL_MODULE := hwcomposer.drm
LOCAL_MODULE_TAGS := optional

View file

@ -16,6 +16,10 @@
struct hwc_import_context;
enum {
GRALLOC_MODULE_PERFORM_DRM_IMPORT = 0xffeeff00
};
struct hwc_drm_bo {
uint32_t width;
uint32_t height;

View file

@ -0,0 +1,73 @@
/*
* Copyright (C) 2015 The Android Open Source Project
* Copyright (C) 2015 NVIDIA Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <cutils/log.h>
#include <hardware/gralloc.h>
#include "drm_hwcomposer.h"
struct hwc_import_context {
const gralloc_module_t *gralloc_module;
};
int hwc_import_init(struct hwc_import_context **ctx)
{
int ret;
struct hwc_import_context *import_ctx;
import_ctx = (struct hwc_import_context *)calloc(1,
sizeof(*import_ctx));
if (!ctx) {
ALOGE("Failed to allocate gralloc import context");
return -ENOMEM;
}
ret = hw_get_module(GRALLOC_HARDWARE_MODULE_ID,
(const hw_module_t **)&import_ctx->gralloc_module);
if (ret) {
ALOGE("Failed to open gralloc module");
goto err;
}
if (!strcasecmp(import_ctx->gralloc_module->common.author, "NVIDIA"))
ALOGW("Using non-NVIDIA gralloc module: %s\n",
import_ctx->gralloc_module->common.name);
*ctx = import_ctx;
return 0;
err:
free(import_ctx);
return ret;
}
int hwc_import_destroy(struct hwc_import_context *ctx)
{
free(ctx);
return 0;
}
int hwc_create_bo_from_import(int fd, hwc_import_context *ctx,
buffer_handle_t handle, struct hwc_drm_bo *bo)
{
const gralloc_module_t *g = ctx->gralloc_module;
bo->importer_fd = -1;
return g->perform(g, GRALLOC_MODULE_PERFORM_DRM_IMPORT, fd, handle, bo);
}