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 **************************************************************************/
33 #include "pipe/p_defines.h"
34 #include "util/u_pack_color.h"
36 #include "sp_context.h"
37 #include "sp_surface.h"
39 #include "sp_tile_cache.h"
43 * Convert packed pixel from one format to another.
46 convert_color(enum pipe_format srcFormat
, unsigned srcColor
,
47 enum pipe_format dstFormat
)
52 util_unpack_color_ub(srcFormat
, &srcColor
, &r
, &g
, &b
, &a
);
53 util_pack_color_ub(r
, g
, b
, a
, dstFormat
, &dstColor
);
61 * Clear the given surface to the specified value.
62 * No masking, no scissor (clear entire buffer).
63 * Note: when clearing a color buffer, the clearValue is always
64 * encoded as PIPE_FORMAT_A8R8G8B8_UNORM.
67 softpipe_clear(struct pipe_context
*pipe
, struct pipe_surface
*ps
,
70 struct softpipe_context
*softpipe
= softpipe_context(pipe
);
73 if (softpipe
->no_rast
)
77 softpipe_update_derived(softpipe
); /* not needed?? */
80 if (ps
== sp_tile_cache_get_surface(softpipe
->zsbuf_cache
)) {
81 sp_tile_cache_clear(softpipe
->zsbuf_cache
, clearValue
);
82 softpipe
->framebuffer
.zsbuf
->status
= PIPE_SURFACE_STATUS_CLEAR
;
83 #if TILE_CLEAR_OPTIMIZATION
88 for (i
= 0; i
< softpipe
->framebuffer
.nr_cbufs
; i
++) {
89 if (ps
== sp_tile_cache_get_surface(softpipe
->cbuf_cache
[i
])) {
91 if (ps
->format
!= PIPE_FORMAT_A8R8G8B8_UNORM
) {
92 cv
= convert_color(PIPE_FORMAT_A8R8G8B8_UNORM
, clearValue
,
98 sp_tile_cache_clear(softpipe
->cbuf_cache
[i
], cv
);
99 softpipe
->framebuffer
.cbufs
[i
]->status
= PIPE_SURFACE_STATUS_CLEAR
;
103 #if !TILE_CLEAR_OPTIMIZATION
104 /* non-cached surface */
105 pipe
->surface_fill(pipe
, ps
, 0, 0, ps
->width
, ps
->height
, clearValue
);