4632N/A/*
4632N/A * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
4632N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4632N/A *
4632N/A * This code is free software; you can redistribute it and/or modify it
4632N/A * under the terms of the GNU General Public License version 2 only, as
4632N/A * published by the Free Software Foundation. Oracle designates this
4632N/A * particular file as subject to the "Classpath" exception as provided
4632N/A * by Oracle in the LICENSE file that accompanied this code.
4632N/A *
4632N/A * This code is distributed in the hope that it will be useful, but WITHOUT
4632N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4632N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4632N/A * version 2 for more details (a copy is included in the LICENSE file that
4632N/A * accompanied this code).
4632N/A *
4632N/A * You should have received a copy of the GNU General Public License version
4632N/A * 2 along with this work; if not, write to the Free Software Foundation,
4632N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4632N/A *
4632N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4632N/A * or visit www.oracle.com if you need additional information or have any
4632N/A * questions.
4632N/A */
4632N/A
4632N/Apackage sun.java2d;
4632N/A
4632N/Aimport java.awt.image.DataBuffer;
4632N/Aimport java.nio.*;
4632N/A
4632N/Apublic final class DataBufferNIOInt extends DataBuffer {
4632N/A
4632N/A /** The default data bank. */
4632N/A IntBuffer data;
4632N/A
4632N/A /** All data banks */
4632N/A IntBuffer bankdata[];
4632N/A
4632N/A /**
4632N/A * Constructs an integer-based <CODE>DataBuffer</CODE> with a single bank
4632N/A * and the specified size.
4632N/A *
4632N/A * @param size The size of the <CODE>DataBuffer</CODE>.
4632N/A */
4632N/A public DataBufferNIOInt(int size) {
4632N/A super(TYPE_INT,size);
4632N/A //+++gdb how to get sizeof(int) in java? Using 4 for now.
4632N/A data = getBufferOfSize(size * 4).asIntBuffer();
4632N/A bankdata = new IntBuffer[1];
4632N/A bankdata[0] = data;
4632N/A }
4632N/A
4632N/A /**
4632N/A * Returns the default (first) IntBuffer in <CODE>DataBuffer</CODE>.
4632N/A *
4632N/A * @return The first IntBuffer.
4632N/A */
4632N/A public IntBuffer getBuffer() {
4632N/A return data;
4632N/A }
4632N/A
4632N/A /**
4632N/A * Returns the Buffer for the specified bank.
4632N/A *
4632N/A * @param bank The bank whose Buffer you want to get.
4632N/A * @return The Buffer for the specified bank.
4632N/A */
4632N/A public IntBuffer getBuffer(int bank) {
4632N/A return bankdata[bank];
4632N/A }
4632N/A
4632N/A /**
4632N/A * Returns the default (first) int data array in <CODE>DataBuffer</CODE>.
4632N/A *
4632N/A * @return The first integer data array.
4632N/A */
4632N/A public int[] getData() {
4632N/A return data.array();
4632N/A }
4632N/A
4632N/A /**
4632N/A * Returns the data array for the specified bank.
4632N/A *
4632N/A * @param bank The bank whose data array you want to get.
4632N/A * @return The data array for the specified bank.
4632N/A */
4632N/A public int[] getData(int bank) {
4632N/A return bankdata[bank].array();
4632N/A }
4632N/A
4632N/A /**
4632N/A * Returns the data arrays for all banks.
4632N/A * @return All of the data arrays.
4632N/A */
4632N/A public int[][] getBankData() {
4632N/A // Unsupported.
4632N/A return null;
4632N/A }
4632N/A
4632N/A /**
4632N/A * Returns the requested data array element from the first (default) bank.
4632N/A *
4632N/A * @param i The data array element you want to get.
4632N/A * @return The requested data array element as an integer.
4632N/A * @see #setElem(int, int)
4632N/A * @see #setElem(int, int, int)
4632N/A */
4632N/A public int getElem(int i) {
4632N/A return data.get(i+offset);
4632N/A }
4632N/A
4632N/A /**
4632N/A * Returns the requested data array element from the specified bank.
4632N/A *
4632N/A * @param bank The bank from which you want to get a data array element.
4632N/A * @param i The data array element you want to get.
4632N/A * @return The requested data array element as an integer.
4632N/A * @see #setElem(int, int)
4632N/A * @see #setElem(int, int, int)
4632N/A */
4632N/A public int getElem(int bank, int i) {
4632N/A return bankdata[bank].get(i+offsets[bank]);
4632N/A }
4632N/A
4632N/A /**
4632N/A * Sets the requested data array element in the first (default) bank
4632N/A * to the specified value.
4632N/A *
4632N/A * @param i The data array element you want to set.
4632N/A * @param val The integer value to which you want to set the data array element.
4632N/A * @see #getElem(int)
4632N/A * @see #getElem(int, int)
4632N/A */
4632N/A public void setElem(int i, int val) {
4632N/A data.put(i+offset, val);
4632N/A }
4632N/A
4632N/A /**
4632N/A * Sets the requested data array element in the specified bank
4632N/A * to the integer value <CODE>i</CODE>.
4632N/A * @param bank The bank in which you want to set the data array element.
4632N/A * @param i The data array element you want to set.
4632N/A * @param val The integer value to which you want to set the specified data array element.
4632N/A * @see #getElem(int)
4632N/A * @see #getElem(int, int)
4632N/A */
4632N/A public void setElem(int bank, int i, int val) {
4632N/A bankdata[bank].put(i+offsets[bank], val);
4632N/A }
4632N/A
4632N/A ByteBuffer getBufferOfSize(int size)
4632N/A {
4632N/A ByteBuffer buffer = ByteBuffer.allocateDirect(size);
4632N/A buffer.order(ByteOrder.nativeOrder());
4632N/A return buffer;
4632N/A }
4632N/A}