Path: blob/master/src/java.desktop/share/native/libawt/java2d/pipe/BufferedRenderPipe.c
41159 views
/*1* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425#include <jni.h>26#include <jlong.h>27#include <jni_util.h>28#include "sun_java2d_pipe_BufferedRenderPipe.h"29#include "sun_java2d_pipe_BufferedOpCodes.h"30#include "SpanIterator.h"31#include "Trace.h"3233/* The "header" consists of a jint opcode and a jint span count value */34#define INTS_PER_HEADER 235#define BYTES_PER_HEADER 83637#define BYTES_PER_SPAN sun_java2d_pipe_BufferedRenderPipe_BYTES_PER_SPAN3839JNIEXPORT jint JNICALL40Java_sun_java2d_pipe_BufferedRenderPipe_fillSpans41(JNIEnv *env, jobject pipe,42jobject rq, jlong buf,43jint bpos, jint limit,44jobject si, jlong pIterator,45jint transx, jint transy)46{47SpanIteratorFuncs *pFuncs = (SpanIteratorFuncs *)jlong_to_ptr(pIterator);48void *srData;49jint spanbox[4];50jint spanCount = 0;51jint remainingBytes, remainingSpans;52unsigned char *bbuf;53jint *ibuf;54jint ipos;55jboolean hasException;5657J2dTraceLn2(J2D_TRACE_INFO,58"BufferedRenderPipe_fillSpans: bpos=%d limit=%d",59bpos, limit);6061if (JNU_IsNull(env, rq)) {62J2dRlsTraceLn(J2D_TRACE_ERROR,63"BufferedRenderPipe_fillSpans: rq is null");64return bpos;65}6667if (JNU_IsNull(env, si)) {68J2dRlsTraceLn(J2D_TRACE_ERROR,69"BufferedRenderPipe_fillSpans: span iterator is null");70return bpos;71}7273if (pFuncs == NULL) {74J2dRlsTraceLn(J2D_TRACE_ERROR,75"BufferedRenderPipe_fillSpans: native iterator not supplied");76return bpos;77}7879bbuf = (unsigned char *)jlong_to_ptr(buf);80if (bbuf == NULL) {81J2dRlsTraceLn(J2D_TRACE_ERROR,82"BufferedRenderPipe_fillSpans: cannot get direct buffer address");83return bpos;84}8586// adjust the int pointer to the current buffer position87ibuf = (jint *)(bbuf + bpos);8889// start new operation90ibuf[0] = sun_java2d_pipe_BufferedOpCodes_FILL_SPANS;91ibuf[1] = 0; // placeholder for the span count9293// skip the opcode and span count94ipos = INTS_PER_HEADER;95bpos += BYTES_PER_HEADER; // skip the opcode and span count9697remainingBytes = limit - bpos;98remainingSpans = remainingBytes / BYTES_PER_SPAN;99100srData = (*pFuncs->open)(env, si);101while ((*pFuncs->nextSpan)(srData, spanbox)) {102if (remainingSpans == 0) {103// fill in span count104ibuf[1] = spanCount;105106// flush the queue107JNU_CallMethodByName(env, &hasException, rq, "flushNow", "(I)V", bpos);108if (hasException) {109break;110}111112// now start a new operation113ibuf = (jint *)bbuf;114ibuf[0] = sun_java2d_pipe_BufferedOpCodes_FILL_SPANS;115ibuf[1] = 0; // placeholder for the span count116117// skip the opcode and span count118ipos = INTS_PER_HEADER;119bpos = BYTES_PER_HEADER;120121// calculate new limits122remainingBytes = limit - bpos;123remainingSpans = remainingBytes / BYTES_PER_SPAN;124spanCount = 0;125}126127// enqueue span128ibuf[ipos++] = spanbox[0] + transx; // x1129ibuf[ipos++] = spanbox[1] + transy; // y1130ibuf[ipos++] = spanbox[2] + transx; // x2131ibuf[ipos++] = spanbox[3] + transy; // y2132133// update positions134bpos += BYTES_PER_SPAN;135spanCount++;136remainingSpans--;137}138(*pFuncs->close)(env, srData);139140// fill in span count141ibuf[1] = spanCount;142143// return the current byte position144return bpos;145}146147148