2 * Support for RENDER extension with rootless
5 * Copyright (c) 2002 Torrey T. Lyons. All Rights Reserved.
6 * Copyright (c) 2002 Apple Computer, Inc. All rights reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
22 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
26 * Except as contained in this notice, the name(s) of the above copyright
27 * holders shall not be used in advertising or otherwise to promote the sale,
28 * use or other dealings in this Software without prior written authorization.
30 /* This file is largely based on fbcompose.c and fbpict.c, which contain
31 * the following copyright:
33 * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc.
35 /* $XFree86: xc/programs/Xserver/hw/darwin/quartz/aquaPicture.c,v 1.3 2002/09/28 00:00:03 torrey Exp $ */
37 #define DEFAULT_LOG_FORMATS 0
42 #include "picturestr.h"
47 # define mod(a,b) ((b) == 1 ? 0 : (a) >= 0 ? (a) % (b) : (b) - (-a) % (b))
50 // Replacement for fbStore_x8r8g8b8 that sets the alpha channel
52 RootlessStore_x8r8g8b8 (FbCompositeOperand *op, CARD32 value)
54 FbBits *line = op->u.drawable.line; CARD32 offset = op->u.drawable.offset;
55 ((CARD32 *)line)[offset >> 5] = (value & 0xffffff) | 0xff000000;
59 // Defined in fbcompose.c
60 extern FbCombineFunc fbCombineFuncU[];
61 extern FbCombineFunc fbCombineFuncC[];
64 RootlessCompositeGeneral(
78 FbCompositeOperand src[4],msk[4],dst[4],*pmsk;
79 FbCompositeOperand *srcPict, *srcAlpha;
80 FbCompositeOperand *dstPict, *dstAlpha;
81 FbCompositeOperand *mskPict = 0, *mskAlpha = 0;
85 if (!fbBuildCompositeOperand (pSrc, src, xSrc, ySrc, TRUE, TRUE))
87 if (!fbBuildCompositeOperand (pDst, dst, xDst, yDst, FALSE, TRUE))
90 // Use Rootless operands for on screen picture formats
91 if (pDst->format == PICT_x8r8g8b8) {
92 dst[0].store = RootlessStore_x8r8g8b8;
115 f = fbCombineFuncU[op];
118 if (!fbBuildCompositeOperand (pMask, msk, xMask, yMask, TRUE, TRUE))
121 if (pMask->componentAlpha)
122 f = fbCombineFuncC[op];
142 (*f) (src, pmsk, dst);
146 (*pmsk->over) (pmsk);
151 (*pmsk->down) (pmsk);
155 static int rootless_log_pict_formats = DEFAULT_LOG_FORMATS;
157 static const char *op_name (int op)
159 static const char *ops[] = {
160 "Clear", "Src", "Dst", "Over", "OverReverse", "In", "InReverse",
161 "Out", "OutReverse", "Atop", "AtopReverse", "Xor", "Add",
162 "Saturate", "Maximum",
164 "DisjointClear", "DisjointSrc", "DisjointDst", "DisjointOver",
165 "DisjointOverReverse", "DisjointIn", "DisjointInReverse",
166 "DisjointOut", "DisjointOutReverse", "DisjointAtop",
167 "DisjointAtopReverse", "DisjointXor", "DisjointMaximum",
169 "ConjointClear", "ConjointSrc", "ConjointDst", "ConjointOver",
170 "ConjointOverReverse", "ConjointIn", "ConjointInReverse",
171 "ConjointOut", "ConjointOutReverse", "ConjointAtop",
172 "ConjointAtopReverse", "ConjointXor", "ConjointMaximum",
175 if (op >= 0 && op < (int) (sizeof (ops) / sizeof (ops[0])))
181 static const char *type_name (int type)
185 case PICT_TYPE_OTHER:
193 case PICT_TYPE_COLOR:
202 static void log_format (int op, unsigned int src,
203 unsigned int dst, unsigned int mask)
207 unsigned int src, dst, mask;
210 static struct op *ops;
211 static int n_ops, allocated_ops;
215 for (i = 0; i < n_ops; i++)
217 if (ops[i].op == op && ops[i].src == src
218 && ops[i].dst == dst && ops[i].mask == mask)
224 if (n_ops == allocated_ops)
227 ops = realloc (ops, allocated_ops * sizeof (struct op));
231 ops[n_ops].src = src;
232 ops[n_ops].dst = dst;
233 ops[n_ops].mask = mask;
237 "op: %s src (%dbpp %s %04x) dst (%dbpp %s %04x) mask (%dbpp %s %04x)\n",
238 op_name (op), PICT_FORMAT_BPP (src),
239 type_name (PICT_FORMAT_TYPE (src)),
240 src & 0xffff, PICT_FORMAT_BPP (dst),
241 type_name (PICT_FORMAT_TYPE (dst)),
242 dst & 0xffff, PICT_FORMAT_BPP (mask),
243 type_name (PICT_FORMAT_TYPE (mask)),
266 Bool srcRepeat = pSrc->repeat;
267 Bool maskRepeat = FALSE;
268 Bool srcAlphaMap = pSrc->alphaMap != 0;
269 Bool maskAlphaMap = FALSE;
270 Bool dstAlphaMap = pDst->alphaMap != 0;
271 int x_msk, y_msk, x_src, y_src, x_dst, y_dst;
272 int w, h, w_this, h_this;
273 int dstDepth = pDst->pDrawable->depth;
275 xDst += pDst->pDrawable->x;
276 yDst += pDst->pDrawable->y;
277 xSrc += pSrc->pDrawable->x;
278 ySrc += pSrc->pDrawable->y;
281 xMask += pMask->pDrawable->x;
282 yMask += pMask->pDrawable->y;
283 maskRepeat = pMask->repeat;
284 maskAlphaMap = pMask->alphaMap != 0;
287 if (rootless_log_pict_formats)
289 log_format (op, pSrc->format, pDst->format,
290 pMask != 0 ? pMask->format : 0);
293 if (!miComputeCompositeRegion (®ion,
307 if (pDst->pDrawable->type == DRAWABLE_WINDOW
308 && pDst->pDrawable->depth == 24
309 && pDst->pDrawable->bitsPerPixel == 32)
311 /* fbpict code sets bits above depth to zero. We don't want that! */
313 pDst->pDrawable->depth = 32;
316 func = RootlessCompositeGeneral;
318 if (!maskAlphaMap && !srcAlphaMap && !dstAlphaMap)
324 pSrc->pDrawable->width == 1 &&
325 pSrc->pDrawable->height == 1)
328 if (PICT_FORMAT_COLOR(pSrc->format)) {
329 switch (pMask->format) {
331 switch (pDst->format) {
334 func = fbCompositeSolidMask_nx8x0565;
338 func = fbCompositeSolidMask_nx8x0888;
344 func = fbCompositeSolidMask_nx8x8888;
349 if (pMask->componentAlpha) {
350 switch (pDst->format) {
353 func = fbCompositeSolidMask_nx8888x8888C;
356 func = fbCompositeSolidMask_nx8888x0565C;
362 if (pMask->componentAlpha) {
363 switch (pDst->format) {
366 func = fbCompositeSolidMask_nx8888x8888C;
369 func = fbCompositeSolidMask_nx8888x0565C;
375 switch (pDst->format) {
384 func = fbCompositeSolidMask_nx1xn;
393 switch (pSrc->format) {
396 switch (pDst->format) {
399 func = fbCompositeSrc_8888x8888;
402 func = fbCompositeSrc_8888x0888;
405 func = fbCompositeSrc_8888x0565;
411 switch (pDst->format) {
414 func = fbCompositeSrc_8888x8888;
417 func = fbCompositeSrc_8888x0888;
420 func = fbCompositeSrc_8888x0565;
425 switch (pDst->format) {
427 func = fbCompositeSrc_0565x0565;
432 switch (pDst->format) {
434 func = fbCompositeSrc_0565x0565;
444 switch (pSrc->format) {
446 switch (pDst->format) {
448 func = fbCompositeSrcAdd_8888x8888;
453 switch (pDst->format) {
455 func = fbCompositeSrcAdd_8888x8888;
460 switch (pDst->format) {
462 func = fbCompositeSrcAdd_8000x8000;
467 switch (pDst->format) {
469 func = fbCompositeSrcAdd_1000x1000;
478 n = REGION_NUM_RECTS (®ion);
479 pbox = REGION_RECTS (®ion);
482 h = pbox->y2 - pbox->y1;
483 y_src = pbox->y1 - yDst + ySrc;
484 y_msk = pbox->y1 - yDst + yMask;
489 w = pbox->x2 - pbox->x1;
490 x_src = pbox->x1 - xDst + xSrc;
491 x_msk = pbox->x1 - xDst + xMask;
495 y_msk = mod (y_msk, pMask->pDrawable->height);
496 if (h_this > pMask->pDrawable->height - y_msk)
497 h_this = pMask->pDrawable->height - y_msk;
501 y_src = mod (y_src, pSrc->pDrawable->height);
502 if (h_this > pSrc->pDrawable->height - y_src)
503 h_this = pSrc->pDrawable->height - y_src;
510 x_msk = mod (x_msk, pMask->pDrawable->width);
511 if (w_this > pMask->pDrawable->width - x_msk)
512 w_this = pMask->pDrawable->width - x_msk;
516 x_src = mod (x_src, pSrc->pDrawable->width);
517 if (w_this > pSrc->pDrawable->width - x_src)
518 w_this = pSrc->pDrawable->width - x_src;
520 (*func) (op, pSrc, pMask, pDst,
521 x_src, y_src, x_msk, y_msk, x_dst, y_dst,
535 REGION_UNINIT (pDst->pDrawable->pScreen, ®ion);
537 pDst->pDrawable->depth = dstDepth;