modules/graphics/src/main/java/com/sun/prism/impl/ps/BaseShaderGraphics.java

Print this page


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


 430         Gradient grad = (Gradient)paint;
 431         TEMP_TX2D.setToTranslation(-dx1, -dy1);
 432         TEMP_TX2D.concatenate(xform);
 433         Texture tex = context.getGradientTexture(grad, TEMP_TX2D,
 434                                                  maskW, maskH, maskData,
 435                                                  bx, by, bw, bh);
 436 
 437         float tx1 = 0f;
 438         float ty1 = 0f;
 439         float tx2 = tx1 + ((float)maskW) / tex.getPhysicalWidth();
 440         float ty2 = ty1 + ((float)maskH) / tex.getPhysicalHeight();
 441 
 442         // the mask has been generated in device space, so we use
 443         // identity transform here
 444         VertexBuffer vb = context.getVertexBuffer();
 445         context.validateTextureOp(this, IDENT, tex, null, tex.getPixelFormat());
 446         vb.addQuad(dx1, dy1, dx2, dy2, tx1, ty1, tx2, ty2);
 447         tex.unlock();
 448     }
 449 

 450     @Override
 451     protected void renderShape(Shape shape, BasicStroke stroke,
 452                                float bx, float by, float bw, float bh)
 453     {
 454         if (isComplexPaint) {
 455             renderWithComplexPaint(shape, stroke, bx, by, bw, bh);
 456             return;
 457         }
 458 
 459         // creating/updating the mask texture may unset the current
 460         // texture used by pending vertices, so flush the vertex buffer first
 461         context.flushVertexBuffer();
 462 
 463         // The following is safe; this method does not mutate the transform
 464         BaseTransform xform = getTransformNoClone();
 465         MaskData maskData =
 466             ShapeUtil.rasterizeShape(shape, stroke, getFinalClipNoClone(), xform, true, isAntialiasedShape());
 467         Texture maskTex = context.getMaskTexture(maskData, false);
 468         int maskW = maskData.getWidth();
 469         int maskH = maskData.getHeight();
 470 
 471         float dx1 = maskData.getOriginX();
 472         float dy1 = maskData.getOriginY();
 473         float dx2 = dx1 + maskW;
 474         float dy2 = dy1 + maskH;
 475         float tx1 = 0f;
 476         float ty1 = 0f;
 477         float tx2 = tx1 + ((float)maskW) / maskTex.getPhysicalWidth();
 478         float ty2 = ty1 + ((float)maskH) / maskTex.getPhysicalHeight();
 479 

 480         if (PrismSettings.primTextureSize != 0) {
 481             // the mask has been generated in device space, so we use
 482             // identity transform here
 483             Shader shader =
 484                 context.validatePaintOp(this, IDENT, MaskType.ALPHA_TEXTURE, maskTex,
 485                                         bx, by, bw, bh);
 486 
 487             VertexBuffer vb = context.getVertexBuffer();
 488             vb.addQuad(dx1, dy1, dx2, dy2, tx1, ty1, tx2, ty2,
 489                     getPaintTextureTx(xform, shader, bx, by, bw, bh));
 490         } else {        
 491             // the mask has been generated in device space, so we use
 492             // identity transform here
 493             context.validatePaintOp(this, IDENT, maskTex, bx, by, bw, bh);













 494 
 495             VertexBuffer vb = context.getVertexBuffer();
 496             vb.addQuad(dx1, dy1, dx2, dy2, tx1, ty1, tx2, ty2);
 497         }
 498         maskTex.unlock();
 499     }
 500 
 501     private static float getStrokeExpansionFactor(BasicStroke stroke) {
 502         if (stroke.getType() == BasicStroke.TYPE_OUTER) {
 503             return 1f;
 504         } else if (stroke.getType() == BasicStroke.TYPE_CENTERED) {
 505             return 0.5f;
 506         } else {
 507             return 0f;
 508         }
 509     }
 510 
 511     private static final float FRINGE_FACTOR;
 512     static {
 513         String v = (String) AccessController.doPrivileged((PrivilegedAction) () -> System.getProperty("prism.primshaderpad"));
 514         if (v == null) {
 515             FRINGE_FACTOR = -0.5f;
 516         } else {
 517             FRINGE_FACTOR = -Float.valueOf(v);


   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


 430         Gradient grad = (Gradient)paint;
 431         TEMP_TX2D.setToTranslation(-dx1, -dy1);
 432         TEMP_TX2D.concatenate(xform);
 433         Texture tex = context.getGradientTexture(grad, TEMP_TX2D,
 434                                                  maskW, maskH, maskData,
 435                                                  bx, by, bw, bh);
 436 
 437         float tx1 = 0f;
 438         float ty1 = 0f;
 439         float tx2 = tx1 + ((float)maskW) / tex.getPhysicalWidth();
 440         float ty2 = ty1 + ((float)maskH) / tex.getPhysicalHeight();
 441 
 442         // the mask has been generated in device space, so we use
 443         // identity transform here
 444         VertexBuffer vb = context.getVertexBuffer();
 445         context.validateTextureOp(this, IDENT, tex, null, tex.getPixelFormat());
 446         vb.addQuad(dx1, dy1, dx2, dy2, tx1, ty1, tx2, ty2);
 447         tex.unlock();
 448     }
 449 
 450     private static RectBounds TMP_BOUNDS = new RectBounds();
 451     @Override
 452     protected void renderShape(Shape shape, BasicStroke stroke,
 453                                float bx, float by, float bw, float bh)
 454     {
 455         if (isComplexPaint) {
 456             renderWithComplexPaint(shape, stroke, bx, by, bw, bh);
 457             return;
 458         }
 459 




 460         // The following is safe; this method does not mutate the transform
 461         BaseTransform xform = getTransformNoClone();
 462         MaskData maskData =
 463             ShapeUtil.rasterizeShape(shape, stroke, getFinalClipNoClone(), xform, true, isAntialiasedShape());
 464         Texture maskTex = context.validateMaskTexture(maskData, false);











 465 
 466         AffineBase paintTx;
 467         if (PrismSettings.primTextureSize != 0) {
 468             // the mask has been generated in device space, so we use
 469             // identity transform here
 470             Shader shader =
 471                 context.validatePaintOp(this, IDENT, MaskType.ALPHA_TEXTURE, maskTex,
 472                                         bx, by, bw, bh);
 473 
 474             paintTx = getPaintTextureTx(xform, shader, bx, by, bw, bh);


 475         } else {        
 476             // the mask has been generated in device space, so we use
 477             // identity transform here
 478             context.validatePaintOp(this, IDENT, maskTex, bx, by, bw, bh);
 479             paintTx = null;
 480         }
 481 
 482         context.updateMaskTexture(maskData, TMP_BOUNDS, false);
 483 
 484         float dx1 = maskData.getOriginX();
 485         float dy1 = maskData.getOriginY();
 486         float dx2 = dx1 + maskData.getWidth();
 487         float dy2 = dy1 + maskData.getHeight();
 488         float tx1 = TMP_BOUNDS.getMinX();
 489         float ty1 = TMP_BOUNDS.getMinY();
 490         float tx2 = TMP_BOUNDS.getMaxX();
 491         float ty2 = TMP_BOUNDS.getMaxY();
 492 
 493         VertexBuffer vb = context.getVertexBuffer();
 494         vb.addQuad(dx1, dy1, dx2, dy2, tx1, ty1, tx2, ty2, paintTx);
 495 
 496         maskTex.unlock();
 497     }
 498 
 499     private static float getStrokeExpansionFactor(BasicStroke stroke) {
 500         if (stroke.getType() == BasicStroke.TYPE_OUTER) {
 501             return 1f;
 502         } else if (stroke.getType() == BasicStroke.TYPE_CENTERED) {
 503             return 0.5f;
 504         } else {
 505             return 0f;
 506         }
 507     }
 508 
 509     private static final float FRINGE_FACTOR;
 510     static {
 511         String v = (String) AccessController.doPrivileged((PrivilegedAction) () -> System.getProperty("prism.primshaderpad"));
 512         if (v == null) {
 513             FRINGE_FACTOR = -0.5f;
 514         } else {
 515             FRINGE_FACTOR = -Float.valueOf(v);