1 /* 2 * Copyright (c) 2010, 2014, 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 23 * questions. 24 */ 25 26 package com.sun.prism.j2d; 27 28 import com.sun.glass.ui.Screen; 29 import com.sun.prism.MediaFrame; 30 import com.sun.prism.Mesh; 31 import com.sun.prism.MeshView; 32 import com.sun.prism.PhongMaterial; 33 import com.sun.prism.PixelFormat; 34 import com.sun.prism.Presentable; 35 import com.sun.prism.PresentableState; 36 import com.sun.prism.RTTexture; 37 import com.sun.prism.Texture; 38 import com.sun.prism.Texture.Usage; 39 import com.sun.prism.Texture.WrapMode; 40 import com.sun.prism.impl.BaseResourceFactory; 41 import com.sun.prism.impl.TextureResourcePool; 42 import com.sun.prism.impl.VertexBuffer; 43 import com.sun.prism.impl.shape.BasicShapeRep; 44 import com.sun.prism.shape.ShapeRep; 45 46 class J2DResourceFactory extends BaseResourceFactory 47 { 48 private Screen screen; 49 50 J2DResourceFactory(Screen screen) { 51 this.screen = screen; 52 } 53 54 J2DPrismGraphics createJ2DPrismGraphics(J2DPresentable target, 55 java.awt.Graphics2D g2d) { 56 return new J2DPrismGraphics(target, g2d); 57 } 58 59 public TextureResourcePool getTextureResourcePool() { 60 return J2DTexturePool.instance; 61 } 62 63 Screen getScreen() { 64 return screen; 65 } 66 67 private static ShapeRep theRep = new BasicShapeRep(); 68 69 public ShapeRep createArcRep() { 70 return theRep; 71 } 72 73 public ShapeRep createEllipseRep() { 74 return theRep; 75 } 76 77 public ShapeRep createRoundRectRep() { 78 return theRep; 79 } 80 81 public ShapeRep createPathRep() { 82 return theRep; 83 } 84 85 public Presentable createPresentable(PresentableState pState) { 86 return J2DPresentable.create(pState, this); 87 } 88 89 public int getRTTWidth(int w, WrapMode wrapMode) { 90 return w; 91 } 92 93 public int getRTTHeight(int h, WrapMode wrapMode) { 94 return h; 95 } 96 97 @Override 98 public RTTexture createRTTexture(int width, int height, Texture.WrapMode wrapMode, boolean antiAliasing) { 99 return createRTTexture(width, height, wrapMode); 100 } 101 102 public RTTexture createRTTexture(int width, int height, WrapMode wrapMode) { 103 J2DTexturePool pool = J2DTexturePool.instance; 104 long size = pool.estimateRTTextureSize(width, height, false); 105 if (!pool.prepareForAllocation(size)) { 106 return null; 107 } 108 return new J2DRTTexture(width, height, this); 109 } 110 111 public Texture createTexture(PixelFormat formatHint, 112 Usage usageHint, WrapMode wrapMode, 113 int w, int h) 114 { 115 return J2DTexture.create(formatHint, wrapMode, w, h); 116 } 117 118 public Texture createTexture(PixelFormat formatHint, 119 Usage usageHint, WrapMode wrapMode, int w, int h, boolean useMipmap) { 120 return createTexture(formatHint, usageHint, wrapMode, w, h); 121 } 122 123 public Texture createTexture(MediaFrame vdb) { 124 Texture tex; 125 126 vdb.holdFrame(); 127 128 if (vdb.getPixelFormat() != PixelFormat.INT_ARGB_PRE) { 129 MediaFrame newFrame = vdb.convertToFormat(PixelFormat.INT_ARGB_PRE); 130 vdb.releaseFrame(); 131 vdb = newFrame; 132 if (null == vdb) { 133 // FIXME: error condition? 134 return null; 135 } 136 } 137 138 tex = J2DTexture.create(vdb.getPixelFormat(), WrapMode.CLAMP_TO_EDGE, 139 vdb.getWidth(), vdb.getHeight()); 140 vdb.releaseFrame(); 141 return tex; 142 } 143 144 @Override 145 public boolean isCompatibleTexture(Texture tex) { 146 return tex instanceof J2DTexture; 147 } 148 149 public int getMaximumTextureSize() { 150 return Integer.MAX_VALUE; 151 } 152 153 public boolean isFormatSupported(PixelFormat format) { 154 switch (format) { 155 case BYTE_RGB: 156 case BYTE_GRAY: 157 case INT_ARGB_PRE: 158 case BYTE_BGRA_PRE: 159 return true; 160 case BYTE_ALPHA: 161 case BYTE_APPLE_422: 162 case MULTI_YCbCr_420: 163 case FLOAT_XYZW: 164 default: 165 return false; 166 } 167 } 168 169 public VertexBuffer createVertexBuffer(int maxQuads) { 170 // This is only used by ES1 and ES2 - it should perhaps be 171 // moved to an ES-specific subclass of ResourceFactory? 172 throw new UnsupportedOperationException("Not supported yet."); 173 } 174 175 public void dispose() { 176 } 177 178 public PhongMaterial createPhongMaterial() { 179 throw new UnsupportedOperationException("Not supported yet."); 180 } 181 182 public MeshView createMeshView(Mesh mesh) { 183 throw new UnsupportedOperationException("Not supported yet."); 184 } 185 186 public Mesh createMesh() { 187 throw new UnsupportedOperationException("Not supported yet."); 188 } 189 }