1 /*
2 * Copyright (c) 2011, 2015, 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
29 import com.sun.prism.PixelFormat;
30 import com.sun.prism.Texture;
31 import com.sun.prism.impl.PrismSettings;
32
33 abstract class SWTexture implements Texture {
34
35 static Texture create(SWResourceFactory factory, PixelFormat formatHint, WrapMode wrapMode, int w, int h) {
36 switch (formatHint) {
37 case BYTE_ALPHA:
38 return new SWMaskTexture(factory, wrapMode, w, h);
39 default:
40 return new SWArgbPreTexture(factory, wrapMode, w, h);
41 }
42 }
43
44 boolean allocated = false;
45 int physicalWidth, physicalHeight, contentWidth, contentHeight;
46 private SWResourceFactory factory;
47 private int lastImageSerial;
48 private final WrapMode wrapMode;
49
50 SWTexture(SWResourceFactory factory, WrapMode wrapMode, int w, int h) {
51 this.factory = factory;
52 this.wrapMode = wrapMode;
53 physicalWidth = w;
54 physicalHeight = h;
55 contentWidth = w;
56 contentHeight = h;
57 lock();
58 }
59
60 SWTexture(SWTexture sharedTex, WrapMode altMode) {
61 this.allocated = sharedTex.allocated;
62 this.physicalWidth = sharedTex.physicalWidth;
63 this.physicalHeight = sharedTex.physicalHeight;
64 this.contentWidth = sharedTex.contentWidth;
65 this.contentHeight = sharedTex.contentHeight;
66 this.factory = sharedTex.factory;
67 // REMIND: Use indirection to share the serial number?
68 this.lastImageSerial = sharedTex.lastImageSerial;
69 this.wrapMode = altMode;
70 lock();
71 }
72
73 SWResourceFactory getResourceFactory() {
74 return this.factory;
75 }
76
77 int getOffset() {
78 return 0;
79 }
80
81 private int lockcount;
82 public void lock() {
83 lockcount++;
84 }
85
86 public void unlock() {
87 assertLocked();
88 lockcount--;
235 }
236 switch (altMode) {
237 case REPEAT:
238 if (wrapMode != WrapMode.CLAMP_TO_EDGE) {
239 return null;
240 }
241 break;
242 case CLAMP_TO_EDGE:
243 if (wrapMode != WrapMode.REPEAT) {
244 return null;
245 }
246 break;
247 default:
248 return null;
249 }
250 return this.createSharedLockedTexture(altMode);
251 }
252
253 @Override
254 public boolean getLinearFiltering() {
255 return false;
256 }
257
258 @Override
259 public void setLinearFiltering(boolean linear) { }
260
261 void allocate() {
262 if (allocated) {
263 return;
264 }
265 if (PrismSettings.debug) {
266 System.out.println("PCS Texture allocating buffer: " + this + ", " + physicalWidth + "x" + physicalHeight);
267 }
268 this.allocateBuffer();
269 allocated = true;
270 }
271
272 abstract void allocateBuffer();
273
274 /**
275 * Returns a new {@code Texture} object sharing all of the information
276 * from this texture, but using the new {@code WrapMode}.
277 * The new texture will be locked (in contrast to the similarly-named
278 * method in BaseTexture).
279 *
|
1 /*
2 * Copyright (c) 2011, 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
29 import com.sun.prism.PixelFormat;
30 import com.sun.prism.Texture;
31 import com.sun.prism.impl.PrismSettings;
32
33 abstract class SWTexture implements Texture {
34
35 static Texture create(SWResourceFactory factory, PixelFormat formatHint, WrapMode wrapMode, int w, int h) {
36 switch (formatHint) {
37 case BYTE_ALPHA:
38 return new SWMaskTexture(factory, wrapMode, w, h);
39 default:
40 return new SWArgbPreTexture(factory, wrapMode, w, h);
41 }
42 }
43
44 boolean allocated = false;
45 int physicalWidth, physicalHeight, contentWidth, contentHeight;
46 private SWResourceFactory factory;
47 private int lastImageSerial;
48 private final WrapMode wrapMode;
49 private boolean linearFiltering = true;
50
51 SWTexture(SWResourceFactory factory, WrapMode wrapMode, int w, int h) {
52 this.factory = factory;
53 this.wrapMode = wrapMode;
54 physicalWidth = w;
55 physicalHeight = h;
56 contentWidth = w;
57 contentHeight = h;
58 lock();
59 }
60
61 SWTexture(SWTexture sharedTex, WrapMode altMode) {
62 this.allocated = sharedTex.allocated;
63 this.physicalWidth = sharedTex.physicalWidth;
64 this.physicalHeight = sharedTex.physicalHeight;
65 this.contentWidth = sharedTex.contentWidth;
66 this.contentHeight = sharedTex.contentHeight;
67 this.factory = sharedTex.factory;
68 // REMIND: Use indirection to share the serial number?
69 this.lastImageSerial = sharedTex.lastImageSerial;
70 this.linearFiltering = sharedTex.linearFiltering;
71 this.wrapMode = altMode;
72 lock();
73 }
74
75 SWResourceFactory getResourceFactory() {
76 return this.factory;
77 }
78
79 int getOffset() {
80 return 0;
81 }
82
83 private int lockcount;
84 public void lock() {
85 lockcount++;
86 }
87
88 public void unlock() {
89 assertLocked();
90 lockcount--;
237 }
238 switch (altMode) {
239 case REPEAT:
240 if (wrapMode != WrapMode.CLAMP_TO_EDGE) {
241 return null;
242 }
243 break;
244 case CLAMP_TO_EDGE:
245 if (wrapMode != WrapMode.REPEAT) {
246 return null;
247 }
248 break;
249 default:
250 return null;
251 }
252 return this.createSharedLockedTexture(altMode);
253 }
254
255 @Override
256 public boolean getLinearFiltering() {
257 return linearFiltering;
258 }
259
260 @Override
261 public void setLinearFiltering(boolean linear) {
262 linearFiltering = linear;
263 }
264
265 void allocate() {
266 if (allocated) {
267 return;
268 }
269 if (PrismSettings.debug) {
270 System.out.println("PCS Texture allocating buffer: " + this + ", " + physicalWidth + "x" + physicalHeight);
271 }
272 this.allocateBuffer();
273 allocated = true;
274 }
275
276 abstract void allocateBuffer();
277
278 /**
279 * Returns a new {@code Texture} object sharing all of the information
280 * from this texture, but using the new {@code WrapMode}.
281 * The new texture will be locked (in contrast to the similarly-named
282 * method in BaseTexture).
283 *
|