intel: Implement DRI image extension
[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, which is
34 * the basic structure for rectangular collections of pixels stored in a dri_bo.
35 */
36
37 #include <xf86drm.h>
38
39 #include "main/mtypes.h"
40 #include "intel_bufmgr.h"
41
42 struct intel_context;
43 struct intel_buffer_object;
44
45 /**
46 * A layer on top of the bufmgr buffers that adds a few useful things:
47 *
48 * - Refcounting for local buffer references.
49 * - Refcounting for buffer maps
50 * - Buffer dimensions - pitch and height.
51 * - Blitter commands for copying 2D regions between buffers. (really???)
52 */
53 struct intel_region
54 {
55 drm_intel_bo *buffer; /**< buffer manager's buffer */
56 GLuint refcount; /**< Reference count for region */
57 GLuint cpp; /**< bytes per pixel */
58 GLuint width; /**< in pixels */
59 GLuint height; /**< in pixels */
60 GLuint pitch; /**< in pixels */
61 GLubyte *map; /**< only non-NULL when region is actually mapped */
62 GLuint map_refcount; /**< Reference count for mapping */
63
64 GLuint draw_offset; /**< Offset of drawing address within the region */
65 GLuint draw_x, draw_y; /**< Offset of drawing within the region */
66
67 uint32_t tiling; /**< Which tiling mode the region is in */
68 uint32_t bit_6_swizzle; /**< GEM flag for address swizzling requirement */
69 struct intel_buffer_object *pbo; /* zero-copy uploads */
70
71 uint32_t name; /**< Global name for the bo */
72 struct intel_screen *screen;
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_context *intel,
80 uint32_t tiling,
81 GLuint cpp, GLuint width,
82 GLuint height, GLuint pitch,
83 GLboolean expect_accelerated_upload);
84
85 struct intel_region *
86 intel_region_alloc_for_handle(struct intel_context *intel,
87 GLuint cpp,
88 GLuint width, GLuint height, GLuint pitch,
89 unsigned int handle, const char *name);
90
91 void intel_region_reference(struct intel_region **dst,
92 struct intel_region *src);
93
94 void intel_region_release(struct intel_region **ib);
95
96 void intel_recreate_static_regions(struct intel_context *intel);
97
98 /* Map/unmap regions. This is refcounted also:
99 */
100 GLubyte *intel_region_map(struct intel_context *intel,
101 struct intel_region *ib);
102
103 void intel_region_unmap(struct intel_context *intel, struct intel_region *ib);
104
105
106 /* Upload data to a rectangular sub-region
107 */
108 void intel_region_data(struct intel_context *intel,
109 struct intel_region *dest,
110 GLuint dest_offset,
111 GLuint destx, GLuint desty,
112 const void *src, GLuint src_stride,
113 GLuint srcx, GLuint srcy, GLuint width, GLuint height);
114
115 /* Copy rectangular sub-regions
116 */
117 GLboolean
118 intel_region_copy(struct intel_context *intel,
119 struct intel_region *dest,
120 GLuint dest_offset,
121 GLuint destx, GLuint desty,
122 struct intel_region *src,
123 GLuint src_offset,
124 GLuint srcx, GLuint srcy, GLuint width, GLuint height,
125 GLenum logicop);
126
127 /* Helpers for zerocopy uploads, particularly texture image uploads:
128 */
129 void intel_region_attach_pbo(struct intel_context *intel,
130 struct intel_region *region,
131 struct intel_buffer_object *pbo);
132 void intel_region_release_pbo(struct intel_context *intel,
133 struct intel_region *region);
134 void intel_region_cow(struct intel_context *intel,
135 struct intel_region *region);
136
137 dri_bo *intel_region_buffer(struct intel_context *intel,
138 struct intel_region *region,
139 GLuint flag);
140
141 void _mesa_copy_rect(GLubyte * dst,
142 GLuint cpp,
143 GLuint dst_pitch,
144 GLuint dst_x,
145 GLuint dst_y,
146 GLuint width,
147 GLuint height,
148 const GLubyte * src,
149 GLuint src_pitch, GLuint src_x, GLuint src_y);
150
151 struct __DRIimageRec {
152 struct intel_region *region;
153 GLenum internal_format;
154 GLuint format;
155 GLenum data_type;
156 void *data;
157 };
158
159 #endif