1 /**************************************************************************
3 * Copyright 2007 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 "pipe/p_defines.h"
29 #include "pipe/p_util.h"
30 #include "pipe/p_inlines.h"
31 #include "pipe/p_winsys.h"
32 #include "util/p_tile.h"
33 #include "sp_context.h"
34 #include "sp_surface.h"
38 /* Assumes all values are within bounds -- no checking at this level -
39 * do it higher up if required.
42 sp_surface_copy(struct pipe_context
*pipe
,
44 struct pipe_surface
*dst
,
45 unsigned dstx
, unsigned dsty
,
46 struct pipe_surface
*src
,
47 unsigned srcx
, unsigned srcy
, unsigned width
, unsigned height
)
49 void *dst_map
= pipe
->screen
->surface_map( pipe
->screen
,
51 PIPE_BUFFER_USAGE_CPU_WRITE
);
53 const void *src_map
= pipe
->screen
->surface_map( pipe
->screen
,
55 PIPE_BUFFER_USAGE_CPU_READ
);
57 assert( dst
->cpp
== src
->cpp
);
58 assert(src_map
&& dst_map
);
60 pipe_copy_rect(dst_map
,
66 do_flip
? -(int) src
->pitch
: src
->pitch
,
67 srcx
, do_flip
? 1 - srcy
- height
: srcy
);
69 pipe
->screen
->surface_unmap(pipe
->screen
, src
);
70 pipe
->screen
->surface_unmap(pipe
->screen
, dst
);
75 get_pointer(struct pipe_surface
*dst
, void *dst_map
, unsigned x
, unsigned y
)
77 return (char *)dst_map
+ (y
* dst
->pitch
+ x
) * dst
->cpp
;
81 #define UBYTE_TO_USHORT(B) ((B) | ((B) << 8))
85 * Fill a rectangular sub-region. Need better logic about when to
86 * push buffers into AGP - will currently do so whenever possible.
89 sp_surface_fill(struct pipe_context
*pipe
,
90 struct pipe_surface
*dst
,
91 unsigned dstx
, unsigned dsty
,
92 unsigned width
, unsigned height
, unsigned value
)
95 void *dst_map
= pipe
->screen
->surface_map( pipe
->screen
,
97 PIPE_BUFFER_USAGE_CPU_WRITE
);
99 assert(dst
->pitch
> 0);
100 assert(width
<= dst
->pitch
);
106 ubyte
*row
= get_pointer(dst
, dst_map
, dstx
, dsty
);
107 for (i
= 0; i
< height
; i
++) {
108 memset(row
, value
, width
);
115 ushort
*row
= get_pointer(dst
, dst_map
, dstx
, dsty
);
116 for (i
= 0; i
< height
; i
++) {
117 for (j
= 0; j
< width
; j
++)
118 row
[j
] = (ushort
) value
;
125 unsigned *row
= get_pointer(dst
, dst_map
, dstx
, dsty
);
126 for (i
= 0; i
< height
; i
++) {
127 for (j
= 0; j
< width
; j
++)
135 /* expand the 4-byte clear value to an 8-byte value */
136 ushort
*row
= (ushort
*) get_pointer(dst
, dst_map
, dstx
, dsty
);
137 ushort val0
= UBYTE_TO_USHORT((value
>> 0) & 0xff);
138 ushort val1
= UBYTE_TO_USHORT((value
>> 8) & 0xff);
139 ushort val2
= UBYTE_TO_USHORT((value
>> 16) & 0xff);
140 ushort val3
= UBYTE_TO_USHORT((value
>> 24) & 0xff);
141 val0
= (val0
<< 8) | val0
;
142 val1
= (val1
<< 8) | val1
;
143 val2
= (val2
<< 8) | val2
;
144 val3
= (val3
<< 8) | val3
;
145 for (i
= 0; i
< height
; i
++) {
146 for (j
= 0; j
< width
; j
++) {
152 row
+= dst
->pitch
* 4;
161 pipe
->screen
->surface_unmap(pipe
->screen
, dst
);
166 sp_init_surface_functions(struct softpipe_context
*sp
)
168 sp
->pipe
.surface_copy
= sp_surface_copy
;
169 sp
->pipe
.surface_fill
= sp_surface_fill
;