1 /**************************************************************************
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
28 #include "i915_surface.h"
29 #include "i915_resource.h"
30 #include "i915_blit.h"
32 #include "i915_screen.h"
33 #include "pipe/p_defines.h"
34 #include "util/u_inlines.h"
35 #include "util/u_math.h"
36 #include "util/u_format.h"
37 #include "util/u_memory.h"
38 #include "util/u_pack_color.h"
41 /* Assumes all values are within bounds -- no checking at this level -
42 * do it higher up if required.
45 i915_surface_copy(struct pipe_context
*pipe
,
46 struct pipe_resource
*dst
, unsigned dst_level
,
47 unsigned dstx
, unsigned dsty
, unsigned dstz
,
48 struct pipe_resource
*src
, unsigned src_level
,
49 const struct pipe_box
*src_box
)
51 struct i915_texture
*dst_tex
= i915_texture(dst
);
52 struct i915_texture
*src_tex
= i915_texture(src
);
53 struct pipe_resource
*dpt
= &dst_tex
->b
.b
;
54 struct pipe_resource
*spt
= &src_tex
->b
.b
;
55 unsigned dst_offset
, src_offset
; /* in bytes */
57 /* XXX cannot copy 3d regions at this time */
58 assert(src_box
->depth
== 1);
59 if (dst
->target
!= PIPE_TEXTURE_CUBE
&&
60 dst
->target
!= PIPE_TEXTURE_3D
)
62 dst_offset
= i915_texture_offset(dst_tex
, dst_level
, dstz
);
64 if (src
->target
!= PIPE_TEXTURE_CUBE
&&
65 src
->target
!= PIPE_TEXTURE_3D
)
66 assert(src_box
->z
== 0);
67 src_offset
= i915_texture_offset(src_tex
, src_level
, src_box
->z
);
70 assert( util_format_get_blocksize(dpt
->format
) == util_format_get_blocksize(spt
->format
) );
71 assert( util_format_get_blockwidth(dpt
->format
) == util_format_get_blockwidth(spt
->format
) );
72 assert( util_format_get_blockheight(dpt
->format
) == util_format_get_blockheight(spt
->format
) );
73 assert( util_format_get_blockwidth(dpt
->format
) == 1 );
74 assert( util_format_get_blockheight(dpt
->format
) == 1 );
76 i915_copy_blit( i915_context(pipe
),
77 util_format_get_blocksize(dpt
->format
),
78 (unsigned short) src_tex
->stride
, src_tex
->buffer
, src_offset
,
79 (unsigned short) dst_tex
->stride
, dst_tex
->buffer
, dst_offset
,
80 (short) src_box
->x
, (short) src_box
->y
, (short) dstx
, (short) dsty
,
81 (short) src_box
->width
, (short) src_box
->height
);
86 i915_clear_render_target(struct pipe_context
*pipe
,
87 struct pipe_surface
*dst
,
89 unsigned dstx
, unsigned dsty
,
90 unsigned width
, unsigned height
)
92 struct i915_texture
*tex
= i915_texture(dst
->texture
);
93 struct pipe_resource
*pt
= &tex
->b
.b
;
95 unsigned offset
= i915_texture_offset(tex
, dst
->u
.tex
.level
, dst
->u
.tex
.first_layer
);
97 assert(util_format_get_blockwidth(pt
->format
) == 1);
98 assert(util_format_get_blockheight(pt
->format
) == 1);
100 util_pack_color(rgba
, dst
->format
, &uc
);
101 i915_fill_blit( i915_context(pipe
),
102 util_format_get_blocksize(pt
->format
),
103 XY_COLOR_BLT_WRITE_ALPHA
| XY_COLOR_BLT_WRITE_RGB
,
104 (unsigned short) tex
->stride
,
106 (short) dstx
, (short) dsty
,
107 (short) width
, (short) height
,
112 i915_clear_depth_stencil(struct pipe_context
*pipe
,
113 struct pipe_surface
*dst
,
114 unsigned clear_flags
,
117 unsigned dstx
, unsigned dsty
,
118 unsigned width
, unsigned height
)
120 struct i915_texture
*tex
= i915_texture(dst
->texture
);
121 struct pipe_resource
*pt
= &tex
->b
.b
;
124 unsigned offset
= i915_texture_offset(tex
, dst
->u
.tex
.level
, dst
->u
.tex
.first_layer
);
126 assert(util_format_get_blockwidth(pt
->format
) == 1);
127 assert(util_format_get_blockheight(pt
->format
) == 1);
129 packedds
= util_pack_z_stencil(dst
->format
, depth
, stencil
);
131 if (clear_flags
& PIPE_CLEAR_DEPTH
)
132 mask
|= XY_COLOR_BLT_WRITE_RGB
;
133 /* XXX presumably this does read-modify-write
134 (otherwise this won't work anyway). Hence will only want to
135 do it if really have stencil and it isn't cleared */
136 if ((clear_flags
& PIPE_CLEAR_STENCIL
) ||
137 (dst
->format
!= PIPE_FORMAT_Z24_UNORM_S8_USCALED
))
138 mask
|= XY_COLOR_BLT_WRITE_ALPHA
;
140 i915_fill_blit( i915_context(pipe
),
141 util_format_get_blocksize(pt
->format
),
143 (unsigned short) tex
->stride
,
145 (short) dstx
, (short) dsty
,
146 (short) width
, (short) height
,
151 * Screen surface functions
155 static struct pipe_surface
*
156 i915_create_surface(struct pipe_context
*ctx
,
157 struct pipe_resource
*pt
,
158 const struct pipe_surface
*surf_tmpl
)
160 struct pipe_surface
*ps
;
162 assert(surf_tmpl
->u
.tex
.first_layer
== surf_tmpl
->u
.tex
.last_layer
);
163 if (pt
->target
!= PIPE_TEXTURE_CUBE
&&
164 pt
->target
!= PIPE_TEXTURE_3D
)
165 assert(surf_tmpl
->u
.tex
.first_layer
== 0);
167 ps
= CALLOC_STRUCT(pipe_surface
);
169 /* could subclass pipe_surface and store offset as it used to do */
170 pipe_reference_init(&ps
->reference
, 1);
171 pipe_resource_reference(&ps
->texture
, pt
);
172 ps
->format
= surf_tmpl
->format
;
173 ps
->width
= u_minify(pt
->width0
, surf_tmpl
->u
.tex
.level
);
174 ps
->height
= u_minify(pt
->height0
, surf_tmpl
->u
.tex
.level
);
175 ps
->u
.tex
.level
= surf_tmpl
->u
.tex
.level
;
176 ps
->u
.tex
.first_layer
= surf_tmpl
->u
.tex
.first_layer
;
177 ps
->u
.tex
.last_layer
= surf_tmpl
->u
.tex
.last_layer
;
178 ps
->usage
= surf_tmpl
->usage
;
185 i915_surface_destroy(struct pipe_context
*ctx
,
186 struct pipe_surface
*surf
)
188 pipe_resource_reference(&surf
->texture
, NULL
);
194 i915_init_surface_functions(struct i915_context
*i915
)
196 i915
->base
.resource_copy_region
= i915_surface_copy
;
197 i915
->base
.clear_render_target
= i915_clear_render_target
;
198 i915
->base
.clear_depth_stencil
= i915_clear_depth_stencil
;
199 i915
->base
.create_surface
= i915_create_surface
;
200 i915
->base
.surface_destroy
= i915_surface_destroy
;