1 /*
2 * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
43 * unsigned values.
44 * <p>
45 * <a id="optimizations">
46 * Note that some implementations may function more efficiently
47 * if they can maintain control over how the data for an image is
48 * stored.
49 * For example, optimizations such as caching an image in video
50 * memory require that the implementation track all modifications
51 * to that data.
52 * Other implementations may operate better if they can store the
53 * data in locations other than a Java array.
54 * To maintain optimum compatibility with various optimizations
55 * it is best to avoid constructors and methods which expose the
56 * underlying storage as a Java array, as noted below in the
57 * documentation for those methods.
58 * </a>
59 */
60 public final class DataBufferByte extends DataBuffer
61 {
62 /** The default data bank. */
63 byte data[];
64
65 /** All data banks */
66 byte bankdata[][];
67
68 /**
69 * Constructs a byte-based {@code DataBuffer} with a single bank and the
70 * specified size.
71 *
72 * @param size The size of the {@code DataBuffer}.
73 */
74 public DataBufferByte(int size) {
75 super(STABLE, TYPE_BYTE, size);
76 data = new byte[size];
77 bankdata = new byte[1][];
78 bankdata[0] = data;
79 }
80
81 /**
82 * Constructs a byte based {@code DataBuffer} with the specified number of
83 * banks all of which are the specified size.
84 *
85 * @param size The size of the banks in the {@code DataBuffer}.
86 * @param numBanks The number of banks in the a {@code DataBuffer}.
92 bankdata[i] = new byte[size];
93 }
94 data = bankdata[0];
95 }
96
97 /**
98 * Constructs a byte-based {@code DataBuffer} with a single bank using the
99 * specified array.
100 * Only the first {@code size} elements should be used by accessors of
101 * this {@code DataBuffer}. {@code dataArray} must be large enough to
102 * hold {@code size} elements.
103 * <p>
104 * Note that {@code DataBuffer} objects created by this constructor
105 * may be incompatible with <a href="#optimizations">performance
106 * optimizations</a> used by some implementations (such as caching
107 * an associated image in video memory).
108 *
109 * @param dataArray The byte array for the {@code DataBuffer}.
110 * @param size The size of the {@code DataBuffer} bank.
111 */
112 public DataBufferByte(byte dataArray[], int size) {
113 super(UNTRACKABLE, TYPE_BYTE, size);
114 data = dataArray;
115 bankdata = new byte[1][];
116 bankdata[0] = data;
117 }
118
119 /**
120 * Constructs a byte-based {@code DataBuffer} with a single bank using the
121 * specified array, size, and offset. {@code dataArray} must have at least
122 * {@code offset} + {@code size} elements. Only elements {@code offset}
123 * through {@code offset} + {@code size} - 1
124 * should be used by accessors of this {@code DataBuffer}.
125 * <p>
126 * Note that {@code DataBuffer} objects created by this constructor
127 * may be incompatible with <a href="#optimizations">performance
128 * optimizations</a> used by some implementations (such as caching
129 * an associated image in video memory).
130 *
131 * @param dataArray The byte array for the {@code DataBuffer}.
132 * @param size The size of the {@code DataBuffer} bank.
133 * @param offset The offset into the {@code dataArray}. {@code dataArray}
134 * must have at least {@code offset} + {@code size} elements.
135 */
136 public DataBufferByte(byte dataArray[], int size, int offset){
137 super(UNTRACKABLE, TYPE_BYTE, size, 1, offset);
138 data = dataArray;
139 bankdata = new byte[1][];
140 bankdata[0] = data;
141 }
142
143 /**
144 * Constructs a byte-based {@code DataBuffer} with the specified arrays.
145 * The number of banks is equal to {@code dataArray.length}.
146 * Only the first {@code size} elements of each array should be used by
147 * accessors of this {@code DataBuffer}.
148 * <p>
149 * Note that {@code DataBuffer} objects created by this constructor
150 * may be incompatible with <a href="#optimizations">performance
151 * optimizations</a> used by some implementations (such as caching
152 * an associated image in video memory).
153 *
154 * @param dataArray The byte arrays for the {@code DataBuffer}.
155 * @param size The size of the banks in the {@code DataBuffer}.
156 */
157 public DataBufferByte(byte dataArray[][], int size) {
158 super(UNTRACKABLE, TYPE_BYTE, size, dataArray.length);
159 bankdata = dataArray.clone();
160 data = bankdata[0];
161 }
162
163 /**
164 * Constructs a byte-based {@code DataBuffer} with the specified arrays, size,
165 * and offsets.
166 * The number of banks is equal to {@code dataArray.length}. Each array must
167 * be at least as large as {@code size} + the corresponding {@code offset}.
168 * There must be an entry in the {@code offset} array for each {@code dataArray}
169 * entry. For each bank, only elements {@code offset} through
170 * {@code offset} + {@code size} - 1 should be used by accessors of this
171 * {@code DataBuffer}.
172 * <p>
173 * Note that {@code DataBuffer} objects created by this constructor
174 * may be incompatible with <a href="#optimizations">performance
175 * optimizations</a> used by some implementations (such as caching
176 * an associated image in video memory).
177 *
178 * @param dataArray The byte arrays for the {@code DataBuffer}.
179 * @param size The size of the banks in the {@code DataBuffer}.
180 * @param offsets The offsets into each array.
181 */
182 public DataBufferByte(byte dataArray[][], int size, int offsets[]) {
183 super(UNTRACKABLE, TYPE_BYTE, size, dataArray.length, offsets);
184 bankdata = dataArray.clone();
185 data = bankdata[0];
186 }
187
188 /**
189 * Returns the default (first) byte data array.
190 * <p>
191 * Note that calling this method may cause this {@code DataBuffer}
192 * object to be incompatible with <a href="#optimizations">performance
193 * optimizations</a> used by some implementations (such as caching
194 * an associated image in video memory).
195 *
196 * @return The first byte data array.
197 */
198 public byte[] getData() {
199 theTrackable.setUntrackable();
200 return data;
201 }
202
|
1 /*
2 * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
43 * unsigned values.
44 * <p>
45 * <a id="optimizations">
46 * Note that some implementations may function more efficiently
47 * if they can maintain control over how the data for an image is
48 * stored.
49 * For example, optimizations such as caching an image in video
50 * memory require that the implementation track all modifications
51 * to that data.
52 * Other implementations may operate better if they can store the
53 * data in locations other than a Java array.
54 * To maintain optimum compatibility with various optimizations
55 * it is best to avoid constructors and methods which expose the
56 * underlying storage as a Java array, as noted below in the
57 * documentation for those methods.
58 * </a>
59 */
60 public final class DataBufferByte extends DataBuffer
61 {
62 /** The default data bank. */
63 byte[] data;
64
65 /** All data banks */
66 byte[][] bankdata;
67
68 /**
69 * Constructs a byte-based {@code DataBuffer} with a single bank and the
70 * specified size.
71 *
72 * @param size The size of the {@code DataBuffer}.
73 */
74 public DataBufferByte(int size) {
75 super(STABLE, TYPE_BYTE, size);
76 data = new byte[size];
77 bankdata = new byte[1][];
78 bankdata[0] = data;
79 }
80
81 /**
82 * Constructs a byte based {@code DataBuffer} with the specified number of
83 * banks all of which are the specified size.
84 *
85 * @param size The size of the banks in the {@code DataBuffer}.
86 * @param numBanks The number of banks in the a {@code DataBuffer}.
92 bankdata[i] = new byte[size];
93 }
94 data = bankdata[0];
95 }
96
97 /**
98 * Constructs a byte-based {@code DataBuffer} with a single bank using the
99 * specified array.
100 * Only the first {@code size} elements should be used by accessors of
101 * this {@code DataBuffer}. {@code dataArray} must be large enough to
102 * hold {@code size} elements.
103 * <p>
104 * Note that {@code DataBuffer} objects created by this constructor
105 * may be incompatible with <a href="#optimizations">performance
106 * optimizations</a> used by some implementations (such as caching
107 * an associated image in video memory).
108 *
109 * @param dataArray The byte array for the {@code DataBuffer}.
110 * @param size The size of the {@code DataBuffer} bank.
111 */
112 public DataBufferByte(byte[] dataArray, int size) {
113 super(UNTRACKABLE, TYPE_BYTE, size);
114 data = dataArray;
115 bankdata = new byte[1][];
116 bankdata[0] = data;
117 }
118
119 /**
120 * Constructs a byte-based {@code DataBuffer} with a single bank using the
121 * specified array, size, and offset. {@code dataArray} must have at least
122 * {@code offset} + {@code size} elements. Only elements {@code offset}
123 * through {@code offset} + {@code size} - 1
124 * should be used by accessors of this {@code DataBuffer}.
125 * <p>
126 * Note that {@code DataBuffer} objects created by this constructor
127 * may be incompatible with <a href="#optimizations">performance
128 * optimizations</a> used by some implementations (such as caching
129 * an associated image in video memory).
130 *
131 * @param dataArray The byte array for the {@code DataBuffer}.
132 * @param size The size of the {@code DataBuffer} bank.
133 * @param offset The offset into the {@code dataArray}. {@code dataArray}
134 * must have at least {@code offset} + {@code size} elements.
135 */
136 public DataBufferByte(byte[] dataArray, int size, int offset){
137 super(UNTRACKABLE, TYPE_BYTE, size, 1, offset);
138 data = dataArray;
139 bankdata = new byte[1][];
140 bankdata[0] = data;
141 }
142
143 /**
144 * Constructs a byte-based {@code DataBuffer} with the specified arrays.
145 * The number of banks is equal to {@code dataArray.length}.
146 * Only the first {@code size} elements of each array should be used by
147 * accessors of this {@code DataBuffer}.
148 * <p>
149 * Note that {@code DataBuffer} objects created by this constructor
150 * may be incompatible with <a href="#optimizations">performance
151 * optimizations</a> used by some implementations (such as caching
152 * an associated image in video memory).
153 *
154 * @param dataArray The byte arrays for the {@code DataBuffer}.
155 * @param size The size of the banks in the {@code DataBuffer}.
156 */
157 public DataBufferByte(byte[][] dataArray, int size) {
158 super(UNTRACKABLE, TYPE_BYTE, size, dataArray.length);
159 bankdata = dataArray.clone();
160 data = bankdata[0];
161 }
162
163 /**
164 * Constructs a byte-based {@code DataBuffer} with the specified arrays, size,
165 * and offsets.
166 * The number of banks is equal to {@code dataArray.length}. Each array must
167 * be at least as large as {@code size} + the corresponding {@code offset}.
168 * There must be an entry in the {@code offset} array for each {@code dataArray}
169 * entry. For each bank, only elements {@code offset} through
170 * {@code offset} + {@code size} - 1 should be used by accessors of this
171 * {@code DataBuffer}.
172 * <p>
173 * Note that {@code DataBuffer} objects created by this constructor
174 * may be incompatible with <a href="#optimizations">performance
175 * optimizations</a> used by some implementations (such as caching
176 * an associated image in video memory).
177 *
178 * @param dataArray The byte arrays for the {@code DataBuffer}.
179 * @param size The size of the banks in the {@code DataBuffer}.
180 * @param offsets The offsets into each array.
181 */
182 public DataBufferByte(byte[][] dataArray, int size, int[] offsets) {
183 super(UNTRACKABLE, TYPE_BYTE, size, dataArray.length, offsets);
184 bankdata = dataArray.clone();
185 data = bankdata[0];
186 }
187
188 /**
189 * Returns the default (first) byte data array.
190 * <p>
191 * Note that calling this method may cause this {@code DataBuffer}
192 * object to be incompatible with <a href="#optimizations">performance
193 * optimizations</a> used by some implementations (such as caching
194 * an associated image in video memory).
195 *
196 * @return The first byte data array.
197 */
198 public byte[] getData() {
199 theTrackable.setUntrackable();
200 return data;
201 }
202
|