1bf215546Sopenharmony_ci/**************************************************************************
2bf215546Sopenharmony_ci *
3bf215546Sopenharmony_ci * Copyright 2003 VMware, Inc.
4bf215546Sopenharmony_ci * All Rights Reserved.
5bf215546Sopenharmony_ci *
6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the
8bf215546Sopenharmony_ci * "Software"), to deal in the Software without restriction, including
9bf215546Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish,
10bf215546Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to
11bf215546Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to
12bf215546Sopenharmony_ci * the following conditions:
13bf215546Sopenharmony_ci *
14bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the
15bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions
16bf215546Sopenharmony_ci * of the Software.
17bf215546Sopenharmony_ci *
18bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20bf215546Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21bf215546Sopenharmony_ci * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22bf215546Sopenharmony_ci * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23bf215546Sopenharmony_ci * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24bf215546Sopenharmony_ci * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25bf215546Sopenharmony_ci *
26bf215546Sopenharmony_ci **************************************************************************/
27bf215546Sopenharmony_ci
28bf215546Sopenharmony_ci#include "i915_blit.h"
29bf215546Sopenharmony_ci#include "i915_batch.h"
30bf215546Sopenharmony_ci#include "i915_debug.h"
31bf215546Sopenharmony_ci#include "i915_reg.h"
32bf215546Sopenharmony_ci
33bf215546Sopenharmony_civoid
34bf215546Sopenharmony_cii915_fill_blit(struct i915_context *i915, unsigned cpp, unsigned rgba_mask,
35bf215546Sopenharmony_ci               unsigned short dst_pitch, struct i915_winsys_buffer *dst_buffer,
36bf215546Sopenharmony_ci               unsigned dst_offset, short x, short y, short w, short h,
37bf215546Sopenharmony_ci               unsigned color)
38bf215546Sopenharmony_ci{
39bf215546Sopenharmony_ci   unsigned BR13, CMD;
40bf215546Sopenharmony_ci
41bf215546Sopenharmony_ci   I915_DBG(DBG_BLIT, "%s dst:buf(%p)/%d+%d %d,%d sz:%dx%d\n", __FUNCTION__,
42bf215546Sopenharmony_ci            dst_buffer, dst_pitch, dst_offset, x, y, w, h);
43bf215546Sopenharmony_ci
44bf215546Sopenharmony_ci   if (!i915_winsys_validate_buffers(i915->batch, &dst_buffer, 1)) {
45bf215546Sopenharmony_ci      FLUSH_BATCH(NULL, I915_FLUSH_ASYNC);
46bf215546Sopenharmony_ci      assert(i915_winsys_validate_buffers(i915->batch, &dst_buffer, 1));
47bf215546Sopenharmony_ci   }
48bf215546Sopenharmony_ci
49bf215546Sopenharmony_ci   switch (cpp) {
50bf215546Sopenharmony_ci   case 1:
51bf215546Sopenharmony_ci   case 2:
52bf215546Sopenharmony_ci   case 3:
53bf215546Sopenharmony_ci      BR13 = (((int)dst_pitch) & 0xffff) | (0xF0 << 16) | (1 << 24);
54bf215546Sopenharmony_ci      CMD = XY_COLOR_BLT_CMD;
55bf215546Sopenharmony_ci      break;
56bf215546Sopenharmony_ci   case 4:
57bf215546Sopenharmony_ci      BR13 = (((int)dst_pitch) & 0xffff) | (0xF0 << 16) | (1 << 24) | (1 << 25);
58bf215546Sopenharmony_ci      CMD = (XY_COLOR_BLT_CMD | rgba_mask);
59bf215546Sopenharmony_ci      break;
60bf215546Sopenharmony_ci   default:
61bf215546Sopenharmony_ci      return;
62bf215546Sopenharmony_ci   }
63bf215546Sopenharmony_ci
64bf215546Sopenharmony_ci   if (!BEGIN_BATCH(6)) {
65bf215546Sopenharmony_ci      FLUSH_BATCH(NULL, I915_FLUSH_ASYNC);
66bf215546Sopenharmony_ci      assert(BEGIN_BATCH(6));
67bf215546Sopenharmony_ci   }
68bf215546Sopenharmony_ci   OUT_BATCH(CMD);
69bf215546Sopenharmony_ci   OUT_BATCH(BR13);
70bf215546Sopenharmony_ci   OUT_BATCH((y << 16) | x);
71bf215546Sopenharmony_ci   OUT_BATCH(((y + h) << 16) | (x + w));
72bf215546Sopenharmony_ci   OUT_RELOC_FENCED(dst_buffer, I915_USAGE_2D_TARGET, dst_offset);
73bf215546Sopenharmony_ci   OUT_BATCH(color);
74bf215546Sopenharmony_ci
75bf215546Sopenharmony_ci   i915_set_flush_dirty(i915, I915_FLUSH_CACHE);
76bf215546Sopenharmony_ci}
77bf215546Sopenharmony_ci
78bf215546Sopenharmony_civoid
79bf215546Sopenharmony_cii915_copy_blit(struct i915_context *i915, unsigned cpp,
80bf215546Sopenharmony_ci               unsigned short src_pitch, struct i915_winsys_buffer *src_buffer,
81bf215546Sopenharmony_ci               unsigned src_offset, unsigned short dst_pitch,
82bf215546Sopenharmony_ci               struct i915_winsys_buffer *dst_buffer, unsigned dst_offset,
83bf215546Sopenharmony_ci               short src_x, short src_y, short dst_x, short dst_y, short w,
84bf215546Sopenharmony_ci               short h)
85bf215546Sopenharmony_ci{
86bf215546Sopenharmony_ci   unsigned CMD, BR13;
87bf215546Sopenharmony_ci   int dst_y2 = dst_y + h;
88bf215546Sopenharmony_ci   int dst_x2 = dst_x + w;
89bf215546Sopenharmony_ci   struct i915_winsys_buffer *buffers[2] = {src_buffer, dst_buffer};
90bf215546Sopenharmony_ci
91bf215546Sopenharmony_ci   I915_DBG(DBG_BLIT,
92bf215546Sopenharmony_ci            "%s src:buf(%p)/%d+%d %d,%d dst:buf(%p)/%d+%d %d,%d sz:%dx%d\n",
93bf215546Sopenharmony_ci            __FUNCTION__, src_buffer, src_pitch, src_offset, src_x, src_y,
94bf215546Sopenharmony_ci            dst_buffer, dst_pitch, dst_offset, dst_x, dst_y, w, h);
95bf215546Sopenharmony_ci
96bf215546Sopenharmony_ci   if (!i915_winsys_validate_buffers(i915->batch, buffers, 2)) {
97bf215546Sopenharmony_ci      FLUSH_BATCH(NULL, I915_FLUSH_ASYNC);
98bf215546Sopenharmony_ci      assert(i915_winsys_validate_buffers(i915->batch, buffers, 2));
99bf215546Sopenharmony_ci   }
100bf215546Sopenharmony_ci
101bf215546Sopenharmony_ci   switch (cpp) {
102bf215546Sopenharmony_ci   case 1:
103bf215546Sopenharmony_ci   case 2:
104bf215546Sopenharmony_ci   case 3:
105bf215546Sopenharmony_ci      BR13 = (((int)dst_pitch) & 0xffff) | (0xCC << 16) | (1 << 24);
106bf215546Sopenharmony_ci      CMD = XY_SRC_COPY_BLT_CMD;
107bf215546Sopenharmony_ci      break;
108bf215546Sopenharmony_ci   case 4:
109bf215546Sopenharmony_ci      BR13 = (((int)dst_pitch) & 0xffff) | (0xCC << 16) | (1 << 24) | (1 << 25);
110bf215546Sopenharmony_ci      CMD = (XY_SRC_COPY_BLT_CMD | XY_SRC_COPY_BLT_WRITE_ALPHA |
111bf215546Sopenharmony_ci             XY_SRC_COPY_BLT_WRITE_RGB);
112bf215546Sopenharmony_ci      break;
113bf215546Sopenharmony_ci   default:
114bf215546Sopenharmony_ci      return;
115bf215546Sopenharmony_ci   }
116bf215546Sopenharmony_ci
117bf215546Sopenharmony_ci   if (dst_y2 < dst_y || dst_x2 < dst_x) {
118bf215546Sopenharmony_ci      return;
119bf215546Sopenharmony_ci   }
120bf215546Sopenharmony_ci
121bf215546Sopenharmony_ci   /* Hardware can handle negative pitches but loses the ability to do
122bf215546Sopenharmony_ci    * proper overlapping blits in that case.  We don't really have a
123bf215546Sopenharmony_ci    * need for either at this stage.
124bf215546Sopenharmony_ci    */
125bf215546Sopenharmony_ci   assert(dst_pitch > 0 && src_pitch > 0);
126bf215546Sopenharmony_ci
127bf215546Sopenharmony_ci   if (!BEGIN_BATCH(8)) {
128bf215546Sopenharmony_ci      FLUSH_BATCH(NULL, I915_FLUSH_ASYNC);
129bf215546Sopenharmony_ci      assert(BEGIN_BATCH(8));
130bf215546Sopenharmony_ci   }
131bf215546Sopenharmony_ci   OUT_BATCH(CMD);
132bf215546Sopenharmony_ci   OUT_BATCH(BR13);
133bf215546Sopenharmony_ci   OUT_BATCH((dst_y << 16) | dst_x);
134bf215546Sopenharmony_ci   OUT_BATCH((dst_y2 << 16) | dst_x2);
135bf215546Sopenharmony_ci   OUT_RELOC_FENCED(dst_buffer, I915_USAGE_2D_TARGET, dst_offset);
136bf215546Sopenharmony_ci   OUT_BATCH((src_y << 16) | src_x);
137bf215546Sopenharmony_ci   OUT_BATCH(((int)src_pitch & 0xffff));
138bf215546Sopenharmony_ci   OUT_RELOC_FENCED(src_buffer, I915_USAGE_2D_SOURCE, src_offset);
139bf215546Sopenharmony_ci
140bf215546Sopenharmony_ci   i915_set_flush_dirty(i915, I915_FLUSH_CACHE);
141bf215546Sopenharmony_ci}
142