1 /*
   2  * Copyright (c) 2012, 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.javafx.sg.prism;
  27 
  28 import java.nio.Buffer;
  29 import com.sun.glass.ui.Screen;
  30 import com.sun.javafx.font.FontStrike;
  31 import com.sun.javafx.geom.RectBounds;
  32 import com.sun.javafx.geom.Shape;
  33 import com.sun.javafx.geom.transform.BaseTransform;
  34 import com.sun.javafx.scene.text.GlyphList;
  35 import com.sun.prism.BasicStroke;
  36 import com.sun.prism.Graphics;
  37 import com.sun.prism.Image;
  38 import com.sun.prism.MediaFrame;
  39 import com.sun.prism.Mesh;
  40 import com.sun.prism.MeshView;
  41 import com.sun.prism.PhongMaterial;
  42 import com.sun.prism.PixelFormat;
  43 import com.sun.prism.Presentable;
  44 import com.sun.prism.PresentableState;
  45 import com.sun.prism.RTTexture;
  46 import com.sun.prism.RenderTarget;
  47 import com.sun.prism.ResourceFactory;
  48 import com.sun.prism.ResourceFactoryListener;
  49 import com.sun.prism.Texture;
  50 import com.sun.prism.Texture.WrapMode;
  51 import com.sun.prism.impl.BaseContext;
  52 import com.sun.prism.impl.BaseGraphics;
  53 import com.sun.prism.impl.TextureResourcePool;
  54 import com.sun.prism.impl.VertexBuffer;
  55 import com.sun.prism.paint.Color;
  56 import com.sun.prism.shape.ShapeRep;
  57 
  58 
  59 /**
  60  *
  61  */
  62 public class TestGraphics extends BaseGraphics {
  63 
  64     public static final Graphics TEST_GRAPHICS = new TestGraphics();
  65 
  66     public TestGraphics() {
  67         super(new TestContext(), new TestRenderTarget());
  68     }
  69 
  70     @Override
  71     public void fillTriangles(VertexBuffer tris, int numVerts, float bx, float by, float bw, float bh) {
  72     }
  73 
  74     @Override
  75     protected void renderShape(Shape shape, BasicStroke stroke, float bx, float by, float bw, float bh) {
  76     }
  77 
  78     public void clear(Color color) {
  79     }
  80 
  81     public void clearQuad(float x1, float y1, float x2, float y2) {
  82     }
  83 
  84     public void fillQuad(float x1, float y1, float x2, float y2) {
  85     }
  86 
  87     public void fillRect(float x, float y, float width, float height) {
  88     }
  89 
  90     public void fillRoundRect(float x, float y, float width, float height, float arcw, float arch) {
  91     }
  92 
  93     public void fillEllipse(float x, float y, float width, float height) {
  94     }
  95 
  96     public void drawLine(float x1, float y1, float x2, float y2) {
  97     }
  98 
  99     public void drawRect(float x, float y, float width, float height) {
 100     }
 101 
 102     public void drawRoundRect(float x, float y, float width, float height, float arcw, float arch) {
 103     }
 104 
 105     public void drawEllipse(float x, float y, float width, float height) {
 106     }
 107 
 108     public void setNodeBounds(RectBounds bounds) {
 109     }
 110 
 111     @Override public void drawString(GlyphList gl, FontStrike strike, float x, float y, Color selectColor, int selectStart, int selectEnd) {
 112     }
 113 
 114     @Override public void drawTexture(Texture tex, float x, float y, float w, float h) {
 115     }
 116 
 117     @Override
 118     public void drawTexture(Texture tex, float dx1, float dy1, float dx2, float dy2, float sx1, float sy1, float sx2, float sy2) {
 119     }
 120 
 121     @Override
 122     public void drawTexture3SliceH(Texture tex, float dx1, float dy1, float dx2, float dy2, float sx1, float sy1, float sx2, float sy2, float dh1, float dh2, float sh1, float sh2) {
 123     }
 124 
 125     @Override
 126     public void drawTexture3SliceV(Texture tex, float dx1, float dy1, float dx2, float dy2, float sx1, float sy1, float sx2, float sy2, float dv1, float dv2, float sv1, float sv2) {
 127     }
 128 
 129     @Override
 130     public void drawTexture9Slice(Texture tex, float dx1, float dy1, float dx2, float dy2, float sx1, float sy1, float sx2, float sy2, float dh1, float dv1, float dh2, float dv2, float sh1, float sv1, float sh2, float sv2) {
 131     }
 132 
 133     public void sync() {
 134     }
 135 
 136     @Override
 137     public void setState3D(boolean flag) {
 138     }
 139 
 140     @Override
 141     public boolean isState3D() {
 142         return false;
 143     }
 144 
 145     public void setup3DRendering() {
 146     }
 147 
 148     public void blit(RTTexture srcTex, RTTexture dstTex, int srcX0, int srcY0, int srcX1, int srcY1, int dstX0, int dstY0, int dstX1, int dstY1) {
 149     }
 150 
 151     private static class TestContext extends BaseContext {
 152 
 153         public TestContext() {
 154             super(null, new TestResourceFactory(), null);
 155         }
 156 
 157         @Override
 158         protected void setRenderTarget(RenderTarget target, NGCamera camera, boolean depthTest, boolean state3D) {
 159         }
 160 
 161         @Override
 162         public void validatePaintOp(BaseGraphics g, BaseTransform xform, Texture maskTex, float bx, float by, float bw, float bh) {
 163         }
 164 
 165         @Override
 166         public void validateTextureOp(BaseGraphics g, BaseTransform xform, Texture src, PixelFormat format) {
 167         }
 168 
 169         @Override
 170         public RTTexture getLCDBuffer() {
 171             return null;
 172         }
 173     }
 174 
 175     private static class TestResourceFactory implements ResourceFactory {
 176         @Override public boolean isDeviceReady() { return true; }
 177 
 178         @Override public TextureResourcePool getTextureResourcePool() { return null; }
 179         @Override public Texture createTexture(Image image, Texture.Usage usageHint, WrapMode wrapMode) { return null; }
 180         @Override public Texture createTexture(Image image, Texture.Usage usageHint, Texture.WrapMode wrapMode, boolean useMipmap) { return null; }
 181         @Override public Texture createTexture(PixelFormat formatHint, Texture.Usage usageHint, WrapMode wrapMode, int w, int h) { return null; }
 182         @Override public Texture createTexture(PixelFormat formatHint, Texture.Usage usageHint, Texture.WrapMode wrapMode, int w, int h, boolean useMipmap) { return null; }
 183         @Override public Texture createTexture(MediaFrame frame) { return null; }
 184         @Override public boolean isCompatibleTexture(Texture tex) { return true; }
 185         @Override public Texture getCachedTexture(Image image, WrapMode wrapMode) { return null; }
 186         @Override public Texture getCachedTexture(Image image, WrapMode wrapMode, boolean useMipmap) { return null; }
 187         @Override public boolean isFormatSupported(PixelFormat format) { return false; }
 188         @Override public int getMaximumTextureSize() { return 0; }
 189         @Override public Texture createMaskTexture(int width, int height, Texture.WrapMode wrapMode) { return null; }
 190         @Override public Texture createFloatTexture(int width, int height) { return null; }
 191         @Override public int getRTTWidth(int w, WrapMode wrapMode) { return w; }
 192         @Override public int getRTTHeight(int h, WrapMode wrapMode) { return h; }
 193         @Override public RTTexture createRTTexture(final int width, final int height, Texture.WrapMode wrapMode) {
 194             return createRTTexture(width, height, wrapMode, false);
 195         }
 196         @Override public RTTexture createRTTexture(final int width, final int height, Texture.WrapMode wrapMode, boolean antiAliasing) {
 197             return new RTTexture() {
 198                 @Override public int[] getPixels() { return new int[0]; }
 199                 @Override public boolean readPixels(Buffer pixels, int x, int y, int width, int height) { return false; }
 200                 @Override public boolean readPixels(Buffer pixels) { return false; }
 201                 @Override public boolean isVolatile() { return false; }
 202                 @Override public boolean isSurfaceLost() { return false; }
 203                 @Override public Screen getAssociatedScreen() { return null; }
 204                 @Override public Graphics createGraphics() {
 205                     return new TestGraphics();
 206                 }
 207 
 208                 @Override public Texture getSharedTexture(WrapMode altMode) { return null; }
 209                 @Override public boolean isOpaque() { return false; }
 210                 @Override public PixelFormat getPixelFormat() { return null; }
 211                 @Override public int getPhysicalWidth() { return width; }
 212                 @Override public int getPhysicalHeight() { return height; }
 213                 @Override public int getContentX() { return 0; }
 214                 @Override public int getContentY() { return 0; }
 215                 @Override public int getContentWidth() { return width; }
 216                 @Override public int getContentHeight() { return height; }
 217                 @Override public int getLastImageSerial() { return 0; }
 218                 @Override public void setLastImageSerial(int serial) { }
 219                 @Override public void update(Image img) { }
 220                 @Override public void update(Image img, int dstx, int dsty) { }
 221                 @Override public void update(Image img, int dstx, int dsty, int srcw, int srch) { }
 222                 @Override public void update(Image img, int dstx, int dsty, int srcw, int srch, boolean skipFlush) { }
 223                 @Override public void update(Buffer buffer, PixelFormat format, int dstx, int dsty, int srcx, int srcy, int srcw, int srch, int srcscan, boolean skipFlush) { }
 224                 @Override public void update(MediaFrame frame, boolean skipFlush) { }
 225                 @Override public WrapMode getWrapMode() { return null; }
 226                 @Override public boolean getLinearFiltering() { return false; }
 227                 @Override public void setLinearFiltering(boolean linear) { }
 228                 @Override public void dispose() { }
 229                 @Override public void lock() { }
 230                 @Override public void unlock() { }
 231                 @Override public boolean isLocked() { return true; }
 232                 @Override public int getLockCount() { return 1; }
 233                 @Override public void assertLocked() { }
 234                 @Override public void makePermanent() { }
 235                 @Override public void contentsUseful() { }
 236                 @Override public void contentsNotUseful() { }
 237                 @Override public void setOpaque(boolean opaque) { }
 238                 @Override public boolean isAntiAliasing() { return false; }
 239                 @Override public int getMaxContentWidth() { return getPhysicalWidth(); }
 240                 @Override public int getMaxContentHeight() { return getPhysicalHeight(); }
 241                 @Override public void setContentWidth(int contentWidth) { }
 242                 @Override public void setContentHeight(int contentHeight) { }
 243                 @Override public boolean getUseMipmap() { return false; }
 244             };
 245         }
 246         @Override public Presentable createPresentable(PresentableState pstate) { return null; }
 247         @Override public VertexBuffer createVertexBuffer(int maxQuads) { return null; }
 248         @Override public ShapeRep createPathRep() { return null; }
 249         @Override public ShapeRep createRoundRectRep() { return null; }
 250         @Override public ShapeRep createEllipseRep() { return null; }
 251         @Override public ShapeRep createArcRep() { return null; }
 252         @Override public void addFactoryListener(ResourceFactoryListener l) { }
 253         @Override public void removeFactoryListener(ResourceFactoryListener l) { }
 254         @Override public void dispose() { }
 255 
 256         @Override public PhongMaterial createPhongMaterial() { return null; }
 257         @Override public MeshView createMeshView(Mesh mesh) { return null; }
 258         @Override public Mesh createMesh() { return null; }
 259         @Override public void setRegionTexture(Texture texture) { }
 260         @Override public Texture getRegionTexture() { return null; }
 261         @Override public void setGlyphTexture(Texture texture) { }
 262         @Override public Texture getGlyphTexture() { return null; }
 263         @Override public boolean isSuperShaderAllowed() {return false; }
 264 
 265     }
 266 
 267     private static class TestRenderTarget implements RenderTarget {
 268 
 269         public Screen getAssociatedScreen() {
 270             return null;
 271         }
 272 
 273         public Graphics createGraphics() {
 274             return null;
 275         }
 276 
 277         public boolean isOpaque() {
 278             return true;
 279         }
 280 
 281         public void setOpaque(boolean opaque) {
 282         }
 283 
 284         public int getPhysicalWidth() {
 285             return 0;
 286         }
 287 
 288         public int getPhysicalHeight() {
 289             return 0;
 290         }
 291 
 292         public int getContentX() {
 293             return 0;
 294         }
 295 
 296         public int getContentY() {
 297             return 0;
 298         }
 299 
 300         public int getContentWidth() {
 301             return 0;
 302         }
 303 
 304         public int getContentHeight() {
 305             return 0;
 306         }
 307 
 308         public boolean isAntiAliasing() {
 309             return false;
 310         }
 311 
 312     }
 313 
 314     @Override
 315     public void setLights(NGLightBase[] lights) {
 316     }
 317 
 318     @Override
 319     public NGLightBase[] getLights() {
 320         return null;
 321     }
 322 }