Merge branch 'mesa_7_7_branch'
[mesa.git] / src / gallium / drivers / cell / ppu / cell_clear.c
index c9c0c721bbe5d812591791b9f319c11f219ddb3d..3a3f968a492f8530854c4502d9258c7d55a4160a 100644 (file)
 #include "cell_state.h"
 
 
-/**
- * Convert packed pixel from one format to another.
- */
-static unsigned
-convert_color(enum pipe_format srcFormat, unsigned srcColor,
-              enum pipe_format dstFormat)
-{
-   ubyte r, g, b, a;
-   unsigned dstColor;
-
-   util_unpack_color_ub(srcFormat, &srcColor, &r, &g, &b, &a);
-   util_pack_color_ub(r, g, b, a, dstFormat, &dstColor);
-
-   return dstColor;
-}
-
-
-
 /**
  * Called via pipe->clear()
  */
 void
-cell_clear_surface(struct pipe_context *pipe, struct pipe_surface *ps,
-                   unsigned clearValue)
+cell_clear(struct pipe_context *pipe, unsigned buffers, const float *rgba,
+           double depth, unsigned stencil)
 {
-   struct pipe_screen *screen = pipe->screen;
    struct cell_context *cell = cell_context(pipe);
-   uint surfIndex;
 
    if (cell->dirty)
       cell_update_derived(cell);
 
+   if (buffers & PIPE_CLEAR_COLOR) {
+      uint surfIndex = 0;
+      union util_color uc;
 
-   if (!cell->cbuf_map[0])
-      cell->cbuf_map[0] = screen->surface_map(screen, ps,
-                                              PIPE_BUFFER_USAGE_GPU_WRITE);
+      util_pack_color(rgba, cell->framebuffer.cbufs[0]->format, &uc);
 
-   if (ps == cell->framebuffer.zsbuf) {
-      /* clear z/stencil buffer */
-      surfIndex = 1;
+      /* Build a CLEAR command and place it in the current batch buffer */
+      STATIC_ASSERT(sizeof(struct cell_command_clear_surface) % 16 == 0);
+      struct cell_command_clear_surface *clr
+         = (struct cell_command_clear_surface *)
+         cell_batch_alloc16(cell, sizeof(*clr));
+      clr->opcode[0] = CELL_CMD_CLEAR_SURFACE;
+      clr->surface = surfIndex;
+      clr->value = uc.ui;
    }
-   else {
-      /* clear color buffer */
-      surfIndex = 0;
 
-      if (ps->format != PIPE_FORMAT_A8R8G8B8_UNORM) {
-         clearValue = convert_color(PIPE_FORMAT_A8R8G8B8_UNORM, clearValue,
-                                    ps->format);
-      }
-   }
+   if (buffers & PIPE_CLEAR_DEPTHSTENCIL) {
+      uint surfIndex = 1;
+      uint clearValue;
 
+      clearValue = util_pack_z_stencil(cell->framebuffer.zsbuf->format,
+                                       depth, stencil);
 
-   /* Build a CLEAR command and place it in the current batch buffer */
-   {
+      /* Build a CLEAR command and place it in the current batch buffer */
+      STATIC_ASSERT(sizeof(struct cell_command_clear_surface) % 16 == 0);
       struct cell_command_clear_surface *clr
          = (struct cell_command_clear_surface *)
-         cell_batch_alloc(cell, sizeof(*clr));
-      clr->opcode = CELL_CMD_CLEAR_SURFACE;
+         cell_batch_alloc16(cell, sizeof(*clr));
+      clr->opcode[0] = CELL_CMD_CLEAR_SURFACE;
       clr->surface = surfIndex;
       clr->value = clearValue;
    }