dri: propagate extra dma_buf import attributes to the drivers
[mesa.git] / src / mesa / drivers / dri / i965 / intel_regions.h
1 /**************************************************************************
2 *
3 * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 #ifndef INTEL_REGIONS_H
29 #define INTEL_REGIONS_H
30
31 /** @file intel_regions.h
32 *
33 * Structure definitions and prototypes for intel_region handling,
34 * which is the basic structure for rectangular collections of pixels
35 * stored in a drm_intel_bo.
36 */
37
38 #include <stdbool.h>
39 #include <xf86drm.h>
40
41 #include "main/mtypes.h"
42 #include "intel_bufmgr.h"
43 #include <GL/internal/dri_interface.h>
44
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48
49 struct brw_context;
50 struct intel_screen;
51 struct intel_buffer_object;
52
53 /**
54 * A layer on top of the bufmgr buffers that adds a few useful things:
55 *
56 * - Refcounting for local buffer references.
57 * - Refcounting for buffer maps
58 * - Buffer dimensions - pitch and height.
59 * - Blitter commands for copying 2D regions between buffers. (really???)
60 */
61 struct intel_region
62 {
63 drm_intel_bo *bo; /**< buffer manager's buffer */
64 GLuint refcount; /**< Reference count for region */
65 GLuint cpp; /**< bytes per pixel */
66 GLuint width; /**< in pixels */
67 GLuint height; /**< in pixels */
68 GLuint pitch; /**< in bytes */
69
70 uint32_t tiling; /**< Which tiling mode the region is in */
71
72 uint32_t name; /**< Global name for the bo */
73 };
74
75
76 /* Allocate a refcounted region. Pointers to regions should only be
77 * copied by calling intel_reference_region().
78 */
79 struct intel_region *intel_region_alloc(struct intel_screen *screen,
80 uint32_t tiling,
81 GLuint cpp, GLuint width,
82 GLuint height,
83 bool expect_accelerated_upload);
84
85 struct intel_region *
86 intel_region_alloc_for_handle(struct intel_screen *screen,
87 GLuint cpp,
88 GLuint width, GLuint height, GLuint pitch,
89 unsigned int handle, const char *name);
90
91 struct intel_region *
92 intel_region_alloc_for_fd(struct intel_screen *screen,
93 GLuint cpp,
94 GLuint width, GLuint height, GLuint pitch,
95 int fd, const char *name);
96
97 bool
98 intel_region_flink(struct intel_region *region, uint32_t *name);
99
100 void intel_region_reference(struct intel_region **dst,
101 struct intel_region *src);
102
103 void intel_region_release(struct intel_region **ib);
104
105 void
106 intel_region_get_tile_masks(struct intel_region *region,
107 uint32_t *mask_x, uint32_t *mask_y,
108 bool map_stencil_as_y_tiled);
109
110 uint32_t
111 intel_region_get_aligned_offset(struct intel_region *region, uint32_t x,
112 uint32_t y, bool map_stencil_as_y_tiled);
113
114 /**
115 * Used with images created with image_from_names
116 * to help support planar images.
117 */
118 struct intel_image_format {
119 int fourcc;
120 int components;
121 int nplanes;
122 struct {
123 int buffer_index;
124 int width_shift;
125 int height_shift;
126 uint32_t dri_format;
127 int cpp;
128 } planes[3];
129 };
130
131 struct __DRIimageRec {
132 struct intel_region *region;
133 GLenum internal_format;
134 uint32_t dri_format;
135 GLuint format;
136 uint32_t offset;
137
138 /*
139 * Need to save these here between calls to
140 * image_from_names and calls to image_from_planar.
141 */
142 uint32_t strides[3];
143 uint32_t offsets[3];
144 struct intel_image_format *planar_format;
145
146 /* particular miptree level */
147 GLuint width;
148 GLuint height;
149 GLuint tile_x;
150 GLuint tile_y;
151 bool has_depthstencil;
152
153 /* Provided by EGL_EXT_image_dma_buf_import */
154 enum __DRIYUVColorSpace yuv_color_space;
155 enum __DRISampleRange sample_range;
156 enum __DRIChromaSiting horizontal_siting;
157 enum __DRIChromaSiting vertical_siting;
158
159 void *data;
160 };
161
162 #ifdef __cplusplus
163 }
164 #endif
165
166 #endif