|
1 /* |
|
2 * Copyright (c) 2000, 2013, Oracle and/or its affiliates. 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. Oracle designates this |
|
8 * particular file as subject to the "Classpath" exception as provided |
|
9 * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 * or visit www.oracle.com if you need additional information or have any |
|
23 * 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 */ |
|
36 JNIEXPORT void JNICALL |
|
37 Java_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 if (srcOps == 0) { |
|
64 return; |
|
65 } |
|
66 dstOps = SurfaceData_GetOps(env, dstData); |
|
67 if (dstOps == 0) { |
|
68 return; |
|
69 } |
|
70 |
|
71 srcInfo.bounds.x1 = srcx; |
|
72 srcInfo.bounds.y1 = srcy; |
|
73 srcInfo.bounds.x2 = srcx + width; |
|
74 srcInfo.bounds.y2 = srcy + height; |
|
75 dstInfo.bounds.x1 = dstx; |
|
76 dstInfo.bounds.y1 = dsty; |
|
77 dstInfo.bounds.x2 = dstx + width; |
|
78 dstInfo.bounds.y2 = dsty + height; |
|
79 srcx -= dstx; |
|
80 srcy -= dsty; |
|
81 SurfaceData_IntersectBounds(&dstInfo.bounds, &clipInfo.bounds); |
|
82 if (srcOps->Lock(env, srcOps, &srcInfo, pPrim->srcflags) != SD_SUCCESS) { |
|
83 return; |
|
84 } |
|
85 if (dstOps->Lock(env, dstOps, &dstInfo, pPrim->dstflags) != SD_SUCCESS) { |
|
86 SurfaceData_InvokeUnlock(env, srcOps, &srcInfo); |
|
87 return; |
|
88 } |
|
89 SurfaceData_IntersectBlitBounds(&dstInfo.bounds, &srcInfo.bounds, |
|
90 srcx, srcy); |
|
91 Region_IntersectBounds(&clipInfo, &dstInfo.bounds); |
|
92 |
|
93 if (!Region_IsEmpty(&clipInfo)) { |
|
94 srcOps->GetRasInfo(env, srcOps, &srcInfo); |
|
95 dstOps->GetRasInfo(env, dstOps, &dstInfo); |
|
96 if (srcInfo.rasBase && dstInfo.rasBase) { |
|
97 SurfaceDataBounds span; |
|
98 unsigned char *pMask = |
|
99 (maskArray |
|
100 ? (*env)->GetPrimitiveArrayCritical(env, maskArray, 0) |
|
101 : 0); |
|
102 jint savesx = srcInfo.bounds.x1; |
|
103 jint savedx = dstInfo.bounds.x1; |
|
104 if (maskArray != NULL && pMask == NULL) { |
|
105 SurfaceData_InvokeRelease(env, dstOps, &dstInfo); |
|
106 SurfaceData_InvokeRelease(env, srcOps, &srcInfo); |
|
107 SurfaceData_InvokeUnlock(env, dstOps, &dstInfo); |
|
108 SurfaceData_InvokeUnlock(env, srcOps, &srcInfo); |
|
109 return; |
|
110 } |
|
111 Region_StartIteration(env, &clipInfo); |
|
112 while (Region_NextIteration(&clipInfo, &span)) { |
|
113 void *pSrc = PtrCoord(srcInfo.rasBase, |
|
114 srcx + span.x1, srcInfo.pixelStride, |
|
115 srcy + span.y1, srcInfo.scanStride); |
|
116 void *pDst = PtrCoord(dstInfo.rasBase, |
|
117 span.x1, dstInfo.pixelStride, |
|
118 span.y1, dstInfo.scanStride); |
|
119 maskoff += ((span.y1 - dsty) * maskscan + (span.x1 - dstx)); |
|
120 /* |
|
121 * Fix for 4804375 |
|
122 * REMIND: There should probably be a better |
|
123 * way to give the span coordinates to the |
|
124 * inner loop. This is only really needed |
|
125 * for the 1, 2, and 4 bit loops. |
|
126 */ |
|
127 srcInfo.bounds.x1 = srcx + span.x1; |
|
128 dstInfo.bounds.x1 = span.x1; |
|
129 (*pPrim->funcs.maskblit)(pDst, pSrc, |
|
130 pMask, maskoff, maskscan, |
|
131 span.x2 - span.x1, span.y2 - span.y1, |
|
132 &dstInfo, &srcInfo, |
|
133 pPrim, &compInfo); |
|
134 } |
|
135 Region_EndIteration(env, &clipInfo); |
|
136 if (pMask) { |
|
137 (*env)->ReleasePrimitiveArrayCritical(env, maskArray, |
|
138 pMask, JNI_ABORT); |
|
139 } |
|
140 srcInfo.bounds.x1 = savesx; |
|
141 dstInfo.bounds.x1 = savedx; |
|
142 } |
|
143 SurfaceData_InvokeRelease(env, dstOps, &dstInfo); |
|
144 SurfaceData_InvokeRelease(env, srcOps, &srcInfo); |
|
145 } |
|
146 SurfaceData_InvokeUnlock(env, dstOps, &dstInfo); |
|
147 SurfaceData_InvokeUnlock(env, srcOps, &srcInfo); |
|
148 } |