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 "nv50_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 nv50_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 nv50_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 nv50_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 nv50_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 nv50_get_tex_surface(struct pipe_context
*pipe
,
186 struct pipe_texture
*pt
,
187 unsigned face
, unsigned level
, unsigned zslice
)
189 NOUVEAU_ERR("unimplemented\n");
194 nv50_surface_data(struct pipe_context
*pipe
, struct pipe_surface
*dest
,
195 unsigned destx
, unsigned desty
, const void *src
,
196 unsigned src_stride
, unsigned srcx
, unsigned srcy
,
197 unsigned width
, unsigned height
)
199 struct nv50_context
*nv50
= (struct nv50_context
*)pipe
;
200 struct nouveau_winsys
*nvws
= nv50
->nvws
;
202 nvws
->surface_data(nvws
, dest
, destx
, desty
, src
, src_stride
,
203 srcx
, srcy
, width
, height
);
207 nv50_surface_copy(struct pipe_context
*pipe
, struct pipe_surface
*dest
,
208 unsigned destx
, unsigned desty
, struct pipe_surface
*src
,
209 unsigned srcx
, unsigned srcy
, unsigned width
, unsigned height
)
211 struct nv50_context
*nv50
= (struct nv50_context
*)pipe
;
212 struct nouveau_winsys
*nvws
= nv50
->nvws
;
214 nvws
->surface_copy(nvws
, dest
, destx
, desty
, src
, srcx
, srcy
,
219 nv50_surface_fill(struct pipe_context
*pipe
, struct pipe_surface
*dest
,
220 unsigned destx
, unsigned desty
, unsigned width
,
221 unsigned height
, unsigned value
)
223 struct nv50_context
*nv50
= (struct nv50_context
*)pipe
;
224 struct nouveau_winsys
*nvws
= nv50
->nvws
;
226 nvws
->surface_fill(nvws
, dest
, destx
, desty
, width
, height
, value
);
230 nv50_init_surface_functions(struct nv50_context
*nv50
)
232 nv50
->pipe
.get_tex_surface
= nv50_get_tex_surface
;
233 nv50
->pipe
.get_tile
= nv50_get_tile
;
234 nv50
->pipe
.put_tile
= nv50_put_tile
;
235 nv50
->pipe
.get_tile_rgba
= nv50_get_tile_rgba
;
236 nv50
->pipe
.put_tile_rgba
= nv50_put_tile_rgba
;
237 nv50
->pipe
.surface_data
= nv50_surface_data
;
238 nv50
->pipe
.surface_copy
= nv50_surface_copy
;
239 nv50
->pipe
.surface_fill
= nv50_surface_fill
;