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 23 * questions. 24 */ 25 26 package com.sun.prism.j2d; 27 28 import com.sun.glass.ui.Application; 29 import com.sun.glass.ui.Pixels; 30 import com.sun.glass.ui.Screen; 31 import com.sun.javafx.geom.Rectangle; 32 import com.sun.prism.Graphics; 33 import com.sun.prism.Presentable; 34 import com.sun.prism.PresentableState; 35 import com.sun.prism.ResourceFactory; 36 import com.sun.prism.Texture.WrapMode; 37 import com.sun.prism.impl.PrismSettings; 38 import com.sun.prism.impl.QueuedPixelSource; 39 40 import java.awt.Graphics2D; 41 import java.awt.image.BufferedImage; 42 import java.nio.ByteOrder; 43 import java.nio.IntBuffer; 44 45 public abstract class J2DPresentable implements Presentable { 46 static J2DPresentable create(PresentableState pState, 47 J2DResourceFactory factory) 48 { 49 return new Glass(pState, factory); 50 } 51 52 static J2DPresentable create(BufferedImage buffer, J2DResourceFactory factory) 53 { 54 return new Bimg(buffer, factory); 55 } 56 57 58 private static class Glass extends J2DPresentable { 59 private final PresentableState pState; 60 private final int theFormat; 61 private Pixels pixels; 62 private QueuedPixelSource pixelSource = new QueuedPixelSource(); 63 private boolean opaque; 64 65 Glass(PresentableState pState, J2DResourceFactory factory) { 66 super(null, factory); 67 this.pState = pState; 68 this.theFormat = pState.getPixelFormat(); 69 needsResize = true; 70 } 71 72 @Override 73 public BufferedImage createBuffer(int w, int h) { 74 if (PrismSettings.verbose) { 75 System.out.println("Glass native format: "+theFormat); 76 } 77 ByteOrder byteorder = ByteOrder.nativeOrder(); 78 switch (theFormat) { 79 case Pixels.Format.BYTE_BGRA_PRE: 80 if (byteorder == ByteOrder.LITTLE_ENDIAN) { 81 return new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB_PRE); 82 } else { 83 throw new UnsupportedOperationException("BYTE_BGRA_PRE pixel format on BIG_ENDIAN"); 84 } 85 /* NOTREACHED */ 86 case Pixels.Format.BYTE_ARGB: 87 if (byteorder == ByteOrder.BIG_ENDIAN) { 88 return new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); 89 } else { 90 throw new UnsupportedOperationException("BYTE_ARGB pixel format on LITTLE_ENDIAN"); 91 } 92 /* NOTREACHED */ 93 default: 94 throw new UnsupportedOperationException("unrecognized pixel format: "+theFormat); 95 } 96 } 97 98 private final Application app = Application.GetApplication(); 99 100 @Override 101 public boolean lockResources(PresentableState pState) { 102 if (this.pState != pState || this.theFormat != pState.getPixelFormat()) { 103 return true; 104 } 105 needsResize = (buffer == null || 106 buffer.getWidth() != pState.getWidth() || 107 buffer.getHeight() != pState.getHeight()); 108 return false; 109 } 110 111 public boolean prepare(Rectangle dirty) { 112 if (pState.isViewClosed() == false) { 113 /* 114 * RT-27385 115 * TODO: make sure the imgrep matches the Pixels.getNativeFormat() 116 * TODO: dirty region support 117 */ 118 int w = getPhysicalWidth(); 119 int h = getPhysicalHeight(); 120 pixelSource.validate(w, h, 1.0f); 121 pixels = pixelSource.getUnusedPixels(); 122 IntBuffer pixBuf; 123 if (pixels != null) { 124 pixBuf = (IntBuffer) pixels.getPixels(); 125 } else { 126 pixBuf = IntBuffer.allocate(w*h); 127 pixels = app.createPixels(w, h, pixBuf); 128 } 129 assert ib.hasArray(); 130 System.arraycopy(ib.array(), 0, pixBuf.array(), 0, w*h); 131 return true; 132 } else { 133 return (false); 134 } 135 } 136 137 public boolean present() { 138 pixelSource.enqueuePixels(pixels); 139 pState.uploadPixels(pixelSource); 140 return true; 141 } 142 143 public int getContentWidth() { 144 return pState.getWidth(); 145 } 146 147 public int getContentHeight() { 148 return pState.getHeight(); | 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 23 * questions. 24 */ 25 26 package com.sun.prism.j2d; 27 28 import com.sun.glass.ui.Pixels; 29 import com.sun.glass.ui.Screen; 30 import com.sun.javafx.geom.Rectangle; 31 import com.sun.prism.Graphics; 32 import com.sun.prism.Presentable; 33 import com.sun.prism.PresentableState; 34 import com.sun.prism.ResourceFactory; 35 import com.sun.prism.Texture.WrapMode; 36 import com.sun.prism.impl.PrismSettings; 37 import com.sun.prism.impl.QueuedPixelSource; 38 39 import java.awt.Graphics2D; 40 import java.awt.image.BufferedImage; 41 import java.nio.ByteOrder; 42 import java.nio.IntBuffer; 43 44 public abstract class J2DPresentable implements Presentable { 45 static J2DPresentable create(PresentableState pState, 46 J2DResourceFactory factory) 47 { 48 return new Glass(pState, factory); 49 } 50 51 static J2DPresentable create(BufferedImage buffer, J2DResourceFactory factory) 52 { 53 return new Bimg(buffer, factory); 54 } 55 56 57 private static class Glass extends J2DPresentable { 58 private final PresentableState pState; 59 private final int theFormat; 60 private Pixels pixels; 61 private QueuedPixelSource pixelSource = new QueuedPixelSource(false); 62 private boolean opaque; 63 64 Glass(PresentableState pState, J2DResourceFactory factory) { 65 super(null, factory); 66 this.pState = pState; 67 this.theFormat = pState.getPixelFormat(); 68 needsResize = true; 69 } 70 71 @Override 72 public BufferedImage createBuffer(int w, int h) { 73 if (PrismSettings.verbose) { 74 System.out.println("Glass native format: "+theFormat); 75 } 76 ByteOrder byteorder = ByteOrder.nativeOrder(); 77 switch (theFormat) { 78 case Pixels.Format.BYTE_BGRA_PRE: 79 if (byteorder == ByteOrder.LITTLE_ENDIAN) { 80 return new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB_PRE); 81 } else { 82 throw new UnsupportedOperationException("BYTE_BGRA_PRE pixel format on BIG_ENDIAN"); 83 } 84 /* NOTREACHED */ 85 case Pixels.Format.BYTE_ARGB: 86 if (byteorder == ByteOrder.BIG_ENDIAN) { 87 return new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); 88 } else { 89 throw new UnsupportedOperationException("BYTE_ARGB pixel format on LITTLE_ENDIAN"); 90 } 91 /* NOTREACHED */ 92 default: 93 throw new UnsupportedOperationException("unrecognized pixel format: "+theFormat); 94 } 95 } 96 97 @Override 98 public boolean lockResources(PresentableState pState) { 99 if (this.pState != pState || this.theFormat != pState.getPixelFormat()) { 100 return true; 101 } 102 needsResize = (buffer == null || 103 buffer.getWidth() != pState.getWidth() || 104 buffer.getHeight() != pState.getHeight()); 105 return false; 106 } 107 108 public boolean prepare(Rectangle dirty) { 109 if (pState.isViewClosed() == false) { 110 /* 111 * RT-27385 112 * TODO: make sure the imgrep matches the Pixels.getNativeFormat() 113 * TODO: dirty region support 114 */ 115 int w = getPhysicalWidth(); 116 int h = getPhysicalHeight(); 117 pixels = pixelSource.getUnusedPixels(w, h, 1.0f); 118 IntBuffer pixBuf = (IntBuffer) pixels.getPixels(); 119 assert ib.hasArray(); 120 System.arraycopy(ib.array(), 0, pixBuf.array(), 0, w*h); 121 return true; 122 } else { 123 return (false); 124 } 125 } 126 127 public boolean present() { 128 pixelSource.enqueuePixels(pixels); 129 pState.uploadPixels(pixelSource); 130 return true; 131 } 132 133 public int getContentWidth() { 134 return pState.getWidth(); 135 } 136 137 public int getContentHeight() { 138 return pState.getHeight(); |