1 /* 2 * Copyright (c) 2011, 2013, 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.sw; 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.ResourceFactory; 37 import com.sun.prism.RTTexture; 38 import com.sun.prism.Texture; 39 import com.sun.prism.Texture.Usage; 40 import com.sun.prism.Texture.WrapMode; 41 import com.sun.prism.impl.BaseResourceFactory; 42 import com.sun.prism.impl.PrismSettings; 43 import com.sun.prism.impl.TextureResourcePool; 44 import com.sun.prism.impl.VertexBuffer; 45 import com.sun.prism.impl.shape.BasicRoundRectRep; 46 import com.sun.prism.impl.shape.BasicShapeRep; 47 import com.sun.prism.shape.ShapeRep; 48 49 final class SWResourceFactory 50 extends BaseResourceFactory 51 implements ResourceFactory { 52 53 private static final ShapeRep theRep = new BasicShapeRep(); 54 private static final ShapeRep rectRep = new BasicRoundRectRep(); 55 56 private Screen screen; 57 private final SWContext context; 58 59 public SWResourceFactory(Screen screen) { 60 this.screen = screen; 61 this.context = new SWContext(this); 62 } 63 64 public TextureResourcePool getTextureResourcePool() { 65 return SWTexturePool.instance; 66 } 67 68 public Screen getScreen() { 69 return screen; 70 } 71 72 SWContext getContext() { 73 return context; 74 } 75 76 @Override public void dispose() { 77 context.dispose(); 78 } 79 80 @Override public ShapeRep createArcRep() { 81 return theRep; 82 } 83 84 @Override public ShapeRep createEllipseRep() { 85 return theRep; 86 } 87 88 @Override public ShapeRep createRoundRectRep() { 89 return rectRep; 90 } 91 92 @Override public ShapeRep createPathRep() { 93 return theRep; 94 } 95 96 @Override public VertexBuffer createVertexBuffer(int maxQuads) { 97 throw new UnsupportedOperationException("createVertexBuffer:unimp"); 98 } 99 100 101 @Override public Presentable createPresentable(PresentableState pState) { 102 if (PrismSettings.debug) { 103 System.out.println("+ SWRF.createPresentable()"); 104 } 105 return new SWPresentable(pState, this); 106 } 107 108 public int getRTTWidth(int w, WrapMode wrapMode) { 109 return w; 110 } 111 112 public int getRTTHeight(int h, WrapMode wrapMode) { 113 return h; 114 } 115 116 @Override 117 public boolean isCompatibleTexture(Texture tex) { 118 return tex instanceof SWTexture; 119 } 120 121 @Override public RTTexture createRTTexture(int width, int height, WrapMode wrapMode, boolean msaa) { 122 return createRTTexture(width, height, wrapMode); 123 } 124 125 @Override public RTTexture createRTTexture(int width, int height, WrapMode wrapMode, boolean msaa, boolean linearFilter) { 126 RTTexture rtt = createRTTexture(width, height, wrapMode); 127 rtt.setLinearFiltering(linearFilter); 128 return rtt; 129 } 130 131 @Override public RTTexture createRTTexture(int width, int height, 132 WrapMode wrapMode) 133 { 134 SWTexturePool pool = SWTexturePool.instance; 135 long size = pool.estimateRTTextureSize(width, height, false); 136 if (!pool.prepareForAllocation(size)) { 137 return null; 138 } 139 return new SWRTTexture(this, width, height); 140 } 141 142 @Override public int getMaximumTextureSize() { 143 return Integer.MAX_VALUE; 144 } 145 146 @Override public boolean isFormatSupported(PixelFormat format) { 147 switch (format) { 148 case BYTE_RGB: 149 case BYTE_GRAY: 150 case INT_ARGB_PRE: 151 case BYTE_BGRA_PRE: 152 return true; 153 case BYTE_ALPHA: 154 case BYTE_APPLE_422: 155 case MULTI_YCbCr_420: 156 case FLOAT_XYZW: 157 default: 158 return false; 159 } 160 } 161 162 @Override 163 protected boolean canClampToZero() { 164 return false; 165 } 166 167 @Override public Texture createTexture(MediaFrame vdb) { 168 return new SWArgbPreTexture(this, WrapMode.CLAMP_TO_EDGE, vdb.getWidth(), vdb.getHeight()); 169 } 170 171 @Override public Texture createTexture(PixelFormat formatHint, 172 Usage usageHint, 173 WrapMode wrapMode, 174 int w, int h) 175 { 176 SWTexturePool pool = SWTexturePool.instance; 177 long size = pool.estimateTextureSize(w, h, formatHint); 178 if (!pool.prepareForAllocation(size)) { 179 return null; 180 } 181 return SWTexture.create(this, formatHint, wrapMode, w, h); 182 } 183 184 @Override public Texture createTexture(PixelFormat formatHint, Usage usageHint, 185 WrapMode wrapMode, int w, int h, boolean useMipmap) { 186 return createTexture(formatHint, usageHint, wrapMode, w, h); 187 } 188 189 public PhongMaterial createPhongMaterial() { 190 throw new UnsupportedOperationException("Not supported yet."); 191 } 192 193 public MeshView createMeshView(Mesh mesh) { 194 throw new UnsupportedOperationException("Not supported yet."); 195 } 196 197 public Mesh createMesh() { 198 throw new UnsupportedOperationException("Not supported yet."); 199 } 200 }