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