Gurchetan Singh | 5521bde | 2016-09-30 14:53:32 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 The Chromium OS Authors. All rights reserved. |
| 3 | * Use of this source code is governed by a BSD-style license that can be |
| 4 | * found in the LICENSE file. |
| 5 | */ |
| 6 | |
| 7 | #include "drv_priv.h" |
| 8 | #include "helpers.h" |
Gurchetan Singh | 179687e | 2016-10-28 10:07:35 -0700 | [diff] [blame] | 9 | #include "util.h" |
| 10 | |
Gurchetan Singh | ebe1e95 | 2016-11-29 20:36:13 -0800 | [diff] [blame] | 11 | #define MESA_LLVMPIPE_TILE_ORDER 6 |
| 12 | #define MESA_LLVMPIPE_TILE_SIZE (1 << MESA_LLVMPIPE_TILE_ORDER) |
| 13 | |
Gurchetan Singh | 45de199 | 2016-12-02 12:32:16 -0800 | [diff] [blame] | 14 | static struct supported_combination combos[4] = { |
Gurchetan Singh | 179687e | 2016-10-28 10:07:35 -0700 | [diff] [blame] | 15 | {DRM_FORMAT_ABGR8888, DRM_FORMAT_MOD_NONE, |
Gurchetan Singh | 6f6e18a | 2016-12-19 15:14:18 -0800 | [diff] [blame] | 16 | BO_USE_CURSOR | BO_USE_LINEAR | BO_USE_RENDERING | BO_USE_SW_READ_OFTEN | |
| 17 | BO_USE_SW_WRITE_OFTEN | BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY}, |
Gurchetan Singh | 45de199 | 2016-12-02 12:32:16 -0800 | [diff] [blame] | 18 | {DRM_FORMAT_RGB565, DRM_FORMAT_MOD_NONE, |
Gurchetan Singh | 6f6e18a | 2016-12-19 15:14:18 -0800 | [diff] [blame] | 19 | BO_USE_LINEAR | BO_USE_RENDERING | BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN | |
Gurchetan Singh | 45de199 | 2016-12-02 12:32:16 -0800 | [diff] [blame] | 20 | BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY}, |
Gurchetan Singh | 6f6e18a | 2016-12-19 15:14:18 -0800 | [diff] [blame] | 21 | {DRM_FORMAT_XBGR8888, DRM_FORMAT_MOD_NONE, |
| 22 | BO_USE_CURSOR | BO_USE_LINEAR | BO_USE_RENDERING | BO_USE_SW_READ_OFTEN | |
| 23 | BO_USE_SW_WRITE_OFTEN | BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY}, |
Gurchetan Singh | 179687e | 2016-10-28 10:07:35 -0700 | [diff] [blame] | 24 | {DRM_FORMAT_YVU420, DRM_FORMAT_MOD_NONE, |
Gurchetan Singh | 6f6e18a | 2016-12-19 15:14:18 -0800 | [diff] [blame] | 25 | BO_USE_LINEAR | BO_USE_RENDERING | BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN | |
| 26 | BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY}, |
Gurchetan Singh | 179687e | 2016-10-28 10:07:35 -0700 | [diff] [blame] | 27 | }; |
| 28 | |
| 29 | static int vgem_init(struct driver *drv) |
| 30 | { |
| 31 | drv_insert_combinations(drv, combos, ARRAY_SIZE(combos)); |
Gurchetan Singh | 714c689 | 2016-12-02 11:02:47 -0800 | [diff] [blame] | 32 | return 0; |
Gurchetan Singh | 179687e | 2016-10-28 10:07:35 -0700 | [diff] [blame] | 33 | } |
Gurchetan Singh | 5521bde | 2016-09-30 14:53:32 -0700 | [diff] [blame] | 34 | |
Gurchetan Singh | ebe1e95 | 2016-11-29 20:36:13 -0800 | [diff] [blame] | 35 | static int vgem_bo_create(struct bo *bo, uint32_t width, uint32_t height, |
| 36 | uint32_t format, uint32_t flags) |
| 37 | { |
| 38 | int ret = drv_dumb_bo_create(bo, ALIGN(width, MESA_LLVMPIPE_TILE_SIZE), |
| 39 | ALIGN(height, MESA_LLVMPIPE_TILE_SIZE), |
| 40 | format, flags); |
| 41 | bo->width = width; |
| 42 | bo->height = height; |
| 43 | |
| 44 | return ret; |
| 45 | } |
| 46 | |
Gurchetan Singh | f3b22da | 2016-11-21 10:46:38 -0800 | [diff] [blame] | 47 | static uint32_t vgem_resolve_format(uint32_t format) |
Gurchetan Singh | 5521bde | 2016-09-30 14:53:32 -0700 | [diff] [blame] | 48 | { |
| 49 | switch (format) { |
Gurchetan Singh | f3b22da | 2016-11-21 10:46:38 -0800 | [diff] [blame] | 50 | case DRM_FORMAT_FLEX_IMPLEMENTATION_DEFINED: |
Gurchetan Singh | 5521bde | 2016-09-30 14:53:32 -0700 | [diff] [blame] | 51 | /*HACK: See b/28671744 */ |
Gurchetan Singh | f3b22da | 2016-11-21 10:46:38 -0800 | [diff] [blame] | 52 | return DRM_FORMAT_XBGR8888; |
| 53 | case DRM_FORMAT_FLEX_YCbCr_420_888: |
| 54 | return DRM_FORMAT_YVU420; |
Gurchetan Singh | 5521bde | 2016-09-30 14:53:32 -0700 | [diff] [blame] | 55 | default: |
| 56 | return format; |
| 57 | } |
| 58 | } |
| 59 | |
Gurchetan Singh | 179687e | 2016-10-28 10:07:35 -0700 | [diff] [blame] | 60 | struct backend backend_vgem = |
Gurchetan Singh | 5521bde | 2016-09-30 14:53:32 -0700 | [diff] [blame] | 61 | { |
| 62 | .name = "vgem", |
Gurchetan Singh | 179687e | 2016-10-28 10:07:35 -0700 | [diff] [blame] | 63 | .init = vgem_init, |
Gurchetan Singh | ebe1e95 | 2016-11-29 20:36:13 -0800 | [diff] [blame] | 64 | .bo_create = vgem_bo_create, |
Gurchetan Singh | 5521bde | 2016-09-30 14:53:32 -0700 | [diff] [blame] | 65 | .bo_destroy = drv_dumb_bo_destroy, |
Gurchetan Singh | 71611d6 | 2017-01-03 16:49:56 -0800 | [diff] [blame] | 66 | .bo_import = drv_prime_bo_import, |
Gurchetan Singh | 5521bde | 2016-09-30 14:53:32 -0700 | [diff] [blame] | 67 | .bo_map = drv_dumb_bo_map, |
| 68 | .resolve_format = vgem_resolve_format, |
Gurchetan Singh | 5521bde | 2016-09-30 14:53:32 -0700 | [diff] [blame] | 69 | }; |
| 70 | |