jdk/src/java.desktop/share/classes/sun/java2d/StateTracker.java
author lbourges
Mon, 23 Nov 2015 15:02:19 -0800
changeset 34419 14108cfd0823
parent 25859 3317bb8137f4
permissions -rw-r--r--
8143849: Integrate Marlin renderer per JEP 265 Reviewed-by: flar, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.java2d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * This interface is used to track changes to the complex data of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * object that implements the StateTrackable interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * The usage pattern for code accessing the trackable data is as follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *     StateTrackable trackedobject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *     MyInfo cacheddata;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *     StateTracker cachetracker;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *     public synchronized MyInfo getInfoAbout(StateTrackable obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *         if (trackedobject != obj || !cachetracker.isCurrent()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *             // Note: Always call getStateTracker() before
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *             // caching any data about the objct...
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *             cachetracker = obj.getStateTracker();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *             cacheddata = calculateInfoFrom(obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *             trackedobject = obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *         return cacheddata;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * Note that the sample code above works correctly regardless of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * {@link StateTrackable.State State} of the complex data of the object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * but it may be inefficient to store precalculated information about
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * an object whose current {@link StateTrackable.State State} is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * {@link StateTrackable.State#UNTRACKABLE UNTRACKABLE}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * and it is unnecessary to perform the {@link #isCurrent} test for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * data whose current {@link StateTrackable.State State} is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * {@link StateTrackable.State#IMMUTABLE IMMUTABLE}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * Optimizations to the sample code for either or both of those terminal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * States may be of benefit for some use cases, but is left out of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * example to reduce its complexity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * @see StateTrackable.State
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * @since 1.7
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
public interface StateTracker {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * An implementation of the StateTracker interface which
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * always returns true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * This implementation is useful for objects whose current
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * {@link StateTrackable.State State} is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * {@link StateTrackable.State#IMMUTABLE IMMUTABLE}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * @since 1.7
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    public StateTracker ALWAYS_CURRENT = new StateTracker() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        public boolean isCurrent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * An implementation of the StateTracker interface which
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * always returns false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * This implementation is useful for objects whose current
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * {@link StateTrackable.State State} is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * {@link StateTrackable.State#UNTRACKABLE UNTRACKABLE}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * This implementation may also be useful for some objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * whose current {@link StateTrackable.State State} is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * {@link StateTrackable.State#DYNAMIC DYNAMIC}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * @since 1.7
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    public StateTracker NEVER_CURRENT = new StateTracker() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        public boolean isCurrent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * Returns true iff the contents of the complex data of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * associated StateTrackable object have not changed since
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * the time that this StateTracker was returned from its
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * getStateTracker() method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * @see StateTrackable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * @since 1.7
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    public boolean isCurrent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
}