jdk/src/share/native/sun/java2d/pipe/RenderBuffer.c
changeset 2843 cc43f23731cc
parent 2842 1a14159efe64
parent 2726 d60a9ce3c3ea
child 2844 e7ca0be66640
equal deleted inserted replaced
2842:1a14159efe64 2843:cc43f23731cc
     1 /*
       
     2  * Copyright 2005 Sun Microsystems, Inc.  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.  Sun designates this
       
     8  * particular file as subject to the "Classpath" exception as provided
       
     9  * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
       
    22  * CA 95054 USA or visit www.sun.com if you need additional information or
       
    23  * have any questions.
       
    24  */
       
    25 
       
    26 #include "jni.h"
       
    27 #include "jni_util.h"
       
    28 #include "jlong.h"
       
    29 #include <string.h>
       
    30 
       
    31 #include "sun_java2d_pipe_RenderBuffer.h"
       
    32 
       
    33 /**
       
    34  * Note: The code in this file is nearly identical to that in
       
    35  *       java/nio/Bits.c...
       
    36  */
       
    37 
       
    38 #define MBYTE 1048576
       
    39 
       
    40 JNIEXPORT void JNICALL
       
    41 Java_sun_java2d_pipe_RenderBuffer_copyFromArray
       
    42     (JNIEnv *env, jclass rb,
       
    43      jobject srcArray, jlong srcPos, jlong dstAddr, jlong length)
       
    44 {
       
    45     jbyte *bytes;
       
    46     size_t size;
       
    47 
       
    48     while (length > 0) {
       
    49         /*
       
    50          * Copy no more than one megabyte at a time, to allow for GC.
       
    51          * (Probably not an issue for STR, since our buffer size is likely
       
    52          * much smaller than a megabyte, but just in case...)
       
    53          */
       
    54         size = (size_t)(length > MBYTE ? MBYTE : length);
       
    55 
       
    56         bytes = (*env)->GetPrimitiveArrayCritical(env, srcArray, NULL);
       
    57         if (bytes == NULL) {
       
    58             JNU_ThrowInternalError(env, "Unable to get array");
       
    59             return;
       
    60         }
       
    61 
       
    62         memcpy(jlong_to_ptr(dstAddr), bytes + srcPos, size);
       
    63 
       
    64         (*env)->ReleasePrimitiveArrayCritical(env, srcArray,
       
    65                                               bytes, JNI_ABORT);
       
    66 
       
    67         length -= size;
       
    68         dstAddr += size;
       
    69         srcPos += size;
       
    70     }
       
    71 }