1 /*
2  * Copyright (c) 2000, 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 "jni_util.h"
27 #include "jlong.h"
28 
29 #include "sun_java2d_loops_FillSpans.h"
30 
31 #include "GraphicsPrimitiveMgr.h"
32 
33 /*
34  * Class:     sun_java2d_loops_FillSpans
35  * Method:    FillSpans
36  * Signature: (Lsun/java2d/SunGraphics2D;Lsun/java2d/SurfaceData;Lsun/java2d/pipe/SpanIterator;)V
37  */
38 JNIEXPORT void JNICALL
Java_sun_java2d_loops_FillSpans_FillSpans(JNIEnv * env,jobject self,jobject sg2d,jobject sData,jint pixel,jlong pIterator,jobject si)39 Java_sun_java2d_loops_FillSpans_FillSpans
40     (JNIEnv *env, jobject self,
41      jobject sg2d, jobject sData, jint pixel, jlong pIterator, jobject si)
42 {
43     SpanIteratorFuncs *pSpanFuncs;
44     SurfaceDataOps *sdOps;
45     SurfaceDataRasInfo rasInfo;
46     void *siData;
47     jint bbox[4];
48     NativePrimitive *pPrim;
49     CompositeInfo compInfo;
50 
51     pSpanFuncs = (SpanIteratorFuncs *) jlong_to_ptr(pIterator);
52     if (pSpanFuncs == NULL) {
53         JNU_ThrowNullPointerException(env, "native iterator not supplied");
54         return;
55     }
56 
57     pPrim = GetNativePrim(env, self);
58     if (pPrim == NULL) {
59         return;
60     }
61     if (pPrim->pCompType->getCompInfo != NULL) {
62         GrPrim_Sg2dGetCompInfo(env, sg2d, pPrim, &compInfo);
63     }
64 
65     sdOps = SurfaceData_GetOps(env, sData);
66     if (sdOps == NULL) {
67         return;
68     }
69 
70     siData = (*pSpanFuncs->open)(env, si);
71 
72     (*pSpanFuncs->getPathBox)(env, siData, bbox);
73     rasInfo.bounds.x1 = bbox[0];
74     rasInfo.bounds.y1 = bbox[1];
75     rasInfo.bounds.x2 = bbox[2];
76     rasInfo.bounds.y2 = bbox[3];
77 
78     if (sdOps->Lock(env, sdOps, &rasInfo, pPrim->dstflags) != SD_SUCCESS) {
79         /* Lock threw an exception */
80         (*pSpanFuncs->close)(env, siData);
81         return;
82     }
83     (*pSpanFuncs->intersectClipBox)(env, siData,
84                                     rasInfo.bounds.x1,
85                                     rasInfo.bounds.y1,
86                                     rasInfo.bounds.x2,
87                                     rasInfo.bounds.y2);
88 
89     sdOps->GetRasInfo(env, sdOps, &rasInfo);
90     /* Protect against silent failure of GetRasInfo */
91     if (rasInfo.rasBase != NULL) {
92         pPrim->funcs.fillspans(&rasInfo, pSpanFuncs, siData,
93                                pixel, pPrim, &compInfo);
94     }
95 
96     SurfaceData_InvokeRelease(env, sdOps, &rasInfo);
97     (*pSpanFuncs->close)(env, siData);
98     SurfaceData_InvokeUnlock(env, sdOps, &rasInfo);
99 }
100