blob: 57e1696351f3140c5fc00a096442368c7cb9c08f [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2000-2003 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26#include "GraphicsPrimitiveMgr.h"
27#include "Region.h"
28
29#include "sun_java2d_loops_MaskBlit.h"
30
31/*
32 * Class: sun_java2d_loops_MaskBlit
33 * Method: MaskBlit
34 * Signature: (Lsun/java2d/SurfaceData;Lsun/java2d/SurfaceData;Ljava/awt/Composite;IIIIII[BII)V
35 */
36JNIEXPORT void JNICALL
37Java_sun_java2d_loops_MaskBlit_MaskBlit
38 (JNIEnv *env, jobject self,
39 jobject srcData, jobject dstData, jobject comp, jobject clip,
40 jint srcx, jint srcy, jint dstx, jint dsty, jint width, jint height,
41 jbyteArray maskArray, jint maskoff, jint maskscan)
42{
43 SurfaceDataOps *srcOps;
44 SurfaceDataOps *dstOps;
45 SurfaceDataRasInfo srcInfo;
46 SurfaceDataRasInfo dstInfo;
47 NativePrimitive *pPrim;
48 CompositeInfo compInfo;
49 RegionData clipInfo;
50
51 pPrim = GetNativePrim(env, self);
52 if (pPrim == NULL) {
53 return;
54 }
55 if (pPrim->pCompType->getCompInfo != NULL) {
56 (*pPrim->pCompType->getCompInfo)(env, &compInfo, comp);
57 }
58 if (Region_GetInfo(env, clip, &clipInfo)) {
59 return;
60 }
61
62 srcOps = SurfaceData_GetOps(env, srcData);
63 dstOps = SurfaceData_GetOps(env, dstData);
64 if (srcOps == 0 || dstOps == 0) {
65 return;
66 }
67
68 srcInfo.bounds.x1 = srcx;
69 srcInfo.bounds.y1 = srcy;
70 srcInfo.bounds.x2 = srcx + width;
71 srcInfo.bounds.y2 = srcy + height;
72 dstInfo.bounds.x1 = dstx;
73 dstInfo.bounds.y1 = dsty;
74 dstInfo.bounds.x2 = dstx + width;
75 dstInfo.bounds.y2 = dsty + height;
76 srcx -= dstx;
77 srcy -= dsty;
78 SurfaceData_IntersectBounds(&dstInfo.bounds, &clipInfo.bounds);
79 if (srcOps->Lock(env, srcOps, &srcInfo, pPrim->srcflags) != SD_SUCCESS) {
80 return;
81 }
82 if (dstOps->Lock(env, dstOps, &dstInfo, pPrim->dstflags) != SD_SUCCESS) {
83 SurfaceData_InvokeUnlock(env, srcOps, &srcInfo);
84 return;
85 }
86 SurfaceData_IntersectBlitBounds(&dstInfo.bounds, &srcInfo.bounds,
87 srcx, srcy);
88 Region_IntersectBounds(&clipInfo, &dstInfo.bounds);
89
90 if (!Region_IsEmpty(&clipInfo)) {
91 srcOps->GetRasInfo(env, srcOps, &srcInfo);
92 dstOps->GetRasInfo(env, dstOps, &dstInfo);
93 if (srcInfo.rasBase && dstInfo.rasBase) {
94 SurfaceDataBounds span;
95 unsigned char *pMask =
96 (maskArray
97 ? (*env)->GetPrimitiveArrayCritical(env, maskArray, 0)
98 : 0);
99 jint savesx = srcInfo.bounds.x1;
100 jint savedx = dstInfo.bounds.x1;
101 Region_StartIteration(env, &clipInfo);
102 while (Region_NextIteration(&clipInfo, &span)) {
103 void *pSrc = PtrCoord(srcInfo.rasBase,
104 srcx + span.x1, srcInfo.pixelStride,
105 srcy + span.y1, srcInfo.scanStride);
106 void *pDst = PtrCoord(dstInfo.rasBase,
107 span.x1, dstInfo.pixelStride,
108 span.y1, dstInfo.scanStride);
109 maskoff += ((span.y1 - dsty) * maskscan + (span.x1 - dstx));
110 /*
111 * Fix for 4804375
112 * REMIND: There should probably be a better
113 * way to give the span coordinates to the
114 * inner loop. This is only really needed
115 * for the 1, 2, and 4 bit loops.
116 */
117 srcInfo.bounds.x1 = srcx + span.x1;
118 dstInfo.bounds.x1 = span.x1;
119 (*pPrim->funcs.maskblit)(pDst, pSrc,
120 pMask, maskoff, maskscan,
121 span.x2 - span.x1, span.y2 - span.y1,
122 &dstInfo, &srcInfo,
123 pPrim, &compInfo);
124 }
125 Region_EndIteration(env, &clipInfo);
126 if (pMask) {
127 (*env)->ReleasePrimitiveArrayCritical(env, maskArray,
128 pMask, JNI_ABORT);
129 }
130 srcInfo.bounds.x1 = savesx;
131 dstInfo.bounds.x1 = savedx;
132 }
133 SurfaceData_InvokeRelease(env, dstOps, &dstInfo);
134 SurfaceData_InvokeRelease(env, srcOps, &srcInfo);
135 }
136 SurfaceData_InvokeUnlock(env, dstOps, &dstInfo);
137 SurfaceData_InvokeUnlock(env, srcOps, &srcInfo);
138}