jdk/src/java.desktop/share/classes/sun/java2d/SurfaceDataProxy.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
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 21278
diff changeset
     2
 * Copyright (c) 2007, 2013, 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: 887
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: 887
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: 887
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 887
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 887
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
import java.awt.Color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.Rectangle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.AlphaComposite;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.GraphicsEnvironment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import sun.awt.DisplayChangedListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import sun.java2d.StateTrackable.State;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import sun.java2d.loops.CompositeType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import sun.java2d.loops.SurfaceType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.java2d.loops.Blit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import sun.java2d.loops.BlitBg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import sun.awt.image.SurfaceManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import sun.awt.image.SurfaceManager.FlushableCacheData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import sun.security.action.GetPropertyAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * The proxy class encapsulates the logic for managing alternate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * SurfaceData representations of a primary SurfaceData.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * The main class will handle tracking the state changes of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * primary SurfaceData and updating the associated SurfaceData
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * proxy variants.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * Subclasses have 2 main responsibilities:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * <li> Override the isSupportedOperation() method to determine if
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *      a given operation can be accelerated with a given source
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *      SurfaceData
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <li> Override the validateSurfaceData() method to create or update
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *      a given accelerated surface to hold the pixels for the indicated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *      source SurfaceData
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * If necessary, a subclass may also override the updateSurfaceData
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * method to transfer the pixels to the accelerated surface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * By default the parent class will transfer the pixels using a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * standard Blit operation between the two SurfaceData objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
public abstract class SurfaceDataProxy
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    implements DisplayChangedListener, SurfaceManager.FlushableCacheData
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private static boolean cachingAllowed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    private static int defaultThreshold;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        cachingAllowed = true;
11080
7e18e343964e 7117914: Fix javac warnings in src/share/classes/sun/java2d
neugens
parents: 5506
diff changeset
    74
        String manimg = AccessController.doPrivileged(
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            new GetPropertyAction("sun.java2d.managedimages"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        if (manimg != null && manimg.equals("false")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            cachingAllowed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            System.out.println("Disabling managed images");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        defaultThreshold = 1;
11080
7e18e343964e 7117914: Fix javac warnings in src/share/classes/sun/java2d
neugens
parents: 5506
diff changeset
    82
        String num = AccessController.doPrivileged(
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            new GetPropertyAction("sun.java2d.accthreshold"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        if (num != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                int parsed = Integer.parseInt(num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                if (parsed >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                    defaultThreshold = parsed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                    System.out.println("New Default Acceleration Threshold: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                                       defaultThreshold);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            } catch (NumberFormatException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                System.err.println("Error setting new threshold:" + e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    public static boolean isCachingAllowed() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        return cachingAllowed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * Determine if an alternate form for the srcData is needed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * and appropriate from the given operational parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    public abstract boolean isSupportedOperation(SurfaceData srcData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                                                 int txtype,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                                                 CompositeType comp,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                                                 Color bgColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * Construct an alternate form of the given SurfaceData.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * The contents of the returned SurfaceData may be undefined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * since the calling code will take care of updating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * contents with a subsequent call to updateSurfaceData.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * If the method returns null then there was a problem with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * allocating the accelerated surface.  The getRetryTracker()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * method will be called to track when to attempt another
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * revalidation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    public abstract SurfaceData validateSurfaceData(SurfaceData srcData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                                                    SurfaceData cachedData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                                                    int w, int h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * If the subclass is unable to validate or create a cached
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * SurfaceData then this method will be used to get a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * StateTracker object that will indicate when to attempt
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * to validate the surface again.  Subclasses may return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * trackers which count down an ever increasing threshold
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * to provide hysteresis on creating surfaces during low
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * memory conditions.  The default implementation just waits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * another "threshold" number of accesses before trying again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    public StateTracker getRetryTracker(SurfaceData srcData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        return new CountdownTracker(threshold);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    public static class CountdownTracker implements StateTracker {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        private int countdown;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        public CountdownTracker(int threshold) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            this.countdown = threshold;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        public synchronized boolean isCurrent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            return (--countdown >= 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * This instance is for cases where a caching implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * determines that a particular source image will never need
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * to be cached - either the source SurfaceData was of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * incompatible type, or it was in an UNTRACKABLE state or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * some other factor is discovered that permanently prevents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * acceleration or caching.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * This class optimally implements NOP variants of all necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * methods to avoid caching with a minimum of fuss.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    public static SurfaceDataProxy UNCACHED = new SurfaceDataProxy(0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        public boolean isAccelerated() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        public boolean isSupportedOperation(SurfaceData srcData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                                            int txtype,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                                            CompositeType comp,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                                            Color bgColor)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        public SurfaceData validateSurfaceData(SurfaceData srcData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                                               SurfaceData cachedData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                                               int w, int h)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            throw new InternalError("UNCACHED should never validate SDs");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        public SurfaceData replaceData(SurfaceData srcData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                                       int txtype,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                                       CompositeType comp,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                                       Color bgColor)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            // Not necessary to override this, but doing so is faster
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            return srcData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    // The number of attempts to copy from a STABLE source before
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    // a cached copy is created or updated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    private int threshold;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * Source tracking data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * Every time that srcTracker is out of date we will reset numtries
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * to threshold and set the cacheTracker to one that is non-current.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * numtries will then count down to 0 at which point the cacheTracker
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * will remind us that we need to update the cachedSD before we can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * use it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * Note that since these fields interrelate we should synchronize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * whenever we update them, but it should be OK to read them
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * without synchronization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    private StateTracker srcTracker;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    private int numtries;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * Cached data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * We cache a SurfaceData created by the subclass in cachedSD and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * track its state (isValid and !surfaceLost) in cacheTracker.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * Also, when we want to note that cachedSD needs to be updated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * we replace the cacheTracker with a NEVER_CURRENT tracker which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * will cause us to try to revalidate and update the surface on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * next use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    private SurfaceData cachedSD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    private StateTracker cacheTracker;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * Are we still the best object to control caching of data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * for the source image?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    private boolean valid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * Create a SurfaceData proxy manager that attempts to create
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * and cache a variant copy of the source SurfaceData after
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * the default threshold number of attempts to copy from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * STABLE source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    public SurfaceDataProxy() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        this(defaultThreshold);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * Create a SurfaceData proxy manager that attempts to create
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * and cache a variant copy of the source SurfaceData after
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * the specified threshold number of attempts to copy from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * the STABLE source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    public SurfaceDataProxy(int threshold) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        this.threshold = threshold;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        this.srcTracker = StateTracker.NEVER_CURRENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        // numtries will be reset on first use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        this.cacheTracker = StateTracker.NEVER_CURRENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        this.valid = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * Returns true iff this SurfaceData proxy is still the best
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * way to control caching of the given source on the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * destination.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    public boolean isValid() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        return valid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * Sets the valid state to false so that the next time this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * proxy is fetched to generate a replacement SurfaceData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * the code in SurfaceData knows to replace the proxy first.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    public void invalidate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        this.valid = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * Flush all cached resources as per the FlushableCacheData interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * The deaccelerated parameter indicates if the flush is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * happening because the associated surface is no longer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * being accelerated (for instance the acceleration priority
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * is set below the threshold needed for acceleration).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * Returns a boolean that indicates if the cached object is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * no longer needed and should be removed from the cache.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    public boolean flush(boolean deaccelerated) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        if (deaccelerated) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        return !isValid();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * Actively flushes (drops and invalidates) the cached surface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * so that it can be reclaimed quickly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    public synchronized void flush() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        SurfaceData csd = this.cachedSD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        this.cachedSD = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        this.cacheTracker = StateTracker.NEVER_CURRENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        if (csd != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            csd.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * Returns true iff this SurfaceData proxy is still valid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * and if it has a currently cached replacement that is also
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * valid and current.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    public boolean isAccelerated() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        return (isValid() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                srcTracker.isCurrent() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                cacheTracker.isCurrent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * This method should be called from subclasses which create
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * cached SurfaceData objects that depend on the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * properties of the display.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    protected void activateDisplayListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        GraphicsEnvironment ge =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            GraphicsEnvironment.getLocalGraphicsEnvironment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        // We could have a HeadlessGE at this point, so double-check before
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        // assuming anything.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        // Also, no point in listening to display change events if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        // the image is never going to be accelerated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        if (ge instanceof SunGraphicsEnvironment) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            ((SunGraphicsEnvironment)ge).addDisplayChangedListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * Invoked when the display mode has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * This method will invalidate and drop the internal cachedSD object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    public void displayChanged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * Invoked when the palette has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    public void paletteChanged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        // We could potentially get away with just resetting cacheTracker
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        // here but there is a small window of vulnerability in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        // replaceData method where we could be just finished with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        // updating the cachedSD when this method is called and even
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        // though we set a non-current cacheTracker here it will then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        // immediately get set to a current one by the thread that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        // updating the cachedSD.  It is safer to just replace the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        // srcTracker with a non-current version that will trigger a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        // full update cycle the next time this proxy is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        // The downside is having to go through a full threshold count
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        // before we can update and use our cache again, but palette
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        // changes should be relatively rare...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        this.srcTracker = StateTracker.NEVER_CURRENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * This method attempts to replace the srcData with a cached version.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * It relies on the subclass to determine if the cached version will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * be useful given the operational parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * This method checks any preexisting cached copy for being "up to date"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * and tries to update it if it is stale or non-existant and the
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 11080
diff changeset
   371
     * appropriate number of accesses have occurred since it last was stale.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * An outline of the process is as follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * <ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * <li> Check the operational parameters (txtype, comp, bgColor)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     *      to make sure that the operation is supported.  Return the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     *      original SurfaceData if the operation cannot be accelerated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * <li> Check the tracker for the source surface to see if it has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     *      remained stable since it was last cached.  Update the state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     *      variables to cause both a threshold countdown and an update
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     *      of the cached copy if it is not.  (Setting cacheTracker to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     *      NEVER_CURRENT effectively marks it as "needing to be updated".)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * <li> Check the tracker for the cached copy to see if is still
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     *      valid and up to date.  Note that the cacheTracker may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     *      non-current if either something happened to the cached copy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     *      (eg. surfaceLost) or if the source was out of date and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     *      cacheTracker was set to NEVER_CURRENT to force an update.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     *      Decrement the countdown and copy the source to the cache
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     *      as necessary and then update the variables to show that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     *      the cached copy is stable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    public SurfaceData replaceData(SurfaceData srcData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                                   int txtype,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                                   CompositeType comp,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                                   Color bgColor)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        if (isSupportedOperation(srcData, txtype, comp, bgColor)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            // First deal with tracking the source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            if (!srcTracker.isCurrent()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                    this.numtries = threshold;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                    this.srcTracker = srcData.getStateTracker();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                    this.cacheTracker = StateTracker.NEVER_CURRENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                if (!srcTracker.isCurrent()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                    // Dynamic or Untrackable (or a very recent modification)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                    if (srcData.getState() == State.UNTRACKABLE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                        // UNTRACKABLE means we can never cache again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                        // Invalidate so we get replaced next time we are used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                        // (presumably with an UNCACHED proxy).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                        invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                        // Aggressively drop our reference to the cachedSD
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                        // in case this proxy is not consulted again (and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                        // thus replaced) for a long time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                        flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                    return srcData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            // Then deal with checking the validity of the cached SurfaceData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            SurfaceData csd = this.cachedSD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            if (!cacheTracker.isCurrent()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                // Next make sure the dust has settled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                    if (numtries > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                        --numtries;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                        return srcData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                Rectangle r = srcData.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                int w = r.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                int h = r.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                // Snapshot the tracker in case it changes while
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                // we are updating the cached SD...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                StateTracker curTracker = srcTracker;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                csd = validateSurfaceData(srcData, csd, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                if (csd == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                    synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                        if (curTracker == srcTracker) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                            this.cacheTracker = getRetryTracker(srcData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                            this.cachedSD = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                    return srcData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                updateSurfaceData(srcData, csd, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                if (!csd.isValid()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                    return srcData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                    // We only reset these variables if the tracker from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                    // before the surface update is still in use and current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                    // Note that we must use a srcTracker that was fetched
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                    // from before the update process to make sure that we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                    // do not lose some pixel changes in the shuffle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                    if (curTracker == srcTracker && curTracker.isCurrent()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                        this.cacheTracker = csd.getStateTracker();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                        this.cachedSD = csd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            if (csd != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                return csd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        return srcData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * This is the default implementation for updating the cached
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * SurfaceData from the source (primary) SurfaceData.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * A simple Blit is used to copy the pixels from the source to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * the destination SurfaceData.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * A subclass can override this implementation if a more complex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * operation is required to update its cached copies.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    public void updateSurfaceData(SurfaceData srcData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                                  SurfaceData dstData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                                  int w, int h)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        SurfaceType srcType = srcData.getSurfaceType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        SurfaceType dstType = dstData.getSurfaceType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        Blit blit = Blit.getFromCache(srcType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                                      CompositeType.SrcNoEa,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                                      dstType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        blit.Blit(srcData, dstData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                  AlphaComposite.Src, null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                  0, 0, 0, 0, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        dstData.markDirty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * This is an alternate implementation for updating the cached
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * SurfaceData from the source (primary) SurfaceData using a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * background color for transparent pixels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * A simple BlitBg is used to copy the pixels from the source to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     * the destination SurfaceData with the specified bgColor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * A subclass can override the normal updateSurfaceData method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * and call this implementation instead if it wants to use color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * keying for bitmask images.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    public void updateSurfaceDataBg(SurfaceData srcData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                                    SurfaceData dstData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                                    int w, int h, Color bgColor)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        SurfaceType srcType = srcData.getSurfaceType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        SurfaceType dstType = dstData.getSurfaceType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        BlitBg blitbg = BlitBg.getFromCache(srcType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                                            CompositeType.SrcNoEa,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                                            dstType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        blitbg.BlitBg(srcData, dstData,
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   524
                      AlphaComposite.Src, null, bgColor.getRGB(),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                      0, 0, 0, 0, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        dstData.markDirty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
}