1 /* 2 * Copyright (c) 2009, 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; 27 28 import com.sun.prism.Texture.WrapMode; 29 import com.sun.prism.impl.TextureResourcePool; 30 import com.sun.prism.impl.VertexBuffer; 31 import com.sun.prism.shape.ShapeRep; 32 33 public interface ResourceFactory extends GraphicsResource { 34 35 /** 36 * Returns status of this graphics device. 37 * If the device is not ready the createRTTexture and 38 * present operations will fail. 39 * Creation of shaders and regular textures will succeed and 40 * return valid resources. 41 * All hardware resources (RenderTargets and SwapChains) have to be recreated 42 * after a device-lost event notification. 43 **/ 44 45 public boolean isDeviceReady(); 46 47 public TextureResourcePool getTextureResourcePool(); 48 49 /** 50 * Returns a new {@code Texture} containing the pixels from the given 51 * image with the indicated texture edge wrap mode. 52 * Note that the dimensions of the returned texture may be larger 53 * than those of the given image. 54 * <p> 55 * Equivalent to (but perhaps more efficient than): 56 * <pre><code> 57 * PixelFormat format = image.getPixelFormat(); 58 * int w = image.getWidth(); 59 * int h = image.getHeight(); 60 * Texture tex = createTexture(format, usageHint, wrapMode, w, h); 61 * tex.update(image, 0, 0, w, h); 62 * </code></pre> 63 * 64 * @param image the pixel data to be uploaded to the new texture 65 * @param usageHint the Dynamic vs. Static nature of the texture data 66 * @param wrapMode the desired edge behavior (clamping vs. wrapping) 67 * @return a new texture 68 */ 69 public Texture createTexture(Image image, 70 Texture.Usage usageHint, 71 Texture.WrapMode wrapMode); 72 73 /** 74 * Returns a new {@code Texture} containing the pixels from the given 75 * image with the indicated texture edge wrap mode. 76 * Note that the dimensions of the returned texture may be larger 77 * than those of the given image. 78 * <p> 79 * Equivalent to (but perhaps more efficient than): 80 * <pre><code> 81 * PixelFormat format = image.getPixelFormat(); 82 * int w = image.getWidth(); 83 * int h = image.getHeight(); 84 * Texture tex = createTexture(format, usageHint, wrapMode, w, h, useMipmap); 85 * tex.update(image, 0, 0, w, h); 86 * </code></pre> 87 * 88 * @param image the pixel data to be uploaded to the new texture 89 * @param usageHint the Dynamic vs. Static nature of the texture data 90 * @param wrapMode the desired edge behavior (clamping vs. wrapping) 91 * @param useMipmap the flag indicates should texture be created with mipmap 92 * @return a new texture 93 */ 94 public Texture createTexture(Image image, Texture.Usage usageHint, 95 Texture.WrapMode wrapMode, boolean useMipmap); 96 97 /** 98 * Returns a new {@code Texture} with the given format and edge wrapping 99 * support. Note that the dimensions of the returned texture may be larger 100 * than those requested and the wrap mode may be a simulated version of 101 * the type requested. 102 * 103 * @param formatHint intended pixel format of the data to be stored 104 * in this texture 105 * @param usageHint the Dynamic vs. Static nature of the texture data 106 * @param wrapMode intended wrap mode to be used for the texture 107 * @param w width of the content in the texture 108 * @param h height of the content in the texture 109 * @return texture most appropriate for the given intended format, wrap 110 * mode and dimensions 111 */ 112 public Texture createTexture(PixelFormat formatHint, 113 Texture.Usage usageHint, 114 Texture.WrapMode wrapMode, 115 int w, int h); 116 117 /** 118 * Returns a new {@code Texture} with the given format and edge wrapping 119 * support. Note that the dimensions of the returned texture may be larger 120 * than those requested and the wrap mode may be a simulated version of 121 * the type requested. 122 * 123 * @param formatHint intended pixel format of the data to be stored 124 * in this texture 125 * @param usageHint the Dynamic vs. Static nature of the texture data 126 * @param wrapMode intended wrap mode to be used for the texture 127 * @param w width of the content in the texture 128 * @param h height of the content in the texture 129 * @param useMipmap the flag indicates should texture be created with mipmap 130 * @return texture most appropriate for the given intended format, wrap 131 * mode and dimensions 132 */ 133 public Texture createTexture(PixelFormat formatHint, Texture.Usage usageHint, 134 Texture.WrapMode wrapMode, int w, int h, boolean useMipmap); 135 136 /** 137 * Returns a new {@code Texture} that can contain the video image as specified 138 * in the provided {@code MediaFrame}. Note that padding is almost implicit 139 * since this method has to accommodate the line strides of each plane. Also 140 * due to renderer limitations, some format conversion may be necessary so 141 * the texture format may end up being different from the video image format. 142 * 143 * @param frame the video image that we need to create a new texture for 144 * @return texture most appropriate for the given video image. 145 */ 146 public Texture createTexture(MediaFrame frame); 147 148 /** 149 * Returns a {@code Texture} for the given image set up to use or 150 * simulate the indicated wrap mode. 151 * If no texture could be found in the cache, this method will create a 152 * new texture and put it in the cache before returning it. 153 * NOTE: the caller of this method should not hold a reference to the 154 * cached texture beyond its immediate needs since the cache may be 155 * cleared at any time. 156 * 157 * @param image the pixel data to be uploaded if the texture is new or 158 * needs new fringe pixels to simulate a new wrap mode 159 * @param wrapMode the mode that describes the behavior for samples 160 * outside the content area 161 * @return a cached texture 162 */ 163 public Texture getCachedTexture(Image image, Texture.WrapMode wrapMode); 164 165 /** 166 * Returns a {@code Texture} for the given image set up to use or 167 * simulate the indicated wrap mode. 168 * If no texture could be found in the cache, this method will create a 169 * new texture and put it in the cache before returning it. 170 * NOTE: the caller of this method should not hold a reference to the 171 * cached texture beyond its immediate needs since the cache may be 172 * cleared at any time. 173 * 174 * @param image the pixel data to be uploaded if the texture is new or 175 * needs new fringe pixels to simulate a new wrap mode 176 * @param wrapMode the mode that describes the behavior for samples 177 * outside the content 178 * @param useMipmap the flag indicates should mipmapping be used for this 179 * texture 180 * @return a cached texture 181 */ 182 public Texture getCachedTexture(Image image, Texture.WrapMode wrapMode, boolean useMipmap); 183 184 /** 185 * Returns true if the given {@code PixelFormat} is supported; otherwise 186 * returns false. 187 * <p> 188 * Note that the following formats are guaranteed to be supported 189 * across all devices: 190 * <pre><code> 191 * BYTE_RGB 192 * BYTE_RGBA_PRE 193 * BYTE_GRAY 194 * BYTE_ALPHA 195 * </code></pre> 196 * <p> 197 * Support for the other formats depends on the capabilities of the 198 * device. Be sure to call this method before attempting to create 199 * a {@code Texture} with a non-standard format and plan to have an 200 * alternate codepath if the given format is not supported. 201 * 202 * @param format the {@code PixelFormat} to test 203 * @return true if the given format is supported; false otherwise 204 */ 205 public boolean isFormatSupported(PixelFormat format); 206 207 /** 208 * Returns true iff the indicated {@link WrapMode wrap mode} is directly 209 * supported (i.e. not simulated) by the underlying pipeline and platform. 210 * 211 * @param mode the desired {@code WrapMode} 212 * @return true iff the wrap mode is supported and not simulated 213 */ 214 public boolean isWrapModeSupported(WrapMode mode); 215 216 /** 217 * Returns the maximum supported texture dimension for this device. 218 * For example, if this method returns 2048, it means that textures 219 * larger than 2048x2048 cannot be created. 220 * 221 * @return the maximum supported texture dimension 222 */ 223 public int getMaximumTextureSize(); 224 225 public int getRTTWidth(int w, Texture.WrapMode wrapMode); 226 public int getRTTHeight(int h, Texture.WrapMode wrapMode); 227 228 public Texture createMaskTexture(int width, int height, Texture.WrapMode wrapMode); 229 public Texture createFloatTexture(int width, int height); 230 public RTTexture createRTTexture(int width, int height, Texture.WrapMode wrapMode); 231 public RTTexture createRTTexture(int width, int height, Texture.WrapMode wrapMode, boolean msaa); 232 public RTTexture createRTTexture(int width, int height, Texture.WrapMode wrapMode, boolean msaa, boolean linearFilter); 233 234 /** 235 * A Texture may have been obtained from a different resource factory. 236 * @param tex the texture to check. 237 * @return whether this texture is compatible. 238 */ 239 public boolean isCompatibleTexture(Texture tex); 240 241 public Presentable createPresentable(PresentableState pState); 242 public VertexBuffer createVertexBuffer(int maxQuads); 243 244 public ShapeRep createPathRep(); 245 public ShapeRep createRoundRectRep(); 246 public ShapeRep createEllipseRep(); 247 public ShapeRep createArcRep(); 248 249 public void addFactoryListener(ResourceFactoryListener l); 250 public void removeFactoryListener(ResourceFactoryListener l); 251 252 public void setRegionTexture(Texture texture); 253 public Texture getRegionTexture(); 254 public void setGlyphTexture(Texture texture); 255 public Texture getGlyphTexture(); 256 public boolean isSuperShaderAllowed(); 257 258 public void dispose(); 259 260 /* 261 * 3D stuff 262 */ 263 public PhongMaterial createPhongMaterial(); 264 public MeshView createMeshView(Mesh mesh); 265 public Mesh createMesh(); 266 }