Path: blob/master/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLComposite.m
41159 views
/*1* Copyright (c) 2019, 2021, 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*/2425#include "MTLComposite.h"26#include "sun_java2d_SunGraphics2D.h"27#include "java_awt_AlphaComposite.h"2829@implementation MTLComposite {30jint _compState;31jint _compositeRule;32jint _xorPixel;33jfloat _extraAlpha;34}3536- (id)init {37self = [super init];38if (self) {39_compositeRule = -1;40_compState = -1;41_xorPixel = 0;42_extraAlpha = 1;43}44return self;45}4647- (BOOL)isEqual:(MTLComposite *)other {48if (self == other)49return YES;5051if (_compState == other->_compState) {52if (_compState == sun_java2d_SunGraphics2D_COMP_XOR) {53return _xorPixel == other->_xorPixel;54}5556if (_compState == sun_java2d_SunGraphics2D_COMP_ALPHA) {57return _extraAlpha == other->_extraAlpha58&& _compositeRule == other->_compositeRule;59}60}6162return NO;63}6465- (void)copyFrom:(MTLComposite *)other {66_extraAlpha = other->_extraAlpha;67_compositeRule = other->_compositeRule;68_compState = other->_compState;69_xorPixel = other->_xorPixel;70}7172- (void)setRule:(jint)rule {73_extraAlpha = 1.f;74_compositeRule = rule;75}7677- (void)setRule:(jint)rule extraAlpha:(jfloat)extraAlpha {78_compState = sun_java2d_SunGraphics2D_COMP_ALPHA;79_extraAlpha = extraAlpha;80_compositeRule = rule;81}8283- (void)reset {84_compState = sun_java2d_SunGraphics2D_COMP_ISCOPY;85_compositeRule = java_awt_AlphaComposite_SRC;86_extraAlpha = 1.f;87}8889- (jint)getRule {90return _compositeRule;91}9293- (NSString *)getDescription {94const char * result = "";95switch (_compositeRule) {96case java_awt_AlphaComposite_CLEAR:97{98result = "CLEAR";99}100break;101case java_awt_AlphaComposite_SRC:102{103result = "SRC";104}105break;106case java_awt_AlphaComposite_DST:107{108result = "DST";109}110break;111case java_awt_AlphaComposite_SRC_OVER:112{113result = "SRC_OVER";114}115break;116case java_awt_AlphaComposite_DST_OVER:117{118result = "DST_OVER";119}120break;121case java_awt_AlphaComposite_SRC_IN:122{123result = "SRC_IN";124}125break;126case java_awt_AlphaComposite_DST_IN:127{128result = "DST_IN";129}130break;131case java_awt_AlphaComposite_SRC_OUT:132{133result = "SRC_OUT";134}135break;136case java_awt_AlphaComposite_DST_OUT:137{138result = "DST_OUT";139}140break;141case java_awt_AlphaComposite_SRC_ATOP:142{143result = "SRC_ATOP";144}145break;146case java_awt_AlphaComposite_DST_ATOP:147{148result = "DST_ATOP";149}150break;151case java_awt_AlphaComposite_XOR:152{153result = "XOR";154}155break;156default:157result = "UNKNOWN";158break;159}160const double epsilon = 0.001f;161if (fabs(_extraAlpha - 1.f) > epsilon) {162return [NSString stringWithFormat:@"%s [%1.2f]", result, _extraAlpha];163}164return [NSString stringWithFormat:@"%s", result];165}166167- (void)setAlphaComposite:(jint)rule {168_compState = sun_java2d_SunGraphics2D_COMP_ALPHA;169[self setRule:rule];170}171172173- (jint)getCompositeState {174return _compState;175}176177178-(void)setXORComposite:(jint)color {179_compState = sun_java2d_SunGraphics2D_COMP_XOR;180_xorPixel = color;181}182183-(jint)getXorColor {184return _xorPixel;185}186187- (jfloat)getExtraAlpha {188return _extraAlpha;189}190191@end192193194