3e130203c3cae1058f19fbb205ccdb1fd6eed613
[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 #include "mtypes.h"
32 #include "dri_bufmgr.h" /* for DBG! */
33 #include "intel_screen.h"
34 struct intel_context;
35
36 /* A layer on top of the bufmgr buffers that adds a few useful things:
37 *
38 * - Refcounting for local buffer references.
39 * - Refcounting for buffer maps
40 * - Buffer dimensions - pitch and height.
41 * - Blitter commands for copying 2D regions between buffers.
42 */
43 struct intel_region {
44 dri_bo *buffer;
45 GLuint refcount;
46 GLuint cpp;
47 GLuint pitch;
48 GLuint height;
49 GLboolean tiled;
50 GLubyte *map;
51 GLuint map_refcount;
52 };
53
54 /* Allocate a refcounted region. Pointers to regions should only be
55 * copied by calling intel_reference_region().
56 *
57 * No support for dynamically allocating tiled regions at this point.
58 */
59 struct intel_region *intel_region_alloc( struct intel_context *intel,
60 GLuint cpp,
61 GLuint pitch,
62 GLuint height );
63
64 void intel_region_reference( struct intel_region **dst,
65 struct intel_region *src );
66
67 void intel_region_release(struct intel_context *intel,
68 struct intel_region **ib );
69
70 void intel_recreate_static_regions(struct intel_context *intel);
71
72 /* Static regions may be tiled. The assumption is that the X server
73 * has set up fence registers to define tiled zones in agp and these
74 * buffers are within those zones. Tiling regions without fence
75 * registers is more work.
76 */
77 struct intel_region *
78 intel_region_create_static(intelScreenPrivate *intelScreen,
79 char *name,
80 GLuint mem_type,
81 unsigned int bo_handle,
82 GLuint offset,
83 void *virtual,
84 GLuint cpp,
85 GLuint pitch, GLuint height, GLboolean tiled);
86 void
87 intel_region_update_static(intelScreenPrivate *intelScreen,
88 struct intel_region *region,
89 GLuint mem_type,
90 unsigned int bo_handle,
91 GLuint offset,
92 void *virtual,
93 GLuint cpp, GLuint pitch, GLuint height,
94 GLboolean tiled);
95
96 /* Map/unmap regions. This is refcounted also:
97 */
98 GLubyte *intel_region_map(struct intel_context *intel,
99 struct intel_region *ib);
100
101 void intel_region_unmap(struct intel_context *intel,
102 struct intel_region *ib);
103
104
105 /* Upload data to a rectangular sub-region
106 */
107 GLboolean intel_region_data(struct intel_context *intel,
108 struct intel_region *dest,
109 GLuint dest_offset,
110 GLuint destx, GLuint desty,
111 const void *src, GLuint src_stride,
112 GLuint srcx, GLuint srcy,
113 GLuint width, GLuint height);
114
115 /* Copy rectangular sub-regions
116 */
117 void intel_region_copy( struct intel_context *intel,
118 struct intel_region *dest,
119 GLuint dest_offset,
120 GLuint destx, GLuint desty,
121 struct intel_region *src,
122 GLuint src_offset,
123 GLuint srcx, GLuint srcy,
124 GLuint width, GLuint height );
125
126 /* Fill a rectangular sub-region
127 */
128 void intel_region_fill( struct intel_context *intel,
129 struct intel_region *dest,
130 GLuint dest_offset,
131 GLuint destx, GLuint desty,
132 GLuint width, GLuint height,
133 GLuint color );
134
135
136 /***********************************************************************
137 * Misc utilities: move to somewhere generic
138 */
139 void _mesa_copy_rect( GLubyte *dst,
140 GLuint cpp,
141 GLuint dst_pitch,
142 GLuint dst_x,
143 GLuint dst_y,
144 GLuint width,
145 GLuint height,
146 const GLubyte *src,
147 GLuint src_pitch,
148 GLuint src_x,
149 GLuint src_y );
150
151
152 #endif