Path: blob/master/src/java.desktop/macosx/classes/sun/java2d/DataBufferNIOInt.java
41152 views
/*1* Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.java2d;2627import java.awt.image.DataBuffer;28import java.nio.*;2930public final class DataBufferNIOInt extends DataBuffer {3132/** The default data bank. */33IntBuffer data;3435/** All data banks */36IntBuffer[] bankdata;3738/**39* Constructs an integer-based {@code DataBuffer} with a single bank40* and the specified size.41*42* @param size The size of the {@code DataBuffer}.43*/44public DataBufferNIOInt(int size) {45super(TYPE_INT,size);46//+++gdb how to get sizeof(int) in java? Using 4 for now.47data = getBufferOfSize(size * 4).asIntBuffer();48bankdata = new IntBuffer[1];49bankdata[0] = data;50}5152/**53* Returns the default (first) IntBuffer in {@code DataBuffer}.54*55* @return The first IntBuffer.56*/57public IntBuffer getBuffer() {58return data;59}6061/**62* Returns the Buffer for the specified bank.63*64* @param bank The bank whose Buffer you want to get.65* @return The Buffer for the specified bank.66*/67public IntBuffer getBuffer(int bank) {68return bankdata[bank];69}7071/**72* Returns the default (first) int data array in {@code DataBuffer}.73*74* @return The first integer data array.75*/76public int[] getData() {77return data.array();78}7980/**81* Returns the data array for the specified bank.82*83* @param bank The bank whose data array you want to get.84* @return The data array for the specified bank.85*/86public int[] getData(int bank) {87return bankdata[bank].array();88}8990/**91* Returns the data arrays for all banks.92* @return All of the data arrays.93*/94public int[][] getBankData() {95// Unsupported.96return null;97}9899/**100* Returns the requested data array element from the first (default) bank.101*102* @param i The data array element you want to get.103* @return The requested data array element as an integer.104* @see #setElem(int, int)105* @see #setElem(int, int, int)106*/107public int getElem(int i) {108return data.get(i+offset);109}110111/**112* Returns the requested data array element from the specified bank.113*114* @param bank The bank from which you want to get a data array element.115* @param i The data array element you want to get.116* @return The requested data array element as an integer.117* @see #setElem(int, int)118* @see #setElem(int, int, int)119*/120public int getElem(int bank, int i) {121return bankdata[bank].get(i+offsets[bank]);122}123124/**125* Sets the requested data array element in the first (default) bank126* to the specified value.127*128* @param i The data array element you want to set.129* @param val The integer value to which you want to set the data array element.130* @see #getElem(int)131* @see #getElem(int, int)132*/133public void setElem(int i, int val) {134data.put(i+offset, val);135}136137/**138* Sets the requested data array element in the specified bank139* to the integer value {@code i}.140* @param bank The bank in which you want to set the data array element.141* @param i The data array element you want to set.142* @param val The integer value to which you want to set the specified data array element.143* @see #getElem(int)144* @see #getElem(int, int)145*/146public void setElem(int bank, int i, int val) {147bankdata[bank].put(i+offsets[bank], val);148}149150ByteBuffer getBufferOfSize(int size)151{152ByteBuffer buffer = ByteBuffer.allocateDirect(size);153buffer.order(ByteOrder.nativeOrder());154return buffer;155}156}157158159