Commit graph

68 commits

Author SHA1 Message Date
Roman Stratiienko
446588514a minigbm: Add drv_bo_get_pixel_stride function
Some drivers may copy/convert the buffer during mapping and
in some cases stride of copied image can be different from
original. Android uses pixel_stride for CPU access and need
map_time stride instead of original stride in this cases.

Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
2026-07-15 22:36:25 -04:00
Roman Stratiienko
37858e5143 minigbm: Add external driver support
Allow backends with custom DRM probing logic or
backends that does not rely on DRM (dma-heap, ION).

Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
Change-Id: I7bcaf10205ca051eb109d6e220b8a2af38267442
2026-07-15 22:36:25 -04:00
710cfdaae9 Drop DRM master after opening card node so the composer can master it
Change-Id: I6e40ed8fbfec788bc8f5382338d573057f230f79
2026-07-12 14:31:15 -04:00
Yiwei Zhang
6af751e128 cros_gralloc: fallback to check ro.board.platform for SS VK
For bringup purpose, SS VK might be used to boot the system. To ease the
runtime vulkan icd switch, normally we preset TARGET_BOARD_PLATFORM to
pastel, so that to leave ro.hardware.vulkan unset post boot. At runtime,
we can push a real hw driver and set ro.hardware.vulkan to switch to it,
which can be safely reset after reboot.

Bug: b/417259528
Test: boot to ui with SS VK chosen by TARGET_BOARD_PLATFORM
Change-Id: I37212fadaf007c2c2d054b878f0a4f411f1a6fe8
2025-05-24 05:54:09 +00:00
Jason Macnak
4cca6f67dd Error when attempting to lock buffer alloc'd without CPU_ usage
... except when running with software rendering as apps do not
know that they would need to request additional CPU_* usage
for GPU_* usage.

Bug: b/356845188
Test: cts -m CtsNativeHardwareTestCases
Change-Id: I3536d80469d2187550558e9d02795896de4f9827
2024-08-02 08:18:36 -07:00
Jason Macnak
92eb16bb24 gralloc: Move buffer metadata accessing into cros_gralloc_buffer
... to hide cros_gralloc_buffer_metadata from the AIDL/HIDL Apis.
No functional change expected.

Bug: b/321158178
Test: vts -m VtsHalGraphicsAllocatorAidl_TargetTest
Test: vts -m VtsHalGraphicsMapperV4_0Target
Test: vts -m VtsHalGraphicsMapperStableC_TargetTest
Change-Id: I33f17670a331385b0afe0e179cab8985b7fe78b9
2024-01-23 13:52:17 -08:00
Jason Macnak
bd616875b5 gralloc: Move buffer metadata initialization into common layer
... to dedup and support upcoming change to metadata initialization.

Bug: b/321158178
Test: vts -m VtsHalGraphicsAllocatorAidl_TargetTest
Test: vts -m VtsHalGraphicsMapperV4_0Target
Test: vts -m VtsHalGraphicsMapperStableC_TargetTest
Change-Id: Ib00873babcb2ec8816b0d319e675d6884594f618
2024-01-23 13:52:14 -08:00
Jason Macnak
1f9a351e4f gralloc: Use std::shared_ptr for cros_gralloc_driver
... to ensure the lifetime of the underlying cros_gralloc_driver
matches those of the various Mapper* interfaces. Without this, the
the destruction of the static cros_gralloc_driver `s_instance`
could race with a potential CrosGralloc4Mapper user on another
thread which is still alive at the time of exit() (for example,
a buffer being cleaned up on a libhwbinder worker thread).

Bug: b/300616292
Bug: b/300194143
Bug: b/294661992
Test: launch Cuttlefish, run SurfaceFlinger_test, inspect
      tracing around lifetime of cros_gralloc_driver
Change-Id: Id8e2dbff471c03f7b663952524905a06cc03fbc1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/4897926
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Tested-by: Jason Macnak <natsu@google.com>
Commit-Queue: Jason Macnak <natsu@google.com>
2023-09-28 17:11:55 +00:00
Dawn Han
3940cbd883 minigbm: move camera work-around
Move mt8183_camera_quirk_ into struct cross_domain_private.
Add a helper `drv_get_os_option` in `drv_helper` to query os option.
Advertise DRM_FORMAT_MTISP_SXYZW10 as supported format in virtgpu_cross_domain.c.
Implement cross domain's own resolve_format_and_use_flags entry point.

BUG=b:269982880

TEST=tested on a kukui machine after applying the change. Camera and
screen recording works fine.

Change-Id: Ia0d6e2cc701477aa6b9542de84e24f8aeb5a29e0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/4304961
Commit-Queue: Dawn Han <dawnhan@google.com>
Reviewed-by: Dominik Behr <dbehr@chromium.org>
Tested-by: Dawn Han <dawnhan@google.com>
2023-05-02 21:06:13 +00:00
Dawn Han
84b3a09ef0 minigbm: clean up bo.handles
The multi-planar formats are being allocated into a single plane,
and the minigbm exynos backend is dropped. So we can use `handle` instead of handles as of now.

Remove some of the helper functions that calculate the number of planes.
There is no need to check if there is more than one kernel buffer per buffer object.

Added a new function `drv_gem_close` in `drv_helpers` that can be used by `drv_gem_bo_destroy` and `drv_prime_bo_import`. It can be used to clean the unused gem_handle.

Bug=b:266776512
TEST=camera and screenshot work fine after deploying the change #strongbad
TEST=camera and screenshot work fine after deploying the change #kukui-arc-r
TEST=camera and screenshot work fine after deploying the change, tested a couple of apps in the Google Play Store, and checked file `dma_buf/bufinfo` to see there's no object leaking. #guybrush

Change-Id: Ib63559504e4cb8f1a32ae90170925146613d694f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/4297873
Commit-Queue: Dawn Han <dawnhan@google.com>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Tested-by: Dawn Han <dawnhan@google.com>
2023-04-09 18:57:40 +00:00
Dawn Han
e0983035ca minigbm: fix format
Correct the formats in cros_gralloc_driver.

Bug=N/A
TEST=N/A

Change-Id: I59bc09ee04dd05ffbd83243d6c071eb018facab2
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/4324140
Tested-by: Dawn Han <dawnhan@google.com>
Commit-Queue: Dawn Han <dawnhan@google.com>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
2023-03-15 02:25:38 +00:00
Yiwei Zhang
7997ad203b cros_gralloc: restrict DRM_FORMAT_MTISP_SXYZW10 to non-scanout
BUG=b:271382698
TEST=cts

Change-Id: Ia81decf01c3254bc61887e2070d9307d6f1f82c6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/4317163
Auto-Submit: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Dawn Han <dawnhan@google.com>
Reviewed-by: Lina Versace <chadversary@chromium.org>
Tested-by: Yiwei Zhang <zzyiwei@chromium.org>
2023-03-08 17:29:01 +00:00
Chia-I Wu
9f36afc60a cros_gralloc: use drv_preload
Help GraphicBufferMapper::preloadHal() preload the dri driver as well.

BUG=b:269664560
TEST="grep radeonsi /proc/$(pidof zygote)/maps" on grunt

Change-Id: I8bd4f7355840162c29958ccd98246e587b9caae7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/4262035
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Tested-by: Chia-I Wu <olv@google.com>
Commit-Queue: Chia-I Wu <olv@google.com>
2023-02-21 19:57:35 +00:00
Yiwei Zhang
b377924a7b minigbm: format fix and add missing header
BUG=n/a
TEST=build

Change-Id: Id2dac9a25190ba8ee05f42ef3a4ff8a1e3965844
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/4269511
Reviewed-by: Satoshi Niwa <niwa@chromium.org>
Commit-Queue: Yiwei Zhang <zzyiwei@chromium.org>
Tested-by: Yiwei Zhang <zzyiwei@chromium.org>
Auto-Submit: Yiwei Zhang <zzyiwei@chromium.org>
2023-02-20 22:49:46 +00:00
David Stevens
3e300b638a gralloc: add workaround for MT8183 private format
Add support for the MT8183 private camera format to gralloc. This is
done as a vendor specific workaround that bypasses the normal minigbm
format resolution, targeting kukui+ARCVM.

This is aimed at working around the fact that the virtgpu cross domain
backend needs to directly resolve formats itself. Proper support for
involving the host when resolving formats would be cleaner. However,
that would be a substantial amount of work for what is (hopefully) a
one-off situation.

BUG=b:158617858
TEST=testBasicOpaqueToJpegReprocessing on kukui-arc-r DUT

Change-Id: I8e1d74aac0a16babd7d7e2e630ff8affb3104e8b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/4258986
Tested-by: David Stevens <stevensd@chromium.org>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Commit-Queue: David Stevens <stevensd@chromium.org>
2023-02-20 05:13:54 +00:00
Jason Macnak
399fa8b592 gralloc: Remove release_fence arg from cros_gralloc_driver::flush()
... to match downstream aosp/2279448.

BUG=b:259311835
TEST=presubmit

Change-Id: I696998e627abb0d88b83d55f8fb335df3dd7576c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/4073504
Commit-Queue: Jason Macnak <natsu@google.com>
Tested-by: Jason Macnak <natsu@google.com>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
2022-12-02 17:43:11 +00:00
Yiwei Zhang
9f1fb038de gralloc: adopt BufferUsage::FRONT_BUFFER
BUG=N/A
TEST=build

Change-Id: I9ffceb16f1a7fd93981ca9eaf72ba68baff5d24b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/3852310
Reviewed-by: Jason Macnak <natsu@google.com>
Tested-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Ryan Neph <ryanneph@google.com>
Commit-Queue: Yiwei Zhang <zzyiwei@chromium.org>
2022-09-09 17:52:58 +00:00
Yiwei Zhang
bfb3c781a4 gralloc: use ALOGE instead of drv_log
TEST=build

Change-Id: I78b123f395fef8853f310a567ac0341b6958c535
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/3761445
Reviewed-by: Jason Macnak <natsu@google.com>
Reviewed-by: Dominik Behr <dbehr@chromium.org>
Commit-Queue: Yiwei Zhang <zzyiwei@chromium.org>
Auto-Submit: Yiwei Zhang <zzyiwei@chromium.org>
Tested-by: Yiwei Zhang <zzyiwei@chromium.org>
2022-07-15 06:50:52 +00:00
Jason Macnak
db3c6fcf02 gralloc: Hide dmabuf heap allocator behind of a flag
... so that devices that have API level 31 but do not have the
system dmabuf heap installed (as it is not required) do not spam
error logs before falling back to memfd.

BUG=b:227375257
TEST=build Cuttlefish with aosp/2051732
TEST=cvd start
TEST=vts -m VtsHalGraphicsMapperV4_0Target

Change-Id: I7ab79ce472b1e3d84ffa8bb06044ecc933847656
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/3563512
Commit-Queue: Jason Macnak <natsu@google.com>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Commit-Queue: Yiwei Zhang <zzyiwei@chromium.org>
Tested-by: Yiwei Zhang <zzyiwei@chromium.org>
2022-04-01 10:00:09 +00:00
Jason Macnak
eaafb204ff gralloc: use a struct for imported handle info
"Prefer to use a struct instead of a pair or a tuple
whenever the elements can have meaningful names."

BUG=b:207388558
TEST=cvd start
TEST=vts -m VtsHalGraphicsMapperV4_0Target

Change-Id: I688267a4c40f0260476029c0d70bc8bb19943e21
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/3481955
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Tested-by: Jason Macnak <natsu@google.com>
Commit-Queue: Jason Macnak <natsu@google.com>
2022-02-24 03:36:32 +00:00
Jason Macnak
736a8d7450 gralloc: re-add tracking imported handles
... as interacting with a cloned handle should not
succeed until it is imported:

```
native_handle_t handle1;
gralloc->alloc(..., &handle1);

native_handle_t handle2 = native_handle_clone(handle1);
gralloc->lock(handle2)   <--- should fail!
```

This is a partial revert of crrev.com/c/3433118

BUG=b:207388558
BUG=b:220537482
TEST=cvd start
TEST=vts -m VtsHalGraphicsMapperV4_0Target

Change-Id: Ia9a9f91fca14ea9f30017fb934c5c48064090d43
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/3481795
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Tested-by: Jason Macnak <natsu@google.com>
Commit-Queue: Jason Macnak <natsu@google.com>
2022-02-24 03:36:31 +00:00
Jason Macnak
40d5c7d98c gralloc: use dmabuf-heaps when available
... for reserved region / metadata as dmabuf heaps are the hot new
thing replacing ion.

Also, Android already has sepolicy in place for passing around
dmabufs (see `dmabuf_system_heap_device:chr_file` references in
system/sepolicy) while memfds require manual additions (see
aosp/1960673).

BUG=b:207388558
TEST=cvd start
TEST=vts -m VtsHalGraphicsMapperV4_0Target

Change-Id: I9acb30a10afb1f9f273ceb17dd44a9ac96da1a97
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/3449613
Reviewed-by: Roman Stratiienko <r.stratiienko@gmail.com>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Tested-by: Jason Macnak <natsu@google.com>
Commit-Queue: Jason Macnak <natsu@google.com>
2022-02-24 03:36:29 +00:00
Jason Macnak
b6aeea6135 gralloc: Use std::unique_ptr for drv_
BUG=b:207388558
TEST=cvd start
TEST=vts -m VtsHalGraphicsMapperV4_0Target

Change-Id: Ic27bcdae1e63cf869ceff779d113df778f3b7e0d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/3449612
Reviewed-by: Roman Stratiienko <r.stratiienko@gmail.com>
Reviewed-by: Dominik Behr <dbehr@chromium.org>
Tested-by: Jason Macnak <natsu@google.com>
Commit-Queue: Jason Macnak <natsu@google.com>
2022-02-17 07:05:58 +00:00
Jason Macnak
d63bacdd02 gralloc: Use std::unique_ptr/std::make_unique
... instead of using raw new/delete.

BUG=b:207388558
TEST=cvd start
TEST=vts -m VtsHalGraphicsMapperV4_0Target

Change-Id: I964a3d5b90af50369432b8e9a08ae56c191eb37a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/3442429
Reviewed-by: Roman Stratiienko <r.stratiienko@gmail.com>
Reviewed-by: Dominik Behr <dbehr@chromium.org>
Tested-by: Jason Macnak <natsu@google.com>
Commit-Queue: Jason Macnak <natsu@google.com>
2022-02-17 07:05:57 +00:00
Jason Macnak
0e9bd65933 gralloc: Move buffer name out of cros_gralloc_handle
... and into CrosGralloc4Metadata to simplify handle
creation by avoiding variable sized handles.

BUG=b:207388558
TEST=cvd start
TEST=vts -m VtsHalGraphicsMapperV4_0Target
TEST=cvd start --gpu_mode=gfxstream
TEST=vts -m VtsHalGraphicsMapperV4_0Target

Change-Id: I2d5e37beef8b9ba6bfbd06d79131b381d3ff73da
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/3433595
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Roman Stratiienko <r.stratiienko@gmail.com>
Reviewed-by: Dominik Behr <dbehr@chromium.org>
Tested-by: Jason Macnak <natsu@google.com>
Reviewed-by: Jason Macnak <natsu@google.com>
Commit-Queue: Jason Macnak <natsu@google.com>
2022-02-17 07:05:56 +00:00
Jason Macnak
d6d2fc5530 gralloc: Replace for-each-handle ​with for-each-buffer
... to support upcoming change where CrosGralloc4Mapper's
get(<metadata>) will want to access metadata that may be
in either the buffer's handle or the buffer's reserved
region. The for-each-[handle|buffer] methods support
dumpBuffers() where we need to iterate over all of the
buffers while holding a lock on the cros_gralloc_driver's
mutex.

BUG=b:207388558
TEST=cvd start
TEST=vts -m VtsHalGraphicsMapperV4_0Target
TEST=cvd start --gpu_mode=gfxstream
TEST=vts -m VtsHalGraphicsMapperV4_0Target

Change-Id: I674cab487d7446af722f94d796f504cf4f97de27
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/3433121
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Roman Stratiienko <r.stratiienko@gmail.com>
Reviewed-by: Dominik Behr <dbehr@chromium.org>
Tested-by: Jason Macnak <natsu@google.com>
Commit-Queue: Jason Macnak <natsu@google.com>
2022-02-17 07:05:55 +00:00
Jason Macnak
06fe94c982 gralloc: minor re-organize setting import data
BUG=b:207388558
TEST=m

Change-Id: Ieb23d5e85eaec219b4fb473770925eee7a70e31e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/3433119
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Roman Stratiienko <r.stratiienko@gmail.com>
Tested-by: Jason Macnak <natsu@google.com>
Commit-Queue: Jason Macnak <natsu@google.com>
2022-02-17 07:05:53 +00:00
Jason Macnak
6235f17371 gralloc: cros_gralloc_buffer always owns a cros_gralloc_handle
... to make it easier handle ownership (no more conditional
ownership if the buffer was allocated versus imported).

This also helps avoid a deadlock in CrosGralloc4Mapper's
dumpBuffers() in an upcoming change where CrosGralloc4Mapper
wants to interact with both metadata in the handle and
metadata in the cros_gralloc_buffer's reserved region. By
having the cros_gralloc_buffer always have a handle, the
CrosGralloc4Mapper can have access to all metadata when it
has a cros_gralloc_buffer parameter.

BUG=b:207388558
TEST=cvd start
TEST=vts -m VtsHalGraphicsMapperV4_0Target
TEST=cvd start --gpu_mode=gfxstream
TEST=vts -m VtsHalGraphicsMapperV4_0Target

Change-Id: I56fffbbfacf8436db165a961bec8ce546b4acc6c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/3433118
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Roman Stratiienko <r.stratiienko@gmail.com>
Reviewed-by: Dominik Behr <dbehr@chromium.org>
Tested-by: Jason Macnak <natsu@google.com>
Commit-Queue: Jason Macnak <natsu@google.com>
2022-02-17 07:05:52 +00:00
Jason Macnak
c06cc9cccb virtgpu_virgl: tighten max texture size on 2D path
... to that of SwiftShader + ANGLE (SwANGLE). With SwANGLE,
GL_MAX_TEXTURE_SIZE comes from a combination of
VkPhysicalDeviceLimits::maxFramebufferWidth and
VkPhysicalDeviceLimits::maxImageDimension2Dcomes  to meet GLES 3.1
requirements (see https://crrev.com/c/1917130).

BUG=b:194426249
TEST=`cts -m CtsNativeHardwareTestCases` with aosp/1845813

Change-Id: Ia14f241b59742c1bb864ef8f6e19de82bbe8fba4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/3208931
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Tested-by: Jason Macnak <natsu@google.com>
Commit-Queue: Jason Macnak <natsu@google.com>
2021-10-07 03:40:48 +00:00
Yiwei Zhang
3a171db9be gralloc: move the logic to strip BO_USE_HW_VIDEO_ENCODER to the backends
BUG=b:199524294
TEST=CQ

Change-Id: I2b36a0ef17cd6ecb77723d4a9d95196ad27ff4ad
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/3200148
Commit-Queue: Yiwei Zhang <zzyiwei@chromium.org>
Tested-by: Yiwei Zhang <zzyiwei@chromium.org>
Tested-by: Jason Macnak <natsu@google.com>
Reviewed-by: Jason Macnak <natsu@google.com>
Reviewed-by: Chia-I Wu <olv@google.com>
2021-10-05 11:05:13 +00:00
Yiwei Zhang
b8ad7b88ca minigbm: refactor to add unified resolve_format_and_use_flags helper
It makes more sense to resovle the format and use_flags together to
avoid duplicates.

Add the helper to vc4 and dumb_driver backends since that's missed
from prior frontend refactoring.

Split the resolve helper in virtgpu_virgl for the 3d and 2d paths to
make code logic cleaner.

BUG=b:199524294
TEST=CQ

Change-Id: I89b633ea484f0fc5bb9b4e0548cad017b9970cc6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/3200143
Tested-by: Yiwei Zhang <zzyiwei@chromium.org>
Tested-by: Jason Macnak <natsu@google.com>
Reviewed-by: Chia-I Wu <olv@google.com>
Reviewed-by: Jason Macnak <natsu@google.com>
Reviewed-by: Dominik Behr <dbehr@chromium.org>
Commit-Queue: Yiwei Zhang <zzyiwei@chromium.org>
2021-10-05 03:43:18 +00:00
Yiwei Zhang
b7a64441ef minigbm: refactor driver helpers
1. frontends access the driver via drv.h only
2. the renamed drv_helpers and drv_array_helpers are for driver only
3. remove extern "C" from drv_helpers.h given not exposed to gralloc
4. remove all redundant includes for those helpers

BUG=b:199524294
TEST=CQ and gralloc builds on aosp

Change-Id: I3f4d33076a6a8161804f1b7c26950ff5496507e9
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/3195651
Tested-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Chia-I Wu <olv@google.com>
Commit-Queue: Yiwei Zhang <zzyiwei@chromium.org>
2021-10-01 18:35:11 +00:00
Jason Macnak
6534dd4d69 gralloc: use max texture size in is_supported()
BUG=b:194426249
TEST=launch Cuttlefish w/ 2D mode
TEST=launch Cuttlefish w/ 3D mode

Change-Id: I077f24ab66124e1f8f9dba065e0a497a7502fa6b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/3194815
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Tested-by: Yiwei Zhang <zzyiwei@chromium.org>
Commit-Queue: Yiwei Zhang <zzyiwei@chromium.org>
2021-09-30 07:58:15 +00:00
Yiwei Zhang
c1413ea43a minigbm: conditionally fallback to strip scanout use_flag
Only 2d virtgpu backend needs to fallback here because virtio primary
plane only allows DRM_FORMAT_XRGB8888.

Most our platforms cannot display YV12 (except msm), thus the fallback
is required for the converted DRM_FORMAT_YVU420_ANDROID. For virgl
backend, additionally append a BO_USE_LINEAR as a replacement for the
hack inside compute_virgl_bind_flags.

BUG=b:199524294
TEST=CQ
TEST=gralloctest alloc_combinations
TEST=android.media.cts.VideoDecoderRotationTest

Change-Id: Ic87838ea2aae2b0abf87ed898ad75a3d7e556471
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/3166775
Tested-by: Yiwei Zhang <zzyiwei@chromium.org>
Auto-Submit: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Commit-Queue: Yiwei Zhang <zzyiwei@chromium.org>
2021-09-22 19:47:06 +00:00
Yiwei Zhang
dfe5ac6b58 gralloc: resolve format and use_flags at cros_gralloc_driver level
This simplify the separate resolving efforts in different gralloc
frontends (including separate logic in gralloc4 mapper and allocator).

BUG=b:199524294
TEST=CtsNativeHardwareTestCases

Change-Id: I74cd19df9b06c26a124e89c3367dd76b5b57dbd0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/3166893
Reviewed-by: Jason Macnak <natsu@google.com>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: Jason Macnak <natsu@google.com>
Tested-by: Yiwei Zhang <zzyiwei@chromium.org>
Commit-Queue: Yiwei Zhang <zzyiwei@chromium.org>
2021-09-17 13:47:55 +00:00
Yiwei Zhang
6032967f76 gralloc: add get_resolved_format_and_use_flags private driver api
This refactoring is to prepare for later unifying use_flags resolution
for all gralloc frontends, so that all fallbacks and special handlings
can be placed in the centralized private helper.

BUG=b:199524294
TEST=CtsNativeHardwareTestCases

Change-Id: I6e37822b7dbaa123c6956ff31bcef6a35a171f74
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/3163215
Tested-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Jason Macnak <natsu@google.com>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Commit-Queue: Yiwei Zhang <zzyiwei@chromium.org>
2021-09-17 13:47:55 +00:00
Yiwei Zhang
1f9b9000b7 minigbm: completely hide bo->meta from cros_gralloc
This change also stores the final use_flags used for bo allocation into
hnd->use_flags.

BUG=b:199524294
TEST=build

Change-Id: I0f4e3fbeb90acdd3852ede98e0a42620a757cb74
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/3163206
Tested-by: Yiwei Zhang <zzyiwei@chromium.org>
Auto-Submit: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Commit-Queue: Yiwei Zhang <zzyiwei@chromium.org>
2021-09-17 13:47:51 +00:00
Yiwei Zhang
61f9752a1c minigbm: refactor cros_gralloc_driver to be a singleton
Only a single cros_gralloc_driver instance is allowed to exist in a
process. However, currently when Gralloc3.0 or Gralloc4.0 is used, it's
possible for 2 independent driver instances to be created. This change
refactors cros_gralloc_driver to be a singleton and ensures the driver
initialization only happens once per process.

BUG=b:191895066
TEST=No regression of gralloc0 in ARCVM

Change-Id: I3cb8b7c3d13717cfe531b557b9d69b72efdbf3da
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/3002266
Tested-by: Yiwei Zhang <zzyiwei@chromium.org>
Tested-by: Jason Macnak <natsu@google.com>
Tested-by: John Stultz <john.stultz@linaro.org>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Jason Macnak <natsu@google.com>
Commit-Queue: Yiwei Zhang <zzyiwei@chromium.org>
2021-07-02 18:26:18 +00:00
Yiwei Zhang
a1e93fd6f1 minibgm: update GRALLOC_DRM_GET_BUFFER_INFO query
Vulkan on Android relis on VkImageDrmFormatModifierExplicitCreateInfoEXT
to import the gralloc allocated buffer, which requires buffer info of
the host storage.

BUG=b:186679287
TEST=venus wsi on arcvm and egl/gles
TEST=CtsNativeHardwareTestCases and related CtsGraphicsTestCases

Change-Id: I7ab0e80ab67a2daae9ea547a8d5abe9417af17d8
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/2862161
Tested-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Commit-Queue: Yiwei Zhang <zzyiwei@chromium.org>
2021-05-05 07:58:40 +00:00
David Stevens
8d62cdf032 cros_gralloc: allow tiled NV12 buffers
BUG=b:79682290
TEST=Verify that YouTube videos display correctly

Change-Id: Icf16e94320b6685936374a8fdf191895b57fac65
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/2721388
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: David Stevens <stevensd@chromium.org>
Commit-Queue: David Stevens <stevensd@chromium.org>
2021-03-04 11:28:33 +00:00
Peter Collingbourne
b48d8b9d61 Fix calculation of num_ints.
We were previously mismatching bytes and ints in this calculation. With
the current version of the code this seems to be harmless resulting
in allocating a larger native_handle than necessary, but prior to
commit 166fe14ab5 this miscalculation led to a buffer overflow when
cloning the handle, resulting in a failed uaccess when MTE was enabled.

Bug: b:178231152
Change-Id: I70cf86c0eb2dfe1bf343eb143db973a94d7e8b13
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/2703833
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Auto-Submit: Peter Collingbourne <pcc@chromium.org>
2021-02-18 23:20:14 +00:00
Jason Macnak
166fe14ab5 cros_gralloc: Handle failure to get prime fd
... in cros_gralloc_driver::allocate().

BUG=b:178495907
TEST=Cuttlefish CFI

Change-Id: Ibb9a5e55f2d2a4bf6be71f03dfe3f0fcd55a1b55
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/2658929
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
2021-02-03 04:22:39 +00:00
Gurchetan Singh
cadc54fe5d minigbm: consistent style
- Sometimes were return -1 and sometimes -errno.  Prefer -errno
  wherever possible.
- No braces for single line if/else statements.  This does not
  apply gralloc3/gralloc4, since that directory follows AOSP
  style.

BUG=b:178495907
TEST=Cuttlefish CFI

Change-Id: I4c35768e015109730772a972b4b18e8d2c3cbb9b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/2665001
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Jason Macnak <natsu@google.com>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
2021-02-03 04:22:38 +00:00
Gurchetan Singh
52155b4b57 minigbm: format_modifiers[0] -> format_modifier
The early version of the modifier assumed per plane modifiers.
The current version is only one modifier per buffer object.

BUG=none
TEST=compile

Change-Id: Ic3899118d44cb172ee2e4eae346e98cdf8328cf9
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/2654590
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
2021-01-29 22:47:35 +00:00
Roman Stratiienko
31a04c3d6e minigbm: Stop relying on drmPrimeFDToHandle() in common code
ARM-based SOCs usually have a separate display controller unit (IP core)
which has its own kernel driver and capabilities.

In most cases display controllers can handle only contiguous buffers
which require to reserve CMA region for them.

GPU itself usually has embedded MMU and can handle non-contiguous buffers.

In this hardware configuration it makes sense to allocate contiguous
memory for the buffers which will be used by display controller, and
non-contiguous memory for buffers which will be used by GPU only,
thus reducing minimum required CMA reserved region size.

Once a buffer is allocated in a non-contiguous region, any attempt of
importing it to the KMS driver using drmPrimeFDToHandle() will fail
with -EINVAL.

BO Handle was used as a unique per-buffer key, where 'id' field can be
used as well. As a positive side effect of this change number of system
calls is also reduced.

Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
Change-Id: I030849ede744b3d6aea04639c9a13d2fe1ccd71c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/2637641
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
2021-01-22 17:48:51 +00:00
François-Denis Gonthier
cea0b84e41 Add vkms support
The vkms driver is used to get the Android to work on the BeagleBone
Black. Only a minimum amount of support is needed but the driver can
only be recognized by looking at card DRM nodes. The vkms driver does
not publish a render node.

We refactored the cros_gralloc_driver::init to test both the render
nodes and the card nodes.

Change-Id: Ie750aa45fc359ba7917919904693b1ab8088ad16
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/2213742
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
2020-12-11 18:12:07 +00:00
Jason Macnak
0a7aeab1c6 cros_gralloc: handle memfd_create availability
BUG=b:172031518
TEST=vts -m VtsHalGraphicsMapperV4_0TargetTest

Change-Id: I9a7a0237620ab2468c014e0778976b379b757acf
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/2521454
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: Jason Macnak <natsu@google.com>
Commit-Queue: Jason Macnak <natsu@google.com>
Auto-Submit: Jason Macnak <natsu@google.com>
2020-11-12 14:55:01 +00:00
David Stevens
b42624c3e6 virtgpu: improve blob support on ARCVM
This change expands the types of buffers which use blob allocation, to
cover decoder/encoder bitstream buffers. It also adds tiling to the
exported buffer metadata, so that flush/invalidate are properly skipped
on imported blob buffers.

BUG=None
TEST=tast run ARCVM-DUT arc.VideoDecodeAccel.*

Change-Id: I460f4448db9e1bd2f7458f3180c4e92ff3b3d74f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/2400839
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: David Stevens <stevensd@chromium.org>
Commit-Queue: David Stevens <stevensd@chromium.org>
2020-09-17 01:13:16 +00:00
Boleyn Su
45aa68b553 minigbm: add O_CLOEXEC for the opened fd
BUG=b:162475183
TEST=None

Change-Id: Ic7debb48874ad90509954f7138e33a9d88da4898
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/2368693
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Lepton Wu <lepton@chromium.org>
Tested-by: Boleyn Su <boleynsu@chromium.org>
Auto-Submit: Boleyn Su <boleynsu@chromium.org>
Commit-Queue: Boleyn Su <boleynsu@chromium.org>
2020-09-02 11:19:08 +00:00
Jason Macnak
1de7f6655d cros_gralloc: Adds gralloc 3.0 support
Implements the allocator 3.0 and mapper 3.0 interfaces
which:

 - Implements HIDL interface directly (older versions
   are wrapped in a passthrough HIDL interface)

 - Adds isSupported() to allow checking for format and
   usage combination support before allocating.

Adds emulated multi-planar buffer support to virtio
backend for non gbm enabled hosts.

Updates cros_gralloc_handle to use uint64_t instead of
two uint32_t for some members.

Updates cros_gralloc_handle to have a single format
modifier.

Replaces Android makefiles with Android bp files.

BUG=b:146515640
TEST=run Cuttlefish w/ gralloc3 and run CTS tests

Change-Id: I43ed9788a2413201bddce17ffb69b76006ef39fd
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/2273554
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: Jason Macnak <natsu@google.com>
Commit-Queue: Jason Macnak <natsu@google.com>
2020-07-08 01:08:59 +00:00