src/java.desktop/share/classes/sun/java2d/pipe/BufferedContext.java
author tvaleev
Thu, 04 Oct 2018 12:40:55 -0700
changeset 52248 2e330da7cbf4
parent 47216 71c04702a3d5
child 58324 0aba35254e00
permissions -rw-r--r--
8211300: Convert C-style array declarations in JDK client code Reviewed-by: prr, serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
52248
2e330da7cbf4 8211300: Convert C-style array declarations in JDK client code
tvaleev
parents: 47216
diff changeset
     2
 * Copyright (c) 2005, 2018, 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: 1732
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: 1732
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: 1732
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1732
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1732
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.pipe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.AlphaComposite;
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    29
import java.awt.Color;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.Composite;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.Paint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.geom.AffineTransform;
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    33
import sun.java2d.pipe.hw.AccelSurface;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import sun.java2d.InvalidPipeException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import sun.java2d.SunGraphics2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import sun.java2d.loops.XORComposite;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import static sun.java2d.pipe.BufferedOpCodes.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import static sun.java2d.pipe.BufferedRenderPipe.BYTES_PER_SPAN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12813
diff changeset
    40
import java.lang.annotation.Native;
39007
576736088436 8028486: java/awt/Window/WindowsLeak/WindowsLeak.java fails
serb
parents: 28059
diff changeset
    41
import java.lang.ref.Reference;
576736088436 8028486: java/awt/Window/WindowsLeak/WindowsLeak.java fails
serb
parents: 28059
diff changeset
    42
import java.lang.ref.WeakReference;
12813
c10ab96dcf41 7170969: Add @GenerateNativeHeader to classes whose fields need to be exported for JNI
erikj
parents: 11897
diff changeset
    43
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * Base context class for managing state in a single-threaded rendering
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * environment.  Each state-setting operation (e.g. SET_COLOR) is added to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * the provided RenderQueue, which will be processed at a later time by a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * single thread.  Note that the RenderQueue lock must be acquired before
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * calling the validate() method (or any other method in this class).  See
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * the RenderQueue class comments for a sample usage scenario.
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    51
 *
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    52
 * @see RenderQueue
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 */
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    54
public abstract class BufferedContext {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * The following flags help the internals of validate() determine
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * the appropriate (meaning correct, or optimal) code path when
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * setting up the current context.  The flags can be bitwise OR'd
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * together as needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * Indicates that no flags are needed; take all default code paths.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     */
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12813
diff changeset
    66
    @Native public static final int NO_CONTEXT_FLAGS = (0 << 0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * Indicates that the source surface (or color value, if it is a simple
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * rendering operation) is opaque (has an alpha value of 1.0).  If this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * flag is present, it allows us to disable blending in certain
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * situations in order to improve performance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     */
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12813
diff changeset
    73
    @Native public static final int SRC_IS_OPAQUE    = (1 << 0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * Indicates that the operation uses an alpha mask, which may determine
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * the code path that is used when setting up the current paint state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     */
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12813
diff changeset
    78
    @Native public static final int USE_MASK         = (1 << 1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    protected RenderQueue rq;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    protected RenderBuffer buf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * This is a reference to the most recently validated BufferedContext.  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * this value is null, it means that there is no current context.  It is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * provided here so that validate() only needs to do a quick reference
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * check to see if the BufferedContext passed to that method is the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * as the one we've cached here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    protected static BufferedContext currentContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
39007
576736088436 8028486: java/awt/Window/WindowsLeak/WindowsLeak.java fails
serb
parents: 28059
diff changeset
    92
    private Reference<AccelSurface> validSrcDataRef = new WeakReference<>(null);
576736088436 8028486: java/awt/Window/WindowsLeak/WindowsLeak.java fails
serb
parents: 28059
diff changeset
    93
    private Reference<AccelSurface> validDstDataRef = new WeakReference<>(null);
576736088436 8028486: java/awt/Window/WindowsLeak/WindowsLeak.java fails
serb
parents: 28059
diff changeset
    94
    private Reference<Region> validClipRef = new WeakReference<>(null);
576736088436 8028486: java/awt/Window/WindowsLeak/WindowsLeak.java fails
serb
parents: 28059
diff changeset
    95
    private Reference<Composite> validCompRef = new WeakReference<>(null);
576736088436 8028486: java/awt/Window/WindowsLeak/WindowsLeak.java fails
serb
parents: 28059
diff changeset
    96
    private Reference<Paint> validPaintRef = new WeakReference<>(null);
1732
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents: 887
diff changeset
    97
    // renamed from isValidatedPaintAColor as part of a work around for 6764257
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents: 887
diff changeset
    98
    private boolean         isValidatedPaintJustAColor;
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    99
    private int             validatedRGB;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    private int             validatedFlags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    private boolean         xformInUse;
16840
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   102
    private AffineTransform transform;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    protected BufferedContext(RenderQueue rq) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        this.rq = rq;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        this.buf = rq.getBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /**
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   110
     * Fetches the BufferedContextContext associated with the dst. surface
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   111
     * and validates the context using the given parameters.  Most rendering
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   112
     * operations will call this method first in order to set the necessary
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   113
     * state before issuing rendering commands.
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   114
     *
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   115
     * Note: must be called while the RenderQueue lock is held.
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   116
     *
11897
9e80dbac0293 7112642: Incorrect checking for graphics rendering object
bagiras
parents: 5506
diff changeset
   117
     * It's assumed that the type of surfaces has been checked by the Renderer
9e80dbac0293 7112642: Incorrect checking for graphics rendering object
bagiras
parents: 5506
diff changeset
   118
     *
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   119
     * @throws InvalidPipeException if either src or dest surface is not valid
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   120
     * or lost
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   121
     * @see RenderQueue#lock
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   122
     * @see RenderQueue#unlock
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   123
     */
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   124
    public static void validateContext(AccelSurface srcData,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   125
                                       AccelSurface dstData,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   126
                                       Region clip, Composite comp,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   127
                                       AffineTransform xform,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   128
                                       Paint paint, SunGraphics2D sg2d,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   129
                                       int flags)
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   130
    {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   131
        // assert rq.lock.isHeldByCurrentThread();
39007
576736088436 8028486: java/awt/Window/WindowsLeak/WindowsLeak.java fails
serb
parents: 28059
diff changeset
   132
        BufferedContext context = dstData.getContext();
576736088436 8028486: java/awt/Window/WindowsLeak/WindowsLeak.java fails
serb
parents: 28059
diff changeset
   133
        context.validate(srcData, dstData,
576736088436 8028486: java/awt/Window/WindowsLeak/WindowsLeak.java fails
serb
parents: 28059
diff changeset
   134
                         clip, comp, xform, paint, sg2d, flags);
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   135
    }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   136
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   137
    /**
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   138
     * Fetches the BufferedContextassociated with the surface
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   139
     * and disables all context state settings.
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   140
     *
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   141
     * Note: must be called while the RenderQueue lock is held.
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   142
     *
11897
9e80dbac0293 7112642: Incorrect checking for graphics rendering object
bagiras
parents: 5506
diff changeset
   143
     * It's assumed that the type of surfaces has been checked by the Renderer
9e80dbac0293 7112642: Incorrect checking for graphics rendering object
bagiras
parents: 5506
diff changeset
   144
     *
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   145
     * @throws InvalidPipeException if the surface is not valid
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   146
     * or lost
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   147
     * @see RenderQueue#lock
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   148
     * @see RenderQueue#unlock
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   149
     */
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   150
    public static void validateContext(AccelSurface surface) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   151
        // assert rt.lock.isHeldByCurrentThread();
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   152
        validateContext(surface, surface,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   153
                        null, null, null, null, null, NO_CONTEXT_FLAGS);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   154
    }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   155
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   156
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * Validates the given parameters against the current state for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * context.  If this context is not current, it will be made current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * for the given source and destination surfaces, and the viewport will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * be updated.  Then each part of the context state (clip, composite,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * etc.) is checked against the previous value.  If the value has changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * since the last call to validate(), it will be updated accordingly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * Note that the SunGraphics2D parameter is only used for the purposes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * of validating a (non-null) Paint parameter.  In all other cases it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * is safe to pass a null SunGraphics2D and it will be ignored.
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   167
     *
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   168
     * Note: must be called while the RenderQueue lock is held.
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   169
     *
11897
9e80dbac0293 7112642: Incorrect checking for graphics rendering object
bagiras
parents: 5506
diff changeset
   170
     * It's assumed that the type of surfaces has been checked by the Renderer
9e80dbac0293 7112642: Incorrect checking for graphics rendering object
bagiras
parents: 5506
diff changeset
   171
     *
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   172
     * @throws InvalidPipeException if either src or dest surface is not valid
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   173
     * or lost
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     */
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   175
    public void validate(AccelSurface srcData, AccelSurface dstData,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                         Region clip, Composite comp,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                         AffineTransform xform,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                         Paint paint, SunGraphics2D sg2d, int flags)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        // assert rq.lock.isHeldByCurrentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   182
        boolean updateClip = false;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   183
        boolean updatePaint = false;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   184
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   185
        if (!dstData.isValid() ||
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   186
            dstData.isSurfaceLost() || srcData.isSurfaceLost())
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   187
        {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   188
            invalidateContext();
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   189
            throw new InvalidPipeException("bounds changed or surface lost");
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   190
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   192
        if (paint instanceof Color) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   193
            // REMIND: not 30-bit friendly
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   194
            int newRGB = ((Color)paint).getRGB();
1732
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents: 887
diff changeset
   195
            if (isValidatedPaintJustAColor) {
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   196
                if (newRGB != validatedRGB) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   197
                    validatedRGB = newRGB;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   198
                    updatePaint = true;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   199
                }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   200
            } else {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   201
                validatedRGB = newRGB;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   202
                updatePaint = true;
1732
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents: 887
diff changeset
   203
                isValidatedPaintJustAColor = true;
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   204
            }
39007
576736088436 8028486: java/awt/Window/WindowsLeak/WindowsLeak.java fails
serb
parents: 28059
diff changeset
   205
        } else if (validPaintRef.get() != paint) {
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   206
            updatePaint = true;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   207
            // this should be set when we are switching from paint to color
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   208
            // in which case this condition will be true
1732
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents: 887
diff changeset
   209
            isValidatedPaintJustAColor = false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
39007
576736088436 8028486: java/awt/Window/WindowsLeak/WindowsLeak.java fails
serb
parents: 28059
diff changeset
   212
        final AccelSurface validatedSrcData = validSrcDataRef.get();
576736088436 8028486: java/awt/Window/WindowsLeak/WindowsLeak.java fails
serb
parents: 28059
diff changeset
   213
        final AccelSurface validatedDstData = validDstDataRef.get();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        if ((currentContext != this) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            (srcData != validatedSrcData) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            (dstData != validatedDstData))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            if (dstData != validatedDstData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                // the clip is dependent on the destination surface, so we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                // need to update it if we have a new destination surface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                updateClip = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            if (paint == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                // make sure we update the color state (otherwise, it might
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                // not be updated if this is the first time the context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                // is being validated)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                updatePaint = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            // update the current source and destination surfaces
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            setSurfaces(srcData, dstData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            currentContext = this;
39007
576736088436 8028486: java/awt/Window/WindowsLeak/WindowsLeak.java fails
serb
parents: 28059
diff changeset
   235
            validSrcDataRef = new WeakReference<>(srcData);
576736088436 8028486: java/awt/Window/WindowsLeak/WindowsLeak.java fails
serb
parents: 28059
diff changeset
   236
            validDstDataRef = new WeakReference<>(dstData);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        // validate clip
39007
576736088436 8028486: java/awt/Window/WindowsLeak/WindowsLeak.java fails
serb
parents: 28059
diff changeset
   240
        final Region validatedClip = validClipRef.get();
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   241
        if ((clip != validatedClip) || updateClip) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            if (clip != null) {
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   243
                if (updateClip ||
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   244
                    validatedClip == null ||
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   245
                    !(validatedClip.isRectangular() && clip.isRectangular()) ||
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   246
                    ((clip.getLoX() != validatedClip.getLoX() ||
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   247
                      clip.getLoY() != validatedClip.getLoY() ||
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   248
                      clip.getHiX() != validatedClip.getHiX() ||
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   249
                      clip.getHiY() != validatedClip.getHiY())))
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   250
                {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   251
                    setClip(clip);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   252
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                resetClip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            }
39007
576736088436 8028486: java/awt/Window/WindowsLeak/WindowsLeak.java fails
serb
parents: 28059
diff changeset
   256
            validClipRef = new WeakReference<>(clip);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        // validate composite (note that a change in the context flags
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        // may require us to update the composite state, even if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        // composite has not changed)
39007
576736088436 8028486: java/awt/Window/WindowsLeak/WindowsLeak.java fails
serb
parents: 28059
diff changeset
   262
        if ((comp != validCompRef.get()) || (flags != validatedFlags)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            if (comp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                setComposite(comp, flags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                resetComposite();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            // the paint state is dependent on the composite state, so make
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            // sure we update the color below
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            updatePaint = true;
39007
576736088436 8028486: java/awt/Window/WindowsLeak/WindowsLeak.java fails
serb
parents: 28059
diff changeset
   271
            validCompRef = new WeakReference<>(comp);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            validatedFlags = flags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        // validate transform
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   276
        boolean txChanged = false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        if (xform == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            if (xformInUse) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                resetTransform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                xformInUse = false;
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   281
                txChanged = true;
16840
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   282
            } else if (sg2d != null && !sg2d.transform.equals(transform)) {
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   283
                txChanged = true;
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   284
            }
16840
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   285
            if (sg2d != null && txChanged) {
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   286
                transform = new AffineTransform(sg2d.transform);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            setTransform(xform);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            xformInUse = true;
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   291
            txChanged = true;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   292
        }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   293
        // non-Color paints may require paint revalidation
1732
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents: 887
diff changeset
   294
        if (!isValidatedPaintJustAColor && txChanged) {
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   295
            updatePaint = true;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        // validate paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        if (updatePaint) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            if (paint != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                BufferedPaints.setPaint(rq, sg2d, paint, flags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                BufferedPaints.resetPaint(rq);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            }
39007
576736088436 8028486: java/awt/Window/WindowsLeak/WindowsLeak.java fails
serb
parents: 28059
diff changeset
   305
            validPaintRef = new WeakReference<>(paint);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        // mark dstData dirty
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   309
        // REMIND: is this really needed now? we do it in SunGraphics2D..
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        dstData.markDirty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * Invalidates the surfaces associated with this context.  This is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * useful when the context is no longer needed, and we want to break
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * the chain caused by these surface references.
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   317
     *
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   318
     * Note: must be called while the RenderQueue lock is held.
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   319
     *
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   320
     * @see RenderQueue#lock
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   321
     * @see RenderQueue#unlock
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     */
39007
576736088436 8028486: java/awt/Window/WindowsLeak/WindowsLeak.java fails
serb
parents: 28059
diff changeset
   323
    private void invalidateSurfaces() {
576736088436 8028486: java/awt/Window/WindowsLeak/WindowsLeak.java fails
serb
parents: 28059
diff changeset
   324
        validSrcDataRef.clear();
576736088436 8028486: java/awt/Window/WindowsLeak/WindowsLeak.java fails
serb
parents: 28059
diff changeset
   325
        validDstDataRef.clear();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   328
    private void setSurfaces(AccelSurface srcData,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   329
                             AccelSurface dstData)
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   330
    {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        // assert rq.lock.isHeldByCurrentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        rq.ensureCapacityAndAlignment(20, 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        buf.putInt(SET_SURFACES);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        buf.putLong(srcData.getNativeOps());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        buf.putLong(dstData.getNativeOps());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    private void resetClip() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        // assert rq.lock.isHeldByCurrentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        rq.ensureCapacity(4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        buf.putInt(RESET_CLIP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    private void setClip(Region clip) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        // assert rq.lock.isHeldByCurrentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        if (clip.isRectangular()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            rq.ensureCapacity(20);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            buf.putInt(SET_RECT_CLIP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            buf.putInt(clip.getLoX()).putInt(clip.getLoY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            buf.putInt(clip.getHiX()).putInt(clip.getHiY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            rq.ensureCapacity(28); // so that we have room for at least a span
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            buf.putInt(BEGIN_SHAPE_CLIP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            buf.putInt(SET_SHAPE_CLIP_SPANS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            // include a placeholder for the span count
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            int countIndex = buf.position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            buf.putInt(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            int spanCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            int remainingSpans = buf.remaining() / BYTES_PER_SPAN;
52248
2e330da7cbf4 8211300: Convert C-style array declarations in JDK client code
tvaleev
parents: 47216
diff changeset
   360
            int[] span = new int[4];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            SpanIterator si = clip.getSpanIterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            while (si.nextSpan(span)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                if (remainingSpans == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                    buf.putInt(countIndex, spanCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                    rq.flushNow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                    buf.putInt(SET_SHAPE_CLIP_SPANS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                    countIndex = buf.position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                    buf.putInt(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                    spanCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                    remainingSpans = buf.remaining() / BYTES_PER_SPAN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                buf.putInt(span[0]); // x1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                buf.putInt(span[1]); // y1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                buf.putInt(span[2]); // x2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                buf.putInt(span[3]); // y2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                spanCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                remainingSpans--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            buf.putInt(countIndex, spanCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            rq.ensureCapacity(4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            buf.putInt(END_SHAPE_CLIP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    private void resetComposite() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        // assert rq.lock.isHeldByCurrentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        rq.ensureCapacity(4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        buf.putInt(RESET_COMPOSITE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    private void setComposite(Composite comp, int flags) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        // assert rq.lock.isHeldByCurrentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        if (comp instanceof AlphaComposite) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            AlphaComposite ac = (AlphaComposite)comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            rq.ensureCapacity(16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            buf.putInt(SET_ALPHA_COMPOSITE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            buf.putInt(ac.getRule());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            buf.putFloat(ac.getAlpha());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            buf.putInt(flags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        } else if (comp instanceof XORComposite) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            int xorPixel = ((XORComposite)comp).getXorPixel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            rq.ensureCapacity(8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            buf.putInt(SET_XOR_COMPOSITE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            buf.putInt(xorPixel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            throw new InternalError("not yet implemented");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    private void resetTransform() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        // assert rq.lock.isHeldByCurrentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        rq.ensureCapacity(4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        buf.putInt(RESET_TRANSFORM);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    private void setTransform(AffineTransform xform) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        // assert rq.lock.isHeldByCurrentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        rq.ensureCapacityAndAlignment(52, 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        buf.putInt(SET_TRANSFORM);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        buf.putDouble(xform.getScaleX());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        buf.putDouble(xform.getShearY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        buf.putDouble(xform.getShearX());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        buf.putDouble(xform.getScaleY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        buf.putDouble(xform.getTranslateX());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        buf.putDouble(xform.getTranslateY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    }
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   427
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   428
    /**
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   429
     * Resets this context's surfaces and all attributes.
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   430
     *
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   431
     * Note: must be called while the RenderQueue lock is held.
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   432
     *
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   433
     * @see RenderQueue#lock
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   434
     * @see RenderQueue#unlock
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   435
     */
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   436
    public void invalidateContext() {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   437
        resetTransform();
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   438
        resetComposite();
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   439
        resetClip();
1732
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents: 887
diff changeset
   440
        BufferedPaints.resetPaint(rq);
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   441
        invalidateSurfaces();
39007
576736088436 8028486: java/awt/Window/WindowsLeak/WindowsLeak.java fails
serb
parents: 28059
diff changeset
   442
        validCompRef.clear();
576736088436 8028486: java/awt/Window/WindowsLeak/WindowsLeak.java fails
serb
parents: 28059
diff changeset
   443
        validClipRef.clear();
576736088436 8028486: java/awt/Window/WindowsLeak/WindowsLeak.java fails
serb
parents: 28059
diff changeset
   444
        validPaintRef.clear();
1732
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents: 887
diff changeset
   445
        isValidatedPaintJustAColor = false;
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   446
        xformInUse = false;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   447
    }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   448
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   449
    /**
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   450
     * Returns a singleton {@code RenderQueue} object used by the rendering
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   451
     * pipeline.
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   452
     *
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   453
     * @return a render queue
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   454
     * @see RenderQueue
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   455
     */
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   456
    public abstract RenderQueue getRenderQueue();
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   457
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   458
    /**
28059
e576535359cc 8067377: My hobby: caning, then then canning, the the can-can
martin
parents: 25859
diff changeset
   459
     * Saves the state of this context.
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   460
     * It may reset the current context.
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   461
     *
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   462
     * Note: must be called while the RenderQueue lock is held.
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   463
     *
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   464
     * @see RenderQueue#lock
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   465
     * @see RenderQueue#unlock
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   466
     */
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   467
    public abstract void saveState();
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   468
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   469
    /**
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   470
     * Restores the native state of this context.
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   471
     * It may reset the current context.
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   472
     *
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   473
     * Note: must be called while the RenderQueue lock is held.
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   474
     *
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   475
     * @see RenderQueue#lock
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   476
     * @see RenderQueue#unlock
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   477
     */
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   478
    public abstract void restoreState();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
}