i915_blit.c

Go to the documentation of this file.
00001 /**************************************************************************
00002  * 
00003  * Copyright 2003 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 
00029 #include "i915_context.h"
00030 #include "i915_winsys.h"
00031 #include "i915_blit.h"
00032 #include "i915_reg.h"
00033 #include "i915_batch.h"
00034 #include "i915_debug.h"
00035 
00036 #define FILE_DEBUG_FLAG DEBUG_BLIT
00037 
00038 void
00039 i915_fill_blit(struct i915_context *i915,
00040                unsigned cpp,
00041                short dst_pitch,
00042                struct pipe_buffer *dst_buffer,
00043                unsigned dst_offset,
00044                short x, short y, 
00045                short w, short h, 
00046                unsigned color)
00047 {
00048    unsigned BR13, CMD;
00049 
00050    switch (cpp) {
00051    case 1:
00052    case 2:
00053    case 3:
00054       BR13 = dst_pitch | (0xF0 << 16) | (1 << 24);
00055       CMD = XY_COLOR_BLT_CMD;
00056       break;
00057    case 4:
00058       BR13 = dst_pitch | (0xF0 << 16) | (1 << 24) | (1 << 25);
00059       CMD = (XY_COLOR_BLT_CMD | XY_COLOR_BLT_WRITE_ALPHA |
00060              XY_COLOR_BLT_WRITE_RGB);
00061       break;
00062    default:
00063       return;
00064    }
00065 
00066 //   DBG("%s dst:buf(%p)/%d+%d %d,%d sz:%dx%d\n",
00067 //       __FUNCTION__, dst_buffer, dst_pitch, dst_offset, x, y, w, h);
00068 
00069 
00070    if (!BEGIN_BATCH(6, 1)) {
00071       FLUSH_BATCH(NULL);
00072       assert(BEGIN_BATCH(6, 1));
00073    }
00074    OUT_BATCH(CMD);
00075    OUT_BATCH(BR13);
00076    OUT_BATCH((y << 16) | x);
00077    OUT_BATCH(((y + h) << 16) | (x + w));
00078    OUT_RELOC( dst_buffer, I915_BUFFER_ACCESS_WRITE, dst_offset);
00079    OUT_BATCH(color);
00080 }
00081 
00082 
00083 void
00084 i915_copy_blit( struct i915_context *i915,
00085                   unsigned do_flip,
00086                   unsigned cpp,
00087                   short src_pitch,
00088                   struct pipe_buffer *src_buffer,
00089                   unsigned src_offset,
00090                   short dst_pitch,
00091                   struct pipe_buffer *dst_buffer,
00092                   unsigned dst_offset,
00093                   short src_x, short src_y,
00094                   short dst_x, short dst_y, 
00095                   short w, short h )
00096 {
00097    unsigned CMD, BR13;
00098    int dst_y2 = dst_y + h;
00099    int dst_x2 = dst_x + w;
00100 
00101 
00102    I915_DBG(i915,
00103        "%s src:buf(%p)/%d+%d %d,%d dst:buf(%p)/%d+%d %d,%d sz:%dx%d\n",
00104        __FUNCTION__,
00105        src_buffer, src_pitch, src_offset, src_x, src_y,
00106        dst_buffer, dst_pitch, dst_offset, dst_x, dst_y, w, h);
00107 
00108    src_pitch *= (short) cpp;
00109    dst_pitch *= (short) cpp;
00110 
00111    switch (cpp) {
00112    case 1:
00113    case 2:
00114    case 3:
00115       BR13 = (((int) dst_pitch) & 0xffff) | 
00116          (0xCC << 16) | (1 << 24);
00117       CMD = XY_SRC_COPY_BLT_CMD;
00118       break;
00119    case 4:
00120       BR13 =
00121          (((int) dst_pitch) & 0xffff) | 
00122          (0xCC << 16) | (1 << 24) | (1 << 25);
00123       CMD =
00124          (XY_SRC_COPY_BLT_CMD | XY_SRC_COPY_BLT_WRITE_ALPHA |
00125           XY_SRC_COPY_BLT_WRITE_RGB);
00126       break;
00127    default:
00128       return;
00129    }
00130 
00131    if (dst_y2 < dst_y || 
00132        dst_x2 < dst_x) {
00133       return;
00134    }
00135 
00136    /* Hardware can handle negative pitches but loses the ability to do
00137     * proper overlapping blits in that case.  We don't really have a
00138     * need for either at this stage.
00139     */
00140    assert (dst_pitch > 0 && src_pitch > 0);
00141 
00142 
00143    if (!BEGIN_BATCH(8, 2)) {
00144       FLUSH_BATCH(NULL);
00145       assert(BEGIN_BATCH(8, 2));
00146    }
00147    OUT_BATCH(CMD);
00148    OUT_BATCH(BR13);
00149    OUT_BATCH((dst_y << 16) | dst_x);
00150    OUT_BATCH((dst_y2 << 16) | dst_x2);
00151    OUT_RELOC(dst_buffer, I915_BUFFER_ACCESS_WRITE, dst_offset);
00152    OUT_BATCH((src_y << 16) | src_x);
00153    OUT_BATCH(((int) src_pitch & 0xffff));
00154    OUT_RELOC(src_buffer, I915_BUFFER_ACCESS_READ, src_offset);
00155 }
00156 
00157 

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