2 /**************************************************************************
4 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 **************************************************************************/
29 #include "nv40_context.h"
30 #include "pipe/p_defines.h"
31 #include "pipe/p_util.h"
32 #include "pipe/p_winsys.h"
33 #include "pipe/p_inlines.h"
40 if (y >= ps->height) \
42 if (x + w > ps->width) \
44 if (y + h > ps->height) \
50 * Note: this is exactly like a8r8g8b8_get_tile() in sp_surface.c
54 nv40_get_tile_rgba(struct pipe_context
*pipe
,
55 struct pipe_surface
*ps
,
56 uint x
, uint y
, uint w
, uint h
, float *p
)
59 = ((const unsigned *) (ps
->map
+ ps
->offset
))
67 case PIPE_FORMAT_A8R8G8B8_UNORM
:
68 for (i
= 0; i
< h
; i
++) {
70 for (j
= 0; j
< w
; j
++) {
71 const unsigned pixel
= src
[j
];
72 pRow
[0] = UBYTE_TO_FLOAT((pixel
>> 16) & 0xff);
73 pRow
[1] = UBYTE_TO_FLOAT((pixel
>> 8) & 0xff);
74 pRow
[2] = UBYTE_TO_FLOAT((pixel
>> 0) & 0xff);
75 pRow
[3] = UBYTE_TO_FLOAT((pixel
>> 24) & 0xff);
82 case PIPE_FORMAT_Z24S8_UNORM
:
84 const float scale
= 1.0 / (float) 0xffffff;
85 for (i
= 0; i
< h
; i
++) {
87 for (j
= 0; j
< w
; j
++) {
88 const unsigned pixel
= src
[j
];
92 pRow
[3] = ((pixel
& 0xffffff) >> 8) * scale
;
107 nv40_put_tile_rgba(struct pipe_context
*pipe
,
108 struct pipe_surface
*ps
,
109 uint x
, uint y
, uint w
, uint h
, const float *p
)
117 * XXX note: same as code in sp_surface.c
120 nv40_get_tile(struct pipe_context
*pipe
,
121 struct pipe_surface
*ps
,
122 uint x
, uint y
, uint w
, uint h
,
123 void *p
, int dst_stride
)
125 const uint cpp
= ps
->cpp
;
135 if (dst_stride
== 0) {
136 dst_stride
= w0
* cpp
;
139 pSrc
= ps
->map
+ ps
->offset
+ (y
* ps
->pitch
+ x
) * cpp
;
142 for (i
= 0; i
< h
; i
++) {
143 memcpy(pDest
, pSrc
, w0
* cpp
);
145 pSrc
+= ps
->pitch
* cpp
;
151 * XXX note: same as code in sp_surface.c
154 nv40_put_tile(struct pipe_context
*pipe
,
155 struct pipe_surface
*ps
,
156 uint x
, uint y
, uint w
, uint h
,
157 const void *p
, int src_stride
)
159 const uint cpp
= ps
->cpp
;
169 if (src_stride
== 0) {
170 src_stride
= w0
* cpp
;
173 pSrc
= (const ubyte
*) p
;
174 pDest
= ps
->map
+ ps
->offset
+ (y
* ps
->pitch
+ x
) * cpp
;
176 for (i
= 0; i
< h
; i
++) {
177 memcpy(pDest
, pSrc
, w0
* cpp
);
178 pDest
+= ps
->pitch
* cpp
;
184 static struct pipe_surface
*
185 nv40_get_tex_surface(struct pipe_context
*pipe
,
186 struct pipe_texture
*pt
,
187 unsigned face
, unsigned level
, unsigned zslice
)
189 struct pipe_winsys
*ws
= pipe
->winsys
;
190 struct nv40_miptree
*nv40mt
= (struct nv40_miptree
*)pt
;
191 struct pipe_surface
*ps
;
193 ps
= ws
->surface_alloc(ws
, pt
->format
);
196 ws
->buffer_reference(ws
, &ps
->buffer
, nv40mt
->buffer
);
198 ps
->width
= pt
->width
[level
];
199 ps
->height
= pt
->height
[level
];
200 ps
->pitch
= nv40mt
->level
[level
].pitch
/ ps
->cpp
;
202 if (pt
->target
== PIPE_TEXTURE_CUBE
) {
203 ps
->offset
= nv40mt
->level
[level
].image_offset
[face
];
205 if (pt
->target
== PIPE_TEXTURE_3D
) {
206 ps
->offset
= nv40mt
->level
[level
].image_offset
[zslice
];
208 ps
->offset
= nv40mt
->level
[level
].image_offset
[0];
215 nv40_surface_data(struct pipe_context
*pipe
, struct pipe_surface
*dest
,
216 unsigned destx
, unsigned desty
, const void *src
,
217 unsigned src_stride
, unsigned srcx
, unsigned srcy
,
218 unsigned width
, unsigned height
)
220 struct nv40_context
*nv40
= (struct nv40_context
*)pipe
;
221 struct nouveau_winsys
*nvws
= nv40
->nvws
;
223 nvws
->surface_data(nvws
, dest
, destx
, desty
, src
, src_stride
,
224 srcx
, srcy
, width
, height
);
228 nv40_surface_copy(struct pipe_context
*pipe
, struct pipe_surface
*dest
,
229 unsigned destx
, unsigned desty
, struct pipe_surface
*src
,
230 unsigned srcx
, unsigned srcy
, unsigned width
, unsigned height
)
232 struct nv40_context
*nv40
= (struct nv40_context
*)pipe
;
233 struct nouveau_winsys
*nvws
= nv40
->nvws
;
235 nvws
->surface_copy(nvws
, dest
, destx
, desty
, src
, srcx
, srcy
,
240 nv40_surface_fill(struct pipe_context
*pipe
, struct pipe_surface
*dest
,
241 unsigned destx
, unsigned desty
, unsigned width
,
242 unsigned height
, unsigned value
)
244 struct nv40_context
*nv40
= (struct nv40_context
*)pipe
;
245 struct nouveau_winsys
*nvws
= nv40
->nvws
;
247 nvws
->surface_fill(nvws
, dest
, destx
, desty
, width
, height
, value
);
251 nv40_init_surface_functions(struct nv40_context
*nv40
)
253 nv40
->pipe
.get_tex_surface
= nv40_get_tex_surface
;
254 nv40
->pipe
.get_tile
= nv40_get_tile
;
255 nv40
->pipe
.put_tile
= nv40_put_tile
;
256 nv40
->pipe
.get_tile_rgba
= nv40_get_tile_rgba
;
257 nv40
->pipe
.put_tile_rgba
= nv40_put_tile_rgba
;
258 nv40
->pipe
.surface_data
= nv40_surface_data
;
259 nv40
->pipe
.surface_copy
= nv40_surface_copy
;
260 nv40
->pipe
.surface_fill
= nv40_surface_fill
;