jdk/src/share/native/sun/java2d/pipe/BufferedRenderPipe.c
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 2 90ce3da70b43
child 20423 23b2db6ffff4
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#include <jni.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include <jlong.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include <jni_util.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include "sun_java2d_pipe_BufferedRenderPipe.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include "sun_java2d_pipe_BufferedOpCodes.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include "SpanIterator.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include "Trace.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/* The "header" consists of a jint opcode and a jint span count value */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#define INTS_PER_HEADER  2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
#define BYTES_PER_HEADER 8
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
#define BYTES_PER_SPAN sun_java2d_pipe_BufferedRenderPipe_BYTES_PER_SPAN
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
JNIEXPORT jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
Java_sun_java2d_pipe_BufferedRenderPipe_fillSpans
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    (JNIEnv *env, jobject pipe,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
     jobject rq, jlong buf,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
     jint bpos, jint limit,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
     jobject si, jlong pIterator,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     jint transx, jint transy)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    SpanIteratorFuncs *pFuncs = (SpanIteratorFuncs *)jlong_to_ptr(pIterator);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    void *srData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    jint spanbox[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    jint spanCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    jint remainingBytes, remainingSpans;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    unsigned char *bbuf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    jint *ibuf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    jint ipos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    J2dTraceLn2(J2D_TRACE_INFO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
                "BufferedRenderPipe_fillSpans: bpos=%d limit=%d",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
                bpos, limit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    if (JNU_IsNull(env, rq)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            "BufferedRenderPipe_fillSpans: rq is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        return bpos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    if (JNU_IsNull(env, si)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            "BufferedRenderPipe_fillSpans: span iterator is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        return bpos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    if (pFuncs == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            "BufferedRenderPipe_fillSpans: native iterator not supplied");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        return bpos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    bbuf = (unsigned char *)jlong_to_ptr(buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    if (bbuf == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            "BufferedRenderPipe_fillSpans: cannot get direct buffer address");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        return bpos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    // adjust the int pointer to the current buffer position
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    ibuf = (jint *)(bbuf + bpos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    // start new operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    ibuf[0] = sun_java2d_pipe_BufferedOpCodes_FILL_SPANS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    ibuf[1] = 0; // placeholder for the span count
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    // skip the opcode and span count
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    ipos = INTS_PER_HEADER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    bpos += BYTES_PER_HEADER; // skip the opcode and span count
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    remainingBytes = limit - bpos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    remainingSpans = remainingBytes / BYTES_PER_SPAN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    srData = (*pFuncs->open)(env, si);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    while ((*pFuncs->nextSpan)(srData, spanbox)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        if (remainingSpans == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            // fill in span count
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            ibuf[1] = spanCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            // flush the queue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            JNU_CallMethodByName(env, NULL, rq, "flushNow", "(I)V", bpos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            // now start a new operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            ibuf = (jint *)bbuf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            ibuf[0] = sun_java2d_pipe_BufferedOpCodes_FILL_SPANS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            ibuf[1] = 0; // placeholder for the span count
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            // skip the opcode and span count
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            ipos = INTS_PER_HEADER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            bpos = BYTES_PER_HEADER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            // calculate new limits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            remainingBytes = limit - bpos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            remainingSpans = remainingBytes / BYTES_PER_SPAN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            spanCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        // enqueue span
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        ibuf[ipos++] = spanbox[0] + transx; // x1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        ibuf[ipos++] = spanbox[1] + transy; // y1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        ibuf[ipos++] = spanbox[2] + transx; // x2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        ibuf[ipos++] = spanbox[3] + transy; // y2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        // update positions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        bpos += BYTES_PER_SPAN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        spanCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        remainingSpans--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    (*pFuncs->close)(env, srData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    // fill in span count
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    ibuf[1] = spanCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    // return the current byte position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    return bpos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
}