jdk/src/share/classes/sun/java2d/pipe/RenderBuffer.java
author erikj
Thu, 07 Jun 2012 18:05:09 -0700
changeset 12813 c10ab96dcf41
parent 7668 d4a77089c587
child 16734 da1901d79073
permissions -rw-r--r--
7170969: Add @GenerateNativeHeader to classes whose fields need to be exported for JNI Reviewed-by: ohair, ohrstrom, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
7668
d4a77089c587 6962318: Update copyright year
ohair
parents: 5580
diff changeset
     2
 * Copyright (c) 2005, 2010, 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: 2696
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: 2696
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: 2696
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2696
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2696
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
package sun.java2d.pipe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import sun.misc.Unsafe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
12813
c10ab96dcf41 7170969: Add @GenerateNativeHeader to classes whose fields need to be exported for JNI
erikj
parents: 7668
diff changeset
    30
import javax.tools.annotation.GenerateNativeHeader;
c10ab96dcf41 7170969: Add @GenerateNativeHeader to classes whose fields need to be exported for JNI
erikj
parents: 7668
diff changeset
    31
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * The RenderBuffer class is a simplified, high-performance, Unsafe wrapper
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * used for buffering rendering operations in a single-threaded rendering
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * environment.  It's functionality is similar to the ByteBuffer and related
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * NIO classes.  However, the methods in this class perform little to no
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * alignment or bounds checks for performance reasons.  Therefore, it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * the caller's responsibility to ensure that all put() calls are properly
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * aligned and within bounds:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *   - int and float values must be aligned on 4-byte boundaries
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *   - long and double values must be aligned on 8-byte boundaries
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * This class only includes the bare minimum of methods to support
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * single-threaded rendering.  For example, there is no put(double[]) method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * because we currently have no need for such a method in the STR classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 */
12813
c10ab96dcf41 7170969: Add @GenerateNativeHeader to classes whose fields need to be exported for JNI
erikj
parents: 7668
diff changeset
    47
/* No native methods here, but the constants are needed in the supporting JNI code */
c10ab96dcf41 7170969: Add @GenerateNativeHeader to classes whose fields need to be exported for JNI
erikj
parents: 7668
diff changeset
    48
@GenerateNativeHeader
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
public class RenderBuffer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * These constants represent the size of various data types (in bytes).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    protected static final long SIZEOF_BYTE   = 1L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    protected static final long SIZEOF_SHORT  = 2L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    protected static final long SIZEOF_INT    = 4L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    protected static final long SIZEOF_FLOAT  = 4L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    protected static final long SIZEOF_LONG   = 8L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    protected static final long SIZEOF_DOUBLE = 8L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * Represents the number of elements at which we have empirically
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * determined that the average cost of a JNI call exceeds the expense
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * of an element by element copy.  In other words, if the number of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * elements in an array to be copied exceeds this value, then we should
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * use the copyFromArray() method to complete the bulk put operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * (This value can be adjusted if the cost of JNI downcalls is reduced
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * in a future release.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     */
2696
1189480fe090 6827989: Use Unsafe.copyMemory for array->Unsafe copy operations in RenderBuffer
jgodinez
parents: 2
diff changeset
    70
    private static final int COPY_FROM_ARRAY_THRESHOLD = 6;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    protected final Unsafe unsafe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    protected final long baseAddress;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    protected final long endAddress;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    protected long curAddress;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    protected final int capacity;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    protected RenderBuffer(int numBytes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        unsafe = Unsafe.getUnsafe();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        curAddress = baseAddress = unsafe.allocateMemory(numBytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        endAddress = baseAddress + numBytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        capacity = numBytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * Allocates a fresh buffer using the machine endianness.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    public static RenderBuffer allocate(int numBytes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        return new RenderBuffer(numBytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * Returns the base address of the underlying memory buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    public final long getAddress() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        return baseAddress;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * The behavior (and names) of the following methods are nearly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * identical to their counterparts in the various NIO Buffer classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    public final int capacity() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        return capacity;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    public final int remaining() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        return (int)(endAddress - curAddress);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    public final int position() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        return (int)(curAddress - baseAddress);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    public final void position(long numBytes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        curAddress = baseAddress + numBytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    public final void clear() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        curAddress = baseAddress;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
5579
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 2696
diff changeset
   124
    public final RenderBuffer skip(long numBytes) {
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 2696
diff changeset
   125
        curAddress += numBytes;
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 2696
diff changeset
   126
        return this;
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 2696
diff changeset
   127
    }
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 2696
diff changeset
   128
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * putByte() methods...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    public final RenderBuffer putByte(byte x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        unsafe.putByte(curAddress, x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        curAddress += SIZEOF_BYTE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    public RenderBuffer put(byte[] x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        return put(x, 0, x.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    public RenderBuffer put(byte[] x, int offset, int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        if (length > COPY_FROM_ARRAY_THRESHOLD) {
2696
1189480fe090 6827989: Use Unsafe.copyMemory for array->Unsafe copy operations in RenderBuffer
jgodinez
parents: 2
diff changeset
   145
            long offsetInBytes = offset * SIZEOF_BYTE + Unsafe.ARRAY_BYTE_BASE_OFFSET;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            long lengthInBytes = length * SIZEOF_BYTE;
2696
1189480fe090 6827989: Use Unsafe.copyMemory for array->Unsafe copy operations in RenderBuffer
jgodinez
parents: 2
diff changeset
   147
            unsafe.copyMemory(x, offsetInBytes, null, curAddress, lengthInBytes);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            position(position() + lengthInBytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            int end = offset + length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            for (int i = offset; i < end; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                putByte(x[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * putShort() methods...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    public final RenderBuffer putShort(short x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        // assert (position() % SIZEOF_SHORT == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        unsafe.putShort(curAddress, x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        curAddress += SIZEOF_SHORT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    public RenderBuffer put(short[] x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        return put(x, 0, x.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    public RenderBuffer put(short[] x, int offset, int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        // assert (position() % SIZEOF_SHORT == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        if (length > COPY_FROM_ARRAY_THRESHOLD) {
2696
1189480fe090 6827989: Use Unsafe.copyMemory for array->Unsafe copy operations in RenderBuffer
jgodinez
parents: 2
diff changeset
   176
            long offsetInBytes = offset * SIZEOF_SHORT + Unsafe.ARRAY_SHORT_BASE_OFFSET;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            long lengthInBytes = length * SIZEOF_SHORT;
2696
1189480fe090 6827989: Use Unsafe.copyMemory for array->Unsafe copy operations in RenderBuffer
jgodinez
parents: 2
diff changeset
   178
            unsafe.copyMemory(x, offsetInBytes, null, curAddress, lengthInBytes);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            position(position() + lengthInBytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            int end = offset + length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            for (int i = offset; i < end; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                putShort(x[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * putInt() methods...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    public final RenderBuffer putInt(int pos, int x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        // assert (baseAddress + pos % SIZEOF_INT == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        unsafe.putInt(baseAddress + pos, x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    public final RenderBuffer putInt(int x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        // assert (position() % SIZEOF_INT == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        unsafe.putInt(curAddress, x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        curAddress += SIZEOF_INT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    public RenderBuffer put(int[] x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        return put(x, 0, x.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    public RenderBuffer put(int[] x, int offset, int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        // assert (position() % SIZEOF_INT == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        if (length > COPY_FROM_ARRAY_THRESHOLD) {
2696
1189480fe090 6827989: Use Unsafe.copyMemory for array->Unsafe copy operations in RenderBuffer
jgodinez
parents: 2
diff changeset
   213
            long offsetInBytes = offset * SIZEOF_INT + Unsafe.ARRAY_INT_BASE_OFFSET;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            long lengthInBytes = length * SIZEOF_INT;
2696
1189480fe090 6827989: Use Unsafe.copyMemory for array->Unsafe copy operations in RenderBuffer
jgodinez
parents: 2
diff changeset
   215
            unsafe.copyMemory(x, offsetInBytes, null, curAddress, lengthInBytes);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            position(position() + lengthInBytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            int end = offset + length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            for (int i = offset; i < end; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                putInt(x[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * putFloat() methods...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    public final RenderBuffer putFloat(float x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        // assert (position() % SIZEOF_FLOAT == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        unsafe.putFloat(curAddress, x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        curAddress += SIZEOF_FLOAT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    public RenderBuffer put(float[] x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        return put(x, 0, x.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    public RenderBuffer put(float[] x, int offset, int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        // assert (position() % SIZEOF_FLOAT == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        if (length > COPY_FROM_ARRAY_THRESHOLD) {
2696
1189480fe090 6827989: Use Unsafe.copyMemory for array->Unsafe copy operations in RenderBuffer
jgodinez
parents: 2
diff changeset
   244
            long offsetInBytes = offset * SIZEOF_FLOAT + Unsafe.ARRAY_FLOAT_BASE_OFFSET;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            long lengthInBytes = length * SIZEOF_FLOAT;
2696
1189480fe090 6827989: Use Unsafe.copyMemory for array->Unsafe copy operations in RenderBuffer
jgodinez
parents: 2
diff changeset
   246
            unsafe.copyMemory(x, offsetInBytes, null, curAddress, lengthInBytes);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            position(position() + lengthInBytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            int end = offset + length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            for (int i = offset; i < end; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                putFloat(x[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * putLong() methods...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    public final RenderBuffer putLong(long x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        // assert (position() % SIZEOF_LONG == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        unsafe.putLong(curAddress, x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        curAddress += SIZEOF_LONG;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    public RenderBuffer put(long[] x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        return put(x, 0, x.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    public RenderBuffer put(long[] x, int offset, int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        // assert (position() % SIZEOF_LONG == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        if (length > COPY_FROM_ARRAY_THRESHOLD) {
2696
1189480fe090 6827989: Use Unsafe.copyMemory for array->Unsafe copy operations in RenderBuffer
jgodinez
parents: 2
diff changeset
   275
            long offsetInBytes = offset * SIZEOF_LONG + Unsafe.ARRAY_LONG_BASE_OFFSET;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            long lengthInBytes = length * SIZEOF_LONG;
2696
1189480fe090 6827989: Use Unsafe.copyMemory for array->Unsafe copy operations in RenderBuffer
jgodinez
parents: 2
diff changeset
   277
            unsafe.copyMemory(x, offsetInBytes, null, curAddress, lengthInBytes);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            position(position() + lengthInBytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            int end = offset + length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            for (int i = offset; i < end; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                putLong(x[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * putDouble() method(s)...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    public final RenderBuffer putDouble(double x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        // assert (position() % SIZEOF_DOUBLE == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        unsafe.putDouble(curAddress, x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        curAddress += SIZEOF_DOUBLE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
}