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