diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-04-05 14:08:31 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-04-11 07:46:53 +0000 |
commit | 6a4cabb866f66d4128a97cdc6d9d08ce074f1247 (patch) | |
tree | ab00f70a5e89278d6a0d16ff0c42578dc4d84a2d /chromium/third_party/minigbm | |
parent | e733310db58160074f574c429d48f8308c0afe17 (diff) | |
download | qtwebengine-chromium-6a4cabb866f66d4128a97cdc6d9d08ce074f1247.tar.gz |
BASELINE: Update Chromium to 57.0.2987.144
Change-Id: I29db402ff696c71a04c4dbaec822c2e53efe0267
Reviewed-by: Peter Varga <pvarga@inf.u-szeged.hu>
Diffstat (limited to 'chromium/third_party/minigbm')
37 files changed, 1551 insertions, 777 deletions
diff --git a/chromium/third_party/minigbm/BUILD.gn b/chromium/third_party/minigbm/BUILD.gn index d96d51fbe80..d8c2e928ef0 100644 --- a/chromium/third_party/minigbm/BUILD.gn +++ b/chromium/third_party/minigbm/BUILD.gn @@ -19,10 +19,6 @@ if (!use_system_minigbm) { include_dirs = [ "src" ] } - pkg_config("libdrm") { - packages = [ "libdrm" ] - } - shared_library("minigbm") { sources = [ "src/amdgpu.c", @@ -37,6 +33,7 @@ if (!use_system_minigbm) { "src/i915.c", "src/marvell.c", "src/mediatek.c", + "src/nouveau.c", "src/rockchip.c", "src/tegra.c", "src/udl.c", @@ -45,11 +42,11 @@ if (!use_system_minigbm) { ] configs -= [ "//build/config/compiler:chromium_code" ] - configs += [ - ":libdrm", - "//build/config/compiler:no_chromium_code", - ] + configs += [ "//build/config/compiler:no_chromium_code" ] + deps = [ + "//third_party/libdrm", + ] public_configs = [ ":minigbm_config" ] # Clients need this to pick up the shared library correctly. diff --git a/chromium/third_party/minigbm/OWNERS b/chromium/third_party/minigbm/OWNERS index f9c5878a0e5..afeec1c1d9e 100644 --- a/chromium/third_party/minigbm/OWNERS +++ b/chromium/third_party/minigbm/OWNERS @@ -1,2 +1,3 @@ marcheu@chromium.org spang@chromium.org +gurchetansingh@chromium.org diff --git a/chromium/third_party/minigbm/src/Makefile b/chromium/third_party/minigbm/src/Makefile index ccc26c7e8b6..32cbb572c46 100644 --- a/chromium/third_party/minigbm/src/Makefile +++ b/chromium/third_party/minigbm/src/Makefile @@ -8,8 +8,9 @@ PC_DEPS = libdrm PC_CFLAGS := $(shell $(PKG_CONFIG) --cflags $(PC_DEPS)) PC_LIBS := $(shell $(PKG_CONFIG) --libs $(PC_DEPS)) -CPPFLAGS += -std=c99 -D_GNU_SOURCE=1 -CFLAGS += -Wall -Wsign-compare -Wpointer-arith -Wcast-qual -Wcast-align +CPPFLAGS += -D_GNU_SOURCE=1 +CFLAGS += -std=c99 -Wall -Wsign-compare -Wpointer-arith -Wcast-qual \ + -Wcast-align -D_GNU_SOURCE=1 -D_FILE_OFFSET_BITS=64 ifdef DRV_AMDGPU CFLAGS += $(shell $(PKG_CONFIG) --cflags libdrm_amdgpu) diff --git a/chromium/third_party/minigbm/src/amdgpu.c b/chromium/third_party/minigbm/src/amdgpu.c index a9d6d4c22eb..5338713dc15 100644 --- a/chromium/third_party/minigbm/src/amdgpu.c +++ b/chromium/third_party/minigbm/src/amdgpu.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 The Chromium OS Authors. All rights reserved. + * Copyright 2016 The Chromium OS Authors. All rights reserved. * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ @@ -38,6 +38,19 @@ enum { FAMILY_LAST, }; +static struct supported_combination combos[5] = { + {DRM_FORMAT_ARGB8888, DRM_FORMAT_MOD_NONE, + BO_USE_CURSOR | BO_USE_LINEAR | BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN}, + {DRM_FORMAT_ARGB8888, DRM_FORMAT_MOD_NONE, + BO_USE_RENDERING | BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY}, + {DRM_FORMAT_XBGR8888, DRM_FORMAT_MOD_NONE, + BO_USE_RENDERING | BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY}, + {DRM_FORMAT_XRGB8888, DRM_FORMAT_MOD_NONE, + BO_USE_LINEAR | BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN}, + {DRM_FORMAT_XRGB8888, DRM_FORMAT_MOD_NONE, + BO_USE_RENDERING | BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY}, +}; + static int amdgpu_set_metadata(int fd, uint32_t handle, struct amdgpu_bo_metadata *info) { @@ -148,7 +161,7 @@ static int amdgpu_addrlib_compute(void *addrlib, uint32_t width, /* Set the requested tiling mode. */ addr_surf_info_in.tileMode = ADDR_TM_2D_TILED_THIN1; - if (usage & (DRV_BO_USE_CURSOR | DRV_BO_USE_LINEAR)) + if (usage & (BO_USE_CURSOR | BO_USE_LINEAR)) addr_surf_info_in.tileMode = ADDR_TM_LINEAR_ALIGNED; if (width <= 16 || height <= 16) addr_surf_info_in.tileMode = ADDR_TM_1D_TILED_THIN1; @@ -166,7 +179,7 @@ static int amdgpu_addrlib_compute(void *addrlib, uint32_t width, addr_surf_info_in.flags.noStencil = 1; /* Set the micro tile type. */ - if (usage & DRV_BO_USE_SCANOUT) + if (usage & BO_USE_SCANOUT) addr_surf_info_in.tileType = ADDR_DISPLAYABLE; else addr_surf_info_in.tileType = ADDR_NON_DISPLAYABLE; @@ -283,7 +296,8 @@ static int amdgpu_init(struct driver *drv) drv->priv = addrlib; - return 0; + drv_insert_combinations(drv, combos, ARRAY_SIZE(combos)); + return drv_add_kms_flags(drv); } static void amdgpu_close(struct driver *drv) @@ -338,21 +352,12 @@ static int amdgpu_bo_create(struct bo *bo, uint32_t width, uint32_t height, return ret; } -const struct backend backend_amdgpu = { +struct backend backend_amdgpu = { .name = "amdgpu", .init = amdgpu_init, .close = amdgpu_close, .bo_create = amdgpu_bo_create, .bo_destroy = drv_gem_bo_destroy, - .format_list = { - /* Linear support */ - {DRV_FORMAT_XRGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_LINEAR}, - {DRV_FORMAT_ARGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_LINEAR}, - /* Blocklinear support */ - {DRV_FORMAT_XRGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_RENDERING}, - {DRV_FORMAT_ARGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_RENDERING}, - {DRV_FORMAT_XBGR8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_RENDERING}, - } }; #endif diff --git a/chromium/third_party/minigbm/src/cirrus.c b/chromium/third_party/minigbm/src/cirrus.c index db4ad5b7924..b656c190f9c 100644 --- a/chromium/third_party/minigbm/src/cirrus.c +++ b/chromium/third_party/minigbm/src/cirrus.c @@ -1,23 +1,36 @@ /* - * Copyright (c) 2014 The Chromium OS Authors. All rights reserved. + * Copyright 2014 The Chromium OS Authors. All rights reserved. * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ #include "drv_priv.h" #include "helpers.h" +#include "util.h" -const struct backend backend_cirrus = +static struct supported_combination combos[3] = { + {DRM_FORMAT_ARGB8888, DRM_FORMAT_MOD_NONE, + BO_USE_CURSOR | BO_USE_LINEAR | BO_USE_RENDERING | BO_USE_SW_READ_OFTEN | + BO_USE_SW_WRITE_OFTEN | BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY}, + {DRM_FORMAT_RGB888, DRM_FORMAT_MOD_NONE, + BO_USE_LINEAR | BO_USE_RENDERING | BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN | + BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY}, + {DRM_FORMAT_XRGB8888, DRM_FORMAT_MOD_NONE, + BO_USE_CURSOR | BO_USE_LINEAR | BO_USE_RENDERING | BO_USE_SW_READ_OFTEN | + BO_USE_SW_WRITE_OFTEN | BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY}, +}; + +static int cirrus_init(struct driver *drv) +{ + drv_insert_combinations(drv, combos, ARRAY_SIZE(combos)); + return drv_add_kms_flags(drv); +} + +struct backend backend_cirrus = { .name = "cirrus", + .init = cirrus_init, .bo_create = drv_dumb_bo_create, .bo_destroy = drv_dumb_bo_destroy, .bo_map = drv_dumb_bo_map, - .format_list = { - {DRV_FORMAT_RGB888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_RENDERING}, - {DRV_FORMAT_XRGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_RENDERING}, - {DRV_FORMAT_XRGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_LINEAR}, - {DRV_FORMAT_ARGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_RENDERING}, - {DRV_FORMAT_ARGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_LINEAR}, - } }; diff --git a/chromium/third_party/minigbm/src/common.mk b/chromium/third_party/minigbm/src/common.mk index 21de50c937e..3d7e7d4674c 100644 --- a/chromium/third_party/minigbm/src/common.mk +++ b/chromium/third_party/minigbm/src/common.mk @@ -1,4 +1,4 @@ -# Copyright (c) 2012 The Chromium OS Authors. All rights reserved. +# Copyright 2012 The Chromium OS Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. # diff --git a/chromium/third_party/minigbm/src/cros_gralloc/Makefile b/chromium/third_party/minigbm/src/cros_gralloc/Makefile index 977d6375f92..27983553ef5 100644 --- a/chromium/third_party/minigbm/src/cros_gralloc/Makefile +++ b/chromium/third_party/minigbm/src/cros_gralloc/Makefile @@ -4,13 +4,15 @@ GRALLOC = gralloc.cros.so -SOURCES = $(wildcard *.cc) -SOURCES += $(wildcard ../*.c) +SRCS = $(wildcard *.cc) +SRCS += $(wildcard ../*.c) +SOURCES = $(filter-out ../gbm%, $(SRCS)) VPATH = $(dir $(SOURCES)) CPPFLAGS += -Wall -fPIC -Werror -flto CXXFLAGS += -std=c++11 +CFLAGS += -std=c99 LIBS += -shared -lcutils -lhardware -ldrm OBJS = $(foreach source, $(SOURCES), $(addsuffix .o, $(basename $(source)))) diff --git a/chromium/third_party/minigbm/src/cros_gralloc/cros_alloc_device.cc b/chromium/third_party/minigbm/src/cros_gralloc/cros_alloc_device.cc index 8e0dbc88e7e..97c8186f8c6 100644 --- a/chromium/third_party/minigbm/src/cros_gralloc/cros_alloc_device.cc +++ b/chromium/third_party/minigbm/src/cros_gralloc/cros_alloc_device.cc @@ -10,18 +10,37 @@ static struct cros_gralloc_bo *cros_gralloc_bo_create(struct driver *drv, int width, int height, int format, int usage) { + int32_t supported; uint64_t drv_usage; - drv_format_t drv_format; + uint32_t drv_format; struct cros_gralloc_bo *bo; drv_format = cros_gralloc_convert_format(format); drv_format = drv_resolve_format(drv, drv_format); drv_usage = cros_gralloc_convert_flags(usage); - if (!drv_is_format_supported(drv, drv_format, drv_usage)) { + supported = drv_is_combination_supported(drv, drv_format, drv_usage, + DRM_FORMAT_MOD_NONE); + + if (!supported && (drv_usage & BO_USE_SCANOUT)) { + drv_usage &= ~BO_USE_SCANOUT; + supported = drv_is_combination_supported(drv, drv_format, + drv_usage, + DRM_FORMAT_MOD_NONE); + } + + if (!supported && (drv_usage & BO_USE_RENDERING) && + (drv_usage && (BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN))) { + drv_usage &= ~BO_USE_RENDERING; + supported = drv_is_combination_supported(drv, drv_format, + drv_usage, + DRM_FORMAT_MOD_NONE); + } + + if (!supported) { cros_gralloc_error("Unsupported combination -- HAL format: %u, " - "HAL flags: %u, drv_format: %u, " - "drv_flags: %llu", format, usage, + "HAL flags: %u, drv_format: %u, " + "drv_flags: %llu", format, usage, drv_format, drv_usage); return NULL; } @@ -36,6 +55,11 @@ static struct cros_gralloc_bo *cros_gralloc_bo_create(struct driver *drv, return NULL; } + /* + * If there is a desire for more than one kernel buffer, this can be + * removed once the ArcCodec and Wayland service have the ability to + * send more than one fd. GL/Vulkan drivers may also have to modified. + */ if (drv_num_buffers_per_bo(bo->bo) != 1) { drv_bo_destroy(bo->bo); delete bo; @@ -50,31 +74,38 @@ static struct cros_gralloc_bo *cros_gralloc_bo_create(struct driver *drv, static struct cros_gralloc_handle *cros_gralloc_handle_from_bo(struct bo *bo) { + uint64_t mod; + size_t num_planes; struct cros_gralloc_handle *hnd; hnd = new cros_gralloc_handle(); memset(hnd, 0, sizeof(*hnd)); - hnd->base.version = sizeof(hnd->base); - hnd->base.numFds = 1; - hnd->base.numInts = num_ints(); + num_planes = drv_bo_get_num_planes(bo); - for (size_t p = 0; p < drv_bo_get_num_planes(bo); p++) { - hnd->data.strides[p] = drv_bo_get_plane_stride(bo, p); - hnd->data.offsets[p] = drv_bo_get_plane_offset(bo, p); - hnd->data.sizes[p] = drv_bo_get_plane_size(bo, p); + hnd->base.version = sizeof(hnd->base); + hnd->base.numFds = num_planes; + hnd->base.numInts = num_ints_handle() - num_planes; + + for (size_t p = 0; p < num_planes; p++) { + hnd->fds[p] = drv_bo_get_plane_fd(bo, p); + hnd->strides[p] = drv_bo_get_plane_stride(bo, p); + hnd->offsets[p] = drv_bo_get_plane_offset(bo, p); + hnd->sizes[p] = drv_bo_get_plane_size(bo, p); + + mod = drv_bo_get_plane_format_modifier(bo, p); + hnd->format_modifiers[p] = static_cast<uint32_t>(mod >> 32); + hnd->format_modifiers[p+1] = static_cast<uint32_t>(mod); } - hnd->data.fds[0] = drv_bo_get_plane_fd(bo, 0); - hnd->data.width = drv_bo_get_width(bo); - hnd->data.height = drv_bo_get_height(bo); - hnd->data.format = drv_bo_get_format(bo); + hnd->width = drv_bo_get_width(bo); + hnd->height = drv_bo_get_height(bo); + hnd->format = drv_bo_get_format(bo); hnd->magic = cros_gralloc_magic(); - hnd->registrations = 0; - hnd->pixel_stride = hnd->data.strides[0]; - hnd->pixel_stride /= drv_stride_from_format(hnd->data.format, 1, 0); + hnd->pixel_stride = hnd->strides[0]; + hnd->pixel_stride /= drv_stride_from_format(hnd->format, 1, 0); return hnd; } @@ -90,13 +121,13 @@ static int cros_gralloc_alloc(alloc_device_t *dev, int w, int h, int format, return CROS_GRALLOC_ERROR_NO_RESOURCES; auto hnd = cros_gralloc_handle_from_bo(bo->bo); - hnd->format = static_cast<int32_t>(format); + hnd->droid_format = static_cast<int32_t>(format); hnd->usage = static_cast<int32_t>(usage); - hnd->bo = reinterpret_cast<uint64_t>(bo); + mod->handles[hnd].registrations = 0; + mod->handles[hnd].bo = bo; bo->hnd = hnd; - mod->handles.insert(reinterpret_cast<uint64_t>(&hnd->base)); mod->buffers[drv_bo_get_plane_handle(bo->bo, 0).u32] = bo; *stride = static_cast<int>(hnd->pixel_stride); @@ -122,7 +153,7 @@ static int cros_gralloc_free(alloc_device_t *dev, buffer_handle_t handle) return CROS_GRALLOC_ERROR_BAD_HANDLE; } - if (hnd->registrations > 0) { + if (mod->handles[hnd].registrations > 0) { cros_gralloc_error("Deallocating before unregistering."); return CROS_GRALLOC_ERROR_BAD_HANDLE; } diff --git a/chromium/third_party/minigbm/src/cros_gralloc/cros_gralloc.h b/chromium/third_party/minigbm/src/cros_gralloc/cros_gralloc.h index 796f4f73dcf..6cd98dd2f48 100644 --- a/chromium/third_party/minigbm/src/cros_gralloc/cros_gralloc.h +++ b/chromium/third_party/minigbm/src/cros_gralloc/cros_gralloc.h @@ -20,11 +20,16 @@ struct cros_gralloc_bo { void *map_data; }; +struct handle_info { + cros_gralloc_bo *bo; + int32_t registrations; +}; + struct cros_gralloc_module { gralloc_module_t base; struct driver *drv; std::mutex mutex; - std::unordered_set<uint64_t> handles; + std::unordered_map<cros_gralloc_handle*, handle_info> handles; std::unordered_map<uint32_t, cros_gralloc_bo*> buffers; }; diff --git a/chromium/third_party/minigbm/src/cros_gralloc/cros_gralloc_handle.h b/chromium/third_party/minigbm/src/cros_gralloc/cros_gralloc_handle.h index a173aee8d58..63b9da9f909 100644 --- a/chromium/third_party/minigbm/src/cros_gralloc/cros_gralloc_handle.h +++ b/chromium/third_party/minigbm/src/cros_gralloc/cros_gralloc_handle.h @@ -10,19 +10,27 @@ #include <cutils/native_handle.h> #include <cstdint> -#include "../drv.h" +#define DRV_MAX_PLANES 4 + +/* + * Only use 32-bit integers in the handle. This guarantees that the handle is + * densely packed (i.e, the compiler does not insert any padding). + */ struct cros_gralloc_handle { native_handle_t base; - drv_import_fd_data data; + int32_t fds[DRV_MAX_PLANES]; + uint32_t strides[DRV_MAX_PLANES]; + uint32_t offsets[DRV_MAX_PLANES]; + uint32_t sizes[DRV_MAX_PLANES]; + uint32_t format_modifiers[2 * DRV_MAX_PLANES]; + uint32_t width; + uint32_t height; + uint32_t format; /* DRM format */ uint32_t magic; uint32_t pixel_stride; - int32_t format, usage; /* Android format and usage. */ - uint64_t bo; /* Pointer to cros_gralloc_bo. */ - int32_t registrations; /* - * Number of times (*register)() has been - * called on this handle. - */ + int32_t droid_format; + int32_t usage; /* Android usage. */ }; #endif diff --git a/chromium/third_party/minigbm/src/cros_gralloc/cros_gralloc_helpers.cc b/chromium/third_party/minigbm/src/cros_gralloc/cros_gralloc_helpers.cc index a6fd3eae3f4..afb1a96dcef 100644 --- a/chromium/third_party/minigbm/src/cros_gralloc/cros_gralloc_helpers.cc +++ b/chromium/third_party/minigbm/src/cros_gralloc/cros_gralloc_helpers.cc @@ -13,50 +13,50 @@ uint64_t cros_gralloc_convert_flags(int flags) { - uint64_t usage = DRV_BO_USE_NONE; + uint64_t usage = BO_USE_NONE; if (flags & GRALLOC_USAGE_CURSOR) - usage |= DRV_BO_USE_CURSOR; + usage |= BO_USE_NONE; if ((flags & sw_read()) == GRALLOC_USAGE_SW_READ_RARELY) - usage |= DRV_BO_USE_SW_READ_RARELY; + usage |= BO_USE_SW_READ_RARELY; if ((flags & sw_read()) == GRALLOC_USAGE_SW_READ_OFTEN) - usage |= DRV_BO_USE_SW_READ_OFTEN; + usage |= BO_USE_SW_READ_OFTEN; if ((flags & sw_write()) == GRALLOC_USAGE_SW_WRITE_RARELY) - usage |= DRV_BO_USE_SW_WRITE_RARELY; + usage |= BO_USE_SW_WRITE_RARELY; if ((flags & sw_write()) == GRALLOC_USAGE_SW_WRITE_OFTEN) - usage |= DRV_BO_USE_SW_WRITE_OFTEN; + usage |= BO_USE_SW_WRITE_OFTEN; if (flags & GRALLOC_USAGE_HW_TEXTURE) - usage |= DRV_BO_USE_RENDERING; + usage |= BO_USE_RENDERING; if (flags & GRALLOC_USAGE_HW_RENDER) - usage |= DRV_BO_USE_RENDERING; + usage |= BO_USE_RENDERING; if (flags & GRALLOC_USAGE_HW_2D) - usage |= DRV_BO_USE_RENDERING; + usage |= BO_USE_RENDERING; if (flags & GRALLOC_USAGE_HW_COMPOSER) /* HWC wants to use display hardware, but can defer to OpenGL. */ - usage |= DRV_BO_USE_SCANOUT | DRV_BO_USE_RENDERING; + usage |= BO_USE_SCANOUT | BO_USE_RENDERING; if (flags & GRALLOC_USAGE_HW_FB) - usage |= DRV_BO_USE_SCANOUT; + usage |= BO_USE_SCANOUT | BO_USE_RENDERING; if (flags & GRALLOC_USAGE_EXTERNAL_DISP) /* We're ignoring this flag until we decide what to with display link */ - usage |= DRV_BO_USE_NONE; + usage |= BO_USE_NONE; if (flags & GRALLOC_USAGE_PROTECTED) - usage |= DRV_BO_USE_PROTECTED; + usage |= BO_USE_PROTECTED; if (flags & GRALLOC_USAGE_HW_VIDEO_ENCODER) /*HACK: See b/30054495 */ - usage |= DRV_BO_USE_SW_READ_OFTEN; + usage |= BO_USE_SW_READ_OFTEN; if (flags & GRALLOC_USAGE_HW_CAMERA_WRITE) - usage |= DRV_BO_USE_HW_CAMERA_WRITE; + usage |= BO_USE_HW_CAMERA_WRITE; if (flags & GRALLOC_USAGE_HW_CAMERA_READ) - usage |= DRV_BO_USE_HW_CAMERA_READ; + usage |= BO_USE_HW_CAMERA_READ; if (flags & GRALLOC_USAGE_HW_CAMERA_ZSL) - usage |= DRV_BO_USE_HW_CAMERA_ZSL; + usage |= BO_USE_HW_CAMERA_ZSL; if (flags & GRALLOC_USAGE_RENDERSCRIPT) - usage |= DRV_BO_USE_RENDERSCRIPT; + usage |= BO_USE_RENDERSCRIPT; return usage; } -drv_format_t cros_gralloc_convert_format(int format) +uint32_t cros_gralloc_convert_format(int format) { /* * Conversion from HAL to fourcc-based DRV formats based on @@ -65,30 +65,36 @@ drv_format_t cros_gralloc_convert_format(int format) switch (format) { case HAL_PIXEL_FORMAT_BGRA_8888: - return DRV_FORMAT_ARGB8888; + return DRM_FORMAT_ARGB8888; case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED: - return DRV_FORMAT_FLEX_IMPLEMENTATION_DEFINED; + return DRM_FORMAT_FLEX_IMPLEMENTATION_DEFINED; case HAL_PIXEL_FORMAT_RGB_565: - return DRV_FORMAT_RGB565; + return DRM_FORMAT_RGB565; case HAL_PIXEL_FORMAT_RGB_888: - return DRV_FORMAT_RGB888; + return DRM_FORMAT_RGB888; case HAL_PIXEL_FORMAT_RGBA_8888: - return DRV_FORMAT_ABGR8888; + return DRM_FORMAT_ABGR8888; case HAL_PIXEL_FORMAT_RGBX_8888: - return DRV_FORMAT_XBGR8888; + return DRM_FORMAT_XBGR8888; case HAL_PIXEL_FORMAT_YCbCr_420_888: - return DRV_FORMAT_FLEX_YCbCr_420_888; + return DRM_FORMAT_FLEX_YCbCr_420_888; case HAL_PIXEL_FORMAT_YV12: - return DRV_FORMAT_YVU420; + return DRM_FORMAT_YVU420; } - return DRV_FORMAT_NONE; + return DRM_FORMAT_NONE; } static int32_t cros_gralloc_query_rendernode(struct driver **drv, - const char *name) + const char *undesired) { - /* TODO(gsingh): Enable render nodes on udl/evdi. */ + /* + * Create a driver from rendernode while filtering out + * the specified undesired driver. + * + * TODO(gsingh): Enable render nodes on udl/evdi. + */ + int fd; drmVersionPtr version; char const *str = "%s/renderD%d"; @@ -109,8 +115,10 @@ static int32_t cros_gralloc_query_rendernode(struct driver **drv, continue; version = drmGetVersion(fd); + if (!version) + continue; - if (version && name && !strcmp(version->name, name)) { + if (undesired && !strcmp(version->name, undesired)) { drmFreeVersion(version); continue; } @@ -128,11 +136,11 @@ static int32_t cros_gralloc_query_rendernode(struct driver **drv, int32_t cros_gralloc_rendernode_open(struct driver **drv) { int32_t ret; - ret = cros_gralloc_query_rendernode(drv, NULL); + ret = cros_gralloc_query_rendernode(drv, "vgem"); - /* Look for vgem driver if no hardware is found. */ + /* Allow vgem driver if no hardware is found. */ if (ret) - ret = cros_gralloc_query_rendernode(drv, "vgem"); + ret = cros_gralloc_query_rendernode(drv, NULL); return ret; } @@ -148,9 +156,11 @@ int32_t cros_gralloc_validate_handle(struct cros_gralloc_handle *hnd) void cros_gralloc_log(const char *prefix, const char *file, int line, const char *format, ...) { + char buf[50]; + snprintf(buf, sizeof(buf), "[%s:%s(%d)]", prefix, basename(file), line); + va_list args; va_start(args, format); - ALOGE("%s - [%s(%d)]", prefix, basename(file), line); - __android_log_vprint(ANDROID_LOG_ERROR, prefix, format, args); + __android_log_vprint(ANDROID_LOG_ERROR, buf, format, args); va_end(args); } diff --git a/chromium/third_party/minigbm/src/cros_gralloc/cros_gralloc_helpers.h b/chromium/third_party/minigbm/src/cros_gralloc/cros_gralloc_helpers.h index 93f12fde3f0..7ba3a9a7033 100644 --- a/chromium/third_party/minigbm/src/cros_gralloc/cros_gralloc_helpers.h +++ b/chromium/third_party/minigbm/src/cros_gralloc/cros_gralloc_helpers.h @@ -7,6 +7,7 @@ #ifndef CROS_GRALLOC_HELPERS_H #define CROS_GRALLOC_HELPERS_H +#include "../drv.h" #include "cros_gralloc_handle.h" #include <hardware/gralloc.h> @@ -44,14 +45,9 @@ constexpr uint32_t cros_gralloc_magic(void) return 0xABCDDCBA; } -constexpr uint32_t num_ints(void) +constexpr uint32_t num_ints_handle() { - /* - * numFds in our case is one. Subtract that from our numInts - * calculation. - */ - return ((sizeof(struct cros_gralloc_handle) - - offsetof(cros_gralloc_handle, data)) / sizeof(int)) - 1; + return ((sizeof(struct cros_gralloc_handle)) / sizeof(int)); } constexpr uint32_t sw_access(void) @@ -71,7 +67,7 @@ constexpr uint32_t sw_write(void) uint64_t cros_gralloc_convert_flags(int flags); -drv_format_t cros_gralloc_convert_format(int format); +uint32_t cros_gralloc_convert_format(int format); int32_t cros_gralloc_rendernode_open(struct driver **drv); @@ -84,7 +80,7 @@ void cros_gralloc_log(const char *prefix, const char *file, int line, #define cros_gralloc_error(...) \ do { \ - cros_gralloc_log("cros_gralloc_error", __FILE__, \ + cros_gralloc_log("CROS_GRALLOC_ERROR", __FILE__, \ __LINE__, __VA_ARGS__); \ } while (0) diff --git a/chromium/third_party/minigbm/src/cros_gralloc/cros_gralloc_module.cc b/chromium/third_party/minigbm/src/cros_gralloc/cros_gralloc_module.cc index 59467419fd9..470648c322b 100644 --- a/chromium/third_party/minigbm/src/cros_gralloc/cros_gralloc_module.cc +++ b/chromium/third_party/minigbm/src/cros_gralloc/cros_gralloc_module.cc @@ -13,12 +13,10 @@ int cros_gralloc_validate_reference(struct cros_gralloc_module *mod, struct cros_gralloc_handle *hnd, struct cros_gralloc_bo **bo) { - uint64_t key = reinterpret_cast<uint64_t>(&hnd->base); - - if (!mod->handles.count(key)) + if (!mod->handles.count(hnd)) return CROS_GRALLOC_ERROR_BAD_HANDLE; - *bo = reinterpret_cast<cros_gralloc_bo*>(hnd->bo); + *bo = mod->handles[hnd].bo; return CROS_GRALLOC_ERROR_NONE; } @@ -35,6 +33,7 @@ int cros_gralloc_decrement_reference_count(struct cros_gralloc_module *mod, drv_bo_destroy(bo->bo); if (bo->hnd) { + mod->handles.erase(bo->hnd); native_handle_close(&bo->hnd->base); delete bo->hnd; } @@ -68,11 +67,11 @@ static int cros_gralloc_register_buffer(struct gralloc_module_t const* module, if (!cros_gralloc_validate_reference(mod, hnd, &bo)) { bo->refcount++; - hnd->registrations++; + mod->handles[hnd].registrations++; return CROS_GRALLOC_ERROR_NONE; } - if (drmPrimeFDToHandle(drv_get_fd(mod->drv), hnd->data.fds[0], &id)) { + if (drmPrimeFDToHandle(drv_get_fd(mod->drv), hnd->fds[0], &id)) { cros_gralloc_error("drmPrimeFDToHandle failed."); return CROS_GRALLOC_ERROR_BAD_HANDLE; } @@ -80,13 +79,26 @@ static int cros_gralloc_register_buffer(struct gralloc_module_t const* module, if (mod->buffers.count(id)) { bo = mod->buffers[id]; bo->refcount++; - hnd->bo = reinterpret_cast<uint64_t>(bo); } else { - hnd->data.fds[1] = hnd->data.fds[2] = hnd->data.fds[3] - = hnd->data.fds[0]; + struct drv_import_fd_data data; + size_t num_planes = drv_num_planes_from_format(hnd->format); + + data.format = hnd->format; + data.width = hnd->width; + data.height = hnd->height; + for (size_t p = 0; p < num_planes; p++) { + data.fds[p] = hnd->fds[p]; + data.strides[p] = hnd->strides[p]; + data.offsets[p] = hnd->offsets[p]; + data.sizes[p] = hnd->sizes[p]; + data.format_modifiers[p] = static_cast<uint64_t> + (hnd->format_modifiers[p]) << 32; + data.format_modifiers[p] |= hnd->format_modifiers[p+1]; + } + bo = new cros_gralloc_bo(); - bo->bo = drv_bo_import(mod->drv, &hnd->data); + bo->bo = drv_bo_import(mod->drv, &data); if (!bo->bo) { delete bo; return CROS_GRALLOC_ERROR_NO_RESOURCES; @@ -96,11 +108,10 @@ static int cros_gralloc_register_buffer(struct gralloc_module_t const* module, mod->buffers[id] = bo; bo->refcount = 1; - hnd->bo = reinterpret_cast<uint64_t>(bo); } - hnd->registrations = 1; - mod->handles.insert(reinterpret_cast<uint64_t>(&hnd->base)); + mod->handles[hnd].bo = bo; + mod->handles[hnd].registrations = 1; return CROS_GRALLOC_ERROR_NONE; } @@ -123,15 +134,15 @@ static int cros_gralloc_unregister_buffer(struct gralloc_module_t const* module, return CROS_GRALLOC_ERROR_BAD_HANDLE; } - if (hnd->registrations <= 0) { + if (mod->handles[hnd].registrations <= 0) { cros_gralloc_error("Handle not registered."); return CROS_GRALLOC_ERROR_BAD_HANDLE; } - hnd->registrations--; + mod->handles[hnd].registrations--; - if (!hnd->registrations) - mod->handles.erase(reinterpret_cast<uint64_t>(&hnd->base)); + if (!mod->handles[hnd].registrations) + mod->handles.erase(hnd); return cros_gralloc_decrement_reference_count(mod, bo); } @@ -155,8 +166,9 @@ static int cros_gralloc_lock(struct gralloc_module_t const* module, return CROS_GRALLOC_ERROR_BAD_HANDLE; } - if (hnd->format == HAL_PIXEL_FORMAT_YCbCr_420_888) { - cros_gralloc_error("YUV format not compatible."); + if ((hnd->droid_format == HAL_PIXEL_FORMAT_YCbCr_420_888)) { + cros_gralloc_error("HAL_PIXEL_FORMAT_YCbCr_*_888 format not " + "compatible."); return CROS_GRALLOC_ERROR_BAD_HANDLE; } @@ -241,13 +253,13 @@ static int cros_gralloc_perform(struct gralloc_module_t const* module, break; case GRALLOC_DRM_GET_FORMAT: out_format = va_arg(args, int32_t *); - *out_format = hnd->format; + *out_format = hnd->droid_format; break; case GRALLOC_DRM_GET_DIMENSIONS: out_width = va_arg(args, uint32_t *); out_height = va_arg(args, uint32_t *); - *out_width = hnd->data.width; - *out_height = hnd->data.height; + *out_width = hnd->width; + *out_height = hnd->height; break; case GRALLOC_DRM_GET_BACKING_STORE: out_store = va_arg(args, uint64_t *); @@ -284,7 +296,8 @@ static int cros_gralloc_lock_ycbcr(struct gralloc_module_t const* module, return CROS_GRALLOC_ERROR_BAD_HANDLE; } - if ((hnd->format != HAL_PIXEL_FORMAT_YCbCr_420_888)) { + if ((hnd->droid_format != HAL_PIXEL_FORMAT_YCbCr_420_888) && + (hnd->droid_format != HAL_PIXEL_FORMAT_YV12)) { cros_gralloc_error("Non-YUV format not compatible."); return CROS_GRALLOC_ERROR_BAD_HANDLE; } @@ -305,8 +318,8 @@ static int cros_gralloc_lock_ycbcr(struct gralloc_module_t const* module, for (size_t p = 0; p < drv_bo_get_num_planes(bo->bo); p++) offsets[p] = drv_bo_get_plane_offset(bo->bo, p); - switch (hnd->data.format) { - case DRV_FORMAT_NV12: + switch (hnd->format) { + case DRM_FORMAT_NV12: ycbcr->y = addr; ycbcr->cb = addr + offsets[1]; ycbcr->cr = addr + offsets[1] + 1; @@ -314,7 +327,7 @@ static int cros_gralloc_lock_ycbcr(struct gralloc_module_t const* module, ycbcr->cstride = drv_bo_get_plane_stride(bo->bo, 1); ycbcr->chroma_step = 2; break; - case DRV_FORMAT_YVU420: + case DRM_FORMAT_YVU420: ycbcr->y = addr; ycbcr->cb = addr + offsets[2]; ycbcr->cr = addr + offsets[1]; @@ -322,7 +335,7 @@ static int cros_gralloc_lock_ycbcr(struct gralloc_module_t const* module, ycbcr->cstride = drv_bo_get_plane_stride(bo->bo, 1); ycbcr->chroma_step = 1; break; - case DRV_FORMAT_UYVY: + case DRM_FORMAT_UYVY: ycbcr->y = addr + 1; ycbcr->cb = addr; ycbcr->cr = addr + 2; diff --git a/chromium/third_party/minigbm/src/drv.c b/chromium/third_party/minigbm/src/drv.c index 3f9ecaee6bc..b4df6a53186 100644 --- a/chromium/third_party/minigbm/src/drv.c +++ b/chromium/third_party/minigbm/src/drv.c @@ -1,9 +1,10 @@ /* - * Copyright (c) 2016 The Chromium OS Authors. All rights reserved. + * Copyright 2016 The Chromium OS Authors. All rights reserved. * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ #include <assert.h> +#include <errno.h> #include <fcntl.h> #include <pthread.h> #include <stdint.h> @@ -35,6 +36,7 @@ extern struct backend backend_marvell; #ifdef DRV_MEDIATEK extern struct backend backend_mediatek; #endif +extern struct backend backend_nouveau; #ifdef DRV_ROCKCHIP extern struct backend backend_rockchip; #endif @@ -74,6 +76,7 @@ static struct backend *drv_get_backend(int fd) #ifdef DRV_MEDIATEK &backend_mediatek, #endif + &backend_nouveau, #ifdef DRV_ROCKCHIP &backend_rockchip, #endif @@ -111,7 +114,7 @@ struct driver *drv_create(int fd) if (!drv->backend) goto free_driver; - if (pthread_mutex_init(&drv->table_lock, NULL)) + if (pthread_mutex_init(&drv->driver_lock, NULL)) goto free_driver; drv->buffer_table = drmHashCreate(); @@ -122,6 +125,8 @@ struct driver *drv_create(int fd) if (!drv->map_table) goto free_buffer_table; + LIST_INITHEAD(&drv->backend->combinations); + if (drv->backend->init) { ret = drv->backend->init(drv); if (ret) @@ -135,7 +140,7 @@ free_map_table: free_buffer_table: drmHashDestroy(drv->buffer_table); free_lock: - pthread_mutex_destroy(&drv->table_lock); + pthread_mutex_destroy(&drv->driver_lock); free_driver: free(drv); return NULL; @@ -143,13 +148,23 @@ free_driver: void drv_destroy(struct driver *drv) { + pthread_mutex_lock(&drv->driver_lock); + if (drv->backend->close) drv->backend->close(drv); - pthread_mutex_destroy(&drv->table_lock); drmHashDestroy(drv->buffer_table); drmHashDestroy(drv->map_table); + list_for_each_entry_safe(struct combination_list_element, elem, + &drv->backend->combinations, link) { + LIST_DEL(&elem->link); + free(elem); + } + + pthread_mutex_unlock(&drv->driver_lock); + pthread_mutex_destroy(&drv->driver_lock); + free(drv); } @@ -164,21 +179,18 @@ drv_get_name(struct driver *drv) return drv->backend->name; } -int drv_is_format_supported(struct driver *drv, drv_format_t format, - uint64_t usage) +int drv_is_combination_supported(struct driver *drv, uint32_t format, + uint64_t usage, uint64_t modifier) { - unsigned int i; - if (format == DRV_FORMAT_NONE || usage == DRV_BO_USE_NONE) + if (format == DRM_FORMAT_NONE || usage == BO_USE_NONE) return 0; - for (i = 0 ; i < ARRAY_SIZE(drv->backend->format_list); i++) - { - if (!drv->backend->format_list[i].format) - break; - - if (drv->backend->format_list[i].format == format && - (drv->backend->format_list[i].usage & usage) == usage) + list_for_each_entry(struct combination_list_element, elem, + &drv->backend->combinations, link) { + if (format == elem->combination.format && + usage == (elem->combination.usage & usage) && + modifier == elem->combination.modifier) return 1; } @@ -186,7 +198,7 @@ int drv_is_format_supported(struct driver *drv, drv_format_t format, } struct bo *drv_bo_new(struct driver *drv, uint32_t width, uint32_t height, - drv_format_t format) + uint32_t format) { struct bo *bo; @@ -210,7 +222,7 @@ struct bo *drv_bo_new(struct driver *drv, uint32_t width, uint32_t height, } struct bo *drv_bo_create(struct driver *drv, uint32_t width, uint32_t height, - drv_format_t format, uint64_t flags) + uint32_t format, uint64_t flags) { int ret; size_t plane; @@ -228,23 +240,61 @@ struct bo *drv_bo_create(struct driver *drv, uint32_t width, uint32_t height, return NULL; } - pthread_mutex_lock(&drv->table_lock); + pthread_mutex_lock(&drv->driver_lock); for (plane = 0; plane < bo->num_planes; plane++) drv_increment_reference_count(drv, bo, plane); - pthread_mutex_unlock(&drv->table_lock); + pthread_mutex_unlock(&drv->driver_lock); return bo; } +struct bo *drv_bo_create_with_modifiers(struct driver *drv, + uint32_t width, uint32_t height, + uint32_t format, + const uint64_t *modifiers, uint32_t count) +{ + int ret; + size_t plane; + struct bo *bo; + + if (!drv->backend->bo_create_with_modifiers) { + errno = ENOENT; + return NULL; + } + + bo = drv_bo_new(drv, width, height, format); + + if (!bo) + return NULL; + + ret = drv->backend->bo_create_with_modifiers(bo, width, height, + format, modifiers, count); + + if (ret) { + free(bo); + return NULL; + } + + pthread_mutex_lock(&drv->driver_lock); + + for (plane = 0; plane < bo->num_planes; plane++) + drv_increment_reference_count(drv, bo, plane); + + pthread_mutex_unlock(&drv->driver_lock); + + return bo; +} + + void drv_bo_destroy(struct bo *bo) { size_t plane; uintptr_t total = 0; struct driver *drv = bo->drv; - pthread_mutex_lock(&drv->table_lock); + pthread_mutex_lock(&drv->driver_lock); for (plane = 0; plane < bo->num_planes; plane++) drv_decrement_reference_count(drv, bo, plane); @@ -252,7 +302,7 @@ void drv_bo_destroy(struct bo *bo) for (plane = 0; plane < bo->num_planes; plane++) total += drv_get_reference_count(drv, bo, plane); - pthread_mutex_unlock(&drv->table_lock); + pthread_mutex_unlock(&drv->driver_lock); if (total == 0) bo->drv->backend->bo_destroy(bo); @@ -301,9 +351,9 @@ struct bo *drv_bo_import(struct driver *drv, struct drv_import_fd_data *data) bo->format_modifiers[plane] = data->format_modifiers[plane]; bo->total_size += data->sizes[plane]; - pthread_mutex_lock(&drv->table_lock); + pthread_mutex_lock(&drv->driver_lock); drv_increment_reference_count(drv, bo, plane); - pthread_mutex_unlock(&drv->table_lock); + pthread_mutex_unlock(&drv->driver_lock); } return bo; @@ -322,7 +372,7 @@ void *drv_bo_map(struct bo *bo, uint32_t x, uint32_t y, uint32_t width, assert(x + width <= drv_bo_get_width(bo)); assert(y + height <= drv_bo_get_height(bo)); - pthread_mutex_lock(&bo->drv->table_lock); + pthread_mutex_lock(&bo->drv->driver_lock); if (!drmHashLookup(bo->drv->map_table, bo->handles[plane].u32, &ptr)) { data = (struct map_info *) ptr; @@ -335,7 +385,7 @@ void *drv_bo_map(struct bo *bo, uint32_t x, uint32_t y, uint32_t width, if (addr == MAP_FAILED) { *map_data = NULL; free(data); - pthread_mutex_unlock(&bo->drv->table_lock); + pthread_mutex_unlock(&bo->drv->driver_lock); return MAP_FAILED; } @@ -351,7 +401,7 @@ success: offset += drv_stride_from_format(bo->format, x, plane); addr = (uint8_t *) data->addr; addr += drv_bo_get_plane_offset(bo, plane) + offset; - pthread_mutex_unlock(&bo->drv->table_lock); + pthread_mutex_unlock(&bo->drv->driver_lock); return (void *) addr; } @@ -364,15 +414,18 @@ int drv_bo_unmap(struct bo *bo, void *map_data) assert(data); assert(data->refcount >= 0); - pthread_mutex_lock(&bo->drv->table_lock); + pthread_mutex_lock(&bo->drv->driver_lock); if (!--data->refcount) { - ret = munmap(data->addr, data->length); + if (bo->drv->backend->bo_unmap) + ret = bo->drv->backend->bo_unmap(bo, data); + else + ret = munmap(data->addr, data->length); drmHashDelete(bo->drv->map_table, data->handle); free(data); } - pthread_mutex_unlock(&bo->drv->table_lock); + pthread_mutex_unlock(&bo->drv->driver_lock); return ret; } @@ -443,12 +496,12 @@ uint64_t drv_bo_get_plane_format_modifier(struct bo *bo, size_t plane) return bo->format_modifiers[plane]; } -drv_format_t drv_bo_get_format(struct bo *bo) +uint32_t drv_bo_get_format(struct bo *bo) { return bo->format; } -drv_format_t drv_resolve_format(struct driver *drv, drv_format_t format) +uint32_t drv_resolve_format(struct driver *drv, uint32_t format) { if (drv->backend->resolve_format) return drv->backend->resolve_format(format); @@ -461,17 +514,18 @@ drv_format_t drv_resolve_format(struct driver *drv, drv_format_t format) */ int drv_stride_from_format(uint32_t format, uint32_t width, size_t plane) { - /* Get stride of the first plane */ - int stride = width * DIV_ROUND_UP(drv_bpp_from_format(format, 0), 8); + int stride = width * DIV_ROUND_UP(drv_bpp_from_format(format, plane), + 8); /* - * Only downsample for certain multiplanar formats which are not - * interleaved and have horizontal subsampling. Only formats supported - * by our drivers are listed here -- add more as needed. + * Only downsample for certain multiplanar formats which have horizontal + * subsampling for chroma planes. Only formats supported by our drivers + * are listed here -- add more as needed. */ if (plane != 0) { switch (format) { - case DRV_FORMAT_YVU420: + case DRM_FORMAT_NV12: + case DRM_FORMAT_YVU420: stride = stride / 2; break; } @@ -480,6 +534,85 @@ int drv_stride_from_format(uint32_t format, uint32_t width, size_t plane) return stride; } +size_t drv_num_planes_from_format(uint32_t format) +{ + switch (format) { + case DRM_FORMAT_ABGR1555: + case DRM_FORMAT_ABGR2101010: + case DRM_FORMAT_ABGR4444: + case DRM_FORMAT_ABGR8888: + case DRM_FORMAT_ARGB1555: + case DRM_FORMAT_ARGB2101010: + case DRM_FORMAT_ARGB4444: + case DRM_FORMAT_ARGB8888: + case DRM_FORMAT_AYUV: + case DRM_FORMAT_BGR233: + case DRM_FORMAT_BGR565: + case DRM_FORMAT_BGR888: + case DRM_FORMAT_BGRA1010102: + case DRM_FORMAT_BGRA4444: + case DRM_FORMAT_BGRA5551: + case DRM_FORMAT_BGRA8888: + case DRM_FORMAT_BGRX1010102: + case DRM_FORMAT_BGRX4444: + case DRM_FORMAT_BGRX5551: + case DRM_FORMAT_BGRX8888: + case DRM_FORMAT_C8: + case DRM_FORMAT_GR88: + case DRM_FORMAT_R8: + case DRM_FORMAT_RG88: + case DRM_FORMAT_RGB332: + case DRM_FORMAT_RGB565: + case DRM_FORMAT_RGB888: + case DRM_FORMAT_RGBA1010102: + case DRM_FORMAT_RGBA4444: + case DRM_FORMAT_RGBA5551: + case DRM_FORMAT_RGBA8888: + case DRM_FORMAT_RGBX1010102: + case DRM_FORMAT_RGBX4444: + case DRM_FORMAT_RGBX5551: + case DRM_FORMAT_RGBX8888: + case DRM_FORMAT_UYVY: + case DRM_FORMAT_VYUY: + case DRM_FORMAT_XBGR1555: + case DRM_FORMAT_XBGR2101010: + case DRM_FORMAT_XBGR4444: + case DRM_FORMAT_XBGR8888: + case DRM_FORMAT_XRGB1555: + case DRM_FORMAT_XRGB2101010: + case DRM_FORMAT_XRGB4444: + case DRM_FORMAT_XRGB8888: + case DRM_FORMAT_YUYV: + case DRM_FORMAT_YVYU: + return 1; + case DRM_FORMAT_NV12: + return 2; + case DRM_FORMAT_YVU420: + return 3; + } + + fprintf(stderr, "drv: UNKNOWN FORMAT %d\n", format); + return 0; +} + +uint32_t drv_size_from_format(uint32_t format, uint32_t stride, + uint32_t height, size_t plane) +{ + assert(plane < drv_num_planes_from_format(format)); + uint32_t vertical_subsampling; + + switch (format) { + case DRM_FORMAT_NV12: + case DRM_FORMAT_YVU420: + vertical_subsampling = (plane == 0) ? 1 : 2; + break; + default: + vertical_subsampling = 1; + } + + return stride * DIV_ROUND_UP(height, vertical_subsampling); +} + uint32_t drv_num_buffers_per_bo(struct bo *bo) { uint32_t count = 0; diff --git a/chromium/third_party/minigbm/src/drv.h b/chromium/third_party/minigbm/src/drv.h index 4b70d58f542..355ea45f03e 100644 --- a/chromium/third_party/minigbm/src/drv.h +++ b/chromium/third_party/minigbm/src/drv.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 The Chromium OS Authors. All rights reserved. + * Copyright 2016 The Chromium OS Authors. All rights reserved. * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ @@ -11,108 +11,40 @@ extern "C" { #endif +#include <drm_fourcc.h> #include <stdint.h> #define DRV_MAX_PLANES 4 -/* Vendor ids and mod_code fourcc function must match gbm.h */ -#define DRV_FORMAT_MOD_NONE 0 -#define DRV_FORMAT_MOD_VENDOR_INTEL 0x01 -#define DRV_FORMAT_MOD_VENDOR_AMD 0x02 -#define DRV_FORMAT_MOD_VENDOR_NV 0x03 -#define DRV_FORMAT_MOD_VENDOR_SAMSUNG 0x04 -#define DRV_FORMAT_MOD_VENDOR_QCOM 0x05 - -#define drv_fourcc_mod_code(vendor, val) \ - ((((__u64)DRV_FORMAT_MOD_VENDOR_## vendor) << 56) | (val & 0x00ffffffffffffffULL)) - /* Use flags */ -#define DRV_BO_USE_NONE 0 -#define DRV_BO_USE_SCANOUT (1ull << 0) -#define DRV_BO_USE_CURSOR (1ull << 1) -#define DRV_BO_USE_CURSOR_64X64 DRV_BO_USE_CURSOR -#define DRV_BO_USE_RENDERING (1ull << 2) -#define DRV_BO_USE_LINEAR (1ull << 3) -#define DRV_BO_USE_SW_READ_NEVER (1ull << 4) -#define DRV_BO_USE_SW_READ_RARELY (1ull << 5) -#define DRV_BO_USE_SW_READ_OFTEN (1ull << 6) -#define DRV_BO_USE_SW_WRITE_NEVER (1ull << 7) -#define DRV_BO_USE_SW_WRITE_RARELY (1ull << 8) -#define DRV_BO_USE_SW_WRITE_OFTEN (1ull << 9) -#define DRV_BO_USE_EXTERNAL_DISP (1ull << 10) -#define DRV_BO_USE_PROTECTED (1ull << 11) -#define DRV_BO_USE_HW_VIDEO_ENCODER (1ull << 12) -#define DRV_BO_USE_HW_CAMERA_WRITE (1ull << 13) -#define DRV_BO_USE_HW_CAMERA_READ (1ull << 14) -#define DRV_BO_USE_HW_CAMERA_ZSL (1ull << 15) -#define DRV_BO_USE_RENDERSCRIPT (1ull << 16) - -typedef enum { - DRV_FORMAT_NONE, - DRV_FORMAT_C8, - DRV_FORMAT_R8, - DRV_FORMAT_RG88, - DRV_FORMAT_GR88, - DRV_FORMAT_RGB332, - DRV_FORMAT_BGR233, - DRV_FORMAT_XRGB4444, - DRV_FORMAT_XBGR4444, - DRV_FORMAT_RGBX4444, - DRV_FORMAT_BGRX4444, - DRV_FORMAT_ARGB4444, - DRV_FORMAT_ABGR4444, - DRV_FORMAT_RGBA4444, - DRV_FORMAT_BGRA4444, - DRV_FORMAT_XRGB1555, - DRV_FORMAT_XBGR1555, - DRV_FORMAT_RGBX5551, - DRV_FORMAT_BGRX5551, - DRV_FORMAT_ARGB1555, - DRV_FORMAT_ABGR1555, - DRV_FORMAT_RGBA5551, - DRV_FORMAT_BGRA5551, - DRV_FORMAT_RGB565, - DRV_FORMAT_BGR565, - DRV_FORMAT_RGB888, - DRV_FORMAT_BGR888, - DRV_FORMAT_XRGB8888, - DRV_FORMAT_XBGR8888, - DRV_FORMAT_RGBX8888, - DRV_FORMAT_BGRX8888, - DRV_FORMAT_ARGB8888, - DRV_FORMAT_ABGR8888, - DRV_FORMAT_RGBA8888, - DRV_FORMAT_BGRA8888, - DRV_FORMAT_XRGB2101010, - DRV_FORMAT_XBGR2101010, - DRV_FORMAT_RGBX1010102, - DRV_FORMAT_BGRX1010102, - DRV_FORMAT_ARGB2101010, - DRV_FORMAT_ABGR2101010, - DRV_FORMAT_RGBA1010102, - DRV_FORMAT_BGRA1010102, - DRV_FORMAT_YUYV, - DRV_FORMAT_YVYU, - DRV_FORMAT_UYVY, - DRV_FORMAT_VYUY, - DRV_FORMAT_AYUV, - DRV_FORMAT_NV12, - DRV_FORMAT_NV21, - DRV_FORMAT_NV16, - DRV_FORMAT_NV61, - DRV_FORMAT_YUV410, - DRV_FORMAT_YVU410, - DRV_FORMAT_YUV411, - DRV_FORMAT_YVU411, - DRV_FORMAT_YUV420, - DRV_FORMAT_YVU420, - DRV_FORMAT_YUV422, - DRV_FORMAT_YVU422, - DRV_FORMAT_YUV444, - DRV_FORMAT_YVU444, - DRV_FORMAT_FLEX_IMPLEMENTATION_DEFINED, - DRV_FORMAT_FLEX_YCbCr_420_888, -} drv_format_t; +#define BO_USE_NONE 0 +#define BO_USE_SCANOUT (1ull << 0) +#define BO_USE_CURSOR (1ull << 1) +#define BO_USE_CURSOR_64X64 BO_USE_CURSOR +#define BO_USE_RENDERING (1ull << 2) +#define BO_USE_LINEAR (1ull << 3) +#define BO_USE_SW_READ_NEVER (1ull << 4) +#define BO_USE_SW_READ_RARELY (1ull << 5) +#define BO_USE_SW_READ_OFTEN (1ull << 6) +#define BO_USE_SW_WRITE_NEVER (1ull << 7) +#define BO_USE_SW_WRITE_RARELY (1ull << 8) +#define BO_USE_SW_WRITE_OFTEN (1ull << 9) +#define BO_USE_EXTERNAL_DISP (1ull << 10) +#define BO_USE_PROTECTED (1ull << 11) +#define BO_USE_HW_VIDEO_ENCODER (1ull << 12) +#define BO_USE_HW_CAMERA_WRITE (1ull << 13) +#define BO_USE_HW_CAMERA_READ (1ull << 14) +#define BO_USE_HW_CAMERA_ZSL (1ull << 15) +#define BO_USE_RENDERSCRIPT (1ull << 16) + +/* This is our extension to <drm_fourcc.h>. We need to make sure we don't step + * on the namespace of already defined formats, which can be done by using invalid + * fourcc codes. + */ + +#define DRM_FORMAT_NONE fourcc_code('0', '0', '0', '0') +#define DRM_FORMAT_FLEX_IMPLEMENTATION_DEFINED fourcc_code('9', '9', '9', '8') +#define DRM_FORMAT_FLEX_YCbCr_420_888 fourcc_code('9', '9', '9', '9') struct driver; struct bo; @@ -133,7 +65,7 @@ struct drv_import_fd_data { uint64_t format_modifiers[DRV_MAX_PLANES]; uint32_t width; uint32_t height; - drv_format_t format; + uint32_t format; }; struct driver * @@ -149,16 +81,22 @@ const char * drv_get_name(struct driver *drv); int -drv_is_format_supported(struct driver *drv, drv_format_t format, - uint64_t usage); +drv_is_combination_supported(struct driver *drv, uint32_t format, + uint64_t usage, uint64_t modifier); struct bo * drv_bo_new(struct driver *drv, uint32_t width, uint32_t height, - drv_format_t format); + uint32_t format); struct bo * drv_bo_create(struct driver *drv, uint32_t width, uint32_t height, - drv_format_t format, uint64_t flags); + uint32_t format, uint64_t flags); + +struct bo * +drv_bo_create_with_modifiers(struct driver *drv, + uint32_t width, uint32_t height, + uint32_t format, + const uint64_t *modifiers, uint32_t count); void drv_bo_destroy(struct bo *bo); @@ -203,15 +141,22 @@ drv_bo_get_plane_stride(struct bo *bo, size_t plane); uint64_t drv_bo_get_plane_format_modifier(struct bo *bo, size_t plane); -drv_format_t +uint32_t drv_bo_get_format(struct bo *bo); -drv_format_t -drv_resolve_format(struct driver *drv, drv_format_t format); +uint32_t +drv_resolve_format(struct driver *drv, uint32_t format); int drv_stride_from_format(uint32_t format, uint32_t width, size_t plane); +size_t +drv_num_planes_from_format(uint32_t format); + +uint32_t +drv_size_from_format(uint32_t format, uint32_t stride, uint32_t height, + size_t plane); + uint32_t drv_num_buffers_per_bo(struct bo *bo); diff --git a/chromium/third_party/minigbm/src/drv_priv.h b/chromium/third_party/minigbm/src/drv_priv.h index 4f83db5abf8..cdd13eee34b 100644 --- a/chromium/third_party/minigbm/src/drv_priv.h +++ b/chromium/third_party/minigbm/src/drv_priv.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 The Chromium OS Authors. All rights reserved. + * Copyright 2016 The Chromium OS Authors. All rights reserved. * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ @@ -13,6 +13,7 @@ #include <sys/types.h> #include "drv.h" +#include "list.h" struct bo { @@ -37,7 +38,7 @@ struct driver { void *priv; void *buffer_table; void *map_table; - pthread_mutex_t table_lock; + pthread_mutex_t driver_lock; }; struct map_info { @@ -45,6 +46,18 @@ struct map_info { size_t length; uint32_t handle; int32_t refcount; + void *priv; +}; + +struct supported_combination { + uint32_t format; + uint64_t modifier; + uint64_t usage; +}; + +struct combination_list_element { + struct supported_combination combination; + struct list_head link; }; struct backend @@ -53,15 +66,17 @@ struct backend int (*init)(struct driver *drv); void (*close)(struct driver *drv); int (*bo_create)(struct bo *bo, uint32_t width, uint32_t height, - drv_format_t format, uint32_t flags); + uint32_t format, uint32_t flags); + int (*bo_create_with_modifiers)(struct bo *bo, + uint32_t width, uint32_t height, + uint32_t format, + const uint64_t *modifiers, + uint32_t count); void* (*bo_map)(struct bo *bo, struct map_info *data, size_t plane); + int (*bo_unmap)(struct bo *bo, struct map_info *data); int (*bo_destroy)(struct bo *bo); - drv_format_t (*resolve_format)(drv_format_t format); - struct format_supported { - drv_format_t format; - uint64_t usage; - } - format_list[19]; + uint32_t (*resolve_format)(uint32_t format); + struct list_head combinations; }; #endif diff --git a/chromium/third_party/minigbm/src/evdi.c b/chromium/third_party/minigbm/src/evdi.c index 349a5f4b639..22f5f144d82 100644 --- a/chromium/third_party/minigbm/src/evdi.c +++ b/chromium/third_party/minigbm/src/evdi.c @@ -6,18 +6,29 @@ #include "drv_priv.h" #include "helpers.h" +#include "util.h" -const struct backend backend_evdi = +static struct supported_combination combos[2] = { + {DRM_FORMAT_ARGB8888, DRM_FORMAT_MOD_NONE, + BO_USE_CURSOR | BO_USE_LINEAR | BO_USE_RENDERING | BO_USE_SW_READ_OFTEN | + BO_USE_SW_WRITE_OFTEN | BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY}, + {DRM_FORMAT_XRGB8888, DRM_FORMAT_MOD_NONE, + BO_USE_CURSOR | BO_USE_LINEAR | BO_USE_RENDERING | BO_USE_SW_READ_OFTEN | + BO_USE_SW_WRITE_OFTEN | BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY}, +}; + +static int evdi_init(struct driver *drv) +{ + drv_insert_combinations(drv, combos, ARRAY_SIZE(combos)); + return drv_add_kms_flags(drv); +} + +struct backend backend_evdi = { .name = "evdi", + .init = evdi_init, .bo_create = drv_dumb_bo_create, .bo_destroy = drv_dumb_bo_destroy, .bo_map = drv_dumb_bo_map, - .format_list = { - {DRV_FORMAT_XRGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_RENDERING}, - {DRV_FORMAT_XRGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_LINEAR}, - {DRV_FORMAT_ARGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_RENDERING}, - {DRV_FORMAT_ARGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_LINEAR}, - } }; diff --git a/chromium/third_party/minigbm/src/exynos.c b/chromium/third_party/minigbm/src/exynos.c index e12c95fc81a..03b092e89c9 100644 --- a/chromium/third_party/minigbm/src/exynos.c +++ b/chromium/third_party/minigbm/src/exynos.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 The Chromium OS Authors. All rights reserved. + * Copyright 2014 The Chromium OS Authors. All rights reserved. * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ @@ -17,12 +17,30 @@ #include "helpers.h" #include "util.h" +static struct supported_combination combos[3] = { + {DRM_FORMAT_ARGB8888, DRM_FORMAT_MOD_NONE, + BO_USE_CURSOR | BO_USE_LINEAR | BO_USE_RENDERING | BO_USE_SW_READ_OFTEN | + BO_USE_SW_WRITE_OFTEN | BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY}, + {DRM_FORMAT_NV12, DRM_FORMAT_MOD_NONE, + BO_USE_LINEAR | BO_USE_RENDERING | BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN | + BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY}, + {DRM_FORMAT_XRGB8888, DRM_FORMAT_MOD_NONE, + BO_USE_CURSOR | BO_USE_LINEAR | BO_USE_RENDERING | BO_USE_SW_READ_OFTEN | + BO_USE_SW_WRITE_OFTEN | BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY}, +}; + +static int exynos_init(struct driver *drv) +{ + drv_insert_combinations(drv, combos, ARRAY_SIZE(combos)); + return drv_add_kms_flags(drv); +} + static int exynos_bo_create(struct bo *bo, uint32_t width, uint32_t height, uint32_t format, uint32_t flags) { size_t plane; - if (format == DRV_FORMAT_NV12) { + if (format == DRM_FORMAT_NV12) { uint32_t chroma_height; /* V4L2 s5p-mfc requires width to be 16 byte aligned and height 32. */ width = ALIGN(width, 16); @@ -34,7 +52,7 @@ static int exynos_bo_create(struct bo *bo, uint32_t width, uint32_t height, bo->sizes[1] = bo->strides[1] * chroma_height + 64; bo->offsets[0] = bo->offsets[1] = 0; bo->total_size = bo->sizes[0] + bo->sizes[1]; - } else if (format == DRV_FORMAT_XRGB8888 || format == DRV_FORMAT_ARGB8888) { + } else if (format == DRM_FORMAT_XRGB8888 || format == DRM_FORMAT_ARGB8888) { bo->strides[0] = drv_stride_from_format(format, width, 0); bo->total_size = bo->sizes[0] = height * bo->strides[0]; bo->offsets[0] = 0; @@ -86,19 +104,13 @@ cleanup_planes: * Use dumb mapping with exynos even though a GEM buffer is created. * libdrm does the same thing in exynos_drm.c */ -const struct backend backend_exynos = +struct backend backend_exynos = { .name = "exynos", + .init = exynos_init, .bo_create = exynos_bo_create, .bo_destroy = drv_gem_bo_destroy, .bo_map = drv_dumb_bo_map, - .format_list = { - {DRV_FORMAT_XRGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_RENDERING}, - {DRV_FORMAT_XRGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_LINEAR}, - {DRV_FORMAT_ARGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_RENDERING}, - {DRV_FORMAT_ARGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_LINEAR}, - {DRV_FORMAT_NV12, DRV_BO_USE_SCANOUT | DRV_BO_USE_RENDERING}, - } }; #endif diff --git a/chromium/third_party/minigbm/src/gbm.c b/chromium/third_party/minigbm/src/gbm.c index 2235b220d12..6ad32ce6bbe 100644 --- a/chromium/third_party/minigbm/src/gbm.c +++ b/chromium/third_party/minigbm/src/gbm.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 The Chromium OS Authors. All rights reserved. + * Copyright 2014 The Chromium OS Authors. All rights reserved. * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ @@ -34,17 +34,16 @@ PUBLIC int gbm_device_is_format_supported(struct gbm_device *gbm, uint32_t format, uint32_t usage) { - uint32_t drv_format; uint64_t drv_usage; if (usage & GBM_BO_USE_CURSOR && usage & GBM_BO_USE_RENDERING) return 0; - drv_format = gbm_convert_format(format); drv_usage = gbm_convert_flags(usage); - return drv_is_format_supported(gbm->drv, drv_format, drv_usage); + return drv_is_combination_supported(gbm->drv, format, drv_usage, + DRM_FORMAT_MOD_NONE); } PUBLIC struct gbm_device *gbm_create_device(int fd) @@ -127,8 +126,7 @@ PUBLIC struct gbm_bo *gbm_bo_create(struct gbm_device *gbm, uint32_t width, if (!bo) return NULL; - bo->bo = drv_bo_create(gbm->drv, width, height, - gbm_convert_format(format), + bo->bo = drv_bo_create(gbm->drv, width, height, format, gbm_convert_flags(flags)); if (!bo->bo) { @@ -139,6 +137,32 @@ PUBLIC struct gbm_bo *gbm_bo_create(struct gbm_device *gbm, uint32_t width, return bo; } +PUBLIC struct gbm_bo *gbm_bo_create_with_modifiers(struct gbm_device *gbm, + uint32_t width, + uint32_t height, + uint32_t format, + const uint64_t *modifiers, + uint32_t count) +{ + struct gbm_bo *bo; + + bo = gbm_bo_new(gbm, format); + + if (!bo) + return NULL; + + bo->bo = drv_bo_create_with_modifiers(gbm->drv, + width, height, format, + modifiers, count); + + if (!bo->bo) { + free(bo); + return NULL; + } + + return bo; +} + PUBLIC void gbm_bo_destroy(struct gbm_bo *bo) { if (bo->destroy_user_data) { @@ -160,7 +184,7 @@ gbm_bo_import(struct gbm_device *gbm, uint32_t type, struct gbm_import_fd_data *fd_data = buffer; struct gbm_import_fd_planar_data *fd_planar_data = buffer; uint32_t gbm_format; - int i; + size_t num_planes, i; memset(&drv_data, 0, sizeof(drv_data)); @@ -169,7 +193,7 @@ gbm_bo_import(struct gbm_device *gbm, uint32_t type, gbm_format = fd_data->format; drv_data.width = fd_data->width; drv_data.height = fd_data->height; - drv_data.format = gbm_convert_format(fd_data->format); + drv_data.format = fd_data->format; drv_data.fds[0] = fd_data->fd; drv_data.strides[0] = fd_data->stride; drv_data.sizes[0] = fd_data->height * fd_data->stride; @@ -178,16 +202,28 @@ gbm_bo_import(struct gbm_device *gbm, uint32_t type, gbm_format = fd_planar_data->format; drv_data.width = fd_planar_data->width; drv_data.height = fd_planar_data->height; - drv_data.format = gbm_convert_format(fd_planar_data->format); - for (i = 0; i < GBM_MAX_PLANES; i++) { + drv_data.format = fd_planar_data->format; + num_planes = drv_num_planes_from_format(drv_data.format); + + assert(num_planes); + + for (i = 0; i < num_planes; i++) { drv_data.fds[i] = fd_planar_data->fds[i]; drv_data.offsets[i] = fd_planar_data->offsets[i]; drv_data.strides[i] = fd_planar_data->strides[i]; - drv_data.sizes[i] = fd_planar_data->height * - fd_planar_data->strides[i]; drv_data.format_modifiers[i] = fd_planar_data->format_modifiers[i]; + + drv_data.sizes[i] = drv_size_from_format( + drv_data.format, + drv_data.strides[i], + drv_data.height, + i); } + + for (i = num_planes; i < GBM_MAX_PLANES; i++) + drv_data.fds[i] = -1; + break; default: return NULL; diff --git a/chromium/third_party/minigbm/src/gbm.h b/chromium/third_party/minigbm/src/gbm.h index 839e2a51c63..1fb338f98e3 100644 --- a/chromium/third_party/minigbm/src/gbm.h +++ b/chromium/third_party/minigbm/src/gbm.h @@ -35,6 +35,7 @@ extern "C" { #define __GBM__ 1 +#include <stddef.h> #include <stdint.h> /** @@ -261,6 +262,12 @@ gbm_bo_create(struct gbm_device *gbm, uint32_t width, uint32_t height, uint32_t format, uint32_t flags); +struct gbm_bo * +gbm_bo_create_with_modifiers(struct gbm_device *gbm, + uint32_t width, uint32_t height, + uint32_t format, + const uint64_t *modifiers, uint32_t count); + #define GBM_BO_IMPORT_WL_BUFFER 0x5501 #define GBM_BO_IMPORT_EGL_IMAGE 0x5502 #define GBM_BO_IMPORT_FD 0x5503 diff --git a/chromium/third_party/minigbm/src/gbm_helpers.c b/chromium/third_party/minigbm/src/gbm_helpers.c index 2f7e034f2d1..c60a315b2cc 100644 --- a/chromium/third_party/minigbm/src/gbm_helpers.c +++ b/chromium/third_party/minigbm/src/gbm_helpers.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 The Chromium OS Authors. All rights reserved. + * Copyright 2016 The Chromium OS Authors. All rights reserved. * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ @@ -10,152 +10,20 @@ #include "drv.h" #include "gbm.h" -drv_format_t gbm_convert_format(uint32_t format) -{ - - switch (format) { - case GBM_FORMAT_C8: - return DRV_FORMAT_C8; - case GBM_FORMAT_R8: - return DRV_FORMAT_R8; - case GBM_FORMAT_RG88: - return DRV_FORMAT_RG88; - case GBM_FORMAT_GR88: - return DRV_FORMAT_GR88; - case GBM_FORMAT_RGB332: - return DRV_FORMAT_RGB332; - case GBM_FORMAT_BGR233: - return DRV_FORMAT_BGR233; - case GBM_FORMAT_XRGB4444: - return DRV_FORMAT_XRGB4444; - case GBM_FORMAT_XBGR4444: - return DRV_FORMAT_XBGR4444; - case GBM_FORMAT_RGBX4444: - return DRV_FORMAT_RGBX4444; - case GBM_FORMAT_BGRX4444: - return DRV_FORMAT_BGRX4444; - case GBM_FORMAT_ARGB4444: - return DRV_FORMAT_ARGB4444; - case GBM_FORMAT_ABGR4444: - return DRV_FORMAT_ABGR4444; - case GBM_FORMAT_RGBA4444: - return DRV_FORMAT_RGBA4444; - case GBM_FORMAT_BGRA4444: - return DRV_FORMAT_BGRA4444; - case GBM_FORMAT_XRGB1555: - return DRV_FORMAT_XRGB1555; - case GBM_FORMAT_XBGR1555: - return DRV_FORMAT_XBGR1555; - case GBM_FORMAT_RGBX5551: - return DRV_FORMAT_RGBX5551; - case GBM_FORMAT_BGRX5551: - return DRV_FORMAT_BGRX5551; - case GBM_FORMAT_ARGB1555: - return DRV_FORMAT_ARGB1555; - case GBM_FORMAT_ABGR1555: - return DRV_FORMAT_ABGR1555; - case GBM_FORMAT_RGBA5551: - return DRV_FORMAT_RGBA5551; - case GBM_FORMAT_BGRA5551: - return DRV_FORMAT_BGRA5551; - case GBM_FORMAT_RGB565: - return DRV_FORMAT_RGB565; - case GBM_FORMAT_BGR565: - return DRV_FORMAT_BGR565; - case GBM_FORMAT_RGB888: - return DRV_FORMAT_RGB888; - case GBM_FORMAT_BGR888: - return DRV_FORMAT_BGR888; - case GBM_FORMAT_XRGB8888: - return DRV_FORMAT_XRGB8888; - case GBM_FORMAT_XBGR8888: - return DRV_FORMAT_XBGR8888; - case GBM_FORMAT_RGBX8888: - return DRV_FORMAT_RGBX8888; - case GBM_FORMAT_BGRX8888: - return DRV_FORMAT_BGRX8888; - case GBM_FORMAT_ARGB8888: - return DRV_FORMAT_ARGB8888; - case GBM_FORMAT_ABGR8888: - return DRV_FORMAT_ABGR8888; - case GBM_FORMAT_RGBA8888: - return DRV_FORMAT_RGBA8888; - case GBM_FORMAT_BGRA8888: - return DRV_FORMAT_BGRA8888; - case GBM_FORMAT_XRGB2101010: - return DRV_FORMAT_XRGB2101010; - case GBM_FORMAT_XBGR2101010: - return DRV_FORMAT_XBGR2101010; - case GBM_FORMAT_RGBX1010102: - return DRV_FORMAT_RGBX1010102; - case GBM_FORMAT_BGRX1010102: - return DRV_FORMAT_BGRX1010102; - case GBM_FORMAT_ARGB2101010: - return DRV_FORMAT_ARGB2101010; - case GBM_FORMAT_ABGR2101010: - return DRV_FORMAT_ABGR2101010; - case GBM_FORMAT_RGBA1010102: - return DRV_FORMAT_RGBA1010102; - case GBM_FORMAT_BGRA1010102: - return DRV_FORMAT_BGRA1010102; - case GBM_FORMAT_YUYV: - return DRV_FORMAT_YUYV; - case GBM_FORMAT_YVYU: - return DRV_FORMAT_YVYU; - case GBM_FORMAT_UYVY: - return DRV_FORMAT_UYVY; - case GBM_FORMAT_VYUY: - return DRV_FORMAT_VYUY; - case GBM_FORMAT_AYUV: - return DRV_FORMAT_AYUV; - case GBM_FORMAT_NV12: - return DRV_FORMAT_NV12; - case GBM_FORMAT_NV21: - return DRV_FORMAT_NV21; - case GBM_FORMAT_NV16: - return DRV_FORMAT_NV16; - case GBM_FORMAT_NV61: - return DRV_FORMAT_NV61; - case GBM_FORMAT_YUV410: - return DRV_FORMAT_YUV410; - case GBM_FORMAT_YVU410: - return DRV_FORMAT_YVU410; - case GBM_FORMAT_YUV411: - return DRV_FORMAT_YUV411; - case GBM_FORMAT_YVU411: - return DRV_FORMAT_YVU411; - case GBM_FORMAT_YUV420: - return DRV_FORMAT_YUV420; - case GBM_FORMAT_YVU420: - return DRV_FORMAT_YVU420; - case GBM_FORMAT_YUV422: - return DRV_FORMAT_YUV422; - case GBM_FORMAT_YVU422: - return DRV_FORMAT_YVU422; - case GBM_FORMAT_YUV444: - return DRV_FORMAT_YVU444; - case GBM_FORMAT_YVU444: - return DRV_FORMAT_YVU444; - } - - fprintf(stderr, "minigbm: UNKNOWN FORMAT %d\n", format); - return DRV_FORMAT_NONE; -} - uint64_t gbm_convert_flags(uint32_t flags) { - uint64_t usage = DRV_BO_USE_NONE; + uint64_t usage = BO_USE_NONE; if (flags & GBM_BO_USE_SCANOUT) - usage |= DRV_BO_USE_SCANOUT; + usage |= BO_USE_SCANOUT; if (flags & GBM_BO_USE_CURSOR) - usage |= DRV_BO_USE_CURSOR; + usage |= BO_USE_CURSOR; if (flags & GBM_BO_USE_CURSOR_64X64) - usage |= DRV_BO_USE_CURSOR_64X64; + usage |= BO_USE_CURSOR_64X64; if (flags & GBM_BO_USE_RENDERING) - usage |= DRV_BO_USE_RENDERING; + usage |= BO_USE_RENDERING; if (flags & GBM_BO_USE_LINEAR) - usage |= DRV_BO_USE_LINEAR; + usage |= BO_USE_LINEAR; return usage; } diff --git a/chromium/third_party/minigbm/src/gbm_helpers.h b/chromium/third_party/minigbm/src/gbm_helpers.h index c2f7e37a3e0..48ff3913736 100644 --- a/chromium/third_party/minigbm/src/gbm_helpers.h +++ b/chromium/third_party/minigbm/src/gbm_helpers.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 The Chromium OS Authors. All rights reserved. + * Copyright 2016 The Chromium OS Authors. All rights reserved. * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ @@ -7,7 +7,6 @@ #ifndef GBM_HELPERS_H #define GBM_HELPERS_H -drv_format_t gbm_convert_format(uint32_t format); uint64_t gbm_convert_flags(uint32_t flags); #endif diff --git a/chromium/third_party/minigbm/src/gbm_priv.h b/chromium/third_party/minigbm/src/gbm_priv.h index 379bf01701a..eb29f1be8a7 100644 --- a/chromium/third_party/minigbm/src/gbm_priv.h +++ b/chromium/third_party/minigbm/src/gbm_priv.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 The Chromium OS Authors. All rights reserved. + * Copyright 2014 The Chromium OS Authors. All rights reserved. * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ diff --git a/chromium/third_party/minigbm/src/gma500.c b/chromium/third_party/minigbm/src/gma500.c index 53c1a4d8624..ca5591da22c 100644 --- a/chromium/third_party/minigbm/src/gma500.c +++ b/chromium/third_party/minigbm/src/gma500.c @@ -1,19 +1,30 @@ /* - * Copyright (c) 2014 The Chromium OS Authors. All rights reserved. + * Copyright 2014 The Chromium OS Authors. All rights reserved. * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ #include "drv_priv.h" #include "helpers.h" +#include "util.h" -const struct backend backend_gma500 = +static struct supported_combination combos[1] = { + {DRM_FORMAT_RGBX8888, DRM_FORMAT_MOD_NONE, + BO_USE_CURSOR | BO_USE_LINEAR | BO_USE_RENDERING | BO_USE_SW_READ_OFTEN | + BO_USE_SW_WRITE_OFTEN | BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY}, +}; + +static int gma500_init(struct driver *drv) +{ + drv_insert_combinations(drv, combos, ARRAY_SIZE(combos)); + return drv_add_kms_flags(drv); +} + +struct backend backend_gma500 = { .name = "gma500", + .init = gma500_init, .bo_create = drv_dumb_bo_create, .bo_destroy = drv_dumb_bo_destroy, .bo_map = drv_dumb_bo_map, - .format_list = { - {DRV_FORMAT_RGBX8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_RENDERING}, - } }; diff --git a/chromium/third_party/minigbm/src/helpers.c b/chromium/third_party/minigbm/src/helpers.c index 8305eafad3d..04e710a511b 100644 --- a/chromium/third_party/minigbm/src/helpers.c +++ b/chromium/third_party/minigbm/src/helpers.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 The Chromium OS Authors. All rights reserved. + * Copyright 2014 The Chromium OS Authors. All rights reserved. * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ @@ -11,135 +11,91 @@ #include <string.h> #include <sys/mman.h> #include <xf86drm.h> +#include <xf86drmMode.h> #include "drv_priv.h" #include "helpers.h" #include "util.h" -size_t drv_num_planes_from_format(uint32_t format) -{ - switch (format) { - case DRV_FORMAT_C8: - case DRV_FORMAT_R8: - case DRV_FORMAT_RG88: - case DRV_FORMAT_GR88: - case DRV_FORMAT_RGB332: - case DRV_FORMAT_BGR233: - case DRV_FORMAT_XRGB4444: - case DRV_FORMAT_XBGR4444: - case DRV_FORMAT_RGBX4444: - case DRV_FORMAT_BGRX4444: - case DRV_FORMAT_ARGB4444: - case DRV_FORMAT_ABGR4444: - case DRV_FORMAT_RGBA4444: - case DRV_FORMAT_BGRA4444: - case DRV_FORMAT_XRGB1555: - case DRV_FORMAT_XBGR1555: - case DRV_FORMAT_RGBX5551: - case DRV_FORMAT_BGRX5551: - case DRV_FORMAT_ARGB1555: - case DRV_FORMAT_ABGR1555: - case DRV_FORMAT_RGBA5551: - case DRV_FORMAT_BGRA5551: - case DRV_FORMAT_RGB565: - case DRV_FORMAT_BGR565: - case DRV_FORMAT_YUYV: - case DRV_FORMAT_YVYU: - case DRV_FORMAT_UYVY: - case DRV_FORMAT_VYUY: - case DRV_FORMAT_RGB888: - case DRV_FORMAT_BGR888: - case DRV_FORMAT_XRGB8888: - case DRV_FORMAT_XBGR8888: - case DRV_FORMAT_RGBX8888: - case DRV_FORMAT_BGRX8888: - case DRV_FORMAT_ARGB8888: - case DRV_FORMAT_ABGR8888: - case DRV_FORMAT_RGBA8888: - case DRV_FORMAT_BGRA8888: - case DRV_FORMAT_XRGB2101010: - case DRV_FORMAT_XBGR2101010: - case DRV_FORMAT_RGBX1010102: - case DRV_FORMAT_BGRX1010102: - case DRV_FORMAT_ARGB2101010: - case DRV_FORMAT_ABGR2101010: - case DRV_FORMAT_RGBA1010102: - case DRV_FORMAT_BGRA1010102: - case DRV_FORMAT_AYUV: - return 1; - case DRV_FORMAT_NV12: - return 2; - case DRV_FORMAT_YVU420: - return 3; - } - - fprintf(stderr, "drv: UNKNOWN FORMAT %d\n", format); - return 0; -} - int drv_bpp_from_format(uint32_t format, size_t plane) { assert(plane < drv_num_planes_from_format(format)); switch (format) { - case DRV_FORMAT_C8: - case DRV_FORMAT_R8: - case DRV_FORMAT_RGB332: - case DRV_FORMAT_BGR233: + case DRM_FORMAT_BGR233: + case DRM_FORMAT_C8: + case DRM_FORMAT_R8: + case DRM_FORMAT_RGB332: + case DRM_FORMAT_YVU420: return 8; - case DRV_FORMAT_NV12: - return (plane == 0) ? 8 : 4; - case DRV_FORMAT_YVU420: - return (plane == 0) ? 8 : 2; - - case DRV_FORMAT_RG88: - case DRV_FORMAT_GR88: - case DRV_FORMAT_XRGB4444: - case DRV_FORMAT_XBGR4444: - case DRV_FORMAT_RGBX4444: - case DRV_FORMAT_BGRX4444: - case DRV_FORMAT_ARGB4444: - case DRV_FORMAT_ABGR4444: - case DRV_FORMAT_RGBA4444: - case DRV_FORMAT_BGRA4444: - case DRV_FORMAT_XRGB1555: - case DRV_FORMAT_XBGR1555: - case DRV_FORMAT_RGBX5551: - case DRV_FORMAT_BGRX5551: - case DRV_FORMAT_ARGB1555: - case DRV_FORMAT_ABGR1555: - case DRV_FORMAT_RGBA5551: - case DRV_FORMAT_BGRA5551: - case DRV_FORMAT_RGB565: - case DRV_FORMAT_BGR565: - case DRV_FORMAT_YUYV: - case DRV_FORMAT_YVYU: - case DRV_FORMAT_UYVY: - case DRV_FORMAT_VYUY: + /* + * NV12 is laid out as follows. Each letter represents a byte. + * Y plane: + * Y0_0, Y0_1, Y0_2, Y0_3, ..., Y0_N + * Y1_0, Y1_1, Y1_2, Y1_3, ..., Y1_N + * ... + * YM_0, YM_1, YM_2, YM_3, ..., YM_N + * CbCr plane: + * Cb01_01, Cr01_01, Cb01_23, Cr01_23, ..., Cb01_(N-1)N, Cr01_(N-1)N + * Cb23_01, Cr23_01, Cb23_23, Cr23_23, ..., Cb23_(N-1)N, Cr23_(N-1)N + * ... + * Cb(M-1)M_01, Cr(M-1)M_01, ..., Cb(M-1)M_(N-1)N, Cr(M-1)M_(N-1)N + * + * Pixel (0, 0) requires Y0_0, Cb01_01 and Cr01_01. Pixel (0, 1) requires + * Y0_1, Cb01_01 and Cr01_01. So for a single pixel, 2 bytes of luma data + * are required. + */ + case DRM_FORMAT_NV12: + return (plane == 0) ? 8 : 16; + + case DRM_FORMAT_ABGR1555: + case DRM_FORMAT_ABGR4444: + case DRM_FORMAT_ARGB1555: + case DRM_FORMAT_ARGB4444: + case DRM_FORMAT_BGR565: + case DRM_FORMAT_BGRA4444: + case DRM_FORMAT_BGRA5551: + case DRM_FORMAT_BGRX4444: + case DRM_FORMAT_BGRX5551: + case DRM_FORMAT_GR88: + case DRM_FORMAT_RG88: + case DRM_FORMAT_RGB565: + case DRM_FORMAT_RGBA4444: + case DRM_FORMAT_RGBA5551: + case DRM_FORMAT_RGBX4444: + case DRM_FORMAT_RGBX5551: + case DRM_FORMAT_UYVY: + case DRM_FORMAT_VYUY: + case DRM_FORMAT_XBGR1555: + case DRM_FORMAT_XBGR4444: + case DRM_FORMAT_XRGB1555: + case DRM_FORMAT_XRGB4444: + case DRM_FORMAT_YUYV: + case DRM_FORMAT_YVYU: return 16; - case DRV_FORMAT_RGB888: - case DRV_FORMAT_BGR888: + case DRM_FORMAT_BGR888: + case DRM_FORMAT_RGB888: return 24; - case DRV_FORMAT_XRGB8888: - case DRV_FORMAT_XBGR8888: - case DRV_FORMAT_RGBX8888: - case DRV_FORMAT_BGRX8888: - case DRV_FORMAT_ARGB8888: - case DRV_FORMAT_ABGR8888: - case DRV_FORMAT_RGBA8888: - case DRV_FORMAT_BGRA8888: - case DRV_FORMAT_XRGB2101010: - case DRV_FORMAT_XBGR2101010: - case DRV_FORMAT_RGBX1010102: - case DRV_FORMAT_BGRX1010102: - case DRV_FORMAT_ARGB2101010: - case DRV_FORMAT_ABGR2101010: - case DRV_FORMAT_RGBA1010102: - case DRV_FORMAT_BGRA1010102: - case DRV_FORMAT_AYUV: + case DRM_FORMAT_ABGR2101010: + case DRM_FORMAT_ABGR8888: + case DRM_FORMAT_ARGB2101010: + case DRM_FORMAT_ARGB8888: + case DRM_FORMAT_AYUV: + case DRM_FORMAT_BGRA1010102: + case DRM_FORMAT_BGRA8888: + case DRM_FORMAT_BGRX1010102: + case DRM_FORMAT_BGRX8888: + case DRM_FORMAT_RGBA1010102: + case DRM_FORMAT_RGBA8888: + case DRM_FORMAT_RGBX1010102: + case DRM_FORMAT_RGBX8888: + case DRM_FORMAT_XBGR2101010: + case DRM_FORMAT_XBGR8888: + case DRM_FORMAT_XRGB2101010: + case DRM_FORMAT_XRGB8888: return 32; } @@ -153,32 +109,21 @@ int drv_bpp_from_format(uint32_t format, size_t plane) * buffer object. */ int drv_bo_from_format(struct bo *bo, uint32_t width, uint32_t height, - drv_format_t format) + uint32_t format) { - switch (format) { - case DRV_FORMAT_YVU420: - bo->strides[0] = drv_stride_from_format(format, width, 0); - bo->strides[1] = drv_stride_from_format(format, width, 1); - bo->strides[2] = drv_stride_from_format(format, width, 2); - bo->sizes[0] = height * bo->strides[0]; - bo->sizes[1] = bo->sizes[2] = (height / 2) * bo->strides[1]; - bo->offsets[0] = 0; - bo->offsets[1] = bo->sizes[0]; - bo->offsets[2] = bo->offsets[1] + bo->sizes[1]; - break; - case DRV_FORMAT_NV12: - bo->strides[0] = drv_stride_from_format(format, width, 0); - bo->strides[1] = drv_stride_from_format(format, width, 1); - bo->sizes[0] = height * bo->strides[0]; - bo->sizes[1] = height * bo->strides[1] / 2; - bo->offsets[0] = 0; - bo->offsets[1] = height * bo->strides[0]; - break; - default: - bo->strides[0] = drv_stride_from_format(format, width, 0); - bo->sizes[0] = height * bo->strides[0]; - bo->offsets[0] = 0; + size_t p, num_planes; + uint32_t offset = 0; + + num_planes = drv_num_planes_from_format(format); + assert(num_planes); + + for (p = 0; p < num_planes; p++) { + bo->strides[p] = drv_stride_from_format(format, width, p); + bo->sizes[p] = drv_size_from_format(format, bo->strides[p], + height, p); + bo->offsets[p] = offset; + offset += bo->sizes[p]; } bo->total_size = bo->offsets[bo->num_planes - 1] + @@ -208,6 +153,8 @@ int drv_dumb_bo_create(struct bo *bo, uint32_t width, uint32_t height, return ret; } + bo->width = width; + bo->height = height; bo->handles[0].u32 = create_dumb.handle; bo->offsets[0] = 0; bo->total_size = bo->sizes[0] = create_dumb.size; @@ -330,3 +277,145 @@ uint32_t drv_log_base2(uint32_t value) return ret; } + +/* Inserts a combination into list -- caller should have lock on driver. */ +void drv_insert_supported_combination(struct driver *drv, uint32_t format, + uint64_t usage, uint64_t modifier) +{ + struct combination_list_element *elem; + + elem = calloc(1, sizeof(*elem)); + elem->combination.format = format; + elem->combination.modifier = modifier; + elem->combination.usage = usage; + LIST_ADD(&elem->link, &drv->backend->combinations); +} + +void drv_insert_combinations(struct driver *drv, struct supported_combination *combos, + uint32_t size) +{ + unsigned int i; + + pthread_mutex_lock(&drv->driver_lock); + + for (i = 0; i < size; i++) + drv_insert_supported_combination(drv, combos[i].format, + combos[i].usage, + combos[i].modifier); + + pthread_mutex_unlock(&drv->driver_lock); +} + +void drv_modify_supported_combination(struct driver *drv, uint32_t format, + uint64_t usage, uint64_t modifier) +{ + /* + * Attempts to add the specified usage to an existing {format, modifier} + * pair. If the pair is not present, a new combination is created. + */ + int found = 0; + + pthread_mutex_lock(&drv->driver_lock); + + list_for_each_entry(struct combination_list_element, + elem, &drv->backend->combinations, link) { + if (elem->combination.format == format && + elem->combination.modifier == modifier) { + elem->combination.usage |= usage; + found = 1; + } + } + + + if (!found) + drv_insert_supported_combination(drv, format, usage, modifier); + + pthread_mutex_unlock(&drv->driver_lock); +} + +int drv_add_kms_flags(struct driver *drv) +{ + int ret; + uint32_t i, j; + uint64_t flag, usage; + drmModePlanePtr plane; + drmModePropertyPtr prop; + drmModePlaneResPtr resources; + drmModeObjectPropertiesPtr props; + + /* + * All current drivers can scanout XRGB8888/ARGB8888 as a primary plane. + * Some older kernel versions can only return overlay planes, so add the + * combination here. Note that the kernel disregards the alpha component + * of ARGB unless it's an overlay plane. + */ + drv_modify_supported_combination(drv, DRM_FORMAT_XRGB8888, + BO_USE_SCANOUT, 0); + drv_modify_supported_combination(drv, DRM_FORMAT_ARGB8888, + BO_USE_SCANOUT, 0); + + /* + * The ability to return universal planes is only complete on + * ChromeOS kernel versions >= v3.18. The SET_CLIENT_CAP ioctl + * therefore might return an error code, so don't check it. If it + * fails, it'll just return the plane list as overlay planes, which is + * fine in our case (our drivers already have cursor bits set). + * modetest in libdrm does the same thing. + */ + drmSetClientCap(drv->fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1); + + resources = drmModeGetPlaneResources(drv->fd); + if (!resources) + goto err; + + for (i = 0; i < resources->count_planes; i++) { + + plane = drmModeGetPlane(drv->fd, resources->planes[i]); + + if (!plane) + goto err; + + props = drmModeObjectGetProperties(drv->fd, plane->plane_id, + DRM_MODE_OBJECT_PLANE); + if (!props) + goto err; + + for (j = 0; j < props->count_props; j++) { + + prop = drmModeGetProperty(drv->fd, props->props[j]); + if (prop) { + if (strcmp(prop->name, "type") == 0) { + flag = props->prop_values[j]; + } + drmModeFreeProperty(prop); + } + } + + switch (flag) { + case DRM_PLANE_TYPE_OVERLAY: + case DRM_PLANE_TYPE_PRIMARY: + usage = BO_USE_SCANOUT; + break; + case DRM_PLANE_TYPE_CURSOR: + usage = BO_USE_CURSOR; + break; + default: + assert(0); + } + + for (j = 0; j < plane->count_formats; j++) + drv_modify_supported_combination(drv, plane->formats[j], + usage, 0); + + drmModeFreeObjectProperties(props); + drmModeFreePlane(plane); + + } + + drmModeFreePlaneResources(resources); + return 0; + +err: + ret = -1; + return ret; +} diff --git a/chromium/third_party/minigbm/src/helpers.h b/chromium/third_party/minigbm/src/helpers.h index 38e2e863541..71171c6fd2f 100644 --- a/chromium/third_party/minigbm/src/helpers.h +++ b/chromium/third_party/minigbm/src/helpers.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 The Chromium OS Authors. All rights reserved. + * Copyright 2014 The Chromium OS Authors. All rights reserved. * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ @@ -9,10 +9,9 @@ #include "drv.h" -size_t drv_num_planes_from_format(uint32_t format); int drv_bpp_from_format(uint32_t format, size_t plane); int drv_bo_from_format(struct bo *bo, uint32_t width, uint32_t height, - drv_format_t format); + uint32_t format); int drv_dumb_bo_create(struct bo *bo, uint32_t width, uint32_t height, uint32_t format, uint32_t flags); int drv_dumb_bo_destroy(struct bo *bo); @@ -25,4 +24,12 @@ void drv_increment_reference_count(struct driver *drv, struct bo *bo, void drv_decrement_reference_count(struct driver *drv, struct bo *bo, size_t plane); uint32_t drv_log_base2(uint32_t value); +void drv_insert_supported_combination(struct driver *drv, uint32_t format, + uint64_t usage, uint64_t modifier); +void drv_insert_combinations(struct driver *drv, + struct supported_combination *combos, + uint32_t size); +void drv_modify_supported_combination(struct driver *drv, uint32_t format, + uint64_t usage, uint64_t modifier); +int drv_add_kms_flags(struct driver *drv); #endif diff --git a/chromium/third_party/minigbm/src/i915.c b/chromium/third_party/minigbm/src/i915.c index 6bd1b966fc9..e74df4776c0 100644 --- a/chromium/third_party/minigbm/src/i915.c +++ b/chromium/third_party/minigbm/src/i915.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 The Chromium OS Authors. All rights reserved. + * Copyright 2014 The Chromium OS Authors. All rights reserved. * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ @@ -17,12 +17,50 @@ #include "helpers.h" #include "util.h" +static struct supported_combination combos[18] = { + {DRM_FORMAT_ARGB1555, DRM_FORMAT_MOD_NONE, + BO_USE_RENDERING | BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY}, + {DRM_FORMAT_ABGR8888, DRM_FORMAT_MOD_NONE, + BO_USE_RENDERING | BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN}, + {DRM_FORMAT_ABGR8888, DRM_FORMAT_MOD_NONE, + BO_USE_RENDERING | BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY}, + {DRM_FORMAT_ARGB8888, DRM_FORMAT_MOD_NONE, + BO_USE_CURSOR | BO_USE_LINEAR | BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN}, + {DRM_FORMAT_ARGB8888, DRM_FORMAT_MOD_NONE, + BO_USE_RENDERING | BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY}, + {DRM_FORMAT_GR88, DRM_FORMAT_MOD_NONE, + BO_USE_LINEAR | BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN}, + {DRM_FORMAT_R8, DRM_FORMAT_MOD_NONE, + BO_USE_LINEAR | BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN}, + {DRM_FORMAT_RGB565, DRM_FORMAT_MOD_NONE, + BO_USE_RENDERING | BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY}, + {DRM_FORMAT_UYVY, DRM_FORMAT_MOD_NONE, + BO_USE_LINEAR | BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN}, + {DRM_FORMAT_UYVY, DRM_FORMAT_MOD_NONE, + BO_USE_RENDERING | BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY}, + {DRM_FORMAT_XBGR8888, DRM_FORMAT_MOD_NONE, + BO_USE_RENDERING | BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN}, + {DRM_FORMAT_XBGR8888, DRM_FORMAT_MOD_NONE, + BO_USE_RENDERING | BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY}, + {DRM_FORMAT_XRGB1555, DRM_FORMAT_MOD_NONE, + BO_USE_RENDERING | BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY}, + {DRM_FORMAT_XRGB8888, DRM_FORMAT_MOD_NONE, + BO_USE_CURSOR | BO_USE_LINEAR | BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN}, + {DRM_FORMAT_XRGB8888, DRM_FORMAT_MOD_NONE, + BO_USE_RENDERING | BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY}, + {DRM_FORMAT_YUYV, DRM_FORMAT_MOD_NONE, + BO_USE_LINEAR | BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN}, + {DRM_FORMAT_YUYV, DRM_FORMAT_MOD_NONE, + BO_USE_RENDERING | BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY}, + {DRM_FORMAT_YVU420, DRM_FORMAT_MOD_NONE, + BO_USE_RENDERING | BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY}, +}; + struct i915_device { int gen; }; - static int get_gen(int device_id) { const uint16_t gen3_ids[] = {0x2582, 0x2592, 0x2772, 0x27A2, 0x27AE, @@ -60,7 +98,8 @@ static int i915_init(struct driver *drv) drv->priv = i915_drv; - return 0; + drv_insert_combinations(drv, combos, ARRAY_SIZE(combos)); + return drv_add_kms_flags(drv); } static void i915_close(struct driver *drv) @@ -130,10 +169,10 @@ static int i915_bo_create(struct bo *bo, uint32_t width, uint32_t height, size_t plane; int ret; - if (flags & (DRV_BO_USE_CURSOR | DRV_BO_USE_LINEAR | - DRV_BO_USE_SW_READ_OFTEN | DRV_BO_USE_SW_WRITE_OFTEN)) + if (flags & (BO_USE_CURSOR | BO_USE_LINEAR | + BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN)) tiling_mode = I915_TILING_NONE; - else if (flags & DRV_BO_USE_SCANOUT) + else if (flags & BO_USE_SCANOUT) tiling_mode = I915_TILING_X; else tiling_mode = I915_TILING_Y; @@ -203,20 +242,20 @@ static void *i915_bo_map(struct bo *bo, struct map_info *data, size_t plane) bo->drv->fd, gem_map.offset); } -static drv_format_t i915_resolve_format(drv_format_t format) +static uint32_t i915_resolve_format(uint32_t format) { switch (format) { - case DRV_FORMAT_FLEX_IMPLEMENTATION_DEFINED: + case DRM_FORMAT_FLEX_IMPLEMENTATION_DEFINED: /*HACK: See b/28671744 */ - return DRV_FORMAT_XBGR8888; - case DRV_FORMAT_FLEX_YCbCr_420_888: - return DRV_FORMAT_YVU420; + return DRM_FORMAT_XBGR8888; + case DRM_FORMAT_FLEX_YCbCr_420_888: + return DRM_FORMAT_YVU420; default: return format; } } -const struct backend backend_i915 = +struct backend backend_i915 = { .name = "i915", .init = i915_init, @@ -225,44 +264,6 @@ const struct backend backend_i915 = .bo_destroy = drv_gem_bo_destroy, .bo_map = i915_bo_map, .resolve_format = i915_resolve_format, - .format_list = { - {DRV_FORMAT_XRGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_RENDERING - | DRV_BO_USE_SW_READ_RARELY | DRV_BO_USE_SW_WRITE_RARELY}, - {DRV_FORMAT_XRGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_LINEAR | - DRV_BO_USE_SW_READ_OFTEN | DRV_BO_USE_SW_WRITE_OFTEN}, - {DRV_FORMAT_ARGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_RENDERING - | DRV_BO_USE_SW_READ_RARELY | DRV_BO_USE_SW_WRITE_RARELY}, - {DRV_FORMAT_ARGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_LINEAR | - DRV_BO_USE_SW_READ_OFTEN | DRV_BO_USE_SW_WRITE_OFTEN}, - {DRV_FORMAT_XBGR8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_RENDERING - | DRV_BO_USE_SW_READ_RARELY | DRV_BO_USE_SW_WRITE_RARELY}, - {DRV_FORMAT_XBGR8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_RENDERING | - DRV_BO_USE_SW_READ_OFTEN | DRV_BO_USE_SW_WRITE_OFTEN}, - {DRV_FORMAT_ABGR8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_RENDERING - | DRV_BO_USE_SW_READ_RARELY | DRV_BO_USE_SW_WRITE_RARELY}, - {DRV_FORMAT_ABGR8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_RENDERING | DRV_BO_USE_CURSOR - | DRV_BO_USE_SW_READ_OFTEN | DRV_BO_USE_SW_WRITE_OFTEN}, - {DRV_FORMAT_XRGB1555, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_RENDERING - | DRV_BO_USE_SW_READ_RARELY | DRV_BO_USE_SW_WRITE_RARELY}, - {DRV_FORMAT_ARGB1555, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_RENDERING - | DRV_BO_USE_SW_READ_RARELY | DRV_BO_USE_SW_WRITE_RARELY}, - {DRV_FORMAT_RGB565, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_RENDERING - | DRV_BO_USE_SW_READ_RARELY | DRV_BO_USE_SW_WRITE_RARELY}, - {DRV_FORMAT_UYVY, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_RENDERING - | DRV_BO_USE_SW_READ_RARELY | DRV_BO_USE_SW_WRITE_RARELY}, - {DRV_FORMAT_UYVY, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_LINEAR | - DRV_BO_USE_SW_READ_OFTEN | DRV_BO_USE_SW_WRITE_OFTEN}, - {DRV_FORMAT_YUYV, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_RENDERING - | DRV_BO_USE_SW_READ_RARELY | DRV_BO_USE_SW_WRITE_RARELY}, - {DRV_FORMAT_YUYV, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_LINEAR | - DRV_BO_USE_SW_READ_OFTEN | DRV_BO_USE_SW_WRITE_OFTEN}, - {DRV_FORMAT_R8, DRV_BO_USE_SCANOUT | DRV_BO_USE_LINEAR | - DRV_BO_USE_SW_READ_OFTEN | DRV_BO_USE_SW_WRITE_OFTEN}, - {DRV_FORMAT_GR88, DRV_BO_USE_SCANOUT | DRV_BO_USE_LINEAR | - DRV_BO_USE_SW_READ_OFTEN | DRV_BO_USE_SW_WRITE_OFTEN}, - {DRV_FORMAT_YVU420, DRV_BO_USE_RENDERING | DRV_BO_USE_SW_READ_RARELY | - DRV_BO_USE_SW_WRITE_RARELY}, - } }; #endif diff --git a/chromium/third_party/minigbm/src/list.h b/chromium/third_party/minigbm/src/list.h new file mode 100644 index 00000000000..53f46e7ffc1 --- /dev/null +++ b/chromium/third_party/minigbm/src/list.h @@ -0,0 +1,247 @@ +/************************************************************************** + * + * Copyright 2006 VMware, Inc., Bismarck, ND. USA. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + **************************************************************************/ + +/** + * \file + * List macros heavily inspired by the Linux kernel + * list handling. No list looping yet. + * + * Is not threadsafe, so common operations need to + * be protected using an external mutex. + */ + +#ifndef _UTIL_LIST_H_ +#define _UTIL_LIST_H_ + + +#include <stdbool.h> +#include <stddef.h> +#include <assert.h> + + +struct list_head +{ + struct list_head *prev; + struct list_head *next; +}; + +static inline void list_inithead(struct list_head *item) +{ + item->prev = item; + item->next = item; +} + +static inline void list_add(struct list_head *item, struct list_head *list) +{ + item->prev = list; + item->next = list->next; + list->next->prev = item; + list->next = item; +} + +static inline void list_addtail(struct list_head *item, struct list_head *list) +{ + item->next = list; + item->prev = list->prev; + list->prev->next = item; + list->prev = item; +} + +static inline bool list_empty(struct list_head *list); + +static inline void list_replace(struct list_head *from, struct list_head *to) +{ + if (list_empty(from)) { + list_inithead(to); + } else { + to->prev = from->prev; + to->next = from->next; + from->next->prev = to; + from->prev->next = to; + } +} + +static inline void list_del(struct list_head *item) +{ + item->prev->next = item->next; + item->next->prev = item->prev; + item->prev = item->next = NULL; +} + +static inline void list_delinit(struct list_head *item) +{ + item->prev->next = item->next; + item->next->prev = item->prev; + item->next = item; + item->prev = item; +} + +static inline bool list_empty(struct list_head *list) +{ + return list->next == list; +} + +/** + * Returns whether the list has exactly one element. + */ +static inline bool list_is_singular(const struct list_head *list) +{ + return list->next != NULL && list->next->next == list; +} + +static inline unsigned list_length(struct list_head *list) +{ + struct list_head *node; + unsigned length = 0; + for (node = list->next; node != list; node = node->next) + length++; + return length; +} + +static inline void list_splice(struct list_head *src, struct list_head *dst) +{ + if (list_empty(src)) + return; + + src->next->prev = dst; + src->prev->next = dst->next; + dst->next->prev = src->prev; + dst->next = src->next; +} + +static inline void list_splicetail(struct list_head *src, struct list_head *dst) +{ + if (list_empty(src)) + return; + + src->prev->next = dst; + src->next->prev = dst->prev; + dst->prev->next = src->next; + dst->prev = src->prev; +} + +static inline void list_validate(struct list_head *list) +{ + struct list_head *node; + assert(list->next->prev == list && list->prev->next == list); + for (node = list->next; node != list; node = node->next) + assert(node->next->prev == node && node->prev->next == node); +} + +#define LIST_INITHEAD(__item) list_inithead(__item) +#define LIST_ADD(__item, __list) list_add(__item, __list) +#define LIST_ADDTAIL(__item, __list) list_addtail(__item, __list) +#define LIST_REPLACE(__from, __to) list_replace(__from, __to) +#define LIST_DEL(__item) list_del(__item) +#define LIST_DELINIT(__item) list_delinit(__item) + +#define LIST_ENTRY(__type, __item, __field) \ + ((__type *)(void *)(((char *)(__item)) - offsetof(__type, __field))) + +#define LIST_IS_EMPTY(__list) \ + ((__list)->next == (__list)) + +/** + * Cast from a pointer to a member of a struct back to the containing struct. + * + * 'sample' MUST be initialized, or else the result is undefined! + */ +#ifndef container_of +#define container_of(ptr, sample, member) \ + (void *)((char *)(ptr) \ + - ((char *)&(sample)->member - (char *)(sample))) +#endif + +#define list_first_entry(ptr, type, member) \ + LIST_ENTRY(type, (ptr)->next, member) + +#define list_last_entry(ptr, type, member) \ + LIST_ENTRY(type, (ptr)->prev, member) + + +#define LIST_FOR_EACH_ENTRY(pos, head, member) \ + for (pos = NULL, pos = container_of((head)->next, pos, member); \ + &pos->member != (head); \ + pos = container_of(pos->member.next, pos, member)) + +#define LIST_FOR_EACH_ENTRY_SAFE(pos, storage, head, member) \ + for (pos = NULL, pos = container_of((head)->next, pos, member), \ + storage = container_of(pos->member.next, pos, member); \ + &pos->member != (head); \ + pos = storage, storage = container_of(storage->member.next, storage, member)) + +#define LIST_FOR_EACH_ENTRY_SAFE_REV(pos, storage, head, member) \ + for (pos = NULL, pos = container_of((head)->prev, pos, member), \ + storage = container_of(pos->member.prev, pos, member); \ + &pos->member != (head); \ + pos = storage, storage = container_of(storage->member.prev, storage, member)) + +#define LIST_FOR_EACH_ENTRY_FROM(pos, start, head, member) \ + for (pos = NULL, pos = container_of((start), pos, member); \ + &pos->member != (head); \ + pos = container_of(pos->member.next, pos, member)) + +#define LIST_FOR_EACH_ENTRY_FROM_REV(pos, start, head, member) \ + for (pos = NULL, pos = container_of((start), pos, member); \ + &pos->member != (head); \ + pos = container_of(pos->member.prev, pos, member)) + +#define list_for_each_entry(type, pos, head, member) \ + for (type *pos = LIST_ENTRY(type, (head)->next, member); \ + &pos->member != (head); \ + pos = LIST_ENTRY(type, pos->member.next, member)) + +#define list_for_each_entry_safe(type, pos, head, member) \ + for (type *pos = LIST_ENTRY(type, (head)->next, member), \ + *__next = LIST_ENTRY(type, pos->member.next, member); \ + &pos->member != (head); \ + pos = __next, \ + __next = LIST_ENTRY(type, __next->member.next, member)) + +#define list_for_each_entry_rev(type, pos, head, member) \ + for (type *pos = LIST_ENTRY(type, (head)->prev, member); \ + &pos->member != (head); \ + pos = LIST_ENTRY(type, pos->member.prev, member)) + +#define list_for_each_entry_safe_rev(type, pos, head, member) \ + for (type *pos = LIST_ENTRY(type, (head)->prev, member), \ + *__prev = LIST_ENTRY(type, pos->member.prev, member); \ + &pos->member != (head); \ + pos = __prev, \ + __prev = LIST_ENTRY(type, __prev->member.prev, member)) + +#define list_for_each_entry_from(type, pos, start, head, member) \ + for (type *pos = LIST_ENTRY(type, (start), member); \ + &pos->member != (head); \ + pos = LIST_ENTRY(type, pos->member.next, member)) + +#define list_for_each_entry_from_rev(type, pos, start, head, member) \ + for (type *pos = LIST_ENTRY(type, (start), member); \ + &pos->member != (head); \ + pos = LIST_ENTRY(type, pos->member.prev, member)) + +#endif /*_UTIL_LIST_H_*/ diff --git a/chromium/third_party/minigbm/src/marvell.c b/chromium/third_party/minigbm/src/marvell.c index 956223b9a84..a3a73ba52aa 100644 --- a/chromium/third_party/minigbm/src/marvell.c +++ b/chromium/third_party/minigbm/src/marvell.c @@ -8,19 +8,30 @@ #include "drv_priv.h" #include "helpers.h" +#include "util.h" -const struct backend backend_marvell = +static struct supported_combination combos[2] = { + {DRM_FORMAT_ARGB8888, DRM_FORMAT_MOD_NONE, + BO_USE_CURSOR | BO_USE_LINEAR | BO_USE_RENDERING | BO_USE_SW_READ_OFTEN | + BO_USE_SW_WRITE_OFTEN | BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY}, + {DRM_FORMAT_XRGB8888, DRM_FORMAT_MOD_NONE, + BO_USE_CURSOR | BO_USE_LINEAR | BO_USE_RENDERING | BO_USE_SW_READ_OFTEN | + BO_USE_SW_WRITE_OFTEN | BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY}, +} + +static int marvell_init(struct driver *drv) +{ + drv_insert_combinations(drv, combos, ARRAY_SIZE(combos)); + return drv_add_kms_flags(drv); +} + +struct backend backend_marvell = { .name = "marvell", + .init = marvell_init, .bo_create = drv_dumb_bo_create, .bo_destroy = drv_dumb_bo_destroy, .bo_map = drv_dumb_bo_map, - .format_list = { - {DRV_FORMAT_XRGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_RENDERING}, - {DRV_FORMAT_XRGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_LINEAR}, - {DRV_FORMAT_ARGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_RENDERING}, - {DRV_FORMAT_ARGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_LINEAR}, - } }; #endif diff --git a/chromium/third_party/minigbm/src/mediatek.c b/chromium/third_party/minigbm/src/mediatek.c index 381d8ab1ec4..9dc56a2e95b 100644 --- a/chromium/third_party/minigbm/src/mediatek.c +++ b/chromium/third_party/minigbm/src/mediatek.c @@ -14,6 +14,34 @@ #include "drv_priv.h" #include "helpers.h" +#include "util.h" + +static struct supported_combination combos[6] = { + {DRM_FORMAT_ABGR8888, DRM_FORMAT_MOD_NONE, + BO_USE_LINEAR | BO_USE_RENDERING | BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN | + BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY}, + {DRM_FORMAT_ARGB8888, DRM_FORMAT_MOD_NONE, + BO_USE_CURSOR | BO_USE_LINEAR | BO_USE_RENDERING | BO_USE_SW_READ_OFTEN | + BO_USE_SW_WRITE_OFTEN | BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY}, + {DRM_FORMAT_RGB565, DRM_FORMAT_MOD_NONE, + BO_USE_RENDERING | BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN | + BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY}, + {DRM_FORMAT_XBGR8888, DRM_FORMAT_MOD_NONE, + BO_USE_RENDERING | BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN | + BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY}, + {DRM_FORMAT_XRGB8888, DRM_FORMAT_MOD_NONE, + BO_USE_CURSOR | BO_USE_LINEAR | BO_USE_RENDERING | BO_USE_SW_READ_OFTEN | + BO_USE_SW_WRITE_OFTEN | BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY}, + {DRM_FORMAT_YVU420, DRM_FORMAT_MOD_NONE, + BO_USE_LINEAR | BO_USE_RENDERING | BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN | + BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY}, +}; + +static int mediatek_init(struct driver *drv) +{ + drv_insert_combinations(drv, combos, ARRAY_SIZE(combos)); + return drv_add_kms_flags(drv); +} static int mediatek_bo_create(struct bo *bo, uint32_t width, uint32_t height, uint32_t format, uint32_t flags) @@ -60,46 +88,27 @@ static void *mediatek_bo_map(struct bo *bo, struct map_info *data, size_t plane) bo->drv->fd, gem_map.offset); } -static drv_format_t mediatek_resolve_format(drv_format_t format) +static uint32_t mediatek_resolve_format(uint32_t format) { switch (format) { - case DRV_FORMAT_FLEX_IMPLEMENTATION_DEFINED: + case DRM_FORMAT_FLEX_IMPLEMENTATION_DEFINED: /*HACK: See b/28671744 */ - return DRV_FORMAT_XBGR8888; - case DRV_FORMAT_FLEX_YCbCr_420_888: - return DRV_FORMAT_YVU420; + return DRM_FORMAT_XBGR8888; + case DRM_FORMAT_FLEX_YCbCr_420_888: + return DRM_FORMAT_YVU420; default: return format; } } -const struct backend backend_mediatek = +struct backend backend_mediatek = { .name = "mediatek", + .init = mediatek_init, .bo_create = mediatek_bo_create, .bo_destroy = drv_gem_bo_destroy, .bo_map = mediatek_bo_map, .resolve_format = mediatek_resolve_format, - .format_list = { - {DRV_FORMAT_XRGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_RENDERING - | DRV_BO_USE_SW_READ_RARELY | DRV_BO_USE_SW_WRITE_RARELY}, - {DRV_FORMAT_XRGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_LINEAR - | DRV_BO_USE_SW_READ_OFTEN | DRV_BO_USE_SW_WRITE_OFTEN}, - {DRV_FORMAT_ARGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_RENDERING - | DRV_BO_USE_SW_READ_RARELY | DRV_BO_USE_SW_WRITE_RARELY}, - {DRV_FORMAT_ARGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_LINEAR | - DRV_BO_USE_SW_READ_OFTEN | DRV_BO_USE_SW_WRITE_OFTEN}, - {DRV_FORMAT_ABGR8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_RENDERING - | DRV_BO_USE_SW_READ_OFTEN | DRV_BO_USE_SW_WRITE_OFTEN - | DRV_BO_USE_SW_READ_RARELY | DRV_BO_USE_SW_WRITE_RARELY}, - {DRV_FORMAT_XBGR8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_RENDERING - | DRV_BO_USE_SW_READ_OFTEN | DRV_BO_USE_SW_WRITE_OFTEN - | DRV_BO_USE_SW_READ_RARELY | DRV_BO_USE_SW_WRITE_RARELY}, - {DRV_FORMAT_RGB565, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_RENDERING - | DRV_BO_USE_SW_READ_RARELY | DRV_BO_USE_SW_WRITE_RARELY}, - {DRV_FORMAT_YVU420, DRV_BO_USE_RENDERING | DRV_BO_USE_SW_READ_RARELY | - DRV_BO_USE_SW_WRITE_RARELY}, - } }; #endif diff --git a/chromium/third_party/minigbm/src/nouveau.c b/chromium/third_party/minigbm/src/nouveau.c new file mode 100644 index 00000000000..89122da75b7 --- /dev/null +++ b/chromium/third_party/minigbm/src/nouveau.c @@ -0,0 +1,29 @@ +/* + * Copyright 2016 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "drv_priv.h" +#include "helpers.h" +#include "util.h" + +static struct supported_combination combos[2] = { + {DRM_FORMAT_XRGB8888, DRM_FORMAT_MOD_NONE, BO_USE_CURSOR | BO_USE_RENDERING}, + {DRM_FORMAT_ARGB8888, DRM_FORMAT_MOD_NONE, BO_USE_CURSOR | BO_USE_RENDERING}, +}; + +static int nouveau_init(struct driver *drv) +{ + drv_insert_combinations(drv, combos, ARRAY_SIZE(combos)); + return drv_add_kms_flags(drv); +} + +struct backend backend_nouveau = +{ + .name = "nouveau", + .init = nouveau_init, + .bo_create = drv_dumb_bo_create, + .bo_destroy = drv_dumb_bo_destroy, + .bo_map = drv_dumb_bo_map, +}; diff --git a/chromium/third_party/minigbm/src/rockchip.c b/chromium/third_party/minigbm/src/rockchip.c index f2b94174e48..5e20036b42e 100644 --- a/chromium/third_party/minigbm/src/rockchip.c +++ b/chromium/third_party/minigbm/src/rockchip.c @@ -1,12 +1,11 @@ /* - * Copyright (c) 2014 The Chromium OS Authors. All rights reserved. + * Copyright 2014 The Chromium OS Authors. All rights reserved. * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ #ifdef DRV_ROCKCHIP -#include <assert.h> #include <errno.h> #include <stdio.h> #include <string.h> @@ -18,14 +17,108 @@ #include "helpers.h" #include "util.h" -static int rockchip_bo_create(struct bo *bo, uint32_t width, uint32_t height, - uint32_t format, uint32_t flags) +static struct supported_combination combos[11] = { + {DRM_FORMAT_ABGR8888, DRM_FORMAT_MOD_NONE, + BO_USE_RENDERING | BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN | + BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY}, + {DRM_FORMAT_ARGB8888, DRM_FORMAT_MOD_NONE, + BO_USE_CURSOR | BO_USE_LINEAR | BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN}, + {DRM_FORMAT_ARGB8888, DRM_FORMAT_MOD_NONE, + BO_USE_RENDERING | BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY}, + {DRM_FORMAT_NV12, DRM_FORMAT_MOD_NONE, + BO_USE_RENDERING | BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY}, + {DRM_FORMAT_NV12, DRM_FORMAT_MOD_NONE, + BO_USE_LINEAR | BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN}, + {DRM_FORMAT_RGB565, DRM_FORMAT_MOD_NONE, + BO_USE_RENDERING | BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY}, + {DRM_FORMAT_XBGR8888, DRM_FORMAT_MOD_NONE, + BO_USE_RENDERING | BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN | + BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY}, + {DRM_FORMAT_XBGR8888, DRM_FORMAT_MOD_NONE, + BO_USE_LINEAR | BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN}, + {DRM_FORMAT_XRGB8888, DRM_FORMAT_MOD_NONE, + BO_USE_CURSOR | BO_USE_LINEAR | BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN}, + {DRM_FORMAT_XRGB8888, DRM_FORMAT_MOD_NONE, + BO_USE_RENDERING | BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY}, + {DRM_FORMAT_YVU420, DRM_FORMAT_MOD_NONE, + BO_USE_RENDERING | BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY}, +}; + +static int afbc_bo_from_format(struct bo *bo, uint32_t width, uint32_t height, + uint32_t format) +{ + /* We've restricted ourselves to four bytes per pixel. */ + const uint32_t pixel_size = 4; + + const uint32_t clump_width = 4; + const uint32_t clump_height = 4; + +#define AFBC_NARROW 1 +#if AFBC_NARROW == 1 + const uint32_t block_width = 4 * clump_width; + const uint32_t block_height = 4 * clump_height; +#else + const uint32_t block_width = 8 * clump_width; + const uint32_t block_height = 2 * clump_height; +#endif + + const uint32_t header_block_size = 16; + const uint32_t body_block_size = block_width * block_height * pixel_size; + const uint32_t width_in_blocks = DIV_ROUND_UP(width, block_width); + const uint32_t height_in_blocks = DIV_ROUND_UP(height, block_height); + const uint32_t total_blocks = width_in_blocks * height_in_blocks; + + const uint32_t header_plane_size = total_blocks * header_block_size; + const uint32_t body_plane_size = total_blocks * body_block_size; + + /* GPU requires 64 bytes, but EGL import code expects 1024 byte + * alignement for the body plane. */ + const uint32_t body_plane_alignment = 1024; + + const uint32_t body_plane_offset = + ALIGN(header_plane_size, body_plane_alignment); + const uint32_t total_size = + body_plane_offset + body_plane_size; + + bo->strides[0] = width_in_blocks * block_width * pixel_size; + bo->sizes[0] = total_size; + bo->offsets[0] = 0; + + bo->total_size = total_size; + + bo->format_modifiers[0] = DRM_FORMAT_MOD_CHROMEOS_ROCKCHIP_AFBC; + + return 0; +} + +static int rockchip_init(struct driver *drv) +{ + drv_insert_combinations(drv, combos, ARRAY_SIZE(combos)); + return drv_add_kms_flags(drv); +} + +static bool has_modifier(const uint64_t *list, uint32_t count, uint64_t modifier) +{ + uint32_t i; + + for (i = 0; i < count; i++) + if (list[i] == modifier) + return true; + + return false; +} + +static int rockchip_bo_create_with_modifiers(struct bo *bo, + uint32_t width, uint32_t height, + uint32_t format, + const uint64_t *modifiers, + uint32_t count) { int ret; size_t plane; struct drm_rockchip_gem_create gem_create; - if (format == DRV_FORMAT_NV12) { + if (format == DRM_FORMAT_NV12) { uint32_t w_mbs = DIV_ROUND_UP(ALIGN(width, 16), 16); uint32_t h_mbs = DIV_ROUND_UP(ALIGN(width, 16), 16); @@ -35,7 +128,17 @@ static int rockchip_bo_create(struct bo *bo, uint32_t width, uint32_t height, drv_bo_from_format(bo, aligned_width, height, format); bo->total_size = bo->strides[0] * aligned_height + w_mbs * h_mbs * 128; + } else if (has_modifier(modifiers, count, + DRM_FORMAT_MOD_CHROMEOS_ROCKCHIP_AFBC)) { + /* If the caller has decided they can use AFBC, always + * pick that */ + afbc_bo_from_format(bo, width, height, format); } else { + if (!has_modifier(modifiers, count, DRM_FORMAT_MOD_NONE)) { + errno = EINVAL; + fprintf(stderr, "no usable modifier found\n"); + return -1; + } drv_bo_from_format(bo, width, height, format); } @@ -57,11 +160,25 @@ static int rockchip_bo_create(struct bo *bo, uint32_t width, uint32_t height, return 0; } +static int rockchip_bo_create(struct bo *bo, uint32_t width, uint32_t height, + uint32_t format, uint32_t flags) +{ + uint64_t modifiers[] = { DRM_FORMAT_MOD_NONE }; + + return rockchip_bo_create_with_modifiers(bo, width, height, format, + modifiers, ARRAY_SIZE(modifiers)); +} + static void *rockchip_bo_map(struct bo *bo, struct map_info *data, size_t plane) { int ret; struct drm_rockchip_gem_map_off gem_map; + /* We can only map buffers created with SW access flags, which should + * have no modifiers (ie, not AFBC). */ + if (bo->format_modifiers[0] == DRM_FORMAT_MOD_CHROMEOS_ROCKCHIP_AFBC) + return MAP_FAILED; + memset(&gem_map, 0, sizeof(gem_map)); gem_map.handle = bo->handles[0].u32; @@ -79,52 +196,28 @@ static void *rockchip_bo_map(struct bo *bo, struct map_info *data, size_t plane) bo->drv->fd, gem_map.offset); } -static drv_format_t rockchip_resolve_format(drv_format_t format) +static uint32_t rockchip_resolve_format(uint32_t format) { switch (format) { - case DRV_FORMAT_FLEX_IMPLEMENTATION_DEFINED: + case DRM_FORMAT_FLEX_IMPLEMENTATION_DEFINED: /*HACK: See b/28671744 */ - return DRV_FORMAT_XBGR8888; - case DRV_FORMAT_FLEX_YCbCr_420_888: - return DRV_FORMAT_NV12; + return DRM_FORMAT_XBGR8888; + case DRM_FORMAT_FLEX_YCbCr_420_888: + return DRM_FORMAT_NV12; default: return format; } } -const struct backend backend_rockchip = +struct backend backend_rockchip = { .name = "rockchip", + .init = rockchip_init, .bo_create = rockchip_bo_create, + .bo_create_with_modifiers = rockchip_bo_create_with_modifiers, .bo_destroy = drv_gem_bo_destroy, .bo_map = rockchip_bo_map, .resolve_format = rockchip_resolve_format, - .format_list = { - {DRV_FORMAT_XRGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_RENDERING - | DRV_BO_USE_SW_READ_RARELY | DRV_BO_USE_SW_WRITE_RARELY}, - {DRV_FORMAT_XRGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_LINEAR | - DRV_BO_USE_SW_READ_OFTEN | DRV_BO_USE_SW_WRITE_OFTEN}, - {DRV_FORMAT_XBGR8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_RENDERING - | DRV_BO_USE_SW_READ_OFTEN | DRV_BO_USE_SW_WRITE_OFTEN - | DRV_BO_USE_SW_READ_RARELY | DRV_BO_USE_SW_WRITE_RARELY}, - {DRV_FORMAT_XBGR8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_LINEAR | - DRV_BO_USE_SW_READ_OFTEN | DRV_BO_USE_SW_WRITE_OFTEN}, - {DRV_FORMAT_ARGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_RENDERING - | DRV_BO_USE_SW_READ_RARELY | DRV_BO_USE_SW_WRITE_RARELY}, - {DRV_FORMAT_RGB565, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_RENDERING - | DRV_BO_USE_SW_READ_RARELY | DRV_BO_USE_SW_WRITE_RARELY}, - {DRV_FORMAT_ARGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_LINEAR | - DRV_BO_USE_SW_READ_OFTEN | DRV_BO_USE_SW_WRITE_OFTEN}, - {DRV_FORMAT_ABGR8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_RENDERING - | DRV_BO_USE_SW_READ_OFTEN | DRV_BO_USE_SW_WRITE_OFTEN - | DRV_BO_USE_SW_READ_RARELY | DRV_BO_USE_SW_WRITE_RARELY}, - {DRV_FORMAT_NV12, DRV_BO_USE_SCANOUT | DRV_BO_USE_RENDERING | - DRV_BO_USE_SW_READ_RARELY | DRV_BO_USE_SW_WRITE_RARELY}, - {DRV_FORMAT_NV12, DRV_BO_USE_SCANOUT | DRV_BO_USE_LINEAR | - DRV_BO_USE_SW_READ_OFTEN | DRV_BO_USE_SW_WRITE_OFTEN}, - {DRV_FORMAT_YVU420, DRV_BO_USE_RENDERING | DRV_BO_USE_SW_READ_RARELY | - DRV_BO_USE_SW_WRITE_RARELY}, - } }; #endif diff --git a/chromium/third_party/minigbm/src/tegra.c b/chromium/third_party/minigbm/src/tegra.c index 28f98c64283..923fef16f00 100644 --- a/chromium/third_party/minigbm/src/tegra.c +++ b/chromium/third_party/minigbm/src/tegra.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 The Chromium OS Authors. All rights reserved. + * Copyright 2014 The Chromium OS Authors. All rights reserved. * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ @@ -33,6 +33,27 @@ enum nv_mem_kind NV_MEM_KIND_GENERIC_16Bx2 = 0xfe, }; +enum tegra_map_type { + TEGRA_READ_TILED_BUFFER = 0, + TEGRA_WRITE_TILED_BUFFER = 1, +}; + +struct tegra_private_map_data { + void *tiled; + void *untiled; +}; + +static struct supported_combination combos[4] = { + {DRM_FORMAT_ARGB8888, DRM_FORMAT_MOD_NONE, + BO_USE_CURSOR | BO_USE_LINEAR | BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN}, + {DRM_FORMAT_ARGB8888, DRM_FORMAT_MOD_NONE, + BO_USE_RENDERING | BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY}, + {DRM_FORMAT_XRGB8888, DRM_FORMAT_MOD_NONE, + BO_USE_CURSOR | BO_USE_LINEAR | BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN}, + {DRM_FORMAT_XRGB8888, DRM_FORMAT_MOD_NONE, + BO_USE_RENDERING | BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY}, +}; + static int compute_block_height_log2(int height) { int block_height_log2 = NV_DEFAULT_BLOCK_HEIGHT_LOG2; @@ -83,10 +104,86 @@ static void compute_layout_blocklinear(int width, int height, int format, static void compute_layout_linear(int width, int height, int format, uint32_t *stride, uint32_t *size) { - *stride = drv_stride_from_format(format, width, 0); + *stride = ALIGN(drv_stride_from_format(format, width, 0), 64); *size = *stride * height; } +static void transfer_tile(struct bo *bo, uint8_t *tiled, uint8_t *untiled, + enum tegra_map_type type, uint32_t bytes_per_pixel, + uint32_t gob_top, uint32_t gob_left, + uint32_t gob_size_pixels) +{ + uint8_t *tmp; + uint32_t x, y, k; + for (k = 0; k < gob_size_pixels; k++) { + /* + * Given the kth pixel starting from the tile specified by + * gob_top and gob_left, unswizzle to get the standard (x, y) + * representation. + */ + x = gob_left + (((k >> 3) & 8) | ((k >> 1) & 4) | (k & 3)); + y = gob_top + ((k >> 7 << 3) | ((k >> 3) & 6) | ((k >> 2) & 1)); + + tmp = untiled + (y * bo->strides[0]) + (x * bytes_per_pixel); + + if (type == TEGRA_READ_TILED_BUFFER) + memcpy(tmp, tiled, bytes_per_pixel); + else if (type == TEGRA_WRITE_TILED_BUFFER) + memcpy(tiled, tmp, bytes_per_pixel); + + /* Move on to next pixel. */ + tiled += bytes_per_pixel; + } +} + +static void transfer_tiled_memory(struct bo *bo, uint8_t *tiled, + uint8_t *untiled, enum tegra_map_type type) +{ + uint32_t gob_width, gob_height, gob_size_bytes, gob_size_pixels, + gob_count_x, gob_count_y, gob_top, gob_left; + uint32_t i, j, offset; + uint8_t *tmp; + uint32_t bytes_per_pixel = drv_stride_from_format(bo->format, 1, 0); + + /* + * The blocklinear format consists of 8*(2^n) x 64 byte sized tiles, + * where 0 <= n <= 4. + */ + gob_width = DIV_ROUND_UP(NV_BLOCKLINEAR_GOB_WIDTH, bytes_per_pixel); + gob_height = NV_BLOCKLINEAR_GOB_HEIGHT * + (1 << NV_DEFAULT_BLOCK_HEIGHT_LOG2); + /* Calculate the height from maximum possible gob height */ + while (gob_height > NV_BLOCKLINEAR_GOB_HEIGHT + && gob_height >= 2 * bo->height) + gob_height /= 2; + + gob_size_bytes = gob_height * NV_BLOCKLINEAR_GOB_WIDTH; + gob_size_pixels = gob_height * gob_width; + + gob_count_x = DIV_ROUND_UP(bo->strides[0], NV_BLOCKLINEAR_GOB_WIDTH); + gob_count_y = DIV_ROUND_UP(bo->height, gob_height); + + offset = 0; + for (j = 0; j < gob_count_y; j++) { + gob_top = j * gob_height; + for (i = 0; i < gob_count_x; i++) { + tmp = tiled + offset; + gob_left = i * gob_width; + + transfer_tile(bo, tmp, untiled, type, bytes_per_pixel, + gob_top, gob_left, gob_size_pixels); + + offset += gob_size_bytes; + } + } +} + +static int tegra_init(struct driver *drv) +{ + drv_insert_combinations(drv, combos, ARRAY_SIZE(combos)); + return drv_add_kms_flags(drv); +} + static int tegra_bo_create(struct bo *bo, uint32_t width, uint32_t height, uint32_t format, uint32_t flags) { @@ -95,7 +192,7 @@ static int tegra_bo_create(struct bo *bo, uint32_t width, uint32_t height, struct drm_tegra_gem_create gem_create; int ret; - if (flags & DRV_BO_USE_RENDERING) + if (flags & BO_USE_RENDERING) compute_layout_blocklinear(width, height, format, &kind, &block_height_log2, &stride, &size); else @@ -135,7 +232,7 @@ static int tegra_bo_create(struct bo *bo, uint32_t width, uint32_t height, /* Encode blocklinear parameters for EGLImage creation. */ bo->tiling = (kind & 0xff) | ((block_height_log2 & 0xf) << 8); - bo->format_modifiers[0] = drv_fourcc_mod_code(NV, bo->tiling); + bo->format_modifiers[0] = fourcc_mod_code(NV, bo->tiling); } return 0; @@ -145,6 +242,7 @@ static void *tegra_bo_map(struct bo *bo, struct map_info *data, size_t plane) { int ret; struct drm_tegra_gem_mmap gem_map; + struct tegra_private_map_data *priv; memset(&gem_map, 0, sizeof(gem_map)); gem_map.handle = bo->handles[0].u32; @@ -156,30 +254,47 @@ static void *tegra_bo_map(struct bo *bo, struct map_info *data, size_t plane) return MAP_FAILED; } + void *addr = mmap(0, bo->total_size, PROT_READ | PROT_WRITE, MAP_SHARED, + bo->drv->fd, gem_map.offset); + data->length = bo->total_size; - return mmap(0, bo->total_size, PROT_READ | PROT_WRITE, MAP_SHARED, - bo->drv->fd, gem_map.offset); + if ((bo->tiling & 0xFF) == NV_MEM_KIND_C32_2CRA && addr != MAP_FAILED) { + priv = calloc(1, sizeof(*priv)); + priv->untiled = calloc(1, bo->total_size); + priv->tiled = addr; + data->priv = priv; + transfer_tiled_memory(bo, priv->tiled, priv->untiled, + TEGRA_READ_TILED_BUFFER); + addr = priv->untiled; + } + + return addr; } -const struct backend backend_tegra = +static int tegra_bo_unmap(struct bo *bo, struct map_info *data) +{ + if (data->priv) { + struct tegra_private_map_data *priv = data->priv; + transfer_tiled_memory(bo, priv->tiled, priv->untiled, + TEGRA_WRITE_TILED_BUFFER); + data->addr = priv->tiled; + free(priv->untiled); + free(priv); + data->priv = NULL; + } + + return munmap(data->addr, data->length); +} + +struct backend backend_tegra = { .name = "tegra", + .init = tegra_init, .bo_create = tegra_bo_create, .bo_destroy = drv_gem_bo_destroy, .bo_map = tegra_bo_map, - .format_list = { - /* Linear support */ - {DRV_FORMAT_XRGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_LINEAR - | DRV_BO_USE_SW_READ_OFTEN | DRV_BO_USE_SW_WRITE_OFTEN}, - {DRV_FORMAT_ARGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_LINEAR - | DRV_BO_USE_SW_READ_OFTEN | DRV_BO_USE_SW_WRITE_OFTEN}, - /* Blocklinear support */ - {DRV_FORMAT_XRGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_RENDERING | - DRV_BO_USE_SW_READ_RARELY | DRV_BO_USE_SW_WRITE_RARELY}, - {DRV_FORMAT_ARGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_RENDERING | - DRV_BO_USE_SW_READ_RARELY | DRV_BO_USE_SW_WRITE_RARELY}, - } + .bo_unmap = tegra_bo_unmap, }; #endif diff --git a/chromium/third_party/minigbm/src/udl.c b/chromium/third_party/minigbm/src/udl.c index 35d3eb44955..bec00225cec 100644 --- a/chromium/third_party/minigbm/src/udl.c +++ b/chromium/third_party/minigbm/src/udl.c @@ -1,22 +1,33 @@ /* - * Copyright (c) 2014 The Chromium OS Authors. All rights reserved. + * Copyright 2014 The Chromium OS Authors. All rights reserved. * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ #include "drv_priv.h" #include "helpers.h" +#include "util.h" -const struct backend backend_udl = +static struct supported_combination combos[2] = { + {DRM_FORMAT_ARGB8888, DRM_FORMAT_MOD_NONE, + BO_USE_CURSOR | BO_USE_LINEAR | BO_USE_RENDERING | BO_USE_SW_READ_OFTEN | + BO_USE_SW_WRITE_OFTEN | BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY}, + {DRM_FORMAT_XRGB8888, DRM_FORMAT_MOD_NONE, + BO_USE_CURSOR | BO_USE_LINEAR | BO_USE_RENDERING | BO_USE_SW_READ_OFTEN | + BO_USE_SW_WRITE_OFTEN | BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY}, +}; + +static int udl_init(struct driver *drv) +{ + drv_insert_combinations(drv, combos, ARRAY_SIZE(combos)); + return drv_add_kms_flags(drv); +} + +struct backend backend_udl = { .name = "udl", + .init = udl_init, .bo_create = drv_dumb_bo_create, .bo_destroy = drv_dumb_bo_destroy, .bo_map = drv_dumb_bo_map, - .format_list = { - {DRV_FORMAT_XRGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_RENDERING}, - {DRV_FORMAT_XRGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_LINEAR}, - {DRV_FORMAT_ARGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_RENDERING}, - {DRV_FORMAT_ARGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_LINEAR}, - } }; diff --git a/chromium/third_party/minigbm/src/util.h b/chromium/third_party/minigbm/src/util.h index 9606336fdc4..696b996b9af 100644 --- a/chromium/third_party/minigbm/src/util.h +++ b/chromium/third_party/minigbm/src/util.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 The Chromium OS Authors. All rights reserved. + * Copyright 2014 The Chromium OS Authors. All rights reserved. * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ diff --git a/chromium/third_party/minigbm/src/vgem.c b/chromium/third_party/minigbm/src/vgem.c index 71efcc73e51..c6f5bb26bab 100644 --- a/chromium/third_party/minigbm/src/vgem.c +++ b/chromium/third_party/minigbm/src/vgem.c @@ -6,32 +6,64 @@ #include "drv_priv.h" #include "helpers.h" +#include "util.h" -static drv_format_t vgem_resolve_format(drv_format_t format) +#define MESA_LLVMPIPE_TILE_ORDER 6 +#define MESA_LLVMPIPE_TILE_SIZE (1 << MESA_LLVMPIPE_TILE_ORDER) + +static struct supported_combination combos[4] = { + {DRM_FORMAT_ABGR8888, DRM_FORMAT_MOD_NONE, + BO_USE_CURSOR | BO_USE_LINEAR | BO_USE_RENDERING | BO_USE_SW_READ_OFTEN | + BO_USE_SW_WRITE_OFTEN | BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY}, + {DRM_FORMAT_RGB565, DRM_FORMAT_MOD_NONE, + BO_USE_LINEAR | BO_USE_RENDERING | BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN | + BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY}, + {DRM_FORMAT_XBGR8888, DRM_FORMAT_MOD_NONE, + BO_USE_CURSOR | BO_USE_LINEAR | BO_USE_RENDERING | BO_USE_SW_READ_OFTEN | + BO_USE_SW_WRITE_OFTEN | BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY}, + {DRM_FORMAT_YVU420, DRM_FORMAT_MOD_NONE, + BO_USE_LINEAR | BO_USE_RENDERING | BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN | + BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY}, +}; + +static int vgem_init(struct driver *drv) +{ + drv_insert_combinations(drv, combos, ARRAY_SIZE(combos)); + return 0; +} + +static int vgem_bo_create(struct bo *bo, uint32_t width, uint32_t height, + uint32_t format, uint32_t flags) +{ + int ret = drv_dumb_bo_create(bo, ALIGN(width, MESA_LLVMPIPE_TILE_SIZE), + ALIGN(height, MESA_LLVMPIPE_TILE_SIZE), + format, flags); + bo->width = width; + bo->height = height; + + return ret; +} + +static uint32_t vgem_resolve_format(uint32_t format) { switch (format) { - case DRV_FORMAT_FLEX_IMPLEMENTATION_DEFINED: + case DRM_FORMAT_FLEX_IMPLEMENTATION_DEFINED: /*HACK: See b/28671744 */ - return DRV_FORMAT_XBGR8888; - case DRV_FORMAT_FLEX_YCbCr_420_888: - return DRV_FORMAT_YVU420; + return DRM_FORMAT_XBGR8888; + case DRM_FORMAT_FLEX_YCbCr_420_888: + return DRM_FORMAT_YVU420; default: return format; } } -const struct backend backend_vgem = +struct backend backend_vgem = { .name = "vgem", - .bo_create = drv_dumb_bo_create, + .init = vgem_init, + .bo_create = vgem_bo_create, .bo_destroy = drv_dumb_bo_destroy, .bo_map = drv_dumb_bo_map, .resolve_format = vgem_resolve_format, - .format_list = { - {DRV_FORMAT_ABGR8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_RENDERING | DRV_BO_USE_CURSOR - | DRV_BO_USE_SW_READ_OFTEN | DRV_BO_USE_SW_WRITE_OFTEN}, - {DRV_FORMAT_YVU420, DRV_BO_USE_SCANOUT | DRV_BO_USE_RENDERING | - DRV_BO_USE_SW_READ_RARELY | DRV_BO_USE_SW_WRITE_RARELY}, - } }; diff --git a/chromium/third_party/minigbm/src/virtio_gpu.c b/chromium/third_party/minigbm/src/virtio_gpu.c index ed50bc097db..5336bacbdd4 100644 --- a/chromium/third_party/minigbm/src/virtio_gpu.c +++ b/chromium/third_party/minigbm/src/virtio_gpu.c @@ -6,18 +6,29 @@ #include "drv_priv.h" #include "helpers.h" +#include "util.h" -const struct backend backend_virtio_gpu = +static struct supported_combination combos[2] = { + {DRM_FORMAT_ARGB8888, DRM_FORMAT_MOD_NONE, + BO_USE_CURSOR | BO_USE_LINEAR | BO_USE_RENDERING | BO_USE_SW_READ_OFTEN | + BO_USE_SW_WRITE_OFTEN | BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY}, + {DRM_FORMAT_XRGB8888, DRM_FORMAT_MOD_NONE, + BO_USE_CURSOR | BO_USE_LINEAR | BO_USE_RENDERING | BO_USE_SW_READ_OFTEN | + BO_USE_SW_WRITE_OFTEN | BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY}, +}; + +static int virtio_gpu_init(struct driver *drv) +{ + drv_insert_combinations(drv, combos, ARRAY_SIZE(combos)); + return drv_add_kms_flags(drv); +} + +struct backend backend_virtio_gpu = { .name = "virtio_gpu", + .init = virtio_gpu_init, .bo_create = drv_dumb_bo_create, .bo_destroy = drv_dumb_bo_destroy, .bo_map = drv_dumb_bo_map, - .format_list = { - {DRV_FORMAT_XRGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_RENDERING}, - {DRV_FORMAT_XRGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_LINEAR}, - {DRV_FORMAT_ARGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_RENDERING}, - {DRV_FORMAT_ARGB8888, DRV_BO_USE_SCANOUT | DRV_BO_USE_CURSOR | DRV_BO_USE_LINEAR}, - } }; |