< prev index next >

modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGCanvas.java

Print this page


   1 /*
   2  * Copyright (c) 2012, 2016, 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


  81     public static final byte GLOBAL_ALPHA  = ATTR_BASE + 0;
  82     public static final byte COMP_MODE     = ATTR_BASE + 1;
  83     public static final byte FILL_PAINT    = ATTR_BASE + 2;
  84     public static final byte STROKE_PAINT  = ATTR_BASE + 3;
  85     public static final byte LINE_WIDTH    = ATTR_BASE + 4;
  86     public static final byte LINE_CAP      = ATTR_BASE + 5;
  87     public static final byte LINE_JOIN     = ATTR_BASE + 6;
  88     public static final byte MITER_LIMIT   = ATTR_BASE + 7;
  89     public static final byte FONT          = ATTR_BASE + 8;
  90     public static final byte TEXT_ALIGN    = ATTR_BASE + 9;
  91     public static final byte TEXT_BASELINE = ATTR_BASE + 10;
  92     public static final byte TRANSFORM     = ATTR_BASE + 11;
  93     public static final byte EFFECT        = ATTR_BASE + 12;
  94     public static final byte PUSH_CLIP     = ATTR_BASE + 13;
  95     public static final byte POP_CLIP      = ATTR_BASE + 14;
  96     public static final byte ARC_TYPE      = ATTR_BASE + 15;
  97     public static final byte FILL_RULE     = ATTR_BASE + 16;
  98     public static final byte DASH_ARRAY    = ATTR_BASE + 17;
  99     public static final byte DASH_OFFSET   = ATTR_BASE + 18;
 100     public static final byte FONT_SMOOTH   = ATTR_BASE + 19;

 101 
 102     public static final byte                     OP_BASE = 20;
 103     public static final byte FILL_RECT         = OP_BASE + 0;
 104     public static final byte STROKE_RECT       = OP_BASE + 1;
 105     public static final byte CLEAR_RECT        = OP_BASE + 2;
 106     public static final byte STROKE_LINE       = OP_BASE + 3;
 107     public static final byte FILL_OVAL         = OP_BASE + 4;
 108     public static final byte STROKE_OVAL       = OP_BASE + 5;
 109     public static final byte FILL_ROUND_RECT   = OP_BASE + 6;
 110     public static final byte STROKE_ROUND_RECT = OP_BASE + 7;
 111     public static final byte FILL_ARC          = OP_BASE + 8;
 112     public static final byte STROKE_ARC        = OP_BASE + 9;
 113     public static final byte FILL_TEXT         = OP_BASE + 10;
 114     public static final byte STROKE_TEXT       = OP_BASE + 11;
 115 
 116     public static final byte                PATH_BASE = 40;
 117     public static final byte PATHSTART    = PATH_BASE + 0;
 118     public static final byte MOVETO       = PATH_BASE + 1;
 119     public static final byte LINETO       = PATH_BASE + 2;
 120     public static final byte QUADTO       = PATH_BASE + 3;
 121     public static final byte CUBICTO      = PATH_BASE + 4;
 122     public static final byte CLOSEPATH    = PATH_BASE + 5;


 317     private int tw, th;
 318     private int cw, ch;
 319     private RenderBuf cv;
 320     private RenderBuf temp;
 321     private RenderBuf clip;
 322 
 323     private float globalAlpha;
 324     private Blend.Mode blendmode;
 325     private Paint fillPaint, strokePaint;
 326     private float linewidth;
 327     private int linecap, linejoin;
 328     private float miterlimit;
 329     private double[] dashes;
 330     private float dashOffset;
 331     private BasicStroke stroke;
 332     private Path2D path;
 333     private NGText ngtext;
 334     private PrismTextLayout textLayout;
 335     private PGFont pgfont;
 336     private int smoothing;

 337     private int align;
 338     private int baseline;
 339     private Affine2D transform;
 340     private Affine2D inverseTransform;
 341     private boolean inversedirty;
 342     private LinkedList<Path2D> clipStack;
 343     private int clipsRendered;
 344     private boolean clipIsRect;
 345     private Rectangle clipRect;
 346     private Effect effect;
 347     private int arctype;
 348 
 349     static float TEMP_COORDS[] = new float[6];
 350     private static Arc2D TEMP_ARC = new Arc2D();
 351     private static RectBounds TEMP_RECTBOUNDS = new RectBounds();
 352 
 353     public NGCanvas() {
 354         Toolkit tk = Toolkit.getToolkit();
 355         ScreenConfigurationAccessor screenAccessor = tk.getScreenConfigurationAccessor();
 356         float hPS = 1.0f;


 372         initAttributes();
 373     }
 374 
 375     private void initAttributes() {
 376         globalAlpha = 1.0f;
 377         blendmode = Mode.SRC_OVER;
 378         fillPaint = Color.BLACK;
 379         strokePaint = Color.BLACK;
 380         linewidth = 1.0f;
 381         linecap = BasicStroke.CAP_SQUARE;
 382         linejoin = BasicStroke.JOIN_MITER;
 383         miterlimit = 10f;
 384         dashes = null;
 385         dashOffset = 0.0f;
 386         stroke = null;
 387         path.setWindingRule(Path2D.WIND_NON_ZERO);
 388         // ngtext stores no state between render operations
 389         // textLayout stores no state between render operations
 390         pgfont = (PGFont) FontHelper.getNativeFont(Font.getDefault());
 391         smoothing = SMOOTH_GRAY;

 392         align = ALIGN_LEFT;
 393         baseline = VPos.BASELINE.ordinal();
 394         transform.setToScale(highestPixelScale, highestPixelScale);
 395         clipStack.clear();
 396         resetClip(false);
 397     }
 398 
 399     static final Affine2D TEMP_PATH_TX = new Affine2D();
 400     static final int numCoords[] = { 2, 2, 4, 6, 0 };
 401     Shape untransformedPath = new Shape() {
 402 
 403         @Override
 404         public RectBounds getBounds() {
 405             if (transform.isTranslateOrIdentity()) {
 406                 RectBounds rb = path.getBounds();
 407                 if (transform.isIdentity()) {
 408                     return rb;
 409                 } else {
 410                     float tx = (float) transform.getMxt();
 411                     float ty = (float) transform.getMyt();


 986                     stroke = null;
 987                     break;
 988                 case MITER_LIMIT:
 989                     miterlimit = buf.getFloat();
 990                     stroke = null;
 991                     break;
 992                 case DASH_ARRAY:
 993                     dashes = (double[]) buf.getObject();
 994                     stroke = null;
 995                     break;
 996                 case DASH_OFFSET:
 997                     dashOffset = buf.getFloat();
 998                     stroke = null;
 999                     break;
1000                 case FONT:
1001                     pgfont = (PGFont) buf.getObject();
1002                     break;
1003                 case FONT_SMOOTH:
1004                     smoothing = buf.getUByte();
1005                     break;



1006                 case TEXT_ALIGN:
1007                     align = buf.getUByte();
1008                     break;
1009                 case TEXT_BASELINE:
1010                     baseline = prbases[buf.getUByte()];
1011                     break;
1012                 case FX_APPLY_EFFECT:
1013                 {
1014                     Effect e = (Effect) buf.getObject();
1015                     RenderBuf dest = clipStack.isEmpty() ? cv : temp;
1016                     BaseTransform tx;
1017                     if (highestPixelScale != 1.0f) {
1018                         TEMP_TX.setToScale(highestPixelScale, highestPixelScale);
1019                         tx = TEMP_TX;
1020                         cv.input.setPixelScale(highestPixelScale);
1021                     } else {
1022                         tx = BaseTransform.IDENTITY_TRANSFORM;
1023                     }
1024                     applyEffectOnAintoC(cv.input, e,
1025                                         tx, null,


1328                     sx = buf.getFloat();
1329                     sy = buf.getFloat();
1330                     sw = buf.getFloat();
1331                     sh = buf.getFloat();
1332                     float ps = img.getPixelScale();
1333                     if (ps != 1.0f) {
1334                         sx *= ps;
1335                         sy *= ps;
1336                         sw *= ps;
1337                         sh *= ps;
1338                     }
1339                 }
1340                 if (bounds != null) {
1341                     bounds.setBounds(dx, dy, dx+dw, dy+dh);
1342                     transformBounds = true;
1343                 }
1344                 if (gr != null) {
1345                     ResourceFactory factory = gr.getResourceFactory();
1346                     Texture tex =
1347                         factory.getCachedTexture(img, Texture.WrapMode.CLAMP_TO_EDGE);




1348                     gr.drawTexture(tex,
1349                                    dx, dy, dx+dw, dy+dh,
1350                                    sx, sy, sx+sw, sy+sh);



1351                     tex.unlock();
1352                 }
1353                 break;
1354             }
1355             case FILL_TEXT:
1356             case STROKE_TEXT:
1357             {
1358                 float x = buf.getFloat();
1359                 float y = buf.getFloat();
1360                 float maxWidth = buf.getFloat();
1361                 boolean rtl = buf.getBoolean();
1362                 String string = (String) buf.getObject();
1363                 int dir = rtl ? PrismTextLayout.DIRECTION_RTL :
1364                                 PrismTextLayout.DIRECTION_LTR;
1365 
1366                 textLayout.setContent(string, pgfont);
1367                 textLayout.setAlignment(align);
1368                 textLayout.setDirection(dir);
1369                 float xAlign = 0, yAlign = 0;
1370                 BaseBounds layoutBounds = textLayout.getBounds();


   1 /*
   2  * Copyright (c) 2012, 2018, 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


  81     public static final byte GLOBAL_ALPHA  = ATTR_BASE + 0;
  82     public static final byte COMP_MODE     = ATTR_BASE + 1;
  83     public static final byte FILL_PAINT    = ATTR_BASE + 2;
  84     public static final byte STROKE_PAINT  = ATTR_BASE + 3;
  85     public static final byte LINE_WIDTH    = ATTR_BASE + 4;
  86     public static final byte LINE_CAP      = ATTR_BASE + 5;
  87     public static final byte LINE_JOIN     = ATTR_BASE + 6;
  88     public static final byte MITER_LIMIT   = ATTR_BASE + 7;
  89     public static final byte FONT          = ATTR_BASE + 8;
  90     public static final byte TEXT_ALIGN    = ATTR_BASE + 9;
  91     public static final byte TEXT_BASELINE = ATTR_BASE + 10;
  92     public static final byte TRANSFORM     = ATTR_BASE + 11;
  93     public static final byte EFFECT        = ATTR_BASE + 12;
  94     public static final byte PUSH_CLIP     = ATTR_BASE + 13;
  95     public static final byte POP_CLIP      = ATTR_BASE + 14;
  96     public static final byte ARC_TYPE      = ATTR_BASE + 15;
  97     public static final byte FILL_RULE     = ATTR_BASE + 16;
  98     public static final byte DASH_ARRAY    = ATTR_BASE + 17;
  99     public static final byte DASH_OFFSET   = ATTR_BASE + 18;
 100     public static final byte FONT_SMOOTH   = ATTR_BASE + 19;
 101     public static final byte IMAGE_SMOOTH  = ATTR_BASE + 20;
 102 
 103     public static final byte                     OP_BASE = 25;
 104     public static final byte FILL_RECT         = OP_BASE + 0;
 105     public static final byte STROKE_RECT       = OP_BASE + 1;
 106     public static final byte CLEAR_RECT        = OP_BASE + 2;
 107     public static final byte STROKE_LINE       = OP_BASE + 3;
 108     public static final byte FILL_OVAL         = OP_BASE + 4;
 109     public static final byte STROKE_OVAL       = OP_BASE + 5;
 110     public static final byte FILL_ROUND_RECT   = OP_BASE + 6;
 111     public static final byte STROKE_ROUND_RECT = OP_BASE + 7;
 112     public static final byte FILL_ARC          = OP_BASE + 8;
 113     public static final byte STROKE_ARC        = OP_BASE + 9;
 114     public static final byte FILL_TEXT         = OP_BASE + 10;
 115     public static final byte STROKE_TEXT       = OP_BASE + 11;
 116 
 117     public static final byte                PATH_BASE = 40;
 118     public static final byte PATHSTART    = PATH_BASE + 0;
 119     public static final byte MOVETO       = PATH_BASE + 1;
 120     public static final byte LINETO       = PATH_BASE + 2;
 121     public static final byte QUADTO       = PATH_BASE + 3;
 122     public static final byte CUBICTO      = PATH_BASE + 4;
 123     public static final byte CLOSEPATH    = PATH_BASE + 5;


 318     private int tw, th;
 319     private int cw, ch;
 320     private RenderBuf cv;
 321     private RenderBuf temp;
 322     private RenderBuf clip;
 323 
 324     private float globalAlpha;
 325     private Blend.Mode blendmode;
 326     private Paint fillPaint, strokePaint;
 327     private float linewidth;
 328     private int linecap, linejoin;
 329     private float miterlimit;
 330     private double[] dashes;
 331     private float dashOffset;
 332     private BasicStroke stroke;
 333     private Path2D path;
 334     private NGText ngtext;
 335     private PrismTextLayout textLayout;
 336     private PGFont pgfont;
 337     private int smoothing;
 338     private boolean imageSmoothing;
 339     private int align;
 340     private int baseline;
 341     private Affine2D transform;
 342     private Affine2D inverseTransform;
 343     private boolean inversedirty;
 344     private LinkedList<Path2D> clipStack;
 345     private int clipsRendered;
 346     private boolean clipIsRect;
 347     private Rectangle clipRect;
 348     private Effect effect;
 349     private int arctype;
 350 
 351     static float TEMP_COORDS[] = new float[6];
 352     private static Arc2D TEMP_ARC = new Arc2D();
 353     private static RectBounds TEMP_RECTBOUNDS = new RectBounds();
 354 
 355     public NGCanvas() {
 356         Toolkit tk = Toolkit.getToolkit();
 357         ScreenConfigurationAccessor screenAccessor = tk.getScreenConfigurationAccessor();
 358         float hPS = 1.0f;


 374         initAttributes();
 375     }
 376 
 377     private void initAttributes() {
 378         globalAlpha = 1.0f;
 379         blendmode = Mode.SRC_OVER;
 380         fillPaint = Color.BLACK;
 381         strokePaint = Color.BLACK;
 382         linewidth = 1.0f;
 383         linecap = BasicStroke.CAP_SQUARE;
 384         linejoin = BasicStroke.JOIN_MITER;
 385         miterlimit = 10f;
 386         dashes = null;
 387         dashOffset = 0.0f;
 388         stroke = null;
 389         path.setWindingRule(Path2D.WIND_NON_ZERO);
 390         // ngtext stores no state between render operations
 391         // textLayout stores no state between render operations
 392         pgfont = (PGFont) FontHelper.getNativeFont(Font.getDefault());
 393         smoothing = SMOOTH_GRAY;
 394         imageSmoothing = true;
 395         align = ALIGN_LEFT;
 396         baseline = VPos.BASELINE.ordinal();
 397         transform.setToScale(highestPixelScale, highestPixelScale);
 398         clipStack.clear();
 399         resetClip(false);
 400     }
 401 
 402     static final Affine2D TEMP_PATH_TX = new Affine2D();
 403     static final int numCoords[] = { 2, 2, 4, 6, 0 };
 404     Shape untransformedPath = new Shape() {
 405 
 406         @Override
 407         public RectBounds getBounds() {
 408             if (transform.isTranslateOrIdentity()) {
 409                 RectBounds rb = path.getBounds();
 410                 if (transform.isIdentity()) {
 411                     return rb;
 412                 } else {
 413                     float tx = (float) transform.getMxt();
 414                     float ty = (float) transform.getMyt();


 989                     stroke = null;
 990                     break;
 991                 case MITER_LIMIT:
 992                     miterlimit = buf.getFloat();
 993                     stroke = null;
 994                     break;
 995                 case DASH_ARRAY:
 996                     dashes = (double[]) buf.getObject();
 997                     stroke = null;
 998                     break;
 999                 case DASH_OFFSET:
1000                     dashOffset = buf.getFloat();
1001                     stroke = null;
1002                     break;
1003                 case FONT:
1004                     pgfont = (PGFont) buf.getObject();
1005                     break;
1006                 case FONT_SMOOTH:
1007                     smoothing = buf.getUByte();
1008                     break;
1009                 case IMAGE_SMOOTH:
1010                     imageSmoothing = buf.getBoolean();
1011                     break;
1012                 case TEXT_ALIGN:
1013                     align = buf.getUByte();
1014                     break;
1015                 case TEXT_BASELINE:
1016                     baseline = prbases[buf.getUByte()];
1017                     break;
1018                 case FX_APPLY_EFFECT:
1019                 {
1020                     Effect e = (Effect) buf.getObject();
1021                     RenderBuf dest = clipStack.isEmpty() ? cv : temp;
1022                     BaseTransform tx;
1023                     if (highestPixelScale != 1.0f) {
1024                         TEMP_TX.setToScale(highestPixelScale, highestPixelScale);
1025                         tx = TEMP_TX;
1026                         cv.input.setPixelScale(highestPixelScale);
1027                     } else {
1028                         tx = BaseTransform.IDENTITY_TRANSFORM;
1029                     }
1030                     applyEffectOnAintoC(cv.input, e,
1031                                         tx, null,


1334                     sx = buf.getFloat();
1335                     sy = buf.getFloat();
1336                     sw = buf.getFloat();
1337                     sh = buf.getFloat();
1338                     float ps = img.getPixelScale();
1339                     if (ps != 1.0f) {
1340                         sx *= ps;
1341                         sy *= ps;
1342                         sw *= ps;
1343                         sh *= ps;
1344                     }
1345                 }
1346                 if (bounds != null) {
1347                     bounds.setBounds(dx, dy, dx+dw, dy+dh);
1348                     transformBounds = true;
1349                 }
1350                 if (gr != null) {
1351                     ResourceFactory factory = gr.getResourceFactory();
1352                     Texture tex =
1353                         factory.getCachedTexture(img, Texture.WrapMode.CLAMP_TO_EDGE);
1354                     boolean isSmooth = tex.getLinearFiltering();
1355                     if (imageSmoothing != isSmooth) {
1356                         tex.setLinearFiltering(imageSmoothing);
1357                     }
1358                     gr.drawTexture(tex,
1359                                    dx, dy, dx+dw, dy+dh,
1360                                    sx, sy, sx+sw, sy+sh);
1361                     if (imageSmoothing != isSmooth) {
1362                         tex.setLinearFiltering(isSmooth);
1363                     }
1364                     tex.unlock();
1365                 }
1366                 break;
1367             }
1368             case FILL_TEXT:
1369             case STROKE_TEXT:
1370             {
1371                 float x = buf.getFloat();
1372                 float y = buf.getFloat();
1373                 float maxWidth = buf.getFloat();
1374                 boolean rtl = buf.getBoolean();
1375                 String string = (String) buf.getObject();
1376                 int dir = rtl ? PrismTextLayout.DIRECTION_RTL :
1377                                 PrismTextLayout.DIRECTION_LTR;
1378 
1379                 textLayout.setContent(string, pgfont);
1380                 textLayout.setAlignment(align);
1381                 textLayout.setDirection(dir);
1382                 float xAlign = 0, yAlign = 0;
1383                 BaseBounds layoutBounds = textLayout.getBounds();


< prev index next >