OSDN Git Service

76fa44319c08023642092a846dd4c1cbf143a74c
[android-x86/external-minigbm.git] / drv_priv.h
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 #ifndef DRV_PRIV_H
8 #define DRV_PRIV_H
9
10 #include <pthread.h>
11 #include <stdint.h>
12 #include <stdlib.h>
13 #include <sys/types.h>
14
15 #include "drv.h"
16
17 struct bo_metadata {
18         uint32_t width;
19         uint32_t height;
20         uint32_t format;
21         uint32_t tiling;
22         size_t num_planes;
23         uint32_t offsets[DRV_MAX_PLANES];
24         uint32_t sizes[DRV_MAX_PLANES];
25         uint32_t strides[DRV_MAX_PLANES];
26         uint64_t format_modifiers[DRV_MAX_PLANES];
27         uint64_t use_flags;
28         size_t total_size;
29 };
30
31 struct bo {
32         struct driver *drv;
33         struct bo_metadata meta;
34         union bo_handle handles[DRV_MAX_PLANES];
35         void *priv;
36 };
37
38 struct format_metadata {
39         uint32_t priority;
40         uint32_t tiling;
41         uint64_t modifier;
42 };
43
44 struct combination {
45         uint32_t format;
46         struct format_metadata metadata;
47         uint64_t use_flags;
48 };
49
50 struct driver {
51         int fd;
52         const struct backend *backend;
53         void *priv;
54         void *buffer_table;
55         struct drv_array *mappings;
56         struct drv_array *combos;
57         pthread_mutex_t driver_lock;
58 };
59
60 struct backend {
61         char *name;
62         int (*init)(struct driver *drv);
63         void (*close)(struct driver *drv);
64         int (*bo_create)(struct bo *bo, uint32_t width, uint32_t height, uint32_t format,
65                          uint64_t use_flags);
66         int (*bo_create_with_modifiers)(struct bo *bo, uint32_t width, uint32_t height,
67                                         uint32_t format, const uint64_t *modifiers, uint32_t count);
68         int (*bo_destroy)(struct bo *bo);
69         int (*bo_import)(struct bo *bo, struct drv_import_fd_data *data);
70         void *(*bo_map)(struct bo *bo, struct vma *vma, size_t plane, uint32_t map_flags);
71         int (*bo_unmap)(struct bo *bo, struct vma *vma);
72         int (*bo_invalidate)(struct bo *bo, struct mapping *mapping);
73         int (*bo_flush)(struct bo *bo, struct mapping *mapping);
74         uint32_t (*resolve_format)(struct driver *drv, uint32_t format, uint64_t use_flags);
75 };
76
77 // clang-format off
78 #define BO_USE_RENDER_MASK (BO_USE_LINEAR | BO_USE_PROTECTED | BO_USE_RENDERING | \
79                            BO_USE_RENDERSCRIPT | BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN | \
80                            BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY | BO_USE_TEXTURE)
81
82 #define BO_USE_TEXTURE_MASK (BO_USE_LINEAR | BO_USE_PROTECTED | BO_USE_RENDERSCRIPT | \
83                             BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN | \
84                             BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY | BO_USE_TEXTURE)
85
86 #define BO_USE_SW_MASK (BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN | \
87                        BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY)
88
89 #define BO_USE_NON_GPU_HW (BO_USE_SCANOUT | BO_USE_CAMERA_WRITE | BO_USE_CAMERA_READ | \
90                           BO_USE_HW_VIDEO_ENCODER | BO_USE_HW_VIDEO_DECODER)
91
92 #ifndef DRM_FORMAT_MOD_LINEAR
93 #define DRM_FORMAT_MOD_LINEAR DRM_FORMAT_MOD_NONE
94 #endif
95
96 #define LINEAR_METADATA (struct format_metadata) { 1, 0, DRM_FORMAT_MOD_LINEAR }
97 // clang-format on
98
99 #endif