OSDN Git Service

minigbm: One buffer for NV12
[android-x86/external-minigbm.git] / rockchip.c
1 /*
2  * Copyright (c) 2014 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 #ifdef GBM_ROCKCHIP
8
9 #include <assert.h>
10 #include <errno.h>
11 #include <stdio.h>
12 #include <string.h>
13 #include <xf86drm.h>
14 #include <rockchip_drm.h>
15
16 #include "gbm_priv.h"
17 #include "helpers.h"
18 #include "util.h"
19
20 static int gbm_rockchip_bo_create(struct gbm_bo *bo,
21                                   uint32_t width, uint32_t height,
22                                   uint32_t format, uint32_t flags)
23 {
24         size_t plane;
25
26         switch (format) {
27                 case GBM_FORMAT_NV12:
28                         width = ALIGN(width, 4);
29                         height = ALIGN(height, 4);
30                         bo->strides[0] = bo->strides[1] = width;
31                         bo->sizes[0] = height * bo->strides[0];
32                         bo->sizes[1] = height * bo->strides[1] / 2;
33                         bo->offsets[0] = 0;
34                         bo->offsets[1] = height * bo->strides[0];
35                         break;
36                 case GBM_FORMAT_XRGB8888:
37                 case GBM_FORMAT_ARGB8888:
38                 case GBM_FORMAT_ABGR8888:
39                         bo->strides[0] = gbm_stride_from_format(format, width);
40                         bo->sizes[0] = height * bo->strides[0];
41                         bo->offsets[0] = 0;
42                         break;
43                 default:
44                         fprintf(stderr, "minigbm: rockchip: unsupported format %4.4s\n",
45                                 (char*)&format);
46                         assert(0);
47                         return -EINVAL;
48         }
49
50         int ret;
51         size_t size = 0;
52
53         for (plane = 0; plane < bo->num_planes; plane++)
54                 size += bo->sizes[plane];
55
56         struct drm_rockchip_gem_create gem_create;
57
58         memset(&gem_create, 0, sizeof(gem_create));
59         gem_create.size = size;
60
61         ret = drmIoctl(bo->gbm->fd, DRM_IOCTL_ROCKCHIP_GEM_CREATE,
62                            &gem_create);
63
64         if (ret) {
65                 fprintf(stderr, "minigbm: DRM_IOCTL_ROCKCHIP_GEM_CREATE failed "
66                                 "(size=%zu)\n", size);
67         }
68         else {
69                 for (plane = 0; plane < bo->num_planes; plane++)
70                         bo->handles[plane].u32 = gem_create.handle;
71         }
72
73         return ret;
74 }
75
76 const struct gbm_driver gbm_driver_rockchip =
77 {
78         .name = "rockchip",
79         .bo_create = gbm_rockchip_bo_create,
80         .bo_destroy = gbm_gem_bo_destroy,
81         .format_list = {
82                 {GBM_FORMAT_XRGB8888, GBM_BO_USE_SCANOUT | GBM_BO_USE_CURSOR | GBM_BO_USE_RENDERING},
83                 {GBM_FORMAT_XRGB8888, GBM_BO_USE_SCANOUT | GBM_BO_USE_CURSOR | GBM_BO_USE_LINEAR},
84                 {GBM_FORMAT_ARGB8888, GBM_BO_USE_SCANOUT | GBM_BO_USE_CURSOR | GBM_BO_USE_RENDERING},
85                 {GBM_FORMAT_ARGB8888, GBM_BO_USE_SCANOUT | GBM_BO_USE_CURSOR | GBM_BO_USE_LINEAR},
86                 {GBM_FORMAT_ABGR8888, GBM_BO_USE_SCANOUT | GBM_BO_USE_CURSOR | GBM_BO_USE_RENDERING},
87                 {GBM_FORMAT_NV12, GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING},
88                 {GBM_FORMAT_NV12, GBM_BO_USE_SCANOUT | GBM_BO_USE_LINEAR},
89         }
90 };
91
92 #endif