0N/A/*
2362N/A * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A#include <jni.h>
0N/A#include <jlong.h>
0N/A#include <jni_util.h>
0N/A#include "sun_java2d_pipe_BufferedRenderPipe.h"
0N/A#include "sun_java2d_pipe_BufferedOpCodes.h"
0N/A#include "SpanIterator.h"
0N/A#include "Trace.h"
0N/A
0N/A/* The "header" consists of a jint opcode and a jint span count value */
0N/A#define INTS_PER_HEADER 2
0N/A#define BYTES_PER_HEADER 8
0N/A
0N/A#define BYTES_PER_SPAN sun_java2d_pipe_BufferedRenderPipe_BYTES_PER_SPAN
0N/A
0N/AJNIEXPORT jint JNICALL
0N/AJava_sun_java2d_pipe_BufferedRenderPipe_fillSpans
0N/A (JNIEnv *env, jobject pipe,
0N/A jobject rq, jlong buf,
0N/A jint bpos, jint limit,
0N/A jobject si, jlong pIterator,
0N/A jint transx, jint transy)
0N/A{
0N/A SpanIteratorFuncs *pFuncs = (SpanIteratorFuncs *)jlong_to_ptr(pIterator);
0N/A void *srData;
0N/A jint spanbox[4];
0N/A jint spanCount = 0;
0N/A jint remainingBytes, remainingSpans;
0N/A unsigned char *bbuf;
0N/A jint *ibuf;
0N/A jint ipos;
0N/A
0N/A J2dTraceLn2(J2D_TRACE_INFO,
0N/A "BufferedRenderPipe_fillSpans: bpos=%d limit=%d",
0N/A bpos, limit);
0N/A
0N/A if (JNU_IsNull(env, rq)) {
0N/A J2dRlsTraceLn(J2D_TRACE_ERROR,
0N/A "BufferedRenderPipe_fillSpans: rq is null");
0N/A return bpos;
0N/A }
0N/A
0N/A if (JNU_IsNull(env, si)) {
0N/A J2dRlsTraceLn(J2D_TRACE_ERROR,
0N/A "BufferedRenderPipe_fillSpans: span iterator is null");
0N/A return bpos;
0N/A }
0N/A
0N/A if (pFuncs == NULL) {
0N/A J2dRlsTraceLn(J2D_TRACE_ERROR,
0N/A "BufferedRenderPipe_fillSpans: native iterator not supplied");
0N/A return bpos;
0N/A }
0N/A
0N/A bbuf = (unsigned char *)jlong_to_ptr(buf);
0N/A if (bbuf == NULL) {
0N/A J2dRlsTraceLn(J2D_TRACE_ERROR,
0N/A "BufferedRenderPipe_fillSpans: cannot get direct buffer address");
0N/A return bpos;
0N/A }
0N/A
0N/A // adjust the int pointer to the current buffer position
0N/A ibuf = (jint *)(bbuf + bpos);
0N/A
0N/A // start new operation
0N/A ibuf[0] = sun_java2d_pipe_BufferedOpCodes_FILL_SPANS;
0N/A ibuf[1] = 0; // placeholder for the span count
0N/A
0N/A // skip the opcode and span count
0N/A ipos = INTS_PER_HEADER;
0N/A bpos += BYTES_PER_HEADER; // skip the opcode and span count
0N/A
0N/A remainingBytes = limit - bpos;
0N/A remainingSpans = remainingBytes / BYTES_PER_SPAN;
0N/A
0N/A srData = (*pFuncs->open)(env, si);
0N/A while ((*pFuncs->nextSpan)(srData, spanbox)) {
0N/A if (remainingSpans == 0) {
0N/A // fill in span count
0N/A ibuf[1] = spanCount;
0N/A
0N/A // flush the queue
0N/A JNU_CallMethodByName(env, NULL, rq, "flushNow", "(I)V", bpos);
0N/A
0N/A // now start a new operation
0N/A ibuf = (jint *)bbuf;
0N/A ibuf[0] = sun_java2d_pipe_BufferedOpCodes_FILL_SPANS;
0N/A ibuf[1] = 0; // placeholder for the span count
0N/A
0N/A // skip the opcode and span count
0N/A ipos = INTS_PER_HEADER;
0N/A bpos = BYTES_PER_HEADER;
0N/A
0N/A // calculate new limits
0N/A remainingBytes = limit - bpos;
0N/A remainingSpans = remainingBytes / BYTES_PER_SPAN;
0N/A spanCount = 0;
0N/A }
0N/A
0N/A // enqueue span
0N/A ibuf[ipos++] = spanbox[0] + transx; // x1
0N/A ibuf[ipos++] = spanbox[1] + transy; // y1
0N/A ibuf[ipos++] = spanbox[2] + transx; // x2
0N/A ibuf[ipos++] = spanbox[3] + transy; // y2
0N/A
0N/A // update positions
0N/A bpos += BYTES_PER_SPAN;
0N/A spanCount++;
0N/A remainingSpans--;
0N/A }
0N/A (*pFuncs->close)(env, srData);
0N/A
0N/A // fill in span count
0N/A ibuf[1] = spanCount;
0N/A
0N/A // return the current byte position
0N/A return bpos;
0N/A}