OSDN Git Service

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