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 **************************************************************************/
36 #include "pipe/p_inlines.h"
37 #include "util/u_memory.h"
38 #include "util/u_pack_color.h"
39 #include "cell/common.h"
40 #include "cell_clear.h"
41 #include "cell_context.h"
42 #include "cell_batch.h"
43 #include "cell_flush.h"
45 #include "cell_state.h"
49 * Convert packed pixel from one format to another.
52 convert_color(enum pipe_format srcFormat
, unsigned srcColor
,
53 enum pipe_format dstFormat
)
58 util_unpack_color_ub(srcFormat
, &srcColor
, &r
, &g
, &b
, &a
);
59 util_pack_color_ub(r
, g
, b
, a
, dstFormat
, &dstColor
);
67 * Called via pipe->clear()
70 cell_clear_surface(struct pipe_context
*pipe
, struct pipe_surface
*ps
,
73 struct pipe_screen
*screen
= pipe
->screen
;
74 struct cell_context
*cell
= cell_context(pipe
);
78 cell_update_derived(cell
);
81 if (!cell
->cbuf_map
[0])
82 cell
->cbuf_map
[0] = screen
->surface_map(screen
, ps
,
83 PIPE_BUFFER_USAGE_GPU_WRITE
);
85 if (ps
== cell
->framebuffer
.zsbuf
) {
86 /* clear z/stencil buffer */
90 /* clear color buffer */
93 if (ps
->format
!= PIPE_FORMAT_A8R8G8B8_UNORM
) {
94 clearValue
= convert_color(PIPE_FORMAT_A8R8G8B8_UNORM
, clearValue
,
100 /* Build a CLEAR command and place it in the current batch buffer */
102 struct cell_command_clear_surface
*clr
103 = (struct cell_command_clear_surface
*)
104 cell_batch_alloc(cell
, sizeof(*clr
));
105 clr
->opcode
= CELL_CMD_CLEAR_SURFACE
;
106 clr
->surface
= surfIndex
;
107 clr
->value
= clearValue
;