93181414c913387169c5186817f80d6a39963575
[mesa.git] / src / mesa / drivers / dri / intel / 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
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47
48 struct intel_context;
49 struct intel_buffer_object;
50
51 /**
52 * A layer on top of the bufmgr buffers that adds a few useful things:
53 *
54 * - Refcounting for local buffer references.
55 * - Refcounting for buffer maps
56 * - Buffer dimensions - pitch and height.
57 * - Blitter commands for copying 2D regions between buffers. (really???)
58 */
59 struct intel_region
60 {
61 drm_intel_bo *bo; /**< buffer manager's buffer */
62 GLuint refcount; /**< Reference count for region */
63 GLuint cpp; /**< bytes per pixel */
64 GLuint width; /**< in pixels */
65 GLuint height; /**< in pixels */
66 GLuint pitch; /**< in bytes */
67 GLubyte *map; /**< only non-NULL when region is actually mapped */
68 GLuint map_refcount; /**< Reference count for mapping */
69
70 uint32_t tiling; /**< Which tiling mode the region is in */
71
72 uint32_t name; /**< Global name for the bo */
73 struct intel_screen *screen;
74 };
75
76
77 /* Allocate a refcounted region. Pointers to regions should only be
78 * copied by calling intel_reference_region().
79 */
80 struct intel_region *intel_region_alloc(struct intel_screen *screen,
81 uint32_t tiling,
82 GLuint cpp, GLuint width,
83 GLuint height,
84 bool expect_accelerated_upload);
85
86 struct intel_region *
87 intel_region_alloc_for_handle(struct intel_screen *screen,
88 GLuint cpp,
89 GLuint width, GLuint height, GLuint pitch,
90 unsigned int handle, const char *name);
91
92 bool
93 intel_region_flink(struct intel_region *region, uint32_t *name);
94
95 void intel_region_reference(struct intel_region **dst,
96 struct intel_region *src);
97
98 void intel_region_release(struct intel_region **ib);
99
100 void intel_recreate_static_regions(struct intel_context *intel);
101
102 /**
103 * Map/unmap regions. This is refcounted also:
104 *
105 * \param mode bitmask of GL_MAP_READ_BIT, GL_MAP_WRITE_BIT
106 */
107 void *intel_region_map(struct intel_context *intel,
108 struct intel_region *ib,
109 GLbitfield mode);
110
111 void intel_region_unmap(struct intel_context *intel, struct intel_region *ib);
112
113 /* Copy rectangular sub-regions
114 */
115 bool
116 intel_region_copy(struct intel_context *intel,
117 struct intel_region *dest,
118 GLuint dest_offset,
119 GLuint destx, GLuint desty,
120 struct intel_region *src,
121 GLuint src_offset,
122 GLuint srcx, GLuint srcy, GLuint width, GLuint height,
123 bool flip,
124 GLenum logicop);
125
126 void
127 intel_region_get_tile_masks(struct intel_region *region,
128 uint32_t *mask_x, uint32_t *mask_y,
129 bool map_stencil_as_y_tiled);
130
131 uint32_t
132 intel_region_get_aligned_offset(struct intel_region *region, uint32_t x,
133 uint32_t y, bool map_stencil_as_y_tiled);
134
135 /**
136 * Used with images created with image_from_names
137 * to help support planar images.
138 */
139 struct intel_image_format {
140 int fourcc;
141 int components;
142 int nplanes;
143 struct {
144 int buffer_index;
145 int width_shift;
146 int height_shift;
147 uint32_t dri_format;
148 int cpp;
149 } planes[3];
150 };
151
152 struct __DRIimageRec {
153 struct intel_region *region;
154 GLenum internal_format;
155 uint32_t dri_format;
156 GLuint format;
157 uint32_t offset;
158
159 /*
160 * Need to save these here between calls to
161 * image_from_names and calls to image_from_planar.
162 */
163 uint32_t strides[3];
164 uint32_t offsets[3];
165 struct intel_image_format *planar_format;
166
167 /* particular miptree level */
168 GLuint width;
169 GLuint height;
170 GLuint tile_x;
171 GLuint tile_y;
172 bool has_depthstencil;
173
174 void *data;
175 };
176
177 #ifdef __cplusplus
178 }
179 #endif
180
181 #endif