OSDN Git Service

minigbm: deal with ArcCodec use case by exposing struct map_info
[android-x86/external-minigbm.git] / vgem.c
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"
9 #include "util.h"
10
11 #define MESA_LLVMPIPE_TILE_ORDER 6
12 #define MESA_LLVMPIPE_TILE_SIZE (1 << MESA_LLVMPIPE_TILE_ORDER)
13
14 static const uint32_t supported_formats[] = {
15         DRM_FORMAT_ARGB8888, DRM_FORMAT_RGB565, DRM_FORMAT_XRGB8888
16 };
17
18 static int vgem_init(struct driver *drv)
19 {
20         return drv_add_linear_combinations(drv, supported_formats,
21                                            ARRAY_SIZE(supported_formats));
22 }
23
24 static int vgem_bo_create(struct bo *bo, uint32_t width, uint32_t height,
25                           uint32_t format, uint32_t flags)
26 {
27         int ret = drv_dumb_bo_create(bo, ALIGN(width, MESA_LLVMPIPE_TILE_SIZE),
28                                      ALIGN(height, MESA_LLVMPIPE_TILE_SIZE),
29                                      format, flags);
30         bo->width = width;
31         bo->height = height;
32
33         return ret;
34 }
35
36 static uint32_t vgem_resolve_format(uint32_t format)
37 {
38         switch (format) {
39         case DRM_FORMAT_FLEX_IMPLEMENTATION_DEFINED:
40                 /*HACK: See b/28671744 */
41                 return DRM_FORMAT_XBGR8888;
42         case DRM_FORMAT_FLEX_YCbCr_420_888:
43                 return DRM_FORMAT_YVU420;
44         default:
45                 return format;
46         }
47 }
48
49 struct backend backend_vgem =
50 {
51         .name = "vgem",
52         .init = vgem_init,
53         .bo_create = vgem_bo_create,
54         .bo_destroy = drv_dumb_bo_destroy,
55         .bo_import = drv_prime_bo_import,
56         .bo_map = drv_dumb_bo_map,
57         .resolve_format = vgem_resolve_format,
58 };
59