1 /*
   2  * Copyright (c) 2009, 2015, 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.glass.ui.Screen;
  29 import com.sun.javafx.font.FontStrike;
  30 import com.sun.javafx.geom.RectBounds;
  31 import com.sun.javafx.geom.Rectangle;
  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.javafx.sg.prism.NGCamera;
  36 import com.sun.javafx.sg.prism.NGLightBase;
  37 import com.sun.javafx.sg.prism.NodePath;
  38 import com.sun.prism.paint.Color;
  39 import com.sun.prism.paint.Paint;
  40 
  41 /**
  42  *
  43  */
  44 public interface Graphics {
  45 
  46     public BaseTransform getTransformNoClone();
  47     public void setTransform(BaseTransform xform);
  48     public void setTransform(double m00, double m10,
  49                              double m01, double m11,
  50                              double m02, double m12);
  51     public void setTransform3D(double mxx, double mxy, double mxz, double mxt,
  52                                double myx, double myy, double myz, double myt,
  53                                double mzx, double mzy, double mzz, double mzt);
  54     public void transform(BaseTransform xform);
  55     public void translate(float tx, float ty);
  56     public void translate(float tx, float ty, float tz);
  57     public void scale(float sx, float sy);
  58     public void scale(float sx, float sy, float sz);
  59 
  60     public void setCamera(NGCamera camera);
  61     public NGCamera getCameraNoClone();
  62     public void setDepthTest(boolean depthTest);
  63     public boolean isDepthTest();
  64     public void setDepthBuffer(boolean depthBuffer);
  65     public boolean isDepthBuffer();
  66     public boolean isAlphaTestShader();
  67     public void setAntialiasedShape(boolean aa);
  68     public boolean isAntialiasedShape();
  69     public RectBounds getFinalClipNoClone();
  70     public Rectangle getClipRect();
  71     public Rectangle getClipRectNoClone();
  72     public void setHasPreCullingBits(boolean hasBits);
  73     public boolean hasPreCullingBits();
  74     public void setClipRect(Rectangle clipRect);
  75     public void setClipRectIndex(int index);
  76     public int getClipRectIndex();
  77     public float getExtraAlpha();
  78     public void setExtraAlpha(float extraAlpha);
  79     public void setLights(NGLightBase[] lights);
  80     public NGLightBase[] getLights();
  81     public Paint getPaint();
  82     public void setPaint(Paint paint);
  83     public BasicStroke getStroke();
  84     public void setStroke(BasicStroke stroke);
  85     public void setCompositeMode(CompositeMode mode);
  86     public CompositeMode getCompositeMode();
  87 
  88     /**
  89      * Clears the current {@code RenderTarget} with transparent pixels.
  90      * Note that this operation is affected by the current clip rectangle,
  91      * if set.  To clear the entire surface, call {@code setClipRect(null)}
  92      * prior to calling {@code clear()}.
  93      * <p>
  94      * This is equivalent to calling:
  95      * <code>
  96      * <pre>
  97      *     clear(Color.TRANSPARENT);
  98      * </pre>
  99      * </code>
 100      */
 101     public void clear();
 102     /**
 103      * Clears the current {@code RenderTarget} with the given {@code Color}.
 104      * Note that this operation is affected by the current clip rectangle,
 105      * if set.  To clear the entire surface, call {@code setClipRect(null)}
 106      * prior to calling {@code clear()}.
 107      */
 108     public void clear(Color color);
 109     /**
 110      * Clears the region represented by the given quad with transparent pixels.
 111      * Note that this operation is affected by the current clip rectangle,
 112      * if set, as well as the current transform (the quad is specified in
 113      * user space).  Also note that unlike the {@code clear()} methods, this
 114      * method does not attempt to clear the depth buffer.
 115      */
 116     public void clearQuad(float x1, float y1, float x2, float y2);
 117 
 118     public void fill(Shape shape);
 119     public void fillQuad(float x1, float y1, float x2, float y2);
 120     public void fillRect(float x, float y, float width, float height);
 121     public void fillRoundRect(float x, float y, float width, float height, float arcw, float arch);
 122     public void fillEllipse(float x, float y, float width, float height);
 123     public void draw(Shape shape);
 124     public void drawLine(float x1, float y1, float x2, float y2);
 125     public void drawRect(float x, float y, float width, float height);
 126     public void drawRoundRect(float x, float y, float width, float height, float arcw, float arch);
 127     public void drawEllipse(float x, float y, float width, float height);
 128 
 129     /**
 130      * Set the node bounds for any node that would like to render objects of a
 131      * different size to self.
 132      *
 133      * This is useful for proportional paints, where by definition proportional
 134      * paint should be stretched across node bounds to which it has been
 135      * applied.
 136      *
 137      * In most cases nodes/shapes are rendered in a single draw call, and if
 138      * needed bounds can be determined by inspecting object to be drawn.
 139      * However not all nodes are so simple, NGText for example can have
 140      * hundreds of Graphics.drawString(...), draw(...), and fill(...) calls per
 141      * a single NGText.renderContent().
 142      *
 143      * Use: Before making several draw calls from a single node,
 144      * setNodeBounds(bounds), when complete invalidate nodeBounds by
 145      * setNodeBounds(null).
 146      *
 147      * @param bounds should not include node transform
 148      */
 149     public void setNodeBounds(RectBounds bounds);
 150     public void drawString(GlyphList gl, FontStrike strike, float x, float y,
 151                            Color selectColor, int selectStart, int selectEnd);
 152 
 153     public void blit(RTTexture srcTex, RTTexture dstTex,
 154                      int srcX0, int srcY0, int srcX1, int srcY1,
 155                      int dstX0, int dstY0, int dstX1, int dstY1);
 156     public void drawTexture(Texture tex, float x, float y, float w, float h);
 157     public void drawTexture(Texture tex,
 158                             float dx1, float dy1, float dx2, float dy2,
 159                             float sx1, float sy1, float sx2, float sy2);
 160     public void drawTexture3SliceH(Texture tex,
 161                                    float dx1, float dy1, float dx2, float dy2,
 162                                    float sx1, float sy1, float sx2, float sy2,
 163                                    float dh1, float dh2, float sh1, float sh2);
 164     public void drawTexture3SliceV(Texture tex,
 165                                    float dx1, float dy1, float dx2, float dy2,
 166                                    float sx1, float sy1, float sx2, float sy2,
 167                                    float dv1, float dv2, float sv1, float sv2);
 168     public void drawTexture9Slice(Texture tex,
 169                                   float dx1, float dy1, float dx2, float dy2,
 170                                   float sx1, float sy1, float sx2, float sy2,
 171                                   float dh1, float dv1, float dh2, float dv2,
 172                                   float sh1, float sv1, float sh2, float sv2);
 173     public void drawTextureVO(Texture tex,
 174                               float topopacity, float botopacity,
 175                               float dx1, float dy1, float dx2, float dy2,
 176                               float sx1, float sy1, float sx2, float sy2);
 177     public void drawTextureRaw(Texture tex,
 178                                float dx1, float dy1, float dx2, float dy2,
 179                                float tx1, float ty1, float tx2, float ty2);
 180     public void drawMappedTextureRaw(Texture tex,
 181                                      float dx1, float dy1, float dx2, float dy2,
 182                                      float tx11, float ty11, float tx21, float ty21,
 183                                      float tx12, float ty12, float tx22, float ty22);
 184 
 185     /**
 186      * Synchronize, or flush, any outstanding rendering operations to the
 187      * destination in preparation for some caller potentially reusing or
 188      * disposing a resource that has been used as the source of a recently
 189      * invoked rendering operation.
 190      *
 191      * This method does not (yet?) guarantee that the actual pixels in the
 192      * destination will be updated - it simply guarantees that no currently
 193      * buffered rendering will depend on any texture data included by
 194      * reference.  The typical usage is before a {@code Texture} disposal
 195      * or "return to texture cache pool" operation.
 196      */
 197     public void sync();
 198 
 199     public Screen getAssociatedScreen();
 200     public ResourceFactory getResourceFactory();
 201     public RenderTarget getRenderTarget();
 202 
 203     public void setRenderRoot(NodePath root);
 204     public NodePath getRenderRoot();
 205 
 206     public void setState3D(boolean flag);
 207     public boolean isState3D();
 208 
 209     // TODO: 3D Get better name, and may want to move this into node render method.
 210     // TODO this is dangerous, must be called *after* setState3D is called, or it won't work
 211     public void setup3DRendering();
 212 
 213     public void setPixelScaleFactor(float pixelScale);
 214     public float getPixelScaleFactor();
 215 }