1 /*
   2  * Copyright (c) 2011, 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.javafx.util;
  27 
  28 import com.sun.javafx.geom.BaseBounds;
  29 import com.sun.javafx.geom.RectBounds;
  30 import com.sun.javafx.geom.transform.Affine3D;
  31 import com.sun.javafx.geom.transform.BaseTransform;
  32 import com.sun.javafx.geom.transform.GeneralTransform3D;
  33 
  34 /**************************************************************************
  35  *                                                                        *
  36  * Temporary state, used to reduce the occurrence of temporary garbage    *
  37  * while computing things such as bounds and transforms, and while        *
  38  * picking. Since these operations happen extremely often and must be     *
  39  * very fast, we need to reduce the load on the garbage collector.        *
  40  *                                                                        *
  41  *************************************************************************/
  42 public final class TempState {
  43     /**
  44      * A temporary rect used for computing bounds by the various bounds
  45      * variables. This bounds starts life as a RectBounds, but may be promoted
  46      * to a BoxBounds if there is a 3D transform mixed into its computation.
  47      */
  48     public BaseBounds bounds = new RectBounds(0, 0, -1, -1);
  49 
  50     /**
  51      * A temporary affine transform used when picking to avoid creating
  52      * temporary garbage.
  53      */
  54     public final BaseTransform pickTx = new Affine3D();
  55 
  56     /**
  57      * A temporary affine transform used by the path transition to avoid
  58      * creating temporary garbage.
  59      */
  60     public final Affine3D leafTx = new Affine3D();
  61 
  62     /**
  63      * A temporary point used for picking and other purposes.
  64      */
  65     public final com.sun.javafx.geom.Point2D point =
  66         new com.sun.javafx.geom.Point2D(0, 0);
  67 
  68     public final com.sun.javafx.geom.Vec3d vec3d =
  69         new com.sun.javafx.geom.Vec3d(0, 0, 0);
  70 
  71 
  72     /**
  73      * A temporary general transform used by LOD helper method, in node,
  74      * to compute area in scene.
  75      */
  76     public final GeneralTransform3D projViewTx = new GeneralTransform3D();
  77 
  78    /**
  79      * A temporary affine transform used by the LOD helper method to get an
  80      * affine transform.
  81      */
  82     public final Affine3D tempTx = new Affine3D();
  83 
  84     private static final ThreadLocal<TempState> tempStateRef =
  85             new ThreadLocal<TempState>() {
  86                 @Override
  87                 protected TempState initialValue() {
  88                     return new TempState();
  89                 }
  90             };
  91 
  92     private TempState() {
  93     }
  94 
  95     public static TempState getInstance() {
  96         return tempStateRef.get();
  97     }
  98 }