1 /* |
1 /* |
2 * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
28 import java.awt.AlphaComposite; |
28 import java.awt.AlphaComposite; |
29 import java.awt.Color; |
29 import java.awt.Color; |
30 import java.awt.Composite; |
30 import java.awt.Composite; |
31 import java.awt.Paint; |
31 import java.awt.Paint; |
32 import java.awt.geom.AffineTransform; |
32 import java.awt.geom.AffineTransform; |
33 import sun.java2d.pipe.hw.AccelSurface; |
33 import java.lang.annotation.Native; |
|
34 import java.lang.ref.Reference; |
|
35 import java.lang.ref.WeakReference; |
|
36 |
34 import sun.java2d.InvalidPipeException; |
37 import sun.java2d.InvalidPipeException; |
35 import sun.java2d.SunGraphics2D; |
38 import sun.java2d.SunGraphics2D; |
36 import sun.java2d.loops.XORComposite; |
39 import sun.java2d.loops.XORComposite; |
37 import static sun.java2d.pipe.BufferedOpCodes.*; |
40 import sun.java2d.pipe.hw.AccelSurface; |
|
41 |
|
42 import static sun.java2d.pipe.BufferedOpCodes.BEGIN_SHAPE_CLIP; |
|
43 import static sun.java2d.pipe.BufferedOpCodes.END_SHAPE_CLIP; |
|
44 import static sun.java2d.pipe.BufferedOpCodes.RESET_CLIP; |
|
45 import static sun.java2d.pipe.BufferedOpCodes.RESET_COMPOSITE; |
|
46 import static sun.java2d.pipe.BufferedOpCodes.RESET_TRANSFORM; |
|
47 import static sun.java2d.pipe.BufferedOpCodes.SET_ALPHA_COMPOSITE; |
|
48 import static sun.java2d.pipe.BufferedOpCodes.SET_RECT_CLIP; |
|
49 import static sun.java2d.pipe.BufferedOpCodes.SET_SHAPE_CLIP_SPANS; |
|
50 import static sun.java2d.pipe.BufferedOpCodes.SET_SURFACES; |
|
51 import static sun.java2d.pipe.BufferedOpCodes.SET_TRANSFORM; |
|
52 import static sun.java2d.pipe.BufferedOpCodes.SET_XOR_COMPOSITE; |
38 import static sun.java2d.pipe.BufferedRenderPipe.BYTES_PER_SPAN; |
53 import static sun.java2d.pipe.BufferedRenderPipe.BYTES_PER_SPAN; |
39 |
|
40 import java.lang.annotation.Native; |
|
41 import java.lang.ref.Reference; |
|
42 import java.lang.ref.WeakReference; |
|
43 |
54 |
44 /** |
55 /** |
45 * Base context class for managing state in a single-threaded rendering |
56 * Base context class for managing state in a single-threaded rendering |
46 * environment. Each state-setting operation (e.g. SET_COLOR) is added to |
57 * environment. Each state-setting operation (e.g. SET_COLOR) is added to |
47 * the provided RenderQueue, which will be processed at a later time by a |
58 * the provided RenderQueue, which will be processed at a later time by a |
75 * Indicates that the operation uses an alpha mask, which may determine |
86 * Indicates that the operation uses an alpha mask, which may determine |
76 * the code path that is used when setting up the current paint state. |
87 * the code path that is used when setting up the current paint state. |
77 */ |
88 */ |
78 @Native public static final int USE_MASK = (1 << 1); |
89 @Native public static final int USE_MASK = (1 << 1); |
79 |
90 |
80 protected RenderQueue rq; |
91 private final RenderQueue rq; |
81 protected RenderBuffer buf; |
92 private final RenderBuffer buf; |
82 |
93 |
83 /** |
94 /** |
84 * This is a reference to the most recently validated BufferedContext. If |
95 * This is a reference to the most recently validated BufferedContext. If |
85 * this value is null, it means that there is no current context. It is |
96 * this value is null, it means that there is no current context. It is |
86 * provided here so that validate() only needs to do a quick reference |
97 * provided here so that validate() only needs to do a quick reference |
170 * It's assumed that the type of surfaces has been checked by the Renderer |
181 * It's assumed that the type of surfaces has been checked by the Renderer |
171 * |
182 * |
172 * @throws InvalidPipeException if either src or dest surface is not valid |
183 * @throws InvalidPipeException if either src or dest surface is not valid |
173 * or lost |
184 * or lost |
174 */ |
185 */ |
175 public void validate(AccelSurface srcData, AccelSurface dstData, |
186 private void validate(AccelSurface srcData, AccelSurface dstData, |
176 Region clip, Composite comp, |
187 Region clip, Composite comp, |
177 AffineTransform xform, |
188 AffineTransform xform, |
178 Paint paint, SunGraphics2D sg2d, int flags) |
189 Paint paint, SunGraphics2D sg2d, int flags) |
179 { |
190 { |
180 // assert rq.lock.isHeldByCurrentThread(); |
191 // assert rq.lock.isHeldByCurrentThread(); |
306 } |
317 } |
307 |
318 |
308 // mark dstData dirty |
319 // mark dstData dirty |
309 // REMIND: is this really needed now? we do it in SunGraphics2D.. |
320 // REMIND: is this really needed now? we do it in SunGraphics2D.. |
310 dstData.markDirty(); |
321 dstData.markDirty(); |
311 } |
|
312 |
|
313 /** |
|
314 * Invalidates the surfaces associated with this context. This is |
|
315 * useful when the context is no longer needed, and we want to break |
|
316 * the chain caused by these surface references. |
|
317 * |
|
318 * Note: must be called while the RenderQueue lock is held. |
|
319 * |
|
320 * @see RenderQueue#lock |
|
321 * @see RenderQueue#unlock |
|
322 */ |
|
323 private void invalidateSurfaces() { |
|
324 validSrcDataRef.clear(); |
|
325 validDstDataRef.clear(); |
|
326 } |
322 } |
327 |
323 |
328 private void setSurfaces(AccelSurface srcData, |
324 private void setSurfaces(AccelSurface srcData, |
329 AccelSurface dstData) |
325 AccelSurface dstData) |
330 { |
326 { |
431 * Note: must be called while the RenderQueue lock is held. |
427 * Note: must be called while the RenderQueue lock is held. |
432 * |
428 * |
433 * @see RenderQueue#lock |
429 * @see RenderQueue#lock |
434 * @see RenderQueue#unlock |
430 * @see RenderQueue#unlock |
435 */ |
431 */ |
436 public void invalidateContext() { |
432 public final void invalidateContext() { |
437 resetTransform(); |
433 resetTransform(); |
438 resetComposite(); |
434 resetComposite(); |
439 resetClip(); |
435 resetClip(); |
440 BufferedPaints.resetPaint(rq); |
436 BufferedPaints.resetPaint(rq); |
441 invalidateSurfaces(); |
437 validSrcDataRef.clear(); |
|
438 validDstDataRef.clear(); |
442 validCompRef.clear(); |
439 validCompRef.clear(); |
443 validClipRef.clear(); |
440 validClipRef.clear(); |
444 validPaintRef.clear(); |
441 validPaintRef.clear(); |
445 isValidatedPaintJustAColor = false; |
442 isValidatedPaintJustAColor = false; |
446 xformInUse = false; |
443 xformInUse = false; |
451 * pipeline. |
448 * pipeline. |
452 * |
449 * |
453 * @return a render queue |
450 * @return a render queue |
454 * @see RenderQueue |
451 * @see RenderQueue |
455 */ |
452 */ |
456 public abstract RenderQueue getRenderQueue(); |
453 public final RenderQueue getRenderQueue() { |
457 |
454 return rq; |
458 /** |
455 } |
459 * Saves the state of this context. |
|
460 * It may reset the current context. |
|
461 * |
|
462 * Note: must be called while the RenderQueue lock is held. |
|
463 * |
|
464 * @see RenderQueue#lock |
|
465 * @see RenderQueue#unlock |
|
466 */ |
|
467 public abstract void saveState(); |
|
468 |
|
469 /** |
|
470 * Restores the native state of this context. |
|
471 * It may reset the current context. |
|
472 * |
|
473 * Note: must be called while the RenderQueue lock is held. |
|
474 * |
|
475 * @see RenderQueue#lock |
|
476 * @see RenderQueue#unlock |
|
477 */ |
|
478 public abstract void restoreState(); |
|
479 } |
456 } |