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 antiAliasing) { 122 return createRTTexture(width, height, wrapMode); 123 } 124 125 @Override public RTTexture createRTTexture(int width, int height, 126 WrapMode wrapMode) 127 { 128 SWTexturePool pool = SWTexturePool.instance; 129 long size = pool.estimateRTTextureSize(width, height, false); 130 if (!pool.prepareForAllocation(size)) { 131 return null; 132 } 133 return new SWRTTexture(this, width, height); 134 } 135 136 @Override public int getMaximumTextureSize() { 137 return Integer.MAX_VALUE; 138 } 139 140 @Override public boolean isFormatSupported(PixelFormat format) { 141 switch (format) { 142 case BYTE_RGB: 143 case BYTE_GRAY: 144 case INT_ARGB_PRE: 145 case BYTE_BGRA_PRE: 146 return true; 147 case BYTE_ALPHA: 148 case BYTE_APPLE_422: 149 case MULTI_YCbCr_420: 150 case FLOAT_XYZW: 151 default: 152 return false; 153 } 154 } 155 156 @Override 157 protected boolean canClampToZero() { 158 return false; 159 } 160 161 @Override public Texture createTexture(MediaFrame vdb) { 162 return new SWArgbPreTexture(this, WrapMode.CLAMP_TO_EDGE, vdb.getWidth(), vdb.getHeight()); 163 } 164 165 @Override public Texture createTexture(PixelFormat formatHint, 166 Usage usageHint, 167 WrapMode wrapMode, 168 int w, int h) 169 { 170 SWTexturePool pool = SWTexturePool.instance; 171 long size = pool.estimateTextureSize(w, h, formatHint); 172 if (!pool.prepareForAllocation(size)) { 173 return null; 174 } 175 return SWTexture.create(this, formatHint, wrapMode, w, h); 176 } 177 178 @Override public Texture createTexture(PixelFormat formatHint, Usage usageHint, 179 WrapMode wrapMode, int w, int h, boolean useMipmap) { 180 return createTexture(formatHint, usageHint, wrapMode, w, h); 181 } 182 183 public PhongMaterial createPhongMaterial() { 184 throw new UnsupportedOperationException("Not supported yet."); 185 } 186 187 public MeshView createMeshView(Mesh mesh) { 188 throw new UnsupportedOperationException("Not supported yet."); 189 } 190 191 public Mesh createMesh() { 192 throw new UnsupportedOperationException("Not supported yet."); 193 } 194 }