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_context.h"
29 #include "i915_blit.h"
30 #include "i915_state.h"
31 #include "pipe/p_defines.h"
32 #include "pipe/p_inlines.h"
33 #include "pipe/p_util.h"
34 #include "pipe/p_inlines.h"
35 #include "pipe/p_winsys.h"
42 if (y >= ps->height) \
44 if (x + w > ps->width) \
46 if (y + h > ps->height) \
52 * Note: this is exactly like a8r8g8b8_get_tile() in sp_surface.c
55 /** XXX this will go away eventually */
57 i915_get_tile_rgba(struct pipe_context
*pipe
,
58 struct pipe_surface
*ps
,
59 uint x
, uint y
, uint w
, uint h
, float *p
)
62 = ((const unsigned *) (ps
->map
))
70 case PIPE_FORMAT_A8R8G8B8_UNORM
:
71 for (i
= 0; i
< h
; i
++) {
73 for (j
= 0; j
< w
; j
++) {
74 const unsigned pixel
= src
[j
];
75 pRow
[0] = UBYTE_TO_FLOAT((pixel
>> 16) & 0xff);
76 pRow
[1] = UBYTE_TO_FLOAT((pixel
>> 8) & 0xff);
77 pRow
[2] = UBYTE_TO_FLOAT((pixel
>> 0) & 0xff);
78 pRow
[3] = UBYTE_TO_FLOAT((pixel
>> 24) & 0xff);
85 case PIPE_FORMAT_S8Z24_UNORM
:
87 const float scale
= 1.0f
/ (float) 0xffffff;
88 for (i
= 0; i
< h
; i
++) {
90 for (j
= 0; j
< w
; j
++) {
91 const unsigned pixel
= src
[j
];
95 pRow
[3] = (pixel
& 0xffffff) * scale
;
109 /** XXX this will go away eventually */
111 i915_put_tile_rgba(struct pipe_context
*pipe
,
112 struct pipe_surface
*ps
,
113 uint x
, uint y
, uint w
, uint h
, const float *p
)
116 = ((unsigned *) (ps
->map
))
121 assert(ps
->format
== PIPE_FORMAT_A8R8G8B8_UNORM
);
125 switch (ps
->format
) {
126 case PIPE_FORMAT_A8R8G8B8_UNORM
:
127 for (i
= 0; i
< h
; i
++) {
128 const float *pRow
= p
;
129 for (j
= 0; j
< w
; j
++) {
131 UNCLAMPED_FLOAT_TO_UBYTE(r
, pRow
[0]);
132 UNCLAMPED_FLOAT_TO_UBYTE(g
, pRow
[1]);
133 UNCLAMPED_FLOAT_TO_UBYTE(b
, pRow
[2]);
134 UNCLAMPED_FLOAT_TO_UBYTE(a
, pRow
[3]);
135 dst
[j
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
149 * XXX note: same as code in sp_surface.c
152 i915_get_tile(struct pipe_context
*pipe
,
153 struct pipe_surface
*ps
,
154 uint x
, uint y
, uint w
, uint h
,
155 void *p
, int dst_stride
)
157 const uint cpp
= ps
->cpp
;
167 if (dst_stride
== 0) {
168 dst_stride
= w0
* cpp
;
171 pSrc
= ps
->map
+ (y
* ps
->pitch
+ x
) * cpp
;
174 for (i
= 0; i
< h
; i
++) {
175 memcpy(pDest
, pSrc
, w0
* cpp
);
177 pSrc
+= ps
->pitch
* cpp
;
183 * XXX note: same as code in sp_surface.c
186 i915_put_tile(struct pipe_context
*pipe
,
187 struct pipe_surface
*ps
,
188 uint x
, uint y
, uint w
, uint h
,
189 const void *p
, int src_stride
)
191 const uint cpp
= ps
->cpp
;
201 if (src_stride
== 0) {
202 src_stride
= w0
* cpp
;
205 pSrc
= (const ubyte
*) p
;
206 pDest
= ps
->map
+ (y
* ps
->pitch
+ x
) * cpp
;
208 for (i
= 0; i
< h
; i
++) {
209 memcpy(pDest
, pSrc
, w0
* cpp
);
210 pDest
+= ps
->pitch
* cpp
;
217 * XXX note: same as code in sp_surface.c
219 static struct pipe_surface
*
220 i915_get_tex_surface(struct pipe_context
*pipe
,
221 struct pipe_texture
*pt
,
222 unsigned face
, unsigned level
, unsigned zslice
)
224 struct i915_texture
*tex
= (struct i915_texture
*)pt
;
225 struct pipe_surface
*ps
;
226 unsigned offset
; /* in bytes */
228 offset
= tex
->level_offset
[level
];
230 if (pt
->target
== PIPE_TEXTURE_CUBE
) {
231 offset
+= tex
->image_offset
[level
][face
] * pt
->cpp
;
233 else if (pt
->target
== PIPE_TEXTURE_3D
) {
234 offset
+= tex
->image_offset
[level
][zslice
] * pt
->cpp
;
241 ps
= pipe
->winsys
->surface_alloc(pipe
->winsys
);
244 assert(ps
->refcount
);
245 pipe
->winsys
->buffer_reference(pipe
->winsys
, &ps
->buffer
, tex
->buffer
);
246 ps
->format
= pt
->format
;
248 ps
->width
= pt
->width
[level
];
249 ps
->height
= pt
->height
[level
];
250 ps
->pitch
= tex
->pitch
;
258 * XXX Move this into core Mesa?
261 _mesa_copy_rect(ubyte
* dst
,
279 dst
+= dst_y
* dst_pitch
;
280 src
+= src_y
* dst_pitch
;
283 if (width
== dst_pitch
&& width
== src_pitch
)
284 memcpy(dst
, src
, height
* width
);
286 for (i
= 0; i
< height
; i
++) {
287 memcpy(dst
, src
, width
);
295 /* Upload data to a rectangular sub-region. Lots of choices how to do this:
297 * - memcpy by span to current destination
298 * - upload data as new buffer and blit
300 * Currently always memcpy.
303 i915_surface_data(struct pipe_context
*pipe
,
304 struct pipe_surface
*dst
,
305 unsigned dstx
, unsigned dsty
,
306 const void *src
, unsigned src_pitch
,
307 unsigned srcx
, unsigned srcy
, unsigned width
, unsigned height
)
309 _mesa_copy_rect(pipe_surface_map(dst
),
312 dstx
, dsty
, width
, height
, src
, src_pitch
, srcx
, srcy
);
314 pipe_surface_unmap(dst
);
318 /* Assumes all values are within bounds -- no checking at this level -
319 * do it higher up if required.
322 i915_surface_copy(struct pipe_context
*pipe
,
323 struct pipe_surface
*dst
,
324 unsigned dstx
, unsigned dsty
,
325 struct pipe_surface
*src
,
326 unsigned srcx
, unsigned srcy
, unsigned width
, unsigned height
)
328 assert( dst
!= src
);
329 assert( dst
->cpp
== src
->cpp
);
332 _mesa_copy_rect(pipe_surface_map(dst
),
337 pipe_surface_map(src
),
341 pipe_surface_unmap(src
);
342 pipe_surface_unmap(dst
);
345 i915_copy_blit( i915_context(pipe
),
347 (short) src
->pitch
, src
->buffer
, src
->offset
,
348 (short) dst
->pitch
, dst
->buffer
, dst
->offset
,
349 (short) srcx
, (short) srcy
, (short) dstx
, (short) dsty
, (short) width
, (short) height
);
353 /* Fill a rectangular sub-region. Need better logic about when to
354 * push buffers into AGP - will currently do so whenever possible.
357 get_pointer(struct pipe_surface
*dst
, unsigned x
, unsigned y
)
359 return dst
->map
+ (y
* dst
->pitch
+ x
) * dst
->cpp
;
364 i915_surface_fill(struct pipe_context
*pipe
,
365 struct pipe_surface
*dst
,
366 unsigned dstx
, unsigned dsty
,
367 unsigned width
, unsigned height
, unsigned value
)
372 (void)pipe_surface_map(dst
);
376 ubyte
*row
= get_pointer(dst
, dstx
, dsty
);
377 for (i
= 0; i
< height
; i
++) {
378 memset(row
, value
, width
);
384 ushort
*row
= (ushort
*) get_pointer(dst
, dstx
, dsty
);
385 for (i
= 0; i
< height
; i
++) {
386 for (j
= 0; j
< width
; j
++)
387 row
[j
] = (ushort
) value
;
393 unsigned *row
= (unsigned *) get_pointer(dst
, dstx
, dsty
);
394 for (i
= 0; i
< height
; i
++) {
395 for (j
= 0; j
< width
; j
++)
407 i915_fill_blit( i915_context(pipe
),
410 dst
->buffer
, dst
->offset
,
411 (short) dstx
, (short) dsty
,
412 (short) width
, (short) height
,
419 i915_init_surface_functions(struct i915_context
*i915
)
421 i915
->pipe
.get_tex_surface
= i915_get_tex_surface
;
422 i915
->pipe
.get_tile
= i915_get_tile
;
423 i915
->pipe
.put_tile
= i915_put_tile
;
424 i915
->pipe
.get_tile_rgba
= i915_get_tile_rgba
;
425 i915
->pipe
.put_tile_rgba
= i915_put_tile_rgba
;
426 i915
->pipe
.surface_data
= i915_surface_data
;
427 i915
->pipe
.surface_copy
= i915_surface_copy
;
428 i915
->pipe
.surface_fill
= i915_surface_fill
;