Path: blob/21.2-virgl/src/gallium/drivers/i915/i915_blit.c
4570 views
/**************************************************************************1*2* Copyright 2003 VMware, Inc.3* All Rights Reserved.4*5* Permission is hereby granted, free of charge, to any person obtaining a6* copy of this software and associated documentation files (the7* "Software"), to deal in the Software without restriction, including8* without limitation the rights to use, copy, modify, merge, publish,9* distribute, sub license, and/or sell copies of the Software, and to10* permit persons to whom the Software is furnished to do so, subject to11* the following conditions:12*13* The above copyright notice and this permission notice (including the14* next paragraph) shall be included in all copies or substantial portions15* of the Software.16*17* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS18* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF19* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.20* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR21* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,22* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE23* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.24*25**************************************************************************/2627#include "i915_blit.h"28#include "i915_batch.h"29#include "i915_debug.h"30#include "i915_reg.h"3132void33i915_fill_blit(struct i915_context *i915, unsigned cpp, unsigned rgba_mask,34unsigned short dst_pitch, struct i915_winsys_buffer *dst_buffer,35unsigned dst_offset, short x, short y, short w, short h,36unsigned color)37{38unsigned BR13, CMD;3940I915_DBG(DBG_BLIT, "%s dst:buf(%p)/%d+%d %d,%d sz:%dx%d\n", __FUNCTION__,41dst_buffer, dst_pitch, dst_offset, x, y, w, h);4243if (!i915_winsys_validate_buffers(i915->batch, &dst_buffer, 1)) {44FLUSH_BATCH(NULL, I915_FLUSH_ASYNC);45assert(i915_winsys_validate_buffers(i915->batch, &dst_buffer, 1));46}4748switch (cpp) {49case 1:50case 2:51case 3:52BR13 = (((int)dst_pitch) & 0xffff) | (0xF0 << 16) | (1 << 24);53CMD = XY_COLOR_BLT_CMD;54break;55case 4:56BR13 = (((int)dst_pitch) & 0xffff) | (0xF0 << 16) | (1 << 24) | (1 << 25);57CMD = (XY_COLOR_BLT_CMD | rgba_mask);58break;59default:60return;61}6263if (!BEGIN_BATCH(6)) {64FLUSH_BATCH(NULL, I915_FLUSH_ASYNC);65assert(BEGIN_BATCH(6));66}67OUT_BATCH(CMD);68OUT_BATCH(BR13);69OUT_BATCH((y << 16) | x);70OUT_BATCH(((y + h) << 16) | (x + w));71OUT_RELOC_FENCED(dst_buffer, I915_USAGE_2D_TARGET, dst_offset);72OUT_BATCH(color);7374i915_set_flush_dirty(i915, I915_FLUSH_CACHE);75}7677void78i915_copy_blit(struct i915_context *i915, unsigned cpp,79unsigned short src_pitch, struct i915_winsys_buffer *src_buffer,80unsigned src_offset, unsigned short dst_pitch,81struct i915_winsys_buffer *dst_buffer, unsigned dst_offset,82short src_x, short src_y, short dst_x, short dst_y, short w,83short h)84{85unsigned CMD, BR13;86int dst_y2 = dst_y + h;87int dst_x2 = dst_x + w;88struct i915_winsys_buffer *buffers[2] = {src_buffer, dst_buffer};8990I915_DBG(DBG_BLIT,91"%s src:buf(%p)/%d+%d %d,%d dst:buf(%p)/%d+%d %d,%d sz:%dx%d\n",92__FUNCTION__, src_buffer, src_pitch, src_offset, src_x, src_y,93dst_buffer, dst_pitch, dst_offset, dst_x, dst_y, w, h);9495if (!i915_winsys_validate_buffers(i915->batch, buffers, 2)) {96FLUSH_BATCH(NULL, I915_FLUSH_ASYNC);97assert(i915_winsys_validate_buffers(i915->batch, buffers, 2));98}99100switch (cpp) {101case 1:102case 2:103case 3:104BR13 = (((int)dst_pitch) & 0xffff) | (0xCC << 16) | (1 << 24);105CMD = XY_SRC_COPY_BLT_CMD;106break;107case 4:108BR13 = (((int)dst_pitch) & 0xffff) | (0xCC << 16) | (1 << 24) | (1 << 25);109CMD = (XY_SRC_COPY_BLT_CMD | XY_SRC_COPY_BLT_WRITE_ALPHA |110XY_SRC_COPY_BLT_WRITE_RGB);111break;112default:113return;114}115116if (dst_y2 < dst_y || dst_x2 < dst_x) {117return;118}119120/* Hardware can handle negative pitches but loses the ability to do121* proper overlapping blits in that case. We don't really have a122* need for either at this stage.123*/124assert(dst_pitch > 0 && src_pitch > 0);125126if (!BEGIN_BATCH(8)) {127FLUSH_BATCH(NULL, I915_FLUSH_ASYNC);128assert(BEGIN_BATCH(8));129}130OUT_BATCH(CMD);131OUT_BATCH(BR13);132OUT_BATCH((dst_y << 16) | dst_x);133OUT_BATCH((dst_y2 << 16) | dst_x2);134OUT_RELOC_FENCED(dst_buffer, I915_USAGE_2D_TARGET, dst_offset);135OUT_BATCH((src_y << 16) | src_x);136OUT_BATCH(((int)src_pitch & 0xffff));137OUT_RELOC_FENCED(src_buffer, I915_USAGE_2D_SOURCE, src_offset);138139i915_set_flush_dirty(i915, I915_FLUSH_CACHE);140}141142143