sp_clear.c

Go to the documentation of this file.
00001 /**************************************************************************
00002  * 
00003  * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
00004  * All Rights Reserved.
00005  * 
00006  * Permission is hereby granted, free of charge, to any person obtaining a
00007  * copy of this software and associated documentation files (the
00008  * "Software"), to deal in the Software without restriction, including
00009  * without limitation the rights to use, copy, modify, merge, publish,
00010  * distribute, sub license, and/or sell copies of the Software, and to
00011  * permit persons to whom the Software is furnished to do so, subject to
00012  * the following conditions:
00013  * 
00014  * The above copyright notice and this permission notice (including the
00015  * next paragraph) shall be included in all copies or substantial portions
00016  * of the Software.
00017  * 
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00019  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00020  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
00021  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
00022  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
00023  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
00024  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00025  * 
00026  **************************************************************************/
00027 
00028 /* Author:
00029  *    Brian Paul
00030  */
00031 
00032 
00033 #include "pipe/p_defines.h"
00034 #include "util/u_pack_color.h"
00035 #include "sp_clear.h"
00036 #include "sp_context.h"
00037 #include "sp_surface.h"
00038 #include "sp_state.h"
00039 #include "sp_tile_cache.h"
00040 
00041 
00045 static unsigned
00046 convert_color(enum pipe_format srcFormat, unsigned srcColor,
00047               enum pipe_format dstFormat)
00048 {
00049    ubyte r, g, b, a;
00050    unsigned dstColor;
00051 
00052    util_unpack_color_ub(srcFormat, &srcColor, &r, &g, &b, &a);
00053    util_pack_color_ub(r, g, b, a, dstFormat, &dstColor);
00054 
00055    return dstColor;
00056 }
00057 
00058 
00059 
00066 void
00067 softpipe_clear(struct pipe_context *pipe, struct pipe_surface *ps,
00068                unsigned clearValue)
00069 {
00070    struct softpipe_context *softpipe = softpipe_context(pipe);
00071    uint i;
00072 
00073    if (softpipe->no_rast)
00074       return;
00075 
00076 #if 0
00077    softpipe_update_derived(softpipe); /* not needed?? */
00078 #endif
00079 
00080    if (ps == sp_tile_cache_get_surface(softpipe->zsbuf_cache)) {
00081       sp_tile_cache_clear(softpipe->zsbuf_cache, clearValue);
00082       softpipe->framebuffer.zsbuf->status = PIPE_SURFACE_STATUS_CLEAR;
00083 #if TILE_CLEAR_OPTIMIZATION
00084       return;
00085 #endif
00086    }
00087 
00088    for (i = 0; i < softpipe->framebuffer.num_cbufs; i++) {
00089       if (ps == sp_tile_cache_get_surface(softpipe->cbuf_cache[i])) {
00090          unsigned cv;
00091          if (ps->format != PIPE_FORMAT_A8R8G8B8_UNORM) {
00092             cv = convert_color(PIPE_FORMAT_A8R8G8B8_UNORM, clearValue,
00093                                ps->format);
00094          }
00095          else {
00096             cv = clearValue;
00097          }
00098          sp_tile_cache_clear(softpipe->cbuf_cache[i], cv);
00099          softpipe->framebuffer.cbufs[i]->status = PIPE_SURFACE_STATUS_CLEAR;
00100       }
00101    }
00102 
00103 #if !TILE_CLEAR_OPTIMIZATION
00104    /* non-cached surface */
00105    pipe->surface_fill(pipe, ps, 0, 0, ps->width, ps->height, clearValue);
00106 #endif
00107 }

Generated on Tue Sep 29 06:25:17 2009 for Gallium3D by  doxygen 1.5.4