Path: blob/master/src/java.desktop/share/classes/java/awt/Composite.java
41152 views
/*1* Copyright (c) 1997, 1998, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package java.awt;2627import java.awt.image.ColorModel;2829/**30* The {@code Composite} interface, along with31* {@link CompositeContext}, defines the methods to compose a draw32* primitive with the underlying graphics area.33* After the {@code Composite} is set in the34* {@link Graphics2D} context, it combines a shape, text, or an image35* being rendered with the colors that have already been rendered36* according to pre-defined rules. The classes37* implementing this interface provide the rules and a method to create38* the context for a particular operation.39* {@code CompositeContext} is an environment used by the40* compositing operation, which is created by the {@code Graphics2D}41* prior to the start of the operation. {@code CompositeContext}42* contains private information and resources needed for a compositing43* operation. When the {@code CompositeContext} is no longer needed,44* the {@code Graphics2D} object disposes of it in order to reclaim45* resources allocated for the operation.46* <p>47* Instances of classes implementing {@code Composite} must be48* immutable because the {@code Graphics2D} does not clone49* these objects when they are set as an attribute with the50* {@code setComposite} method or when the {@code Graphics2D}51* object is cloned. This is to avoid undefined rendering behavior of52* {@code Graphics2D}, resulting from the modification of53* the {@code Composite} object after it has been set in the54* {@code Graphics2D} context.55* <p>56* Since this interface must expose the contents of pixels on the57* target device or image to potentially arbitrary code, the use of58* custom objects which implement this interface when rendering directly59* to a screen device is governed by the {@code readDisplayPixels}60* {@link AWTPermission}. The permission check will occur when such61* a custom object is passed to the {@code setComposite} method62* of a {@code Graphics2D} retrieved from a {@link Component}.63* @see AlphaComposite64* @see CompositeContext65* @see Graphics2D#setComposite66*/67public interface Composite {6869/**70* Creates a context containing state that is used to perform71* the compositing operation. In a multi-threaded environment,72* several contexts can exist simultaneously for a single73* {@code Composite} object.74* @param srcColorModel the {@link ColorModel} of the source75* @param dstColorModel the {@code ColorModel} of the destination76* @param hints the hint that the context object uses to choose between77* rendering alternatives78* @return the {@code CompositeContext} object used to perform the79* compositing operation.80*/81public CompositeContext createContext(ColorModel srcColorModel,82ColorModel dstColorModel,83RenderingHints hints);8485}868788