]> git.saurik.com Git - apple/xnu.git/blob - iokit/Families/IOGraphics/IOCursorBlits.h
xnu-124.13.tar.gz
[apple/xnu.git] / iokit / Families / IOGraphics / IOCursorBlits.h
1 /*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22
23 #define RBMASK 0xF0F0 /* Short, or 16 bit format */
24 #define GAMASK 0x0F0F /* Short, or 16 bit format */
25 #define AMASK 0x000F /* Short, or 16 bit format */
26
27 #if 1
28 #define short34to35WithGamma(x) \
29 ( (((x) & 0xf000) >> 1) \
30 | (((x) & 0x0f00) >> 2) \
31 | (((x) & 0x00f0) >> 3) \
32 | (((x) & 0x8000) >> 5) \
33 | (((x) & 0x0800) >> 6) \
34 | (((x) & 0x0080) >> 7) )
35
36 #define short35to34WithGamma(x) \
37 ( 0x000F \
38 | (((x) & 0x001e) << 3) \
39 | (((x) & 0x03c0) << 2) \
40 | (((x) & 0x7800) << 1) )
41 #else
42 #define short34to35WithGamma(x) \
43 ( (_bm34To35SampleTable[((x) & 0x00F0) >> 4]) \
44 | (_bm34To35SampleTable[((x) & 0x0F00) >> 8] << 5) \
45 | (_bm34To35SampleTable[(x) >> 12] << 10) )
46
47 #define short35to34WithGamma(x) \
48 ( 0x000F \
49 | (_bm35To34SampleTable[x & 0x001F] << 4) \
50 | (_bm35To34SampleTable[(x & 0x03E0) >> 5] << 8) \
51 | (_bm35To34SampleTable[(x & 0x7C00) >> 10] << 12) )
52 #endif
53
54 void IOFramebuffer::StdFBDisplayCursor555(
55 IOFramebuffer * inst,
56 StdFBShmem_t *shmem,
57 volatile unsigned short *vramPtr,
58 unsigned int cursStart,
59 unsigned int vramRow,
60 unsigned int cursRow,
61 int width,
62 int height )
63 {
64 int i, j;
65 volatile unsigned short *cursPtr;
66 volatile unsigned short *savePtr;
67 unsigned short s, d, f;
68 unsigned char *_bm34To35SampleTable;
69 unsigned char *_bm35To34SampleTable;
70
71 savePtr = (volatile unsigned short *) inst->cursorSave;
72 cursPtr = (volatile unsigned short *) inst->cursorImages[ shmem->frame ];
73 cursPtr += cursStart;
74
75 _bm34To35SampleTable = inst->colorConvert.t._bm34To35SampleTable;
76 _bm35To34SampleTable = inst->colorConvert.t._bm35To34SampleTable;
77
78 for (i = height; --i >= 0; ) {
79 for (j = width; --j >= 0; ) {
80 d = *savePtr++ = *vramPtr;
81 if ( (s = *cursPtr++) == 0 )
82 { /* Transparent black area. Leave dst as is. */
83 ++vramPtr;
84 continue;
85 }
86 if ( (f = (~s) & (unsigned int)AMASK) == 0 )
87 { /* Opaque cursor pixel. Mark it. */
88 *vramPtr++ = short34to35WithGamma(s);
89 continue;
90 }
91 if ((f == AMASK))
92 { /* Transparent non black cursor pixel. xor it. */
93 *vramPtr++ = d ^ short34to35WithGamma(s);
94 continue;
95 }
96 /* Alpha is not 0 or 1.0. Sover the cursor. */
97 d = short35to34WithGamma(d);
98 d = s + (((((d & RBMASK)>>4)*f + GAMASK) & RBMASK)
99 | ((((d & GAMASK)*f+GAMASK)>>4) & GAMASK));
100 *vramPtr++ = short34to35WithGamma(d);
101 }
102 cursPtr += cursRow; /* starting point of next cursor line */
103 vramPtr += vramRow; /* starting point of next screen line */
104 }
105 }
106
107 void IOFramebuffer::StdFBDisplayCursor444(
108 IOFramebuffer * inst,
109 StdFBShmem_t *shmem,
110 volatile unsigned short *vramPtr,
111 unsigned int cursStart,
112 unsigned int vramRow,
113 unsigned int cursRow,
114 int width,
115 int height )
116 {
117 int i, j;
118 volatile unsigned short *savePtr; /* saved screen data pointer */
119 volatile unsigned short *cursPtr;
120 unsigned short s, d, f;
121
122 savePtr = (volatile unsigned short *) inst->cursorSave;
123 cursPtr = (volatile unsigned short *) inst->cursorImages[ shmem->frame ];
124 cursPtr += cursStart;
125
126 for (i = height; --i >= 0; ) {
127 for (j = width; --j >= 0; ) {
128 d = *savePtr++ = *vramPtr;
129 if ( (s = *cursPtr++) == 0 )
130 { /* Transparent black area. Leave dst as is. */
131 ++vramPtr;
132 continue;
133 }
134 if ( (f = (~s) & (unsigned int)AMASK) == 0 )
135 { /* Opaque cursor pixel. Mark it. */
136 *vramPtr++ = s;
137 continue;
138 }
139 if ((f == AMASK))
140 { /* Transparent non black cursor pixel. xor it. */
141 *vramPtr++ = d ^ s;
142 continue;
143 }
144 /* Alpha is not 0 or 1.0. Sover the cursor. */
145 *vramPtr++ = s + (((((d & RBMASK)>>4)*f + GAMASK) & RBMASK)
146 | ((((d & GAMASK)*f+GAMASK)>>4) & GAMASK));
147 }
148 cursPtr += cursRow; /* starting point of next cursor line */
149 vramPtr += vramRow; /* starting point of next screen line */
150 }
151 }
152
153 static inline unsigned int MUL32(unsigned int a, unsigned int b)
154 {
155 unsigned int v, w;
156
157 v = ((a & 0xff00ff00) >> 8) * b;
158 v += ((v & 0xff00ff00) >> 8) + 0x00010001;
159 w = (a & 0x00ff00ff) * b;
160 w += ((w & 0xff00ff00) >> 8) + 0x00010001;
161
162 return (v & 0xff00ff00) | ((w >> 8) & 0x00ff00ff);
163 }
164
165 static inline unsigned char map32to256( unsigned char *directToLogical, unsigned int s)
166 {
167 unsigned char logicalValue;
168
169 if ((s ^ (s>>8)) & 0x00ffff00) {
170 logicalValue = directToLogical[(s>>24) + 0] +
171 directToLogical[((s>>16)&0xff) + 256] +
172 directToLogical[((s>>8)&0xff) + 512];
173 } else {
174 logicalValue = directToLogical[(s>>24) + 768];
175 }
176 // final conversion to actual palette
177 return( directToLogical[ logicalValue + 1024 ]);
178 }
179
180 void IOFramebuffer::StdFBDisplayCursor8P(
181 IOFramebuffer * inst,
182 StdFBShmem_t *shmem,
183 volatile unsigned char *vramPtr,
184 unsigned int cursStart,
185 unsigned int vramRow,
186 unsigned int cursRow,
187 int width,
188 int height )
189 {
190 int i, j;
191 volatile unsigned char *savePtr; /* saved screen data pointer */
192 volatile unsigned char *cursPtr;
193 unsigned char dst, src, alpha, white;
194 unsigned int rgb32val;
195 volatile unsigned char *maskPtr; /* cursor mask pointer */
196 unsigned int *_bm256To38SampleTable
197 = inst->colorConvert.t._bm256To38SampleTable;
198 unsigned char *_bm38To256SampleTable
199 = inst->colorConvert.t._bm38To256SampleTable;
200
201 savePtr = (volatile unsigned char *) inst->cursorSave;
202 cursPtr = (volatile unsigned char *) inst->cursorImages[ shmem->frame ];
203 maskPtr = (volatile unsigned char *) inst->cursorMasks[ shmem->frame ];
204 cursPtr += cursStart;
205 maskPtr += cursStart;
206
207 white = inst->white;
208 for (i = height; --i >= 0; ) {
209 for (j = width; --j >= 0; savePtr++,maskPtr++,cursPtr++,vramPtr++) {
210 dst = *savePtr = *vramPtr;
211 src = *cursPtr;
212 if ((alpha = *maskPtr)) {
213 if ((alpha = ~alpha)) {
214 rgb32val = _bm256To38SampleTable[dst];
215 rgb32val = (_bm256To38SampleTable[src] & ~0xff) +
216 MUL32(rgb32val, alpha);
217 *vramPtr = map32to256(_bm38To256SampleTable, rgb32val);
218 } else
219 *vramPtr = src;
220 } else if (src == white)
221 *vramPtr = map32to256(_bm38To256SampleTable,
222 _bm256To38SampleTable[dst] ^ 0xffffffff);
223 }
224 cursPtr += cursRow; /* starting point of next cursor line */
225 maskPtr += cursRow;
226 vramPtr += vramRow; /* starting point of next screen line */
227 }
228 }
229
230
231 void IOFramebuffer::StdFBDisplayCursor8G(
232 IOFramebuffer * inst,
233 StdFBShmem_t *shmem,
234 volatile unsigned char *vramPtr,
235 unsigned int cursStart,
236 unsigned int vramRow,
237 unsigned int cursRow,
238 int width,
239 int height )
240 {
241 int i, j;
242 volatile unsigned char *savePtr; /* saved screen data pointer */
243 unsigned short s, d, a;
244 volatile unsigned char *cursPtr;
245 volatile unsigned char *maskPtr; /* cursor mask pointer */
246
247 savePtr = (volatile unsigned char *) inst->cursorSave;
248 cursPtr = (volatile unsigned char *) inst->cursorImages[ shmem->frame ];
249 maskPtr = (volatile unsigned char *) inst->cursorMasks[ shmem->frame ];
250 cursPtr += cursStart;
251 maskPtr += cursStart;
252
253 for (i = height; --i >= 0; ) {
254 for (j = width; --j >= 0; ) {
255 int t;
256 d = *savePtr++ = *vramPtr;
257 s = *cursPtr++;
258 a = *maskPtr++;
259 if (a) {
260 t = d * (255 - *maskPtr++);
261 *vramPtr = s + ((t + (t >> 8) + 1) >> 8);
262 } else if (s)
263 *vramPtr = d ^ s;
264 vramPtr++;
265 }
266 cursPtr += cursRow; /* starting point of next cursor line */
267 maskPtr += cursRow;
268 vramPtr += vramRow; /* starting point of next screen line */
269 }
270 }
271
272 void IOFramebuffer::StdFBDisplayCursor32Axxx(
273 IOFramebuffer * inst,
274 StdFBShmem_t *shmem,
275 volatile unsigned int *vramPtr,
276 unsigned int cursStart,
277 unsigned int vramRow,
278 unsigned int cursRow,
279 int width,
280 int height )
281 {
282 int i, j;
283 volatile unsigned int *savePtr; /* saved screen data pointer */
284 unsigned int s, d, f;
285 volatile unsigned int *cursPtr;
286
287 savePtr = (volatile unsigned int *) inst->cursorSave;
288 cursPtr = (volatile unsigned int *) inst->cursorImages[ shmem->frame ];
289 cursPtr += cursStart;
290
291 /* Pixel format is Axxx */
292 for (i = height; --i >= 0; ) {
293 for (j = width; --j >= 0; ) {
294 d = *savePtr++ = *vramPtr;
295 s = *cursPtr++;
296 f = s >> 24;
297 if (f) {
298 if (f == 0xff) // Opaque pixel
299 *vramPtr++ = s;
300 else { // SOVER the cursor pixel
301 s <<= 8; d <<= 8; /* Now pixels are xxxA */
302 f ^= 0xFF;
303 d = s+(((((d&0xFF00FF00)>>8)*f+0x00FF00FF)&0xFF00FF00)
304 | ((((d & 0x00FF00FF)*f+0x00FF00FF)>>8) &
305 0x00FF00FF));
306 *vramPtr++ = (d>>8) | 0xff000000;
307 }
308 } else if (s) {
309 // Transparent non black cursor pixel. xor it.
310 *vramPtr++ = d ^ s;
311 continue;
312 } else // Transparent cursor pixel
313 vramPtr++;
314 }
315 cursPtr += cursRow; /* starting point of next cursor line */
316 vramPtr += vramRow; /* starting point of next screen line */
317 }
318 }
319
320 void IOFramebuffer::StdFBDisplayCursor32xxxA(
321 IOFramebuffer * inst,
322 StdFBShmem_t *shmem,
323 volatile unsigned int *vramPtr,
324 unsigned int cursStart,
325 unsigned int vramRow,
326 unsigned int cursRow,
327 int width,
328 int height )
329 {
330 int i, j;
331 volatile unsigned int *savePtr; /* saved screen data pointer */
332 unsigned int s, d, f;
333 volatile unsigned int *cursPtr;
334
335 savePtr = (volatile unsigned int *) inst->cursorSave;
336 cursPtr = (volatile unsigned int *) inst->cursorImages[ shmem->frame ];
337 cursPtr += cursStart;
338
339 /* Pixel format is xxxA */
340 for (i = height; --i >= 0; ) {
341 for (j = width; --j >= 0; ) {
342 d = *savePtr++ = *vramPtr;
343 s = *cursPtr++;
344 f = s & (unsigned int)0xFF;
345 if (f) {
346 if (f == 0xff) // Opaque pixel
347 *vramPtr++ = s;
348 else { // SOVER the cursor pixel
349 f ^= 0xFF;
350 d = s+(((((d&0xFF00FF00)>>8)*f+0x00FF00FF)&0xFF00FF00)
351 | ((((d & 0x00FF00FF)*f+0x00FF00FF)>>8) &
352 0x00FF00FF));
353 *vramPtr++ = d;
354 }
355 } else if (s) {
356 // Transparent non black cursor pixel. xor it.
357 *vramPtr++ = d ^ s;
358 continue;
359 } else // Transparent cursor pixel
360 vramPtr++;
361 }
362 cursPtr += cursRow; /* starting point of next cursor line */
363 vramPtr += vramRow; /* starting point of next screen line */
364 }
365 }
366
367 void IOFramebuffer::StdFBRemoveCursor16(
368 IOFramebuffer * inst,
369 StdFBShmem_t *shmem,
370 volatile unsigned short *vramPtr,
371 unsigned int vramRow,
372 int width,
373 int height )
374 {
375 int i, j;
376 volatile unsigned short *savePtr;
377
378 savePtr = (volatile unsigned short *) inst->cursorSave;
379
380 for (i = height; --i >= 0; ) {
381 for (j = width; --j >= 0; )
382 *vramPtr++ = *savePtr++;
383 vramPtr += vramRow;
384 }
385 }
386
387 void IOFramebuffer::StdFBRemoveCursor8(
388 IOFramebuffer * inst,
389 StdFBShmem_t *shmem,
390 volatile unsigned char *vramPtr,
391 unsigned int vramRow,
392 int width,
393 int height )
394 {
395 int i, j;
396 volatile unsigned char *savePtr;
397
398 savePtr = (volatile unsigned char *) inst->cursorSave;
399
400 for (i = height; --i >= 0; ) {
401 for (j = width; --j >= 0; )
402 *vramPtr++ = *savePtr++;
403 vramPtr += vramRow;
404 }
405 }
406
407 void IOFramebuffer::StdFBRemoveCursor32(
408 IOFramebuffer * inst,
409 StdFBShmem_t *shmem,
410 volatile unsigned int *vramPtr,
411 unsigned int vramRow,
412 int width,
413 int height )
414 {
415 int i, j;
416 volatile unsigned int *savePtr;
417
418 savePtr = (volatile unsigned int *) inst->cursorSave;
419
420 for (i = height; --i >= 0; ) {
421 for (j = width; --j >= 0; )
422 *vramPtr++ = *savePtr++;
423 vramPtr += vramRow;
424 }
425 }