1 /*
2 * Copyright (c) 2005, 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 <math.h>
27 #include <assert.h>
28 #include <stdlib.h>
29 #include <string.h>
30
31 #include "j2d_md.h"
32 #include "java_awt_geom_PathIterator.h"
33
34 #include "ProcessPath.h"
35
36 /*
37 * This framework performs filling and drawing of paths with sub-pixel
38 * precision. Also, it performs clipping by the specified view area.
39 *
40 * Drawing of the shapes is performed not pixel by pixel but segment by segment
41 * except several pixels near endpoints of the drawn line. This approach saves
42 * lot's of cpu cycles especially in case of large primitives (like ovals with
43 * sizes more than 50) and helps in achieving appropriate visual quality. Also,
44 * such method of drawing is useful for the accelerated pipelines where
45 * overhead of the per-pixel drawing could eliminate all benefits of the
46 * hardware acceleration.
47 *
48 * Filling of the path was taken from
49 *
50 * [Graphics Gems, edited by Andrew S Glassner. Academic Press 1990,
2160 }
2161
2162 FD_ADD_POINT(pfd, x2, y2, JNI_FALSE);
2163
2164 if (endSubPath) {
2165 FD_SET_ENDED(pfd);
2166 }
2167 }
2168
2169
2170 static void endSubPath(ProcessHandler* hnd) {
2171 FillData* pfd = (FillData*)(hnd->pData);
2172 if (!FD_IS_EMPTY(pfd)) {
2173 FD_SET_ENDED(pfd);
2174 }
2175 }
2176
2177 static void stubEndSubPath(ProcessHandler* hnd) {
2178 }
2179
2180 jboolean doFillPath(DrawHandler* dhnd,
2181 jint transX, jint transY,
2182 jfloat* coords, jint maxCoords,
2183 jbyte* types, jint numTypes,
2184 PHStroke stroke, jint fillRule)
2185 {
2186 jint res;
2187
2188 FillData fillData;
2189
2190 ProcessHandler hnd =
2191 {
2192 &StoreFixedLine,
2193 &endSubPath,
2194 NULL,
2195 PH_STROKE_DEFAULT,
2196 PH_MODE_FILL_CLIP,
2197 NULL
2198 };
2199
2200 /* Initialization of the following fields in the declaration of the hnd
2201 * above causes warnings on sun studio compiler with -xc99=%none option
2202 * applied (this option means compliance with C90 standard instead of C99)
2203 */
2204 hnd.dhnd = dhnd;
2205 hnd.pData = &fillData;
2206 hnd.stroke = stroke;
2207
2208 FD_INIT(&fillData);
2209 res = ProcessPath(&hnd, (jfloat)transX, (jfloat)transY,
2210 coords, maxCoords, types, numTypes);
2211 if (!res) {
2212 FD_FREE_POINTS(&fillData);
2213 return JNI_FALSE;
2214 }
2215 FillPolygon(&hnd, fillRule);
2216 FD_FREE_POINTS(&fillData);
2217 return JNI_TRUE;
2218 }
2219
2220 jboolean doDrawPath(DrawHandler* dhnd,
2221 void (*pProcessEndSubPath)(ProcessHandler*),
2222 jint transX, jint transY,
2223 jfloat* coords, jint maxCoords,
2224 jbyte* types, jint numTypes, PHStroke stroke)
2225 {
2226 ProcessHandler hnd =
2227 {
2228 &ProcessFixedLine,
2229 NULL,
2230 NULL,
2231 PH_STROKE_DEFAULT,
2232 PH_MODE_DRAW_CLIP,
2233 NULL
2234 };
2235
2236 /* Initialization of the following fields in the declaration of the hnd
2237 * above causes warnings on sun studio compiler with -xc99=%none option
2238 * applied (this option means compliance with C90 standard instead of C99)
2239 */
2240 hnd.dhnd = dhnd;
|
1 /*
2 * Copyright (c) 2005, 2018, 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 <math.h>
27 #include <assert.h>
28 #include <stdlib.h>
29 #include <string.h>
30
31 #include "jni.h"
32 #include "j2d_md.h"
33 #include "java_awt_geom_PathIterator.h"
34
35 #include "ProcessPath.h"
36
37 /*
38 * This framework performs filling and drawing of paths with sub-pixel
39 * precision. Also, it performs clipping by the specified view area.
40 *
41 * Drawing of the shapes is performed not pixel by pixel but segment by segment
42 * except several pixels near endpoints of the drawn line. This approach saves
43 * lot's of cpu cycles especially in case of large primitives (like ovals with
44 * sizes more than 50) and helps in achieving appropriate visual quality. Also,
45 * such method of drawing is useful for the accelerated pipelines where
46 * overhead of the per-pixel drawing could eliminate all benefits of the
47 * hardware acceleration.
48 *
49 * Filling of the path was taken from
50 *
51 * [Graphics Gems, edited by Andrew S Glassner. Academic Press 1990,
2161 }
2162
2163 FD_ADD_POINT(pfd, x2, y2, JNI_FALSE);
2164
2165 if (endSubPath) {
2166 FD_SET_ENDED(pfd);
2167 }
2168 }
2169
2170
2171 static void endSubPath(ProcessHandler* hnd) {
2172 FillData* pfd = (FillData*)(hnd->pData);
2173 if (!FD_IS_EMPTY(pfd)) {
2174 FD_SET_ENDED(pfd);
2175 }
2176 }
2177
2178 static void stubEndSubPath(ProcessHandler* hnd) {
2179 }
2180
2181 JNIEXPORT jboolean JNICALL
2182 doFillPath(DrawHandler* dhnd,
2183 jint transX, jint transY,
2184 jfloat* coords, jint maxCoords,
2185 jbyte* types, jint numTypes,
2186 PHStroke stroke, jint fillRule)
2187 {
2188 jint res;
2189
2190 FillData fillData;
2191
2192 ProcessHandler hnd =
2193 {
2194 &StoreFixedLine,
2195 &endSubPath,
2196 NULL,
2197 PH_STROKE_DEFAULT,
2198 PH_MODE_FILL_CLIP,
2199 NULL
2200 };
2201
2202 /* Initialization of the following fields in the declaration of the hnd
2203 * above causes warnings on sun studio compiler with -xc99=%none option
2204 * applied (this option means compliance with C90 standard instead of C99)
2205 */
2206 hnd.dhnd = dhnd;
2207 hnd.pData = &fillData;
2208 hnd.stroke = stroke;
2209
2210 FD_INIT(&fillData);
2211 res = ProcessPath(&hnd, (jfloat)transX, (jfloat)transY,
2212 coords, maxCoords, types, numTypes);
2213 if (!res) {
2214 FD_FREE_POINTS(&fillData);
2215 return JNI_FALSE;
2216 }
2217 FillPolygon(&hnd, fillRule);
2218 FD_FREE_POINTS(&fillData);
2219 return JNI_TRUE;
2220 }
2221
2222 JNIEXPORT jboolean JNICALL
2223 doDrawPath(DrawHandler* dhnd,
2224 void (*pProcessEndSubPath)(ProcessHandler*),
2225 jint transX, jint transY,
2226 jfloat* coords, jint maxCoords,
2227 jbyte* types, jint numTypes, PHStroke stroke)
2228 {
2229 ProcessHandler hnd =
2230 {
2231 &ProcessFixedLine,
2232 NULL,
2233 NULL,
2234 PH_STROKE_DEFAULT,
2235 PH_MODE_DRAW_CLIP,
2236 NULL
2237 };
2238
2239 /* Initialization of the following fields in the declaration of the hnd
2240 * above causes warnings on sun studio compiler with -xc99=%none option
2241 * applied (this option means compliance with C90 standard instead of C99)
2242 */
2243 hnd.dhnd = dhnd;
|