2
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
|
2
|
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
|
5506
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
2
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
5506
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
2
|
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 |
*
|
5506
|
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.
|
2
|
24 |
*/
|
|
25 |
|
|
26 |
#include <jni.h>
|
|
27 |
#include <jlong.h>
|
|
28 |
#include <jni_util.h>
|
|
29 |
#include "sun_java2d_pipe_BufferedRenderPipe.h"
|
|
30 |
#include "sun_java2d_pipe_BufferedOpCodes.h"
|
|
31 |
#include "SpanIterator.h"
|
|
32 |
#include "Trace.h"
|
|
33 |
|
|
34 |
/* The "header" consists of a jint opcode and a jint span count value */
|
|
35 |
#define INTS_PER_HEADER 2
|
|
36 |
#define BYTES_PER_HEADER 8
|
|
37 |
|
|
38 |
#define BYTES_PER_SPAN sun_java2d_pipe_BufferedRenderPipe_BYTES_PER_SPAN
|
|
39 |
|
|
40 |
JNIEXPORT jint JNICALL
|
|
41 |
Java_sun_java2d_pipe_BufferedRenderPipe_fillSpans
|
|
42 |
(JNIEnv *env, jobject pipe,
|
|
43 |
jobject rq, jlong buf,
|
|
44 |
jint bpos, jint limit,
|
|
45 |
jobject si, jlong pIterator,
|
|
46 |
jint transx, jint transy)
|
|
47 |
{
|
|
48 |
SpanIteratorFuncs *pFuncs = (SpanIteratorFuncs *)jlong_to_ptr(pIterator);
|
|
49 |
void *srData;
|
|
50 |
jint spanbox[4];
|
|
51 |
jint spanCount = 0;
|
|
52 |
jint remainingBytes, remainingSpans;
|
|
53 |
unsigned char *bbuf;
|
|
54 |
jint *ibuf;
|
|
55 |
jint ipos;
|
|
56 |
|
|
57 |
J2dTraceLn2(J2D_TRACE_INFO,
|
|
58 |
"BufferedRenderPipe_fillSpans: bpos=%d limit=%d",
|
|
59 |
bpos, limit);
|
|
60 |
|
|
61 |
if (JNU_IsNull(env, rq)) {
|
|
62 |
J2dRlsTraceLn(J2D_TRACE_ERROR,
|
|
63 |
"BufferedRenderPipe_fillSpans: rq is null");
|
|
64 |
return bpos;
|
|
65 |
}
|
|
66 |
|
|
67 |
if (JNU_IsNull(env, si)) {
|
|
68 |
J2dRlsTraceLn(J2D_TRACE_ERROR,
|
|
69 |
"BufferedRenderPipe_fillSpans: span iterator is null");
|
|
70 |
return bpos;
|
|
71 |
}
|
|
72 |
|
|
73 |
if (pFuncs == NULL) {
|
|
74 |
J2dRlsTraceLn(J2D_TRACE_ERROR,
|
|
75 |
"BufferedRenderPipe_fillSpans: native iterator not supplied");
|
|
76 |
return bpos;
|
|
77 |
}
|
|
78 |
|
|
79 |
bbuf = (unsigned char *)jlong_to_ptr(buf);
|
|
80 |
if (bbuf == NULL) {
|
|
81 |
J2dRlsTraceLn(J2D_TRACE_ERROR,
|
|
82 |
"BufferedRenderPipe_fillSpans: cannot get direct buffer address");
|
|
83 |
return bpos;
|
|
84 |
}
|
|
85 |
|
|
86 |
// adjust the int pointer to the current buffer position
|
|
87 |
ibuf = (jint *)(bbuf + bpos);
|
|
88 |
|
|
89 |
// start new operation
|
|
90 |
ibuf[0] = sun_java2d_pipe_BufferedOpCodes_FILL_SPANS;
|
|
91 |
ibuf[1] = 0; // placeholder for the span count
|
|
92 |
|
|
93 |
// skip the opcode and span count
|
|
94 |
ipos = INTS_PER_HEADER;
|
|
95 |
bpos += BYTES_PER_HEADER; // skip the opcode and span count
|
|
96 |
|
|
97 |
remainingBytes = limit - bpos;
|
|
98 |
remainingSpans = remainingBytes / BYTES_PER_SPAN;
|
|
99 |
|
|
100 |
srData = (*pFuncs->open)(env, si);
|
|
101 |
while ((*pFuncs->nextSpan)(srData, spanbox)) {
|
|
102 |
if (remainingSpans == 0) {
|
|
103 |
// fill in span count
|
|
104 |
ibuf[1] = spanCount;
|
|
105 |
|
|
106 |
// flush the queue
|
|
107 |
JNU_CallMethodByName(env, NULL, rq, "flushNow", "(I)V", bpos);
|
|
108 |
|
|
109 |
// now start a new operation
|
|
110 |
ibuf = (jint *)bbuf;
|
|
111 |
ibuf[0] = sun_java2d_pipe_BufferedOpCodes_FILL_SPANS;
|
|
112 |
ibuf[1] = 0; // placeholder for the span count
|
|
113 |
|
|
114 |
// skip the opcode and span count
|
|
115 |
ipos = INTS_PER_HEADER;
|
|
116 |
bpos = BYTES_PER_HEADER;
|
|
117 |
|
|
118 |
// calculate new limits
|
|
119 |
remainingBytes = limit - bpos;
|
|
120 |
remainingSpans = remainingBytes / BYTES_PER_SPAN;
|
|
121 |
spanCount = 0;
|
|
122 |
}
|
|
123 |
|
|
124 |
// enqueue span
|
|
125 |
ibuf[ipos++] = spanbox[0] + transx; // x1
|
|
126 |
ibuf[ipos++] = spanbox[1] + transy; // y1
|
|
127 |
ibuf[ipos++] = spanbox[2] + transx; // x2
|
|
128 |
ibuf[ipos++] = spanbox[3] + transy; // y2
|
|
129 |
|
|
130 |
// update positions
|
|
131 |
bpos += BYTES_PER_SPAN;
|
|
132 |
spanCount++;
|
|
133 |
remainingSpans--;
|
|
134 |
}
|
|
135 |
(*pFuncs->close)(env, srData);
|
|
136 |
|
|
137 |
// fill in span count
|
|
138 |
ibuf[1] = spanCount;
|
|
139 |
|
|
140 |
// return the current byte position
|
|
141 |
return bpos;
|
|
142 |
}
|