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